/*
 * Does It Dream — design tokens.
 *
 * The single source of truth for colour, type, spacing, and motion, extracted
 * verbatim from the design system (Board A + Board M). Nothing elsewhere in the
 * CSS hardcodes a colour or size; everything derives from the custom properties
 * declared here. Light is the default; dark is applied by media query when the
 * reader has expressed no preference, and forced by [data-theme] otherwise.
 */

:root {
  /* Colour — six tokens named by role, plus three utility surfaces. */
  --surface: #EDEDEB;          /* the page — "paper" */
  --raised: #F7F7F5;           /* panels, previews, admin rail */
  --ink: #1C1D1A;              /* human turns, titles, primary text */
  --ink-quiet: #34352F;        /* assistant turns and body prose */
  --muted: #63655F;            /* metadata, model names, counts */
  --rule: #C9CAC3;             /* the hairline */
  --accent: #2F5754;           /* half-light — current state / the thing you asked for */
  --on-accent: #EDEDEB;        /* text/graphics reversed out of accent */
  --tint-on: rgba(47, 87, 84, 0.05);   /* assistant-turn tint when speakers shown */
  --flag: rgba(47, 87, 84, 0.10);       /* redaction flag highlight */
  --redacted: #DEDEDA;         /* confirmed-redaction token background */

  /* Type — three faces, seven roles. Fallbacks match the design's stacks. */
  --font-display: 'Archivo', Helvetica, Arial, sans-serif;
  --font-body: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
  --font-cjk: 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Noto Sans CJK SC', sans-serif;

  --weight-body: 400;
  --weight-display: 500;

  /* Reading measure and the attribution gutter. Stated once (Board A). */
  --measure: 68ch;
  --gutter-attr: 168px;

  /* Per-script reading rules — Latin defaults; overridden for CJK below. */
  --body-size: 19.5px;
  --body-leading: 1.72;
  /* Reader text-size selector multiplier (persisted per reader). */
  --reading-scale: 1;
  --body-track-human: 0.003em;
  --body-track-assistant: -0.002em;
  --line-break: auto;

  /* Spacing — base 4px, scale 4 8 12 16 24 32 48 64 96. */
  --s4: 4px; --s8: 8px; --s12: 12px; --s16: 16px; --s24: 24px;
  --s32: 32px; --s48: 48px; --s64: 64px; --s96: 96px;
  --page-margin: var(--s96);

  /* Motion — three durations, two curves (Board M). Nothing else ships. */
  --dur-state: 120ms;
  --dur-element: 240ms;
  --dur-orchestrated: 400ms;
  --ease-enter: cubic-bezier(0.16, 0.72, 0.3, 1);
  --ease-exit: cubic-bezier(0.5, 0, 0.78, 0.4);

  color-scheme: light dark;
}

/* Dark — applied when the reader has expressed no explicit preference. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --surface: #1A1918;
    --raised: #222120;
    --ink: #E9E7E2;
    --ink-quiet: #D6D3CD;
    --muted: #98958E;
    --rule: #35322E;
    --accent: #93B8B1;
    --on-accent: #1A1918;
    --tint-on: rgba(147, 184, 177, 0.06);
    --flag: rgba(147, 184, 177, 0.14);
    --redacted: #2C2A28;
    /* Dark-mode optical correction (Board A). */
    --weight-body: 380;
    --weight-display: 480;
  }
}

/* Explicit dark, chosen by the theme toggle. */
:root[data-theme="dark"] {
  --surface: #1A1918;
  --raised: #222120;
  --ink: #E9E7E2;
  --ink-quiet: #D6D3CD;
  --muted: #98958E;
  --rule: #35322E;
  --accent: #93B8B1;
  --on-accent: #1A1918;
  --tint-on: rgba(147, 184, 177, 0.06);
  --flag: rgba(147, 184, 177, 0.14);
  --redacted: #2C2A28;
  --weight-body: 380;
  --weight-display: 480;
}

/* Explicit light, chosen by the theme toggle (overrides the OS dark default). */
:root[data-theme="light"] {
  --surface: #EDEDEB;
  --raised: #F7F7F5;
  --ink: #1C1D1A;
  --ink-quiet: #34352F;
  --muted: #63655F;
  --rule: #C9CAC3;
  --accent: #2F5754;
  --on-accent: #EDEDEB;
  --tint-on: rgba(47, 87, 84, 0.05);
  --flag: rgba(47, 87, 84, 0.10);
  --redacted: #DEDEDA;
  --weight-body: 400;
  --weight-display: 500;
}

/*
 * CJK breaks the Latin assumptions. Where transcript or interface text is
 * Chinese/Japanese/Korean, the measure halves, leading opens up, tracking is
 * neutralised, and line-breaking becomes strict. Applied by :lang() and by an
 * explicit .cjk hook for transcript blocks whose lang differs from the page.
 */
:lang(zh), :lang(ja), :lang(ko), .cjk {
  --measure: 34ch;
  --body-leading: 1.75;
  --body-track-human: normal;
  --body-track-assistant: normal;
  --line-break: strict;
  font-family: var(--font-cjk);
  overflow-wrap: break-word;
  word-break: normal;
  line-break: strict;
}

/* Reduced motion — every duration becomes an instant state change (Board M). */
@media (prefers-reduced-motion: reduce) {
  :root {
    --dur-state: 0ms;
    --dur-element: 0ms;
    --dur-orchestrated: 0ms;
  }
  *, *::before, *::after {
    transition-duration: 0ms !important;
    transition-delay: 0ms !important;
    animation-duration: 0ms !important;
  }
}
