/* Velofy design tokens, v2.0.0 ("Lab notebook").
   Source of truth: design/DIRECTION.md (velofy-overhaul). Vendored copies keep this first line so a
   diff against velofy-co/shared/tokens.css shows drift.
   Dark is the default and needs no JavaScript. Light is html[data-theme="light"].
   With no data-theme attribute at all, the page follows the OS (prefers-color-scheme), which is what
   the static subdomain sites and the docs do today. The Astro Layout renders data-theme="dark" on <html>
   so the main site stays dark-by-default without JS.
   How to apply without a rewrite: load this file BEFORE the site's own CSS, then delete the site's own
   custom-property blocks (:root, [data-theme], prefers-color-scheme) or reduce them to a bridge that maps
   local names to these tokens (e.g. --card:var(--bg-raised)). A later :root block with the same names
   silently wins and makes this file a no-op.
   AINS swaps only the accent: [data-brand="ains"] (or the existing .ains scope).
   Product subdomains use gold by default; a product --accent is allowed only for an
   identity that predates this system (today: summitjs) and needs a token PR.
   Contrast ratios in comments are WCAG 2.x, measured against --bg / --bg-raised / --bg-inset.
   Fluid sizes interpolate between 360px and 1440px viewports.
   Breakpoints (use literally in @media, custom properties do not work there):
     sm 650px · md 900px · lg 1180px · xl 1440px */

:root{
  color-scheme:dark;

  /* ---------- Color: dark (default) ---------- */
  /* Ground. Warm off-black, not #000. */
  --bg:#0d0c0a;            /* page */
  --bg-raised:#151411;     /* cards, panels, table heads, figures */
  --bg-inset:#1c1a16;      /* inputs, inline code, hover fill, chips */
  --bg-plate:#0d0c0a;      /* footer plate, set-piece sections (same in both themes) */

  /* Ink. Two-tone headlines use --ink then --ink-dim. */
  --ink:#e6dec7;           /* 14.56 / 13.72 / 12.94 */
  --ink-prose:#d6cfb9;     /* 12.55 / 11.83 / 11.16  long-form body */
  --ink-muted:#a09a8a;     /*  6.97 /  6.56 /  6.19  secondary text, deks */
  --ink-faint:#8e8879;     /*  5.54 /  5.22 /  4.92  captions, metadata; smallest text allowed.
                              4.64 on --accent-wash over --bg; below 4.5 on --accent-wash over --bg-raised (4.26),
                              on --selection and on --seq-3..5: never set faint text there. */
  --ink-dim:var(--accent); /* second clause of a two-tone headline */

  /* Lines. --line is decorative (hairlines between rows); --line-strong is for
     component boundaries that must be seen (inputs, ghost buttons): >= 3:1. */
  --line:#2f2c27;
  --line-strong:#6b6559;   /* 3.38 / 3.18 / 3.00 */

  /* Accent: core Velofy gold. Links, focus, the "subject" series in charts, primary fill. */
  --accent-velofy:#c8ad86;        /* 9.10 / 8.58 / 8.09 */
  --accent-velofy-strong:#d9c19c; /* hover on dark, 11.23 */
  /* Sibling accent: AINS sea glass. */
  --accent-ains:#86c5b3;          /* 9.92 / 9.34 / 8.81 */
  --accent-ains-strong:#a3d6c7;   /* 12.10 */

  --accent:var(--accent-velofy);
  --accent-strong:var(--accent-velofy-strong);
  --on-accent:#0d0c0a;            /* text on an accent fill: 9.10 gold, 9.92 sea glass */
  --wash-pct:12%;
  --accent-wash:color-mix(in srgb,var(--accent) var(--wash-pct),transparent); /* = rgba(200,173,134,.12) for gold; follows a product --accent set on :root.
                                          selected row, active tab fill. Text on it: --ink or --ink-muted only
                                          (muted 5.36 even over --bg-raised); never --ink-faint or accent text over --bg-raised. */
  --selection:#3a3122;
  --selection-ink:var(--ink); /* ::selection{background:var(--selection);color:var(--selection-ink)}. Required: faint (3.62)
                                 and muted (4.56) text keep their colour inside a selection otherwise. ink: 9.52 dark / 12.32 light. */
  --focus-ring:var(--accent);

  /* Status, for callouts and badges. Text colors pass 4.5:1 on all three grounds. */
  --info:#8fb3d9;    --info-bg:#12161b;    /* 8.95 */
  --ok:#8fbf8a;      --ok-bg:#121a14;      /* 9.30 */
  --warn:#d9a95b;    --warn-bg:#1a1610;    /* 9.10. OPEN: hue 37deg vs gold accent 35deg, so caution reads as brand; see DIRECTION "Critique: brand and taste" */
  --danger:#e8836f;  --danger-bg:#1d1311;  /* 7.36 */
  /* --ink on every *-bg tint is >= 13.2:1. */

  /* Data / charts. One encoding per chart. Graphics need 3:1, direct labels 4.5:1. */
  --chart-subject:var(--accent);  /* the thing the chart is about (Velofy run, the winner) */
  /* The closed/open pair is the CVD-validated pair already shipped in benchmarks.css. Marks only:
     value labels and names are set in --ink, never in the series colour. */
  --chart-closed:#3987e5;         /* closed weights: 5.37 / 5.06 */
  --chart-open:#d95926;           /* open weights:   5.03 / 4.74. OPEN: hue 17deg, next to the banned terracotta #d97757 (15deg) */
  --chart-neutral:#7d7668;        /* everything else, dominated points: 4.34 / 4.09 */
  --chart-grid:#24221e;           /* gridlines, 1px, never solid black/white */
  --chart-axis:var(--ink-faint);
  --chart-hatch:repeating-linear-gradient(135deg,currentColor 0 1px,transparent 1px 5px); /* partial period, "no public API" */
  /* Sequential ramp for heatmap table cells (low -> high). Text on every step stays --ink (>= 7.48 both themes).
     --ink-muted fails from --seq-4 (4.42 dark, 3.76 light) and --ink-faint from --seq-3: never use them on the ramp.
     The printed value is the encoding; colour is redundant (WCAG 1.4.1). */
  --seq-1:#15140f; --seq-2:#211d15; --seq-3:#2e271b; --seq-4:#3d3322; --seq-5:#4d3f2a;

  /* Code: dark in both themes. */
  --code-bg:#12110e;
  --code-head:#1a1814;
  --code-line:#2a2722;
  --code-ink:#e6dec7;     /* 14.06 */
  --code-muted:#a09a8a;   /*  6.73 */
  --code-comment:#8f8977; /*  5.41 */
  --code-keyword:#d9b98a; /* 10.12 */
  --code-string:#9ccfa8;  /* 10.70 */
  --code-function:#9fc1e8;/* 10.13 */
  --code-number:#e8a07a;  /*  8.76 */
  --code-added-bg:rgba(143,191,138,.10);
  --code-added-bar:#8fbf8a;
  --code-removed-bg:rgba(232,131,111,.10);
  --code-removed-bar:#e8836f;

  /* ---------- Type ---------- */
  --font-sans:'Switzer',system-ui,-apple-system,'Segoe UI',sans-serif;
  --font-display:var(--font-sans);
  --font-mono:'Fragment Mono',ui-monospace,'SFMono-Regular',Menlo,Consolas,monospace;
  --font-wordmark:'Michroma',var(--font-sans); /* wordmark and AINS lockup only */

  /* Fluid scale, 360 -> 1440. */
  --fs-micro:clamp(0.6875rem,0.6771rem + 0.0463vw,0.71875rem);  /* 11 -> 11.5  mono eyebrows; the floor */
  --fs-xs:clamp(0.78125rem,0.7708rem + 0.0463vw,0.8125rem);     /* 12.5 -> 13  captions, table meta */
  --fs-sm:clamp(0.875rem,0.8542rem + 0.0926vw,0.9375rem);       /* 14 -> 15    UI, nav, tables */
  --fs-base:clamp(1rem,0.9792rem + 0.0926vw,1.0625rem);         /* 16 -> 17    body */
  --fs-read:clamp(1.0625rem,1.0208rem + 0.1852vw,1.1875rem);    /* 17 -> 19    long-form body */
  --fs-lead:clamp(1.125rem,1.0625rem + 0.2778vw,1.3125rem);     /* 18 -> 21    deks, ledes */
  --fs-h4:clamp(1.1875rem,1.125rem + 0.2778vw,1.375rem);        /* 19 -> 22 */
  --fs-h3:clamp(1.375rem,1.25rem + 0.5556vw,1.75rem);           /* 22 -> 28 */
  --fs-h2:clamp(1.75rem,1.4167rem + 1.4815vw,2.75rem);          /* 28 -> 44 */
  --fs-h1:clamp(2.25rem,1.6667rem + 2.5926vw,4rem);             /* 36 -> 64 */
  --fs-display:clamp(2.625rem,1.6667rem + 4.2593vw,5.5rem);     /* 42 -> 88   home and AINS heroes */
  --fs-mega:clamp(3.5rem,1.8333rem + 7.4074vw,8.5rem);          /* 56 -> 136  launch set pieces only */

  --lh-tight:1.02;   /* display, h1 */
  --lh-heading:1.12; /* h2-h4 */
  --lh-ui:1.4;
  --lh-body:1.6;
  --lh-read:1.7;

  --tracking-display:-0.035em;
  --tracking-heading:-0.02em;
  --tracking-body:0;
  --tracking-eyebrow:0.08em; /* mono uppercase labels */

  --fw-light:300; --fw-regular:400; --fw-medium:500; --fw-semibold:600;

  --measure:66ch;     /* reading column */
  --measure-dek:52ch; /* ledes under titles */

  /* ---------- Space (4px base) ---------- */
  --space-0:0;
  --space-1:0.25rem;  /*   4 */
  --space-2:0.5rem;   /*   8 */
  --space-3:0.75rem;  /*  12 */
  --space-4:1rem;     /*  16 */
  --space-5:1.5rem;   /*  24 */
  --space-6:2rem;     /*  32 */
  --space-7:3rem;     /*  48 */
  --space-8:4rem;     /*  64 */
  --space-9:6rem;     /*  96 */
  --space-10:8rem;    /* 128 */
  --space-11:10rem;   /* 160 */
  --space-section:clamp(4.5rem,2.6667rem + 8.1481vw,10rem); /* 72 -> 160 between page sections */
  --space-stack:clamp(2.5rem,1.8333rem + 2.963vw,4.5rem);   /* 40 -> 72 between blocks in a section */

  /* ---------- Radii ---------- */
  --radius-0:0;
  --radius-1:2px;     /* tags, inline code, table chips */
  --radius-2:4px;     /* cards, callouts, inputs in dense UI */
  --radius-3:8px;     /* code blocks, figures, media */
  --radius-pill:999px;/* buttons, header controls, filter pills */

  /* ---------- Shadows ----------
     The system is flat: hairlines group things, shadows do not.
     Shadows exist only for layers that float over content. */
  --shadow-none:none;
  --shadow-pop:0 1px 0 rgba(255,255,255,.04) inset,0 12px 32px -8px rgba(0,0,0,.6),0 0 0 1px var(--line);
  --shadow-sheet:0 -16px 48px -12px rgba(0,0,0,.7);
  --shadow-focus:0 0 0 2px var(--bg),0 0 0 4px var(--focus-ring);

  /* ---------- Motion ---------- */
  --dur-instant:80ms;  /* press states */
  --dur-fast:150ms;    /* color, border, background */
  --dur-base:220ms;    /* arrows, thumbs, accordions */
  --dur-slow:420ms;    /* sheets, menu entrance */
  --dur-slower:600ms;  /* figure reveal; never on text */
  --ease-out:cubic-bezier(.22,1,.36,1);     /* default for things arriving */
  --ease-in-out:cubic-bezier(.65,0,.35,1);  /* things moving between two states */
  --ease-in:cubic-bezier(.4,0,1,1);         /* things leaving */
  --ease-linear:linear;                     /* progress, loops */
  --stagger:40ms;

  /* ---------- Grid ---------- */
  --page-max:1280px;   /* outer frame (header, footer) */
  --content-max:1184px;/* 12-column content frame */
  --gutter:clamp(1.25rem,0.6667rem + 2.5926vw,3rem); /* 20 -> 48 page side padding */
  --columns:12;
  --col-gap:clamp(1rem,0.7917rem + 0.9259vw,1.5rem); /* 16 -> 24 */
  --rail:200px;        /* left gutter for dates, TOC, section labels (index + paper pages) */
  --read-col:680px;    /* long-form text track */
  --wide-col:960px;    /* figures that break out of the text track */
  --note-col:240px;    /* right sidenote gutter (>= 1180px) */
  --docs-nav:248px;
  --docs-toc:220px;
  --docs-content:760px;
  --header-h:64px;
  --header-h-sm:56px;

  /* ---------- Layers ---------- */
  --z-base:0; --z-sticky:20; --z-header:40; --z-sheet:60; --z-popover:80; --z-toast:100;

  /* ---------- Legacy aliases (remove once theme.css is migrated) ---------- */
  --paper:var(--bg); --panel:var(--bg-raised); --soft:var(--bg-inset); --lime:var(--bg-inset);
  --prose-ink:var(--ink-prose); --muted:var(--ink-muted); --edge:var(--line-strong);
  --glyph:#8a7656; --footer:var(--bg-plate); --tag:rgba(255,247,221,.11); --raise:var(--bg-inset);
  --display-font:var(--font-display); --sans-font:var(--font-sans); --mono-font:var(--font-mono); --wordmark-font:var(--font-wordmark);
}

/* ---------- Color: light ("paper") ---------- */
html[data-theme="light"]{
  color-scheme:light;
  --bg:#f5efe0;
  --bg-raised:#ede6d4;
  --bg-inset:#e6dec9;
  --bg-plate:#0d0c0a;      /* footer stays a dark plate */

  --ink:#17140e;           /* 16.02 / 14.76 / 13.70 */
  --ink-prose:#2a251b;     /* 13.28 / 12.23 / 11.35 */
  --ink-muted:#5c5546;     /*  6.44 /  5.93 /  5.51 */
  --ink-faint:#645d4d;     /*  5.69 /  5.25 /  4.87 */

  --line:#d6ccb4;
  --line-strong:#857b66;   /* 3.64 / 3.36 / 3.12 */

  --accent-velofy:#765a33;        /* 5.58 / 5.14 / 4.77 */
  --accent-velofy-strong:#5d4626; /* 7.73 */
  --accent-ains:#2d6a5c;          /* 5.50 / 5.07 / 4.70 */
  --accent-ains-strong:#225246;   /* 7.75 */
  --on-accent:#f5efe0;            /* 5.58 gold fill, 5.50 sea glass fill */
  --wash-pct:10%;          /* --accent-wash = rgba(118,90,51,.10) for gold */
  --selection:#e2d2b0;

  --info:#2c5c8f;    --info-bg:#e4e9ef;    /* 6.03 */
  --ok:#2f6b34;      --ok-bg:#dfeadb;      /* 5.59 */
  --warn:#7f5612;    --warn-bg:#f3e6c9;    /* 5.65 */
  --danger:#a63a24;  --danger-bg:#f4dcd4;  /* 5.63 */
  /* --ink on every *-bg tint is >= 14.0:1. */

  --chart-closed:#2a78d6;  /* 3.85 / 3.55 (marks only) */
  --chart-open:#c9531f;    /* 3.86 / 3.56 (marks only) */
  --chart-neutral:#7f7764; /* 3.87 / 3.57 (graphics only) */
  --chart-grid:#e3dac6;
  --seq-1:#efe8d6; --seq-2:#e7dbbf; --seq-3:#dccaa3; --seq-4:#cfb686; --seq-5:#c0a16a;

  --shadow-pop:0 12px 32px -10px rgba(40,30,10,.22),0 0 0 1px var(--line);
  --shadow-sheet:0 -16px 48px -12px rgba(40,30,10,.25);

  --glyph:#a88d63; --tag:rgba(23,20,14,.07);
  /* Code tokens are not redefined: code blocks stay dark in light mode. */
}

/* ---------- Color: light, following the OS when no data-theme is set ----------
   Same values as the html[data-theme="light"] block above (CSS cannot share one declaration list
   between a selector and a media query). Edit both together; a sync check should diff them. */
@media (prefers-color-scheme:light){
  html:not([data-theme]){
    color-scheme:light;
    --bg:#f5efe0;
    --bg-raised:#ede6d4;
    --bg-inset:#e6dec9;
    --bg-plate:#0d0c0a;
    --ink:#17140e;
    --ink-prose:#2a251b;
    --ink-muted:#5c5546;
    --ink-faint:#645d4d;
    --line:#d6ccb4;
    --line-strong:#857b66;
    --accent-velofy:#765a33;
    --accent-velofy-strong:#5d4626;
    --accent-ains:#2d6a5c;
    --accent-ains-strong:#225246;
    --on-accent:#f5efe0;
    --wash-pct:10%;
    --selection:#e2d2b0;
    --info:#2c5c8f;    --info-bg:#e4e9ef;
    --ok:#2f6b34;      --ok-bg:#dfeadb;
    --warn:#7f5612;    --warn-bg:#f3e6c9;
    --danger:#a63a24;  --danger-bg:#f4dcd4;
    --chart-closed:#2a78d6;
    --chart-open:#c9531f;
    --chart-neutral:#7f7764;
    --chart-grid:#e3dac6;
    --seq-1:#efe8d6; --seq-2:#e7dbbf; --seq-3:#dccaa3; --seq-4:#cfb686; --seq-5:#c0a16a;
    --shadow-pop:0 12px 32px -10px rgba(40,30,10,.22),0 0 0 1px var(--line);
    --shadow-sheet:0 -16px 48px -12px rgba(40,30,10,.25);
    --glyph:#a88d63; --tag:rgba(23,20,14,.07);
  }
}

/* ---------- AINS: sibling accent, everything else shared ---------- */
[data-brand="ains"],.ains{
  --accent:var(--accent-ains);
  --accent-strong:var(--accent-ains-strong);
  --accent-wash:color-mix(in srgb,var(--accent-ains) var(--wash-pct),transparent);
  --chart-subject:var(--accent-ains);
  /* Tokens that reference --accent are re-declared here, because custom properties resolve where declared. */
  --ink-dim:var(--accent-ains);
  --focus-ring:var(--accent-ains);
  --shadow-focus:0 0 0 2px var(--bg),0 0 0 4px var(--accent-ains);
}

/* ---------- Dark plate: footer and launch set pieces, in both themes ----------
   --bg-plate stays #0d0c0a in light mode, but light --ink (#17140e) on it is 1.06:1, and light gold
   (#765a33) is 3.05:1. Anything painted on the plate must take dark values, so the plate pins them.
   Custom properties resolve where declared, so every token that derives from --accent or --ink is
   re-declared here too. The plate stays gold on AINS pages (DIRECTION 3.2), so this also beats .ains. */
.lab-footer,[data-surface="plate"]{
  color-scheme:dark;
  --bg:#0d0c0a; --bg-raised:#151411; --bg-inset:#1c1a16;
  --ink:#e6dec7; --ink-prose:#d6cfb9; --ink-muted:#a09a8a; --ink-faint:#8e8879;
  --line:#2f2c27; --line-strong:#6b6559;
  --accent:#c8ad86; --accent-strong:#d9c19c; --ink-dim:#c8ad86; --on-accent:#0d0c0a;
  --accent-wash:rgba(200,173,134,.12); --selection:#3a3122; --selection-ink:#e6dec7;
  --focus-ring:#c8ad86; --shadow-focus:0 0 0 2px #0d0c0a,0 0 0 4px #c8ad86;
  --chart-subject:#c8ad86; --chart-axis:#8e8879;
  /* Legacy aliases resolve where declared (:root), so inside the plate they would keep light values. */
  --paper:var(--bg); --panel:var(--bg-raised); --soft:var(--bg-inset); --lime:var(--bg-inset); --raise:var(--bg-inset);
  --prose-ink:var(--ink-prose); --muted:var(--ink-muted); --edge:var(--line-strong);
  --glyph:#8a7656; --tag:rgba(255,247,221,.11);
  background:var(--bg-plate); color:var(--ink);
}

/* ---------- Reduced motion ----------
   Durations go to 0.01ms, not 0: a 0s transition never fires transitionend, so any JS that waits for it
   (sheet close, accordion, toast dismissal) would hang. This only covers transitions and one-shot
   animations that read the tokens. Loops (live dot, MarkField, ASCII field) must be gated with
   @media (prefers-reduced-motion:no-preference) or matchMedia, never by a token: an infinite animation
   at 0.01ms flickers. */
@media (prefers-reduced-motion:reduce){
  :root{--dur-instant:0.01ms;--dur-fast:0.01ms;--dur-base:0.01ms;--dur-slow:0.01ms;--dur-slower:0.01ms;--stagger:0ms}
  :root{scroll-behavior:auto}
}
