/* html-kit prototype — all design lives here. Pages carry content + class names only.
   Page types: <body class="doc"> (scrolling document) or <body class="deck"> (slides).
   Component reference: ../AUTHORING.md */

:root {
  --paper: #F6F8F5; --raised: #FFFFFF; --ink: #1C2A26; --muted: #5B6B64; --rule: #DAE1DB;
  --accent: #0E6B54;
  --ok: #0E6B54;   --ok-bg: #E3EFEA;
  --info: #29618F; --info-bg: #E4ECF4;
  --warn: #7E520B; --warn-bg: #F3ECDD;
  --bad: #A93638;  --bad-bg: #F4E4E4;
  --display: "Avenir Next", "Futura", "Century Gothic", "Segoe UI", system-ui, sans-serif;
  --body: "Charter", "Iowan Old Style", "Georgia", serif;
  --mono: ui-monospace, "SF Mono", "Menlo", "Cascadia Code", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #121816; --raised: #1A2220; --ink: #E4ECE8; --muted: #9AABA3; --rule: #2C3834;
    --accent: #5CC4A2;
    --ok: #5CC4A2;   --ok-bg: #173229;
    --info: #7FB2E0; --info-bg: #182A3B;
    --warn: #E0B464; --warn-bg: #352A14;
    --bad: #EE8A8B;  --bad-bg: #3A1D1E;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #121816; --raised: #1A2220; --ink: #E4ECE8; --muted: #9AABA3; --rule: #2C3834;
  --accent: #5CC4A2;
  --ok: #5CC4A2;   --ok-bg: #173229;
  --info: #7FB2E0; --info-bg: #182A3B;
  --warn: #E0B464; --warn-bg: #352A14;
  --bad: #EE8A8B;  --bad-bg: #3A1D1E;
  color-scheme: dark;
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--body); font-size: clamp(16px, 1.6vw, 20px); line-height: 1.5;
}
h1, h2, h3 { font-family: var(--display); font-weight: 600; line-height: 1.12; text-wrap: balance; margin: 0; }
h1 { font-size: clamp(2.2rem, 6vw, 4.2rem); letter-spacing: -0.015em; }
h2 { font-size: clamp(1.5rem, 3.4vw, 2.5rem); letter-spacing: -0.01em; }
h3 { font-size: 1.08em; }
p { margin: 0; }
b, strong { font-family: var(--display); font-weight: 600; }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
code { font-family: var(--mono); font-size: 0.88em; background: var(--raised); border: 1px solid var(--rule); border-radius: 3px; padding: 0 0.3em; }
ul, ol { margin: 0; padding-left: 1.3em; display: grid; gap: 6px; }

/* ---------- code blocks: <pre><code>…</code></pre>; caption one with <figure> + <figcaption> ---------- */
pre:not(.mermaid) { margin: 0; min-width: 0; overflow-x: auto; font-family: var(--mono); font-size: 0.8em; line-height: 1.55; background: var(--raised); border: 1px solid var(--rule); border-radius: 6px; padding: 12px 16px; tab-size: 2; }
pre > code { font-size: inherit; background: none; border: 0; padding: 0; }

/* ---------- text roles ---------- */
.eyebrow { font-family: var(--mono); font-size: 0.68em; letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent); }
.lede { font-size: 1.12em; max-width: 34em; }
.note { color: var(--muted); font-size: 0.85em; max-width: 44em; }
.note strong, .note b { color: var(--ink); }
.meta { font-family: var(--mono); font-size: 0.72em; }
.callout { border-left: 3px solid var(--accent); padding: 6px 0 6px 18px; max-width: 46em; }
div.callout { display: grid; gap: 8px; }  /* boxed: <div class="callout"><h3>…</h3><p>/<ul>…</div> */
.statement { display: grid; gap: clamp(14px, 3vh, 28px); }
.statement > p { font-family: var(--display); font-weight: 600; font-size: clamp(1.5rem, 3.8vw, 2.7rem); line-height: 1.15; letter-spacing: -0.01em; text-wrap: balance; }
.statement > p:nth-child(even) { color: var(--accent); }

/* ---------- tags (tone: ok | info | warn | bad) ---------- */
.tag { font-family: var(--mono); font-size: 0.72em; padding: 0.15em 0.5em; border-radius: 3px; white-space: nowrap; vertical-align: 0.08em; color: var(--muted); background: var(--rule); }
.tag.ok   { color: var(--ok);   background: var(--ok-bg); }
.tag.info { color: var(--info); background: var(--info-bg); }
.tag.warn { color: var(--warn); background: var(--warn-bg); }
.tag.bad  { color: var(--bad);  background: var(--bad-bg); }

/* ---------- numbered points: <ol class="points"> ---------- */
ol.points { list-style: none; padding: 0; counter-reset: pt; gap: clamp(10px, 1.8vh, 18px); max-width: 46em; }
ol.points > li { counter-increment: pt; position: relative; padding-left: 2.2em; }
ol.points > li::before { content: counter(pt); position: absolute; left: 0; top: -0.1em; font-family: var(--display); font-weight: 600; color: var(--accent); font-size: 1.15em; font-variant-numeric: tabular-nums; }

/* ---------- big numbers: <div class="stats"><div class="stat"><b>…</b><p>…</p></div> ---------- */
.stats { display: flex; gap: clamp(28px, 6vw, 72px); flex-wrap: wrap; }
.stat > b { display: block; font-size: clamp(2.6rem, 6.4vw, 4.6rem); line-height: 1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat > p { color: var(--muted); font-size: 0.9em; max-width: 15em; margin-top: 6px; }

/* ---------- grids and cards ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 16em), 1fr)); gap: clamp(12px, 2.4vw, 28px); }
.grid.small { grid-template-columns: repeat(auto-fit, minmax(min(100%, 10em), 1fr)); gap: 12px; }
.card { background: var(--raised); border: 1px solid var(--rule); border-radius: 6px; padding: clamp(14px, 2.4vh, 24px) clamp(16px, 2vw, 26px); display: grid; gap: 8px; align-content: start; }
.card > p { font-size: 0.92em; color: var(--muted); }
.card > p.meta { color: var(--ink); font-size: 0.72em; }
.card > h3 small { display: block; font-family: var(--mono); font-size: 0.68em; font-weight: 500; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin-top: 3px; }
.card > ul { list-style: none; padding: 0; font-size: 0.92em; }
.card > ul > li { padding-left: 1em; text-indent: -1em; }
.card > ul > li::before { content: "— "; color: var(--muted); }
.grid.small .card { padding: 12px 14px; gap: 5px; }
.grid.small .card > h3 { font-size: 0.95em; }
.grid.small .card > p { font-size: 0.8em; }
.card.accent { border-top: 3px solid var(--accent); }
.card.ink    { border-top: 3px solid var(--ink); }
.card.ok     { border-top: 3px solid var(--ok); }
.card.info   { border-top: 3px solid var(--info); }
.card.warn   { border-top: 3px solid var(--warn); }
.card.bad    { border-top: 3px solid var(--bad); }

/* ---------- tables (kit.js wraps each in a scroll box) ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--rule); border-radius: 6px; background: var(--raised); }
table { border-collapse: collapse; width: 100%; font-size: 0.88em; }
th, td { text-align: left; padding: 9px 16px; border-bottom: 1px solid var(--rule); vertical-align: baseline; }
tr:last-child td { border-bottom: none; }
th { font-family: var(--mono); font-size: 0.75em; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); font-weight: 500; }
td:first-child { font-family: var(--display); font-weight: 600; }

/* ---------- figures and diagrams ---------- */
figure { margin: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
figure img, figure svg { max-width: 100%; height: auto; margin: 0 auto; display: block; }
figcaption { color: var(--muted); font-size: 0.82em; max-width: 52em; }
pre.mermaid { margin: 0; text-align: center; background: none; font-family: var(--display); }
pre.mermaid:not([data-processed]) { color: transparent; min-height: 8em; }
pre.mermaid svg { max-height: 52vh; }
body.doc pre.mermaid { overflow-x: auto; }  /* kit.js gives doc diagrams a min-width so labels stay readable */
body.doc pre.mermaid svg { max-height: none; }

/* hand-drawn diagrams: <svg class="diagram"> — authors draw geometry, the kit colours it.
   Shapes are outlined nodes, lines are plain strokes, text is centred. Classes:
   .arrow (arrowhead at the end), .dash, tone .accent/.ok/.info/.warn/.bad (stroke or text colour),
   .solid (shape filled with its tone, accent by default), text .small (mono edge label), text .inverse (on .solid). */
svg.diagram { width: 100%; max-height: 60vh; overflow: visible; }
.diagram :is(rect, circle, ellipse, polygon) { fill: var(--raised); stroke: var(--ink); stroke-width: 1.6; }
.diagram :is(path, line, polyline) { fill: none; stroke: var(--ink); stroke-width: 2; }
.diagram text { fill: var(--ink); stroke: none; font-family: var(--display); font-size: 16px; font-weight: 600; text-anchor: middle; dominant-baseline: central; }
.diagram text[class] { stroke: none; }  /* tone classes set stroke; text never takes one */
.diagram text.small { font-family: var(--mono); font-size: 14px; font-weight: 400; }
.diagram .arrow { marker-end: url(#kit-arrow); }
.diagram .dash { stroke-dasharray: 4 4; }
.diagram .accent { stroke: var(--accent); } .diagram text.accent { fill: var(--accent); }
.diagram .ok     { stroke: var(--ok); }     .diagram text.ok     { fill: var(--ok); }
.diagram .info   { stroke: var(--info); }   .diagram text.info   { fill: var(--info); }
.diagram .warn   { stroke: var(--warn); }   .diagram text.warn   { fill: var(--warn); }
.diagram .bad    { stroke: var(--bad); }    .diagram text.bad    { fill: var(--bad); }
.diagram .solid { fill: var(--accent); stroke: none; }
.diagram .solid.ok { fill: var(--ok); } .diagram .solid.info { fill: var(--info); }
.diagram .solid.warn { fill: var(--warn); } .diagram .solid.bad { fill: var(--bad); }
.diagram text.inverse { fill: var(--paper); }
#kit-arrow path { fill: var(--ink); fill: context-stroke; stroke: none; }

/* ---------- rows: a coloured ladder. <ul class="rows"><li class="ok">label · text · <b>verdict</b></li> ---------- */
.rows { list-style: none; padding: 0; display: grid; gap: 10px; max-width: 52em; }
.rows > li { display: grid; grid-template-columns: 9.5em 1fr auto; gap: 18px; align-items: center; background: var(--raised); border: 1px solid var(--rule); border-radius: 6px; padding: 14px 18px; }
.rows > li > span:not(.tag) { color: var(--muted); font-size: 0.9em; }
.rows > li > b { font-family: var(--display); font-size: 0.85em; text-align: right; white-space: nowrap; }
.rows > li.accent > b { color: var(--accent); } .rows > li.ok > b { color: var(--ok); } .rows > li.info > b { color: var(--info); }
.rows > li.warn > b { color: var(--warn); } .rows > li.bad > b { color: var(--bad); }
@media (max-width: 700px) { .rows > li { grid-template-columns: 1fr; gap: 6px; } .rows > li > b { text-align: left; } }

/* ---------- doc layout ---------- */
body.doc > main { max-width: 46em; margin: 0 auto; padding: clamp(24px, 6vh, 64px) 20px 80px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; }
body.doc > main > section { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; margin-top: 1.6em; }
body.doc > main > section > h2 { font-size: clamp(1.4rem, 2.6vw, 1.9rem); padding-top: 0.8em; border-top: 1px solid var(--rule); }
/* wide things bleed past the text column; a figure's caption stays in it */
body.doc .grid, body.doc .table-wrap, body.doc figure > pre.mermaid { margin-inline: min(0px, (46em - 100vw) / 2 + 20px); }
/* a doc diagram is sized so its 16-unit labels land at body text size: narrower than the column on
   wide screens, bleeding past it only when the viewBox is wide, full width on phones (kit.js sets --vbw) */
body.doc figure > svg.diagram { --w: min(100vw - 40px, var(--vbw, 600) * 0.0625em); width: var(--w); max-width: none; margin-inline: calc((100% - var(--w)) / 2); }
/* on a phone a viewBox wider than 600 keeps 16-unit labels at 12px and scrolls sideways in its figure */
@media (max-width: 700px) { body.doc figure:has(> svg.diagram[data-wide]) { overflow-x: auto; } body.doc figure > svg.diagram[data-wide] { min-width: calc(var(--vbw) * 0.75px); margin-inline: 0; } }
/* contents: <nav class="toc"><ol><li><a href="#id">…</a></li></ol></nav> */
nav.toc { border-top: 1px solid var(--rule); padding-top: 14px; }
nav.toc > ol { display: block; columns: 2 14em; column-gap: 32px; padding-left: 2.2em; list-style: decimal-leading-zero; font-family: var(--display); }
nav.toc li { padding: 3px 0; break-inside: avoid; }
nav.toc li::marker { font-family: var(--mono); font-size: 0.8em; color: var(--muted); }
/* steps that hold code: <ol class="steps"><li><h3>…</h3><p>…</p><pre><code>…</code></pre></li></ol> */
ol.steps { list-style: none; padding: 0; counter-reset: st; gap: 28px; grid-template-columns: minmax(0, 1fr); }
ol.steps > li { counter-increment: st; position: relative; padding-left: 2.4em; display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
ol.steps > li::before { content: counter(st); position: absolute; left: 0; top: 0; width: 1.6em; height: 1.6em; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--paper); font-family: var(--display); font-weight: 600; font-size: 0.85em; font-variant-numeric: tabular-nums; }
/* page footer: <footer> right after </main> */
body.doc > footer { max-width: 46em; margin: 0 auto; padding: 18px 20px 48px; border-top: 1px solid var(--rule); color: var(--muted); display: grid; gap: 6px; }
body.doc > footer > * { font-size: 0.82em; }

/* ---------- deck layout (kit.js adds .progress, .bar and slide state) ---------- */
body.deck { height: 100dvh; overflow: hidden; display: flex; flex-direction: column; }
body.deck > main { flex: 1; min-height: 0; position: relative; }
body.deck .slide { position: absolute; inset: 0; display: none; overflow-y: auto; padding: clamp(24px, 5vh, 56px) clamp(24px, 7vw, 96px); }
body.deck .slide.current { display: flex; flex-direction: column; justify-content: center; }
body.deck .slide:focus { outline: none; }
body.deck .slide > * { width: 100%; max-width: 1040px; margin-inline: auto; }
body.deck .slide > * + * { margin-top: clamp(14px, 2.4vh, 26px); }
body.deck .slide.backup .eyebrow { color: var(--muted); }
@media (prefers-reduced-motion: no-preference) {
  body.deck .slide.current > * { animation: kit-rise 320ms ease both; }
  @keyframes kit-rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
}
.progress { height: 3px; background: var(--rule); flex: none; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width 240ms ease; }
.bar { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px clamp(24px, 7vw, 96px); border-top: 1px solid var(--rule); font-family: var(--mono); font-size: 12px; color: var(--muted); }
.bar .nav { display: flex; gap: 8px; align-items: center; font-variant-numeric: tabular-nums; }
.bar button { font: inherit; color: var(--ink); background: var(--raised); border: 1px solid var(--rule); border-radius: 4px; padding: 3px 12px; cursor: pointer; }
.bar button:hover { border-color: var(--accent); color: var(--accent); }

@media (max-width: 760px) {
  .bar .keys { display: none; }
}
@media print {
  body.deck { height: auto; overflow: visible; display: block; }
  body.deck .slide { position: static; display: block; break-after: page; }
  .progress, .bar { display: none; }
}
