/* Self-hosted fonts (SIL Open Font License, see fonts/LICENSE-*.txt). Latin subset covers English and Spanish. */
@font-face {
  font-family: "Newsreader";
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
  src: url("fonts/newsreader-latin-opsz-normal.woff2") format("woff2");
}

@font-face {
  font-family: "DM Sans";
  font-style: normal;
  font-weight: 100 1000;
  font-display: swap;
  src: url("fonts/dm-sans-latin-opsz-normal.woff2") format("woff2");
}

/* Brand colors (see BRAND.md). Paper is the default; Night follows the visitor's system. */
:root {
  --bg: #f8f6f1;
  --surface: #efeae0;
  --text: #252c34;
  --muted: #5e646b;
  --border: #d9d8d1;
  --link: #385c55;
  --on-link: #f8f6f1;
  --accent: #a2523a;
  --clay: #c97859;
  --sage: #879488;
  --danger: #a8322a;
  --success: #2f6b4f;

  --serif: "Newsreader", Georgia, "Times New Roman", serif;
  --sans: "DM Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --site: 1160px;
  --read: 690px;
  --gutter: clamp(16px, 4vw, 40px);
  --radius: 4px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1f24;
    --surface: #232830;
    --text: #ece7dd;
    --muted: #a3a9ae;
    --border: #343a42;
    --link: #86b3a8;
    --on-link: #1b1f24;
    --accent: #d98b6c;
    --clay: #d98b6c;
    --danger: #f0897c;
    --success: #8cc4a3;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 1.0625rem;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Page frame: header and footer span the site width; main is a reading column */
.site-header,
.site-footer {
  max-width: var(--site);
  margin: 0 auto;
  padding-inline: var(--gutter);
}

main {
  max-width: calc(var(--read) + 2 * var(--gutter));
  margin: 0 auto;
  padding: 48px var(--gutter) 32px;
}

main.wide {
  max-width: calc(960px + 2 * var(--gutter));
}

main.site {
  max-width: var(--site);
  padding-top: 0;
}

h1,
h2,
h3 {
  text-wrap: balance;
}

h1 {
  margin: 0 0 12px;
  font-family: var(--serif);
  font-size: clamp(2rem, 5vw, 2.6rem);
  font-weight: 500;
  letter-spacing: -0.015em;
  line-height: 1.1;
}

h2 {
  margin: 0 0 12px;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.005em;
}

p {
  margin: 0 0 16px;
}

a {
  color: var(--link);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

a:hover {
  text-decoration-color: var(--clay);
}

a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
}

/* Small uppercase label for dates, sections and annotations */
.eyebrow {
  margin: 0 0 12px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.eyebrow a {
  color: inherit;
  text-decoration: none;
}

.eyebrow a:hover {
  color: var(--link);
}

/* Site header: mark, wordmark and navigation, over a hairline rule */
.site-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px 24px;
  padding-block: 20px;
}

.site-header::after {
  content: "";
  flex-basis: 100%;
  height: 1px;
  margin-top: 12px;
  background: var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.mark {
  width: 28px;
  height: 28px;
  flex: none;
  color: var(--accent);
}

.site-header nav {
  display: flex;
  gap: 24px;
}

.site-header nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.95rem;
}

.site-header nav a:hover,
.site-header nav a[aria-current="page"] {
  color: var(--text);
}

.site-header nav a[aria-current="page"] {
  box-shadow: 0 1px 0 var(--accent);
}

/* Site footer */
.site-footer {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px 40px;
  margin-top: 64px;
  padding-block: 24px 40px;
  color: var(--muted);
  font-size: 0.85rem;
}

.site-footer::before {
  content: "";
  height: 1px;
  background: var(--border);
  grid-column: 1 / -1;
  margin-bottom: 8px;
}

.site-footer p {
  margin: 0;
  max-width: 60ch;
}

.site-footer p + .copyright {
  margin-top: 8px;
}

.site-footer .colophon {
  font-family: var(--serif);
  font-size: 1.05rem;
  color: var(--text);
}

@media (min-width: 720px) {
  .site-footer {
    grid-template-columns: 1fr 2fr;
  }
}

.lead {
  color: var(--muted);
  font-size: 1.15rem;
  margin-bottom: 32px;
  max-width: 36em;
}

.back {
  display: inline-block;
  margin-bottom: 24px;
  text-decoration: none;
}

/* ---------- Home page ---------- */

.hero {
  display: grid;
  gap: 24px 64px;
  padding: clamp(40px, 9vw, 112px) 0 clamp(40px, 7vw, 88px);
  border-bottom: 1px solid var(--border);
}

.hero h1 {
  font-size: clamp(2.6rem, 8vw, 5rem);
  font-weight: 400;
  line-height: 1;
  letter-spacing: -0.025em;
  margin: 0;
}

.hero h1 em {
  font-style: normal;
  color: var(--accent);
}

.hero .intro {
  font-size: 1.15rem;
  max-width: 34em;
  margin: 0;
}

.hero .intro p:last-child {
  margin-bottom: 0;
}

/* A margin note, like one pencilled beside a journal entry */
.note {
  font-family: var(--serif);
  font-size: 1.05rem;
  color: var(--muted);
  border-left: 2px solid var(--clay);
  padding-left: 12px;
  max-width: 22em;
}

.note .eyebrow {
  margin-bottom: 4px;
  font-family: var(--sans);
}

@media (min-width: 900px) {
  .hero {
    grid-template-columns: 7fr 4fr;
    align-items: end;
  }

  .hero h1 {
    grid-column: 1 / -1;
  }
}

/* Section heading: a label on the left, an optional link on the right */
.section {
  padding: 48px 0;
}

.section + .section {
  border-top: 1px solid var(--border);
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  margin-bottom: 28px;
}

.section-head h2 {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.section-head a {
  font-size: 0.95rem;
}

/* The three content pillars */
.pillars {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 32px 40px;
  counter-reset: pillar;
}

.pillars li {
  counter-increment: pillar;
}

.pillars li::before {
  content: counter(pillar, decimal-leading-zero);
  display: block;
  margin-bottom: 8px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.pillars h3 {
  margin: 0 0 6px;
  font-family: var(--serif);
  font-size: 1.6rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  line-height: 1.15;
}

.pillars p {
  margin: 0;
  color: var(--muted);
}

@media (min-width: 720px) {
  .pillars {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ---------- Tool lists (home strip and the Tools index) ---------- */

.tools {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr));
  column-gap: 32px;
}

.tools li {
  border-top: 1px solid var(--border);
}

.tools a {
  display: block;
  height: 100%;
  padding: 16px 0 20px;
  text-decoration: none;
  color: inherit;
}

.tools strong {
  display: block;
  margin-bottom: 4px;
  font-family: var(--serif);
  font-size: 1.3rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  line-height: 1.2;
  color: var(--text);
}

.tools a:hover strong,
.tools a:focus-visible strong {
  color: var(--link);
}

.tools span {
  display: block;
  color: var(--muted);
  font-size: 0.95rem;
}

/* Group headings on the Tools index */
.group {
  margin: 48px 0 16px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.group:first-of-type {
  margin-top: 0;
}

/* ---------- Tool pages ---------- */

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
}

/* Form controls */
input,
select,
button {
  font: inherit;
  color: inherit;
}

input[type="number"],
input[type="text"],
input[type="color"],
select,
textarea {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-variant-numeric: tabular-nums;
}

input[type="number"]:focus,
input[type="text"]:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--link);
  outline-offset: -1px;
}

input[type="color"] {
  padding: 2px;
  height: 40px;
  cursor: pointer;
}

textarea {
  min-height: 200px;
  resize: vertical;
  font-family: var(--mono);
  font-size: 0.9rem;
}

button {
  padding: 8px 16px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
}

button:hover {
  border-color: var(--link);
  color: var(--link);
}

button.primary {
  background: var(--link);
  border-color: var(--link);
  color: var(--on-link);
}

button.primary:hover {
  color: var(--on-link);
  filter: brightness(1.1);
}

label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 4px;
}

/* A sentence-style row: "What is [ ] % of [ ] ? = result" */
.sentence {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.sentence input {
  width: 110px;
}

.result {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.35rem;
  color: var(--accent);
  min-width: 4ch;
  font-variant-numeric: tabular-nums;
}

.row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 8px;
  margin-bottom: 16px;
}

.row .sep {
  padding-bottom: 8px;
  color: var(--muted);
}

.hint {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px 16px;
}

.field {
  margin-bottom: 12px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

/* Segmented toggle built from radio buttons */
.tabs {
  display: inline-flex;
  flex-wrap: wrap;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
  background: var(--bg);
}

.tabs label {
  margin: 0;
  padding: 8px 14px;
  font-size: 0.95rem;
  color: var(--text);
  cursor: pointer;
}

.tabs input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.tabs label:has(input:checked) {
  background: var(--link);
  color: var(--on-link);
}

.tabs label:has(input:focus-visible) {
  outline: 2px solid var(--link);
  outline-offset: -2px;
}

/* Number tables */
table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

th,
td {
  padding: 6px 4px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}

td.num,
th.num {
  text-align: right;
}

/* Lets a wide table scroll inside its card instead of widening the page */
.table-scroll {
  overflow-x: auto;
}

tr.total td {
  font-weight: 600;
  border-bottom: none;
}

.big {
  font-family: var(--serif);
  font-size: 2.4rem;
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--accent);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.error {
  color: var(--danger);
}

.ok {
  color: var(--success);
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
  font-size: 0.95rem;
}

/* Motion: short color changes and a press on buttons, nothing more. Off for reduced motion. */
:root {
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

a,
button,
input,
select,
textarea,
.tabs label,
.tools strong {
  transition:
    color 160ms var(--ease),
    background-color 160ms var(--ease),
    border-color 160ms var(--ease),
    text-decoration-color 160ms var(--ease),
    transform 100ms var(--ease);
}

button:active,
.tabs label:active {
  transform: scale(0.97);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
  }

  button:active,
  .tabs label:active {
    transform: none;
  }
}

/* Home page: three featured tools, stacked on narrow screens and in a row on wider ones */
.tools-strip {
  grid-template-columns: 1fr;
}

@media (min-width: 720px) {
  .tools-strip {
    grid-template-columns: repeat(3, 1fr);
  }
}
