/*
 * AlphaTutor design tokens. Load this file first on every student page.
 * Spec: docs/UI-REDESIGN.md §3. Components reference the semantic tokens, never the primitives.
 * Themes: light (default) and dark. scripts/theme.js sets <html data-theme="light|dark"> from the
 * learner's choice (System, Light or Dark; System follows the device). Only semantic tokens change
 * between themes, so a component that uses semantic tokens is dark-ready with no extra rules.
 */
@font-face {
  font-family: "Plus Jakarta Sans";
  src: url("../assets/fonts/plus-jakarta-sans/PlusJakartaSans-variable.ttf") format("truetype");
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;

  /* Primitives */
  --green-50: #eefcf5; --green-100: #dbf7e8; --green-200: #bcedd4; --green-300: #96dcbb;
  --green-400: #67c59b; --green-500: #36ab7d; --green-600: #0b8f64; --green-700: #07724f;
  --green-800: #0d573c; --green-900: #07412c; --green-950: #052a1c;
  --neutral-0: #ffffff; --neutral-50: #f6f8f7; --neutral-100: #f1f5f3; --neutral-200: #e4e9e7;
  --neutral-300: #d4dbd7; --neutral-400: #b4bdb9; --neutral-500: #858f8a; --neutral-600: #656e6a;
  --neutral-700: #535c57; --neutral-800: #3d4642; --neutral-900: #29312d; --neutral-950: #171e1a;
  --blue-50: #f2f7fe; --blue-100: #e6effe; --blue-200: #cbe0fe; --blue-300: #a6c9fe;
  --blue-500: #438af1; --blue-600: #1a6fe1; --blue-700: #025ac3; --blue-800: #01489f;
  --amber-50: #fff9f2; --amber-100: #fff0df; --amber-200: #fee1be; --amber-300: #fecc8d;
  --amber-400: #ffb03e; --amber-600: #c48006; --amber-700: #9d6603; --amber-800: #7b4f04;
  --red-50: #fef4f3; --red-100: #fee8e6; --red-200: #fed2cd; --red-300: #feb0a9;
  --red-600: #d43538; --red-700: #b5242a; --red-800: #941c20;
  --violet-50: #f6f6fe; --violet-100: #eeecfe; --violet-600: #7a54e6; --violet-700: #6441c2; --violet-800: #50339e;

  /* Surfaces */
  --color-bg: var(--neutral-50);
  --color-surface: var(--neutral-0);
  --color-surface-subtle: var(--neutral-100);
  --color-surface-sunken: var(--neutral-200);
  --color-surface-inverse: var(--neutral-950);
  --color-surface-figure: #fffdf8; /* plate the sha256-pinned Notes SVGs were drawn on */
  --color-overlay: rgb(12 18 15 / .52);
  /* Paper: whiteboards and drawn diagrams whose ink is fixed dark (JS/SVG). Stays light in dark theme. */
  --color-paper: #fffefa;
  --color-paper-text: #1d2a24;
  --color-paper-text-secondary: #4d5a53;
  --color-paper-border: var(--neutral-200);

  /* Text */
  --color-text: var(--neutral-950);
  --color-text-secondary: var(--neutral-700);
  --color-text-tertiary: var(--neutral-600);
  --color-text-disabled: var(--neutral-500);
  --color-text-inverse: var(--neutral-0);
  --color-text-on-brand: var(--neutral-0);
  --color-text-link: var(--green-700);
  --color-text-link-hover: var(--green-800);

  /* Borders */
  --color-border: var(--neutral-200);
  --color-border-strong: var(--neutral-300);
  --color-border-control: var(--neutral-500);
  --color-border-selected: var(--green-700);

  /* Brand and actions */
  --color-brand: var(--green-700);
  --color-brand-strong: var(--green-800);
  --color-brand-deep: var(--green-900);
  --color-brand-subtle: var(--green-100);
  --color-brand-faint: var(--green-50);
  --color-brand-subtle-text: var(--green-900);
  --color-brand-border: var(--green-200);
  --color-brand-border-strong: var(--green-300);
  --color-selection: var(--green-200);
  --color-action-primary: var(--green-700);
  --color-action-primary-hover: var(--green-800);
  --color-action-primary-press: var(--green-900);
  --color-action-secondary-hover: var(--green-50);
  --color-action-neutral-hover: var(--neutral-100);
  --color-action-neutral-press: var(--neutral-200);
  --color-action-disabled-bg: var(--neutral-200);
  --color-action-disabled-text: var(--neutral-500);
  --color-progress: var(--green-600);
  --color-progress-track: var(--neutral-200);

  /* Focus */
  --color-focus-ring: var(--blue-600);
  --color-focus-gap: var(--neutral-0);

  /* Status (always pair with a text label or icon, never colour alone) */
  --color-success: var(--green-700); --color-success-strong: var(--green-800);
  --color-success-bg: var(--green-50); --color-success-border: var(--green-300);
  --color-warning: var(--amber-700); --color-warning-strong: var(--amber-800);
  --color-warning-bg: var(--amber-50); --color-warning-border: var(--amber-300);
  --color-danger: var(--red-600); --color-danger-strong: var(--red-800);
  --color-danger-bg: var(--red-50); --color-danger-border: var(--red-300);
  --color-info: var(--blue-700); --color-info-strong: var(--blue-800);
  --color-info-bg: var(--blue-50); --color-info-border: var(--blue-300);

  /* Accents (icon tiles, subject covers, simple charts) and neutral indicators */
  --color-accent-blue: var(--blue-700); --color-accent-blue-bg: var(--blue-100);
  --color-accent-amber: var(--amber-800); --color-accent-amber-bg: var(--amber-100);
  --color-accent-violet: var(--violet-700); --color-accent-violet-bg: var(--violet-100);
  --color-chart-1: var(--blue-700); --color-chart-2: var(--amber-700); --color-chart-3: var(--green-700);
  --color-chart-axis: var(--neutral-800); --color-chart-fill: var(--blue-100);
  --color-highlight: var(--amber-200);
  --color-indicator: var(--neutral-400);
  --color-skeleton: var(--neutral-200); --color-skeleton-shine: var(--neutral-100);
  --color-scrollbar: var(--neutral-400);

  /* Type */
  --font-sans: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Noto Sans SC", sans-serif;
  --font-cjk: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Noto Sans SC", sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --weight-regular: 400; --weight-medium: 500; --weight-semibold: 600; --weight-bold: 700; --weight-extrabold: 800;
  --text-xs: .75rem;   --leading-xs: 1rem;      /* 12/16 — the floor */
  --text-sm: .875rem;  --leading-sm: 1.25rem;   /* 14/20 */
  --text-md: 1rem;     --leading-md: 1.5rem;    /* 16/24 */
  --text-lg: 1.125rem; --leading-lg: 1.75rem;   /* 18/28 */
  --text-xl: 1.25rem;  --leading-xl: 1.75rem;   /* 20/28 */
  --text-2xl: 1.5rem;  --leading-2xl: 2rem;     /* 24/32 */
  --text-3xl: 1.875rem; --leading-3xl: 2.375rem; /* 30/38 */
  --text-4xl: 2.25rem; --leading-4xl: 2.75rem;  /* 36/44 */
  --text-5xl: 3rem;    --leading-5xl: 3.5rem;   /* 48/56 */
  --text-reading: 1.125rem; --leading-reading: 1.75;
  --tracking-tight: -.02em; --tracking-snug: -.01em; --tracking-caps: .08em;
  --measure: 34em; --measure-wide: 44em; /* em, never ch: Jakarta 1ch = .732em */

  /* Space (4px grid) */
  --space-0: 0; --space-1: .25rem; --space-2: .5rem; --space-3: .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;

  /* Radius */
  --radius-xs: 4px; --radius-sm: 8px; --radius-md: 12px; --radius-lg: 16px; --radius-xl: 24px; --radius-full: 9999px;

  /* Elevation */
  --shadow-color: 23 30 26;
  --shadow-low: 0 1px 2px 0 rgb(var(--shadow-color) / .08), 0 1px 1px 0 rgb(var(--shadow-color) / .04);
  --shadow-mid: 0 4px 8px 0 rgb(var(--shadow-color) / .08), 0 1px 2px 0 rgb(var(--shadow-color) / .06);
  --shadow-high: 0 8px 16px 0 rgb(var(--shadow-color) / .10), 0 2px 4px 0 rgb(var(--shadow-color) / .06);
  --shadow-overlay: 0 24px 48px -12px rgb(var(--shadow-color) / .28);

  /* Layers (kept compatible with existing values: header 30, sidebar 60, drawers 80, toast 150, gates 300) */
  --z-sticky: 20; --z-header: 30; --z-dropdown: 55; --z-backdrop: 59; --z-sidebar: 60; --z-tabbar: 62;
  --z-scrim: 70; --z-drawer: 80; --z-toast: 150; --z-skip-link: 200; --z-gate: 300;

  /* Motion */
  --duration-fast: 150ms; --duration-base: 200ms; --duration-slow: 300ms;
  --ease-standard: cubic-bezier(.2, 0, 0, 1); --ease-enter: cubic-bezier(.05, .7, .1, 1);

  /* Layout */
  --sidebar-width: 240px;
  --topbar-height: 64px;
  --tabbar-height: 64px;
  --container: 1120px;
  --container-wide: 1240px;
  --gutter: var(--space-4);
}

/*
 * Dark theme. Green-tinted neutrals; brand and status colours are lifted so text stays at or above
 * WCAG AA (body text >= 9:1, tertiary >= 4.5:1 on every surface, primary button text 5.7:1).
 * Primary actions become a bright green fill with dark text. Paper surfaces stay light on purpose.
 */
:root[data-theme="dark"] {
  color-scheme: dark;

  --color-bg: #0f1412;
  --color-surface: #161c19;
  --color-surface-subtle: #1c2420;
  --color-surface-sunken: #232c28;
  --color-surface-inverse: #e6ece9;
  --color-surface-figure: #f3f1ea;
  --color-overlay: rgb(0 0 0 / .62);
  --color-paper: #f1efe7;
  --color-paper-text: #1d2a24;
  --color-paper-text-secondary: #4d5a53;
  --color-paper-border: #3a4540;

  --color-text: #e7ede9;
  --color-text-secondary: #b5bfba;
  --color-text-tertiary: #97a29d;
  --color-text-disabled: #6c7772;
  --color-text-inverse: #0f1412;
  --color-text-on-brand: #04241a;
  --color-text-link: #6fd0a6;
  --color-text-link-hover: #9fe3c3;

  --color-border: #27312c;
  --color-border-strong: #35403b;
  --color-border-control: #6c7872;
  --color-border-selected: var(--green-400);

  --color-brand: var(--green-400);
  --color-brand-strong: var(--green-300);
  --color-brand-deep: var(--green-200);
  --color-brand-subtle: #163d2e;
  --color-brand-faint: #11281f;
  --color-brand-subtle-text: var(--green-200);
  --color-brand-border: #24553f;
  --color-brand-border-strong: #2f6e52;
  --color-selection: #24553f;
  --color-action-primary: var(--green-500);
  --color-action-primary-hover: var(--green-400);
  --color-action-primary-press: #2a9a6e;
  --color-action-secondary-hover: #12291f;
  --color-action-neutral-hover: #202925;
  --color-action-neutral-press: #29332e;
  --color-action-disabled-bg: #232b27;
  --color-action-disabled-text: #6c7772;
  --color-progress: #3fb583;
  --color-progress-track: #2a3430;

  --color-focus-ring: #6ea8ff;
  --color-focus-gap: #0f1412;

  --color-success: #6fcf9f; --color-success-strong: #9fe3c3;
  --color-success-bg: #10291f; --color-success-border: #2a6247;
  --color-warning: #f2b552; --color-warning-strong: #fdd08f;
  --color-warning-bg: #2c2111; --color-warning-border: #6e4c14;
  --color-danger: #ff8e86; --color-danger-strong: #ffb7b0;
  --color-danger-bg: #321819; --color-danger-border: #7d3033;
  --color-info: #80b4ff; --color-info-strong: #abcbff;
  --color-info-bg: #13233a; --color-info-border: #2c4f80;

  --color-accent-blue: #9cc4ff; --color-accent-blue-bg: #182b45;
  --color-accent-amber: #f6c272; --color-accent-amber-bg: #33260f;
  --color-accent-violet: #c3b5ff; --color-accent-violet-bg: #261f45;
  --color-chart-1: #80b4ff; --color-chart-2: #f2b552; --color-chart-3: #6fcf9f;
  --color-chart-axis: #c3ccc7; --color-chart-fill: #1e3556;
  --color-highlight: rgb(242 181 82 / .3);
  --color-indicator: #5c6762;
  --color-skeleton: #232c28; --color-skeleton-shine: #2c3631;
  --color-scrollbar: #4a5550;

  --shadow-color: 0 0 0;
  --shadow-low: 0 1px 2px 0 rgb(var(--shadow-color) / .4);
  --shadow-mid: 0 4px 10px 0 rgb(var(--shadow-color) / .42), 0 1px 2px 0 rgb(var(--shadow-color) / .3);
  --shadow-high: 0 10px 24px 0 rgb(var(--shadow-color) / .5), 0 2px 4px 0 rgb(var(--shadow-color) / .3);
  --shadow-overlay: 0 24px 56px -12px rgb(var(--shadow-color) / .7);
}

/* Smooth the switch itself, but never animate on first paint (theme.js adds the class after load). */
:root.theme-transition, :root.theme-transition *, :root.theme-transition *::before, :root.theme-transition *::after {
  transition: background-color var(--duration-base) var(--ease-standard), border-color var(--duration-base) var(--ease-standard), color var(--duration-base) var(--ease-standard), fill var(--duration-base) var(--ease-standard) !important;
}

@media (min-width: 781px) { :root { --gutter: var(--space-6); } }
@media (min-width: 1024px) { :root { --gutter: var(--space-8); } }

@media (prefers-reduced-motion: reduce) {
  :root { --duration-fast: 0ms; --duration-base: 0ms; --duration-slow: 0ms; }
}
