/* Design tokens: the only place with colors, fonts, radii and motion curves.
   Components use var(--...) only. Light values here, dark below (twice, so both the
   system setting and the in-app switch work). See docs/frontend-guidelines.md. */
:root {
  --bg: #f2f2f7;
  --surface: #ffffff;
  --paper: #fffdf8;
  --fg: #15171c;
  --muted: #62667a; /* 5.1:1 on --bg (WCAG AA) */
  --line: rgba(60, 64, 82, 0.14);
  --fill: rgba(60, 64, 82, 0.06);
  --accent: #2f5fd0;
  --accent-soft: rgba(47, 95, 208, 0.08);
  --on-accent: #ffffff;
  --primary: var(--accent);
  --on-primary: var(--on-accent);
  --primary-soft: var(--accent-soft);
  --card-border: transparent;
  --know: #14753f; /* 5.2:1 on --surface */
  --again: #c2410c; /* 4.6:1 on --bg */
  --started: #8a6100; /* started, not done yet: dark amber, 4.8:1 on --surface */
  --know-soft: color-mix(in srgb, var(--know) 10%, transparent);
  --again-soft: color-mix(in srgb, var(--again) 8%, transparent);
  --started-soft: color-mix(in srgb, var(--started) 8%, transparent);
  --subject-english: #2f5fd0;
  --subject-history: #8a5a2b;
  --subject-ukr: #c99a06;
  --subject-math: #6b5bd2;
  --graph-grid: color-mix(in srgb, var(--fg) 9%, transparent);
  --skeleton: color-mix(in srgb, var(--fg) 9%, transparent); /* grey blocks of a loading screen */
  --graph-axis: color-mix(in srgb, var(--fg) 55%, transparent);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 6px 18px rgba(20, 24, 40, 0.06);
  --blur-bg: rgba(242, 242, 247, 0.8);
  --toast-action: #8aa6ff; /* on the dark toast (--fg): 7.7:1 */

  --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  --font-head: var(--font-ui);
  --head-weight: 700;
  --head-track: -0.022em; /* large titles: a little tighter, as Apple tracks big type */
  --small-track: 0; /* 13px and smaller: no tightening, it would hurt reading */
  --font-mono: ui-monospace, Consolas, monospace;

  /* Text styles of Apple HIG (decision 0110). Sizes in rem: they grow with the reader's text
     size setting (1rem = 16px by default). Use only these: never a literal font-size. */
  --text-display-large: 3.5rem; /* 56: a hero figure (session done), not in HIG */
  --text-display: 2.75rem; /* 44: big numbers and public page titles, not in HIG */
  --text-large-title: 2.125rem; /* 34 */
  --text-title1: 1.75rem; /* 28 */
  --text-title2: 1.375rem; /* 22 */
  --text-title3: 1.25rem; /* 20 */
  --text-headline: 1.0625rem; /* 17, weight 600 */
  --text-body: 1.0625rem; /* 17 */
  --text-callout: 1rem; /* 16 */
  --text-subhead: 0.9375rem; /* 15 */
  --text-footnote: 0.8125rem; /* 13 */
  --text-caption1: 0.75rem; /* 12 */
  --text-caption2: 0.6875rem; /* 11 */
  --headline-weight: 600;
  /* Leading: tight on titles, roomier on text; body 1.4, not HIG 1.29: Cyrillic reads better. */
  --leading-display: 1.1; /* display sizes, 44 and up */
  --leading-title: 1.2;
  --leading-title3: 1.25;
  --leading-headline: 1.3;
  --leading-body: 1.4;
  --leading-small: 1.35; /* footnote and captions */
  --leading-read: 1.55; /* long reading: notes, public prose */
  /* Tracking by size: titles tighter, body slightly, small text none (SF on Apple tracks itself). */
  --track-body: -0.01em;

  /* Spacing: a 4px grid. Gaps, margins and paddings use only these. Kept in px: a larger
     text size gets more room on the line instead of bigger empty margins (as in iOS). */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
  --space-8: 32px;
  --space-12: 48px;
  --space-16: 64px;
  --paper-rule: color-mix(in srgb, var(--accent) 18%, transparent);
  --paper-margin: color-mix(in srgb, var(--again) 38%, transparent);
  --font-word: ui-serif, "New York", "Newsreader", Georgia, serif;

  --radius-group: 14px;
  --radius-card: 22px;
  --radius-study: 28px;
  --radius-today: 16px;
  --radius-button: 14px; /* a rounded rectangle: a pill on every button looked templated */
  --radius-action: 12px;
  --radius-segment: 9px;
  --radius-segment-item: 7px;
  --radius-indicator: 2px;
  --corner: round; /* squircle where the browser can (see the end of this file) */
  --tabbar-h: 56px;
  --topbar-h: 56px;

  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --press-scale: 0.97; /* pressed: shrinks at once, on touch-down */
  --press-dim: 0.5; /* pressed text-only controls (back, tabs, plain buttons) */
  --press-in: 0.06s; /* the press shows almost instantly, the release eases back */
  --spring: linear(0, 0.009, 0.035 2.1%, 0.141, 0.281 6.7%, 0.723 12.9%, 0.938 16.7%, 1.017, 1.077, 1.121, 1.149 24.3%, 1.159, 1.163, 1.161, 1.154 29.9%, 1.129 32.8%, 1.051 39.6%, 1.017 43.1%, 0.991, 0.977 51%, 0.974 53.8%, 0.975 57.1%, 0.997 69.8%, 1.003 76.9%, 1);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0c0f; --surface: #1b1d22; --paper: #22242a; --fg: #f2f3f6; --muted: #9a9fac;
    --line: rgba(255, 255, 255, 0.1); --fill: rgba(255, 255, 255, 0.06);
    --accent: #7f9cff; --accent-soft: rgba(127, 156, 255, 0.14); --on-accent: #0b0c0f;
    --know: #3fd082; --again: #ff8a52; --started: #f0c63c;
    --subject-english: #7f9cff; --subject-history: #d29a62; --subject-ukr: #f0c63c; --subject-math: #a598ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 14px 36px rgba(0, 0, 0, 0.5);
    --blur-bg: rgba(11, 12, 15, 0.74);
    --toast-action: #2f5fd0; /* on the light toast (--fg): 5.2:1, strict 4.8:1 */
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0c0f; --surface: #1b1d22; --paper: #22242a; --fg: #f2f3f6; --muted: #9a9fac;
  --line: rgba(255, 255, 255, 0.1); --fill: rgba(255, 255, 255, 0.06);
  --accent: #7f9cff; --accent-soft: rgba(127, 156, 255, 0.14); --on-accent: #0b0c0f;
  --know: #3fd082; --again: #ff8a52; --started: #f0c63c;
  --subject-english: #7f9cff; --subject-history: #d29a62; --subject-ukr: #f0c63c; --subject-math: #a598ff;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 14px 36px rgba(0, 0, 0, 0.5);
  --blur-bg: rgba(11, 12, 15, 0.74);
  --toast-action: #2f5fd0;
  color-scheme: dark;
}

/* Strict, variant C. WCAG AA (minimum on --bg and --surface): fg 15.02:1,
   muted 5.38:1, links 5.21:1, late status 5.00:1. Primary label 16.24:1. */
:root[data-style="strict"] {
  --bg: #f6f4ef; --surface: #fffdf8; --fg: #1b1f27; --muted: #5f6472;
  --paper: var(--surface); --line: #e2ddd2;
  --fill: color-mix(in srgb, var(--fg) 8%, transparent);
  --blur-bg: color-mix(in srgb, var(--bg) 90%, transparent);
  --primary: var(--fg); --on-primary: var(--surface);
  --primary-soft: color-mix(in srgb, var(--primary) 8%, transparent);
  --again: #b3470d; --subject-ukr: #b48806;
  --shadow: none; --card-border: var(--line);
  --font-head: "Newsreader", Georgia, serif; --head-weight: 600; --head-track: 0;
  --radius-group: 6px; --radius-card: 6px; --radius-today: 6px;
  --radius-button: 6px; --radius-action: 6px;
  --radius-segment: 6px; --radius-segment-item: 4px;
}

/* Strict dark (minimum on --bg and --surface): fg 14.87:1, muted 7.06:1,
   links 7.59:1, late status 8.51:1. Primary label 15.83:1. */
@media (prefers-color-scheme: dark) {
  :root[data-style="strict"]:not([data-theme="light"]) {
    --bg: #101113; --surface: #17181b; --fg: #ecebe6; --muted: #a2a3a9;
    --line: #2b2c30;
    --accent: #8aa6ff; --accent-soft: rgba(138, 166, 255, 0.14); --on-accent: var(--bg);
    --on-primary: var(--bg);
    --again: #ff9a66;
    --subject-history: #d6a06a; --subject-ukr: #e8c24a; --subject-english: var(--accent);
  }
}
:root[data-style="strict"][data-theme="dark"] {
  --bg: #101113; --surface: #17181b; --fg: #ecebe6; --muted: #a2a3a9;
  --line: #2b2c30;
  --accent: #8aa6ff; --accent-soft: rgba(138, 166, 255, 0.14); --on-accent: var(--bg);
  --on-primary: var(--bg);
  --again: #ff9a66;
  --subject-history: #d6a06a; --subject-ukr: #e8c24a; --subject-english: var(--accent);
}

/* Smooth corners (decision 0107). At the same radius a squircle looks less rounded, so the
   radii grow 1.7 times: the cut corner then matches the round one it replaces. Browsers
   without corner-shape keep the round corners and the radii above. */
@supports (corner-shape: squircle) {
  :root {
    --corner: squircle;
    --radius-group: 24px; --radius-card: 37px; --radius-study: 48px; --radius-today: 27px;
    --radius-button: 24px; --radius-action: 20px;
    --radius-segment: 15px; --radius-segment-item: 12px;
  }
  :root[data-style="strict"] {
    --radius-group: 10px; --radius-card: 10px; --radius-today: 10px;
    --radius-button: 10px; --radius-action: 10px;
    --radius-segment: 10px; --radius-segment-item: 7px;
  }
}
/* ---------- Palettes (decision 0112) ----------
   data-palette on <html>: none or "blue" keeps every token above, "steel" (the default, below) only
   changes its accent. The other three share
   a monochrome base and differ only in the accent. A palette sets colors only, the style
   (soft or strict) keeps fonts, radii, borders and shadows, so a palette rule comes after the
   strict ones and is one step more specific in dark, where strict dark is (0,3,0).
   WCAG AA, light (on --bg #f5f5f5 / --surface #ffffff): fg 17.32 / 18.88, muted 4.89 / 5.33,
   know 4.63 / 5.05, again 5.07 / 5.52, started 5.25 / 5.72, history 4.67 / 5.09,
   ukr 4.56 / 4.97 (was #857345, 4.25), math 5.31 / 5.78. */
:root:is([data-palette="indigo"], [data-palette="mono"], [data-palette="violet"]) {
  --bg: #f5f5f5; --surface: #ffffff; --paper: #ffffff; --fg: #111111; --muted: #6b6b6b;
  --line: #e3e3e3; --card-border: var(--line);
  --fill: color-mix(in srgb, var(--fg) 6%, transparent);
  --blur-bg: color-mix(in srgb, var(--bg) 80%, transparent);
  --know: #2e7d4f; --again: #b5432a; --started: #7a6420;
  --subject-history: #7d6b5a; --subject-ukr: #806e42; --subject-math: #66637a;
  --primary: var(--accent); --on-primary: var(--on-accent);
  --accent-soft: color-mix(in srgb, var(--accent) 10%, transparent);
  --primary-soft: var(--accent-soft);
  --subject-english: var(--accent);
}
/* Dark (on --bg #0a0a0a / --surface #161616): fg 17.68 / 16.16, muted 7.12 / 6.51,
   know 9.74 / 8.90, again 7.82 / 7.15, started 11.24 / 10.27, history 8.24 / 7.54,
   ukr 10.12 / 9.25, math 8.41 / 7.69. */
@media (prefers-color-scheme: dark) {
  :root:is([data-palette="indigo"], [data-palette="mono"], [data-palette="violet"]):not([data-theme="light"]) {
    --bg: #0a0a0a; --surface: #161616; --paper: #1e1e1e; --fg: #f2f2f2; --muted: #9b9b9b;
    --line: #2a2a2a;
    --know: #6cc895; --again: #e88a6e; --started: #d8c27a;
    --subject-history: #b8a48f; --subject-ukr: #c9b97f; --subject-math: #a9a6c2;
    --accent-soft: color-mix(in srgb, var(--accent) 12%, transparent);
    --on-primary: var(--on-accent); --subject-english: var(--accent);
  }
}
:root:is([data-palette="indigo"], [data-palette="mono"], [data-palette="violet"])[data-theme="dark"] {
  --bg: #0a0a0a; --surface: #161616; --paper: #1e1e1e; --fg: #f2f2f2; --muted: #9b9b9b;
  --line: #2a2a2a;
  --know: #6cc895; --again: #e88a6e; --started: #d8c27a;
  --subject-history: #b8a48f; --subject-ukr: #c9b97f; --subject-math: #a9a6c2;
  --accent-soft: color-mix(in srgb, var(--accent) 12%, transparent);
  --on-primary: var(--on-accent); --subject-english: var(--accent);
}

/* Accents. Light: indigo 5.39 / 5.87 on bg / surface (was #5e6ad2, 4.31), 4.69 on its own
   soft fill, label on the button 5.87. Violet 5.78 / 6.30, soft 4.84, label 6.30.
   Mono 17.32 / 18.88, label 18.88: text actions get a shape cue in theme.css.
   Dark: indigo 7.27 / 6.65, label 7.27; violet 8.20 / 7.50, label 8.20; mono as fg. */
:root[data-palette="indigo"] { --accent: #4b58cd; --on-accent: #ffffff; }
:root[data-palette="violet"] { --accent: #6741d9; --on-accent: #ffffff; }
:root[data-palette="mono"] { --accent: #111111; --on-accent: #ffffff; }
@media (prefers-color-scheme: dark) {
  :root[data-palette="indigo"]:not([data-theme="light"]) { --accent: #8b93ff; --on-accent: #0a0a0a; }
  :root[data-palette="violet"]:not([data-theme="light"]) { --accent: #b197fc; --on-accent: #0a0a0a; }
  :root[data-palette="mono"]:not([data-theme="light"]) { --accent: #f2f2f2; --on-accent: #0a0a0a; }
}
:root[data-palette="indigo"][data-theme="dark"] { --accent: #8b93ff; --on-accent: #0a0a0a; }
:root[data-palette="violet"][data-theme="dark"] { --accent: #b197fc; --on-accent: #0a0a0a; }
:root[data-palette="mono"][data-theme="dark"] { --accent: #f2f2f2; --on-accent: #0a0a0a; }

/* Swatches for the palette picker: each option shows its own accent in the current theme. */
:root {
  --swatch-blue: #2f5fd0; --swatch-indigo: #4b58cd; --swatch-mono: #111111; --swatch-violet: #6741d9;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --swatch-blue: #7f9cff; --swatch-indigo: #8b93ff; --swatch-mono: #f2f2f2; --swatch-violet: #b197fc;
  }
}
:root[data-theme="dark"] {
  --swatch-blue: #7f9cff; --swatch-indigo: #8b93ff; --swatch-mono: #f2f2f2; --swatch-violet: #b197fc;
}

/* Steel, the default palette (decision 0113): the base of "blue" (the neutral tokens above, soft
   or strict) with a steel-blue accent. In strict the main button stays ink, as with "blue".
   Light #3a6d99 (Steel Blue #4682b4 darkened for text): soft 4.92 / 5.49 on --bg / --surface,
   strict 4.99 / 5.40, label on the button 5.49. Soft fill: Periwinkle #c3cde6 at 25 %, accent
   on it 4.52 soft, 4.56 strict (a 10 % accent tint gave 4.34).
   Dark #8aaed6 (near Dark Pastel Blue #779ecb): soft 8.48 / 7.31, strict 8.19 / 7.70,
   label 8.48, on its 12 % fill 5.92 or more. */
:root[data-palette="steel"] {
  --accent: #3a6d99; --on-accent: #ffffff; --subject-english: var(--accent);
  --accent-soft: color-mix(in srgb, #c3cde6 25%, transparent);
}
@media (prefers-color-scheme: dark) {
  :root[data-palette="steel"]:not([data-theme="light"]) {
    --accent: #8aaed6; --on-accent: #0b0c0f; --subject-english: var(--accent);
    --accent-soft: color-mix(in srgb, var(--accent) 12%, transparent);
  }
}
:root[data-palette="steel"][data-theme="dark"] {
  --accent: #8aaed6; --on-accent: #0b0c0f; --subject-english: var(--accent);
  --accent-soft: color-mix(in srgb, var(--accent) 12%, transparent);
}
:root { --swatch-steel: #3a6d99; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --swatch-steel: #8aaed6; }
}
:root[data-theme="dark"] { --swatch-steel: #8aaed6; }
