/* Kimi K3 course — shared stylesheet.
   Tufte-influenced: generous margins, sidenotes, restrained palette, prints cleanly. */

:root {
  --ink:        #1a1a18;
  --ink-soft:   #5c5b57;
  --ink-faint:  #8e8d87;
  --paper:      #fffef9;
  --rule:       #e0ded4;
  --rule-soft:  #efede4;

  /* Axis colours — one per information-flow dimension. Consistent across all lessons. */
  --seq:    #1f6f8b;  /* sequence  — KDA / MLA        */
  --depth:  #8b5a2b;  /* depth     — AttnRes          */
  --width:  #6b4c8a;  /* width     — LatentMoE        */
  --vision: #2d6a4f;  /* vision    — MoonViT          */
  --warn:   #a8321e;  /* problems, costs, limitations */

  --seq-bg:    #eaf2f5;
  --depth-bg:  #f5efe7;
  --width-bg:  #f1ecf5;
  --vision-bg: #e9f2ed;
  --warn-bg:   #f9ece9;

  --serif: "iA Writer Quattro", "Charter", "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
  --mono:  "Berkeley Mono", "SF Mono", "IBM Plex Mono", ui-monospace, Menlo, monospace;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0 auto;
  padding: 4rem 2rem 8rem;
  max-width: 48rem;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.0625rem;
  line-height: 1.62;
  font-kerning: normal;
  text-rendering: optimizeLegibility;
}

/* ─── Masthead ─────────────────────────────────────────── */

.masthead {
  border-bottom: 1px solid var(--rule);
  padding-bottom: 1.4rem;
  margin-bottom: 2.6rem;
}

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

h1 {
  font-size: 2.05rem;
  line-height: 1.14;
  font-weight: 600;
  letter-spacing: -0.018em;
  margin: 0 0 0.6rem;
}

.standfirst {
  font-size: 1.15rem;
  line-height: 1.5;
  color: var(--ink-soft);
  margin: 0;
  max-width: 34rem;
}

/* ─── Structure ────────────────────────────────────────── */

h2 {
  font-size: 1.32rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 3.2rem 0 1rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--rule-soft);
}

h3 {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 2.1rem 0 0.6rem;
}

h4 {
  font-family: var(--mono);
  font-size: 0.76rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 500;
  margin: 1.7rem 0 0.5rem;
}

p { margin: 0 0 1.1rem; }

a {
  color: var(--seq);
  text-decoration: none;
  border-bottom: 1px solid rgba(31, 111, 139, 0.32);
}
a:hover { border-bottom-color: var(--seq); }

strong { font-weight: 640; }

code {
  font-family: var(--mono);
  font-size: 0.87em;
  background: #f4f2ea;
  padding: 0.08em 0.32em;
  border-radius: 2px;
}

ul, ol { margin: 0 0 1.2rem; padding-left: 1.4rem; }
li { margin-bottom: 0.5rem; }
li > ul, li > ol { margin-top: 0.5rem; margin-bottom: 0.3rem; }

/* ─── Figures & schemas ────────────────────────────────── */

figure {
  margin: 2rem 0;
}

figcaption {
  font-size: 0.83rem;
  line-height: 1.5;
  color: var(--ink-faint);
  margin-top: 0.7rem;
  padding-left: 0.1rem;
}
figcaption b { color: var(--ink-soft); font-weight: 600; }

.schema {
  font-family: var(--mono);
  font-size: 0.775rem;
  line-height: 1.5;
  white-space: pre;
  overflow-x: auto;
  background: #fbfaf4;
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 1.35rem 1.5rem;
  margin: 0;
  color: var(--ink);
  tab-size: 2;
}

.schema.tight { font-size: 0.72rem; }

svg.schema {
  white-space: normal;
  display: block;
  width: 100%;
  height: auto;
  padding: 1rem;
}

/* ─── SVG figure primitives ─────────────────────────────
   Presentation attributes cannot resolve var(), so SVG
   colour and type live here as classes instead. */

svg.schema text { font-family: var(--mono); fill: var(--ink); }
svg.schema .lbl   { font-size: 11px;   fill: var(--ink-faint); }
svg.schema .lbl-s { font-size: 10.5px; fill: var(--ink-faint); }
svg.schema .key   { font-size: 11.5px; }
svg.schema .axis  { stroke: var(--rule); stroke-width: 1; fill: none; }
svg.schema .grid  { stroke: var(--rule-soft); stroke-width: 1; stroke-dasharray: 2 3; fill: none; }
svg.schema .plate { fill: var(--paper); }

/* Series: baseline being compared against, and the K3 result. */
svg.schema .s-base { stroke: var(--ink-faint); stroke-width: 2;   fill: none; }
svg.schema .s-k3   { stroke: var(--width);     stroke-width: 2.4; fill: none; }
svg.schema .t-base { fill: var(--ink-faint); }
svg.schema .t-k3   { fill: var(--width); font-weight: 600; }

/* Measurement annotation — the quantity the figure exists to show. */
svg.schema .meas   { stroke: var(--warn); stroke-width: 1.4; fill: none; }
svg.schema .t-meas { fill: var(--warn); font-weight: 600; }

/* ─── Flow diagrams ─────────────────────────────────────
   Box-and-arrow flows converted from monospace schemas.
   Fork/join bars mark branches that run in parallel. */

svg.schema .gv-box  { fill: var(--paper); stroke: var(--ink-soft); stroke-width: 1.2; }
svg.schema .gv-dash { stroke-dasharray: 5 3; }
svg.schema .gv-bar  { fill: var(--ink); stroke: none; }
svg.schema .gv-edge { stroke: var(--ink-soft); stroke-width: 1.3; fill: none; }
svg.schema .gv-head { fill: var(--ink-soft); stroke: none; }
svg.schema .gv-t    { font-size: 11px; fill: var(--ink); }
svg.schema .gv-note { font-size: 10px; fill: var(--ink-faint); }

/* Axis-tinted variants, so a flow inherits its lesson's colour. */
svg.schema .gv-seq   { fill: var(--seq-bg);   stroke: var(--seq); }
svg.schema .gv-width { fill: var(--width-bg); stroke: var(--width); }

/* A dashed frame groups layers that repeat as a unit. */
svg.schema .gv-frame {
  fill: none;
  stroke: var(--rule);
  stroke-width: 1.2;
  stroke-dasharray: 4 3;
}
svg.schema .gv-mult    { font-size: 10.5px; fill: var(--ink-faint); }
svg.schema .gv-depth-t { fill: var(--depth); }
svg.schema .gv-seq-t   { fill: var(--seq); }

/* A step in a sequence the figure is teaching, weighted above
   the state that merely passes through it. */
svg.schema .gv-step { stroke: var(--seq); stroke-width: 2; }
svg.schema .gv-rule { stroke: var(--rule); stroke-width: 1; }

/* The three information-flow axes, colour-coded as the course promises. */
svg.schema .ax-s  { stroke: var(--seq);   stroke-width: 1.8; fill: none; }
svg.schema .ax-d  { stroke: var(--depth); stroke-width: 1.8; fill: none; }
svg.schema .ax-w  { stroke: var(--width); stroke-width: 1.8; fill: none; }
svg.schema .ax-hs { fill: var(--seq);   stroke: none; }
svg.schema .ax-hd { fill: var(--depth); stroke: none; }
svg.schema .ax-hw { fill: var(--width); stroke: none; }
svg.schema .ax-ts { fill: var(--seq); }
svg.schema .ax-td { fill: var(--depth); }
svg.schema .ax-tw { fill: var(--width); }
svg.schema .ax-hub { fill: var(--ink); stroke: none; }
svg.schema .ax-lbl {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
}

svg.schema .s-vis  { stroke: var(--vision); stroke-width: 2.2; fill: none; }
svg.schema .t-vis  { fill: var(--vision); font-weight: 600; }
svg.schema .f-seq  { fill: var(--seq); }
svg.schema .f-soft { fill: var(--rule-soft); }
svg.schema .st-seq { stroke: var(--seq); stroke-width: 1.4; fill: none; }

@media print {
  svg.schema .plate { fill: #fff; }
}

/* ─── Callouts ─────────────────────────────────────────── */

.note {
  border-left: 3px solid var(--rule);
  padding: 0.1rem 0 0.1rem 1.15rem;
  margin: 1.6rem 0;
  font-size: 0.96rem;
  color: var(--ink-soft);
}

.note > :last-child { margin-bottom: 0; }
.note .label {
  display: block;
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  margin-bottom: 0.35rem;
  color: var(--ink-faint);
}

.note.seq    { border-left-color: var(--seq);    }
.note.depth  { border-left-color: var(--depth);  }
.note.width  { border-left-color: var(--width);  }
.note.vision { border-left-color: var(--vision); }
.note.warn   { border-left-color: var(--warn);   }
.note.warn .label { color: var(--warn); }

/* Jargon buster — for a term being defined for the first time */
.define {
  background: #fbfaf2;
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 1rem 1.2rem;
  margin: 1.5rem 0;
  font-size: 0.96rem;
}
.define > :last-child { margin-bottom: 0; }
.define dt {
  font-weight: 640;
  font-family: var(--mono);
  font-size: 0.9rem;
  margin-top: 0.8rem;
}
.define dt:first-child { margin-top: 0; }
.define dd { margin: 0.25rem 0 0; color: var(--ink-soft); }

/* ─── Math disclosure ──────────────────────────────────── */

details.math {
  margin: 1.4rem 0;
  border: 1px solid var(--rule);
  border-radius: 3px;
  background: #fbfaf4;
}

details.math > summary {
  cursor: pointer;
  padding: 0.6rem 1rem;
  font-family: var(--mono);
  font-size: 0.76rem;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  list-style: none;
  user-select: none;
}
details.math > summary::-webkit-details-marker { display: none; }
details.math > summary::before {
  content: "▸ ";
  color: var(--ink-faint);
}
details.math[open] > summary::before { content: "▾ "; }
details.math[open] > summary { border-bottom: 1px solid var(--rule-soft); }
details.math > summary:hover { color: var(--ink); }

.math-body {
  padding: 1rem 1.2rem 0.4rem;
  font-size: 0.95rem;
}
.math-body > :last-child { margin-bottom: 0.8rem; }

.eq {
  font-family: var(--mono);
  font-size: 0.86rem;
  line-height: 1.7;
  overflow-x: auto;
  padding: 0.7rem 0;
  white-space: pre;
}

/* ─── Tables ───────────────────────────────────────────── */

table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.6rem 0;
  font-size: 0.9rem;
}

caption {
  caption-side: top;
  text-align: left;
  font-size: 0.83rem;
  color: var(--ink-faint);
  padding-bottom: 0.6rem;
}

th {
  text-align: left;
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  font-weight: 500;
  color: var(--ink-faint);
  border-bottom: 1px solid var(--ink-soft);
  padding: 0.4rem 0.7rem 0.4rem 0;
  vertical-align: bottom;
}

td {
  padding: 0.42rem 0.7rem 0.42rem 0;
  border-bottom: 1px solid var(--rule-soft);
  vertical-align: top;
}

tbody tr:last-child td { border-bottom: 1px solid var(--rule); }

td.num { text-align: right; font-family: var(--mono); font-size: 0.85rem; }
/* Headers keep the shared th type scale; only alignment differs. */
th.num { text-align: right; }
td.new { color: var(--width); font-weight: 600; }
.delta { font-family: var(--mono); font-size: 0.8rem; color: var(--ink-faint); }

/* Secondary line inside a cell — the qualifier, not the value. */
td .sub {
  display: block;
  font-size: 0.8em;
  line-height: 1.3;
  color: var(--ink-faint);
}

/* Tables that carry formulae rather than prose. */
table.family td.fn { font-family: var(--mono); font-size: 0.82rem; }
table.family td.yes { color: var(--width); font-weight: 600; }

/* Formulae cannot reflow, so a narrow screen scrolls the table
   instead of clipping it. Wrap the table, never the caption. */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.table-scroll > table { min-width: 27rem; }

/* Captions on figure-tables echo the old schema headings. */
figure > table > caption {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

/* A trailing remark belonging to the table above it. */
.table-note {
  margin: -0.9rem 0 0;
  font-size: 0.83rem;
  color: var(--ink-faint);
}

/* ─── Footer navigation ────────────────────────────────── */

.lesson-footer {
  margin-top: 4.5rem;
  padding-top: 1.6rem;
  border-top: 1px solid var(--rule);
}

.primary-source {
  background: #fbfaf2;
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 1.1rem 1.3rem;
  margin-bottom: 1.8rem;
}
.primary-source .label {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--ink-faint);
  display: block;
  margin-bottom: 0.45rem;
}
.primary-source p { margin: 0.4rem 0 0; font-size: 0.92rem; color: var(--ink-soft); }

.lesson-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  font-family: var(--mono);
  font-size: 0.8rem;
}
.lesson-nav a { border-bottom: none; color: var(--ink-soft); }
.lesson-nav a:hover { color: var(--seq); }

/* ─── Top rail ─────────────────────────────────────────────
   Prev / contents / next, directly under the masthead. Three
   columns so the edges hold even when one end is missing. */

.rail {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
  margin: 0 0 2.6rem;
  padding-bottom: 0.7rem;
  border-bottom: 1px solid var(--rule-soft);
  font-family: var(--mono);
  font-size: 0.78rem;
}
.rail a { border-bottom: none; color: var(--ink-faint); }
.rail a:hover { color: var(--seq); }
.rail-prev  { justify-self: start; }
.rail-index { justify-self: center; letter-spacing: 0.06em; text-transform: uppercase; }
.rail-next  { justify-self: end; text-align: right; }

@media print { .rail { display: none; } }

@media (max-width: 34rem) {
  .rail { font-size: 0.72rem; gap: 0.5rem; }
  .rail-index { display: none; }
  .rail { grid-template-columns: 1fr 1fr; }
}

/* ─── Print ────────────────────────────────────────────── */

@media print {
  body { padding: 0; max-width: none; font-size: 10.5pt; background: #fff; }
  h2 { page-break-after: avoid; }
  figure, .quiz, table, .define { page-break-inside: avoid; }
  details.math { border-color: #ccc; }
  details.math > summary { display: none; }
  .math-body { display: block !important; }
  details.math .math-body { padding-top: 0.5rem; }
  .lesson-nav { display: none; }
  a { color: var(--ink); border-bottom: none; }
  .schema { background: #fff; }
}

@media (max-width: 34rem) {
  body { padding: 2.2rem 1.1rem 4rem; font-size: 1rem; }
  h1 { font-size: 1.6rem; }
  .schema { font-size: 0.65rem; padding: 0.9rem; }
  .schema.tight { font-size: 0.58rem; }

  table { font-size: 0.84rem; }
  th { font-size: 0.64rem; letter-spacing: 0.05em; }
  table.family td.fn { font-size: 0.72rem; }
}
