/*
 * Textree design tokens — Obsidian-flavored, minimal.
 *
 * Single source of truth: every color, type, spacing, radius, and shadow is defined here and
 * components reference it only via var(--token). No hardcoded values. Borrows the semantic model
 * of Obsidian's CSS variables while following the naming convention from the design foundation plan.
 *
 * Theme: :root = light (default). @media (prefers-color-scheme: dark) {
  :root {
  /* Match native UI (scrollbars, form controls) to the active theme. Without this the WebView
     renders a light scrollbar even in the dark theme. Set per theme root so it follows the
     same [data-theme] switch as every other token. */
  color-scheme: light;
  /* ── Type ───────────────────────────────────────────────── */
  --font-ui:
    system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial,
    "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  --font-text: var(--font-ui);
  --font-monospace:
    "JetBrains Mono", "Cascadia Code", "SF Mono", "Consolas",
    "Liberation Mono", Menlo, monospace;

  /* Size scale — UI chrome stays small (information density), editor body is reading-optimized. */
  --font-size-smallest: 11px;
  --font-size-smaller: 12px;
  --font-size-small: 13px;
  --font-size-ui: 14px;
  --font-size-editor: 16px;
  /* Heading scale — a modular (~1.2 ratio) progression for an opinionated, harmonious hierarchy.
     Sizes are em-relative so they track the editor body size. */
  --font-size-h1: 1.8em;
  --font-size-h2: 1.5em;
  --font-size-h3: 1.25em;
  --font-size-h4: 1.1em;
  --font-size-h5: 1em;
  --font-size-h6: 0.9em;
  /* Page title (frontmatter header) — larger than body H1 for the pretty-by-default page top. */
  --font-size-title: 2.2rem;

  --line-height-tight: 1.3;
  --line-height-normal: 1.5;
  --line-height-relaxed: 1.7;

  --font-weight-normal: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;

  /* ── Spacing scale (4px base) ───────────────────────────── */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;

  /* Editor body reading width (caps line length on wide windows — readability). */
  --content-max-width: 48rem;

  /* ── Radius ─────────────────────────────────────────────── */
  --radius-s: 4px;
  --radius-m: 6px;
  --radius-l: 8px;

  /* ── Motion ─────────────────────────────────────────────── */
  --transition-fast: 80ms ease;
  --transition-normal: 140ms ease;

  /* ── Color (light) ──────────────────────────────────────── */
  --bg-primary: #ffffff;
  --bg-secondary: #f6f7f8;
  --bg-secondary-alt: #ececef;
  --bg-hover: rgba(0, 0, 0, 0.045);
  --bg-active: rgba(0, 0, 0, 0.075);

  --text-normal: #2a2d34;
  --text-muted: #6a707c;
  /* Faint = lightest text tier. Tuned to clear WCAG 3:1 (UI/non-text) on the primary surface
     while staying lighter than muted (preserves the normal > muted > faint hierarchy). */
  --text-faint: #868d97;
  --text-on-accent: #ffffff;
  --text-error: #c0392b;

  /* Brand emerald (matches the logo's green). Deep enough to carry white CTA text and to read as
     link/active text on the white surface (~4.4:1, on par with the prior accent's contrast tier). */
  --accent: #0a8a57;
  --accent-hover: #097a4b;

  /* Selection/drop highlights derive from accent's alpha (auto-harmonize across themes). */
  --selection-bg: rgba(10, 138, 87, 0.15);
  --drop-bg: rgba(10, 138, 87, 0.1);
  --drop-border: rgba(10, 138, 87, 0.7);

  --border: rgba(0, 0, 0, 0.1);
  --border-strong: rgba(0, 0, 0, 0.18);

  /* Warning/banner (conflict / save status) */
  --warning-bg: #fff6e0;
  --warning-border: #e0c060;
  --warning-text: #5a4a00;

  /* Callout accents — same names as canopy's tokens (published-site injection stays drop-in). */
  --callout-note: #2f6fed;
  --callout-note-bg: rgba(47, 111, 237, 0.08);
  --callout-tip: #0a8a57;
  --callout-tip-bg: rgba(10, 138, 87, 0.08);
  --callout-warning: #b45309;
  --callout-warning-bg: rgba(180, 83, 9, 0.08);
  --callout-danger: #c0392b;
  --callout-danger-bg: rgba(192, 57, 43, 0.08);
  --callout-quote: #6a707c;
  --callout-quote-bg: rgba(106, 112, 124, 0.08);

  --shadow-s: 0 1px 2px rgba(0, 0, 0, 0.08);
  --shadow-m: 0 2px 8px rgba(0, 0, 0, 0.12);

  /* Syntax highlighting (fenced code) — github-light-inspired, tuned for the app. */
  --syntax-keyword: #cf222e;
  --syntax-string: #0a3069;
  --syntax-comment: #6e7781;
  --syntax-number: #0550ae;
  --syntax-name: #8250df;
  --syntax-type: #953800;
  --syntax-punctuation: #57606a;
}
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg-primary: #1e1f23;
  --bg-secondary: #181a1d;
  --bg-secondary-alt: #25272c;
  --bg-hover: rgba(255, 255, 255, 0.055);
  --bg-active: rgba(255, 255, 255, 0.09);

  --text-normal: #dadde2;
  --text-muted: #9aa0aa;
  --text-faint: #6b7178;
  /* On the bright dark-theme emerald, dark text (not white) clears contrast — used by the CTA fill. */
  --text-on-accent: #06241a;
  --text-error: #ff6b5e;

  /* Brighter emerald for the dark surface (vivid on near-black, ample contrast for link/active text). */
  --accent: #34d399;
  --accent-hover: #5ce0a9;

  --selection-bg: rgba(52, 211, 153, 0.2);
  --drop-bg: rgba(52, 211, 153, 0.16);
  --drop-border: rgba(52, 211, 153, 0.8);

  --border: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.18);

  --warning-bg: #3a3012;
  --warning-border: #6b5a1e;
  --warning-text: #e8d48a;

  /* Callout accents — same names as canopy's tokens (published-site injection stays drop-in). */
  --callout-note: #6d8bff;
  --callout-note-bg: rgba(109, 139, 255, 0.12);
  --callout-tip: #34d399;
  --callout-tip-bg: rgba(52, 211, 153, 0.12);
  --callout-warning: #f0b350;
  --callout-warning-bg: rgba(240, 179, 80, 0.12);
  --callout-danger: #ff6b5e;
  --callout-danger-bg: rgba(255, 107, 94, 0.12);
  --callout-quote: #9aa0aa;
  --callout-quote-bg: rgba(154, 160, 170, 0.12);

  --shadow-s: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-m: 0 2px 10px rgba(0, 0, 0, 0.45);

  /* Syntax highlighting (fenced code) — github-dark-inspired. */
  --syntax-keyword: #ff7b72;
  --syntax-string: #a5d6ff;
  --syntax-comment: #8b949e;
  --syntax-number: #79c0ff;
  --syntax-name: #d2a8ff;
  --syntax-type: #ffa657;
  --syntax-punctuation: #8b949e;
}

/* A plain CSS file (global import), so selectors are global as written — a :global() wrapper is
   Svelte <style>-only syntax and would become an invalid selector here (do not use it). */
html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg-primary);
  color: var(--text-normal);
  font-family: var(--font-ui);
  font-size: var(--font-size-ui);
  /* Smooth color change on theme switch (respects reduced-motion). */
  transition:
    background-color var(--transition-normal),
    color var(--transition-normal);
}

@media (prefers-reduced-motion: reduce) {
  /* Override the motion tokens to 0 to disable every token-driven transition from a single source. */
  :root {
    --transition-fast: 0s;
    --transition-normal: 0s;
  }
  body {
    transition: none;
  }
}
