/* ─────────────────────────────────────────────────────────────────────
   THE RULE — base: the dozen components. Face-agnostic; reads only the
   slots tokens.css declares. Load AFTER tokens.css and a face.
   ───────────────────────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--step-0);
  font-optical-sizing: auto;
  line-height: 1.62;
  -webkit-font-smoothing: antialiased;
}

/* 1. wrap — page gutter */
.wrap { max-width: var(--measure-wide); margin: 0 auto; padding: 0 var(--gutter); }
.prose { max-width: var(--measure); }

/* 2. headings — display face, no weight games */
h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 400;
  line-height: 1.06;
  margin: 0;
  text-wrap: balance;
}
h1 { font-size: var(--step-4); letter-spacing: -.015em; }
h2 { font-size: var(--step-2); margin-top: 3rem; margin-bottom: .8rem; }
h3 { font-size: var(--step-1); margin-top: 2rem; margin-bottom: .5rem; }
h1 em, h2 em { font-style: italic; }

p { margin: 0 0 1.1rem; }
.prose p, .prose li { max-width: var(--measure); }

/* 3. label — small caps in mono; every section is labelled */
.label, .mono, code, kbd, td.num, .num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}
.label {
  font-size: .68rem;
  font-weight: 500;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--ink-faint);
  display: block;
}

/* 4. links — underlined, never coloured blocks */
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: .18em; }
a:hover { color: var(--ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* 5. masthead */
.masthead { padding: clamp(3rem, 8vw, 6rem) 0 clamp(1.6rem, 3vw, 2.4rem); border-bottom: var(--hairline) solid var(--rule-strong); }
.masthead .label { margin-bottom: 1.4rem; }
.deck { max-width: var(--measure); margin-top: 1.3rem; font-size: var(--step-1); color: var(--ink-muted); line-height: 1.45; }

/* 6. nav — a ruled line of words */
.nav { display: flex; flex-wrap: wrap; gap: 0 1.6rem; padding: .9rem 0; border-bottom: var(--hairline) solid var(--rule); font-family: var(--font-mono); font-size: var(--step--1); }
.nav a { color: var(--ink-muted); text-decoration: none; }
.nav a:hover, .nav a[aria-current="page"] { color: var(--ink); }
.nav .home { color: var(--ink); margin-right: auto; }

/* 7. index — the tool list. A ruled table, not cards. */
.index { list-style: none; margin: 0; padding: 0; border-top: var(--hairline) solid var(--rule-strong); }
.index li { display: grid; grid-template-columns: minmax(9rem, 14rem) 1fr auto; gap: 1rem 1.5rem; align-items: baseline; padding: 1.05rem 0; border-bottom: var(--hairline) solid var(--rule); }
.index .name { font-family: var(--font-mono); font-size: var(--step-0); }
.index .name a { text-decoration: none; }
.index .name a:hover { text-decoration: underline; }
.index .what { color: var(--ink-muted); margin: 0; max-width: var(--measure); }
.index .state { font-family: var(--font-mono); font-size: var(--step--1); color: var(--ink-faint); white-space: nowrap; }
@media (max-width: 40rem) {
  .index li { grid-template-columns: 1fr; gap: .25rem; }
  .index .state { order: -1; }
}

/* 8. facts — key/value table */
.facts { width: 100%; table-layout: fixed; border-collapse: collapse; margin: 0 0 1.5rem; border-top: var(--hairline) solid var(--rule-strong); }
.facts td:last-child { overflow-wrap: anywhere; }
code { overflow-wrap: anywhere; }
.facts td { padding: .55rem .8rem .55rem 0; border-bottom: var(--hairline) solid var(--rule); vertical-align: top; }
.facts td:first-child { font-family: var(--font-mono); font-size: var(--step--1); letter-spacing: .05em; text-transform: uppercase; color: var(--ink-faint); white-space: nowrap; width: 10rem; }

/* 9. code */
code { font-size: .9em; background: var(--surface-2); padding: .12em .38em; border-radius: var(--radius); }
pre { font-family: var(--font-mono); font-size: .84rem; line-height: 1.6; background: var(--surface); border: var(--hairline) solid var(--rule); padding: 1rem 1.2rem; overflow-x: auto; margin: 0 0 1.3rem; color: var(--ink); }
pre code { background: none; padding: 0; font-size: 1em; }

/* 9a. syntax tokens — applied at BUILD time (build/highlight.py), never in the
   browser, so the code exists for a crawler. Colours are The Rule's own, each
   measured ≥4.8:1 on --surface in tests/contrast.py (CODE_TOKENS); comments
   are the usual casualty in off-the-shelf themes, so here they are --ink-muted,
   not a lighter grey. Decoration over content: no meaning rides on colour.  */
.tk-c { color: var(--ink-muted); font-style: italic; }
.tk-s { color: var(--second); }
.tk-k { color: var(--accent); font-weight: 500; }
.tk-n { color: var(--tk-number); }
.tk-f { color: var(--tk-flag); }
.tk-v { color: var(--tk-var); }
.tk-p { color: var(--ink-muted); }

/* 10. aside — a ruled margin note. .warn uses the second colour. */
.aside { border-left: 2px solid var(--accent); padding-left: 1.1rem; color: var(--ink-muted); margin: 0 0 1.3rem; max-width: var(--measure); }
.aside.warn { border-left-color: var(--second); }
.aside strong { color: var(--ink); }

/* 11. section — what / how / breaks are h2s with labels above */
section { margin-top: 2.6rem; }
section > .label { margin-bottom: -.2rem; }

/* 12. colophon */
.colophon { margin-top: 5rem; padding: 1.4rem 0 3rem; border-top: var(--hairline) solid var(--rule-strong); font-family: var(--font-mono); font-size: var(--step--1); color: var(--ink-faint); display: flex; flex-wrap: wrap; gap: .4rem 1.6rem; }
.colophon a { color: var(--ink-faint); text-decoration: none; }
.colophon a:hover { color: var(--ink); }

ul, ol { margin: 0 0 1.2rem; padding-left: 1.3rem; }
li { margin: 0 0 .5rem; }
hr { border: 0; border-top: var(--hairline) solid var(--rule); margin: 2.4rem 0; }
strong { font-weight: 600; }

/* the one motion */
main { animation: rule-rise .38s ease-out both; }
