/*
 * The lab's own variables: the frame around the exhibits (page, titles,
 * labels, navigator, dock, notes, the Atlas home) reads these and nothing of
 * Dusk's. Presented Dusk components keep reading Dusk's tokens.
 *
 * One file, kept identical in the lab (src/zlab/lab) and the Atlas (src/lab);
 * the Atlas's scripts/check-lab.mjs fails when the copies drift.
 *
 * Colours are OKLCH triplets, used as oklch(var(--zl-ink)). The palette is
 * Level: flat on Dusk's own paper and graphite, lines instead of shadows,
 * graphite ink as the accent. Secondary and tertiary ink hold 4.5:1 on the
 * paper and raised surfaces; lines sit 1.5:1 off the paper so panels read in the dark.
 */

:root {
  --zl-canvas: 0.965 0.015 72;
  --zl-card: 0.965 0.015 72;
  --zl-raised: 0.985 0.008 76;
  --zl-line: 0.85 0.018 70;
  --zl-line-raised: 0.84 0.018 70;
  --zl-ink: 0.182 0.01 62;
  --zl-ink-muted: 0.44 0.017 62;
  --zl-ink-subtle: 0.53 0.017 66;
  --zl-well: 0.935 0.017 71;
  --zl-well-raised: 0.945 0.016 72;
  --zl-skeleton: 0.925 0.018 71; /* a loading or blueprint mark: Dusk's --skeleton */
  --zl-track: 0.93 0.017 71;
  --zl-fill: 0.942 0.016 72;
  --zl-selected: 0.915 0.02 70;
  --zl-thumb: 0.985 0.008 76;
  --zl-device: 0.182 0.01 62;
  --zl-accent: 0.3 0.012 62;
  --zl-positive: 0.525 0.11 165;
  --zl-shadow-card: 0 0 0 0 transparent;
  --zl-shadow-raised: inset 0 0 0 1px oklch(0.84 0.018 70);
  --zl-shadow-overlay:
    inset 0 0 0 1px oklch(0.84 0.018 70), 0 16px 40px -16px oklch(0.3 0.03 62 / 0.2);
  --zl-shadow-device: 0 0 0 1px oklch(0.3 0.02 62 / 0.12);
  --zl-thumb-shadow: 0 0 0 1px oklch(0.85 0.018 70);
  --zl-scrim: oklch(0.182 0.01 62 / 0.24);

  /* The dock, inverted against the page: graphite on a light page, porcelain on a dark one. */
  --zl-inv: 0.215 0.004 62;
  --zl-inv-ink: 0.96 0.003 75;
  --zl-inv-muted: 0.72 0.004 68;
  --zl-inv-subtle: 0.62 0.004 62;
  --zl-inv-fill: 1 0 0 / 0.08;
  --zl-inv-thumb: 0.34 0.004 62;
  --zl-inv-line: 1 0 0 / 0.1;
  --zl-inv-shadow: drop-shadow(0 1px 1px oklch(0.2 0.01 62 / 0.12));
  --zl-inv-panel-shadow:
    0 1px 2px oklch(0.2 0.01 62 / 0.12), 0 16px 40px -8px oklch(0.2 0.01 62 / 0.24);

  /*
   * Type: Timeless Grotesk (Timeless Sans VF at STYL 0, wght 300 to 800), with
   * fallbacks matched to its width and line box so the swap does not move text.
   * Dusk's exhibits keep M Saans (--zl-font-dusk).
   */
  --zl-font: "Timeless Grotesk", "Timeless Fallback", "Timeless Fallback Arial", ui-sans-serif, system-ui, sans-serif;
  --zl-font-title: var(--zl-font);
  --zl-font-dusk: "M Saans", ui-sans-serif, system-ui, sans-serif;
  --zl-font-mono: ui-monospace, "SF Mono", Menlo, monospace;
  --zl-tracking: 1;
  /* The face's line box and the middle of its x-height, in em (ascent 0.963, descent 0.248, x-height 0.518). */
  --zl-font-box: 1.211;
  --zl-font-xmid: 0.704;

  /* Weights: the face's Regular for text, its Medium for labels and titles, between them for display. */
  --zl-weight: 420;
  --zl-label-weight: 500;
  --zl-title-weight: 500;
  --zl-display-weight: 460;

  /*
   * The scale, locked: six sizes, seven roles. Base 14, the size a dense tool
   * reads at, carries running text and labels; secondary text steps down in
   * ink, never in size. 12 is the one small step and is rare: counts, keys,
   * dates, versions. Above 14 a perfect fourth snapped to even pixels: 18, 24,
   * 32, 44. Leading opens to 1.57 for reading at 14 and tightens as size grows
   * (titles on a 2px grid); tracking opens slightly below 14 and closes on a
   * log curve to -0.026em at 44. scripts/check-type.mjs fails the build on
   * any frame size, leading or tracking that is not one of these variables.
   */
  --zl-display: 2.75rem; /* 44px */
  --zl-display-lh: calc(48 / 44);
  --zl-display-track: -0.026em;
  --zl-title-1: 2rem; /* 32px */
  --zl-title-1-lh: calc(38 / 32);
  --zl-title-1-track: -0.02em;
  --zl-title-2: 1.5rem; /* 24px */
  --zl-title-2-lh: calc(30 / 24);
  --zl-title-2-track: -0.014em;
  --zl-title-3: 1.125rem; /* 18px */
  --zl-title-3-lh: calc(24 / 18);
  --zl-title-3-track: -0.007em;
  --zl-lead: 1.125rem; /* 18px */
  --zl-lead-lh: calc(28 / 18);
  --zl-lead-track: -0.005em;
  --zl-body: 0.875rem; /* 14px */
  --zl-body-lh: calc(22 / 14);
  --zl-body-track: 0.003em;
  --zl-meta: 0.75rem; /* 12px */
  --zl-meta-lh: calc(16 / 12);
  --zl-meta-track: 0.012em;
}

/* Phones: display and the first title each step down one (44 to 32, 32 to 24). */
@media (max-width: 640px) {
  :root {
    --zl-display: 2rem;
    --zl-display-lh: calc(36 / 32);
    --zl-display-track: -0.019em;
    --zl-title-1: 1.5rem;
    --zl-title-1-lh: calc(30 / 24);
    --zl-title-1-track: -0.014em;
  }
}

:root[data-theme="dark"] {
  /* Light type on a dark ground reads heavier: each weight eases 20. */
  --zl-weight: 400;
  --zl-label-weight: 480;
  --zl-title-weight: 480;
  --zl-display-weight: 440;
  --zl-canvas: 0.165 0.002 62;
  --zl-card: 0.165 0.002 62;
  --zl-raised: 0.215 0.003 62;
  --zl-line: 0.335 0.004 62;
  --zl-line-raised: 0.36 0.004 62;
  --zl-ink: 0.948 0.002 75;
  --zl-ink-muted: 0.735 0.003 68;
  --zl-ink-subtle: 0.63 0.003 62;
  --zl-well: 0.215 0.003 62;
  --zl-well-raised: 0.235 0.0035 62;
  --zl-skeleton: 0.262 0.0035 62;
  --zl-track: 0.205 0.003 62;
  --zl-fill: 0.22 0.003 62;
  --zl-selected: 0.255 0.004 62;
  --zl-thumb: 0.32 0.004 62;
  --zl-device: 0.11 0.002 62;
  --zl-accent: 0.9 0.004 75;
  --zl-positive: 0.74 0.15 165;
  --zl-shadow-card: 0 0 0 0 transparent;
  --zl-shadow-raised: inset 0 0 0 1px oklch(0.36 0.004 62);
  --zl-shadow-overlay:
    inset 0 0 0 1px oklch(0.36 0.004 62), 0 16px 40px -16px oklch(0 0 0 / 0.5);
  --zl-shadow-device: 0 0 0 1px oklch(1 0 0 / 0.08);
  --zl-thumb-shadow: inset 0 0 0 1px oklch(1 0 0 / 0.07);
  --zl-scrim: oklch(0.1 0.002 62 / 0.62);

  --zl-inv: 0.965 0.008 76;
  --zl-inv-ink: 0.182 0.01 62;
  --zl-inv-muted: 0.47 0.017 62;
  --zl-inv-subtle: 0.53 0.015 66;
  --zl-inv-fill: 0.182 0.01 62 / 0.07;
  --zl-inv-thumb: 1 0 0;
  --zl-inv-line: 0.182 0.01 62 / 0.12;
  --zl-inv-shadow: drop-shadow(0 1px 1px oklch(0 0 0 / 0.3));
  --zl-inv-panel-shadow:
    0 1px 2px oklch(0 0 0 / 0.3), 0 16px 40px -8px oklch(0 0 0 / 0.5);
}

/* With no theme chosen, the page follows the system (the Atlas; the lab always sets one). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --zl-weight: 400;
    --zl-label-weight: 480;
    --zl-title-weight: 480;
    --zl-display-weight: 440;
    --zl-canvas: 0.165 0.002 62;
    --zl-card: 0.165 0.002 62;
    --zl-raised: 0.215 0.003 62;
    --zl-line: 0.335 0.004 62;
    --zl-line-raised: 0.36 0.004 62;
    --zl-ink: 0.948 0.002 75;
    --zl-ink-muted: 0.735 0.003 68;
    --zl-ink-subtle: 0.63 0.003 62;
    --zl-well: 0.215 0.003 62;
    --zl-well-raised: 0.235 0.0035 62;
    --zl-skeleton: 0.262 0.0035 62;
    --zl-track: 0.205 0.003 62;
    --zl-fill: 0.22 0.003 62;
    --zl-selected: 0.255 0.004 62;
    --zl-thumb: 0.32 0.004 62;
    --zl-device: 0.11 0.002 62;
    --zl-accent: 0.9 0.004 75;
    --zl-positive: 0.74 0.15 165;
    --zl-shadow-card: 0 0 0 0 transparent;
    --zl-shadow-raised: inset 0 0 0 1px oklch(0.36 0.004 62);
    --zl-shadow-overlay:
      inset 0 0 0 1px oklch(0.36 0.004 62), 0 16px 40px -16px oklch(0 0 0 / 0.5);
    --zl-shadow-device: 0 0 0 1px oklch(1 0 0 / 0.08);
    --zl-thumb-shadow: inset 0 0 0 1px oklch(1 0 0 / 0.07);
    --zl-scrim: oklch(0.1 0.002 62 / 0.62);

    --zl-inv: 0.965 0.008 76;
    --zl-inv-ink: 0.182 0.01 62;
    --zl-inv-muted: 0.47 0.017 62;
    --zl-inv-subtle: 0.53 0.015 66;
    --zl-inv-fill: 0.182 0.01 62 / 0.07;
    --zl-inv-thumb: 1 0 0;
    --zl-inv-line: 0.182 0.01 62 / 0.12;
    --zl-inv-shadow: drop-shadow(0 1px 1px oklch(0 0 0 / 0.3));
    --zl-inv-panel-shadow:
      0 1px 2px oklch(0 0 0 / 0.3), 0 16px 40px -8px oklch(0 0 0 / 0.5);
  }
}
