/* ───────────────────────────────────────────────────────────────────────────
   theme.css — shared theme tokens + accessibility, driven by prefs.js

   Light/dark colours are semantic CSS variables. Dark mode + accessibility are
   applied centrally here (keyed off the data-attributes prefs.js sets on <html>)
   so individual pages don't each need bespoke dark styles for their shared
   chrome (nav, cards, panels, chips…).
   ─────────────────────────────────────────────────────────────────────────── */

/* OpenDyslexic for the dyslexia-friendly option (system fonts as resilient
   fallback) is now self-hosted — see fonts.css, loaded on every page
   alongside this file. */

:root {
  --bg:        #F4F6FB;
  --surface:   #FFFFFF;
  --surface-2: #F1F3F8;
  --text:      #111827;
  --text-2:    #4B5563;
  --text-3:    #5B6472;   /* was #9CA3AF — failed WCAG AA (~2.5:1) on white/cards */
  --border:    #EAECF4;
  --p:         #B31B1B;
  --p-dk:      #991414;
  --p-soft:    #FFF0F0;
  --p-rgb:     179,27,27;   /* --p's components, comma-separated, for rgba(var(--p-rgb),alpha) */
  --shadow:    rgba(16,24,40,.08);
}

html[data-theme="dark"] {
  --bg:        #0F1217;
  --surface:   #181C23;
  --surface-2: #232A33;
  --text:      #E7EAF0;
  --text-2:    #B6BECB;
  --text-3:    #99A2B0;
  --border:    #2A313B;
  --p:         #E45E5B;   /* lifted red so it stays legible on dark */
  --p-dk:      #C8423F;
  --p-soft:    #2C1B1C;
  --p-rgb:     228,94,91;
  --shadow:    rgba(0,0,0,.55);
  --shadow-md: 0 6px 20px rgba(0,0,0,.45);
}

/* The hidden attribute must always win. A class rule that sets display (flex/grid/block) otherwise overrides it, since
   both have the same specificity and an author rule beats the browser's own [hidden] rule. That is how an invisible
   full-screen layer once ate every tap on phones, and how a "closed" panel kept taking up space. */
[hidden] { display: none !important; }

/* In dark mode, the browser's own parts of form fields (date pickers, dropdown lists, spin buttons) go dark too; they
   otherwise stay light. Scoped to the fields rather than the page, so it can't reach the chat widget's light-only
   shadow DOM. */
html[data-theme="dark"] input, html[data-theme="dark"] select, html[data-theme="dark"] textarea { color-scheme: dark; }

/* Solid fills that carry WHITE text, and status text colours. Dark mode's lifted --p (#E45E5B) is right for red
   text on a dark surface but only 3.5:1 under white button text; #C8423F keeps white text at 4.9:1. The status
   colours are each tuned to clear WCAG AA (4.5:1) on --surface, --bg and their own -soft tint in their own mode
   (the older #16A34A green was 3.3:1 on white; #DC2626/#B45309 were 3.6/3.4:1 on the dark surface and just
   under 4.5:1 on a light tint).
   Adopted page by page; a page that doesn't use these is unaffected. */
:root {
  --p-solid:    var(--p);
  --p-solid-hv: var(--p-dk);
  --ok:   #15803D;
  --warn: #9C4A07;
  --err:  #C62828;
  --ok-soft:   rgba(21,128,61,.10);
  --warn-soft: rgba(180,83,9,.10);
  --err-soft:  rgba(220,38,38,.08);
}
html[data-theme="dark"] {
  --p-solid:    #C8423F;
  --p-solid-hv: #B03734;
  --ok:   #4ADE80;
  --warn: #FBBF24;
  --err:  #F87171;
  --ok-soft:   rgba(74,222,128,.12);
  --warn-soft: rgba(251,191,36,.12);
  --err-soft:  rgba(248,113,113,.12);
}

/* ── Design-system scale (UI consistency sweep, 10.7.26) ──────────────────
   Radius/shadow/typography/button/segmented-control tokens shared by every
   page. Same red palette as above — this section is about applying it
   consistently, not changing it. */
:root {
  --r-sm:   10px;  /* buttons, inputs, small chips */
  --r-md:   14px;  /* the one canonical "primary card" radius */
  --r-pill: 999px; /* segmented controls, tags, pill buttons */
  --shadow-sm: 0 1px 4px var(--shadow);        /* card at rest */
  --shadow-md: 0 6px 20px rgba(16,24,40,.10);  /* canonical card hover-lift */
}

/* Typography scale — one size/weight per semantic role, replacing the
   dozen near-duplicate variants found across pages (page-title/.hero h1/
   .page-header h1 etc all converge here). Pages keep their existing class
   names for layout reasons; these rules just standardise the values. */
.h-page, .page-title, .page-header h1 {
  font-size: clamp(24px, 4vw, 32px); font-weight: 750; letter-spacing: -.3px; line-height: 1.15;
}
.h-section, .section-title, .panel-title, .highlight-title, .group-title, .stats-head h2 {
  font-size: 17px; font-weight: 700; letter-spacing: -.1px;
}
.h-card, .card-title, .paper-title, .material-title {
  font-size: 14.5px; font-weight: 650;
}
.t-body { font-size: 13.5px; font-weight: 500; }
.t-sub, .card-desc, .section-sub, .page-sub, .panel-sub, .group-sub {
  font-size: 13px; color: var(--text-3);
}

/* Canonical card treatment — the one border/radius/shadow combo for a
   "primary card" (paper-card/material-card were already the best-adopted
   version of this; promoted here so every page can share it). */
.card, .panel, .paper-card, .material-card, .highlight, .stats-card, .board-card, .chat-card {
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
}

/* Canonical button system — one .btn base (incl. the press micro-
   interaction already on revision-timetable's .cta / settings' .btn, but
   missing from the flat var(--p) buttons on past-papers/course-materials)
   plus primary/ghost/secondary modifiers. */
/* Base properties apply whether a button uses just ".btn-primary" alone
   (past-papers.html/course-materials.html's convention) or the combined
   ".btn .btn-primary" form (onboarding.html/settings.html's convention) —
   both exist in the codebase, so the shared rule has to work either way
   rather than requiring every page's markup to change. */
.btn, .btn-primary, .btn-ghost, .btn-secondary, .cta, .submit {
  font-family: inherit; font-size: 13.5px; font-weight: 650;
  border: none; border-radius: var(--r-sm); padding: 11px 20px;
  cursor: pointer; transition: filter .14s, box-shadow .16s, transform .1s;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:active, .btn-primary:active, .btn-ghost:active, .btn-secondary:active, .cta:active, .submit:active { transform: translateY(1px); }
/* --p-solid/--p-solid-hv, not --p/--p-dk: they are the same colours in light mode, but dark mode's lifted --p is only
   3.5:1 under white text (see the token block above). The glow follows the school's colour, not CNCS red. */
.btn-primary, .cta, .submit {
  color: #fff;
  background: linear-gradient(180deg, var(--p-solid), var(--p-solid-hv));
  box-shadow: 0 2px 8px rgba(var(--p-rgb),.28);
}
.btn-primary:hover, .cta:hover, .submit:hover { filter: brightness(1.05); box-shadow: 0 4px 14px rgba(var(--p-rgb),.34); }
.btn-ghost {
  color: var(--text-2); background: var(--surface-2);
}
.btn-ghost:hover { background: var(--border); }
.btn-secondary {
  color: var(--text-2); background: var(--surface-2); border: 1.5px solid var(--border);
}
.btn-secondary:hover { border-color: var(--p); color: var(--p); }

/* Canonical segmented control — unifies settings' text-size toggle,
   subjects.css's tier toggle, and revision-timetable's stats toggle into
   one shared visual language (all three already looked almost identical). */
.seg, .tier-seg, .stats-seg {
  display: flex; background: var(--surface-2); border-radius: var(--r-pill); padding: 3px; gap: 2px;
}
.seg-opt, .tier-opt, .stats-seg-btn {
  border: none; background: none; font-family: inherit; font-weight: 600;
  border-radius: var(--r-pill); cursor: pointer; transition: all .12s; color: var(--text-3);
  padding: 7px 16px; font-size: 12.5px; white-space: nowrap;
}
/* A visible, colour-filled "on" pill (not just a subtle elevation shadow —
   that reads as a near-invisible shade difference in dark mode, where the
   active pill's background and the track behind it are both dark, leaving
   nothing but a colour change in the text to show which option is picked). */
.seg-opt.on, .tier-opt.on, .stats-seg-btn.active {
  background: var(--p-soft); color: var(--p); box-shadow: 0 1px 3px rgba(16,24,40,.12);
}
/* Below 680px every use of this control (Settings' text-size toggle, the
   subject Tier picker, Revision Timetable's stats view) was squeezed into
   whatever leftover width its row's other content left behind — three
   buttons crammed into ~120px, cramped and hard to read/tap. Force it full
   width with evenly-sized buttons instead. */
@media (max-width: 680px) {
  .seg, .tier-seg, .stats-seg { width: 100%; }
  .seg-opt, .tier-opt, .stats-seg-btn { flex: 1; padding: 10px 0 !important; font-size: 13px !important; text-align: center; }
}

/* Entrance animation — the one genuinely new visual moment (the sweep
   found zero entrance animation anywhere on the site). Respects the
   existing [data-motion="reduced"] rule below, which already zeroes out
   all animation durations globally. */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}
.fade-in-up { animation: fadeInUp .32s ease-out both; }

/* ── Dark mode: shared chrome across pages ── */
.paper-ref { color: #6B7280; }  /* light base; dark override lifts it below */

html[data-theme="dark"] body { background: var(--bg) !important; color: var(--text); }

/* The logo PNG has a white background — against the dark nav it reads as a
   harsh square. Round it into a tidy white badge so it looks intentional. */
html[data-theme="dark"] .nav-logo-img {
  background: #fff;
  border-radius: 50%;
  padding: 5px;
  object-fit: contain;
  box-shadow: 0 0 0 1px rgba(255,255,255,.12);
}

html[data-theme="dark"] nav,
html[data-theme="dark"] .card,
html[data-theme="dark"] .panel,
html[data-theme="dark"] .cal,
html[data-theme="dark"] .side,
html[data-theme="dark"] .highlight,
html[data-theme="dark"] .stats,
html[data-theme="dark"] footer,
html[data-theme="dark"] .user-chip,
html[data-theme="dark"] .save-bar {
  background: var(--surface) !important;
  border-color: var(--border) !important;
}

html[data-theme="dark"] .cell,
html[data-theme="dark"] .tier-row,
html[data-theme="dark"] .field input,
html[data-theme="dark"] .pw-field input,
html[data-theme="dark"] .cal-btn {
  background: var(--surface) !important;
  border-color: var(--border) !important;
  color: var(--text);
}
html[data-theme="dark"] .pw-field label { color: var(--text-2) !important; }
html[data-theme="dark"] .cell.empty { background: transparent !important; border: none !important; }

/* Primary headings / body text → brightest foreground */
html[data-theme="dark"] .nav-name,
html[data-theme="dark"] .card-title, html[data-theme="dark"] .card-text,
html[data-theme="dark"] .page-title, html[data-theme="dark"] .panel-title,
html[data-theme="dark"] .section-title, html[data-theme="dark"] .cal-month,
html[data-theme="dark"] .cal-num, html[data-theme="dark"] .cell-num,
html[data-theme="dark"] .prog-name, html[data-theme="dark"] .tier-name,
html[data-theme="dark"] .side-head, html[data-theme="dark"] .setting-name,
html[data-theme="dark"] .brand h1,
html[data-theme="dark"] h1, html[data-theme="dark"] h2, html[data-theme="dark"] h3 {
  color: var(--text) !important;
}
/* Secondary text → mid foreground */
html[data-theme="dark"] .nav-sub, html[data-theme="dark"] .card-desc,
html[data-theme="dark"] .page-sub, html[data-theme="dark"] .panel-sub,
html[data-theme="dark"] .section-sub, html[data-theme="dark"] .user-email,
html[data-theme="dark"] .prog-pct, html[data-theme="dark"] .ev-meta,
html[data-theme="dark"] .nav-links a, html[data-theme="dark"] .paper-ref,
html[data-theme="dark"] .brand p, html[data-theme="dark"] .ev-title,
html[data-theme="dark"] .tier-opt, html[data-theme="dark"] .seg-opt {
  color: var(--text-2) !important;
}
/* Muted text (#9CA3AF / #6B7280) → lifted so it's still readable on dark */
html[data-theme="dark"] .stat-l, html[data-theme="dark"] .hint,
html[data-theme="dark"] .demo-note, html[data-theme="dark"] .step-label,
html[data-theme="dark"] .count-note, html[data-theme="dark"] .setting-desc,
html[data-theme="dark"] .side-sub, html[data-theme="dark"] .ev-date,
html[data-theme="dark"] .ev-empty, html[data-theme="dark"] .dow span,
html[data-theme="dark"] .subj-group-note, html[data-theme="dark"] .page-label,
html[data-theme="dark"] .section-label, html[data-theme="dark"] .req,
html[data-theme="dark"] .prog-pct {
  color: var(--text-3) !important;
}

/* Soft red surfaces (chips, active states, announcement) */
html[data-theme="dark"] .nav-links a.active,
html[data-theme="dark"] .logout-btn,
html[data-theme="dark"] .announcement,
html[data-theme="dark"] .highlight-tag { background: var(--p-soft) !important; }
/* Segmented controls (text size + tiers): dark track, lighter active pill */
html[data-theme="dark"] .tier-seg,
html[data-theme="dark"] .seg { background: var(--surface-2) !important; }
html[data-theme="dark"] .tier-opt.on,
html[data-theme="dark"] .seg-opt.on { color: var(--p) !important; }
html[data-theme="dark"] .save-bar { background: rgba(24,28,35,.92) !important; }

/* Brand-red text that's hardcoded #B31B1B → use the lifted red so it stays
   legible on dark surfaces (announcement, tags, etc.). .stat-n used to be here too; only the two insights pages use it
   now, where it carries its own score colour, and forcing it red in dark mode made an 83% class average look alarming. */
html[data-theme="dark"] .highlight-tag,
html[data-theme="dark"] .logout-btn,
html[data-theme="dark"] .ann-text,
html[data-theme="dark"] .ann-text strong,
html[data-theme="dark"] .subj-group-label,
html[data-theme="dark"] .highlight-tag span { color: var(--p) !important; }
html[data-theme="dark"] .ann-dot,
html[data-theme="dark"] .highlight-tag span { background: var(--p) !important; }

/* ── Accessibility: text size (whole-page zoom) ── */
html[data-text-size="small"]  body { zoom: 0.92; }
html[data-text-size="large"]  body { zoom: 1.12; }

/* ── Accessibility: dyslexia-friendly font ── */
html[data-font="dyslexic"],
html[data-font="dyslexic"] * {
  font-family: 'OpenDyslexic', 'Comic Sans MS', Verdana, sans-serif !important;
  letter-spacing: .2px;
}

/* ── Accessibility: reduce motion ── */
html[data-motion="reduced"] *,
html[data-motion="reduced"] *::before,
html[data-motion="reduced"] *::after {
  animation-duration: .001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: .001ms !important;
  scroll-behavior: auto !important;
}
/* The same for anyone who has Reduce Motion on in their phone's or computer's own settings, whether or not they have
   found the portal's toggle (only that toggle used to count). widget.js, timer.js and tour.js check it too. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ── Phones: the top bar's 32px sign-out button gets a 44px tap area (without making the bar taller) ── */
@media (max-width: 680px) {
  html .mobile-topbar-signout { position: relative; }
  html .mobile-topbar-signout::after { content: ""; position: absolute; inset: -6px; }
}

/* ── Phone landscape: the top bar scrolls away ──
   Sticky, the top bar and the tab bar took over a quarter of a 375px-tall screen. timer.js moves its chip with the bar. */
@media (max-width: 680px) and (max-height: 500px) {
  html .mobile-topbar { position: relative !important; }
}

/* ── Phones: no zoom-in when a field is tapped ──
   Safari on iPhone zooms the whole page in whenever a text field under 16px gets focus, and leaves it zoomed. Fields
   here were 13-15px (sign-in, quiz answers, the class code, teacher search and filters). 16px on phones only; no field
   on any page is set larger than that on a phone, so this only ever raises the size. Desktop is unchanged.
   iPads zoom the same way, so it also applies on any touch-first screen (no hover, coarse pointer) at any width. */
@media (max-width: 680px), (hover: none) and (pointer: coarse) {
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not([type="submit"]):not([type="button"]),
  select,
  textarea {
    font-size: 16px !important;
  }
}

/* The sidebar scrolls on short screens but shows no scrollbar (it looked like a stray bar beside the nav). */
.sidebar { scrollbar-width: none; }
.sidebar::-webkit-scrollbar { display: none; }

/* ── Motion (2.12.26): small transitions so the site doesn't feel static. Off with "Reduce motion" (the portal's toggle
   or the device's own setting), as everything above. ──
   1. Moving between pages: the browser's own cross-page transition (Chrome/Edge 126+, Safari 18.2+; others just load as
      before). The menu stays where it is and only the page content fades and rises in. */
@media (prefers-reduced-motion: no-preference) {
  @view-transition { navigation: auto; }
}
.sidebar { view-transition-name: sernio-sidebar; }
.mobile-tabbar { view-transition-name: sernio-tabbar; }
::view-transition-old(root) { animation: sernio-page-out .12s ease-out both; }
::view-transition-new(root) { animation: sernio-page-in .24s cubic-bezier(.2, .7, .2, 1) both; }
::view-transition-group(sernio-sidebar), ::view-transition-group(sernio-tabbar) { animation-duration: 0s; }
@keyframes sernio-page-out { to { opacity: 0; } }
@keyframes sernio-page-in { from { opacity: 0; transform: translateY(6px); } }
html[data-motion="reduced"]::view-transition-old(root), html[data-motion="reduced"]::view-transition-new(root) { animation: none; }

/* 2. A press you can feel on the site's buttons and chips. */
.btn-primary, .btn-soft, .btn, .chip, .rail-item, .pr-tab, .tn-min, .mp-open, .mp-del, .bk-show, .state-retry, .sq-primary,
.tp-chip, .warm-btn, .cta, .submit, .mix-go {
  transition-property: background-color, border-color, color, box-shadow, filter, transform, opacity;
  transition-duration: .15s;
}
.btn-primary:not(:disabled):active, .btn-soft:not(:disabled):active, .btn:not(:disabled):active, .chip:not(:disabled):active,
.pr-tab:active, .tn-min:active, .mp-open:active, .mp-del:not(:disabled):active, .bk-show:active, .state-retry:active,
.sq-primary:not(:disabled):active, .tp-chip:active, .warm-btn:active, .cta:not(:disabled):active, .submit:not(:disabled):active {
  transform: scale(.97);
}

/* 3. Content that appears after a click (a new tab, the next question, a list loading) rises in. Add .sernio-in. */
@keyframes sernio-rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.sernio-in { animation: sernio-rise .26s cubic-bezier(.2, .7, .2, 1) both; }
.sernio-in-list > * { animation: sernio-rise .3s cubic-bezier(.2, .7, .2, 1) both; }
.sernio-in-list > *:nth-child(2) { animation-delay: .03s; } .sernio-in-list > *:nth-child(3) { animation-delay: .06s; }
.sernio-in-list > *:nth-child(4) { animation-delay: .09s; } .sernio-in-list > *:nth-child(5) { animation-delay: .12s; }
.sernio-in-list > *:nth-child(n+6) { animation-delay: .15s; }
