/* Homespun -- editorial reader.
 *
 * DESIGN_VARIANCE 6 / MOTION_INTENSITY 4 / VISUAL_DENSITY 3.
 *
 * Palette is cool grey paper with a single deep-green accent. Deliberately not
 * the warm cream and brass that documentary and heritage briefs default to:
 * that palette is everywhere, and this page needs the Devanagari to be the
 * warmest thing on it.
 *
 * Type: Archivo for Latin, Noto Serif Devanagari for the testimony. The serif
 * is justified by the script rather than by mood -- Devanagari reads better
 * with its traditional letterforms, and the contrast marks spoken words apart
 * from everything written about them.
 */

:root {
  /* Warm paper with a green accent, not the beige and brass every heritage
     page reaches for. The warmth belongs to the page; the accent stays cool so
     the two never blur into the same sepia wash. */
  --paper: #f3ecdf;
  --surface: #f9f3e7;
  --sunk: #eae0cd;
  --ink: #2c2318;          /* warm brown-black, never #000 */
  --ink-2: #5f5547;
  --ink-3: #847e70;
  --rule: #dbd0bb;
  --accent: #1d5c48;
  --accent-deep: #143f31;  /* headings, so colour is in the type not just the gaps */
  --accent-ink: #f9f3e7;
  --accent-wash: #e2eae0;
  --warn: #96563a;
  --before: #b5663a;
  --after: #2f8f6b;

  --measure: 36rem;
  --radius: 4px;

  --latin: "Archivo", ui-sans-serif, system-ui, sans-serif;
  --deva: "Noto Serif Devanagari", "Nirmala UI", "Mangal", serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", monospace;

  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

/* The script sets data-theme on load, so this only governs the first paint
   before it runs. Light is the default; the toggle and localStorage decide
   thereafter. */
/* Dark keeps the same warmth rather than flipping to a cold grey, so the
   toggle reads as the lights going down on one room, not a move to another. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    --paper: #16120e;
    --surface: #1d1813;
    --sunk: #241e17;
    --ink: #efe9df;
    --ink-2: #b4aa9b;
    --ink-3: #847b6d;
    --rule: #332b22;
    --accent: #7fbca4;
    --accent-ink: #11190f;
    --accent-wash: #1b251e;
    --warn: #d98f63;
  }
}
:root[data-theme="dark"] {
  --paper: #16120e;
  --surface: #1f1a14;
  --sunk: #261f18;
  --ink: #f0e9dd;
  --ink-2: #b7ad9d;
  --ink-3: #8a8070;
  --rule: #362d23;
  --accent: #86c2a9;
  --accent-deep: #a8d6c1;
  --accent-ink: #11190f;
  --accent-wash: #1d2820;
  --warn: #c08f78;
  --before: #c0784a;
  --after: #4ca985;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--paper);
  /* A barely-there warm bloom at the top, so a long page of text is not a flat
     fill. Fixed, so it does not travel with the scroll. */
  background-image:
    radial-gradient(100% 60% at 50% -8%, rgb(255 252 244 / 0.9), rgb(255 252 244 / 0) 55%),
    radial-gradient(80% 50% at 85% 8%, rgb(29 92 72 / 0.07), rgb(29 92 72 / 0) 60%),
    radial-gradient(70% 45% at 8% 22%, rgb(181 102 58 / 0.06), rgb(181 102 58 / 0) 60%);
  background-attachment: fixed;
}

:root[data-theme="dark"] body {
  background-image:
    radial-gradient(100% 60% at 50% -8%, rgb(255 255 255 / 0.05), rgb(255 255 255 / 0) 55%),
    radial-gradient(80% 50% at 85% 8%, rgb(134 194 169 / 0.07), rgb(134 194 169 / 0) 60%);
  color: var(--ink);
  font-family: var(--latin);
  font-size: 1rem;
  line-height: 1.6;
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
}

/* Paper grain. Fixed and pointer-events none so it never repaints on scroll,
   which is what makes this cheap enough to leave on. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0.4;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)' opacity='0.26'/%3E%3C/svg%3E");
  mix-blend-mode: multiply;
}
:root[data-theme="dark"] body::before { mix-blend-mode: screen; opacity: 0.16; }


.wrap { width: 100%; max-width: 64rem; margin: 0 auto; padding: 0 clamp(1rem, 4vw, 2.5rem); }
.col { max-width: var(--measure); }

h1, h2, h3 {
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0;
  text-wrap: balance;
  color: var(--accent-deep);
}
p { margin: 0; text-wrap: pretty; }

.eyebrow {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 1.25rem;
}

/* ------------------------------------------------------------------ hero --- */

.hero {
  padding: clamp(3.5rem, 9vw, 6rem) 0 clamp(2.5rem, 6vw, 4rem);
  border-bottom: 1px solid var(--rule);
}
.hero h1 {
  font-size: clamp(2.6rem, 9vw, 5.2rem);
  line-height: 0.98;
  margin-bottom: 1.25rem;
  color: var(--accent);
}
:root[data-theme="dark"] .hero h1 { color: var(--accent-deep); }
.hero .lede {
  font-size: clamp(1.05rem, 2.2vw, 1.3rem);
  color: var(--ink-2);
  max-width: 32rem;
}

/* ---------------------------------------------------------------- exhibit --- */

.exhibit { padding: clamp(3rem, 7vw, 5rem) 0; border-bottom: 1px solid var(--rule); }
.exhibit-grid { display: grid; gap: 2rem; }
@media (min-width: 56rem) {
  .exhibit-grid { grid-template-columns: 1.15fr 1fr; gap: 3.5rem; align-items: start; }
}

.exhibit-grid .said {
  font-family: var(--deva);
  font-size: clamp(1.35rem, 3vw, 1.7rem);
  line-height: 2.1;
  margin-bottom: 1.25rem;
}
.gloss { color: var(--ink-2); font-size: 0.95rem; }

.machine { display: grid; gap: 1px; background: var(--rule); border: 1px solid var(--rule); border-radius: var(--radius); overflow: hidden; }
.machine > div { background: var(--surface); padding: 1rem 1.1rem; }
.machine .who {
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 0.5rem;
}
.machine .out { font-family: var(--deva); line-height: 1.95; font-size: 1rem; }
.machine .bad .out { color: var(--ink-2); }
.machine .bad { background: var(--sunk); border-left: 3px solid var(--rule); }
.machine .good { background: var(--accent-wash); border-left: 3px solid var(--accent); }

/* -------------------------------------------------------------- chapters --- */

.chapters { padding: clamp(3rem, 7vw, 5rem) 0; }
.section-title { font-size: clamp(1.7rem, 4vw, 2.4rem); margin-bottom: 0.9rem; }
.section-note { color: var(--ink-2); max-width: var(--measure); margin-bottom: clamp(2.5rem, 6vw, 3.5rem); }
.chapter { padding-bottom: clamp(3rem, 7vw, 4.5rem); }
.chapter + .chapter { border-top: 1px solid var(--rule); padding-top: clamp(2.5rem, 6vw, 4rem); }

.chapter-head { display: grid; gap: 0.6rem; margin-bottom: 2rem; }
.chapter-head h2 { font-size: clamp(1.5rem, 3.4vw, 2rem); line-height: 1.15; }
.chapter-head .intro { color: var(--ink-2); max-width: var(--measure); }

.narration {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.45rem 0.8rem 0.45rem 0.6rem;
  background: var(--sunk);
  border: 1px solid var(--rule);
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-2);
  cursor: pointer;
  transition: background 0.25s var(--ease), border-color 0.25s var(--ease);
}
.narration:hover { background: var(--accent-wash); border-color: var(--accent); }
.narration:active { transform: scale(0.98); }
.narration[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* --------------------------------------------------------------- entries --- */

.entries { display: grid; gap: 1.5rem; }

.entry {
  display: grid;
  gap: 0.9rem;
  padding: 1.35rem 1.4rem;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
}

/* Devanagari needs far more leading than Latin at the same size, or the
   matras collide with the line above. 2.0 is not generous, it is the floor. */
.quote {
  font-family: var(--deva);
  font-size: clamp(1.15rem, 2.4vw, 1.35rem);
  line-height: 2.05;
}

.english {
  color: var(--ink-2);
  font-size: 0.95rem;
  line-height: 1.65;
  font-style: italic;
  padding-top: 0.8rem;
  border-top: 1px dashed var(--rule);
  max-width: var(--measure);
}

.player { display: flex; align-items: center; gap: 0.9rem; }

.play {
  flex: none;
  width: 2.5rem; height: 2.5rem;
  border-radius: 999px;
  border: 1px solid var(--rule);
  background: var(--surface);
  color: var(--ink);
  display: grid; place-items: center;
  cursor: pointer;
  transition: background 0.25s var(--ease), border-color 0.25s var(--ease), transform 0.12s var(--ease);
}
.play:hover { border-color: var(--accent); color: var(--accent); }
.play:active { transform: scale(0.94); }
.play[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.play svg { width: 1rem; height: 1rem; display: block; }

.wave { flex: 1 1 auto; height: 2.5rem; display: block; min-width: 0; }
.wave rect { fill: var(--rule); transition: fill 0.2s linear; }
.wave rect.on { fill: var(--accent); }

.dur { flex: none; font-family: var(--mono); font-size: 0.72rem; color: var(--ink-3); font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------ measurement --- */

.measure-section { padding: clamp(3rem, 7vw, 5rem) 0; border-top: 1px solid var(--rule); }
.measure-section h2 { font-size: clamp(1.7rem, 4vw, 2.4rem); margin-bottom: 1rem; }
.measure-section .intro { color: var(--ink-2); max-width: var(--measure); margin-bottom: 2.5rem; }

.panel {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: clamp(1.1rem, 3vw, 1.75rem);
  margin-bottom: 2rem;
}
.figures { display: grid; gap: 1px; background: var(--rule); border: 1px solid var(--rule); border-radius: var(--radius); overflow: hidden; margin-bottom: 2.5rem; }
@media (min-width: 40rem) { .figures { grid-template-columns: repeat(3, 1fr); } }
.figure { background: var(--surface); padding: 1.4rem 1.2rem; }
.figure .k { font-family: var(--mono); font-size: 0.66rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-3); }
.figure .v { font-size: clamp(1.9rem, 5vw, 2.6rem); font-weight: 600; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; margin: 0.4rem 0 0.1rem; }
.figure .was { font-family: var(--mono); font-size: 0.75rem; color: var(--ink-3); }
.figure .delta { color: var(--accent); font-weight: 600; }

table.metrics { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table.metrics th, table.metrics td { text-align: right; padding: 0.7rem 0.5rem; border-bottom: 1px solid var(--rule); font-variant-numeric: tabular-nums; }
table.metrics th:first-child, table.metrics td:first-child { text-align: left; font-variant-numeric: normal; }
table.metrics thead th { font-family: var(--mono); font-size: 0.66rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-3); font-weight: 400; }
table.metrics td.num { font-family: var(--mono); }
table.metrics td.win { color: var(--accent); font-weight: 600; }

/* ---------------------------------------------------------------- samples --- */

.samples { display: grid; gap: 1.5rem; margin-top: 3rem; }
.sample { border-top: 1px solid var(--rule); padding-top: 1.25rem; }
.sample .meta { font-family: var(--mono); font-size: 0.66rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 0.9rem; }
.row { display: grid; grid-template-columns: 5rem 1fr; gap: 0.75rem; margin-bottom: 0.6rem; }
.row .tag { font-family: var(--mono); font-size: 0.66rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); padding-top: 0.5rem; }
.row .val { font-family: var(--deva); line-height: 1.95; font-size: 1.02rem; }
.row.ref .val { font-weight: 500; color: var(--ink); }
.row.stock .val, .row.tuned .val { font-size: 0.98rem; }
.row.stock .val { color: var(--ink-2); }
.row.tuned .val { color: var(--ink); }
@media (max-width: 40rem) {
  .row { grid-template-columns: 1fr; gap: 0.1rem; }
  .row .tag { padding-top: 0.5rem; }
}

/* ----------------------------------------------------------------- notes --- */

.notes { padding: clamp(3rem, 7vw, 5rem) 0; border-top: 1px solid var(--rule); }
.notes h2 { font-size: clamp(1.4rem, 3vw, 1.8rem); margin-bottom: 1.5rem; }
.note-list { display: grid; gap: 1.25rem; max-width: var(--measure); }
.note { display: grid; gap: 0.3rem; }
.note b { font-weight: 600; }
.note span { color: var(--ink-2); font-size: 0.95rem; }

/* ---------------------------------------------------------------- footer --- */

footer { border-top: 1px solid var(--rule); padding: 3rem 0 4rem; color: var(--ink-3); font-size: 0.85rem; }
footer p { margin-bottom: 1rem; max-width: 44rem; }
footer a { color: var(--accent); text-underline-offset: 2px; }
.cite { font-family: var(--mono); font-size: 0.72rem; line-height: 1.7; background: var(--sunk); border: 1px solid var(--rule); border-radius: var(--radius); padding: 1rem; white-space: pre-wrap; word-break: break-word; color: var(--ink-2); }

.status { color: var(--ink-3); font-size: 0.9rem; }

/* ----------------------------------------------------------------- motion --- */

.reveal { opacity: 0; transform: translateY(14px); }
@media (prefers-reduced-motion: no-preference) {
  .reveal { transition: opacity 0.6s var(--ease), transform 0.6s var(--ease); }
}
.reveal.in { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) {
  .reveal { opacity: 1; transform: none; transition: none; }
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }

/* ------------------------------------------------------------------- nav --- */

.nav {
  border-bottom: 1px solid var(--rule);
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: 10;
}
@supports not (backdrop-filter: blur(1px)) { .nav { background: var(--paper); } }
.nav-inner { display: flex; align-items: center; justify-content: space-between; gap: 1.5rem; height: 60px; }
.brand { font-weight: 600; letter-spacing: -0.01em; text-decoration: none; color: var(--ink); font-size: 1.05rem; }
.nav-links { display: flex; gap: clamp(0.9rem, 3vw, 1.75rem); }
.nav-links a {
  text-decoration: none;
  color: var(--ink-2);
  font-size: 0.88rem;
  padding: 0.2rem 0;
  border-bottom: 1px solid transparent;
  transition: color 0.2s var(--ease), border-color 0.2s var(--ease);
}
.nav-links a:hover { color: var(--ink); }
.nav-links a[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); }

.hero.compact { padding: clamp(2.5rem, 6vw, 4rem) 0 clamp(2rem, 4vw, 2.5rem); }
.hero.compact h1 { font-size: clamp(2rem, 6vw, 3.2rem); }

/* -------------------------------------------------------------- try page --- */

.examples-section, .live-section { padding: clamp(2.5rem, 6vw, 4rem) 0; }
.live-section { border-top: 1px solid var(--rule); }
.live-section.first { border-top: 0; padding-top: clamp(1rem, 3vw, 1.5rem); }
.examples-section { border-top: 1px solid var(--rule); }
.section-note.small { font-size: 0.85rem; margin-top: 2rem; }

.example {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1.35rem 1.4rem;
  margin-bottom: 1.25rem;
}
.example .meta { font-family: var(--mono); font-size: 0.68rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 0.9rem; }
.example .meta .better { color: var(--accent); }
.example .meta .worse { color: var(--warn); font-weight: 600; }
.example .meta .flag { color: var(--warn); }
.example .player { margin-bottom: 1rem; }

.live-controls { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-bottom: 1.25rem; }
.btn {
  font-family: var(--latin);
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius);
  border: 1px solid var(--rule);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.2s var(--ease), border-color 0.2s var(--ease), transform 0.12s var(--ease);
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.quiet { color: var(--ink-2); }
.btn.recording { background: var(--warn); border-color: var(--warn); color: #fff; }

progress { width: 100%; max-width: 24rem; height: 6px; display: block; margin-bottom: 0.75rem; accent-color: var(--accent); }

.live-status { font-size: 0.9rem; color: var(--ink-2); margin-bottom: 1rem; }
.live-status.ok { color: var(--accent); }
.live-status.bad { color: var(--warn); }

.live-text {
  font-family: var(--deva);
  font-size: 1.2rem;
  line-height: 2.05;
  background: var(--accent-wash);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
}

.theme {
  font-family: var(--latin);
  font-size: 0.82rem;
  color: var(--ink-2);
  background: none;
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 0.22rem 0.7rem;
  cursor: pointer;
  transition: color 0.2s var(--ease), border-color 0.2s var(--ease);
}
.theme:hover { color: var(--ink); border-color: var(--accent); }

.wordwall {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  user-select: none;
  /* Faded at the edges so words never collide with the nav or the footer. */
  -webkit-mask-image: radial-gradient(130% 90% at 50% 40%, #000 35%, transparent 85%);
  mask-image: radial-gradient(130% 90% at 50% 40%, #000 35%, transparent 85%);
}
.wordwall { opacity: 0.14; }
:root[data-theme="dark"] .wordwall { opacity: 0.1; }

.wordwall span {
  position: absolute;
  font-family: var(--deva);
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  color: var(--accent);
}


/* Content sits above the wall; the grain stays above both. */
body > *:not(.wordwall) { position: relative; z-index: 2; }
body::before { z-index: 3; }

@media (max-width: 48rem) {
  .wordwall span { opacity: 0.1; }
  :root[data-theme="dark"] .wordwall span { opacity: 0.08; }
}

.example .why {
  margin-top: 0.9rem;
  padding: 0.7rem 0.85rem;
  background: var(--sunk);
  border-left: 3px solid var(--warn);
  border-radius: var(--radius);
  font-size: 0.86rem;
  color: var(--ink-2);
}

/* -------------------------------------------------------------- bar chart --- */

.chart-legend {
  display: flex;
  gap: 1.1rem;
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-2);
  margin-bottom: 1.4rem;
}
.chart-legend span { display: inline-flex; align-items: center; gap: 0.4rem; }
.swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.swatch.before { background: var(--before); }
.swatch.after { background: var(--after); }

.bar-row { margin-bottom: 1.35rem; }
.bar-row:last-child { margin-bottom: 0; }
.bar-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 0.45rem;
}
.bar-head .name { font-weight: 500; }
.bar-head .n {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--ink-3);
  white-space: nowrap;
}
/* Two thin marks, 2px apart, both anchored to the same baseline. */
.bar { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 0.6rem; }
.bar + .bar { margin-top: 2px; }
.track { height: 10px; border-radius: 2px; background: var(--sunk); overflow: hidden; }
.fill { height: 100%; border-radius: 0 4px 4px 0; }
.fill.before { background: var(--before); }
.fill.after { background: var(--after); }
.bar .v {
  font-family: var(--mono);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
  min-width: 3.4rem;
  text-align: right;
}
.bar .v b { font-weight: 600; color: var(--ink); }
.chart-note { font-size: 0.85rem; color: var(--ink-3); margin-top: 1.25rem; }

/* English beneath a Devanagari line, so the comparison reads without the
   script. Set apart from the transcript it explains rather than beside it. */
.gloss-line,
.out-note {
  display: block;
  font-family: var(--latin);
  font-size: 0.84rem;
  font-style: italic;
  line-height: 1.55;
  color: var(--ink-3);
  margin-top: 0.35rem;
}
.row.stock .gloss-line, .machine .bad .out-note { color: var(--ink-3); font-style: normal; }
.machine .out-note { margin-top: 0.5rem; }

.meter {
  background: var(--sunk);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.9rem;
}
.wave.live { height: 2.75rem; width: 100%; }
.wave.live rect { fill: var(--rule); transition: none; }
.wave.live rect.on { fill: var(--accent); }

.live-note {
  margin-top: 0.7rem;
  padding: 0.7rem 0.85rem;
  background: var(--sunk);
  border-left: 3px solid var(--warn);
  border-radius: var(--radius);
  font-size: 0.86rem;
  color: var(--ink-2);
}
.live-text { word-break: break-word; overflow-wrap: anywhere; }
