/*
 * This playbook owns this file: edit it here (issue #269). It began as a copy of the website's
 * brand tokens and no longer follows the website.
 */
/*
 * InsightSurge design tokens. SOURCE OF TRUTH for the brand (ADR-0002).
 * Direction "Forest" (B1), from the Claude Design system. Plain CSS so the same file works in
 * Next.js (imported by src/app/globals.css), Quarto and Shiny (copy it next to _brand.yml).
 *
 * Dark mode switches on .dark (Tailwind/shadcn), [data-theme="dark"], :root[data-bs-theme="dark"]
 * (Bootstrap/bslib set it on <html>) or .quarto-dark (Quarto sets this class on <body>).
 * [data-theme="light"] forces the light roles back on, e.g. a light section inside a dark page.
 * Never switch on a bare [data-bs-theme="dark"]: Quarto 1.8 always writes it on its navbar, which
 * would turn the navbar dark in light mode.
 * [data-surface="blog"] is the calmer, neutral-first variant for the personal Quarto blog.
 *
 * When you change a colour here, update brand/_brand.yml too: tests/testthat/test-site-brand.R fails if they drift,
 * and it checks WCAG AA contrast for the text pairs in both themes.
 */

:root,
[data-theme="light"] {
  /* ---- Base palette (theme-independent) ---- */

  /* Forest: the only brand hue */
  --forest-50: #eff5f1;
  --forest-100: #e1ece5;
  --forest-200: #c3d9cb;
  --forest-300: #a6ddbf;
  --forest-400: #7fcba4;
  --forest-500: #3f8a66;
  --forest-600: #2b7053;
  --forest-700: #1d5a43;
  --forest-800: #1a4d39;
  --forest-900: #1e3329;
  --forest-950: #0a1f15;

  /* Stone: cool neutrals */
  --stone-0: #ffffff;
  --stone-25: #f5f6f4;
  --stone-50: #eceeea;
  --stone-75: #f0f2ef;
  --stone-100: #dce0db;
  --stone-200: #c4cac4;
  --stone-300: #a2aea7;
  --stone-400: #7d8982;
  --stone-500: #626d67;
  --stone-600: #525d57;
  --stone-700: #35423a;
  --stone-800: #26312b;
  --stone-850: #18211c;
  --stone-900: #161e1a;
  --stone-925: #121915;
  --stone-950: #0f1512;
  --stone-ink: #16201b;

  /* Ochre: secondary, and the warning role */
  --ochre-100: #f3ebd9;
  --ochre-300: #d9b35c;
  --ochre-600: #7a5a12;
  --ochre-800: #5a420c;
  --ochre-900: #2e2615;

  /* Status */
  --green-600: #1d6b45;
  --green-300: #7fcba4;
  --blue-600: #2f5f86;
  --blue-300: #9dc3e6;
  --red-600: #a33a30;
  --red-300: #f29b8f;

  /* Categorical data-viz: Paul Tol "muted" (colour-blind safe). Use in order 1 → n. */
  --viz-1: #117733;
  --viz-2: #88ccee;
  --viz-3: #ddcc77;
  --viz-4: #cc6677;
  --viz-5: #332288;
  --viz-6: #aa4499;
  --viz-7: #44aa99;

  /* Aurora hues for page washes, glows and grain. Each site owns strengths/mix,
   * blur, breathing and geometry. Keep dark glows weak enough for text contrast. */
  --aurora-1: var(--forest-400);
  --aurora-2: var(--ochre-300);
  --aurora-3: var(--forest-200);
  --aurora-wash: var(--forest-50);
  --aurora-grain: var(--stone-ink);
  --aurora-1-dark: var(--forest-400);
  --aurora-2-dark: var(--ochre-300);
  --aurora-3-dark: var(--forest-200);
  --aurora-wash-dark: var(--forest-900);
  --aurora-grain-dark: #e7ece8; /* the dark theme's --fg */

  /* ---- Semantic roles: light (default) ---- */
  color-scheme: light;
  --bg: var(--stone-25);
  --surface: var(--stone-50);
  --surface-raised: var(--stone-0);
  --fg: var(--stone-ink);
  --fg-muted: var(--stone-600);
  --fg-subtle: var(
    --stone-400
  ); /* non-text only: icons, placeholders (3.4:1) */
  --border: var(--stone-100);
  --border-strong: var(--stone-200);
  /* form-field edges: WCAG 1.4.11 needs 3:1 */
  --border-input: var(--stone-400);
  --primary: var(--forest-700);
  --primary-hover: var(--forest-800);
  --primary-fg: #ffffff;
  --primary-soft: var(--forest-100);
  --primary-soft-fg: var(--forest-800);
  --secondary: var(--ochre-600);
  --secondary-hover: var(--ochre-800);
  --secondary-fg: #ffffff;
  --secondary-soft: var(--ochre-100);
  --secondary-soft-fg: var(--ochre-800);
  --link: var(--forest-700);
  --link-hover: var(--forest-950);
  --success: var(--green-600);
  --success-soft: #e4f0e8;
  --info: var(--blue-600);
  --info-soft: #e3ecf4;
  --warning: var(--ochre-600);
  --warning-soft: var(--ochre-100);
  --danger: var(--red-600);
  --danger-soft: #f6e3e0;
  --danger-fg: #ffffff;
  --focus-ring: var(--forest-600);
  --selection: var(--forest-200);
  --overlay: rgba(15, 21, 18, 0.45);
  --code-bg: var(--stone-75);
  --code-fg: var(--stone-ink);
  --code-comment: var(--stone-500);
  --code-keyword: var(--forest-700);
  --code-string: var(--ochre-600);
  --code-fn: var(--blue-600);
  --code-number: var(--red-600);

  /* ---- Typography ---- */
  --font-sans:
    "Hanken Grotesk", ui-sans-serif, system-ui, -apple-system, "Segoe UI",
    sans-serif;
  --font-display: var(--font-sans);
  --font-mono:
    "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* Scale (rem @ 16px), ratio ≈ 1.25 rounded to whole px */
  --text-xs: 0.75rem; /* 12: labels, table meta */
  --text-sm: 0.875rem; /* 14: UI, tables, captions */
  --text-base: 1rem; /* 16: UI body */
  --text-md: 1.125rem; /* 18: long-form prose, lead */
  --text-lg: 1.25rem; /* 20: h5, card titles */
  --text-xl: 1.5rem; /* 24: h4 */
  --text-2xl: 1.875rem; /* 30: h3 */
  --text-3xl: 2.375rem; /* 38: h2 */
  --text-4xl: 3rem; /* 48: h1 */
  --text-5xl: 3.75rem; /* 60: marketing hero */

  --leading-tight: 1.08;
  --leading-snug: 1.25;
  --leading-normal: 1.5;
  --leading-relaxed: 1.65;
  --tracking-display: -0.025em;
  --tracking-heading: -0.015em;
  --tracking-normal: 0;
  --tracking-label: 0.08em;
  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;
  --measure-prose: 68ch;

  /* Composite font shorthands (components.css uses these) */
  --type-body:
    var(--weight-regular) var(--text-base) / var(--leading-normal)
    var(--font-sans);
  --type-prose:
    var(--weight-regular) var(--text-md) / var(--leading-relaxed)
    var(--font-sans);
  --type-label: var(--weight-medium) var(--text-xs) / 1 var(--font-mono);

  /* Mono: ligatures off so R's |> and <- render exactly as typed */
  --mono-ligatures: none;
  --mono-features: "liga" 0, "calt" 0;

  /* ---- Spacing (4px base) ---- */
  --space-0: 0;
  --space-0-5: 2px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;
  --space-20: 80px;
  --space-24: 96px;
  --space-32: 128px;

  /* ---- Radius (--radius is the shadcn base) ---- */
  --radius-xs: 4px; /* inline code, status chips */
  --radius-sm: 6px; /* inputs, small buttons */
  --radius: 8px; /* buttons, code blocks */
  --radius-lg: 12px; /* cards, callouts, tables */
  --radius-xl: 16px; /* cookie banner, dialogs */
  --radius-pill: 999px;

  /* ---- Elevation: soft, stone-tinted; off in dark mode ---- */
  --shadow-xs: 0 1px 2px rgba(22, 32, 27, 0.05);
  --shadow-sm:
    0 1px 2px rgba(22, 32, 27, 0.05), 0 4px 16px rgba(22, 32, 27, 0.04);
  --shadow-md:
    0 2px 4px rgba(22, 32, 27, 0.05), 0 12px 32px rgba(22, 32, 27, 0.08);
  --shadow-lg:
    0 4px 8px rgba(22, 32, 27, 0.06), 0 24px 56px rgba(22, 32, 27, 0.12);

  /* ---- Layout ---- */
  --container: 1200px;
  --container-prose: 760px;
  --nav-height: 64px;

  /* ---- Motion: short, eased, no bounce ---- */
  --ease-standard: cubic-bezier(0.2, 0, 0, 1);
  --duration-fast: 120ms;
  --duration: 180ms;
  --duration-slow: 280ms;
}

/* Blog surface (personal Quarto site): ink replaces forest for buttons, pills and eyebrows.
   Green survives only in links and focus. */
[data-surface="blog"] {
  --primary: var(--stone-ink);
  --primary-hover: #2a3530;
  --primary-fg: #ffffff;
  --primary-soft: var(--stone-50);
  --primary-soft-fg: var(--stone-ink);
  --secondary: var(--stone-600);
  --secondary-fg: #ffffff;
  --secondary-soft: var(--stone-50);
  --secondary-soft-fg: var(--stone-600);
}

/* ---- Semantic roles: dark. Not an inversion: primaries lighten, borders replace shadows. ---- */
:root[data-bs-theme="dark"],
.dark,
[data-theme="dark"],
.quarto-dark {
  color-scheme: dark;
  --viz-1: #3aa864;
  --viz-5: #7b6fd6;
  --bg: var(--stone-950);
  --surface: var(--stone-900);
  --surface-raised: var(--stone-850);
  --fg: #e7ece8;
  --fg-muted: var(--stone-300);
  --fg-subtle: var(--stone-500);
  --border: var(--stone-800);
  --border-strong: var(--stone-700);
  --border-input: #707c75; /* 3.8:1 on the card, 4.3:1 on the page */
  --primary: var(--forest-400);
  --primary-hover: var(--forest-300);
  --primary-fg: var(--forest-950);
  --primary-soft: var(--forest-900);
  --primary-soft-fg: var(--forest-300);
  --secondary: var(--ochre-300);
  --secondary-hover: #e8c77d;
  --secondary-fg: #221a06;
  --secondary-soft: var(--ochre-900);
  --secondary-soft-fg: #ebcb85;
  --link: #8fd6b1;
  --link-hover: var(--forest-300);
  --success: var(--green-300);
  --success-soft: #15281d;
  --info: var(--blue-300);
  --info-soft: #172430;
  --warning: var(--ochre-300);
  --warning-soft: var(--ochre-900);
  --danger: var(--red-300);
  --danger-soft: #321b18;
  --danger-fg: #2a0e0b;
  --focus-ring: var(--forest-400);
  --selection: var(--forest-900);
  --overlay: rgba(0, 0, 0, 0.6);
  --code-bg: var(--stone-925);
  --code-fg: #e7ece8;
  --code-comment: #8e9a93;
  --code-keyword: var(--forest-400);
  --code-string: var(--ochre-300);
  --code-fn: var(--blue-300);
  --code-number: var(--red-300);
  --shadow-xs: none;
  --shadow-sm: none;
  --shadow-md: 0 12px 32px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 24px 56px rgba(0, 0, 0, 0.5);
}

[data-surface="blog"]:is(
  :root[data-bs-theme="dark"],
  .dark,
  [data-theme="dark"],
  .quarto-dark
),
[data-surface="blog"] :is(.dark, [data-theme="dark"], .quarto-dark),
:is(:root[data-bs-theme="dark"], .dark, [data-theme="dark"], .quarto-dark)
  [data-surface="blog"] {
  --primary: #e7ece8;
  --primary-hover: #ffffff;
  --primary-fg: var(--stone-950);
  --primary-soft: var(--stone-850);
  --primary-soft-fg: #e7ece8;
  --secondary: var(--stone-300);
  --secondary-fg: var(--stone-950);
  --secondary-soft: var(--stone-850);
  --secondary-soft-fg: var(--stone-300);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    /* biome-ignore lint/complexity/noImportantStyles: reduced motion must beat component styles */
    transition-duration: 0s !important;
    /* biome-ignore lint/complexity/noImportantStyles: reduced motion must beat component styles */
    animation-duration: 0s !important;
  }
}
