/* ============ FizzyQuiz look: white first, with a dark mode ============
   Loaded after styles.css, so these tokens win. The theme lives on <html data-theme="light|dark">,
   set before the page paints by the small script in index.html and switched by js/theme.js. */

/* ---------- white (the main theme) ---------- */
:root, :root[data-theme="light"] {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #ffffff;
  --card: #ffffff;
  --well: #f5f5f6;
  --well-2: #ededef;
  --line: #ebebee;
  --line-2: #dedee3;
  --ink: #0f1115;
  --ink-2: #3d414c;
  --muted: #6f7482;
  --navy: #111318;
  --brand-soft: color-mix(in srgb, var(--brand) 9%, #fff);
  --good-soft: #e7f8ee;
  --bad-soft: #fdecef;
  --sh-1: 0 1px 2px rgba(15, 17, 21, .04), 0 1px 1px rgba(15, 17, 21, .02);
  --sh-2: 0 10px 30px -10px rgba(15, 17, 21, .12), 0 2px 6px rgba(15, 17, 21, .04);
  --sh-3: 0 30px 70px -20px rgba(15, 17, 21, .28);
  --glass: rgba(255, 255, 255, .82);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

/* ---------- dark ---------- */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0c0e;
  --surface: #141518;
  --card: #141518;
  --well: #1b1c20;
  --well-2: #24252a;
  --line: #26272c;
  --line-2: #33343a;
  --ink: #f3f4f6;
  --ink-2: #c9ccd3;
  --muted: #8d919c;
  --navy: #1d1f24;
  --brand-soft: color-mix(in srgb, var(--brand) 22%, #141518);
  --good-soft: #10291c;
  --bad-soft: #2e1418;
  --sh-1: 0 1px 0 rgba(255, 255, 255, .03) inset, 0 1px 2px rgba(0, 0, 0, .4);
  --sh-2: 0 12px 30px -10px rgba(0, 0, 0, .6), 0 2px 6px rgba(0, 0, 0, .4);
  --sh-3: 0 30px 70px -20px rgba(0, 0, 0, .8);
  --glass: rgba(20, 21, 24, .78);
}

/* ---------- the page ---------- */
body { background: var(--bg); color: var(--ink); }
.tn { background: var(--glass) !important; backdrop-filter: saturate(1.4) blur(14px); border-bottom-color: var(--line) !important; }
.card, .list-row { box-shadow: var(--sh-1); }
.list-row:hover, .me-chip:hover { box-shadow: var(--sh-2); }
.welcome { background: radial-gradient(circle at 18% 8%, color-mix(in srgb, var(--brand) 7%, transparent), transparent 45%), radial-gradient(circle at 92% 92%, color-mix(in srgb, #7c3aed 6%, transparent), transparent 45%), var(--bg); }
.toast { background: var(--navy); border: 1px solid color-mix(in srgb, #fff 8%, transparent); }
.btn.ghost { background: var(--surface); color: var(--ink); border-color: var(--line); box-shadow: 0 2px 0 var(--line-2), var(--sh-1); }
.field input, .field select, .tn-q, .tn-grade select { background: var(--surface); color: var(--ink); }
.tn-q { background: var(--well) !important; border-color: transparent !important; }
.tn-q:focus-within { background: var(--surface) !important; border-color: var(--brand) !important; }
.tn-letter, .tn-stats { background: var(--well) !important; }
.tn-drop { box-shadow: 0 24px 60px -18px rgba(15, 17, 21, .28), 0 2px 8px rgba(15, 17, 21, .06) !important; }
:root[data-theme="dark"] .tn-drop { box-shadow: 0 24px 60px -18px rgba(0, 0, 0, .85) !important; }
.auth-scrim { background: color-mix(in srgb, var(--bg) 45%, rgba(8, 10, 16, .55)); }

/* Dark: the few places that still say "white" or a dark ink colour by hand. */
:root[data-theme="dark"] .subject-frame { background: var(--bg); }
:root[data-theme="dark"] .shop-switch a .i { background: var(--well-2); color: var(--brand-2); }
:root[data-theme="dark"] .cl-watch-btn { background: var(--well); color: var(--ink); border-color: var(--line-2); }
:root[data-theme="dark"] .game-card .play-dot { background: var(--surface); }
:root[data-theme="dark"] img[src$="logo.svg"] { filter: drop-shadow(0 0 0.5px rgba(255, 255, 255, .25)); }
:root[data-theme="dark"] ::selection { background: color-mix(in srgb, var(--brand) 45%, transparent); }

/* ---------- switching themes ----------
   With the View Transitions API the new theme grows out of the switch in a circle (js/theme.js sets --tx/--ty).
   Without it, colours ease across for a moment. */
html.theme-fading, html.theme-fading * { transition: background-color .45s var(--ease), border-color .45s var(--ease), color .35s var(--ease), fill .35s, box-shadow .45s !important; }
::view-transition-old(root), ::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
::view-transition-new(root) { animation: theme-reveal .7s cubic-bezier(.65, 0, .25, 1) both; }
@keyframes theme-reveal {
  from { clip-path: circle(0 at var(--tx, 50%) var(--ty, 0)); }
  to { clip-path: circle(var(--tr, 150vmax) at var(--tx, 50%) var(--ty, 0)); }
}

/* ---------- the theme switch: a soft key in a well, with a dot-matrix sun or moon ---------- */
.fq-theme { --w: 74px; --h: 42px; --k: 34px; position: relative; flex: none; width: var(--w); height: var(--h); padding: 0; border: 0; border-radius: 15px; cursor: pointer;
  background: linear-gradient(180deg, #e6e6e8, #f1f1f3); box-shadow: inset 0 2px 4px rgba(15, 17, 21, .14), inset 0 -1px 0 rgba(255, 255, 255, .9), 0 1px 0 rgba(255, 255, 255, .8);
  -webkit-tap-highlight-color: transparent; isolation: isolate; }
.fq-theme:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 55%, transparent); outline-offset: 3px; }
.fq-theme .fq-knob { position: absolute; top: 4px; left: 4px; width: var(--k); height: var(--k); border-radius: 11px; display: grid; place-items: center;
  background: linear-gradient(180deg, #ffffff, #f2f2f4); box-shadow: 0 1px 0 rgba(255, 255, 255, 1) inset, 0 -1px 0 rgba(15, 17, 21, .05) inset, 0 4px 10px -2px rgba(15, 17, 21, .25), 0 1px 2px rgba(15, 17, 21, .18);
  transform: translateX(calc(var(--w) - var(--k) - 8px)); transition: transform .55s cubic-bezier(.34, 1.4, .5, 1), background .5s, box-shadow .5s; }
/* the warm rim light along the top and leading edge of the key */
.fq-theme .fq-knob::before { content: ""; position: absolute; inset: -1px; border-radius: 12px; pointer-events: none; padding: 1.5px;
  background: conic-gradient(from 200deg, transparent 0 35%, #ffc56b 48%, #ff9d2e 55%, transparent 70%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor; mask-composite: exclude; opacity: .95; transition: opacity .5s, filter .5s; }
.fq-theme .fq-knob::after { content: ""; position: absolute; inset: -6px; border-radius: 16px; z-index: -1; pointer-events: none;
  background: radial-gradient(60% 60% at 50% 0%, rgba(255, 170, 60, .55), transparent 70%); filter: blur(6px); transition: opacity .5s, background .5s; }
.fq-theme svg { width: 22px; height: 22px; overflow: visible; }
.fq-theme svg circle { fill: #2b2d33; transition: fill .5s; }
.fq-theme:hover .fq-knob { box-shadow: 0 1px 0 #fff inset, 0 -1px 0 rgba(15, 17, 21, .05) inset, 0 6px 14px -3px rgba(15, 17, 21, .3), 0 1px 2px rgba(15, 17, 21, .18); }
.fq-theme:active .fq-knob { scale: .94; transition: transform .55s cubic-bezier(.34, 1.4, .5, 1), scale .12s; }

:root[data-theme="dark"] .fq-theme { background: linear-gradient(180deg, #0a0b0d, #17181b); box-shadow: inset 0 2px 5px rgba(0, 0, 0, .7), inset 0 -1px 0 rgba(255, 255, 255, .05), 0 1px 0 rgba(255, 255, 255, .04); }
:root[data-theme="dark"] .fq-theme .fq-knob { transform: translateX(0); background: linear-gradient(180deg, #3a3c42, #2a2c31);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .14) inset, 0 -1px 0 rgba(0, 0, 0, .3) inset, 0 6px 14px -3px rgba(0, 0, 0, .8), 0 1px 2px rgba(0, 0, 0, .5); }
:root[data-theme="dark"] .fq-theme .fq-knob::before { background: conic-gradient(from 20deg, transparent 0 30%, #f3f6ff 45%, #b9c7ff 55%, transparent 72%); }
:root[data-theme="dark"] .fq-theme .fq-knob::after { background: radial-gradient(60% 60% at 0% 50%, rgba(220, 230, 255, .35), transparent 70%); }
:root[data-theme="dark"] .fq-theme svg circle { fill: #eef0f6; }
.fq-theme.sm { --w: 60px; --h: 34px; --k: 26px; border-radius: 12px; }
.fq-theme.sm .fq-knob { border-radius: 9px; }
.fq-theme.sm svg { width: 17px; height: 17px; }
.tn-right .fq-theme { --w: 60px; --h: 34px; --k: 26px; border-radius: 12px; }
.tn-right .fq-theme .fq-knob { border-radius: 9px; }
.tn-right .fq-theme svg { width: 17px; height: 17px; }
.tn-theme-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 10px 0 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--well); font-weight: 700; }
.tn-theme-row small { display: block; color: var(--muted); font-weight: 600; font-size: .78rem; }
@media (max-width: 520px) { .tn-right > .fq-theme { display: none; } }

@media (prefers-reduced-motion: reduce) {
  .fq-theme .fq-knob { transition: none; }
  ::view-transition-new(root) { animation: none; }
  html.theme-fading, html.theme-fading * { transition: none !important; }
}

/* Dark: the Events calendar days are drawn white by hand in js/rewards.js. */
:root[data-theme="dark"] .ev-day { background: var(--surface); border-color: var(--line-2); color: var(--ink-2); }
:root[data-theme="dark"] .ev-day.got { background: var(--good-soft); border-color: #1f6b3f; }
