/*
 * DDT Design System: tokens.
 * Light is the default. Dark follows the OS (prefers-color-scheme) unless
 * the page sets data-theme="light" or data-theme="dark" on <html>.
 * Contrast ratios are WCAG 2.x, measured against --bg / --surface.
 */

:root {
  color-scheme: light;

  /* Colour: light theme (default) */
  --bg: #ffffff;
  --surface: #f7f6f3;           /* cards, bands, code blocks */
  --ink: #111110;               /* 18.89 : 1  / 17.48 : 1 */
  --ink-muted: #52524e;         /*  7.85 : 1  /  7.26 : 1 secondary text */
  --ink-subtle: #63635e;        /*  6.04 : 1  /  5.59 : 1 captions, meta */
  --accent: #9a4a12;            /*  6.25 : 1  /  5.78 : 1 copper; links, primary button */
  --accent-hover: #7c3b0e;      /*  8.44 : 1  /  7.81 : 1 */
  --accent-ink: #ffffff;        /* on --accent 6.25 : 1, on --accent-hover 8.44 : 1 */
  --border: #d6d4ce;            /*  1.48 : 1 decorative hairline only, never the only boundary of a control */
  --border-ui: #86847d;         /*  3.74 : 1  /  3.46 : 1 input and control boundaries (WCAG 1.4.11) */
  --focus: #111110;             /* 18.89 : 1 focus ring */
  --selection: #f1dfd1;         /* text selection background; --ink on it 14.59 : 1 */

  /* Technical figures: the board (light). Ratios against --board-substrate / --board-pour.
     Resting copper and the board edge are graphics needed to read the figure: >= 3:1 (WCAG 1.4.11).
     --board-copper-back, --board-copper-dim and --board-pour are context only, never the sole carrier of meaning. */
  --board-substrate: #f1ece2;   /* board body; 1.18 : 1 against --bg, the edge line carries the shape */
  --board-pour: #e9dccb;        /* copper zones as a quiet tint; 1.15 : 1 */
  --board-copper: #a8581f;      /*  4.37 : 1  /  3.81 : 1 top copper at rest */
  --board-copper-back: #c99a74; /*  2.13 : 1 bottom copper, seen through the substrate */
  --board-copper-dim: #dccab6;  /*  1.35 : 1 copper not in the selected signal */
  --board-highlight: #7c3b0e;   /*  7.17 : 1  /  6.25 : 1 selected signal; 5.29 : 1 against --board-copper-dim */
  --board-silk: #3b3a36;        /*  9.67 : 1  /  8.44 : 1 silkscreen lines and text */
  --board-drill: var(--bg);     /* holes show the page through the board */
  --board-edge: #86847d;        /*  3.18 : 1 on substrate, 3.74 : 1 on --bg; board outline */
  --board-shadow: rgb(17 17 16 / 0.10);

  /* Type families */
  --font-display: "Instrument Serif", "Instrument Serif Fallback", "Iowan Old Style", Georgia, "Times New Roman", serif;
  --font-sans: "Inter", "Inter Fallback", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* Type scale. Display face only for --text-h3 and up (>= 24px). */
  --text-xs: 0.75rem;                        /* 12px  meta only, never body */
  --text-sm: 0.875rem;                       /* 14px  captions, footer, tags */
  --text-body: 1rem;                         /* 16px */
  --text-lead: 1.1875rem;                    /* 19px  intro paragraphs */
  --text-h3: 1.5rem;                         /* 24px  display face allowed from here */
  --text-h2: clamp(1.85rem, 3vw, 2.75rem);   /* 29.6 to 44px */
  --text-h1: clamp(2.4rem, 4.8vw, 4.25rem);  /* 38.4 to 68px */
  --text-display: clamp(3.25rem, 7.2vw, 6.5rem); /* 52 to 104px, hero line */

  --leading-display: 1.02;
  --leading-heading: 1.15;
  --leading-body: 1.6;
  --leading-tight: 1.3;                      /* UI, buttons, nav */

  --tracking-display: -0.01em;
  --tracking-body: 0;

  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 600;

  /* Space (4px base) */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;
  --s-7: 48px;
  --s-8: 72px;
  --s-9: 112px;

  /* Layout */
  --container: 1120px;
  --gutter: clamp(16px, 4vw, 32px);   /* page side margin; 16px at phone width */
  --measure: 62ch;                     /* max line length for prose */
  --nav-height: 64px;
  --target-min: 44px;                  /* minimum touch target */

  /* Shape */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-pill: 999px;
  --hairline: 1px;

  /* Focus */
  --focus-width: 2px;
  --focus-offset: 3px;

  /* Motion */
  --ease: cubic-bezier(0.22, 1, 0.36, 1);        /* default ease-out: UI responses */
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);  /* state changes that move geometry (layer spread, tilt) */
  --ease-draw: cubic-bezier(0.33, 0, 0.2, 1);     /* stroke draw-in */
  --dur-fast: 120ms;   /* hover, press, colour */
  --dur: 200ms;        /* focus, small reveals, signal highlight */
  --dur-slow: 360ms;   /* layer spread, figure tilt */
  --dur-draw: 900ms;   /* one-time copper draw-in; with --stagger the whole draw stays <= 1.2s */
  --stagger: 30ms;     /* per-group delay in a draw-in, at most 10 groups */

  /* Technical figure geometry */
  --figure-perspective: 1800px;
  --figure-tilt-x: 38deg;     /* rest tilt, applied only with JS, motion allowed and width >= 720px */
  --figure-tilt-z: -16deg;
  --figure-scale: 0.84;       /* keeps the tilted board inside its column */
  --layer-gap: 10px;          /* distance between layers at rest */
  --layer-gap-spread: 44px;   /* distance when the layer control is on */
  --layer-mid: 1.5;           /* stack centre: (layers - 1) / 2 for 4 layers */

  /* Layers */
  --z-nav: 10;
  --z-menu: 20;
  --z-skip: 30;
}

/* Dark theme: values shared by the OS preference and the explicit toggle. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0e0f10;
    --surface: #16181a;
    --ink: #f4f3ef;             /* 17.28 : 1  / 16.03 : 1 */
    --ink-muted: #a8a9a4;       /*  8.11 : 1  /  7.52 : 1 */
    --ink-subtle: #8e908b;      /*  5.95 : 1  /  5.52 : 1 */
    --accent: #e09a63;          /*  8.20 : 1  /  7.61 : 1 */
    --accent-hover: #eab089;    /* 10.11 : 1  /  9.38 : 1 */
    --accent-ink: #111110;      /* on --accent 8.07 : 1, on --accent-hover 9.96 : 1 */
    --border: #2a2d30;          /*  1.39 : 1 decorative only */
    --border-ui: #6e7278;       /*  3.97 : 1  /  3.68 : 1 */
    --focus: #e09a63;           /*  8.20 : 1 */
    --selection: #4a3222;       /* --ink on it 10.68 : 1 */

    --board-substrate: #1b1d1c;
    --board-pour: #2a2622;
    --board-copper: #d08a55;      /*  6.01 : 1  /  5.32 : 1 */
    --board-copper-back: #7d5a40; /*  2.75 : 1 */
    --board-copper-dim: #3d342c;  /*  1.39 : 1 */
    --board-highlight: #f0b688;   /*  9.48 : 1  /  8.40 : 1; 6.81 : 1 against --board-copper-dim */
    --board-silk: #c9c7c0;        /* 10.02 : 1  /  8.87 : 1 */
    --board-edge: #6e7278;        /*  3.50 : 1 on substrate, 3.97 : 1 on --bg */
    --board-shadow: rgb(0 0 0 / 0.45);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e0f10;
  --surface: #16181a;
  --ink: #f4f3ef;
  --ink-muted: #a8a9a4;
  --ink-subtle: #8e908b;
  --accent: #e09a63;
  --accent-hover: #eab089;
  --accent-ink: #111110;
  --border: #2a2d30;
  --border-ui: #6e7278;
  --focus: #e09a63;
  --selection: #4a3222;

  --board-substrate: #1b1d1c;
  --board-pour: #2a2622;
  --board-copper: #d08a55;      /*  6.01 : 1  /  5.32 : 1 */
  --board-copper-back: #7d5a40; /*  2.75 : 1 */
  --board-copper-dim: #3d342c;  /*  1.39 : 1 */
  --board-highlight: #f0b688;   /*  9.48 : 1  /  8.40 : 1; 6.81 : 1 against --board-copper-dim */
  --board-silk: #c9c7c0;        /* 10.02 : 1  /  8.87 : 1 */
  --board-edge: #6e7278;        /*  3.50 : 1 on substrate, 3.97 : 1 on --bg */
  --board-shadow: rgb(0 0 0 / 0.45);
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --dur-fast: 0ms;
    --dur: 0ms;
    --dur-slow: 0ms;
    --dur-draw: 0ms;
    --stagger: 0ms;
    --figure-tilt-x: 0deg;
    --figure-tilt-z: 0deg;
    --figure-scale: 1;
    --layer-gap: 0px;
    --layer-gap-spread: 0px;
  }
}
