/* Tujian — the whole design system (spec §15.1).
 *
 * ⚠ A TOKEN SET PLUS A CLOSED COMPONENT VOCABULARY. Every page composes these;
 * there is no page-specific CSS anywhere, because a one-off style is a value
 * with no canonical home (rules §3). If a screen needs something new, it needs a
 * new component here — named, once — not a class in a template.
 *
 * ⚠ HAND-WRITTEN, not Tailwind-compiled, and that is a correction to the spec
 * argued in §15.1. The short version: this design forbids one-off styles and
 * fixes a small component list, which is exactly the case where utility classes
 * cost a build toolchain and buy nothing — and the tokens below ARE the "token
 * set" the spec asks for, expressed in the mechanism CSS already has.
 */

/* ── tokens ────────────────────────────────────────────────────────────────
 * ⚠ Every colour has a light and a dark value and NOTHING ELSE CHANGES between
 * themes (spec §15.1). A theme that also moves spacing or type is two layouts
 * to keep working.
 */
:root {
  color-scheme: light dark;

  /* Type. A system stack: no webfont, no swap, no layout shift (spec §15.2). */
  --font-body: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji",
    "Segoe UI Emoji";
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;

  /* ⚠ A SMALL scale, and these are the only sizes. A directory is scanned, not
   * read — six sizes is already generous for something with no marketing page. */
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.375rem;
  --text-2xl: 1.75rem;

  /* Spacing, on a 4px base. The only spacing values there are. */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-12: 3rem;

  --radius: 3px;
  --border: 1px solid var(--line);

  /* ⚠ Dense by default (spec §15.1): a reference work, not an editorial page.
   * The measure is wide because this is tabular data as often as prose. */
  --measure: 46rem;
  --frame: 72rem;
}

/* Light. */
:root, [data-theme="light"] {
  --bg: #ffffff;
  --bg-sunk: #f4f5f7;
  --bg-raised: #ffffff;
  --ink: #16181d;
  --ink-dim: #545a66;
  --ink-faint: #676d78;
  --line: #d8dbe1;
  --line-strong: #83878f;
  --accent: #1b4f9c;
  --accent-ink: #ffffff;
  --visited: #5c3d8f;
  --warn-bg: #fdf3e0;
  --warn-ink: #6b4a08;
  --warn-line: #e5c88a;
  --bad-bg: #fdeceb;
  --bad-ink: #8c1d16;
  --bad-line: #eeb4af;
  --good-bg: #eaf6ec;
  --good-ink: #1d5c2b;
  --good-line: #a9d5b3;
  --focus: #1b4f9c;
}

/* Dark. ⚠ Contrast is checked in BOTH themes (spec §15.1) — a palette that
 * passes in light and fails in dark is the usual way this breaks.
 *
 * ⚠ "Checked" meant READ until 2026-08-27, and computing it found two failures
 * this comment had asserted away. `--line-strong` borders every form input, so
 * WCAG 1.4.11 wants 3:1 to identify the control, and it was 1.91:1 in light and
 * 2.01:1 in dark. `--ink-faint` colours the facet count at --text-xs and the
 * external-link marker, both small text, and it was 4.14:1 in light against a
 * 4.5:1 floor. TestEveryColourPairClearsWCAGInBothThemes computes every pair the
 * token vocabulary permits, in both themes, so this is now a check rather than
 * a claim. */
[data-theme="dark"] {
  --bg: #14161a;
  --bg-sunk: #1b1e24;
  --bg-raised: #1e2228;
  --ink: #e6e8ec;
  --ink-dim: #a8aeb9;
  --ink-faint: #8b919c;
  --line: #333842;
  --line-strong: #677185;
  --accent: #8ab4f8;
  --accent-ink: #14161a;
  --visited: #c4a7f0;
  --warn-bg: #2e2617;
  --warn-ink: #f0d193;
  --warn-line: #574728;
  --bad-bg: #2f1c1b;
  --bad-ink: #f4b0aa;
  --bad-line: #5d3330;
  --good-bg: #17281c;
  --good-ink: #a5d9b2;
  --good-line: #2f5138;
  --focus: #8ab4f8;
}

/* ⚠ The OS preference is the DEFAULT and needs no JavaScript (spec §15.1).
 * Most visitors never touch the toggle and get the right answer anyway; the
 * inline script only matters for somebody who overrode it.
 *
 * ⚠ THIS BLOCK IS A COPY OF THE ONE ABOVE, BYTE FOR BYTE, AND IT HAS TO BE. CSS
 * cannot share a declaration block across an @media boundary — a selector list
 * cannot span one — so the dark palette is written twice, and that is a
 * language constraint rather than a choice.
 *
 * ⚠ IT DRIFTED THE FIRST TIME ANYBODY EDITED ONE. `5615e1f` ("The accessibility
 * claims were reviewed, never computed, and two were false") corrected
 * `--line-strong` in the [data-theme="dark"] block and not in this one — and
 * this is the block a visitor gets WITHOUT EVER TOUCHING THE TOGGLE. The default
 * dark theme failed WCAG 1.4.11 on all three surfaces at 2.01–2.27:1 against a
 * 3.0 floor, for the whole build, while the guard's regex read only the block
 * that had been fixed.
 *
 * ⚠ SO THE GATE COMPARES THEM. TestEveryDarkPaletteIsTheSame asserts every block
 * setting a dark token is token-for-token identical — the same answer the gate
 * already gives for infra/caddy/Caddyfile and its Helm copy, which exist twice
 * for the same kind of reason. Edit one, edit both; the gate is what makes that
 * true rather than remembered. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161a;
    --bg-sunk: #1b1e24;
    --bg-raised: #1e2228;
    --ink: #e6e8ec;
    --ink-dim: #a8aeb9;
    --ink-faint: #8b919c;
    --line: #333842;
    --line-strong: #677185;
    --accent: #8ab4f8;
    --accent-ink: #14161a;
    --visited: #c4a7f0;
    --warn-bg: #2e2617;
    --warn-ink: #f0d193;
    --warn-line: #574728;
    --bad-bg: #2f1c1b;
    --bad-ink: #f4b0aa;
    --bad-line: #5d3330;
    --good-bg: #17281c;
    --good-ink: #a5d9b2;
    --good-line: #2f5138;
    --focus: #8ab4f8;
  }
}

/* ── reset ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
}
h1, h2, h3, h4, p, ul, ol, dl, figure, table, pre, blockquote { margin: 0 0 var(--space-4); }
h1, h2, h3, h4 { line-height: 1.25; font-weight: 600; }
h1 { font-size: var(--text-2xl); }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); }
h4 { font-size: var(--text-base); }
img { max-width: 100%; height: auto; }
code, pre, kbd { font-family: var(--font-mono); font-size: 0.9em; }
pre { overflow-x: auto; padding: var(--space-3); background: var(--bg-sunk); border-radius: var(--radius); }
hr { border: 0; border-top: var(--border); margin: var(--space-6) 0; }

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:visited { color: var(--visited); }

/* ⚠ VISIBLE focus, in both themes (spec §15.1). :focus-visible so a mouse click
 * does not draw a ring, while every keyboard route does. */
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--radius);
}

/* ⚠ Skip link. The frame puts navigation before content on every page, so a
 * keyboard user would otherwise tab the whole header on all 400,000 of them. */
.skip {
  position: absolute;
  left: -9999px;
  top: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-raised);
  border: var(--border);
  border-radius: var(--radius);
  z-index: 10;
}
.skip:focus { left: var(--space-2); }

/* ── the frame (spec §15.1) ────────────────────────────────────────────────
 * ⚠ ONE shell, every route inside it, and it renders IDENTICALLY FOR EVERYONE —
 * a frame that said "Hello, Bob" would make every page per-user and forfeit
 * public caching for the whole site.
 */
.frame-head {
  border-bottom: var(--border);
  background: var(--bg-raised);
}
.frame-head__inner,
.frame-body,
.frame-foot__inner {
  max-width: var(--frame);
  margin: 0 auto;
  padding: var(--space-3) var(--space-4);
}
.frame-head__inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
}
.frame-brand {
  font-weight: 700;
  font-size: var(--text-lg);
  color: var(--ink);
  text-decoration: none;
}
.frame-brand:visited { color: var(--ink); }
.frame-head__search { flex: 1 1 12rem; min-width: 0; }
.frame-head__links {
  display: flex;
  gap: var(--space-3);
  align-items: center;
  font-size: var(--text-sm);
}
/* ⚠ WCAG 2.5.8: a target under 24×24 CSS px is hard to hit, and this is a
 * reference work people read on phones. These links were 21px tall — the line
 * box of `--text-sm` and nothing else — which a browser measured and no
 * stylesheet review would have: the rule sets a font size, not a height.
 *
 * ⚠ Padding rather than a height, so the target grows with the text when
 * somebody enlarges it rather than clipping against a fixed box. 2.5.8's
 * inline exception does NOT apply here: these are not in a sentence. */
.frame-head__links > a,
.frame-head__links > button {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding-block: var(--space-1);
}
.frame-body { padding-top: var(--space-6); padding-bottom: var(--space-12); }
.frame-foot {
  border-top: var(--border);
  background: var(--bg-sunk);
  color: var(--ink-dim);
  font-size: var(--text-sm);
}
.frame-foot__inner { display: flex; flex-wrap: wrap; gap: var(--space-3); }

/* ── prose ────────────────────────────────────────────────────────────────
 * ⚠ Applied to RENDERED USER CONTENT only, and it is the only place a measure
 * is imposed. Everything else is tabular and wants the width.
 */
.prose { max-width: var(--measure); }
.prose > :last-child { margin-bottom: 0; }
.prose blockquote {
  margin-left: 0;
  padding-left: var(--space-4);
  border-left: 3px solid var(--line-strong);
  color: var(--ink-dim);
}
.prose table { width: 100%; }
/* ⚠ An external link is marked in the CONTENT ONLY. The marker means "this
 * leaves the site", which is meaningless in the frame's own footer. */
.prose a[rel~="nofollow"]::after {
  content: "↗";
  font-size: 0.8em;
  margin-left: 0.15em;
  color: var(--ink-faint);
}

/* ── the component vocabulary (spec §15.1) ─────────────────────────────── */

/* Infobox — the thing this product has instead of a hero. */
.infobox {
  float: right;
  width: min(22rem, 100%);
  margin: 0 0 var(--space-4) var(--space-6);
  padding: var(--space-3);
  background: var(--bg-sunk);
  border: var(--border);
  border-radius: var(--radius);
  font-size: var(--text-sm);
}
.infobox img { border-radius: var(--radius); }

/* Field row — one label/value line inside an infobox. */
.fields { margin: 0; }
.field {
  display: grid;
  grid-template-columns: minmax(6rem, 38%) 1fr;
  gap: var(--space-2);
  padding: var(--space-1) 0;
  border-top: var(--border);
}
.field:first-child { border-top: 0; }
.field > dt { color: var(--ink-dim); margin: 0; }
.field > dd { margin: 0; }

/* Tag chips. */
.chips { list-style: none; display: flex; flex-wrap: wrap; gap: var(--space-2); padding: 0; margin: 0; }
.chips > li { margin: 0; }
.chips a {
  display: inline-block;
  padding: 0 var(--space-2);
  border: var(--border);
  border-radius: 999px;
  background: var(--bg-sunk);
  color: var(--ink);
  text-decoration: none;
  font-size: var(--text-sm);
  line-height: 1.6;
}
.chips a:hover { border-color: var(--line-strong); }
.chips a[aria-current] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* Facet control — a vocabulary's terms, offered as filters. */
.facet { margin-bottom: var(--space-6); }
.facet > h2 { font-size: var(--text-sm); text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-dim); }
.facet .count { color: var(--ink-faint); font-size: var(--text-xs); }

/* Listing table — the directory index, and every admin listing. */
.listing { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.listing th, .listing td { text-align: left; padding: var(--space-2); border-bottom: var(--border); vertical-align: top; }
.listing thead th { color: var(--ink-dim); font-weight: 600; white-space: nowrap; }
.listing tbody tr:hover { background: var(--bg-sunk); }
.listing time { color: var(--ink-dim); white-space: nowrap; }

/* Stacked list — the listing's shape when there are no columns to fill. */
.rows { list-style: none; padding: 0; margin: 0; }
.rows > li {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: baseline;
  padding: var(--space-2);
  border-bottom: var(--border);
}
.rows time, .rows .meta { color: var(--ink-dim); font-size: var(--text-sm); }

/* Notices. ⚠ Three states, and colour is never the only signal — each carries a
 * word as well, because a colour-only status is invisible to a good number of
 * readers and to anyone printing the page. */
.notice { padding: var(--space-2) var(--space-3); border: 1px solid; border-radius: var(--radius); margin-bottom: var(--space-4); }
.notice--good { background: var(--good-bg); color: var(--good-ink); border-color: var(--good-line); }
.notice--warn { background: var(--warn-bg); color: var(--warn-ink); border-color: var(--warn-line); }
.notice--bad { background: var(--bad-bg); color: var(--bad-ink); border-color: var(--bad-line); }

/* Forms. */
label { display: inline-block; font-weight: 600; font-size: var(--text-sm); margin-bottom: var(--space-1); }
.hint { display: block; color: var(--ink-dim); font-size: var(--text-sm); margin-top: var(--space-1); }
input[type="text"], input[type="email"], input[type="password"], input[type="search"],
input[type="date"], input[type="number"], select, textarea {
  width: 100%;
  max-width: 100%;
  padding: var(--space-2);
  font: inherit;
  color: var(--ink);
  background: var(--bg-raised);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
}
textarea { min-height: 18rem; resize: vertical; font-family: var(--font-mono); font-size: var(--text-sm); }
input[type="checkbox"] { width: auto; }
button, .button {
  font: inherit;
  font-weight: 600;
  padding: var(--space-2) var(--space-3);
  color: var(--accent-ink);
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  cursor: pointer;
}
button:hover { filter: brightness(1.1); }
/* ⚠ A destructive control is marked, but never by colour ALONE — it sits under
 * a stated warning and a typed confirmation (spec §13). */
button.danger { background: var(--bad-ink); border-color: var(--bad-ink); color: #fff; }

/* Tab strip — tabs are LINKS (spec §5), so this is styling, not behaviour. */
.tabs { border-bottom: var(--border); margin-bottom: var(--space-4); }
.tabs ul { list-style: none; display: flex; gap: var(--space-1); padding: 0; margin: 0; }
.tabs li { margin: 0; }
.tabs a, .tabs strong {
  display: block;
  padding: var(--space-2) var(--space-3);
  text-decoration: none;
  color: var(--ink-dim);
  border-bottom: 2px solid transparent;
}
.tabs strong { color: var(--ink); border-bottom-color: var(--accent); }

/* Admin navigation reuses the strip, wrapped. */
.tabs--wrap ul { flex-wrap: wrap; }

/* ── narrow screens ───────────────────────────────────────────────────────
 * ⚠ THE SAME PAGE, not a stripped one (spec §15.1). Density degrades to narrow
 * gracefully — the infobox stops floating and the table scrolls — and nothing
 * is hidden, because a directory read on a phone is still a directory.
 */
@media (max-width: 44rem) {
  .infobox { float: none; width: auto; margin-left: 0; }
  .field { grid-template-columns: 1fr; gap: 0; }
  .field > dt { font-size: var(--text-xs); }
  .listing { display: block; overflow-x: auto; }
  .frame-head__inner { gap: var(--space-2); }
}

/* ── the editor's sections (spec §7.7) ────────────────────────────────────
 * ⚠ A SECTION IS A BOX, and it needs to look like one. The ↑/↓ buttons belong
 * to the section above them, and a flat list of controls gives no clue which
 * ones — so the boundary is the whole point rather than decoration.
 *
 * ⚠ No drag handles and no per-section styling controls. §7.7: "blocks and
 * ordering, with markdown doing the formatting inside them and no per-block
 * styling controls at all." Dragging would need JavaScript; the arrows work
 * without it.
 */
.section-edit {
  border: var(--border);
  border-radius: var(--radius);
  padding: var(--space-3);
  margin: 0 0 var(--space-4);
}
.section-edit__controls {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
  margin: var(--space-2) 0 0;
  font-size: var(--text-xs);
}
/* ⚠ The reason the last tags section cannot be removed, said where the missing
 * button would have been. A control that is simply absent teaches nothing. */
.section-edit__controls span { color: var(--ink-dim); }
.section-edit__palette {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: 0 0 var(--space-4);
}

/* ⚠ Motion is opt-out, and there is barely any to opt out of. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ── print ────────────────────────────────────────────────────────────────
 * A reference work gets printed. The frame is furniture; the content is not.
 */
@media print {
  .frame-head, .frame-foot, .tabs, .skip, form { display: none; }
  body { background: #fff; color: #000; }
  .infobox { float: none; border: 1px solid #999; }
  a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 0.8em; }
}
