/* ==========================================================================
   Science Team study site
   Template tokens (colors, font, 12px cards, 8px controls) + topic accents.
   ========================================================================== */

/* ---- Tokens -------------------------------------------------------------- */
:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --card: #fff;
  --fg: #1c2024;
  --muted: #6b7480;
  --line: #e2e5ea;
  --accent: #3b6df0;
  --ok: #1a9d55;
  --bad: #d23a3a;
  --warn: #c27a05;

  --raise: #eef0f4;
  --shadow: 0 1px 2px rgb(16 24 40 / .05), 0 4px 16px rgb(16 24 40 / .06);
  --shadow-lg: 0 2px 4px rgb(16 24 40 / .06), 0 16px 40px rgb(16 24 40 / .12);
  --r-card: 12px;
  --r-ctl: 8px;
  --gutter: 16px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --spring: cubic-bezier(.34, 1.56, .64, 1);

  /* Topic accents */
  --t-biology: #16a34a;
  --t-chemistry: #8b5cf6;
  --t-physics: #2563eb;
  --t-earth-space: #d97706;
  --t-general: #64748b;
  --t: var(--accent);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #14161a;
    --card: #1d2026;
    --fg: #e8eaee;
    --muted: #8b94a0;
    --line: #2d3139;
    --accent: #6c93ff;
    --ok: #3ecf7e;
    --bad: #ff6b6b;
    --warn: #f5b13d;
    --raise: #252932;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 4px 16px rgb(0 0 0 / .25);
    --shadow-lg: 0 2px 4px rgb(0 0 0 / .3), 0 16px 40px rgb(0 0 0 / .45);
    --t-biology: #4ade80;
    --t-chemistry: #a78bfa;
    --t-physics: #60a5fa;
    --t-earth-space: #fbbf24;
    --t-general: #94a3b8;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #14161a;
  --card: #1d2026;
  --fg: #e8eaee;
  --muted: #8b94a0;
  --line: #2d3139;
  --accent: #6c93ff;
  --ok: #3ecf7e;
  --bad: #ff6b6b;
  --warn: #f5b13d;
  --raise: #252932;
  --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 4px 16px rgb(0 0 0 / .25);
  --shadow-lg: 0 2px 4px rgb(0 0 0 / .3), 0 16px 40px rgb(0 0 0 / .45);
  --t-biology: #4ade80;
  --t-chemistry: #a78bfa;
  --t-physics: #60a5fa;
  --t-earth-space: #fbbf24;
  --t-general: #94a3b8;
}

.t-biology { --t: var(--t-biology); }
.t-chemistry { --t: var(--t-chemistry); }
.t-physics { --t: var(--t-physics); }
.t-earth-space { --t: var(--t-earth-space); }
.t-general { --t: var(--t-general); }

/* ---- Base ---------------------------------------------------------------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; height: auto; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -.015em; }
h1 { font-size: clamp(1.6rem, 4vw, 2.1rem); font-weight: 750; }
h2 { font-size: 1.15rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 650; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.eyebrow { font-size: .75rem; font-weight: 650; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--card); padding: .5rem 1rem; border-radius: var(--r-ctl); z-index: 100; }
.skip:focus { left: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- App bar ------------------------------------------------------------- */
.appbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
.appbar-in {
  max-width: 64rem; margin: 0 auto; padding: .6rem var(--gutter);
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.brand { display: flex; align-items: center; gap: .55rem; color: var(--fg); font-weight: 750; letter-spacing: -.01em; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
  color: #fff; background: linear-gradient(135deg, var(--t-physics), var(--t-chemistry));
}
.appbar-actions { display: flex; align-items: center; gap: .5rem; min-width: 0; }
.who { color: var(--muted); font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 12rem; }
@media (max-width: 480px) { .brand-name { display: none; } .who { max-width: 7rem; } }

/* ---- Layout -------------------------------------------------------------- */
main { max-width: 64rem; margin: 0 auto; padding: 1.5rem var(--gutter) 4rem; outline: none; }
.view { animation: view-in .35s var(--ease) both; }
@keyframes view-in { from { opacity: 0; transform: translateY(6px); } }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.row { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 18rem), 1fr)); }
.section { margin-top: 2rem; }
.section > .spread { margin-bottom: .85rem; }
.narrow { max-width: 44rem; margin-inline: auto; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  min-width: 0;
}
.card.flat { box-shadow: none; }

/* ---- Buttons & inputs ---------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  padding: .55rem 1rem; min-height: 40px;
  font: inherit; font-weight: 600; font-size: .95rem; line-height: 1.2;
  color: #fff; background: var(--accent);
  border: 1px solid transparent; border-radius: var(--r-ctl);
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: transform .12s var(--ease), background-color .15s, box-shadow .15s, border-color .15s, color .15s;
}
.btn:hover { text-decoration: none; filter: brightness(1.06); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-ghost { color: var(--fg); background: transparent; border-color: var(--line); }
.btn-ghost:hover { background: var(--raise); filter: none; }
.btn-soft { color: var(--t); background: color-mix(in srgb, var(--t) 12%, transparent); }
.btn-soft:hover { background: color-mix(in srgb, var(--t) 20%, transparent); filter: none; }
.btn-topic { background: var(--t); color: #fff; }
.btn-ok { background: var(--ok); }
.btn-bad { background: var(--bad); }
.btn-sm { min-height: 32px; padding: .3rem .7rem; font-size: .85rem; }
.btn-lg { min-height: 48px; padding: .75rem 1.4rem; font-size: 1rem; }
.btn-block { width: 100%; }
.kbd, kbd {
  font: 600 .72rem/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  padding: .2rem .35rem; border-radius: 5px;
  border: 1px solid var(--line); border-bottom-width: 2px;
  background: var(--card); color: var(--muted);
}
.btn kbd { background: transparent; color: inherit; border-color: currentColor; opacity: .6; }
.icon-btn {
  display: grid; place-items: center; width: 36px; height: 36px; padding: 0;
  color: var(--muted); background: transparent; border: 1px solid var(--line); border-radius: var(--r-ctl); cursor: pointer;
}
.icon-btn:hover { color: var(--fg); background: var(--raise); }

label.field { display: flex; flex-direction: column; gap: .35rem; font-size: .9rem; font-weight: 600; }
label.field .hint { font-weight: 400; color: var(--muted); font-size: .8rem; }
input {
  width: 100%; padding: .6rem .8rem; min-height: 44px;
  font: inherit; color: inherit; background: var(--bg);
  border: 1px solid var(--line); border-radius: var(--r-ctl);
  transition: border-color .15s, box-shadow .15s;
}
input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }

/* ---- Chips, pills -------------------------------------------------------- */
.chip {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .2rem .6rem; border-radius: 99px;
  font-size: .78rem; font-weight: 650;
  color: var(--t); background: color-mix(in srgb, var(--t) 13%, transparent);
  white-space: nowrap;
}
.chip::before { content: ""; width: .5rem; height: .5rem; border-radius: 50%; background: var(--t); }
.chip.plain::before { display: none; }
.pill { display: inline-flex; align-items: center; gap: .35rem; padding: .25rem .7rem; border-radius: 99px; border: 1px solid var(--line); font-size: .85rem; color: var(--muted); }

/* ---- Boot / empty / error states ---------------------------------------- */
.boot { display: grid; place-items: center; min-height: 50vh; }
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.empty {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: .6rem;
  padding: 2.5rem 1rem; color: var(--muted);
  border: 1.5px dashed var(--line); border-radius: var(--r-card);
}
.empty .empty-icon { font-size: 2rem; line-height: 1; }
.empty h3 { color: var(--fg); }
.alert {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap;
  padding: .75rem 1rem; border-radius: var(--r-ctl);
  color: var(--bad); background: color-mix(in srgb, var(--bad) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--bad) 30%, transparent);
  font-size: .92rem;
}
.skeleton { background: linear-gradient(90deg, var(--raise), var(--line), var(--raise)); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; border-radius: var(--r-card); min-height: 7rem; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---- Toasts -------------------------------------------------------------- */
.toasts { position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: .5rem; width: min(26rem, calc(100vw - 32px)); pointer-events: none; }
.toast {
  padding: .7rem 1rem; border-radius: var(--r-ctl);
  background: var(--fg); color: var(--bg); box-shadow: var(--shadow-lg); font-size: .92rem;
  animation: toast-in .3s var(--spring) both;
}
.toast.bad { background: var(--bad); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px) scale(.96); } }

/* ---- Login --------------------------------------------------------------- */
.auth { min-height: calc(100vh - 6rem); display: grid; place-items: center; }
.auth-card { width: 100%; max-width: 26rem; padding: 2rem 1.5rem; }
.auth-hero { text-align: center; margin-bottom: 1.5rem; }
.auth-hero .brand-mark { width: 52px; height: 52px; border-radius: 14px; margin: 0 auto 1rem; }
.auth-hero .brand-mark svg { width: 28px; height: 28px; }
.auth-hero p { margin-top: .4rem; color: var(--muted); }
.atoms { display: flex; justify-content: center; gap: .35rem; margin-top: .9rem; }
.atoms span { width: 8px; height: 8px; border-radius: 50%; background: var(--t); }
.tabs { display: grid; grid-template-columns: 1fr 1fr; padding: 4px; background: var(--raise); border-radius: 10px; margin-bottom: 1.25rem; }
.tabs button {
  font: inherit; font-weight: 600; font-size: .92rem; padding: .5rem; border: 0; border-radius: var(--r-ctl);
  background: transparent; color: var(--muted); cursor: pointer; transition: background-color .2s, color .2s, box-shadow .2s;
}
.tabs button[aria-selected="true"] { background: var(--card); color: var(--fg); box-shadow: var(--shadow); }
.auth form { display: flex; flex-direction: column; gap: 1rem; }

/* ---- Dashboard ----------------------------------------------------------- */
.hello { display: flex; align-items: center; justify-content: space-between; gap: 1.25rem; flex-wrap: wrap; }
.hello p { margin-top: .35rem; }
.kpis { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr)); margin-top: 1.5rem; }
.kpi { display: flex; align-items: center; gap: 1rem; }
.kpi-val { font-size: 1.6rem; font-weight: 750; letter-spacing: -.02em; line-height: 1.1; }
.kpi .kpi-ico { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; font-size: 1.3rem; background: color-mix(in srgb, var(--t) 13%, transparent); color: var(--t); flex: none; }

.test-card { display: flex; flex-direction: column; gap: .9rem; position: relative; overflow: hidden; transition: transform .2s var(--ease), box-shadow .2s; }
.test-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.test-card .meta { display: flex; gap: .5rem 1rem; flex-wrap: wrap; font-size: .85rem; color: var(--muted); }
.mixbar { display: flex; height: 8px; border-radius: 99px; overflow: hidden; background: var(--raise); gap: 2px; }
.mixbar span { background: var(--t); min-width: 3px; }
.legend { display: flex; flex-wrap: wrap; gap: .3rem .75rem; font-size: .78rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: .3rem; }
.legend span::before { content: ""; width: .5rem; height: .5rem; border-radius: 2px; background: var(--t); }
.test-card .actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: auto; }
.test-card .actions .btn { flex: 1; }
.resume-tag { position: absolute; top: 1rem; right: 1rem; }

.topics { display: flex; flex-direction: column; gap: .25rem; }
.topic-row {
  display: grid; grid-template-columns: minmax(7rem, 10rem) 1fr auto; align-items: center; gap: 1rem;
  padding: .7rem .5rem; border-radius: var(--r-ctl);
}
.topic-row:hover { background: var(--raise); }
.topic-row .name { display: flex; flex-direction: column; min-width: 0; }
.topic-row .name strong { font-weight: 650; }
.bar { position: relative; height: 10px; border-radius: 99px; background: color-mix(in srgb, var(--t) 12%, var(--raise)); overflow: hidden; }
.bar > span { position: absolute; inset: 0 auto 0 0; border-radius: inherit; background: var(--t); transform-origin: left; animation: bar-in .9s var(--ease) both; }
@keyframes bar-in { from { transform: scaleX(0); } }
.bar-label { font-size: .8rem; color: var(--muted); margin-top: .25rem; }
.topic-row .acts { display: flex; gap: .4rem; }
@media (max-width: 560px) {
  .topic-row { grid-template-columns: 1fr auto; }
  .topic-row .barwrap { grid-column: 1 / -1; grid-row: 2; }
}

.results-list { display: flex; flex-direction: column; }
.result-row { display: grid; grid-template-columns: 1fr auto; gap: .25rem 1rem; padding: .8rem 0; border-top: 1px solid var(--line); align-items: center; }
.result-row:first-child { border-top: 0; }
.result-row .score { font-weight: 750; font-variant-numeric: tabular-nums; text-align: right; }

/* ---- Progress ring & bar ------------------------------------------------- */
.ring { position: relative; display: inline-grid; place-items: center; flex: none; }
.ring svg { transform: rotate(-90deg); display: block; }
.ring .track { stroke: color-mix(in srgb, var(--t) 14%, var(--raise)); }
.ring .fill { stroke: var(--t); stroke-linecap: round; transition: stroke-dashoffset 1s var(--ease); }
.ring .ring-label { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; line-height: 1.1; }
.ring .ring-label strong { font-size: 1.05em; font-weight: 750; font-variant-numeric: tabular-nums; }

.progress { height: 6px; border-radius: 99px; background: var(--raise); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--t); border-radius: inherit; transition: width .4s var(--ease); }

/* ---- Question / quiz ----------------------------------------------------- */
.quiz-top { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.quiz-top .progress { flex: 1; }
.qcard { padding: 1.5rem; border-top: 4px solid var(--t); }
.qhead { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.qprompt { font-size: 1.15rem; line-height: 1.55; font-weight: 500; overflow-wrap: anywhere; }
.qprompt .katex-display, .choice-text .katex-display { margin: .5em 0; overflow-x: auto; overflow-y: hidden; }
.qimg { display: block; margin: 1rem auto 0; max-height: 22rem; border-radius: var(--r-ctl); border: 1px solid var(--line); background: #fff; }
.choices { display: flex; flex-direction: column; gap: .6rem; margin-top: 1.4rem; }
.choice {
  display: flex; align-items: center; gap: .85rem; width: 100%; text-align: left;
  padding: .7rem .9rem; min-height: 52px;
  font: inherit; color: var(--fg); background: var(--card);
  border: 1.5px solid var(--line); border-radius: 10px; cursor: pointer;
  transition: border-color .15s, background-color .15s, transform .12s var(--ease), box-shadow .15s;
}
.choice:hover:not(:disabled) { border-color: color-mix(in srgb, var(--t) 60%, var(--line)); background: color-mix(in srgb, var(--t) 5%, var(--card)); }
.choice:active:not(:disabled) { transform: scale(.99); }
.choice:disabled { cursor: default; }
.bubble {
  display: grid; place-items: center; flex: none;
  width: 32px; height: 32px; border-radius: 50%;
  font-weight: 700; font-size: .9rem;
  border: 1.5px solid var(--line); color: var(--muted); background: var(--bg);
  transition: all .2s var(--ease);
}
.choice-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.choice.selected { border-color: var(--t); background: color-mix(in srgb, var(--t) 9%, var(--card)); }
.choice.selected .bubble { background: var(--t); border-color: var(--t); color: #fff; transform: scale(1.06); }
.choice.correct { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 11%, var(--card)); }
.choice.correct .bubble { background: var(--ok); border-color: var(--ok); color: #fff; }
.choice.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 10%, var(--card)); }
.choice.wrong .bubble { background: var(--bad); border-color: var(--bad); color: #fff; }
.choice.dim { opacity: .55; }
.choice.correct.pop .bubble { animation: pop .45s var(--spring); }
.choice.wrong.shake { animation: shake .4s var(--ease); }
@keyframes pop { 0% { transform: scale(.6); } 60% { transform: scale(1.25); } 100% { transform: scale(1); } }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
.qcard.flash-ok { animation: glow-ok .8s var(--ease); }
.qcard.flash-bad { animation: glow-bad .8s var(--ease); }
@keyframes glow-ok { 30% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 35%, transparent), var(--shadow); } }
@keyframes glow-bad { 30% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--bad) 30%, transparent), var(--shadow); } }

.feedback {
  margin-top: 1.25rem; padding: 1rem 1.1rem; border-radius: 10px;
  border-left: 4px solid var(--fb); background: color-mix(in srgb, var(--fb) 9%, transparent);
  animation: view-in .35s var(--ease) both;
}
.feedback.ok { --fb: var(--ok); }
.feedback.bad { --fb: var(--bad); }
.feedback .fb-title { display: flex; align-items: center; gap: .5rem; font-weight: 750; color: var(--fb); }
.feedback .fb-body { margin-top: .4rem; line-height: 1.55; overflow-wrap: anywhere; }
.solved-note { margin: .6rem 0 0; font-size: .8rem; font-style: italic; color: var(--muted); }
.quiz-foot { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; margin-top: 1.25rem; }
.keys { display: flex; gap: .75rem; flex-wrap: wrap; font-size: .8rem; color: var(--muted); }
.keys span { display: inline-flex; align-items: center; gap: .3rem; }
@media (max-width: 560px) { .keys { display: none; } }
.streak { font-weight: 700; color: var(--warn); }

/* ---- Timed test ---------------------------------------------------------- */
.test-layout { display: grid; gap: 1.25rem; grid-template-columns: 1fr; }
@media (min-width: 860px) { .test-layout { grid-template-columns: minmax(0, 1fr) 17rem; align-items: start; } .test-side { position: sticky; top: 4.5rem; } }
.test-bar { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.test-bar h2 { overflow-wrap: anywhere; }
.timer {
  display: inline-flex; align-items: center; gap: .45rem;
  padding: .4rem .85rem; border-radius: 99px;
  font: 700 1.05rem/1 ui-monospace, SFMono-Regular, Menlo, monospace; font-variant-numeric: tabular-nums;
  background: var(--raise); color: var(--fg); border: 1px solid var(--line);
}
.timer.low { color: var(--warn); border-color: var(--warn); background: color-mix(in srgb, var(--warn) 10%, transparent); }
.timer.crit { color: var(--bad); border-color: var(--bad); background: color-mix(in srgb, var(--bad) 10%, transparent); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.navgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(36px, 1fr)); gap: 6px; margin-top: .75rem; }
.navcell {
  position: relative; aspect-ratio: 1; min-width: 0; padding: 0;
  font: 600 .82rem/1 inherit; font-family: inherit; font-variant-numeric: tabular-nums;
  color: var(--muted); background: var(--bg); border: 1.5px solid var(--line); border-radius: var(--r-ctl);
  cursor: pointer; transition: all .15s var(--ease);
}
.navcell:hover { border-color: var(--accent); color: var(--fg); }
.navcell.answered { background: color-mix(in srgb, var(--accent) 38%, var(--card)); color: var(--fg); font-weight: 600; border-color: color-mix(in srgb, var(--accent) 70%, var(--line)); }
.navcell.current { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent); color: var(--fg); }
.navcell.flagged::after { content: ""; position: absolute; top: 3px; right: 3px; width: 6px; height: 6px; border-radius: 50%; background: var(--warn); }
.nav-legend { display: flex; gap: .4rem .9rem; flex-wrap: wrap; font-size: .75rem; color: var(--muted); margin-top: .75rem; }
.nav-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: .3rem; vertical-align: -1px; border: 1.5px solid var(--line); }
.nav-legend i.a { background: color-mix(in srgb, var(--accent) 16%, var(--card)); border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.nav-legend i.f { background: var(--warn); border-color: var(--warn); border-radius: 50%; }
.flag-btn[aria-pressed="true"] { color: var(--warn); border-color: var(--warn); background: color-mix(in srgb, var(--warn) 10%, transparent); }
.intro { text-align: center; padding: 2.5rem 1.5rem; }
.intro .facts { display: flex; justify-content: center; gap: 1rem; flex-wrap: wrap; margin: 1.5rem 0; }
.intro .fact { min-width: 7rem; padding: .9rem 1rem; border-radius: 10px; background: var(--raise); }
.intro .fact strong { display: block; font-size: 1.35rem; font-variant-numeric: tabular-nums; }

/* ---- Results ------------------------------------------------------------- */
.score-hero { display: flex; align-items: center; gap: 2rem; flex-wrap: wrap; justify-content: center; text-align: left; }
.score-hero .facts { display: grid; grid-template-columns: repeat(3, minmax(5rem, 1fr)); gap: .75rem; }
.stat { padding: .75rem 1rem; border-radius: 10px; background: var(--raise); text-align: center; }
.stat strong { display: block; font-size: 1.4rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.stat.ok strong { color: var(--ok); }
.stat.bad strong { color: var(--bad); }
.filters { display: flex; gap: .4rem; flex-wrap: wrap; }
.filters button[aria-pressed="true"] { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.review-item { padding: 1rem 0; border-top: 1px solid var(--line); }
.review-item:first-child { border-top: 0; }
.review-item .rhead { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: .5rem; }
.mark { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; color: #fff; font-size: .8rem; font-weight: 800; flex: none; }
.mark.ok { background: var(--ok); }
.mark.bad { background: var(--bad); }
.mark.blank { background: var(--muted); }
.review-item .ans { display: flex; flex-direction: column; gap: .3rem; margin-top: .6rem; font-size: .93rem; }
.review-item .ans .ok { color: var(--ok); }
.review-item .ans .bad { color: var(--bad); }
.review-item .explain { margin-top: .6rem; padding: .7rem .9rem; border-radius: var(--r-ctl); background: var(--raise); font-size: .93rem; overflow-wrap: anywhere; }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 40; overflow: hidden; }
.confetti i { position: absolute; top: -12px; width: 8px; height: 12px; border-radius: 2px; animation: fall 1.8s var(--ease) forwards; }
@keyframes fall { to { transform: translateY(105vh) rotate(540deg); opacity: .3; } }

/* ---- Flashcards ---------------------------------------------------------- */
.flash-wrap { perspective: 1400px; margin-top: .5rem; }
.flashcard {
  position: relative; width: 100%; min-height: 22rem;
  display: grid; cursor: pointer;
  transform-style: preserve-3d; transition: transform .6s var(--ease);
  border-radius: 16px; outline: none;
}
.flashcard.flipped { transform: rotateY(180deg); }
.flashcard:focus-visible .face { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 45%, transparent), var(--shadow-lg); }
.face {
  grid-area: 1 / 1; display: flex; flex-direction: column;
  padding: 1.75rem 1.5rem; border-radius: 16px;
  background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow-lg);
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  min-width: 0; overflow: hidden;
}
.face.front { border-top: 5px solid var(--t); }
.face.back { transform: rotateY(180deg); border-top: 5px solid var(--ok); }
.face .face-body { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 1rem; padding: 1rem 0; }
.face .qprompt { font-size: clamp(1.1rem, 2.6vw, 1.35rem); text-align: center; }
.face .flist { display: grid; gap: .35rem; font-size: .92rem; color: var(--muted); max-width: 32rem; margin: 0 auto; width: 100%; }
.face .flist div { display: flex; gap: .5rem; }
.face .flist b { color: var(--fg); }
.face .answer-big { display: flex; align-items: center; gap: .9rem; justify-content: center; font-size: clamp(1.15rem, 3vw, 1.5rem); font-weight: 700; text-align: left; }
.face .answer-big .bubble { width: 40px; height: 40px; font-size: 1.1rem; background: var(--ok); border-color: var(--ok); color: #fff; }
.face .explain { color: var(--muted); line-height: 1.6; text-align: center; max-width: 34rem; margin: 0 auto; overflow-wrap: anywhere; }
.face .hint-flip { text-align: center; font-size: .8rem; color: var(--muted); }
.flash-ctrls { display: flex; align-items: center; justify-content: center; gap: .75rem; margin-top: 1.25rem; flex-wrap: wrap; }
.flash-ctrls .btn { min-width: 9rem; }
.flash-nav { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-top: 1rem; }
.flash-count { display: flex; gap: 1rem; font-size: .88rem; font-variant-numeric: tabular-nums; }
.flash-count .ok { color: var(--ok); font-weight: 700; }
.flash-count .bad { color: var(--warn); font-weight: 700; }
.flashcard.swipe-l { animation: swipe-l .35s var(--ease); }
.flashcard.swipe-r { animation: swipe-r .35s var(--ease); }
@keyframes swipe-l { from { opacity: 0; transform: translateX(40px); } }
@keyframes swipe-r { from { opacity: 0; transform: translateX(-40px); } }
.done-card { text-align: center; padding: 2.5rem 1.5rem; }
.done-card .big-emoji { font-size: 3rem; line-height: 1; margin-bottom: 1rem; }
.done-card .row { justify-content: center; margin-top: 1.5rem; }

/* ---- Modal --------------------------------------------------------------- */
.modal-back { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: var(--gutter); background: rgb(10 12 16 / .5); animation: fade .2s both; }
.modal { width: 100%; max-width: 26rem; padding: 1.5rem; animation: toast-in .3s var(--spring) both; }
.modal p { margin-top: .5rem; color: var(--muted); }
.modal .row { justify-content: flex-end; margin-top: 1.5rem; }
@keyframes fade { from { opacity: 0; } }

/* ---- Phone tweaks -------------------------------------------------------- */
@media (max-width: 560px) {
  main { padding-top: 1rem; }
  .card { padding: 1rem; }
  .qcard { padding: 1.1rem; }
  .qprompt { font-size: 1.05rem; }
  .face { padding: 1.25rem 1rem; }
  .flashcard { min-height: 20rem; }
  .flash-ctrls .btn { min-width: 0; flex: 1; }
  .score-hero { gap: 1.25rem; }
  .score-hero .facts { width: 100%; }
}

/* ---- Reduced motion ------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
  /* Swap faces instead of rotating in 3D. */
  .flashcard, .flashcard.flipped { transform: none; }
  .face.back { transform: none; visibility: hidden; }
  .flashcard.flipped .face.back { visibility: visible; }
  .flashcard.flipped .face.front { visibility: hidden; }
  .confetti { display: none; }
  .timer.crit { animation: none; }
}

/* ---- Nav, admin, account ------------------------------------------------- */
.navlink { color: var(--muted); font-size: .9rem; font-weight: 600; padding: .35rem .6rem; border-radius: var(--r-ctl); }
.navlink:hover { color: var(--fg); background: var(--raise); text-decoration: none; }
.navlink[aria-current="page"] { color: var(--fg); background: var(--raise); }
.danger-text { color: var(--bad); }
.danger-text:hover:not(:disabled) { border-color: var(--bad); }
.joincode { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.code-big {
  font: 700 clamp(1.1rem, 4vw, 1.5rem)/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .04em;
  padding: .6rem 1rem; border-radius: var(--r-ctl); border: 1.5px dashed var(--line); background: var(--raise);
  overflow-wrap: anywhere; user-select: all; min-width: 0;
}
.table-wrap { overflow-x: auto; margin: -.25rem; padding: .25rem; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; font-size: .72rem; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: .5rem .75rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: .75rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: color-mix(in srgb, var(--raise) 60%, transparent); }
.user-cell { display: flex; flex-direction: column; min-width: 8rem; }
.switch { position: relative; display: inline-flex; cursor: pointer; }
.switch-input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch-track { width: 40px; height: 24px; border-radius: 99px; background: var(--line); position: relative; transition: background-color .2s var(--ease); }
.switch-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / .25); transition: transform .2s var(--spring); }
.switch-input:checked + .switch-track { background: var(--accent); }
.switch-input:checked + .switch-track::after { transform: translateX(16px); }
.switch-input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch-input:disabled { cursor: not-allowed; }
.switch-input:disabled + .switch-track { opacity: .45; }
@media (max-width: 480px) { #admin-link { padding: .35rem .45rem; } }
