/* ==========================================================================
   Kettlefinch — editorial design system
   One stylesheet, no build step, no webfont requests.

   Structure comes from full-bleed tonal bands and space, never from
   separator rules. Sections alternate --paper and --band; the footer is a
   near-black block against the light head of the page.

   THEME: light is the default; dark is a full repaint of the same tokens.
   The masthead toggle writes data-theme onto <html> and remembers it; with
   no stored choice the OS preference wins. No component rule below cares
   which theme is on — they all read tokens.
   ========================================================================== */

/* ── Tokens: neutrals (shared by all three palettes) ───────────────────── */
:root {
    color-scheme: light dark;

    --paper:      #fafaf9;   /* page ground                                */
    --band:       #f1f2f4;   /* alternating section ground                 */
    --band-head:  #e9ebef;   /* masthead band — a touch firmer than --band */
    --sheet:      #ffffff;   /* panels and inputs                          */
    --ink:        #14161b;   /* headings, body                             */
    --ink-2:      #3c4250;   /* secondary body                             */
    --muted:      #5c6270;   /* meta, labels                               */
    --field-line: #7c8495;   /* input border — 3.8:1, clears the UI floor  */

    --foot-bg:    #0a0c10;
    --foot-text:  #e9ebf1;
    --foot-muted: #9aa3b5;
    --code-bg:    #0a0c10;   /* code blocks and the license key             */
    --on-accent:  #ffffff;   /* text on an accent fill                      */
    --show-sun:   none;      /* the toggle shows the theme you would get to  */
    --show-moon:  block;

    /* Accent: ink blue */
    --accent:      #1b4bcf;  /* links, kickers, marks                      */
    --accent-deep: #143aa0;  /* pressed / hover on light                   */
    --accent-lift: #8fb0ff;  /* the same accent on a dark ground           */
    --accent-wash: #e8edfb;  /* notice backgrounds                         */
    /* Two alternates that were built and measured alongside this one; swap
       all four values to change the whole site. Both clear AA on --paper.
         green:   #14664a  #0e4d37  #6fd3a6  #e4f2ec
         oxblood: #8e1f3a  #6e1329  #f08ca4  #fae9ed                        */

    --serif: Charter, "Bitstream Charter", "Iowan Old Style", Georgia,
             "Noto Serif", "Liberation Serif", "Palatino Linotype", Palatino,
             serif;
    --sans:  ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
             "Helvetica Neue", "Noto Sans", Arial, sans-serif;
    --mono:  ui-monospace, SFMono-Regular, "SF Mono", "Source Code Pro", Menlo,
             Consolas, "Liberation Mono", monospace;

    --page:    1240px;
    --measure: 34rem;
    --gutter:  clamp(1.25rem, 4.5vw, 3rem);

    --s1: .25rem;  --s2: .5rem;   --s3: .75rem;  --s4: 1rem;
    --s5: 1.5rem;  --s6: 2rem;    --s7: 3rem;    --s8: 4.5rem;  --s9: 7rem;
}

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

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

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--paper);
    color: var(--ink);
    font: 400 1.0625rem/1.65 var(--serif);
    font-kerning: normal;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
}

img, svg { max-width: 100%; }

a { color: var(--accent); text-underline-offset: .18em; text-decoration-thickness: from-font; }
a:hover { color: var(--accent-deep); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 1px; }

.skip {
    position: absolute;
    left: -9999px;
    top: var(--s3);
    z-index: 10;
    background: var(--ink);
    color: var(--paper);
    padding: var(--s3) var(--s4);
    font: 600 .85rem/1 var(--sans);
    text-decoration: none;
}
.skip:focus { left: var(--s4); }

/* ── Type ────────────────────────────────────────────────────────────── */
h1, h2, h3, h4 {
    font-family: var(--serif);
    font-weight: 600;
    line-height: 1.12;
    letter-spacing: -.012em;
    margin: 0 0 var(--s4);
    text-wrap: balance;
}
h1 { font-size: clamp(2.35rem, 5.4vw, 3.9rem); line-height: 1.04; letter-spacing: -.022em; }
h2 { font-size: clamp(1.55rem, 2.8vw, 2.15rem); }
h3 { font-size: 1.2rem; letter-spacing: -.005em; }
h4 { font-size: 1rem; }

p { margin: 0 0 var(--s4); max-width: var(--measure); }
p:last-child { margin-bottom: 0; }

.eyebrow, .label, .kicker, .tag, .entry-meta, .colophon, nav, .hint, .opt,
.hero-facts, .count { font-family: var(--sans); }

.eyebrow, .label {
    display: block;
    margin: 0 0 var(--s3);
    font-size: .7rem;
    font-weight: 600;
    letter-spacing: .2em;
    text-transform: uppercase;
    color: var(--accent);
}
.label { color: var(--muted); }

.lede {
    font-size: clamp(1.1rem, 1.6vw, 1.3rem);
    line-height: 1.55;
    color: var(--ink-2);
    max-width: 36rem;
}

.note, .hint { font-size: .9rem; line-height: 1.6; color: var(--muted); max-width: 32rem; }

/* ── Page frame: full-bleed bands, constrained content ───────────────── */
main { flex: 1 0 auto; }

.wrap {
    width: 100%;
    max-width: var(--page);
    margin-inline: auto;
    padding-inline: var(--gutter);
}

section { padding-block: clamp(2.75rem, 5.2vw, 6rem); }
section.band { background: var(--band); }
.hero { padding-block: clamp(2.25rem, 4.6vw, 4.25rem) clamp(1.25rem, 2.2vw, 1.75rem); }

/* Section header — an accent label and a heading, no rule. */
.section-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--s3) var(--s5);
    margin-bottom: clamp(2rem, 4vw, var(--s7));
}
.section-head h2 { margin: 0; }
.count {
    font-size: .72rem;
    font-weight: 600;
    letter-spacing: .18em;
    text-transform: uppercase;
    color: var(--muted);
}

/* ── Masthead ────────────────────────────────────────────────────────── */
.mast { background: var(--band-head); }
.mast .wrap {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--s4) var(--s5);
    padding-block: var(--s5);
}

.mark { display: flex; align-items: center; gap: var(--s3); text-decoration: none; color: inherit; }
.mark svg { flex: none; }
.mark strong { display: block; font: 600 1.35rem/1.1 var(--serif); letter-spacing: -.015em; }
.mark small {
    display: block;
    margin-top: .15rem;
    font: 500 .68rem/1 var(--sans);
    letter-spacing: .16em;
    text-transform: uppercase;
    color: var(--muted);
}

/* Bird mark — theme-driven so it survives dark mode. */
.mark-body { fill: var(--accent); }
.mark-wing { fill: var(--ink); }
.mark-tail { fill: var(--accent-deep); }
.mark-eye  { fill: var(--paper); }
.mark-beak { fill: var(--accent); }

nav { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s5); align-items: center; }
nav a {
    font-size: .88rem;
    font-weight: 500;
    color: var(--ink-2);
    text-decoration: none;
    padding-block: var(--s1);
}
nav a:hover { color: var(--accent); }
nav a.cta {
    color: var(--sheet);
    background: var(--ink);
    padding: .5rem .9rem;
    font-weight: 600;
}
nav a.cta:hover { background: var(--accent); color: var(--on-accent); }

/* Theme toggle — hidden until the script reveals it, so a no-JS visitor is
   never shown a dead control. Which glyph shows is a token, not a selector. */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--ink-2);
    cursor: pointer;
    transition: background .14s ease, color .14s ease;
}
.theme-toggle:hover { background: var(--sheet); color: var(--accent); }
.theme-toggle svg { width: 1.05rem; height: 1.05rem; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }
.icon-sun  { display: var(--show-sun); }
.icon-moon { display: var(--show-moon); }

/* ── Hero ────────────────────────────────────────────────────────────── */
.hero h1 { max-width: 15ch; }
.hero .lede { margin-top: var(--s5); }

.hero-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: clamp(2rem, 5vw, var(--s8));
    align-items: start;
}
.hero-grid > *, .pair > *, .catalog > *, .foot-grid > * { min-width: 0; }

.hero-facts {
    display: flex;
    flex-wrap: wrap;
    gap: var(--s3) var(--s4);
    max-width: 36rem;
    margin: var(--s6) 0 0;
    padding: 0;
    list-style: none;
    font-size: .78rem;
    font-weight: 500;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--muted);
}
.hero-facts li { display: flex; align-items: center; gap: var(--s2); }
.hero-facts li::before { content: ""; flex: none; width: 5px; height: 5px; background: var(--accent); }

/* Price plate: a tonal block, not an outlined card. */
.plate-price { background: var(--band); padding: var(--s6); }
.plate-price .amount {
    display: block;
    margin: 0;
    font: 600 clamp(2.6rem, 4.4vw, 3.4rem)/1 var(--serif);
    letter-spacing: -.03em;
}
.plate-price .per {
    display: block;
    margin: var(--s2) 0 var(--s5);
    font: 500 .8rem/1.5 var(--sans);
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--muted);
}
.plate-price ul { list-style: none; margin: 0 0 var(--s5); padding: 0; display: grid; gap: var(--s4); }
.plate-price li { display: flex; gap: var(--s3); font-size: .95rem; color: var(--ink-2); }
.plate-price li::before { content: "—"; color: var(--accent); flex: none; }

/* ── Catalog ─────────────────────────────────────────────────────────── */
.catalog {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: clamp(2.5rem, 4.6vw, var(--s8)) var(--s7);
}

.entry { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--s4) var(--s5); align-items: start; }

.entry-no {
    font: 400 1rem/1 var(--sans);
    font-variant-numeric: tabular-nums;
    letter-spacing: .06em;
    color: var(--muted);
    padding-top: .45rem;
    min-width: 2.25rem;
}

.entry-body { min-width: 0; }
.entry h3 { margin: 0 0 var(--s1); font-size: 1.45rem; }
.entry h3 a { color: inherit; text-decoration: none; }
.entry h3 a:hover { color: var(--accent); }

.kicker {
    display: block;
    margin-bottom: var(--s3);
    font-size: .78rem;
    font-weight: 600;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--accent);
}
.entry p { margin-bottom: var(--s4); color: var(--ink-2); max-width: 34rem; }

.tags { display: flex; flex-wrap: wrap; gap: var(--s2); margin: 0 0 var(--s4); padding: 0; list-style: none; }
.tag {
    font-size: .72rem;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--muted);
    background: var(--band);
    padding: .25rem .55rem;
    white-space: nowrap;
}
.band .tag { background: var(--sheet); }

.entry-foot { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s3) var(--s5); }
.entry-meta {
    display: flex;
    flex-wrap: wrap;
    gap: var(--s2) var(--s4);
    margin: 0;
    font-size: .8rem;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}
.entry-meta span { white-space: nowrap; }
.entry-meta span:not(:last-child)::after { content: "·"; margin-left: var(--s4); color: var(--muted); opacity: .55; }

.dl {
    font: 600 .88rem/1 var(--sans);
    color: var(--accent);
    text-decoration: none;
    border-bottom: 1px solid currentColor;
    padding-bottom: .15rem;
    white-space: nowrap;
}
.dl:hover { color: var(--accent-deep); }
.dl::after { content: " ↓"; }

.entry.lead h3 { font-size: clamp(1.7rem, 3vw, 2.3rem); }
.entry.lead p { font-size: 1.1rem; max-width: 36rem; }

/* ── Panels & forms ──────────────────────────────────────────────────── */
.panel { background: var(--sheet); padding: clamp(1.4rem, 3.5vw, var(--s6)); }
section:not(.band) .panel { background: var(--band); }
.panel h2, .panel h3 { margin-bottom: var(--s2); }
.panel > .note { margin-bottom: var(--s5); }

.pair { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s5); align-items: stretch; }

form { margin: 0; }
.field { display: block; margin-bottom: var(--s5); }
.field > span, label > span.field-name {
    display: block;
    margin-bottom: var(--s2);
    font: 600 .78rem/1.4 var(--sans);
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--ink-2);
}
.opt { font-weight: 400; letter-spacing: .04em; text-transform: none; color: var(--muted); }

input[type="text"], input[type="email"], select, textarea {
    display: block;
    width: 100%;
    padding: .8rem .85rem;
    border: 1px solid var(--field-line);
    background: var(--sheet);
    color: var(--ink);
    font: 1rem/1.4 var(--serif);
}
input::placeholder { color: var(--muted); opacity: .8; }
input:focus-visible { outline-offset: 1px; border-color: var(--accent); }

/* ── Buttons ─────────────────────────────────────────────────────────── */
button, .button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--s2);
    padding: .82rem 1.4rem;
    border: 1px solid var(--ink);
    background: var(--ink);
    color: var(--paper);
    font: 600 .92rem/1.2 var(--sans);
    letter-spacing: .02em;
    text-decoration: none;
    cursor: pointer;
    transition: background .14s ease, color .14s ease, border-color .14s ease;
}
button:hover, .button:hover { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

button.ghost, .ghost { background: transparent; color: var(--ink); border-color: var(--ink); }
button.ghost:hover, .ghost:hover { background: var(--ink); color: var(--paper); border-color: var(--ink); }

button.wide, .button.wide { width: 100%; }

/* ── Code ────────────────────────────────────────────────────────────── */
.api pre, pre {
    margin: 0 0 var(--s4);
    max-width: 100%;
    padding: var(--s5);
    background: var(--code-bg);
    color: var(--foot-text);
    border: 0;
    overflow-x: auto;
    font: .84rem/1.7 var(--mono);
    tab-size: 2;
}
pre code { font: inherit; color: inherit; background: none; padding: 0; }
:not(pre) > code {
    font: .88em/1 var(--mono);
    background: var(--band);
    padding: .15em .35em;
    color: var(--ink-2);
    white-space: nowrap;
}
.band :not(pre) > code { background: var(--sheet); }

/* ── Notices & license key ───────────────────────────────────────────── */
.banner {
    display: flex;
    gap: var(--s3);
    margin-bottom: var(--s6);
    padding: var(--s4) var(--s5);
    background: var(--accent-wash);
    color: var(--ink-2);
    font-size: .95rem;
}
.banner::before { content: "!"; font-weight: 700; color: var(--accent); }

.key {
    margin: 0 0 var(--s4);
    padding: var(--s5);
    background: var(--code-bg);
    color: var(--foot-text);
    font: 1.15rem/1.5 var(--mono);
    letter-spacing: .1em;
    word-break: break-all;
    max-width: none;
}

.meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
    gap: var(--s5);
    margin: var(--s6) 0;
}
.meta dt {
    margin-bottom: var(--s1);
    font: 600 .72rem/1.4 var(--sans);
    letter-spacing: .16em;
    text-transform: uppercase;
    color: var(--muted);
}
.meta dd { margin: 0; font-size: 1.05rem; }

.steps { counter-reset: step; list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s5); }
.steps li {
    counter-increment: step;
    position: relative;
    padding-left: 2.75rem;
    max-width: 36rem;
    color: var(--ink-2);
}
.steps li::before {
    content: counter(step, decimal-leading-zero);
    position: absolute;
    left: 0;
    top: .1em;
    font: 600 .8rem/1.6 var(--sans);
    letter-spacing: .1em;
    color: var(--accent);
}
.steps strong { color: var(--ink); font-weight: 600; }

/* ── Footer: a near-black block against the light head of the page ───── */
footer {
    flex: none;
    background: var(--foot-bg);
    color: var(--foot-muted);
    padding-block: clamp(3rem, 6vw, var(--s8)) var(--s7);
    font-family: var(--sans);
    font-size: .88rem;
}
.foot-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s6); align-items: start; }
footer h4 {
    margin: 0 0 var(--s3);
    font: 600 .72rem/1.4 var(--sans);
    letter-spacing: .18em;
    text-transform: uppercase;
    color: var(--foot-text);
}
footer ul { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s2); }
footer a { color: var(--foot-muted); text-decoration: none; }
footer a:hover { color: var(--accent-lift); }
footer p { max-width: 24rem; margin: 0; }
.colophon {
    margin-top: var(--s7);
    display: flex;
    flex-wrap: wrap;
    gap: var(--s2) var(--s5);
    justify-content: space-between;
    font-size: .8rem;
}
footer .mark-eye { fill: var(--foot-bg); }

/* ── Responsive ──────────────────────────────────────────────────────── */
/* Breakpoints are set by measure, not by device: a column only splits once
   the text inside it still runs to ~50 characters or more. */
@media (min-width: 46rem) {
    .entry { grid-template-columns: 3rem minmax(0, 1fr); }
    .foot-grid { grid-template-columns: 2fr 1fr 1fr; gap: var(--s7); }
}

@media (min-width: 62rem) {
    .hero-grid { grid-template-columns: minmax(0, 1.7fr) minmax(18rem, 1fr); }
    .pair { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s6); }
}

@media (min-width: 75rem) {
    .catalog { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .entry.lead { grid-column: 1 / -1; }
    .entry.lead .entry-body { max-width: 46rem; }
}

@media (max-width: 30rem) {
    .entry { grid-template-columns: minmax(0, 1fr); }
    .entry-no { padding-top: 0; }
    .entry-foot { align-items: flex-start; flex-direction: column; }
}

/* ── Dark theme ──────────────────────────────────────────────────────────
   Three states: system default (media query), an explicit light choice that
   must beat it, and an explicit dark choice that must win when the system is
   light. Values only — every component rule above reads these tokens. */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
    color-scheme: dark;
    --paper:      #0f1115;
    --band:       #15181e;
    --band-head:  #12151a;
    --sheet:      #1a1e25;
    --ink:        #eef0f4;
    --ink-2:      #c2c8d4;
    --muted:      #949baa;
    --field-line: #70788a;
    --foot-bg:    #06070a;
    --foot-text:  #eef0f4;
    --foot-muted: #949baa;
    --code-bg:    #040507;
    --on-accent:  #0f1115;
    --show-sun:   block;
    --show-moon:  none;
    --accent:      var(--accent-lift);
    --accent-deep: var(--accent-lift);
    --accent-wash: #1c2331;
    }
}
:root[data-theme="dark"] {
    color-scheme: dark;
    --paper:      #0f1115;
    --band:       #15181e;
    --band-head:  #12151a;
    --sheet:      #1a1e25;
    --ink:        #eef0f4;
    --ink-2:      #c2c8d4;
    --muted:      #949baa;
    --field-line: #70788a;
    --foot-bg:    #06070a;
    --foot-text:  #eef0f4;
    --foot-muted: #949baa;
    --code-bg:    #040507;
    --on-accent:  #0f1115;
    --show-sun:   block;
    --show-moon:  none;
    --accent:      var(--accent-lift);
    --accent-deep: var(--accent-lift);
    --accent-wash: #1c2331;
}
:root[data-theme="light"] { color-scheme: light; }

/* ── Motion & print ──────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}

@media print {
    body { background: #fff; color: #000; }
    section.band, .mast, footer { background: #fff !important; color: #000; }
    nav, .plate-price .button, form, .skip { display: none; }
    pre, .key { background: #fff; color: #000; border: 1px solid #999; }
}
