/* ====================================================================
 * study-café — the palette and furniture, carried over from Liffy.
 *
 * Same two-attribute scheme as the app: `data-theme` picks the palette,
 * `.light`/`.dark` carries the polarity. The boot script in index.html sets
 * both before first paint so there is no flash.
 *
 * Values are Liffy's measured ones, not re-picked: the contrast ratios in
 * the comments were earned there and still hold here.
 * ==================================================================== */

:root,
[data-theme="paper"] {
  color-scheme: light;

  --paper: #f0ece3;
  --card: #fbf9f5;
  --recessed: #e4dfd3;
  --rule: #c5bca9;
  --rule-strong: #a89e8b;
  --shadow-edge: #bdb3a0;

  --ink: #2b2925;      /* 10.9:1 */
  --ink-dim: #524b3e;  /*  6.5:1 */
  --ink-sub: #696154;  /*  4.6:1 */

  --oxide: #9a3f2b;    /* critical · missed */
  --sage: #456646;     /* solved · complete */
  --ochre: #775b17;    /* warning · read-only */
  --payne: #3b5670;    /* info */

  --tint-mix: 18%;
  --oxide-tint: color-mix(in oklab, var(--oxide) var(--tint-mix), var(--card));
  --sage-tint: color-mix(in oklab, var(--sage) var(--tint-mix), var(--card));
  --ochre-tint: color-mix(in oklab, var(--ochre) var(--tint-mix), var(--card));
  --payne-tint: color-mix(in oklab, var(--payne) var(--tint-mix), var(--card));
  --neutral-tint: #ece7dc;

  --chrome: #2b2925;
  --chrome-ink: #f0ece3;
  --chrome-ink-dim: #a49b8a;
  --chrome-rule: #524a40;
  --chrome-active: #3b3730;

  /* The scene. Mixed out of the palette rather than written as hexes, so the
     room themes itself — exactly as the café does in Liffy. */
  --scene-wall: color-mix(in oklab, var(--recessed) 35%, var(--card));
  --scene-wall-lo: color-mix(in oklab, var(--recessed) 70%, var(--card));
  --scene-line: var(--rule);
  --scene-rule: var(--rule-strong);
  --scene-frame: var(--ink-sub);
  --scene-frame-hi: var(--ink-dim);
  --scene-ink: var(--ink);
  --scene-glass: color-mix(in oklab, var(--payne) 20%, var(--card));
  --scene-glass-lo: color-mix(in oklab, var(--ochre) 24%, var(--card));
  --scene-cloud: color-mix(in oklab, var(--ochre) 32%, var(--card));
  --scene-far: color-mix(in oklab, var(--payne) 58%, var(--card));
  --scene-ground: color-mix(in oklab, var(--sage) 30%, var(--card));
  --scene-tree: color-mix(in oklab, var(--sage) 55%, var(--card));
  --scene-warm: color-mix(in oklab, var(--ochre) 45%, var(--card));
  --scene-glow: color-mix(in oklab, var(--ochre) 22%, var(--card));
  --scene-steam: color-mix(in oklab, var(--ink-sub) 18%, var(--card));

  /* --- the café's own materials -------------------------------------
     Every one is mixed out of the four palette inks, so the room themes
     itself: redefining --card and --ochre under graphite re-resolves all
     of these at computed-value time, and none of them needs a second
     copy in the dark block. */
  --scene-wood: color-mix(in oklab, var(--ochre) 38%, var(--card));
  --scene-wood-hi: color-mix(in oklab, var(--ochre) 24%, var(--card));
  --scene-wood-lo: color-mix(in oklab, var(--ochre) 52%, var(--recessed));
  --scene-brass: color-mix(in oklab, var(--ochre) 72%, var(--card));
  --scene-steel: color-mix(in oklab, var(--payne) 30%, var(--recessed));
  --scene-steel-hi: color-mix(in oklab, var(--payne) 14%, var(--card));

  /* Depth inside the casework. Built from --recessed and --rule-strong
     because those two are the only pair that stays darker than --card in
     both polarities — anything mixed toward --ink inverts, and the shelf
     backs came out lighter than the shelves under a light theme. */
  --scene-hollow: color-mix(in oklab, var(--recessed) 58%, var(--rule-strong));

  /* The cat — the one thing in the room written as literal colour.
     Every other material is mixed from the palette so it re-themes, but
     --ink inverts between polarities, and a cat derived from it came out
     black on paper and white on graphite: two different animals. A ginger
     cat is ginger in any light. Three flat tones is all a forty-pixel
     animal can carry, and they hold 3:1 or better against both walls. */
  --scene-cat: #9a6330;
  --scene-cat-hi: #d8a86b;
  --scene-cat-lo: #663c1a;

  --scene-rug: color-mix(in oklab, var(--oxide) 42%, var(--card));
  --scene-rug-alt: color-mix(in oklab, var(--oxide) 24%, var(--card));
  --scene-chalk: color-mix(in oklab, var(--sage) 34%, var(--recessed));

  /* Five spines. Enough that a full shelf has rhythm, few enough that it
     still reads as one library rather than a paint chart. */
  --scene-book-a: color-mix(in oklab, var(--oxide) 62%, var(--card));
  --scene-book-b: color-mix(in oklab, var(--sage) 66%, var(--card));
  --scene-book-c: color-mix(in oklab, var(--ochre) 58%, var(--card));
  --scene-book-d: color-mix(in oklab, var(--payne) 60%, var(--card));
  --scene-book-e: color-mix(in oklab, var(--ink) 55%, var(--card));

  /* Sky, by the clock rather than by the theme — a café at seven in the
     morning is a different room from the same café at ten at night, and
     that is most of what makes it feel like a place. */
  --scene-sky-dawn: color-mix(in oklab, var(--oxide) 26%, var(--card));
  --scene-sky-day: color-mix(in oklab, var(--payne) 22%, var(--card));
  --scene-sky-dusk: color-mix(in oklab, var(--oxide) 40%, var(--card));
  --scene-sky-night: color-mix(in oklab, var(--payne) 62%, var(--recessed));
  --scene-sun: color-mix(in oklab, var(--ochre) 66%, var(--card));
}

[data-theme="graphite"] {
  color-scheme: dark;

  --paper: #1d1b18;
  --card: #28251f;
  --recessed: #141311;
  --rule: #423d36;
  --rule-strong: #5a5349;
  --shadow-edge: #0d0c0a;

  --ink: #e6e1d6;      /* 11.7:1 */
  --ink-dim: #b2a898;  /*  6.5:1 */
  --ink-sub: #958c7c;  /*  4.6:1 */

  --oxide: #dd8462;
  --sage: #7ba171;
  --ochre: #bd9433;
  --payne: #84a5c2;

  --neutral-tint: #34302a;

  --chrome: #151310;
  --chrome-ink: #e6e1d6;
  --chrome-ink-dim: #948a78;
  --chrome-rule: #403a32;
  --chrome-active: #242019;
}

/* Follow the OS only when no explicit choice is stored. The boot script
   stamps data-theme, so this block just decides the default. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="paper"]) {
    color-scheme: dark;
    --paper: #1d1b18; --card: #28251f; --recessed: #141311;
    --rule: #423d36; --rule-strong: #5a5349; --shadow-edge: #0d0c0a;
    --ink: #e6e1d6; --ink-dim: #b2a898; --ink-sub: #958c7c;
    --oxide: #dd8462; --sage: #7ba171; --ochre: #bd9433; --payne: #84a5c2;
    --neutral-tint: #34302a;
    --chrome: #151310; --chrome-ink: #e6e1d6; --chrome-ink-dim: #948a78;
    --chrome-rule: #403a32; --chrome-active: #242019;
  }
}

/* ==================================================================== *
 * Type. Monaspace first — if you copy the woff2 files from Liffy into
 * assets/fonts/ and add the @font-face rules, the whole site upgrades
 * with no other change. Until then the OS mono stack carries it.
 * ==================================================================== */
:root {
  --f-ui: "Monaspace Neon", ui-monospace, "SF Mono", "Cascadia Mono",
    "Roboto Mono", Menlo, Consolas, monospace;
  --f-hand: "Monaspace Argon", var(--f-ui);

  /* Prose gets a reading face, not the UI's mono.
     The first pass set all 4,800 lines of notes in Monaspace, which is the
     right call for a dev tool's chrome and the wrong one for a document:
     with every word the same width there is no hierarchy for the eye to
     use, and the page reads as one undifferentiated texture. A serif also
     happens to suit a library. Code, tables and inline code stay mono —
     that is where fixed width is doing actual work. */
  --f-read: "Iowan Old Style", "Palatino Linotype", Palatino, Charter,
    "Bitstream Charter", Georgia, ui-serif, serif;

  --page: 88rem;
  --measure: 34rem;
  --rail: 13.5rem;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--f-ui);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--ink); color: var(--paper); }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

a { color: inherit; text-decoration-color: var(--rule-strong); text-underline-offset: 2px; }
a:hover { text-decoration-color: var(--ink); }

h1, h2, h3, h4 { font-weight: 600; letter-spacing: -0.01em; line-height: 1.2; margin: 0; }

.lbl {
  font-size: 0.66rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ink-sub);
  margin: 0;
}

.dim { color: var(--ink-dim); }
.sub { color: var(--ink-sub); }

/* ==================================================================== *
 * Shell — inked rail + page, the Liffy arrangement.
 * ==================================================================== */
.shell { display: flex; min-height: 100%; }

.rail {
  position: sticky;
  top: 0;
  align-self: flex-start;
  height: 100vh;
  width: var(--rail);
  flex: 0 0 var(--rail);
  background: var(--chrome);
  color: var(--chrome-ink);
  border-right: 1px solid var(--chrome-rule);
  display: flex;
  flex-direction: column;
  padding: 1rem 0;
}

.rail-mark {
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0 1rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-bottom: 1px solid var(--chrome-rule);
}

.rail nav { padding: 0.75rem 0.5rem; display: flex; flex-direction: column; gap: 1px; }

.rail nav a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.44rem 0.6rem;
  color: var(--chrome-ink-dim);
  text-decoration: none;
  border-radius: 2px;
  font-size: 0.82rem;
}
.rail nav a:hover { background: var(--chrome-active); color: var(--chrome-ink); }
.rail nav a[aria-current="page"] { background: var(--chrome-active); color: var(--chrome-ink); }

.rail-foot { margin-top: auto; padding: 0.75rem 1rem 0; border-top: 1px solid var(--chrome-rule); }

/* The track switcher. Present only when config.js lists more than one track,
   so the single-track case keeps the rail as bare as it was. */
.track-pick { margin-bottom: 0.6rem; }
.track-pick .lbl { display: block; margin-bottom: 0.25rem; color: var(--chrome-ink-dim); }
.track-pick select {
  width: 100%;
  font: inherit;
  font-size: 0.78rem;
  padding: 0.3rem 0.4rem;
  color: var(--chrome-ink);
  background: color-mix(in oklab, var(--chrome-ink) 8%, transparent);
  border: 1px solid var(--chrome-rule);
  border-radius: 3px;
}

.page { flex: 1; min-width: 0; }
.page-in { max-width: var(--page); margin: 0 auto; padding: 1.75rem clamp(1rem, 3vw, 2.25rem) 5rem; }

/* ==================================================================== *
 * Surfaces. A hard 2px shadow, no blur — the printed look.
 * ==================================================================== */
.card {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 3px;
}
.card.raised { box-shadow: 2px 2px 0 var(--shadow-edge); }

.card-h {
  background: var(--recessed);
  border-bottom: 1px solid var(--rule);
  padding: 0.5rem 0.85rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.card-b { padding: 0.85rem; }

.grid { display: grid; gap: 0.85rem; }
.cols-2 { grid-template-columns: 1fr 1fr; }
.today-btm.cols-2 { grid-template-columns: 1.75fr 1fr; }
@media (max-width: 74rem) { .today-btm.cols-2 { grid-template-columns: 1fr; } }
/* The scene leads, the timer sits beside it. Giving the room roughly two
   thirds is what takes it from 1.1× to about 1.5×, which is the difference
   between "there is a cat there" and being able to see the cat. */
.today-top { display: grid; grid-template-columns: 1.75fr 1fr; gap: 0.85rem; align-items: start; }
@media (max-width: 74rem) { .today-top { grid-template-columns: 1fr; } }
@media (max-width: 62rem) { .cols-2 { grid-template-columns: 1fr; } }

/* ==================================================================== *
 * Controls
 * ==================================================================== */
button, .btn {
  font: inherit;
  font-size: 0.82rem;
  padding: 0.32rem 0.7rem;
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--rule-strong);
  border-radius: 2px;
  cursor: pointer;
  white-space: nowrap;
}
button:hover, .btn:hover { background: var(--neutral-tint); }
button:active { transform: translate(1px, 1px); }
button.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
button.primary:hover { background: var(--ink-dim); }
button.ghost { background: transparent; border-color: transparent; color: var(--ink-dim); }
button.ghost:hover { background: var(--neutral-tint); color: var(--ink); }
button:disabled { opacity: 0.45; cursor: not-allowed; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.66rem;
  letter-spacing: 0.06em;
  padding: 0.1rem 0.35rem;
  border-radius: 2px;
  background: var(--neutral-tint);
  color: var(--ink-dim);
  border: 1px solid var(--rule);
}
/* Tier chips are coloured by *tone*, not by tier name: a track picks one of
   these five words per tier and gets a colour that already holds its contrast
   in both polarities. Naming a hex in a track file is how forks end up with
   an unreadable chip on one theme. */
.chip.tone-neutral { background: var(--neutral-tint); }
.chip.tone-cool  { background: var(--payne-tint); color: var(--payne); border-color: color-mix(in oklab, var(--payne) 30%, transparent); }
.chip.tone-warm  { background: var(--ochre-tint); color: var(--ochre); border-color: color-mix(in oklab, var(--ochre) 30%, transparent); }
.chip.tone-alert { background: var(--oxide-tint); color: var(--oxide); border-color: color-mix(in oklab, var(--oxide) 30%, transparent); }
.chip.tone-good  { background: var(--sage-tint); color: var(--sage); border-color: color-mix(in oklab, var(--sage) 30%, transparent); }
/* Status chips share the row colours, so a SOLVED chip and a solved row are
   the same green rather than two different greens. */
.chip.st-SOLVED { background: var(--sage-tint); color: var(--sage); border-color: color-mix(in oklab, var(--sage) 30%, transparent); }
.chip.st-HINT   { background: var(--payne-tint); color: var(--payne); border-color: color-mix(in oklab, var(--payne) 30%, transparent); }
.chip.st-READ   { background: var(--ochre-tint); color: var(--ochre); border-color: color-mix(in oklab, var(--ochre) 30%, transparent); }
.chip.st-FAIL   { background: var(--oxide-tint); color: var(--oxide); border-color: color-mix(in oklab, var(--oxide) 30%, transparent); }

/* ==================================================================== *
 * Problem rows — the tracker's core object.
 * ==================================================================== */
.prob {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--rule);
}
.prob:last-child { border-bottom: 0; }
.prob:hover { background: var(--neutral-tint); }
.prob-id { color: var(--ink-sub); font-size: 0.76rem; min-width: 2.6rem; }
.prob-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prob-name a { text-decoration: none; }
.prob-name a:hover { text-decoration: underline; }
.prob[data-status="SOLVED"] .prob-name { color: var(--sage); }
.prob[data-status="READ"] .prob-name { color: var(--ochre); }
.prob[data-status="FAIL"] .prob-name { color: var(--oxide); }
.prob[data-status="SOLVED"] .prob-name a { text-decoration: line-through; text-decoration-color: color-mix(in oklab, var(--sage) 50%, transparent); }

/* Four-state cycle button. Deliberately not a checkbox: READ is not a
   half-checked SOLVED, it is a different fact, and the plan turns on the
   difference. */
.cyc {
  width: 4.6rem;
  text-align: center;
  font-size: 0.64rem;
  letter-spacing: 0.08em;
  padding: 0.16rem 0;
}
.cyc[data-v=""]       { color: var(--ink-sub); }
.cyc[data-v="SOLVED"] { background: var(--sage-tint); color: var(--sage); border-color: color-mix(in oklab, var(--sage) 40%, transparent); }
.cyc[data-v="HINT"]   { background: var(--payne-tint); color: var(--payne); border-color: color-mix(in oklab, var(--payne) 40%, transparent); }
.cyc[data-v="READ"]   { background: var(--ochre-tint); color: var(--ochre); border-color: color-mix(in oklab, var(--ochre) 40%, transparent); }
.cyc[data-v="FAIL"]   { background: var(--oxide-tint); color: var(--oxide); border-color: color-mix(in oklab, var(--oxide) 40%, transparent); }

/* ==================================================================== *
 * Meters — a filled bar with a hairline, not a rounded pill.
 * ==================================================================== */
.meter { height: 6px; background: var(--recessed); border: 1px solid var(--rule); border-radius: 1px; overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--sage); transition: width 0.4s ease; }
.meter.warm > i { background: var(--ochre); }

/* ==================================================================== *
 * The scene
 * ==================================================================== */
.scene-wrap {
  position: relative;
  border: 1px solid var(--rule);
  border-radius: 3px;
  overflow: hidden;
  background: var(--scene-wall);
  box-shadow: 2px 2px 0 var(--shadow-edge);
}
.scene-wrap canvas {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
}
/* Below the canvas, not over it. Floated on top it sat exactly on the floor
   line and hid the desk, the lamp and the cup — every part of the picture
   that moves. */
.scene-cap {
  padding: 0.5rem 0.75rem;
  background: var(--recessed);
  border-top: 1px solid var(--rule);
  font-size: 0.76rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

/* ==================================================================== *
 * Timer
 * ==================================================================== */
.timer-face {
  font-size: clamp(2.4rem, 7vw, 3.6rem);
  line-height: 1;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}
.timer-face.over { color: var(--oxide); }
.blocks { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.blocks button { display: flex; flex-direction: column; align-items: flex-start; gap: 0.1rem; min-width: 5.6rem; }
.blocks button[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.blocks button b { font-weight: 600; font-size: 0.8rem; }
.blocks button span { font-size: 0.64rem; opacity: 0.75; }
.blocks button.done { border-color: var(--sage); }
.blocks button.done b::after { content: " ✓"; color: var(--sage); }
.blocks button[aria-pressed="true"].done b::after { color: var(--paper); }

/* The escalation ladder, shown while Block C runs. */
.ladder { display: flex; gap: 0; margin-top: 0.6rem; border: 1px solid var(--rule); border-radius: 2px; overflow: hidden; }
.ladder div { flex: 1; padding: 0.4rem 0.55rem; font-size: 0.7rem; border-right: 1px solid var(--rule); background: var(--card); }
.ladder div:last-child { border-right: 0; }
.ladder div.on { background: var(--ochre-tint); color: var(--ochre); }
.ladder div.on:last-child { background: var(--oxide-tint); color: var(--oxide); }
.ladder b { display: block; font-size: 0.64rem; letter-spacing: 0.08em; text-transform: uppercase; opacity: 0.8; }

/* ==================================================================== *
 * Notes reader
 * ==================================================================== */
/* Notebook layout: a contents rail, a hard rule, then the page — with the
   text set in from that rule the way a ruled notebook's margin works. The
   two columns previously just floated in whitespace with nothing marking
   where one ended and the other began. No paper texture: the *structure* is
   the notebook, not a background image. */
.reader { display: grid; grid-template-columns: 16rem minmax(0, 1fr); align-items: start; }
.reader > .doc {
  border-left: 1px solid var(--rule);
  padding-left: clamp(1.5rem, 4vw, 3.25rem);
  position: relative;
}
/* The margin rule. Sits inside the page, not at its edge, so the heading
   numbers can hang to the left of it. */
.reader > .doc::before {
  content: "";
  position: absolute;
  top: 0; bottom: 0;
  left: clamp(0.9rem, 2.4vw, 2rem);
  width: 1px;
  background: color-mix(in oklab, var(--oxide) 35%, transparent);
}
@media (max-width: 68rem) {
  .reader { grid-template-columns: 1fr; gap: 1rem; }
  .reader > .doc { border-left: 0; padding-left: 1.25rem; }
  .reader > .doc::before { left: 0; }
}

/* --- contents ------------------------------------------------------
   Two lists, not one flat wall of 360 links: the eleven sections always,
   and the headings of the section you are actually in. The first pass
   printed every section title in full at body size and the sidebar became
   a second document to read before you could read the document. */
.toc { position: sticky; top: 0; max-height: 100vh; overflow: auto; padding: 1.75rem 1.25rem 2rem 0; font-size: 0.78rem; line-height: 1.45; }
.toc::-webkit-scrollbar { width: 6px; }
.toc::-webkit-scrollbar-thumb { background: var(--rule); border-radius: 3px; }
.toc a {
  display: block;
  padding: 0.22rem 0.5rem;
  color: var(--ink-dim);
  text-decoration: none;
  border-left: 2px solid transparent;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.toc a:hover { color: var(--ink); background: var(--neutral-tint); }
.toc a.sec.on { color: var(--ink); background: var(--neutral-tint); border-left-color: var(--ink); font-weight: 600; }
/* Scroll-spy: the heading you are currently under. */
.toc a.here { color: var(--ink); border-left-color: var(--ochre); }
.toc a[data-l="2"] { padding-left: 0.85rem; }
.toc a[data-l="3"] { padding-left: 1.6rem; font-size: 0.74rem; color: var(--ink-sub); }
.toc .lbl { padding: 0 0.5rem; margin: 1.1rem 0 0.35rem; }
.toc .lbl:first-child { margin-top: 0; }

/* --- the document --------------------------------------------------- */
/* Wide container, narrow prose. Tables and code listings want the room —
   several of the notes' tables have three columns of prose — while running
   text past about 75 characters gets hard to track back from. One measure
   for both would have to lose one of them. */
.doc {
  max-width: 46rem;
  font-family: var(--f-read);
  font-size: 1.06rem;
  line-height: 1.66;
  padding: 1.5rem 0 6rem;
  text-wrap: pretty;
}
.doc > :first-child { margin-top: 0; }

.doc h1, .doc h2, .doc h3, .doc h4 { font-family: var(--f-ui); letter-spacing: -0.015em; }
.doc h1 {
  font-size: 1.55rem;
  line-height: 1.2;
  margin: 0 0 1.5rem;
  padding-bottom: 0.7rem;
  border-bottom: 2px solid var(--ink);
}
.doc h2 {
  font-size: 1.12rem;
  margin: 2.6rem 0 0.6rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--rule);
}
.doc h3 {
  font-size: 0.76rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-sub);
  margin: 1.9rem 0 0.5rem;
}
.doc h4 { font-size: 0.92rem; margin: 1.3rem 0 0.35rem; color: var(--ink-dim); }

.doc p, .doc ul, .doc ol, .doc blockquote, .doc h3, .doc h4 { max-width: var(--measure); }
.doc p { margin: 0.9rem 0; }
.doc ul, .doc ol { margin: 0.9rem 0; padding-left: 1.35rem; }
.doc li { margin: 0.35rem 0; }
.doc li::marker { color: var(--ink-sub); }
.doc hr { border: 0; border-top: 1px solid var(--rule); margin: 2.4rem 0; }
.doc strong { font-weight: 700; }

/* A quote is a change of voice, not a slab. The heavy filled block read as
   a code sample at a glance, which is exactly wrong for the summaries these
   actually hold. */
.doc blockquote {
  margin: 1.2rem 0;
  padding: 0.1rem 0 0.1rem 1.1rem;
  border-left: 2px solid var(--ochre);
  color: var(--ink-dim);
  font-style: italic;
}
.doc blockquote strong { font-style: normal; }
.doc blockquote > :first-child { margin-top: 0; }
.doc blockquote > :last-child { margin-bottom: 0; }

.doc code {
  font-family: var(--f-ui);
  background: var(--neutral-tint);
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 0.05em 0.3em;
  font-size: 0.82em;
  /* pre-wrap keeps the internal spacing of a snippet, and anywhere lets a
     genuinely long one break rather than push the page sideways. `nowrap`
     was right for `a[i]` and wrong for
     `vector<vector<int>> memo(n, vector<int>(m, -1))`, which at 404px was
     the only thing overflowing a 375px phone. */
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.doc .code {
  font-family: var(--f-ui);
  background: var(--recessed);
  border: 1px solid var(--rule);
  border-left: 2px solid var(--rule-strong);
  border-radius: 3px;
  padding: 0.85rem 1rem;
  overflow-x: auto;
  margin: 1.1rem 0;
  font-size: 0.79rem;
  line-height: 1.6;
  position: relative;
}
.doc .code::before {
  content: attr(data-lang);
  position: absolute;
  top: 0; right: 0;
  padding: 0.1rem 0.45rem;
  font-size: 0.6rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-sub);
  background: var(--neutral-tint);
  border-left: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  border-radius: 0 3px 0 3px;
}
.doc .code[data-lang="text"]::before { content: none; }
.doc .code code { background: none; border: 0; padding: 0; font-size: inherit; white-space: pre; }

.doc .tw {
  overflow-x: auto;
  margin: 1.2rem 0;
  max-width: 100%;
  border: 1px solid var(--rule);
  border-radius: 3px;
}
.doc table { border-collapse: collapse; font-family: var(--f-ui); font-size: 0.78rem; width: 100%; }
.doc th, .doc td { padding: 0.42rem 0.7rem; text-align: left; vertical-align: top; border-bottom: 1px solid var(--rule); }
.doc td + td, .doc th + th { border-left: 1px solid var(--rule); }
.doc tbody tr:last-child td { border-bottom: 0; }
.doc tbody tr:nth-child(even) { background: color-mix(in oklab, var(--recessed) 45%, transparent); }
.doc th { background: var(--recessed); font-weight: 600; white-space: nowrap; color: var(--ink); }
.doc td code { white-space: normal; }

/* Anything the router jumps to lands below the top edge rather than flush
   against it — flush was the "cuts off at an awkward scroll position" bug. */
.doc h1, .doc h2, .doc h3, .doc h4 { scroll-margin-top: 1.75rem; }

.doc :target { animation: flash 1.6s ease-out; }
@keyframes flash {
  from { background: var(--ochre-tint); box-shadow: -0.6rem 0 0 var(--ochre-tint), 0.6rem 0 0 var(--ochre-tint); }
  to { background: transparent; box-shadow: none; }
}

/* ==================================================================== *
 * Log
 * ==================================================================== */
.field { display: block; margin: 0.55rem 0; }
.field span { display: block; font-size: 0.68rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-sub); margin-bottom: 0.2rem; }
input[type="text"], textarea, select {
  font: inherit;
  font-size: 0.84rem;
  width: 100%;
  padding: 0.35rem 0.5rem;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--rule-strong);
  border-radius: 2px;
}
textarea { resize: vertical; min-height: 3.5rem; line-height: 1.5; }

.entry { border-bottom: 1px solid var(--rule); padding: 0.7rem 0.85rem; }
.entry:last-child { border-bottom: 0; }
.entry h4 { font-size: 0.86rem; display: flex; align-items: center; gap: 0.5rem; }
.entry dl { margin: 0.4rem 0 0; display: grid; grid-template-columns: 8rem 1fr; gap: 0.15rem 0.75rem; font-size: 0.8rem; }
.entry dt { color: var(--ink-sub); font-size: 0.68rem; letter-spacing: 0.06em; text-transform: uppercase; padding-top: 0.15rem; }
.entry dd { margin: 0; }

.due { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; padding: 0.35rem 0.6rem; border-bottom: 1px solid var(--rule); font-size: 0.82rem; }
.due:last-child { border-bottom: 0; }
.due.overdue { background: var(--ochre-tint); }

.empty { padding: 1.5rem 0.85rem; text-align: center; color: var(--ink-sub); font-size: 0.82rem; }

/* ==================================================================== *
 * Motion. Liffy's two, and nothing else — the whole vocabulary is a blink
 * and a caret. Everything sits behind the reduced-motion gate.
 * ==================================================================== */
.blip { display: inline-block; width: 6px; height: 6px; background: var(--sage); flex: 0 0 auto; }
.blip.warm { background: var(--ochre); }
.blip.cold { background: var(--ink-sub); }
.caret { display: inline-block; width: 0.55em; height: 1.05em; background: currentColor; vertical-align: -0.18em; margin-left: 0.1em; }

@media (prefers-reduced-motion: no-preference) {
  .blip { animation: blip 1.8s ease-in-out infinite; }
  .caret { animation: caret 1s steps(1) infinite; }
  .rise { animation: rise 0.4s ease both; }
}
@keyframes blip { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
@keyframes caret { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.row { display: flex; align-items: center; gap: 0.6rem; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 0.85rem; }
.tnum { font-variant-numeric: tabular-nums; }

@media (max-width: 48rem) {
  .rail { position: static; height: auto; width: 100%; flex: none; }
  .shell { flex-direction: column; }
  .rail nav { flex-direction: row; flex-wrap: wrap; }
  .rail-foot { margin-top: 0.5rem; }
}


/* ==================================================================== *
 * Turntable
 * ==================================================================== */
.vinyl {
  width: 150px;
  height: 150px;
  flex: 0 0 auto;
  image-rendering: pixelated;
}
.track {
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.track-sub { font-size: 0.74rem; margin-top: 0.15rem; }
.vol { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.6rem; }
.vol input[type="range"] {
  flex: 1;
  min-width: 0;
  width: auto;
  padding: 0;
  height: 4px;
  border: 0;
  border-radius: 2px;
  background: var(--rule);
  appearance: none;
  -webkit-appearance: none;
}
.vol input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 10px; height: 14px;
  border-radius: 1px;
  background: var(--ink);
  border: 1px solid var(--ink);
  cursor: pointer;
}
.vol input[type="range"]::-moz-range-thumb {
  width: 10px; height: 14px;
  border-radius: 1px;
  background: var(--ink);
  border: 1px solid var(--ink);
  cursor: pointer;
}

/* A paused clock reads as deliberately stopped, not as broken. */
.timer-face.paused { color: var(--ink-sub); }

@media (max-width: 34rem) {
  .vinyl { width: 112px; height: 112px; }
}

/* ==================================================================== *
 * Narrow widths
 *
 * Grid and flex items default to `min-width: auto`, which means they will
 * not shrink below their content — so on a 375px phone the problem rows
 * pushed the whole page out to 525px and the site scrolled sideways. This
 * is the fix for that class of bug, applied once at the containers rather
 * than chased per component.
 * ==================================================================== */
.grid > *, .today-top > *, .reader > *, .stack > *, .row > * { min-width: 0; }
.ladder div { min-width: 0; }
.card, .card-h, .card-b { min-width: 0; }
.card-h { flex-wrap: wrap; row-gap: 0.3rem; }

@media (max-width: 48rem) {
  .page-in { padding-left: 0.85rem; padding-right: 0.85rem; }
  .timer-face { font-size: clamp(2rem, 12vw, 3rem); }
  /* The blocks are a five-across strip on a desktop and a two-across grid
     on a phone; wrapping them as flex items left a ragged last row. */
  .blocks { display: grid; grid-template-columns: 1fr 1fr; }
  .blocks button { min-width: 0; }
  .ladder { flex-direction: column; }
  .ladder div { border-right: 0; border-bottom: 1px solid var(--rule); }
  .ladder div:last-child { border-bottom: 0; }
  .entry dl { grid-template-columns: 1fr; gap: 0 0; }
  .entry dt { margin-top: 0.35rem; }
}

/* Give the contents rail and the page a little more air between them, so
   the divider and the notebook margin rule do not read as one double line. */
.toc { padding-right: 1.75rem; }
.reader > .doc { padding-left: clamp(2rem, 5vw, 4rem); }
.reader > .doc::before { left: clamp(1.1rem, 3vw, 2.4rem); }

/* ==================================================================== *
 * Page header
 *
 * One <h1> per view, at the top of it, with the controls that change what
 * it names sitting beside it. Previously the day title lived in the right
 * column between two cards, which broke that column's rhythm and buried
 * the page's own heading two thirds of the way down the screen.
 * ==================================================================== */
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.5rem;
  margin: 0 0 1.1rem;
  padding-bottom: 0.95rem;
  border-bottom: 1px solid var(--rule);
}
.page-head-t { min-width: 0; }
.page-head h1 {
  font-size: clamp(1.3rem, 1rem + 1.2vw, 1.85rem);
  line-height: 1.18;
  margin: 0.3rem 0 0;
  /* Wide enough that most day titles sit on one line at desktop width,
     narrow enough that the longest ones break to two rather than
     running the full width of a 1400px page. */
  max-width: 42ch;
  text-wrap: balance;
}
.page-head .lede {
  margin: 0.5rem 0 0;
  max-width: 62ch;
  font-size: 0.86rem;
  line-height: 1.55;
}
.day-nav { display: flex; gap: 0.35rem; flex: 0 0 auto; }

@media (max-width: 42rem) {
  .page-head { flex-direction: column; gap: 0.75rem; }
  .day-nav { width: 100%; }
}

/* Both rows of the Today view share ONE column definition, so the seam
   between the wide and narrow columns runs straight down the page.
   They previously differed — 1.75fr/1fr on top and 1fr/1fr below — which
   put the café's right edge 180px away from the problems card's right
   edge and made the page read as two unrelated layouts stacked up. */
.today-top, .today-btm {
  display: grid;
  grid-template-columns: 1.75fr 1fr;
  column-gap: 0.85rem;
  row-gap: 0.85rem;
  align-items: start;
}
.today-btm { margin-top: 0.85rem; }
@media (max-width: 74rem) {
  .today-top, .today-btm { grid-template-columns: 1fr; }
}

/* The two timer faces are the same component at two sizes, rather than one
   of them carrying an inline font-size. */
.timer-face.sm { font-size: clamp(1.5rem, 4vw, 1.9rem); }

/* ==================================================================== *
 * Transport
 * ==================================================================== */
.seek {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.55rem;
  font-size: 0.68rem;
  color: var(--ink-sub);
}
.seek input[type="range"] {
  flex: 1;
  min-width: 0;
  width: auto;
  padding: 0;
  height: 5px;
  border: 0;
  border-radius: 2px;
  background: var(--rule);
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}
.seek input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 8px; height: 16px;
  border-radius: 1px;
  background: var(--ink);
  border: 1px solid var(--ink);
  cursor: grab;
}
.seek input[type="range"]::-moz-range-thumb {
  width: 8px; height: 16px;
  border-radius: 1px;
  background: var(--ink);
  border: 1px solid var(--ink);
  cursor: grab;
}
.seek input:disabled, .vol input:disabled { opacity: 0.4; cursor: not-allowed; }

.transport { margin-top: 0.5rem; gap: 0.25rem; }
.transport button { padding: 0.3rem 0.5rem; font-size: 0.9rem; line-height: 1; }
.transport button.primary { padding-left: 0.75rem; padding-right: 0.75rem; }
