/* ============================================================
   ARCHIVE — Neo-Archival, dual-mode.
   IBM Plex Sans (body) · IBM Plex Mono (metadata) · Plex Serif (display)
   Card-catalog-for-the-network. Tight, deliberate, slightly technical.

   STAGE 1: foundation — tokens, type system, theme switcher,
   masthead, nav, base type rhythm.
   Other components inherit new tokens but await deeper refinement
   in Stages 2–5.
   ============================================================ */

/* ---------- TOKENS · DARK (default) ---------- */
:root,
:root[data-theme="dark"] {
  color-scheme: dark;

  /* Surfaces — neutral charcoal, cooler than warm */
  --bg:           #0e0e0d;
  --surface-1:    #161614;
  --surface-2:    #1d1d1a;
  --surface-3:    #232320;

  /* Lines — hairline borders, no shadow theatre */
  --line:         rgba(232, 228, 216, 0.07);
  --line-strong:  rgba(232, 228, 216, 0.14);
  --line-accent:  rgba(201, 162, 75, 0.32);

  /* Text — cool-warm off-white, faintly cool */
  --text:         #e8e4d8;
  --text-bright:  #f4f1e6;
  --text-dim:     #c2bdae;
  --text-muted:   #9a9587;
  --text-faint:   #6a665c;

  /* Accent — single desaturated brass */
  --accent:       #c9a24b;
  --accent-bright:#e0bd6c;
  --accent-soft:  rgba(201, 162, 75, 0.10);

  --danger:       #c97a6f;
  --danger-soft:  rgba(201, 122, 111, 0.12);

  /* On-accent (button text on accent bg) */
  --on-accent:    #1a1611;

  /* Decoration */
  --selection:    rgba(201, 162, 75, 0.28);
}

/* ---------- TOKENS · LIGHT ---------- */
:root[data-theme="light"] {
  color-scheme: light;

  --bg:           #eceae4;
  --surface-1:    #e3e0d8;
  --surface-2:    #d9d5cb;
  --surface-3:    #d0ccc1;

  --line:         rgba(28, 28, 26, 0.10);
  --line-strong:  rgba(28, 28, 26, 0.20);
  --line-accent:  rgba(148, 111, 45, 0.36);

  --text:         #1c1c1a;
  --text-bright:  #0e0e0d;
  --text-dim:     #44423c;
  --text-muted:   #6b6860;
  --text-faint:   #908d83;

  --accent:       #946f2d;
  --accent-bright:#7c5d24;
  --accent-soft:  rgba(148, 111, 45, 0.08);

  --danger:       #a8483e;
  --danger-soft:  rgba(168, 72, 62, 0.08);

  --on-accent:    #faf7ef;

  --selection:    rgba(148, 111, 45, 0.22);
}

/* ---------- TYPE STACKS · GEOMETRY ---------- */
:root {
  --sans:    "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  --mono:    "IBM Plex Mono", "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  --serif:   "IBM Plex Serif", "Iowan Old Style", Georgia, serif;

  --type-xs:   11.5px;
  --type-sm:   12.5px;
  --type-md:   14.5px;
  --type-base: 16px;
  --type-prose: 17px;
  --type-lg:   19px;
  --type-xl:   23px;
  --type-2xl:  29px;
  --type-3xl:  38px;
  --type-4xl:  52px;

  --line-tight: 1.14;
  --line-snug:  1.36;
  --line-body:  1.6;
  --line-prose: 1.7;
  --line-loose: 1.8;

  --tracking-tight: -0.012em;
  --tracking-normal: 0;
  --tracking-wide:   0.04em;
  --tracking-mono:   0.02em;
  --tracking-label:  0.14em;

  --radius:    2px;
  --radius-md: 4px;
  --radius-lg: 6px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 40px;
  --space-9: 56px;
  --space-10: 80px;

  --ease:     cubic-bezier(0.2, 0, 0, 1);
  --ease-out: cubic-bezier(0, 0, 0.2, 1);
  --duration-fast:   140ms;
  --duration:        200ms;
  --duration-slow:   320ms;
}

/* ---------- RESET ---------- */
* { box-sizing: border-box; }
*:focus { outline: none; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: var(--type-base);
  line-height: var(--line-body);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
  transition: background var(--duration) var(--ease), color var(--duration) var(--ease);
}

/* Subtle paper-grain + soft vignette so the background isn't a flat field.
   The grain SVG is tiny (200x200) and tiled. Opacity is intentionally very
   low so it reads as texture, not pattern. */
body {
  background:
    radial-gradient(120% 80% at 50% -10%, var(--bg-glow), transparent 60%),
    radial-gradient(120% 80% at 50% 110%, var(--bg-shade), transparent 60%),
    var(--bg);
  position: relative;
  isolation: isolate;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: var(--grain-opacity);
  mix-blend-mode: var(--grain-blend);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220' viewBox='0 0 220 220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.6 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  background-size: 220px 220px;
}

:root,
:root[data-theme="dark"] {
  --bg-glow:        rgba(232, 228, 216, 0.025);
  --bg-shade:       rgba(0, 0, 0, 0.45);
  --grain-opacity:  0.06;
  --grain-blend:    overlay;
}

:root[data-theme="light"] {
  --bg-glow:        rgba(255, 252, 240, 0.55);
  --bg-shade:       rgba(28, 28, 26, 0.06);
  --grain-opacity:  0.085;
  --grain-blend:    multiply;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: transparent; border: 0; padding: 0; }
button:disabled { cursor: not-allowed; opacity: 0.50; }
[hidden] { display: none !important; }

a {
  color: var(--text-bright);
  text-decoration: none;
  border-bottom: 1px solid var(--line-strong);
  transition: color var(--duration-fast) var(--ease), border-color var(--duration-fast) var(--ease);
}
a:hover { color: var(--accent-bright); border-bottom-color: var(--accent); }

::selection { background: var(--selection); color: var(--text-bright); }

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

/* ---------- ACCESSIBILITY ---------- */

.skip-link {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translate(-50%, -120%);
  padding: 8px 14px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--accent-bright);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: 0.06em;
  z-index: 100;
  transition: transform var(--duration) var(--ease);
}

.skip-link:focus,
.skip-link:focus-visible {
  transform: translate(-50%, 12px);
  outline: none;
  border-bottom: 1px solid var(--accent);
}

/* ---------- MASTHEAD ---------- */

.masthead {
  border-bottom: 1px solid var(--line);
  padding: 18px 32px 0;
}

.masthead-right {
  display: inline-flex;
  align-items: center;
  gap: 14px;
}

.masthead-edition {
  color: var(--text-faint);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  white-space: nowrap;
}

.masthead-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 18px;
  flex-wrap: wrap;
}

.masthead-brand {
  display: inline-flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  font-family: var(--mono);
  font-size: var(--type-sm);
  letter-spacing: var(--tracking-mono);
}

.masthead-mark {
  color: var(--accent);
  font-family: var(--sans);
  font-size: var(--type-md);
  line-height: 1;
  transform: translateY(1px);
}

.masthead-title {
  color: var(--text-bright);
  font-family: var(--sans);
  font-size: var(--type-md);
  font-weight: 500;
  letter-spacing: var(--tracking-tight);
}

.masthead-divider {
  color: var(--text-faint);
}

.masthead-subtitle {
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--type-sm);
  font-style: italic;
  letter-spacing: var(--tracking-mono);
}

/* Theme toggle — minimal mono switch */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: var(--tracking-mono);
  text-transform: lowercase;
  transition: color var(--duration-fast) var(--ease),
              border-color var(--duration-fast) var(--ease);
}

.theme-toggle:hover {
  color: var(--text-bright);
  border-color: var(--line-strong);
}

.theme-toggle-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 var(--accent-soft);
  transition: background var(--duration-fast) var(--ease);
}

/* ---------- PRIMARY NAV ---------- */

.library-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  margin: 0 -32px;
}

.nav-link {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  padding: 12px 18px;
  border: 0;
  border-right: 1px solid var(--line);
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--type-sm);
  font-weight: 400;
  letter-spacing: var(--tracking-mono);
  text-transform: lowercase;
  transition: color var(--duration-fast) var(--ease),
              background var(--duration-fast) var(--ease);
}

.nav-link:hover {
  color: var(--text-bright);
  background: var(--surface-1);
  border-bottom-color: transparent;
}

.nav-link.is-active {
  color: var(--text-bright);
  background: var(--surface-1);
  border-bottom-color: transparent;
}

.nav-link.is-active .nav-key {
  color: var(--accent);
}

.nav-key {
  color: var(--text-faint);
  font-family: var(--mono);
  font-size: var(--type-xs);
  font-weight: 500;
  letter-spacing: var(--tracking-mono);
  transition: color var(--duration-fast) var(--ease);
}

/* legacy rule element (kept hidden — replaced by border system) */
.rule { display: none; }

/* ---------- MAIN ---------- */

.vellum {
  max-width: 880px;
  margin: 0 auto;
  padding: 56px 32px 140px;
}

.page { animation: fade-in var(--duration-slow) var(--ease) both; }

@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* End-of-page mark — quiet "finis" ornament that closes each page,
   borrowed from old book conventions (the diamond ornament). */
.vellum-foot {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin: 80px 0 0;
  color: var(--text-faint);
  font-family: var(--serif);
  font-style: italic;
  font-size: var(--type-xs);
  letter-spacing: 0.18em;
  opacity: 0.65;
}

.vellum-foot-mark {
  color: var(--accent);
  opacity: 0.5;
  font-size: 11px;
  font-style: normal;
}

.vellum-foot-text {
  font-variant: small-caps;
  font-style: normal;
}

/* Respect reduced-motion preference */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- TYPE PRIMITIVES ---------- */

.page-eyebrow {
  display: inline-block;
  margin: 0 0 14px;
  color: var(--accent);
  font-family: var(--mono);
  font-size: var(--type-xs);
  font-weight: 500;
  letter-spacing: var(--tracking-mono);
  text-transform: lowercase;
}

.page-title {
  margin: 0;
  color: var(--text-bright);
  font-family: var(--sans);
  font-size: var(--type-3xl);
  font-weight: 500;
  letter-spacing: var(--tracking-tight);
  line-height: var(--line-tight);
}

.page-prose {
  margin: 18px 0 0;
  max-width: 60ch;
  color: var(--text-dim);
  font-family: var(--serif);
  font-size: var(--type-prose);
  font-weight: 400;
  letter-spacing: var(--tracking-normal);
  line-height: var(--line-prose);
}

.page-header {
  margin: 0 0 48px;
}

.page-count {
  margin: 0 0 24px;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: var(--tracking-mono);
  text-transform: lowercase;
}

.page-count span { color: var(--accent); }

.back-link {
  display: inline-block;
  margin-bottom: 18px;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: var(--tracking-mono);
  text-transform: lowercase;
  border: 0;
}

.back-link:hover { color: var(--accent-bright); border: 0; }

/* ---------- HOME ---------- */

.hero { padding: 8px 0 40px; }

/* ============================================================
   HALL HERO — a salutation, set as the opening line of a letter.
   The greeting line now hosts a drop-cap "W" in serif brass.
   The recipient (Chris / Princess Ananya) stays in mono so the
   personal name still reads as a hand-set tag.
   ============================================================ */
.hero-greeting {
  margin: 0 0 22px;
  color: var(--text-dim);
  font-family: var(--serif);
  font-style: italic;
  font-size: var(--type-prose);
  line-height: var(--line-prose);
  letter-spacing: 0;
  text-transform: none;
}

.hero-greeting::first-letter {
  font-family: var(--serif);
  font-style: normal;
  font-weight: 500;
  font-size: 3.6em;
  line-height: 0.82;
  float: left;
  color: var(--accent);
  margin: 6px 10px -4px 0;
  font-feature-settings: "lnum";
}

.hero-greeting span {
  display: inline;
  color: var(--text-bright);
  font-family: var(--mono);
  font-style: normal;
  font-size: 0.82em;
  letter-spacing: var(--tracking-mono);
  margin-left: 2px;
  padding: 1px 6px;
  background: var(--accent-soft);
  border-radius: var(--radius);
}

.hero-title {
  margin: 0;
  color: var(--text-bright);
  font-family: var(--sans);
  font-size: var(--type-4xl);
  font-weight: 500;
  letter-spacing: var(--tracking-tight);
  line-height: var(--line-tight);
}

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

.hero-prose {
  margin: 20px 0 0;
  max-width: 60ch;
  color: var(--text-dim);
  font-family: var(--serif);
  font-size: var(--type-prose);
  line-height: var(--line-prose);
}

/* ============================================================
   HALL RULE — engraved-brass ornament between the hero and
   the stacks. Inline SVG (.hall-rule > svg) inherits brass
   from `color`, with the line + dots dimmed and a centred
   diamond drawn at full saturation.
   ============================================================ */
.hall-rule {
  margin: 24px auto 36px;
  max-width: 260px;
  color: var(--accent);
  display: block;
}

.hall-rule svg {
  display: block;
  width: 100%;
  height: auto;
}

/* SHELVES — record-list aesthetic, refined.
   Each shelf is a horizontal slip in a bound register.
   Hover slides a brass margin-bar in from the bottom-left
   instead of flooding the background. */

.stacks {
  margin: 0 0 56px;
  padding: 4px 0;
  border-top: 1px solid var(--line-strong);
  border-bottom: 1px solid var(--line-strong);
  box-shadow: inset 0 1px 0 var(--surface-2),
              inset 0 -1px 0 var(--surface-2);
}

.shelves {
  list-style: none;
  margin: 0;
  padding: 0;
}

.shelf-card {
  position: relative;
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 20px;
  padding: 24px 16px;
  border-bottom: 1px solid var(--line);
  text-decoration: none;
  color: inherit;
  overflow: hidden;
  transition: color var(--duration-fast) var(--ease);
}

.shelf-card:last-child { border-bottom: 0; }

/* Brass margin-bar that slides in from the bottom-left on hover.
   Subtler than the old accent-soft flood — feels like the shelf
   gets a brief brass tab in the margin. */
.shelf-card::before {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  width: 3px;
  height: 0;
  background: var(--accent);
  transition: height var(--duration) var(--ease);
}

.shelf-card:hover { color: var(--text-bright); }
.shelf-card:hover::before { height: 100%; }
.shelf-card:focus-visible {
  outline: none;
  background: var(--accent-soft);
}

.shelf-numeral {
  font-family: var(--mono);
  font-size: var(--type-xs);
  font-weight: 500;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  text-transform: uppercase;
  padding-left: 6px;
  font-feature-settings: "tnum";
  transition: color var(--duration-fast) var(--ease);
}

.shelf-card:hover .shelf-numeral { color: var(--accent); }

.shelf-text { min-width: 0; }

.shelf-card::after {
  content: "→";
  color: var(--text-faint);
  font-size: var(--type-md);
  opacity: 0;
  transform: translateX(-6px);
  transition: opacity var(--duration-fast) var(--ease),
              transform var(--duration-fast) var(--ease),
              color var(--duration-fast) var(--ease);
}

.shelf-card:hover::after {
  opacity: 1;
  transform: translateX(0);
  color: var(--accent);
}

.shelf-name {
  margin: 0;
  color: var(--text-bright);
  font-family: var(--sans);
  font-size: var(--type-xl);
  font-weight: 500;
  letter-spacing: var(--tracking-tight);
  line-height: var(--line-snug);
}

.shelf-meta {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: var(--tracking-mono);
  text-transform: lowercase;
}

.shelf-count {
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: var(--tracking-mono);
  text-transform: lowercase;
  white-space: nowrap;
  padding-right: 6px;
}

.shelf-count strong {
  color: var(--accent);
  font-weight: 500;
  margin-right: 6px;
  font-feature-settings: "tnum", "lnum";
}

.empty-shelves {
  position: relative;
  margin: 56px auto;
  max-width: 48ch;
  padding: 40px 32px 36px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  color: var(--text-dim);
  font-family: var(--serif);
  font-style: italic;
  font-size: var(--type-prose);
  line-height: var(--line-prose);
  text-align: center;
}

.empty-shelves::before {
  content: "◇";
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  padding: 0 12px;
  background: var(--bg);
  color: var(--accent);
  font-style: normal;
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1;
}

.empty-shelves a { color: var(--accent); border-bottom-color: var(--accent-soft); }

/* ============================================================
   HALL QUOTE — pulled from a rotating pool. Italic serif body
   with a thin brass margin rule; attribution in mono small caps
   on its own line. The quote rotates per render — see
   pickHallQuote() in script.js.
   ============================================================ */
.hall-quote {
  display: block;
  margin: 72px 0 0;
  max-width: 56ch;
  padding-left: 20px;
  border-left: 2px solid var(--line-accent);
}

.hall-quote-body {
  margin: 0;
  color: var(--text-muted);
  font-family: var(--serif);
  font-style: italic;
  font-size: var(--type-prose);
  line-height: var(--line-prose);
}

.hall-quote-attribution {
  margin: 6px 0 0;
  color: var(--text-faint);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: var(--tracking-label);
  text-transform: lowercase;
}

/* ---------- CARD SURFACE (was .parchment) ----------
   The "Inscribe" form lives on this surface. Styled as an
   intake card with a hairline frame and a subtle filed-index
   header — not a heavy "parchment paper" pretend.
*/

.parchment {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 56px 36px 32px;
  background:
    linear-gradient(180deg, var(--surface-2) 0, var(--surface-1) 44px),
    var(--surface-1);
  color: var(--text);
}

.parchment::before {
  content: "INTAKE · NEW ENTRY";
  position: absolute;
  top: 18px;
  left: 36px;
  color: var(--text-faint);
  font-family: var(--mono);
  font-size: var(--type-xs);
  font-weight: 500;
  letter-spacing: 0.18em;
}

.parchment::after {
  content: "";
  position: absolute;
  top: 44px;
  left: 36px;
  right: 36px;
  height: 1px;
  background: var(--line);
}

/* ---------- FORM ---------- */

.inscribe-form { max-width: 720px; margin: 0; }

.inscribe-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 26px 28px;
}

.field { display: grid; gap: 8px; }
.field-title, .field-url, .field-notes { grid-column: 1 / -1; }

.field-label {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--type-xs);
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.field-label::before {
  content: "—";
  color: var(--accent);
  opacity: 0.5;
}

.field-label em {
  color: var(--text-faint);
  font-style: normal;
  text-transform: none;
  letter-spacing: 0.04em;
  margin-left: 2px;
  font-weight: 400;
}

.field input,
.field textarea {
  width: 100%;
  padding: 12px 14px;
  border: 0;
  border-bottom: 1px solid var(--line-strong);
  border-radius: 0;
  background: transparent;
  color: var(--text-bright);
  font-family: var(--sans);
  font-size: var(--type-prose);
  line-height: var(--line-snug);
  transition: border-color var(--duration-fast) var(--ease),
              background var(--duration-fast) var(--ease),
              padding var(--duration-fast) var(--ease);
}

.field textarea {
  min-height: 120px;
  resize: vertical;
  line-height: var(--line-body);
  font-family: var(--serif);
}

.field input::placeholder,
.field textarea::placeholder {
  color: var(--text-faint);
  font-style: italic;
}

.field input:hover,
.field textarea:hover {
  border-bottom-color: var(--text-faint);
  background: var(--accent-soft);
}

.field input:focus,
.field textarea:focus {
  outline: none;
  border-bottom-color: var(--accent);
  border-bottom-width: 2px;
  padding-bottom: 11px;
  background: var(--accent-soft);
}

.error-message {
  min-height: 18px;
  margin: 24px 0 0;
  color: var(--danger);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: var(--tracking-mono);
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 32px;
  padding-top: 20px;
  border-top: 1px dashed var(--line);
}

/* ---------- BUTTONS ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 9px 16px;
  background: transparent;
  color: var(--text);
  font-family: var(--mono);
  font-size: var(--type-sm);
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-decoration: none;
  border-bottom: 1px solid var(--line-strong);
  transition: border-color var(--duration-fast) var(--ease),
              color var(--duration-fast) var(--ease),
              background var(--duration-fast) var(--ease),
              transform 80ms var(--ease),
              box-shadow var(--duration-fast) var(--ease);
}

.btn:hover {
  border-color: var(--accent);
  color: var(--accent-bright);
  background: var(--accent-soft);
}

.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  box-shadow: 0 1px 0 0 rgba(0, 0, 0, 0.12);
}

.btn-primary:hover {
  background: var(--accent-bright);
  border-color: var(--accent-bright);
  color: var(--on-accent);
  box-shadow: 0 2px 0 0 rgba(0, 0, 0, 0.18);
}

.btn-primary::after {
  content: "→";
  color: var(--on-accent);
  font-family: var(--sans);
  font-size: 1em;
  opacity: 0.7;
  transition: transform var(--duration-fast) var(--ease), opacity var(--duration-fast) var(--ease);
}

.btn-primary:hover::after {
  transform: translateX(3px);
  opacity: 1;
}

.btn-sm {
  padding: 5px 10px;
  font-size: var(--type-xs);
  letter-spacing: 0.05em;
}

.btn-ghost { color: var(--text-muted); border-color: var(--line); }
.btn-ghost:hover { color: var(--accent-bright); border-color: var(--line-accent); background: transparent; }

/* ---------- SHELF PAGE — folio list ---------- */

.shelf-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin: 0 0 32px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

.shelf-search {
  flex: 1;
  min-width: 240px;
  position: relative;
}

.shelf-search::before {
  content: "⌕";
  position: absolute;
  top: 50%;
  left: 12px;
  transform: translateY(-52%);
  color: var(--text-faint);
  font-family: var(--sans);
  font-size: 16px;
  pointer-events: none;
}

.shelf-search input {
  width: 100%;
  padding: 10px 14px 10px 36px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-1);
  color: var(--text-bright);
  font-family: var(--sans);
  font-size: var(--type-md);
  transition: border-color var(--duration-fast) var(--ease),
              background var(--duration-fast) var(--ease);
}

.shelf-search input::placeholder {
  color: var(--text-faint);
  font-style: italic;
}

.shelf-search input:hover { border-color: var(--line-strong); }

.shelf-search input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.shelf-bulk, .bulk-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.bulk-actions {
  padding: 4px 10px;
  border-left: 1px solid var(--line-strong);
}

.bulk-actions span {
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: 0.04em;
  text-transform: lowercase;
  padding-right: 4px;
  font-feature-settings: "tnum";
}

.folio-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--line);
  counter-reset: folio;
}

.folio-item {
  position: relative;
  display: grid;
  gap: 10px;
  padding: 24px 0 24px 56px;
  border-bottom: 1px solid var(--line);
  counter-increment: folio;
  transition: background var(--duration-fast) var(--ease),
              padding var(--duration-fast) var(--ease);
}

.folio-item::before {
  content: counter(folio, decimal-leading-zero);
  position: absolute;
  top: 26px;
  left: 0;
  width: 44px;
  color: var(--text-faint);
  font-family: var(--mono);
  font-size: var(--type-xs);
  font-weight: 500;
  letter-spacing: 0.08em;
  font-feature-settings: "tnum", "lnum";
  transition: color var(--duration-fast) var(--ease);
}

.folio-item:hover {
  background: var(--accent-soft);
  padding-left: 60px;
}

.folio-item:hover::before {
  color: var(--accent);
  left: 4px;
}

.folio-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 12px;
}

.folio-title {
  color: var(--text-bright);
  font-family: var(--sans);
  font-size: var(--type-xl);
  font-weight: 500;
  letter-spacing: var(--tracking-tight);
  line-height: var(--line-snug);
  text-decoration: none;
  border: 0;
}

.folio-title:hover { color: var(--accent-bright); border: 0; }

.folio-item.is-favorite .folio-title::before {
  content: "★  ";
  color: var(--accent);
  font-size: 0.62em;
  vertical-align: 0.22em;
}

.folio-meta {
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: 0.04em;
  text-transform: lowercase;
  font-feature-settings: "tnum";
}

.folio-meta span + span::before {
  content: "  ⁄  ";
  color: var(--text-faint);
  margin: 0 2px;
  opacity: 0.7;
}

.folio-tags {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.folio-tags span {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px 2px 6px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: var(--type-xs);
  font-weight: 500;
  letter-spacing: 0.02em;
}

.folio-tags span::before {
  content: "#";
  color: var(--accent);
  margin-right: 3px;
  opacity: 0.7;
}

.folio-notes {
  margin-top: 12px;
  padding-left: 16px;
  border-left: 2px solid var(--line-strong);
  color: var(--text-dim);
  font-family: var(--serif);
  font-size: var(--type-prose);
  line-height: var(--line-prose);
  max-width: 64ch;
}

.folio-notes p { margin: 0 0 6px; }
.folio-notes p:last-child { margin: 0; }
.folio-notes ul { margin: 0 0 6px 18px; padding: 0; }
.folio-notes code {
  padding: 1px 5px;
  background: var(--surface-2);
  color: var(--text-bright);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 0.88em;
}

.folio-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  margin-top: 14px;
  margin-left: -10px;
  padding-top: 8px;
  border-top: 1px dashed var(--line);
}

.folio-action {
  position: relative;
  padding: 5px 10px;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--type-xs);
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: lowercase;
  border-radius: var(--radius);
  transition: color var(--duration-fast) var(--ease),
              background var(--duration-fast) var(--ease);
}

.folio-action:hover { color: var(--accent-bright); background: var(--accent-soft); }
.folio-action.danger:hover { color: var(--danger); background: var(--danger-soft); }

.folio-action.favorite[aria-pressed="true"] {
  color: var(--accent);
}

.folio-action.favorite[aria-pressed="true"]::before {
  content: "★ ";
  margin-right: 2px;
}

.folio-action[disabled] { color: var(--text-faint); }

.folio-select {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0 8px 0 0;
  color: var(--text-faint);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: var(--tracking-mono);
  text-transform: lowercase;
}

.folio-select input { accent-color: var(--accent); }

/* Folio summary */
.folio-summary {
  margin-top: 14px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-left: 2px solid var(--accent);
  background: var(--surface-1);
  border-radius: 0 var(--radius) var(--radius) 0;
}

.folio-summary-eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: var(--tracking-mono);
  text-transform: lowercase;
  font-weight: 500;
}

.folio-summary-about {
  margin: 0 0 14px;
  color: var(--text);
  font-family: var(--serif);
  font-size: var(--type-prose);
  font-style: italic;
  line-height: var(--line-prose);
  max-width: 64ch;
}

.folio-summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px;
}

.folio-summary-block h4 {
  margin: 0 0 8px;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--type-xs);
  font-weight: 500;
  letter-spacing: var(--tracking-mono);
  text-transform: lowercase;
}

.folio-summary-block ol,
.folio-summary-block ul {
  margin: 0;
  padding: 0 0 0 20px;
  display: grid;
  gap: 4px;
}

.folio-summary-block li {
  color: var(--text-dim);
  font-family: var(--sans);
  font-size: var(--type-md);
  line-height: var(--line-snug);
  overflow-wrap: anywhere;
}

.folio-summary-block ol li::marker {
  color: var(--accent);
  font-family: var(--mono);
  font-size: 0.85em;
}

.folio-summary-meta {
  margin: 12px 0 0;
  color: var(--text-faint);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: var(--tracking-mono);
}

/* ---------- SIDEBAR (Plates / Stories) ---------- */

.page-with-sidebar {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  gap: 32px;
  align-items: start;
}

.page-sidebar {
  position: sticky;
  top: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 16px;
  border-right: 1px solid var(--line);
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-section-actions {
  margin-top: 4px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
}

.sidebar-tab {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 0;
  border-left: 2px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--type-sm);
  font-weight: 500;
  letter-spacing: 0.02em;
  text-align: left;
  cursor: pointer;
  transition: color var(--duration-fast) var(--ease),
              background var(--duration-fast) var(--ease),
              border-color var(--duration-fast) var(--ease),
              padding-left var(--duration-fast) var(--ease);
}

.sidebar-tab:hover {
  color: var(--text-bright);
  background: var(--surface-1);
  padding-left: 12px;
}

.sidebar-tab.is-active {
  color: var(--text-bright);
  background: var(--accent-soft);
  border-left-color: var(--accent);
}

.sidebar-tab.is-active .sidebar-tab-mark { color: var(--accent); }
.sidebar-tab.is-active .sidebar-tab-count {
  background: rgba(212, 165, 116, 0.18);
  color: var(--accent-bright);
}

.sidebar-tab-mark {
  color: var(--text-faint);
  font-size: var(--type-xs);
  line-height: 1;
}

.sidebar-tab-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-tab-count {
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  font-feature-settings: "tnum", "lnum";
}

.sidebar-tab.is-upload {
  color: var(--accent);
}

.sidebar-tab.is-upload .sidebar-tab-mark { color: var(--accent); }

.sidebar-tab.is-upload:hover {
  color: var(--accent-bright);
}

.sidebar-tab.is-upload.is-active {
  background: var(--accent-soft);
  border-left-color: var(--accent);
}

/* ---------- THREAD HEADER (above the items) ---------- */

.thread-header {
  margin: 0 0 22px;
  padding-bottom: 16px;
  border-bottom: 1px dashed var(--line);
}

.thread-eyebrow {
  margin: 0 0 6px;
  color: var(--text-faint);
  font-family: var(--mono);
  font-size: var(--type-xs);
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.thread-title {
  margin: 0;
  color: var(--text-bright);
  font-family: var(--sans);
  font-size: var(--type-2xl);
  font-weight: 500;
  letter-spacing: var(--tracking-tight);
  line-height: var(--line-tight);
}

/* ---------- THREAD / FLOW VISUAL on the items ---------- */

/* Recordings: vertical thread — left rail + node mark next to each item. */
.recording-list {
  position: relative;
  margin: 0;
  padding: 0 0 0 28px;
  list-style: none;
}

.recording-list::before {
  content: "";
  position: absolute;
  top: 8px;
  bottom: 8px;
  left: 9px;
  width: 1px;
  background: linear-gradient(180deg, transparent 0, var(--line-strong) 12%, var(--line-strong) 88%, transparent 100%);
}

.recording-list .recording-item {
  position: relative;
}

.recording-list .recording-item::before {
  content: "◆";
  position: absolute;
  top: 24px;
  left: -27px;
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  color: var(--accent);
  font-size: 10px;
  background: var(--bg);
  border-radius: 50%;
  z-index: 1;
}

.recording-list .recording-item:hover::before {
  color: var(--accent-bright);
}

/* Plates: keep grid but add a top rule + node marker on each card so
   the page still reads as a connected category, not as detached tiles. */
.plate-grid {
  position: relative;
}

.plate-grid .plate-card {
  position: relative;
}

/* ---------- LIBRARY TOOLBAR ---------- */

.library-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px 18px;
  margin: 0 0 22px;
}

.library-sort,
.library-filter {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.library-density { margin-left: auto; }

.library-sort-label {
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.library-sort-select {
  appearance: none;
  -webkit-appearance: none;
  padding: 7px 30px 7px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background-color: var(--surface-1);
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position:
    calc(100% - 14px) calc(50% - 2px),
    calc(100% - 9px) calc(50% - 2px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  color: var(--text-bright);
  font-family: var(--sans);
  font-size: var(--type-sm);
  outline: none;
  cursor: pointer;
  transition: border-color var(--duration-fast) var(--ease),
              background-color var(--duration-fast) var(--ease);
}

.library-sort-select:hover {
  border-color: var(--text-faint);
}

.library-sort-select:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  outline: none;
}

.library-density {
  display: inline-flex;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  overflow: hidden;
}

.density-button {
  padding: 6px 12px;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--type-xs);
  font-weight: 500;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: color var(--duration-fast) var(--ease),
              background var(--duration-fast) var(--ease);
}

.density-button + .density-button {
  border-left: 1px solid var(--line);
}

.density-button:hover { color: var(--text-bright); }

.density-button.is-active {
  color: var(--accent-bright);
  background: var(--accent-soft);
}

/* ---------- CATEGORY CHIP (on plate / recording cards) ---------- */

.media-category {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: var(--type-xs);
  font-weight: 500;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: color var(--duration-fast) var(--ease),
              border-color var(--duration-fast) var(--ease),
              background var(--duration-fast) var(--ease);
}

.media-category::before {
  content: "◆";
  color: var(--accent);
  opacity: 0.7;
  font-size: 0.78em;
}

.media-category:hover {
  color: var(--accent-bright);
  border-color: var(--accent-line);
}

.media-category.is-empty {
  color: var(--text-faint);
  background: transparent;
  border-style: dashed;
}

.media-category.is-empty::before { content: ""; }

.media-category.is-empty:hover {
  color: var(--accent);
  border-color: var(--accent-line);
  border-style: dashed;
}

/* Plate card: tuck the category chip just under the thumbnail */
.plate-card .media-category {
  align-self: flex-start;
  margin: 2px 0 0;
}

/* Recording: place chip inline next to the title */
.recording-title-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

/* ---------- DENSITY VARIANTS ---------- */

.plate-grid[data-density="compact"] {
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 14px;
}

.plate-grid[data-density="compact"] .plate-caption {
  font-size: var(--type-sm);
}

/* ---------- EMPTY-STATE ACTION BUTTON ---------- */

.empty-action {
  border: 0;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-style: italic;
  border-bottom: 1px solid var(--accent-line);
  cursor: pointer;
  padding: 0;
  transition: color var(--duration-fast) var(--ease), border-color var(--duration-fast) var(--ease);
}

.empty-action:hover {
  color: var(--text-bright);
  border-bottom-color: var(--accent);
}

/* ---------- UPLOAD ZONE (plates + recordings) ---------- */

.upload-zone {
  position: relative;
  margin: 0 0 32px;
  padding: 30px 28px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface-1);
  text-align: center;
  transition: border-color var(--duration) var(--ease),
              background var(--duration) var(--ease);
}

.upload-zone.is-dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.upload-zone-label {
  margin: 0;
  color: var(--text-dim);
  font-family: var(--serif);
  font-size: var(--type-prose);
  line-height: var(--line-snug);
}

.upload-zone-pick {
  color: var(--accent-bright);
  font-family: var(--serif);
  font-size: var(--type-prose);
  border-bottom: 1px solid var(--accent-line);
  padding: 0 2px;
  background: transparent;
  border-radius: 0;
  transition: color var(--duration-fast) var(--ease), border-color var(--duration-fast) var(--ease);
}

.upload-zone-pick:hover {
  color: var(--text-bright);
  border-bottom-color: var(--accent);
}

.upload-zone-hint {
  margin: 10px 0 0;
  color: var(--text-faint);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: 0.06em;
  text-transform: lowercase;
}

.upload-progress {
  margin: 14px 0 0;
  color: var(--accent);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: 0.06em;
  text-transform: lowercase;
}

.upload-error {
  margin: 14px 0 0;
  color: var(--danger);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: 0.04em;
}

/* ---------- PLATES (Math Help — Chris) ---------- */

.plate-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 22px;
  margin: 8px 0 0;
}

.plate-card {
  margin: 0;
  display: grid;
  gap: 8px;
}

.plate-thumb {
  position: relative;
  aspect-ratio: 3 / 4;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-1);
  transition: border-color var(--duration-fast) var(--ease), transform var(--duration-fast) var(--ease);
}

.plate-card:hover .plate-thumb {
  border-color: var(--line-accent);
  transform: translateY(-2px);
}

.plate-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.plate-number {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 1;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(8, 8, 7, 0.72);
  backdrop-filter: blur(6px);
  color: var(--accent-bright);
  font-family: var(--mono);
  font-size: var(--type-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  font-feature-settings: "tnum";
}

.plate-questions-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 1;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font-family: var(--mono);
  font-size: var(--type-xs);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: lowercase;
  font-feature-settings: "tnum";
}

.plate-caption {
  margin: 0;
  padding: 0 2px;
  color: var(--text-dim);
  font-family: var(--serif);
  font-style: italic;
  font-size: var(--type-md);
  line-height: var(--line-snug);
}

.plate-caption em {
  color: var(--text-faint);
  font-style: italic;
}

.plate-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  margin-left: -8px;
}

/* ---------- RECORDINGS (Stories — Ananya) ---------- */

.recording-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 18px;
}

.recording-item {
  position: relative;
  display: grid;
  gap: 12px;
  padding: 20px 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-1);
  transition: border-color var(--duration-fast) var(--ease);
}

.recording-item:hover { border-color: var(--line-accent); }

.recording-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: baseline;
  gap: 16px;
}

.recording-number {
  color: var(--accent);
  font-family: var(--mono);
  font-size: var(--type-xs);
  font-weight: 500;
  letter-spacing: 0.06em;
  font-feature-settings: "tnum", "lnum";
  padding-top: 4px;
}

.recording-title {
  margin: 0;
  color: var(--text-bright);
  font-family: var(--serif);
  font-size: var(--type-xl);
  font-weight: 500;
  letter-spacing: var(--tracking-tight);
  line-height: var(--line-snug);
}

.recording-meta {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: 0.04em;
  text-transform: lowercase;
  font-feature-settings: "tnum";
}

/* Phase 23 — native audio is fully hidden; .tape-player below replaces it. */
.recording-audio {
  display: none;
}

.recording-notes {
  margin: 0;
  padding-left: 14px;
  border-left: 2px solid var(--line-strong);
  color: var(--text-dim);
  font-family: var(--serif);
  font-style: italic;
  font-size: var(--type-md);
  line-height: var(--line-body);
}

.recording-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  margin-left: -8px;
  padding-top: 6px;
  border-top: 1px dashed var(--line);
}

@media (max-width: 520px) {
  .plate-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; }
  .recording-item { padding: 16px 16px; }
  .recording-title { font-size: var(--type-lg); }
}

/* ============================================================
   PAGE-PROSE ASIDE — the secondary line below page-prose, used
   to introduce a feature without crowding the hero hierarchy.
   ============================================================ */
.page-prose-aside {
  margin-top: 6px;
  color: var(--text-muted);
  font-family: var(--serif);
  font-style: italic;
  font-size: var(--type-md);
  line-height: var(--line-prose);
}

.page-prose-aside em {
  font-style: normal;
  color: var(--accent);
  font-family: var(--mono);
  font-size: 0.9em;
  font-weight: 500;
  padding: 0 2px;
}

/* ============================================================
   UPLOAD CATEGORY STRIP — chip selector sitting above the drop
   zone. Pre-selects the category the next cassette will be
   filed under, so curators can drop several files in a row
   without retouching the category each time.
   ============================================================ */
.upload-category-strip {
  display: grid;
  gap: 8px;
  padding: 14px 18px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.upload-category-label {
  margin: 0;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
}

.upload-category-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.upload-category-chip {
  padding: 5px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: transparent;
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: 0.04em;
  text-transform: lowercase;
  cursor: pointer;
  transition: color var(--duration-fast) var(--ease),
              border-color var(--duration-fast) var(--ease),
              background var(--duration-fast) var(--ease);
}

.upload-category-chip:hover {
  color: var(--accent-bright);
  border-color: var(--line-accent);
}

.upload-category-chip.is-active {
  color: var(--surface-1);
  background: var(--accent);
  border-color: var(--accent);
}

:root[data-theme="light"] .upload-category-chip.is-active {
  color: var(--text-bright);
  background: var(--accent-soft);
  border-color: var(--accent);
}

/* ============================================================
   MARGINALIA — the rating dial + review/question feed beneath
   each cassette. Reads as a margin in an old book: italic
   serif body, a thin rule above, the rating displayed as a
   row of inked dots filled up to the current score.
   ============================================================ */
.marginalia-strip {
  display: grid;
  gap: 12px;
  padding: 16px 0 0;
  margin-top: 4px;
  border-top: 1px dashed var(--line-strong);
}

.marginalia-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px 18px;
  justify-content: space-between;
}

.marginalia-eyebrow {
  margin: 0;
  color: var(--accent);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
}

/* Rating dial — ten dots, filled up to the current rating, with
   the active one quietly emphasised. */
.rating-dial {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 10px;
}

.rating-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  font-feature-settings: "tnum";
  cursor: pointer;
  transition: color var(--duration-fast) var(--ease),
              background var(--duration-fast) var(--ease),
              border-color var(--duration-fast) var(--ease),
              transform var(--duration-fast) var(--ease);
}

.rating-dot:hover {
  color: var(--accent-bright);
  border-color: var(--line-accent);
}

.rating-dot.is-filled {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--surface-1);
}

:root[data-theme="light"] .rating-dot.is-filled {
  color: #fff;
}

.rating-dot.is-peak {
  transform: scale(1.12);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.rating-caption {
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: 0.04em;
  text-transform: lowercase;
}

.rating-caption-empty {
  font-style: italic;
}

/* Marginalia feed — list of entries, italic serif, like
   pencilled-in notes in a margin. */
.marginalia-feed {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 12px;
}

.marginalia-empty {
  margin: 0;
  padding: 4px 0;
  color: var(--text-muted);
  font-family: var(--serif);
  font-style: italic;
  font-size: var(--type-md);
}

.marginalia-entry {
  position: relative;
  display: grid;
  gap: 6px;
  padding: 10px 14px;
  border-left: 2px solid var(--line-accent);
  background: var(--surface-2);
  border-radius: 0 var(--radius) var(--radius) 0;
}

.marginalia-entry[data-kind="question"] {
  border-left-color: var(--accent);
}

.marginalia-entry-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: 0.04em;
}

.marginalia-kind {
  padding: 1px 7px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: var(--tracking-label);
  font-size: 9.5px;
}

.marginalia-kind-question {
  color: var(--accent-bright);
  border-color: var(--line-accent);
}

.marginalia-by {
  color: var(--text-dim);
  text-transform: lowercase;
}

.marginalia-when {
  color: var(--text-muted);
  text-transform: lowercase;
  margin-left: auto;
}

.marginalia-remove {
  width: 20px;
  height: 20px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  transition: color var(--duration-fast) var(--ease);
}

.marginalia-remove:hover {
  color: var(--danger, #c25a5a);
}

.marginalia-body {
  margin: 0;
  color: var(--text-dim);
  font-family: var(--serif);
  font-style: italic;
  font-size: var(--type-md);
  line-height: var(--line-body);
  white-space: pre-wrap;
  word-break: break-word;
}

/* Composer — kind toggle on top, textarea, then post button
   row. Stays visible by default so leaving a note feels light. */
.marginalia-composer {
  display: grid;
  gap: 8px;
  padding: 10px 12px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.marginalia-kind-toggle {
  display: inline-flex;
  gap: 4px;
}

.marginalia-kind-button {
  padding: 4px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: 0.04em;
  text-transform: lowercase;
  cursor: pointer;
  transition: color var(--duration-fast) var(--ease),
              border-color var(--duration-fast) var(--ease),
              background var(--duration-fast) var(--ease);
}

.marginalia-kind-button:hover {
  color: var(--accent-bright);
  border-color: var(--line-accent);
}

.marginalia-kind-button.is-active {
  color: var(--surface-1);
  background: var(--accent);
  border-color: var(--accent);
}

:root[data-theme="light"] .marginalia-kind-button.is-active {
  color: var(--text-bright);
  background: var(--accent-soft);
  border-color: var(--accent);
}

.marginalia-input {
  width: 100%;
  resize: vertical;
  min-height: 56px;
  max-height: 220px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-1);
  color: var(--text-bright);
  font-family: var(--serif);
  font-style: italic;
  font-size: var(--type-md);
  line-height: var(--line-body);
  transition: border-color var(--duration-fast) var(--ease);
}

.marginalia-input:focus-visible {
  outline: none;
  border-color: var(--accent);
}

.marginalia-composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.marginalia-counter {
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: 0.04em;
  font-feature-settings: "tnum";
}

/* ---------- CHRONICLE ----------
   A daybook of events. Left rail of mono event-codes anchors a
   vertical hairline (the timeline). Each row reads like a log entry.
*/

.chronicle-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--line);
  position: relative;
}

.chronicle-entry {
  position: relative;
  display: grid;
  grid-template-columns: 130px 1px minmax(0, 1fr) auto;
  align-items: start;
  gap: 0 22px;
  padding: 16px 0 16px 0;
  border-bottom: 1px solid var(--line);
}

.chronicle-event {
  color: var(--accent);
  font-family: var(--mono);
  font-size: var(--type-xs);
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding-top: 2px;
}

/* The vertical hairline separating the event-code column from the body */
.chronicle-entry::before {
  content: "";
  grid-column: 2;
  grid-row: 1;
  width: 1px;
  height: 100%;
  background: var(--line);
  align-self: stretch;
}

.chronicle-text {
  color: var(--text-dim);
  font-family: var(--serif);
  font-size: var(--type-prose);
  line-height: var(--line-prose);
  grid-column: 3;
}

.chronicle-text em {
  color: var(--text-bright);
  font-style: normal;
  font-weight: 500;
}

.chronicle-time {
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: 0.04em;
  white-space: nowrap;
  font-feature-settings: "tnum";
  padding-top: 2px;
  grid-column: 4;
}

.chronicle-entry:hover { background: var(--accent-soft); }
.chronicle-entry:hover .chronicle-event { color: var(--accent-bright); }

/* ---------- LEDGER ----------
   A bookkeeping aesthetic. Stats sit as tally-cards; the
   ranked list and weekly-usage chart feel like clean entries
   in a register.
*/

.ledger-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin: 0 0 32px;
}

.stat-card {
  position: relative;
  padding: 22px 18px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, var(--surface-2) 0, var(--surface-1) 38px),
    var(--surface-1);
  transition: border-color var(--duration-fast) var(--ease),
              transform 160ms var(--ease);
}

.stat-card::after {
  content: "";
  position: absolute;
  top: 14px;
  right: 14px;
  width: 4px;
  height: 4px;
  background: var(--accent);
  opacity: 0.5;
  border-radius: 50%;
  transition: opacity var(--duration-fast) var(--ease);
}

.stat-card:hover {
  border-color: var(--line-accent);
  transform: translateY(-1px);
}

.stat-card:hover::after { opacity: 1; }

.stat-card span {
  display: block;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--type-xs);
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.stat-card strong {
  display: block;
  margin-top: 10px;
  color: var(--text-bright);
  font-family: var(--sans);
  font-size: 34px;
  font-weight: 500;
  letter-spacing: var(--tracking-tight);
  line-height: 1;
  font-feature-settings: "tnum", "lnum";
}

.ledger-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.ledger-card {
  position: relative;
  padding: 22px 24px 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-1);
}

.ledger-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 24px;
  right: 24px;
  height: 2px;
  background: var(--accent);
  opacity: 0.4;
}

.ledger-title {
  margin: 0 0 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
  color: var(--text-bright);
  font-family: var(--sans);
  font-size: var(--type-md);
  font-weight: 500;
  letter-spacing: 0.02em;
}

.ranked-list { list-style: none; margin: 0; padding: 0; counter-reset: rank; }

.ranked-list li {
  counter-increment: rank;
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 14px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  transition: padding var(--duration-fast) var(--ease);
}

.ranked-list li:last-child { border-bottom: 0; }

.ranked-list li:hover { padding-left: 4px; }

.ranked-list li::before {
  content: counter(rank, decimal-leading-zero);
  color: var(--text-faint);
  font-family: var(--mono);
  font-size: var(--type-xs);
  font-weight: 500;
  letter-spacing: 0.06em;
  font-feature-settings: "tnum", "lnum";
  transition: color var(--duration-fast) var(--ease);
}

.ranked-list li:hover::before { color: var(--accent); }

.ranked-list span {
  color: var(--text);
  font-family: var(--sans);
  font-size: var(--type-md);
  overflow-wrap: anywhere;
  line-height: var(--line-snug);
}

.ranked-list strong {
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--type-xs);
  font-weight: 500;
  letter-spacing: 0.04em;
  font-feature-settings: "tnum";
}

.usage-chart {
  position: relative;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  align-items: end;
  gap: 10px;
  min-height: 180px;
  padding-top: 8px;
}

.usage-chart::after {
  content: "";
  position: absolute;
  bottom: 22px;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--line);
}

.chart-bar {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 6px;
  text-align: center;
}

.chart-bar span {
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--type-xs);
  font-weight: 500;
  letter-spacing: 0.04em;
  font-feature-settings: "tnum";
}

.chart-bar i {
  align-self: end;
  display: block;
  min-height: 4px;
  height: var(--bar-height);
  background: linear-gradient(180deg, var(--accent-bright), var(--accent));
  opacity: 0.85;
  border-radius: 1px 1px 0 0;
  transition: opacity var(--duration-fast) var(--ease);
}

.chart-bar:hover i { opacity: 1; }

.chart-bar em {
  color: var(--text-faint);
  font-family: var(--mono);
  font-style: normal;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-feature-settings: "tnum";
}

/* ---------- CURATOR CHIP ---------- */

.curator-chip {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 5;
  padding: 8px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface-1);
  backdrop-filter: blur(14px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.20);
  transition: border-color var(--duration-fast) var(--ease),
              background var(--duration-fast) var(--ease);
}

.curator-chip:hover {
  border-color: var(--line-accent);
}

.curator-chip {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.curator-chip .curator-label {
  color: var(--accent);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  opacity: 0.85;
}

.curator-chip .curator-name {
  color: var(--text-bright);
  font-family: var(--sans);
  font-size: var(--type-sm);
  font-weight: 500;
  letter-spacing: var(--tracking-tight);
}

.curator-chip .curator-logout {
  margin-left: 4px;
  border: 0;
  background: transparent;
  color: var(--text-faint);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  cursor: pointer;
  padding: 0;
  transition: color var(--duration-fast) var(--ease);
}

.curator-chip .curator-logout:hover {
  color: var(--accent);
}

/* ---------- AUTH GATE ----------
   Full-viewport sign-in screen. Body[data-auth] gates app vs. gate. */

.auth-gate { display: none; }

body[data-auth="pending"] .masthead,
body[data-auth="pending"] main,
body[data-auth="pending"] .curator-chip,
body[data-auth="locked"] .masthead,
body[data-auth="locked"] main,
body[data-auth="locked"] .curator-chip {
  display: none !important;
}

body[data-auth="pending"] .auth-gate,
body[data-auth="locked"] .auth-gate {
  display: flex;
  position: fixed;
  inset: 0;
  z-index: 100;
  align-items: center;
  justify-content: center;
  background: var(--surface-0, #0a0a0a);
  padding: 24px;
}

.auth-card {
  width: min(420px, 100%);
  padding: 36px 32px 28px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface-1);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-eyebrow {
  margin: 0;
  color: var(--accent);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

.auth-title {
  margin: 0;
  font-family: var(--serif, var(--sans));
  font-size: 32px;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--text-bright);
}

.auth-prose {
  margin: 0 0 6px;
  color: var(--text-muted, var(--text-faint));
  font-size: var(--type-sm);
  line-height: 1.55;
}

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.auth-field span {
  color: var(--accent);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  opacity: 0.85;
}

.auth-field input {
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--surface-0, transparent);
  color: var(--text-bright);
  font-family: var(--sans);
  font-size: var(--type-sm);
  outline: none;
  transition: border-color var(--duration-fast) var(--ease);
}

.auth-field input:focus {
  border-color: var(--accent);
}

.auth-submit {
  margin-top: 6px;
  padding: 12px 18px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: var(--accent);
  color: var(--surface-0, #0a0a0a);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  transition: opacity var(--duration-fast) var(--ease);
}

.auth-submit:hover { opacity: 0.85; }
.auth-submit:disabled { opacity: 0.5; cursor: progress; }

.auth-error {
  margin: 0;
  color: #d97777;
  font-family: var(--sans);
  font-size: var(--type-xs, 12px);
}

/* ---------- QUESTION CALENDAR (under each plate card) ---------- */

.question-calendar {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(36px, 1fr));
  gap: 4px;
  margin: 8px 0 4px;
}

.question-tile {
  display: grid;
  place-items: center;
  aspect-ratio: 1 / 1;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface-1);
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: var(--type-xs);
  font-weight: 600;
  font-feature-settings: "tnum", "lnum";
  cursor: pointer;
  transition: border-color var(--duration-fast) var(--ease),
              color var(--duration-fast) var(--ease),
              background var(--duration-fast) var(--ease),
              transform 80ms var(--ease);
}

.question-tile:hover {
  border-color: var(--accent);
  color: var(--accent-bright);
  background: var(--accent-soft);
  transform: translateY(-1px);
}

.question-tile.is-loaded {
  border-color: var(--accent-line);
  color: var(--accent);
}

.question-tile.is-correct {
  background: rgba(124, 197, 118, 0.18);
  border-color: rgba(124, 197, 118, 0.6);
  color: #a3d99e;
}

.question-tile.is-wrong {
  background: rgba(201, 122, 111, 0.16);
  border-color: rgba(201, 122, 111, 0.55);
  color: #d99a92;
}

/* ---------- QUESTION DETAIL MODAL ---------- */

.question-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: rgba(8, 8, 7, 0.78);
  padding: 24px;
  backdrop-filter: blur(8px);
  animation: fade-in 180ms var(--ease) both;
}

.question-dialog {
  display: grid;
  grid-template-rows: auto 1fr;
  width: min(720px, 100%);
  max-height: calc(100vh - 48px);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  background: var(--surface-1);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  overflow: hidden;
  animation: dialog-rise 220ms var(--ease) both;
}

.question-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.question-header-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.question-eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-family: var(--mono);
  font-size: var(--type-xs);
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: lowercase;
}

.question-title {
  margin: 0;
  color: var(--text-bright);
  font-family: var(--sans);
  font-size: var(--type-xl);
  font-weight: 500;
  letter-spacing: var(--tracking-tight);
}

.question-body {
  overflow: auto;
  padding: 20px;
  display: grid;
  gap: 18px;
}

.question-plate-thumb img {
  max-width: 100%;
  max-height: 220px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: block;
  margin: 0 auto;
  opacity: 0.6;
  transition: opacity var(--duration-fast) var(--ease);
}

.question-plate-thumb img:hover { opacity: 1; }

/* Slot: voiceHint / imageHint / solution */

.slot {
  display: grid;
  gap: 8px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-left: 2px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: rgba(212, 165, 116, 0.04);
}

.slot.is-empty {
  border-left-color: var(--line-strong);
  background: transparent;
}

.slot-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.slot-eyebrow {
  margin: 0;
  color: var(--accent);
  font-family: var(--mono);
  font-size: var(--type-xs);
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.slot-meta {
  margin: 0;
  color: var(--text-faint);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: 0.04em;
  font-feature-settings: "tnum";
}

.slot-body {
  display: grid;
  gap: 8px;
}

.slot-image {
  max-width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  display: block;
}

.slot audio {
  width: 100%;
  filter: invert(0.85) hue-rotate(180deg) contrast(0.9);
}

:root[data-theme="light"] .slot audio { filter: none; }

.slot-controls {
  display: flex;
  gap: 2px;
  margin-left: -10px;
}

.slot-upload-btn {
  align-self: start;
  padding: 8px 14px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: 0.06em;
  text-transform: lowercase;
  cursor: pointer;
  transition: color var(--duration-fast) var(--ease),
              border-color var(--duration-fast) var(--ease);
}

.slot-upload-btn:hover {
  color: var(--accent-bright);
  border-color: var(--accent);
}

.slot-reveal {
  padding: 5px 12px;
  background: var(--accent);
  color: var(--on-accent);
  font-family: var(--mono);
  font-size: var(--type-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: lowercase;
  border-radius: var(--radius);
  cursor: pointer;
  border: 0;
  transition: background var(--duration-fast) var(--ease);
}

.slot-reveal:hover { background: var(--accent-bright); }

/* Reveal-slot: when content is hidden, dim & blur it so the user can opt in */
.reveal-slot.is-hidden .slot-body {
  filter: blur(8px);
  opacity: 0.4;
  pointer-events: none;
}

/* Self-assessment + history */

.question-assess {
  margin-top: 6px;
  padding-top: 18px;
  border-top: 1px dashed var(--line);
  text-align: center;
}

.assess-prompt {
  margin: 0 0 12px;
  color: var(--text-muted);
  font-family: var(--serif);
  font-style: italic;
  font-size: var(--type-md);
}

.assess-buttons {
  display: inline-flex;
  gap: 12px;
}

.assess-button {
  min-width: 160px;
  font-size: var(--type-sm);
  padding: 10px 20px;
}

.assess-correct { color: #a3d99e; border-color: rgba(124, 197, 118, 0.45); }
.assess-correct:hover { color: #c4e8c1; border-color: rgba(124, 197, 118, 0.85); background: rgba(124, 197, 118, 0.12); }

.assess-wrong { color: #d99a92; border-color: rgba(201, 122, 111, 0.45); }
.assess-wrong:hover { color: #f0bdb6; border-color: rgba(201, 122, 111, 0.85); background: rgba(201, 122, 111, 0.12); }

.assess-history {
  margin: 14px 0 0;
  color: var(--text-faint);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: 0.04em;
  font-feature-settings: "tnum";
}

/* ---------- FLOWER OVERLAY ---------- */

.flower-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  display: none;
}

.flower-overlay.is-active { display: block; }

.flower {
  position: absolute;
  bottom: -120px;
  width: 120px;
  height: 120px;
  filter: drop-shadow(0 8px 20px rgba(196, 66, 114, 0.35));
  animation: flower-bloom 2400ms var(--ease) both;
  animation-delay: var(--delay, 0ms);
}

.flower svg { width: 100%; height: 100%; }

@keyframes flower-bloom {
  0%   { transform: translate(0, 0) scale(0.2) rotate(0deg); opacity: 0; }
  18%  { transform: translate(var(--drift, 0), -50vh) scale(1.0) rotate(calc(var(--rotate, 0deg) * 0.5)); opacity: 1; }
  60%  { transform: translate(var(--drift, 0), -55vh) scale(1.0) rotate(var(--rotate, 0deg)); opacity: 1; }
  100% { transform: translate(var(--drift, 0), -90vh) scale(0.85) rotate(calc(var(--rotate, 0deg) * 1.4)); opacity: 0; }
}

/* ---------- CASSETTE PLAYER (animates while audio is playing) ---------- */

.cassette-player {
  margin: 0 0 22px;
  display: flex;
  justify-content: center;
}

.cassette-shell {
  position: relative;
  width: min(440px, 100%);
  padding: 18px 22px;
  background: linear-gradient(180deg, #2c2924 0%, #1f1d19 100%);
  border: 1px solid #423d34;
  border-radius: 10px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    inset 0 -8px 16px rgba(0, 0, 0, 0.6),
    0 8px 24px rgba(0, 0, 0, 0.4);
}

:root[data-theme="light"] .cassette-shell {
  background: linear-gradient(180deg, #e6dec8 0%, #cfc3a2 100%);
  border-color: #b6a679;
}

.cassette-label {
  background: #f1e6cb;
  border: 1px solid #b6a679;
  border-radius: 4px;
  padding: 6px 14px;
  text-align: center;
  font-family: var(--mono);
  font-size: var(--type-xs);
  color: #4a3522;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  margin-bottom: 14px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6), 0 1px 2px rgba(0, 0, 0, 0.15);
}

.cassette-reels {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 14px;
}

.cassette-reel {
  position: relative;
  width: 64px;
  height: 64px;
  margin: 0 auto;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, #15130f 0%, #2a2620 60%, #1a1814 100%);
  border: 1px solid #4a4338;
  box-shadow:
    inset 0 0 12px rgba(0, 0, 0, 0.8),
    inset 0 0 2px rgba(255, 220, 150, 0.05);
}

.cassette-reel-inner {
  position: absolute;
  inset: 14px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, #2a2620 0%, #1c1a16 100%);
  border: 1px solid #3a342b;
  display: grid;
  place-items: center;
}

.cassette-reel-inner::before,
.cassette-reel-inner::after {
  content: "";
  position: absolute;
  background: #5a4f3b;
  border-radius: 1px;
}

.cassette-reel-inner::before {
  width: 100%;
  height: 2px;
  box-shadow:
    0 -10px 0 #5a4f3b,
    0 10px 0 #5a4f3b;
}

.cassette-reel-inner::after {
  height: 100%;
  width: 2px;
  box-shadow:
    -10px 0 0 #5a4f3b,
    10px 0 0 #5a4f3b;
}

.cassette-player.is-playing .cassette-reel { animation: reel-spin 1.6s linear infinite; }
.cassette-player.is-playing .cassette-reel-right { animation-duration: 1.2s; }

@keyframes reel-spin {
  from { transform: rotate(0); }
  to   { transform: rotate(360deg); }
}

.cassette-window {
  width: 60px;
  height: 30px;
  background: linear-gradient(180deg, #181612 0%, #100e0b 100%);
  border-radius: 4px;
  border: 1px solid #443c30;
  display: grid;
  place-items: center;
  overflow: hidden;
  position: relative;
}

.cassette-tape {
  width: 80%;
  height: 4px;
  background: linear-gradient(90deg, #5a3018 0%, #8c4a24 50%, #5a3018 100%);
  border-radius: 1px;
  opacity: 0.6;
}

.cassette-player.is-playing .cassette-tape {
  animation: tape-shift 1.2s linear infinite;
}

@keyframes tape-shift {
  from { transform: translateX(-6px); opacity: 0.6; }
  50%  { opacity: 1; }
  to   { transform: translateX(6px); opacity: 0.6; }
}

.cassette-base {
  display: flex;
  justify-content: space-between;
  margin-top: 12px;
  padding: 0 6px;
}

.cassette-hole {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #0c0a08;
  border: 1px solid #322c23;
  box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.8);
}

/* ---------- PREVIEW MODAL ---------- */

.preview-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: rgba(8, 8, 7, 0.78);
  padding: 24px;
  backdrop-filter: blur(10px);
  animation: fade-in 180ms var(--ease) both;
}

.preview-dialog {
  display: grid;
  grid-template-rows: auto 1fr;
  width: min(1100px, 100%);
  height: min(820px, calc(100vh - 48px));
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  background: var(--surface-1);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  overflow: hidden;
  animation: dialog-rise 220ms var(--ease) both;
}

@keyframes dialog-rise {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.preview-header h2 {
  margin: 0;
  color: var(--text-bright);
  font-family: var(--sans);
  font-size: var(--type-md);
  font-weight: 500;
  letter-spacing: var(--tracking-tight);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-header h2::before {
  content: "PEEK · ";
  color: var(--accent);
  font-family: var(--mono);
  font-size: var(--type-xs);
  font-weight: 500;
  letter-spacing: 0.14em;
  margin-right: 6px;
  opacity: 0.85;
}

.preview-actions { display: flex; gap: 6px; }
.preview-frame { width: 100%; height: 100%; border: 0; background: #f3eccd; }
body.preview-open { overflow: hidden; }

/* ---------- MODAL (alert / confirm / prompt) ---------- */

.modal-host {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
}

.modal-host > .modal-backdrop {
  pointer-events: auto;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(8, 8, 7, 0.78);
  padding: 24px;
  backdrop-filter: blur(10px);
  animation: fade-in 160ms var(--ease) both;
}

.modal-dialog {
  width: min(440px, 100%);
  max-width: calc(100vw - 48px);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  background: var(--surface-1);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  overflow: hidden;
  animation: dialog-rise 200ms var(--ease) both;
  display: flex;
  flex-direction: column;
}

.modal-header {
  padding: 14px 20px 0;
  border-bottom: 0;
  background: var(--surface-2);
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.modal-eyebrow {
  margin: 0;
  color: var(--accent);
  font-family: var(--mono);
  font-size: var(--type-xs);
  font-weight: 500;
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  opacity: 0.9;
}

.modal-body {
  padding: 18px 20px 16px;
}

.modal-message {
  margin: 0;
  color: var(--text-bright);
  font-family: var(--serif);
  font-size: var(--type-prose);
  line-height: var(--line-snug);
  white-space: pre-wrap;
}

.modal-input {
  margin-top: 14px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text-bright);
  font-family: var(--sans);
  font-size: var(--type-base);
  outline: none;
  transition: border-color var(--duration-fast) var(--ease);
}
.modal-input:focus {
  border-color: var(--accent);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px 16px;
  background: var(--surface-2);
  border-top: 1px solid var(--line);
}

body.modal-open { overflow: hidden; }

/* ---------- RESPONSIVE ---------- */

@media (max-width: 880px) {
  .masthead { padding: 14px 20px 0; }
  .library-nav { margin: 0 -20px; }
  .nav-link { padding: 10px 14px; }
  .vellum { padding: 36px 20px 100px; }
  .masthead-edition { display: none; }

  /* Sidebar collapses to a horizontal scrolling strip at the top */
  .page-with-sidebar {
    grid-template-columns: 1fr;
    gap: 20px;
  }
  .page-sidebar {
    position: static;
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-right: 0;
    padding-bottom: 8px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    gap: 6px;
  }
  .sidebar-section {
    flex-direction: row;
    flex-shrink: 0;
    gap: 4px;
  }
  .sidebar-section-actions {
    margin-top: 0;
    padding-top: 0;
    padding-left: 8px;
    border-top: 0;
    border-left: 1px dashed var(--line);
  }
  .sidebar-tab {
    grid-template-columns: auto auto auto;
    border-left: 0;
    border-bottom: 2px solid transparent;
    padding: 6px 10px;
    white-space: nowrap;
  }
  .sidebar-tab:hover { padding-left: 10px; }
  .sidebar-tab.is-active { border-left-color: transparent; border-bottom-color: var(--accent); }
  .recording-list { padding-left: 24px; }
  .recording-list .recording-item::before { left: -22px; }

  .inscribe-grid { grid-template-columns: 1fr; }
  .ledger-grid { grid-template-columns: repeat(2, 1fr); }
  .ledger-layout { grid-template-columns: 1fr; }
  .folio-summary-grid { grid-template-columns: 1fr; }

  .shelf-card { grid-template-columns: 40px 1fr auto auto; gap: 12px; padding: 22px 0; }
  .shelf-card:hover { padding-left: 8px; padding-right: 8px; }

  .chronicle-entry {
    grid-template-columns: 100px 1px 1fr;
    gap: 0 16px;
  }
  .chronicle-time {
    grid-column: 3;
    color: var(--text-faint);
    padding-top: 4px;
    font-size: 10px;
  }

  .folio-item { padding-left: 44px; }
  .folio-item:hover { padding-left: 50px; }

  .curator-chip { bottom: 12px; right: 12px; }
  .curator-chip input { width: 110px; }

  .preview-dialog { height: calc(100vh - 24px); }
  .parchment { padding: 48px 22px 24px; }
  .parchment::before { left: 22px; top: 16px; }
  .parchment::after { left: 22px; right: 22px; top: 38px; }
}

@media (max-width: 520px) {
  .ledger-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card strong { font-size: var(--type-xl); }
  .folio-action { padding: 4px 6px; }
  .nav-link { padding: 10px 12px; font-size: var(--type-xs); }
  .masthead-brand { flex-direction: column; align-items: flex-start; gap: 2px; }
  .masthead-divider { display: none; }
}

/* ============================================================
   PHASE 4 — Cassette spectacle additions
   Tighter focus on the cassette page: the reels get a soft
   blur while playing, the player picks up a small rating badge
   from the currently-playing tape, and the recording list
   stops looking like a list of meta strings.
   ============================================================ */

/* Reel motion blur: a hair of blur on the spinning reels reads
   as motion without becoming a CPU smear. Steady when paused. */
.cassette-player.is-playing .cassette-reel {
  filter: blur(0.5px) contrast(1.06);
}
.cassette-player.is-playing .cassette-reel-inner {
  filter: blur(0.3px);
}

/* Cassette label can pick up a star + rating dot from the
   currently-playing tape, in the same typewriter look. */
.cassette-label-rating {
  display: inline-block;
  margin-left: 10px;
  padding: 0 6px;
  background: #c9a24b;
  color: #1a1611;
  border-radius: 2px;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  vertical-align: 1px;
}

/* Now-playing rail — sticks under the masthead so the visitor
   never loses the tape when wandering to another page. */
.now-playing-rail {
  position: sticky;
  top: 0;
  z-index: 9;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 16px;
  margin: 0 -36px;
  padding: 10px 36px;
  background: linear-gradient(180deg, var(--surface-2) 0%, var(--surface-1) 100%);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line-strong);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.18);
  animation: rail-down 240ms var(--ease) both;
}

@keyframes rail-down {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.np-mark {
  color: var(--accent);
  font-family: var(--mono);
  font-size: var(--type-md);
  width: 24px;
  text-align: center;
}
.np-text {
  min-width: 0;
  display: grid;
  gap: 2px;
}
.np-eyebrow {
  margin: 0;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
}
.np-title {
  background: transparent;
  border: 0;
  padding: 0;
  text-align: left;
  color: var(--text-bright);
  font-family: var(--serif);
  font-size: var(--type-md);
  font-style: italic;
  cursor: pointer;
  border-bottom: 1px solid transparent;
  transition: color var(--duration-fast) var(--ease), border-color var(--duration-fast) var(--ease);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.np-title:hover {
  color: var(--accent-bright);
  border-bottom-color: var(--accent-line);
}
.np-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: var(--type-xs);
  color: var(--text-muted);
  font-feature-settings: "tnum", "lnum";
}
.np-rating {
  padding: 1px 6px;
  background: var(--accent);
  color: var(--on-accent);
  border-radius: 2px;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.np-controls { display: flex; gap: 4px; }
.np-btn {
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: var(--type-xs);
  font-feature-settings: "tnum";
  cursor: pointer;
  transition: color var(--duration-fast) var(--ease),
              border-color var(--duration-fast) var(--ease),
              background var(--duration-fast) var(--ease);
}
.np-btn:hover {
  color: var(--accent-bright);
  border-color: var(--line-accent);
}
.np-btn-play {
  min-width: 32px;
  text-align: center;
}
.np-btn-close {
  color: var(--text-muted);
  padding: 4px 8px;
}

@media (max-width: 880px) {
  .now-playing-rail { margin: 0 -20px; padding: 8px 16px; gap: 10px; grid-template-columns: auto minmax(0, 1fr) auto; }
  .np-meta { display: none; }
}

/* Rating chip beside the cassette title — typewriter look,
   uses the same brass palette as the cassette label badge. */
.recording-rating-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font-family: var(--mono);
  font-size: var(--type-xs);
  font-weight: 700;
  letter-spacing: 0.04em;
  font-feature-settings: "tnum";
}

/* Recording list — hairline between items, time-of-day capsule
   instead of bare timestamp, duration aligned with a thin space
   so a tight column of m:ss values vertically aligns cleanly. */
.recording-meta-row {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin: 6px 0 0;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: 0.04em;
  text-transform: lowercase;
  font-feature-settings: "tnum", "lnum";
}
.recording-meta-duration {
  display: inline-block;
  min-width: 4ch;
  text-align: right;
  color: var(--text-dim);
}
.recording-meta-sep {
  color: var(--text-faint);
  opacity: 0.55;
}
.recording-meta-when {
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--text-dim);
  border: 1px solid var(--line);
  text-transform: lowercase;
  font-feature-settings: "tnum";
}
.recording-meta-size { color: var(--text-faint); }

/* Hairline divider between recording items — same look as the
   parchment node marker on the left, but stretching across to
   read as a divider rather than a list separator. */
.recording-list .recording-item + .recording-item {
  margin-top: 4px;
}
.recording-list .recording-item + .recording-item::after {
  content: "";
  position: absolute;
  top: -12px;
  left: 12%;
  right: 12%;
  height: 1px;
  background: linear-gradient(90deg, transparent 0%, var(--line-strong) 25%, var(--line-strong) 75%, transparent 100%);
  opacity: 0.5;
  pointer-events: none;
}

/* ============================================================
   PHASE 5 — Plates + question modal polish
   ============================================================ */

/* Plates: hover reveals an over-sized order number in the
   corner of the thumbnail; the action buttons fade in only on
   hover so the grid stays calm. */
.plate-card .plate-number {
  transition: transform var(--duration) var(--ease),
              opacity var(--duration) var(--ease),
              background var(--duration-fast) var(--ease);
}
.plate-card:hover .plate-number {
  transform: scale(1.18);
  background: rgba(8, 8, 7, 0.92);
}
.plate-card .plate-actions {
  opacity: 0;
  transform: translateY(2px);
  transition: opacity var(--duration) var(--ease),
              transform var(--duration) var(--ease);
}
.plate-card:hover .plate-actions,
.plate-card:focus-within .plate-actions {
  opacity: 1;
  transform: translateY(0);
}
/* Captions: italic by default (already), but make em-attribute
   tighter so "untitled" reads as a stage direction. */
.plate-card:hover .plate-caption {
  color: var(--text-bright);
}

/* Question ribbon — three slot panels in a row, voice → hint → solution.
   On narrow screens the ribbon falls back to a vertical stack so
   it reads top-to-bottom on a phone. */
.question-ribbon {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 14px;
}
.ribbon-panel {
  position: relative;
  display: grid;
  gap: 10px;
  padding: 14px 14px 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  min-height: 140px;
  transition: border-color var(--duration-fast) var(--ease),
              transform var(--duration) var(--ease);
}
.ribbon-panel + .ribbon-panel::before {
  content: "→";
  position: absolute;
  left: -14px;
  top: 50%;
  transform: translate(-2px, -50%);
  color: var(--accent);
  font-family: var(--mono);
  font-size: var(--type-md);
  opacity: 0.55;
  pointer-events: none;
}
.ribbon-panel.is-empty { background: transparent; border-style: dashed; }
.ribbon-panel.is-hidden .slot-body { display: none; }
/* When a slot is revealed, it nudges forward a hair so the
   ribbon doesn't sit flat across all three states. */
.ribbon-panel:not(.is-hidden):not(.is-empty) {
  border-color: var(--line-accent);
}

@media (max-width: 880px) {
  .question-ribbon { grid-template-columns: 1fr; gap: 14px; }
  .ribbon-panel + .ribbon-panel::before {
    content: "↓";
    top: -12px;
    left: 50%;
    transform: translate(-50%, 0);
  }
}

/* Streak counter — sits below the question title and shows the
   last four attempts as glyphs plus a short prose run ("3 of
   last 4 correct"). */
.question-streak {
  margin: 6px 0 0;
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--mono);
  font-size: var(--type-xs);
  color: var(--text-muted);
  letter-spacing: 0.06em;
  font-feature-settings: "tnum";
}
.streak-glyphs {
  display: inline-flex;
  gap: 4px;
}
.streak-mark {
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  font-size: 10px;
  border: 1px solid var(--line);
}
.streak-mark.is-correct {
  background: var(--accent-soft);
  color: var(--accent-bright);
  border-color: var(--line-accent);
}
.streak-mark.is-wrong {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: rgba(201, 122, 111, 0.32);
}
.streak-prose { font-style: italic; color: var(--text-dim); font-family: var(--serif); font-size: var(--type-sm); letter-spacing: 0; text-transform: none; }

/* ============================================================
   PHASE 6 — Micro-touches: empty-state SVGs, toasts, page
   transitions, tighter focus rings, keyboard cheat sheet.
   ============================================================ */

/* Inline empty-state art: small monoline drawings in brass. */
.empty-art {
  display: block;
  margin: 0 auto 14px;
  width: 96px;
  height: 64px;
  color: var(--accent);
  opacity: 0.62;
}
.empty-art svg { width: 100%; height: 100%; display: block; }
.empty-shelves { text-align: center; }

/* Toast region: lower-right stack, queue up to 3 visible. */
.toast-region {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 60;
  display: grid;
  gap: 8px;
  pointer-events: none;
  max-width: min(380px, calc(100vw - 44px));
}
.toast {
  pointer-events: auto;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 14px;
  background: var(--surface-1);
  border: 1px solid var(--line-strong);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.32);
  color: var(--text-bright);
  font-family: var(--serif);
  font-size: var(--type-md);
  line-height: var(--line-snug);
  animation: toast-in var(--duration) var(--ease) both;
}
.toast.is-error   { border-left-color: var(--danger); }
.toast.is-success { border-left-color: var(--accent-bright); }
.toast.is-leaving { animation: toast-out 200ms var(--ease) both; }
.toast-mark {
  font-family: var(--mono);
  font-size: var(--type-sm);
  color: var(--accent);
  letter-spacing: 0.06em;
}
.toast.is-error .toast-mark { color: var(--danger); }
.toast-body { min-width: 0; }
.toast-close {
  background: transparent;
  border: 0;
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--mono);
  font-size: var(--type-md);
  padding: 2px 6px;
  border-radius: var(--radius);
  transition: color var(--duration-fast) var(--ease);
}
.toast-close:hover { color: var(--text-bright); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes toast-out {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(6px); }
}

/* Page transitions: 200ms fade on route change. The page wrapper
   becomes "is-leaving" briefly, then "is-entering" on the new
   page. We don't animate every micro-interaction inside; only
   the cross-fade between pages. */
.page {
  transition: opacity var(--duration) var(--ease);
}
.page.is-entering {
  animation: page-enter 240ms var(--ease) both;
}
@keyframes page-enter {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Tighter, accent-tinted focus rings. The browser default
   covers buttons and links with a thick blue halo — replace
   with a 2px brass ring and a soft fill behind it. */
*:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}
button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  box-shadow: 0 0 0 3px var(--accent-soft);
}
/* The existing modal/inputs already set their own focus styles
   via box-shadow — keep theirs from layering with our default. */
.modal-input:focus,
.library-sort-select:focus-visible {
  outline: none;
}

/* Keyboard cheat sheet — opens with `?`, closes with Esc, the
   close button, or a click on the backdrop. */
.cheat-sheet {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  background: rgba(8, 8, 7, 0.72);
  padding: 24px;
  backdrop-filter: blur(8px);
  animation: fade-in 160ms var(--ease) both;
}
.cheat-card {
  width: min(440px, 100%);
  background: var(--surface-1);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  animation: dialog-rise 220ms var(--ease) both;
  overflow: hidden;
}
.cheat-head {
  position: relative;
  padding: 16px 22px 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}
.cheat-eyebrow {
  margin: 0;
  color: var(--accent);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
}
.cheat-title {
  margin: 4px 0 0;
  color: var(--text-bright);
  font-family: var(--serif);
  font-style: italic;
  font-size: var(--type-lg);
  font-weight: 500;
}
.cheat-close {
  position: absolute;
  right: 14px;
  top: 14px;
  background: transparent;
  border: 0;
  color: var(--text-muted);
  font-size: var(--type-lg);
  cursor: pointer;
  padding: 2px 8px;
  border-radius: var(--radius);
  transition: color var(--duration-fast) var(--ease);
}
.cheat-close:hover { color: var(--text-bright); }
.cheat-list { margin: 0; padding: 14px 22px 18px; display: grid; gap: 10px; }
.cheat-row {
  display: grid;
  grid-template-columns: 110px 1fr;
  align-items: baseline;
  gap: 14px;
}
.cheat-row dt {
  display: flex;
  gap: 4px;
}
.cheat-row dd {
  margin: 0;
  color: var(--text-dim);
  font-family: var(--serif);
  font-style: italic;
  font-size: var(--type-md);
}
.cheat-row kbd {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: var(--radius);
  color: var(--text-bright);
  font-family: var(--mono);
  font-size: var(--type-xs);
  font-weight: 600;
}

/* ============================================================
   PHASE 7 — Listening progress
   The "resume at" line sits between the title row and the audio
   element, italic serif so it reads as a marginal note rather
   than UI chrome.
   ============================================================ */
.recording-resume {
  margin: 0;
  padding: 2px 0 4px;
  color: var(--text-muted);
  font-family: var(--serif);
  font-style: italic;
  font-size: var(--type-sm);
  cursor: pointer;
  border-bottom: 0;
  transition: color var(--duration-fast) var(--ease);
}
.recording-resume:hover { color: var(--accent-bright); }
.recording-resume strong {
  color: var(--text-bright);
  font-family: var(--mono);
  font-style: normal;
  font-weight: 600;
  font-feature-settings: "tnum";
  margin-left: 4px;
}

/* ============================================================
   PHASE 8 — Plate lightbox
   Full-screen viewer: image centered, prev/next on the sides,
   a header with caption + close, and a thin footer counter.
   The image gets near-fullscreen with object-fit: contain so
   tall textbook pages still fit without cropping.
   ============================================================ */
.plate-lightbox {
  position: fixed;
  inset: 0;
  z-index: 65;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: rgba(8, 8, 7, 0.92);
  backdrop-filter: blur(6px);
  animation: fade-in 160ms var(--ease) both;
}
.lightbox-head {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.32);
}
.lightbox-head-text { min-width: 0; }
.lightbox-eyebrow {
  margin: 0;
  color: var(--accent);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
}
.lightbox-title {
  margin: 2px 0 0;
  color: var(--text-bright);
  font-family: var(--serif);
  font-style: italic;
  font-size: var(--type-lg);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lightbox-close {
  background: transparent;
  border: 0;
  color: var(--text-bright);
  font-size: 28px;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: var(--radius);
  transition: color var(--duration-fast) var(--ease);
}
.lightbox-close:hover { color: var(--accent-bright); }

.lightbox-body {
  position: relative;
  display: grid;
  place-items: center;
  padding: 24px 80px;
  overflow: hidden;
}
.lightbox-image {
  display: block;
  max-width: 92vw;
  max-height: 78vh;
  object-fit: contain;
  background: var(--surface-1);
  border-radius: var(--radius);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.6);
  animation: dialog-rise 220ms var(--ease) both;
}
.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--line-strong);
  color: var(--text-bright);
  width: 48px;
  height: 96px;
  font-size: 28px;
  cursor: pointer;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  transition: background var(--duration-fast) var(--ease),
              color var(--duration-fast) var(--ease);
}
.lightbox-nav:hover {
  background: rgba(0, 0, 0, 0.72);
  color: var(--accent-bright);
}
.lightbox-nav-prev { left: 18px; }
.lightbox-nav-next { right: 18px; }

.lightbox-foot {
  padding: 10px 20px;
  text-align: center;
  border-top: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.32);
}
.lightbox-counter {
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: 0.08em;
  font-feature-settings: "tnum";
}

@media (max-width: 720px) {
  .lightbox-body { padding: 24px 16px; }
  .lightbox-image { max-height: 70vh; }
  .lightbox-nav { width: 36px; height: 72px; font-size: 22px; }
  .lightbox-nav-prev { left: 6px; }
  .lightbox-nav-next { right: 6px; }
}

/* Plate thumb cursor signal — the image is now clickable. */
.plate-card .plate-image { cursor: zoom-in; }

/* ============================================================
   PHASE 9 — "Since you were here"
   ============================================================ */
.activity-line {
  margin: 14px 0 0;
  color: var(--text-muted);
  font-family: var(--serif);
  font-style: italic;
  font-size: var(--type-sm);
  line-height: var(--line-snug);
}
.activity-line a {
  color: var(--accent-bright);
  text-decoration: none;
  border-bottom: 1px solid var(--accent-line);
  padding: 0 2px;
  font-style: normal;
}
.activity-line a:hover {
  color: var(--text-bright);
  border-bottom-color: var(--accent);
}
.activity-eyebrow {
  display: inline-block;
  margin-right: 8px;
  color: var(--accent);
  font-family: var(--mono);
  font-style: normal;
  font-size: var(--type-xs);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
}
.activity-sep {
  margin: 0 4px;
  color: var(--text-faint);
}

/* Nav-link new-dot — a tiny brass disc trailing the link's text. */
.nav-link.has-new::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  margin-left: 6px;
  vertical-align: 4px;
  box-shadow: 0 0 0 2px rgba(201, 162, 75, 0.18);
}

/* ============================================================
   PHASE 10 — Practice deck
   In-modal session strip + summary card.
   ============================================================ */
.practice-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 0 0 14px;
  padding: 8px 14px;
  background: var(--accent-soft);
  border: 1px solid var(--line-accent);
  border-radius: var(--radius);
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: 0.04em;
  text-transform: lowercase;
  font-feature-settings: "tnum";
}
.practice-strip-position { color: var(--accent-bright); font-weight: 600; }
.practice-strip-sep { color: var(--text-faint); opacity: 0.55; }
.practice-strip-score { color: var(--text-bright); }
.practice-strip-end {
  margin-left: auto;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--type-xs);
  padding: 3px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  letter-spacing: 0.06em;
  transition: color var(--duration-fast) var(--ease),
              border-color var(--duration-fast) var(--ease);
}
.practice-strip-end:hover {
  color: var(--accent-bright);
  border-color: var(--line-accent);
}

.practice-summary {
  display: grid;
  gap: 14px;
  padding: 26px 22px;
  margin-top: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  text-align: center;
  animation: dialog-rise 220ms var(--ease) both;
}
.practice-summary-eyebrow {
  margin: 0;
  color: var(--accent);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
}
.practice-summary-title {
  margin: 0;
  color: var(--text-bright);
  font-family: var(--serif);
  font-style: italic;
  font-size: var(--type-xl);
  font-weight: 500;
  font-feature-settings: "tnum";
}
.practice-summary-stats {
  list-style: none;
  margin: 8px 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.practice-summary-stats li {
  display: grid;
  gap: 4px;
  padding: 10px;
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.practice-summary-stats li span {
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
}
.practice-summary-stats li strong {
  color: var(--text-bright);
  font-family: var(--serif);
  font-size: var(--type-lg);
  font-weight: 500;
  font-feature-settings: "tnum";
}
.practice-summary .btn {
  justify-self: center;
}

.practice-button {
  margin-left: 8px;
  border: 1px solid var(--line-accent);
  color: var(--accent-bright);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: 0.06em;
  text-transform: lowercase;
  font-weight: 500;
}
.practice-button:hover {
  background: var(--accent-soft);
  color: var(--text-bright);
}

@media (max-width: 720px) {
  .practice-summary-stats { grid-template-columns: repeat(2, 1fr); }
}

/* ============================================================
   PHASE 11 — Global search overlay
   ============================================================ */
.search-overlay {
  position: fixed;
  inset: 0;
  z-index: 75;
  display: grid;
  align-items: flex-start;
  justify-items: center;
  padding: 12vh 20px 20px;
  background: rgba(8, 8, 7, 0.72);
  backdrop-filter: blur(8px);
  animation: fade-in 160ms var(--ease) both;
}
.search-card {
  width: min(640px, 100%);
  background: var(--surface-1);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  animation: dialog-rise 220ms var(--ease) both;
  display: grid;
  grid-template-rows: auto 1fr auto;
  max-height: 70vh;
  overflow: hidden;
}
.search-head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}
.search-mark {
  color: var(--accent);
  font-family: var(--mono);
  font-size: var(--type-md);
  width: 24px;
  text-align: center;
}
.search-input {
  background: transparent;
  border: 0;
  outline: none;
  color: var(--text-bright);
  font-family: var(--sans);
  font-size: var(--type-md);
  padding: 6px 4px;
  width: 100%;
}
.search-close {
  background: transparent;
  border: 0;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
  padding: 2px 8px;
  border-radius: var(--radius);
  transition: color var(--duration-fast) var(--ease);
}
.search-close:hover { color: var(--text-bright); }
.search-results {
  overflow-y: auto;
  padding: 6px 0;
}
.search-empty {
  margin: 24px 16px;
  color: var(--text-muted);
  font-family: var(--serif);
  font-style: italic;
  font-size: var(--type-md);
  text-align: center;
}
.search-group {
  padding: 6px 0;
  border-top: 1px solid var(--line);
}
.search-group:first-of-type { border-top: 0; }
.search-group-label {
  margin: 6px 16px;
  color: var(--accent);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
}
.search-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  width: 100%;
  padding: 8px 16px;
  background: transparent;
  border: 0;
  text-align: left;
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease);
}
.search-row:hover,
.search-row.is-active {
  background: var(--accent-soft);
}
.search-row-mark {
  color: var(--accent);
  font-family: var(--mono);
  font-size: var(--type-md);
  width: 16px;
  text-align: center;
  padding-top: 2px;
}
.search-row-text {
  min-width: 0;
  display: grid;
  gap: 2px;
}
.search-row-title {
  color: var(--text-bright);
  font-family: var(--serif);
  font-size: var(--type-md);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-row-excerpt {
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: 0.04em;
  text-transform: lowercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-foot {
  display: flex;
  justify-content: center;
  gap: 16px;
  padding: 8px 16px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text-faint);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: 0.06em;
}
.search-foot kbd {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 18px;
  padding: 0 4px;
  background: var(--surface-1);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 10px;
  margin-right: 4px;
}

/* Brass-flash when a search result is jumped to. */
.search-flash {
  animation: search-flash 1400ms var(--ease) both;
}
@keyframes search-flash {
  0%   { box-shadow: 0 0 0 0 var(--accent); }
  20%  { box-shadow: 0 0 0 4px var(--accent-soft); }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* ============================================================
   PHASE 12 — Practice heatmap on the plates page
   ============================================================ */
.practice-heatmap {
  display: grid;
  gap: 12px;
  margin: 0 0 22px;
  padding: 14px 18px;
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.heatmap-caption {
  display: grid;
  gap: 4px;
}
.heatmap-eyebrow {
  margin: 0;
  color: var(--accent);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
}
.heatmap-stats {
  margin: 0;
  color: var(--text-dim);
  font-family: var(--serif);
  font-style: italic;
  font-size: var(--type-sm);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.heatmap-stats strong {
  font-family: var(--mono);
  font-style: normal;
  color: var(--text-bright);
  font-feature-settings: "tnum";
}
.heatmap-sep { color: var(--text-faint); }
.heatmap-grid {
  display: flex;
  gap: 3px;
  overflow-x: auto;
}
.heatmap-col {
  display: grid;
  grid-template-rows: repeat(7, 12px);
  gap: 3px;
}
.heatmap-cell {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  background: var(--surface-3);
  transition: transform var(--duration-fast) var(--ease);
  cursor: default;
}
.heatmap-cell.is-band-0 { background: var(--surface-3); }
.heatmap-cell.is-band-1 { background: var(--accent-soft); border: 1px solid var(--line-accent); }
.heatmap-cell.is-band-2 { background: var(--accent); opacity: 0.65; }
.heatmap-cell.is-band-3 { background: var(--accent-bright); }
.heatmap-cell.is-future { background: transparent; border: 1px dashed var(--line); }
.heatmap-cell:hover { transform: scale(1.4); }
.heatmap-legend {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: 0.06em;
}
.heatmap-legend .heatmap-cell { width: 10px; height: 10px; }

/* ============================================================
   PHASE 13 — Markdown rendering
   Style the rendered output of <div data-md>. Inline bold,
   italic, code, and link are all unsurprising; lists pick up
   the brass bullet from the existing palette. Recording notes
   used to be a <p> with a left rule — keep that look on the
   wrapper <div> so the visual identity is unchanged.
   ============================================================ */
.recording-notes {
  margin: 0;
  padding-left: 14px;
  border-left: 2px solid var(--line-strong);
  color: var(--text-dim);
  font-family: var(--serif);
  font-style: italic;
  font-size: var(--type-md);
  line-height: var(--line-body);
}
.recording-notes p { margin: 0 0 6px; }
.recording-notes p:last-child { margin-bottom: 0; }
.recording-notes ul { margin: 4px 0; padding-left: 20px; }
.recording-notes li { margin: 2px 0; }
.recording-notes strong { font-style: normal; color: var(--text-bright); font-weight: 600; }
.recording-notes em { font-style: italic; }
.recording-notes code {
  font-family: var(--mono);
  font-style: normal;
  font-size: 0.92em;
  background: var(--accent-soft);
  padding: 1px 5px;
  border-radius: 3px;
  color: var(--text-bright);
}
.recording-notes a {
  color: var(--accent-bright);
  text-decoration: none;
  border-bottom: 1px solid var(--accent-line);
  font-style: normal;
}
.recording-notes a:hover { color: var(--text-bright); border-bottom-color: var(--accent); }

/* Same set of inline styles, applied inside marginalia bodies. */
.marginalia-body { /* base styles from the earlier marginalia block apply */ }
.marginalia-body p { margin: 0 0 4px; }
.marginalia-body p:last-child { margin-bottom: 0; }
.marginalia-body ul { margin: 4px 0; padding-left: 20px; }
.marginalia-body li { margin: 2px 0; }
.marginalia-body strong { color: var(--text-bright); font-weight: 600; font-style: normal; }
.marginalia-body em { font-style: italic; }
.marginalia-body code {
  font-family: var(--mono);
  font-style: normal;
  font-size: 0.92em;
  background: var(--accent-soft);
  padding: 1px 5px;
  border-radius: 3px;
  color: var(--text-bright);
}
.marginalia-body a {
  color: var(--accent-bright);
  text-decoration: none;
  border-bottom: 1px solid var(--accent-line);
}
.marginalia-body a:hover { color: var(--text-bright); border-bottom-color: var(--accent); }

/* Cheat-sheet decoration — small "or" between key clusters. */
.cheat-or {
  color: var(--text-muted);
  font-family: var(--serif);
  font-style: italic;
  margin: 0 4px;
  font-size: var(--type-xs);
}

/* ============================================================
   PHASE 14 — Tablet & touch tuning
   Targets Princess Ananya's Lenovo Tab K11 Gen 2 specifically:
   ~800×1280 portrait, ~1280×800 landscape. The min-700/max-1100
   band catches both the K11 in portrait and most tablets in
   landscape. Bumps touch targets to ≥44px and tightens the
   layout where the phone breakpoint over-reaches.
   ============================================================ */

/* Generic touch-device tweaks — apply to any coarse-pointer input. */
@media (pointer: coarse) {
  /* Rating dial dots: bigger hit areas. */
  .rating-dot {
    min-width: 28px;
    min-height: 28px;
    padding: 4px;
  }
  /* Marginalia kind toggle, density buttons, np-rail controls. */
  .marginalia-kind-button,
  .density-button,
  .np-btn,
  .upload-category-chip,
  .marginalia-remove,
  .folio-action {
    min-height: 36px;
  }
  /* The plate image lightbox: navigation arrows are easier to hit. */
  .lightbox-nav { width: 56px; height: 110px; font-size: 32px; }
}

/* Tablet-specific layout band. */
@media (min-width: 700px) and (max-width: 1100px) {
  /* Touch targets bigger across the board. */
  .rating-dot { min-width: 30px; min-height: 30px; }
  .sidebar-tab { min-height: 40px; }
  .marginalia-kind-button { padding: 10px 18px; }
  .np-btn { padding: 8px 14px; min-width: 44px; }

  /* The page sidebar stays vertical but tightens. */
  .page-with-sidebar {
    grid-template-columns: 200px 1fr;
    gap: 22px;
  }

  /* Cassette player grows so the spinning reels read from a couch. */
  .cassette-shell { padding: 22px 26px; }
  .cassette-reel { width: 78px; height: 78px; }

  /* Lightbox uses more of the screen. */
  .lightbox-body { padding: 22px 30px; }
  .lightbox-image { max-height: 82vh; }
  .lightbox-nav { width: 52px; height: 96px; }

  /* Question modal ribbon: stays horizontal at landscape, stacks at
     portrait (orientation-based — overrides the 3-col grid). */
  @media (orientation: portrait) {
    .question-ribbon { grid-template-columns: 1fr; gap: 14px; }
    .ribbon-panel + .ribbon-panel::before {
      content: "↓";
      top: -12px;
      left: 50%;
      transform: translate(-50%, 0);
    }
    .assess-buttons { flex-direction: column; gap: 8px; }
    .assess-buttons .btn { width: 100%; }
  }

  /* Now-playing rail: simpler layout — drop the absolute time. */
  @media (orientation: portrait) {
    .now-playing-rail { grid-template-columns: auto minmax(0, 1fr) auto; }
    .np-meta { display: none; }
  }

  /* Plate grid: a denser, more deliberate 3 × n at desktop wash. */
  .plate-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 18px; }
  .plate-grid[data-density="compact"] { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }

  /* Practice heatmap: a touch more padding so cells aren't crammed. */
  .practice-heatmap { padding: 18px 22px; }
  .heatmap-cell, .heatmap-grid .heatmap-cell { width: 14px; height: 14px; }
  .heatmap-col { grid-template-rows: repeat(7, 14px); }
}

/* ============================================================
   PHASE 16 — Cassette playback speed button
   ============================================================ */
.np-btn-speed {
  font-feature-settings: "tnum";
  min-width: 42px;
}
.np-btn-speed.is-non-default {
  color: var(--accent-bright);
  border-color: var(--line-accent);
}

/* ============================================================
   PHASE 17 — Sleep timer button + popover menu
   ============================================================ */
.np-sleep-wrap {
  position: relative;
  display: inline-flex;
}
.np-btn-sleep {
  font-feature-settings: "tnum";
  min-width: 42px;
}
.np-btn-sleep.is-active {
  color: var(--accent-bright);
  border-color: var(--line-accent);
  background: var(--accent-soft);
}
.np-sleep-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  z-index: 11;
  background: var(--surface-1);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.32);
  display: grid;
  min-width: 120px;
  overflow: hidden;
  animation: dialog-rise 180ms var(--ease) both;
}
.np-sleep-menu button {
  background: transparent;
  border: 0;
  text-align: left;
  padding: 8px 14px;
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease), color var(--duration-fast) var(--ease);
}
.np-sleep-menu button:hover,
.np-sleep-menu button:focus-visible {
  background: var(--accent-soft);
  color: var(--accent-bright);
}

/* ============================================================
   PHASE 18 — Today's plate quick-practice card on the hall
   ============================================================ */
.todays-plate {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 18px;
  margin: 16px 0 0;
  padding: 14px 16px;
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  animation: dialog-rise 200ms var(--ease) both;
}
.todays-thumb {
  aspect-ratio: 3 / 4;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--line);
}
.todays-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.todays-text {
  display: grid;
  gap: 4px;
  align-content: center;
  min-width: 0;
}
.todays-eyebrow {
  margin: 0;
  color: var(--accent);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
}
.todays-title {
  margin: 0;
  color: var(--text-bright);
  font-family: var(--serif);
  font-style: italic;
  font-size: var(--type-md);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.todays-meta {
  margin: 0;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: 0.04em;
  text-transform: lowercase;
}
.todays-start {
  justify-self: start;
  margin-top: 4px;
  border: 1px solid var(--line-accent);
  color: var(--accent-bright);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: 0.06em;
}
.todays-start:hover {
  background: var(--accent-soft);
  color: var(--text-bright);
}

@media (max-width: 520px) {
  .todays-plate { grid-template-columns: 72px 1fr; gap: 12px; padding: 12px; }
  .todays-thumb { aspect-ratio: 1; }
}

/* ============================================================
   PHASE 19 — Auth gate atmospheric redesign
   Replaces the original compact card with a taller, more
   crafted layout: an SVG ornament at top, hairline-flanked
   eyebrow, italic-serif title, rotating epigram, parchment
   input with a key icon, ghost submit with a sliding arrow.
   ============================================================ */
body[data-auth="pending"] .auth-gate,
body[data-auth="locked"] .auth-gate {
  background: radial-gradient(circle at 50% 30%, var(--surface-1) 0%, var(--bg) 75%);
}
.auth-card {
  width: min(440px, 100%);
  padding: 38px 36px 30px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, var(--surface-1) 0%, var(--surface-2) 100%);
  box-shadow: 0 32px 80px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.04);
  display: grid;
  gap: 14px;
  text-align: center;
  animation: dialog-rise 320ms var(--ease) both;
}
.auth-ornament {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  margin: 0 auto;
  color: var(--accent);
}
.auth-ornament svg { width: 100%; height: 100%; }
.auth-eyebrow {
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--accent);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.28em;
  text-transform: uppercase;
}
.auth-rule {
  flex: 0 1 60px;
  height: 1px;
  background: linear-gradient(90deg, transparent 0%, var(--line-accent) 50%, transparent 100%);
}
.auth-title {
  margin: 0;
  font-family: var(--serif);
  font-style: italic;
  font-size: 38px;
  font-weight: 500;
  letter-spacing: -0.012em;
  color: var(--text-bright);
}
.auth-prose {
  margin: 0;
  color: var(--text-muted);
  font-family: var(--serif);
  font-size: var(--type-md);
  line-height: var(--line-snug);
}
.auth-epigram {
  margin: 6px auto 4px;
  max-width: 320px;
  color: var(--text-dim);
  font-family: var(--serif);
  font-size: var(--type-sm);
  line-height: var(--line-snug);
  font-style: italic;
}
.auth-epigram-by {
  display: block;
  margin-top: 4px;
  font-style: normal;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--text-muted);
  text-transform: uppercase;
}
.auth-field {
  position: relative;
  display: grid;
  gap: 6px;
  margin-top: 6px;
  text-align: left;
}
.auth-field-label {
  color: var(--accent);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}
.auth-field-icon {
  position: absolute;
  left: 12px;
  top: 30px;
  width: 16px;
  height: 16px;
  color: var(--accent);
  opacity: 0.6;
  pointer-events: none;
}
.auth-field input {
  padding: 12px 12px 12px 36px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text-bright);
  font-family: var(--sans);
  font-size: var(--type-md);
  outline: none;
  transition: border-color var(--duration-fast) var(--ease),
              box-shadow var(--duration-fast) var(--ease);
}
.auth-field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  outline: none;
}
.auth-field input:focus + .auth-field-icon,
.auth-field:focus-within .auth-field-icon { opacity: 0.95; }

.auth-submit {
  margin-top: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 18px;
  border: 1px solid var(--line-accent);
  border-radius: var(--radius);
  background: transparent;
  color: var(--accent-bright);
  font-family: var(--mono);
  font-size: var(--type-sm);
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease),
              color var(--duration-fast) var(--ease),
              border-color var(--duration-fast) var(--ease);
}
.auth-submit:hover {
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
}
.auth-submit:disabled { opacity: 0.5; cursor: progress; }
.auth-submit-arrow {
  font-family: var(--mono);
  transition: transform var(--duration) var(--ease);
}
.auth-submit:hover .auth-submit-arrow { transform: translateX(4px); }

.auth-error {
  margin: 0;
  color: var(--danger);
  font-family: var(--serif);
  font-style: italic;
  font-size: var(--type-sm);
  animation: fade-in 200ms var(--ease) both;
}

/* ============================================================
   PHASE 20 — Chronicle (daybook) richer rendering
   Day-grouped, filter chips, event-type glyph in the rail.
   ============================================================ */
.chronicle-tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px 18px;
  margin: 0 0 18px;
}
.chronicle-filters {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-left: auto;
}
.chronicle-filter {
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: 0.06em;
  text-transform: lowercase;
  cursor: pointer;
  transition: color var(--duration-fast) var(--ease),
              border-color var(--duration-fast) var(--ease),
              background var(--duration-fast) var(--ease);
}
.chronicle-filter:hover {
  color: var(--accent-bright);
  border-color: var(--line-accent);
}
.chronicle-filter.is-active {
  color: var(--on-accent);
  background: var(--accent);
  border-color: var(--accent);
}
:root[data-theme="light"] .chronicle-filter.is-active {
  color: var(--text-bright);
  background: var(--accent-soft);
  border-color: var(--accent);
}

.chronicle-days {
  display: grid;
  gap: 28px;
}
.chronicle-day {
  display: grid;
  gap: 8px;
}
.chronicle-day-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 0 0 8px;
  border-bottom: 1px solid var(--line);
}
.chronicle-day-label {
  color: var(--text-bright);
  font-family: var(--serif);
  font-style: italic;
  font-size: var(--type-md);
  font-weight: 500;
}
.chronicle-day-pill {
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: 0.06em;
  text-transform: lowercase;
}
.chronicle-day-pill.is-today {
  background: var(--accent-soft);
  border-color: var(--line-accent);
  color: var(--accent-bright);
}
.chronicle-day-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 4px;
}
.chronicle-day .chronicle-entry {
  display: grid;
  grid-template-columns: 22px 110px 1fr auto;
  align-items: baseline;
  gap: 14px;
  padding: 7px 8px;
  border-radius: var(--radius);
  background: transparent;
  border-left: 0;
  transition: background var(--duration-fast) var(--ease);
}
.chronicle-day .chronicle-entry::before { content: none; }
.chronicle-day .chronicle-entry:hover { background: var(--accent-soft); }
.chronicle-glyph {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--accent);
  font-family: var(--mono);
  font-size: var(--type-xs);
}
.chronicle-day .chronicle-entry.is-today .chronicle-glyph {
  background: var(--accent-soft);
  border-color: var(--line-accent);
  color: var(--accent-bright);
}
.chronicle-event-type {
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: 0.06em;
  text-transform: lowercase;
}
.chronicle-day .chronicle-text {
  color: var(--text-dim);
  font-family: var(--serif);
  font-size: var(--type-md);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chronicle-day .chronicle-text em {
  color: var(--text-bright);
  font-style: italic;
}
.chronicle-day .chronicle-time {
  color: var(--text-faint);
  font-family: var(--mono);
  font-size: var(--type-xs);
  font-feature-settings: "tnum";
}
.chronicle-empty {
  margin: 18px 0;
  color: var(--text-muted);
  font-family: var(--serif);
  font-style: italic;
  font-size: var(--type-md);
  text-align: center;
}

@media (max-width: 720px) {
  .chronicle-day .chronicle-entry { grid-template-columns: 22px 1fr auto; }
  .chronicle-event-type { display: none; }
}

/* ============================================================
   PHASE 21 — Ledger refinements: sparklines, deltas, breakdown
   ============================================================ */
.stat-card {
  display: grid;
  gap: 4px;
  align-content: start;
}
.stat-spark {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 22px;
  margin-top: 2px;
}
.stat-spark i {
  flex: 1 1 0;
  background: var(--accent);
  height: var(--h, 8%);
  min-height: 2px;
  border-radius: 1px;
  opacity: 0.55;
  transition: opacity var(--duration-fast) var(--ease);
}
.stat-spark i:last-child { opacity: 1; background: var(--accent-bright); }
.stat-card:hover .stat-spark i { opacity: 0.85; }
.stat-card:hover .stat-spark i:last-child { opacity: 1; }

.stat-delta {
  margin-top: 2px;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: 0.04em;
  text-transform: lowercase;
  font-feature-settings: "tnum";
}
.stat-delta.is-up { color: var(--accent-bright); }
.stat-delta.is-down { color: var(--danger); }

/* Most-consulted: tiny play-count bar between title and number. */
.ranked-list li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 80px auto;
  gap: 12px;
  align-items: center;
}
.ranked-bar {
  display: inline-block;
  width: 80px;
  height: 6px;
  background: var(--surface-3);
  border-radius: 3px;
  overflow: hidden;
}
.ranked-bar i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent-soft) 0%, var(--accent) 100%);
}

/* Average-line on the usage chart. */
.usage-chart { position: relative; }
.chart-avg-line {
  position: absolute;
  left: 0;
  right: 0;
  bottom: var(--avg-pct, 50%);
  height: 1px;
  background: linear-gradient(90deg, transparent 0%, var(--accent) 30%, var(--accent) 70%, transparent 100%);
  opacity: 0.55;
  pointer-events: none;
}
.chart-avg-line::after {
  content: "avg";
  position: absolute;
  right: 0;
  top: -16px;
  color: var(--accent);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  opacity: 0.85;
}

/* Category breakdown card. */
.category-breakdown {
  display: grid;
  gap: 10px;
}
.breakdown-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 1fr auto;
  gap: 12px;
  align-items: center;
}
.breakdown-name {
  color: var(--text-bright);
  font-family: var(--serif);
  font-size: var(--type-sm);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.breakdown-bar {
  height: 8px;
  background: var(--surface-3);
  border-radius: 4px;
  overflow: hidden;
}
.breakdown-bar i {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
}
.breakdown-count {
  color: var(--text-bright);
  font-family: var(--mono);
  font-size: var(--type-sm);
  font-weight: 600;
  font-feature-settings: "tnum";
}
.breakdown-empty {
  margin: 0;
  color: var(--text-muted);
  font-family: var(--serif);
  font-style: italic;
  font-size: var(--type-md);
  text-align: center;
}

/* ============================================================
   PHASE 22 — Motion preferences, scrollbars, selection, focus
   ============================================================ */

/* Reduced motion: collapse animation/transition durations to a
   blink so the layout still settles cleanly but no movement
   occurs. Reels keep their spin (it's the visual signal that
   audio is playing) but we pause the tape-shift wash. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .cassette-player.is-playing .cassette-tape { animation: none; }
  .cassette-player.is-playing .cassette-reel { animation-duration: 6s !important; }
  .flower-overlay { display: none; }
}

/* Selection — single rule, theme-aware via the existing token. */
::selection {
  background: var(--selection);
  color: var(--text-bright);
}

/* Custom scrollbars — Firefox + WebKit/Blink. Thin, parchment thumb. */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}
*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
*::-webkit-scrollbar-track {
  background: transparent;
}
*::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 5px;
  border: 2px solid var(--bg);
}
*::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}
*::-webkit-scrollbar-corner { background: transparent; }

/* Skip-link — only visible on focus, but make it land as a
   proper button when keyboard users hit it. */
.skip-link {
  position: absolute;
  top: -40px;
  left: 12px;
  z-index: 100;
  padding: 8px 14px;
  background: var(--accent);
  color: var(--on-accent);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: 0.08em;
  text-decoration: none;
  border-radius: var(--radius);
  border: 1px solid var(--accent);
  transition: top var(--duration-fast) var(--ease);
}
.skip-link:focus,
.skip-link:focus-visible {
  top: 12px;
  outline: 2px solid var(--text-bright);
  outline-offset: 2px;
}

/* ============================================================
   PHASE 23 — Custom audio player (.tape-player)
   Brass play button on the left, parchment progress track
   with a brass-gradient fill and a draggable thumb in the
   middle, mono time readout on the right.
   ============================================================ */
.tape-player {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 8px 10px;
  background: linear-gradient(180deg, var(--surface-2) 0%, var(--surface-1) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: border-color var(--duration-fast) var(--ease);
}
.tape-player.is-playing {
  border-color: var(--line-accent);
}
.tape-play {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  border: 1px solid var(--line-accent);
  border-radius: 50%;
  color: var(--accent-bright);
  font-family: var(--mono);
  font-size: var(--type-md);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease),
              color var(--duration-fast) var(--ease),
              transform var(--duration-fast) var(--ease);
}
.tape-play:hover {
  background: var(--accent);
  color: var(--on-accent);
  transform: scale(1.04);
}
.tape-play:active { transform: scale(0.96); }
.tape-player.is-playing .tape-play {
  background: var(--accent);
  color: var(--on-accent);
}

.tape-progress {
  display: flex;
  align-items: center;
  height: 36px;
  cursor: pointer;
}
.tape-progress-track {
  position: relative;
  width: 100%;
  height: 6px;
  background: var(--surface-3);
  border-radius: 3px;
  overflow: visible;
}
.tape-progress-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-soft) 0%, var(--accent) 100%);
  border-radius: 3px;
  transition: width 80ms linear;
}
.tape-progress-thumb {
  position: absolute;
  top: 50%;
  left: 0%;
  width: 14px;
  height: 14px;
  margin-left: -7px;
  margin-top: -7px;
  background: var(--accent-bright);
  border: 2px solid var(--bg);
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  cursor: grab;
  transition: transform var(--duration-fast) var(--ease);
  touch-action: none;
}
.tape-progress-thumb:hover { transform: scale(1.2); }
.tape-progress-thumb:active { cursor: grabbing; transform: scale(0.95); }

.tape-time {
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: 0.04em;
  font-feature-settings: "tnum", "lnum";
  white-space: nowrap;
}

@media (pointer: coarse) {
  .tape-play { width: 44px; height: 44px; font-size: var(--type-lg); }
  .tape-progress-thumb { width: 18px; height: 18px; margin-left: -9px; margin-top: -9px; }
  .tape-progress-track { height: 8px; }
}

/* ============================================================
   PHASE 24 — Cassette shell J-card + reel fullness + grain
   The reels' inner radius shifts with --reel-fill-left/right
   from JS, so the visible "tape" thickens on one side and
   thins on the other as playback moves through.
   ============================================================ */
.cassette-label {
  position: relative;
  text-align: left;
  padding: 8px 14px;
  letter-spacing: 0.14em;
}
.cassette-label::before {
  content: "A";
  position: absolute;
  top: 6px;
  right: 12px;
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  background: #2a2620;
  color: #f1e6cb;
  border-radius: 50%;
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0;
}
.cassette-label::after {
  content: "";
  position: absolute;
  left: 14px;
  right: 38px;
  bottom: 4px;
  height: 1px;
  background: rgba(74, 53, 34, 0.25);
}
.cassette-tape-name {
  display: inline-block;
  padding-right: 24px;
}

/* Reel inner: radial-gradient with two stops driven by --reel-fill. */
.cassette-reel-left .cassette-reel-inner {
  background:
    radial-gradient(circle at 50% 50%,
      #1c1a16 0%,
      #1c1a16 calc((1 - var(--reel-fill-left, 0.6)) * 50%),
      #5a4a32 calc((1 - var(--reel-fill-left, 0.6)) * 50% + 0.5%),
      #6e5a3c calc((1 - var(--reel-fill-left, 0.6)) * 50% + 12%),
      #2a2620 calc((1 - var(--reel-fill-left, 0.6)) * 50% + 14%),
      #2a2620 100%);
  transition: background 220ms linear;
}
.cassette-reel-right .cassette-reel-inner {
  background:
    radial-gradient(circle at 50% 50%,
      #1c1a16 0%,
      #1c1a16 calc((1 - var(--reel-fill-right, 0.6)) * 50%),
      #5a4a32 calc((1 - var(--reel-fill-right, 0.6)) * 50% + 0.5%),
      #6e5a3c calc((1 - var(--reel-fill-right, 0.6)) * 50% + 12%),
      #2a2620 calc((1 - var(--reel-fill-right, 0.6)) * 50% + 14%),
      #2a2620 100%);
  transition: background 220ms linear;
}

/* Light theme: warmer brass tape. */
:root[data-theme="light"] .cassette-reel-left .cassette-reel-inner {
  background:
    radial-gradient(circle at 50% 50%,
      #2a2620 0%,
      #2a2620 calc((1 - var(--reel-fill-left, 0.6)) * 50%),
      #b18c4a calc((1 - var(--reel-fill-left, 0.6)) * 50% + 0.5%),
      #c79b54 calc((1 - var(--reel-fill-left, 0.6)) * 50% + 12%),
      #1c1a16 calc((1 - var(--reel-fill-left, 0.6)) * 50% + 14%),
      #1c1a16 100%);
}
:root[data-theme="light"] .cassette-reel-right .cassette-reel-inner {
  background:
    radial-gradient(circle at 50% 50%,
      #2a2620 0%,
      #2a2620 calc((1 - var(--reel-fill-right, 0.6)) * 50%),
      #b18c4a calc((1 - var(--reel-fill-right, 0.6)) * 50% + 0.5%),
      #c79b54 calc((1 - var(--reel-fill-right, 0.6)) * 50% + 12%),
      #1c1a16 calc((1 - var(--reel-fill-right, 0.6)) * 50% + 14%),
      #1c1a16 100%);
}

/* Brighten the brass spokes in light theme so they remain visible. */
:root[data-theme="light"] .cassette-reel-inner::before,
:root[data-theme="light"] .cassette-reel-inner::after {
  background: #e8d8a8;
}

/* Tiny screw heads at the bottom corners of the shell. */
.cassette-shell::before,
.cassette-shell::after {
  content: "";
  position: absolute;
  bottom: 6px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #5a4a32 0%, #2a2620 70%);
  border: 1px solid #1a1814;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06) inset;
}
.cassette-shell::before { left: 12px; }
.cassette-shell::after { right: 12px; }

/* Subtle grain on the shell — a tiled SVG noise pattern. */
.cassette-shell {
  background-image:
    linear-gradient(180deg, #2c2924 0%, #1f1d19 100%),
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='80' height='80'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='1.2' numOctaves='2' seed='4'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.05 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  background-blend-mode: overlay;
  background-size: cover, 80px 80px;
}
:root[data-theme="light"] .cassette-shell {
  background-image:
    linear-gradient(180deg, #e6dec8 0%, #cfc3a2 100%),
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='80' height='80'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='1.2' numOctaves='2' seed='4'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.04 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

/* ============================================================
   PHASE 25 — VU meter on the now-playing rail
   Six brass bars; each animates with a different period and
   phase so the cluster reads as organic, not synchronised.
   ============================================================ */
.np-vu {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 16px;
  padding: 0 4px;
}
.np-vu i {
  width: 3px;
  height: 50%;
  background: var(--accent);
  opacity: 0.45;
  border-radius: 1px;
  animation: vu-pulse var(--vu-dur, 0.7s) ease-in-out infinite alternate;
  animation-delay: calc(var(--vu-i, 0) * 80ms);
  animation-play-state: paused;
}
.np-vu i:nth-child(1) { --vu-dur: 0.62s; }
.np-vu i:nth-child(2) { --vu-dur: 0.83s; }
.np-vu i:nth-child(3) { --vu-dur: 0.55s; }
.np-vu i:nth-child(4) { --vu-dur: 0.71s; }
.np-vu i:nth-child(5) { --vu-dur: 0.93s; }
.np-vu i:nth-child(6) { --vu-dur: 0.66s; }
.now-playing-rail.is-vu-playing .np-vu i {
  animation-play-state: running;
}

@keyframes vu-pulse {
  0%   { height: 25%; opacity: 0.4; }
  100% { height: 95%; opacity: 0.95; }
}

@media (prefers-reduced-motion: reduce) {
  .np-vu i {
    animation: none !important;
    height: 50% !important;
    opacity: 0.6;
  }
}

@media (max-width: 880px) {
  .np-vu { display: none; }
}

/* ============================================================
   PHASE 26 — Autoplay-next prompt on the now-playing rail
   ============================================================ */
.np-autoplay {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
  padding: 6px 12px;
  background: var(--accent-soft);
  border: 1px solid var(--line-accent);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: var(--type-xs);
  color: var(--text-dim);
  animation: dialog-rise 200ms var(--ease) both;
}
.np-autoplay-eyebrow {
  color: var(--accent);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
}
.np-autoplay-title {
  color: var(--text-bright);
  font-family: var(--serif);
  font-style: italic;
  font-size: var(--type-sm);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1 1 auto;
  min-width: 0;
}
.np-autoplay-countdown {
  color: var(--accent-bright);
  font-feature-settings: "tnum";
  letter-spacing: 0.06em;
}
.np-autoplay-cancel {
  background: transparent;
  border: 0;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 8px;
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: var(--type-md);
  transition: color var(--duration-fast) var(--ease);
}
.np-autoplay-cancel:hover { color: var(--text-bright); }

/* ============================================================
   PHASE 27 — Cassette bookmarks: pegs on the track + chip row
   ============================================================ */
.tape-player {
  /* Re-declare to add the bookmark add-button column. */
  grid-template-columns: auto 1fr auto auto;
}
.tape-bookmark-add {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--type-sm);
  cursor: pointer;
  transition: color var(--duration-fast) var(--ease),
              border-color var(--duration-fast) var(--ease),
              background var(--duration-fast) var(--ease);
}
.tape-bookmark-add:hover {
  color: var(--accent-bright);
  border-color: var(--line-accent);
  background: var(--accent-soft);
}
.tape-bookmarks {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.tape-bookmark-peg {
  position: absolute;
  top: -3px;
  width: 0;
  height: 0;
  margin-left: -4px;
  background: transparent;
  border: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 7px solid var(--accent-bright);
  cursor: pointer;
  pointer-events: auto;
  transition: transform var(--duration-fast) var(--ease);
  filter: drop-shadow(0 1px 0 var(--bg));
}
.tape-bookmark-peg::after {
  content: "";
  position: absolute;
  top: -7px;
  left: -4px;
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-bottom: 7px solid var(--accent-bright);
  opacity: 0;
  transition: opacity var(--duration-fast) var(--ease);
}
.tape-bookmark-peg:hover { transform: scale(1.3); }
.tape-bookmark-peg:hover::after { opacity: 0.6; }

.tape-bookmarks-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  padding-left: 50px;  /* aligns under the progress track, not the play button */
}
.tape-bookmark-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 4px 2px 8px;
  background: var(--accent-soft);
  border: 1px solid var(--line-accent);
  border-radius: 999px;
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: 0.04em;
  font-feature-settings: "tnum";
}
.tape-bookmark-jump {
  background: transparent;
  border: 0;
  color: var(--accent-bright);
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  padding: 0;
}
.tape-bookmark-jump:hover { color: var(--text-bright); }
.tape-bookmark-remove {
  background: transparent;
  border: 0;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1;
  padding: 0 4px;
  cursor: pointer;
  border-radius: 50%;
  transition: color var(--duration-fast) var(--ease);
}
.tape-bookmark-remove:hover { color: var(--danger); }

@media (max-width: 520px) {
  .tape-bookmarks-list { padding-left: 0; justify-content: center; }
}

/* ============================================================
   PHASE 28 — Offline cassette button
   ============================================================ */
.tape-offline-btn {
  align-self: flex-start;
  margin-top: 8px;
  padding: 4px 12px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: var(--type-xs);
  letter-spacing: 0.04em;
  text-transform: lowercase;
  cursor: pointer;
  transition: color var(--duration-fast) var(--ease),
              border-color var(--duration-fast) var(--ease),
              background var(--duration-fast) var(--ease);
}
.tape-offline-btn:hover {
  color: var(--accent-bright);
  border-color: var(--line-accent);
}
.tape-offline-btn.is-offline {
  color: var(--accent-bright);
  border-color: var(--accent);
  background: var(--accent-soft);
}
.tape-offline-btn:disabled {
  opacity: 0.7;
  cursor: progress;
}

/* ============================================================
   PHASE 31 — Drive (personal cloud)
   Folder + file grid; breadcrumbs; preview lightbox. Borrows
   the parchment/brass system already in use elsewhere — no
   new tokens, just compositions of what's there.
   ============================================================ */

.page-drive { padding-top: 4px; }

.drive-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 12px 0 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.drive-crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px;
  font-family: var(--mono);
  font-size: 0.88rem;
  letter-spacing: 0.02em;
}

.drive-crumb {
  color: var(--text-muted);
  text-decoration: none;
  padding: 2px 6px;
  border-radius: 3px;
  transition: color var(--duration-fast, 160ms), background var(--duration-fast, 160ms);
}
.drive-crumb:hover {
  color: var(--accent);
  background: var(--accent-soft);
}
.drive-crumb.is-current {
  color: var(--text-bright);
  font-weight: 500;
}
.drive-crumb-sep {
  color: var(--text-faint);
  user-select: none;
}

.drive-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.drive-zone {
  position: relative;
  min-height: 260px;
  border: 1px dashed transparent;
  border-radius: 6px;
  padding: 4px;
  transition: border-color var(--duration-fast, 160ms), background var(--duration-fast, 160ms);
}
.drive-zone.is-dropping {
  border-color: var(--line-accent);
  background: var(--accent-soft);
}

.drive-progress {
  font-family: var(--mono);
  font-size: 0.86rem;
  color: var(--accent);
  margin: 0 0 10px;
}
.drive-error {
  font-family: var(--mono);
  font-size: 0.86rem;
  color: var(--danger, #c8553d);
  margin: 0 0 10px;
}

.drive-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  align-items: stretch;
}

.drive-card {
  position: relative;
  display: grid;
  grid-template-rows: auto auto auto;
  gap: 4px;
  padding: 14px 14px 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  text-align: left;
  color: var(--text-bright);
  font-family: inherit;
  cursor: pointer;
  transition: border-color var(--duration-fast, 160ms), transform var(--duration-fast, 160ms), background var(--duration-fast, 160ms);
}
.drive-card:hover {
  border-color: var(--line-accent);
  transform: translateY(-1px);
}
.drive-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.drive-card-folder .drive-card-glyph {
  font-size: 1.6rem;
  color: var(--accent);
  margin-bottom: 4px;
}

.drive-card-thumb {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 92px;
  margin-bottom: 6px;
  background: var(--surface-3);
  border-radius: 3px;
  overflow: hidden;
}
.drive-card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.drive-card-thumb .drive-card-glyph {
  font-size: 1.8rem;
  color: var(--accent);
  opacity: 0.78;
}

.drive-card-name {
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.98rem;
  color: var(--text-bright);
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-word;
}

.drive-card-meta {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-faint);
  letter-spacing: 0.04em;
}

.drive-card-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  opacity: 0;
  transform: translateY(2px);
  transition: opacity var(--duration-fast, 160ms), transform var(--duration-fast, 160ms);
}
.drive-card:hover .drive-card-actions,
.drive-card:focus-within .drive-card-actions {
  opacity: 1;
  transform: translateY(0);
}

.drive-card-action {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 2px 7px;
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  cursor: pointer;
  transition: color var(--duration-fast, 160ms), border-color var(--duration-fast, 160ms), background var(--duration-fast, 160ms);
}
.drive-card-action:hover {
  color: var(--accent);
  border-color: var(--line-accent);
  background: var(--accent-soft);
}
.drive-card-action-danger:hover {
  color: var(--danger, #c8553d);
  border-color: rgba(200, 85, 61, 0.35);
  background: rgba(200, 85, 61, 0.06);
}

/* ---- Preview lightbox ---- */

.drive-preview {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(8, 8, 8, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 36px;
  backdrop-filter: blur(2px);
}

.drive-preview-card {
  width: min(960px, 100%);
  max-height: calc(100vh - 72px);
  background: var(--surface-1);
  border: 1px solid var(--line-accent);
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.drive-preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.drive-preview-text { min-width: 0; }
.drive-preview-eyebrow {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  text-transform: lowercase;
  margin: 0 0 2px;
}
.drive-preview-title {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.15rem;
  color: var(--text-bright);
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drive-preview-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.drive-preview-body {
  flex: 1;
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--surface-3);
  overflow: auto;
}

.drive-preview-image,
.drive-preview-video {
  max-width: 100%;
  max-height: 70vh;
  display: block;
}

.drive-preview-audio {
  width: min(560px, 100%);
}

.drive-preview-frame {
  width: 100%;
  height: 70vh;
  border: 0;
  background: #fff;
}

.drive-preview-pre {
  width: 100%;
  max-height: 70vh;
  overflow: auto;
  margin: 0;
  padding: 14px 18px;
  font-family: var(--mono);
  font-size: 0.84rem;
  background: var(--surface-1);
  color: var(--text-bright);
  border: 1px solid var(--line);
  border-radius: 3px;
  white-space: pre-wrap;
  word-break: break-word;
}

.drive-preview-fallback {
  font-family: var(--serif);
  font-style: italic;
  color: var(--text-muted);
  text-align: center;
  margin: 0;
}

@media (max-width: 760px) {
  .drive-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
  }
  .drive-card-thumb { height: 72px; }
  .drive-preview { padding: 12px; }
  .drive-preview-head { padding: 10px 12px; }
  .drive-card-actions {
    /* Touch: actions always visible — there's no hover. */
    opacity: 1;
    transform: none;
  }
}

/* ============================================================
   PHASE 29 — Print stylesheet
   Hide chrome; serif throughout; brass becomes black; thin
   page-break rules so multi-plate prints don't split mid-card.
   ============================================================ */
@media print {
  /* Drop colour everywhere — printers handle black ink better. */
  :root, :root[data-theme="dark"], :root[data-theme="light"] {
    --bg: #ffffff;
    --surface-1: #ffffff;
    --surface-2: #ffffff;
    --surface-3: #f4f4f0;
    --text: #1a1a18;
    --text-bright: #000000;
    --text-dim: #2a2a26;
    --text-muted: #4a4a44;
    --text-faint: #6a6a64;
    --accent: #6a4a18;
    --accent-bright: #4a3010;
    --accent-soft: rgba(106, 74, 24, 0.08);
    --line: rgba(0, 0, 0, 0.18);
    --line-strong: rgba(0, 0, 0, 0.36);
    --line-accent: rgba(106, 74, 24, 0.45);
    color-scheme: light;
  }
  body {
    background: #ffffff !important;
    color: #000000;
    font-family: var(--serif);
  }

  /* Chrome that doesn't print. */
  .masthead, .library-nav, .now-playing-rail,
  .curator-chip, .skip-link,
  .auth-gate, .preview-modal, .question-modal, .plate-lightbox,
  .search-overlay, .cheat-sheet, .toast-region,
  .modal-host, .flower-overlay,
  .page-sidebar, .upload-zone, .upload-category-strip,
  .drive-preview, .drive-toolbar, .drive-zone,
  .recording-audio, .tape-player, .tape-bookmarks-list, .tape-offline-btn,
  .cassette-player, .marginalia-composer, .marginalia-kind-toggle,
  .practice-strip, .practice-button, .practice-heatmap,
  .activity-line, .todays-plate, .hall-quote,
  .chronicle-filters, .chronicle-tools .page-count,
  .library-toolbar, .shelf-tools, .bulk-actions,
  .folio-actions, .plate-actions, .recording-actions,
  .form-actions, .empty-action, .empty-art,
  .stat-spark, .stat-delta, .ranked-bar, .chart-avg-line,
  .vellum-foot, .hall-rule, .question-streak,
  .video-actions { display: none !important; }

  .page { display: block !important; }
  .page[hidden] { display: none !important; }

  /* Tight page setup. */
  @page { margin: 0.6in 0.5in; }
  .vellum { padding: 0 !important; }

  /* Typography — black on white, serif. */
  h1, h2, h3, h4 { color: #000; font-family: var(--serif); }
  p, li, span { color: #1a1a18; }

  /* Plates — each card prints in full, page break between. */
  .plate-grid { display: block !important; }
  .plate-card {
    page-break-inside: avoid;
    margin: 0 0 24pt;
    padding: 12pt 0 12pt 0;
    border-bottom: 0.5pt solid #888;
  }
  .plate-thumb {
    aspect-ratio: auto;
    border: 0;
    box-shadow: none;
    transform: none !important;
  }
  .plate-image {
    max-width: 100%;
    max-height: 6in;
    object-fit: contain;
    border: 0.5pt solid #ccc;
  }
  .plate-number { position: static; background: transparent; color: #000; padding: 0; margin: 0 0 4pt; }
  .plate-caption { color: #000; font-style: italic; }
  .plate-questions-badge { background: transparent; color: #000; border: 0.5pt solid #888; }

  /* Folio (volume) entries — printed as paragraphs. */
  .folio-list { list-style: none; padding: 0; }
  .folio-item {
    page-break-inside: avoid;
    margin: 0 0 14pt;
    padding: 8pt 0;
    border-bottom: 0.25pt solid #ccc;
  }
  .folio-title { color: #000; font-weight: 600; }
  .folio-notes { color: #1a1a18; font-style: italic; }
  .folio-meta { color: #4a4a44; font-family: var(--mono); font-size: 9pt; }

  /* Recordings — print title, meta, notes, marginalia. */
  .recording-list { list-style: none; padding: 0; }
  .recording-item {
    page-break-inside: avoid;
    margin: 0 0 14pt;
    padding: 8pt 0;
    border: 0;
    border-bottom: 0.25pt solid #ccc;
  }
  .recording-title { font-style: italic; }
  .marginalia-strip {
    border-top: 0.25pt solid #ccc;
    margin-top: 6pt;
    padding-top: 6pt;
  }
  .marginalia-entry { page-break-inside: avoid; }

  /* Chronicle — day groups stay together. */
  .chronicle-day { page-break-inside: avoid; margin-bottom: 16pt; }
  .chronicle-day-head { border-bottom: 0.5pt solid #888; }
  .chronicle-glyph { background: transparent; border: 0.5pt solid #888; }

  /* Ledger — stat cards print as a row of headings. */
  .ledger-grid { display: grid !important; grid-template-columns: repeat(4, 1fr); gap: 12pt; }
  .stat-card { border: 0.25pt solid #ccc; padding: 8pt; page-break-inside: avoid; }

  /* No hover styles in print. */
  *:hover, *:focus, *:focus-visible {
    background: transparent !important;
    border-color: inherit !important;
    box-shadow: none !important;
    outline: none !important;
  }
}
