/* Design tokens. Every color, size, spacing and radius used in the UI is defined here. */

/* Light and dark theme: every color is light-dark(light, dark). Without a choice
   the system setting decides; the toggle (theme.js) sets data-theme on <html>,
   which the server renders from the "theme" cookie. */
:root {
  color-scheme: light dark;
}

:root[data-theme="light"] {
  color-scheme: light;
}

:root[data-theme="dark"] {
  color-scheme: dark;
}

/* Every value here is a deliberate choice; components never invent their own.
   The system follows Apple's interface guidelines translated for the web:
   neutral surfaces with one accent, translucent materials for floating chrome,
   size-specific tracking and leading, and spring timing for everything that moves. */
:root {
  /* Neutral palette: near-neutral grays, slightly warm, so the accent and the
     court tones carry all the color. */
  --color-bg: light-dark(#ffffff, #1c1c1e);
  --color-bg-subtle: light-dark(#f5f5f7, #222225);
  --color-bg-muted: light-dark(#e8e8ed, #2c2c2e);
  --color-surface: light-dark(#ffffff, #242427);
  --color-surface-translucent: light-dark(rgb(255 255 255 / 0.72), rgb(28 28 30 / 0.7));
  --color-border: light-dark(#e3e3e8, #343437);
  --color-border-strong: light-dark(#c9c9cf, #48484c);
  --color-text: light-dark(#1d1d1f, #f5f5f7);
  --color-text-muted: light-dark(#5f5f66, #aeaeb4);
  --color-text-subtle: light-dark(#727279, #97979e);
  /* On --color-text and --color-accent backgrounds. */
  --color-text-inverse: light-dark(#ffffff, #1c1c1e);

  /* Single accent */
  --color-accent: light-dark(#1f4bb8, #86a8f8);
  --color-accent-hover: light-dark(#193d96, #a2bcfa);
  --color-accent-active: light-dark(#142f74, #bccffc);
  --color-accent-subtle: light-dark(#eef2fb, #262f45);
  --color-accent-border: light-dark(#c8d4f1, #3f5283);

  /* Status colors (used sparingly, text always meets 4.5:1 on its background) */
  --color-success: light-dark(#17693f, #6fd09a);
  --color-success-bg: light-dark(#edf6f0, #1f2e25);
  --color-success-border: light-dark(#bfdcca, #355640);
  --color-warning: light-dark(#8a4f00, #ebb563);
  --color-warning-bg: light-dark(#fdf5e6, #332b1d);
  --color-warning-border: light-dark(#f0d5a6, #5f4d2f);
  --color-danger: light-dark(#b42318, #f4877f);
  --color-danger-hover: light-dark(#93190f, #f7a59f);
  --color-danger-bg: light-dark(#fdf0ef, #362424);
  --color-danger-border: light-dark(#f2c4bf, #663734);
  --color-danger-ring: light-dark(rgb(180 35 24 / 0.2), rgb(244 135 127 / 0.3));
  --color-info: var(--color-accent);
  --color-info-bg: var(--color-accent-subtle);
  --color-info-border: var(--color-accent-border);

  /* Court badges: one tone per court level */
  --color-court-constitutional: light-dark(#5b2a86, #c9a6ec);
  --color-court-constitutional-bg: light-dark(#f5f0fa, #30283a);
  --color-court-constitutional-border: light-dark(#ddd0ec, #524266);
  --color-court-fiscal: light-dark(#2f5d62, #7fc4ca);
  --color-court-fiscal-bg: light-dark(#eef5f5, #213134);
  --color-court-fiscal-border: light-dark(#cbe0e1, #36575b);
  --color-court-european: light-dark(#7a4a12, #e2b27a);
  --color-court-european-bg: light-dark(#fbf4ea, #332a1f);
  --color-court-european-border: light-dark(#ecd8bd, #5e482e);

  --color-highlight: light-dark(#fff1b8, #6b5b20);
  /* Dimming scrim behind modal tasks. */
  --color-overlay: light-dark(rgb(0 0 0 / 0.28), rgb(0 0 0 / 0.55));
  --color-focus: light-dark(#2f62e0, #86a8f8);

  /* ---------- Materials ----------
     Floating chrome is a translucent layer that content scrolls under. Weight
     encodes hierarchy: bars are regular, overlays (menus, dialogs, toasts) are
     thick, so a light layer never sits on another light layer. The bright top
     edge is light catching the material. */
  --material-regular: light-dark(rgb(255 255 255 / 0.72), rgb(30 30 32 / 0.7));
  --material-thick: light-dark(rgb(255 255 255 / 0.86), rgb(38 38 41 / 0.86));
  --material-chrome: light-dark(rgb(245 245 247 / 0.8), rgb(28 28 30 / 0.78));
  --material-blur-regular: saturate(180%) blur(20px);
  --material-blur-thick: saturate(180%) blur(32px);
  --material-edge: light-dark(rgb(255 255 255 / 0.7), rgb(255 255 255 / 0.08));
  --material-hairline: light-dark(rgb(0 0 0 / 0.08), rgb(255 255 255 / 0.09));
  /* Scroll edge: a soft fade where content meets floating chrome, instead of a
     hard divider; only drawn while content actually sits under the chrome. */
  --scroll-edge: light-dark(rgb(0 0 0 / 0.06), rgb(0 0 0 / 0.35));

  /* macOS controls and grouped lists (design-app.css): push buttons are a
     lighter fill than the window in dark mode, groups sit one step above it,
     and filled buttons carry a faint top sheen. */
  --color-window: light-dark(#f5f5f7, #1e1e20);
  --color-group: light-dark(#ffffff, #2c2c2e);
  --color-sidebar: light-dark(rgb(232 232 237 / 0.72), rgb(44 44 46 / 0.6));
  --color-control: light-dark(#ffffff, #48484b);
  --control-sheen: light-dark(rgb(255 255 255 / 0.16), rgb(255 255 255 / 0.1));
  --control-shadow: 0 0 0 0.5px light-dark(rgb(0 0 0 / 0.14), rgb(0 0 0 / 0.5)),
    0 1px 1.5px light-dark(rgb(0 0 0 / 0.1), rgb(0 0 0 / 0.3));

  /* ---------- Typography ----------
     The platform's own font: SF Pro on Apple devices (which switches between
     its Text and Display cuts by size), Segoe UI on Windows, Roboto on Android.
     Tracking changes with size, after the values apple.com uses with SF Pro:
     body text tightens, mid-size headings open up slightly (the Display cut is
     already tight), very large text tightens again. Never one letter-spacing
     for every size. */
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;

  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.3125rem;
  --text-2xl: 1.625rem;
  --text-3xl: 2.125rem;
  --text-4xl: 3rem;

  --tracking-xs: -0.01em;
  --tracking-sm: -0.016em;
  --tracking-base: -0.022em;
  --tracking-lg: -0.02em;
  --tracking-xl: 0.009em;
  --tracking-2xl: 0.004em;
  --tracking-3xl: -0.003em;
  --tracking-4xl: -0.005em;
  --tracking-display: -0.015em;
  /* Headings below 2xl; kept for components that set it directly. */
  --tracking-tight: var(--tracking-xl);

  --leading-display: 1.08;
  --leading-tight: 1.2;
  --leading-snug: 1.35;
  --leading-normal: 1.55;
  --leading-relaxed: 1.7;

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

  /* Spacing scale (4px base, in rem so it grows with the text size) */
  --space-0: 0;
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;
  --space-24: 6rem;

  /* Radii: bigger surfaces get rounder corners, so nested corners stay concentric. */
  --radius-sm: 6px;
  --radius-md: 9px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --radius-full: 999px;

  /* Borders and elevation. Bigger surfaces read as thicker: deeper, softer shadows. */
  --border-width: 1px;
  --border: var(--border-width) solid var(--color-border);
  --shadow-sm: 0 1px 2px light-dark(rgb(0 0 0 / 0.04), rgb(0 0 0 / 0.3));
  --shadow-overlay: 0 0 0 0.5px var(--material-hairline),
    0 24px 48px -12px light-dark(rgb(0 0 0 / 0.18), rgb(0 0 0 / 0.6)),
    0 4px 12px light-dark(rgb(0 0 0 / 0.06), rgb(0 0 0 / 0.3));
  --shadow-popover: 0 0 0 0.5px var(--material-hairline),
    0 12px 28px -6px light-dark(rgb(0 0 0 / 0.16), rgb(0 0 0 / 0.55)),
    0 2px 6px light-dark(rgb(0 0 0 / 0.05), rgb(0 0 0 / 0.3));

  /* Layout */
  --container-max: 72rem;
  --container-narrow: 30rem;
  --container-medium: 48rem;
  --measure: 68ch;
  --navbar-height: 3.5rem;
  /* Space the navbar takes at the top; 0 while it is hidden (navbar.js). */
  --navbar-offset: var(--navbar-height);
  --sidebar-width: 17rem;
  --gutter: var(--space-6);

  /* Controls */
  --control-height: 2.5rem;
  --control-height-sm: 2rem;
  --control-height-lg: 3rem;
  --focus-ring: 0 0 0 4px light-dark(rgb(47 98 224 / 0.3), rgb(134 168 248 / 0.4));

  /* ---------- Motion ----------
     Springs, described the way Apple does: damping ratio (1 = no overshoot)
     and response (how fast it gets there). A critically damped spring has the
     same shape at every response, so one curve serves all of them and only the
     duration (its settle time) changes. --ease-spring overshoots slightly
     (damping 0.8) and is only for motion that follows a gesture with momentum.
     Gesture-driven motion runs on the JavaScript spring in spring.js with the
     same parameters, so CSS and JS motion feel the same. */
  --duration-fast: 120ms;
  --duration-base: 220ms;
  --duration-slow: 370ms;
  /* Settle times: damping 1.0 at response 0.25 s and 0.4 s; damping 0.8 at 0.35 s. */
  --duration-spring: 370ms;
  --duration-spring-slow: 590ms;
  --duration-spring-bouncy: 470ms;
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  /* The mirror image of --ease-out: exits retrace the entrance. */
  --ease-in: cubic-bezier(0.8, 0, 0.8, 0.2);
  --ease-spring: cubic-bezier(0.3, 1.3, 0.6, 1);
  --stagger: 45ms;

  /* Press feedback: applied on pointer-down, instantly. */
  --press-scale: 0.97;
  --duration-press: 90ms;

  --shadow-raised: 0 0 0 0.5px var(--material-hairline),
    0 10px 24px -8px light-dark(rgb(0 0 0 / 0.14), rgb(0 0 0 / 0.5));
  --shadow-accent: 0 6px 16px -6px light-dark(rgb(31 75 184 / 0.45), rgb(134 168 248 / 0.35));
  --shadow-danger: 0 6px 16px -6px light-dark(rgb(180 35 24 / 0.4), rgb(244 135 127 / 0.3));
  --color-glow: light-dark(rgb(31 75 184 / 0.5), rgb(134 168 248 / 0.5));
  --color-pulse: light-dark(rgb(31 75 184 / 0.35), rgb(134 168 248 / 0.35));
  --color-pulse-danger: light-dark(rgb(180 35 24 / 0.35), rgb(244 135 127 / 0.35));
  --color-pulse-warning: light-dark(rgb(138 79 0 / 0.3), rgb(235 181 99 / 0.3));

  /* Stacking */
  --z-navbar: 50;
  --z-dropdown: 60;
  --z-overlay: 100;
  --z-toast: 200;
}

/* The real spring curves, where the browser can express them. */
@supports (transition-timing-function: linear(0, 1)) {
  :root {
    /* damping 1.0 (any response; pair with a --duration-spring*) */
    --ease-out: linear(0, 0.057, 0.18, 0.32, 0.455, 0.572, 0.671, 0.75, 0.812, 0.86, 0.896,
      0.924, 0.944, 0.959, 0.971, 0.979, 0.985, 0.989, 0.992, 0.994, 0.996, 0.997, 0.998,
      0.999, 1);
    /* damping 0.8, response 0.35 s (pair with --duration-spring-bouncy) */
    --ease-spring: linear(0, 0.02, 0.071, 0.143, 0.227, 0.316, 0.405, 0.491, 0.572, 0.646,
      0.712, 0.77, 0.82, 0.862, 0.898, 0.927, 0.95, 0.969, 0.984, 0.994, 1.002, 1.008, 1.012,
      1.014, 1.015, 1.015, 1.015, 1.014, 1.013, 1.011, 1.01, 1.009, 1.007, 1.006, 1.005,
      1.004, 1.003, 1.003, 1.002, 1.001, 1);
  }
}

@media (max-width: 40rem) {
  :root {
    --gutter: var(--space-4);
    --text-4xl: 2.25rem;
    --text-3xl: 1.75rem;
    --text-2xl: 1.5rem;
  }
}

/* Reduced motion is not no feedback: movement goes, short cross-fades stay. */
@media (prefers-reduced-motion: reduce) {
  :root {
    --duration-fast: 80ms;
    --duration-base: 150ms;
    --duration-slow: 150ms;
    --duration-spring: 0ms;
    --duration-spring-slow: 0ms;
    --duration-spring-bouncy: 0ms;
    --stagger: 0ms;
    --press-scale: 1;
  }
}

/* Reduced transparency: materials become solid and lose their blur. */
@media (prefers-reduced-transparency: reduce) {
  :root {
    --material-regular: var(--color-bg);
    --material-thick: var(--color-surface);
    --material-chrome: var(--color-bg-subtle);
    --color-surface-translucent: var(--color-bg);
    --material-blur-regular: none;
    --material-blur-thick: none;
  }
}

/* More contrast: solid surfaces with defined borders. */
@media (prefers-contrast: more) {
  :root {
    --material-regular: var(--color-bg);
    --material-thick: var(--color-surface);
    --material-chrome: var(--color-bg);
    --material-blur-regular: none;
    --material-blur-thick: none;
    --material-hairline: var(--color-text-muted);
    --color-border: light-dark(#8e8e94, #7a7a80);
    --color-border-strong: var(--color-text-muted);
    --color-text-subtle: var(--color-text-muted);
  }
}
