/* ===== Tokens ===== */
:root {
  --ink: #0C0E2A;
  --ink-2: #16134A;
  --nebula: #3B1F7E;
  --star: #F3F1FF;
  --muted: #A9A6D6;
  --line: rgba(243, 241, 255, .12);
  --glass: rgba(255, 255, 255, .055);
  --glass-hi: rgba(255, 255, 255, .1);
  --good: #35E08A;
  --bad: #FF5A76;
  --key: #FFC542;
  --accent: #7C8CFF;
  --radius-lg: 28px;
  --radius: 18px;
  --radius-sm: 12px;
  --display: "Unbounded", system-ui, sans-serif;
  --body: "Manrope", system-ui, sans-serif;
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: radial-gradient(120% 80% at 50% 0%, var(--ink-2) 0%, var(--ink) 60%) fixed, var(--ink);
  color: var(--star);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--key); outline-offset: 3px; border-radius: 10px; }

#stars { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; }
.nebula {
  position: fixed; inset: -20%; z-index: 0; pointer-events: none;
  background:
    radial-gradient(40% 30% at 15% 20%, rgba(124, 140, 255, .22), transparent 70%),
    radial-gradient(35% 30% at 85% 75%, rgba(255, 111, 165, .16), transparent 70%),
    radial-gradient(30% 25% at 70% 15%, rgba(79, 209, 255, .14), transparent 70%);
  filter: blur(10px);
  animation: drift 40s ease-in-out infinite alternate;
}
@keyframes drift { to { transform: translate3d(3%, -2%, 0) rotate(4deg); } }

/* ===== Top bar ===== */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  background: linear-gradient(to bottom, rgba(12, 14, 42, .9), rgba(12, 14, 42, 0));
  backdrop-filter: blur(6px);
}
.icon-btn {
  display: grid; place-items: center; width: 42px; height: 42px; flex: none;
  border-radius: 14px; border: 1px solid var(--line); background: var(--glass);
  transition: transform .2s var(--ease-spring), background .2s;
}
.icon-btn:hover { background: var(--glass-hi); }
.icon-btn:active { transform: scale(.9); }
.crumbs { flex: 1; min-width: 0; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crumbs b { color: var(--star); font-weight: 700; }
.brand { font-family: var(--display); font-weight: 800; font-size: 14px; text-decoration: none; letter-spacing: .02em; color: var(--accent); }

/* ===== Stage and screens ===== */
#stage { position: relative; z-index: 1; perspective: 1400px; min-height: calc(100dvh - 70px); }
.screen {
  width: 100%; max-width: 760px; margin: 0 auto;
  padding: 8px 16px calc(40px + env(safe-area-inset-bottom));
  transform-origin: 50% 30%;
}
.screen.enter { animation: screenIn .7s var(--ease-out) both; }
.screen.enter.back { animation-name: screenInBack; }
.screen.leave { position: absolute; inset: 0 0 auto 0; left: 0; right: 0; pointer-events: none; animation: screenOut .45s ease-in both; }
.screen.leave.back { animation-name: screenOutBack; }
@keyframes screenIn { from { opacity: 0; transform: translate3d(60px, 0, -260px) rotateY(-18deg); } }
@keyframes screenInBack { from { opacity: 0; transform: translate3d(-60px, 0, -260px) rotateY(18deg); } }
@keyframes screenOut { to { opacity: 0; transform: translate3d(-80px, 0, -300px) rotateY(16deg); } }
@keyframes screenOutBack { to { opacity: 0; transform: translate3d(80px, 0, -300px) rotateY(-16deg); } }

.screen-head { margin: 18px 0 26px; }
.screen-head h1 {
  font-family: var(--display); font-weight: 800; letter-spacing: -.01em;
  font-size: clamp(28px, 7vw, 44px); line-height: 1.08; margin: 0 0 10px;
}
.screen-head p { margin: 0; color: var(--muted); max-width: 52ch; }

/* ===== Planets ===== */
.planet {
  --c: var(--accent);
  --size: 120px;
  position: relative; width: var(--size); height: var(--size); flex: none;
  display: grid; place-items: center;
}
.planet .body {
  position: absolute; inset: 0; border-radius: 50%; z-index: 1;
  background:
    radial-gradient(circle at 32% 28%, rgba(255,255,255,.95) 0 4%, transparent 22%),
    radial-gradient(circle at 35% 32%, color-mix(in srgb, var(--c) 70%, white) 0%, var(--c) 32%, color-mix(in srgb, var(--c) 45%, #0b0630) 72%, #05031a 100%);
  box-shadow:
    inset calc(var(--size) * -.1) calc(var(--size) * -.12) calc(var(--size) * .22) rgba(5, 3, 26, .7),
    0 0 calc(var(--size) * .35) color-mix(in srgb, var(--c) 45%, transparent);
  overflow: hidden;
}
.planet .body::after { /* surface bands that rotate, so the planet reads as spinning */
  content: ""; position: absolute; inset: -10% -100%;
  background: repeating-linear-gradient(-12deg, transparent 0 14%, rgba(255,255,255,.07) 14% 18%, transparent 18% 30%, rgba(5,3,26,.12) 30% 36%);
  animation: spinSurface 14s linear infinite;
  mix-blend-mode: overlay;
}
@keyframes spinSurface { to { transform: translateX(50%); } }
.planet .ring {
  position: absolute; left: -32%; right: -32%; top: 38%; bottom: 38%;
  border-radius: 50%;
  border: calc(var(--size) * .035) solid color-mix(in srgb, var(--c) 55%, white);
  box-shadow: 0 0 12px color-mix(in srgb, var(--c) 50%, transparent);
  transform: rotate(-16deg);
  opacity: .85;
}
.planet .ring.back { z-index: 0; }
.planet .ring.front { z-index: 2; clip-path: inset(50% 0 0 0); }
.planet .moon {
  position: absolute; z-index: 3; width: 12%; height: 12%; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff, #b9b4e6 60%, #4b4680);
  left: 50%; top: 50%;
  animation: orbit 6s linear infinite;
}
@keyframes orbit {
  0%   { transform: translate(-50%, -50%) rotate(0deg)   translateX(calc(var(--size) * .78)) rotate(0deg) scale(1); z-index: 3; }
  50%  { transform: translate(-50%, -50%) rotate(180deg) translateX(calc(var(--size) * .78)) rotate(-180deg) scale(.7); }
  100% { transform: translate(-50%, -50%) rotate(360deg) translateX(calc(var(--size) * .78)) rotate(-360deg) scale(1); }
}
.planet .glyph { position: relative; z-index: 2; width: 46%; height: 46%; color: rgba(255,255,255,.95); filter: drop-shadow(0 2px 6px rgba(5,3,26,.6)); display: grid; place-items: center; }
.planet .glyph svg { width: 100%; height: 100%; }
.planet .glyph .t { font-family: var(--display); font-weight: 800; font-size: calc(var(--size) * .3); line-height: 1; }
.planet .glyph .t.sd { font-family: "Noto Naskh Arabic", "Segoe UI", serif; font-size: calc(var(--size) * .38); }

/* ===== Splash ===== */
.splash {
  min-height: 100dvh; display: grid; place-items: center; text-align: center;
  padding: 24px 16px; cursor: pointer; position: relative;
}
.splash .stack { display: grid; justify-items: center; gap: 26px; perspective: 900px; }
.splash .planet { --size: min(42vw, 190px); --c: #7C8CFF; animation: planetBirth 1.6s var(--ease-spring) both; }
@keyframes planetBirth {
  0% { transform: scale(0) rotate(-120deg); opacity: 0; filter: blur(12px); }
  60% { opacity: 1; filter: blur(0); }
  100% { transform: scale(1) rotate(0); }
}
.splash .hello { font-family: var(--body); font-weight: 600; color: var(--muted); font-size: clamp(16px, 4.4vw, 20px); margin: 0; opacity: 0; animation: fadeUp .8s .9s var(--ease-out) forwards; }
.splash h1 {
  margin: 0; font-family: var(--display); font-weight: 800;
  font-size: clamp(40px, 12vw, 92px); line-height: 1; letter-spacing: -.02em;
  display: flex; gap: .02em; justify-content: center; flex-wrap: wrap;
  transform-style: preserve-3d;
}
.splash h1 .ch {
  display: inline-block;
  background: linear-gradient(180deg, #fff 10%, #b9c2ff 55%, #7C8CFF 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  opacity: 0; transform-origin: 50% 100%;
  animation: letterIn .9s var(--ease-spring) forwards;
  animation-delay: calc(1.15s + var(--i) * 70ms);
  text-shadow: 0 0 0 transparent;
}
.splash h1 .sp { width: .3em; }
@keyframes letterIn {
  0% { opacity: 0; transform: translate3d(0, -60px, 200px) rotateX(-95deg) scale(1.4); }
  100% { opacity: 1; transform: none; }
}
.splash .tag { margin: 0; color: var(--muted); max-width: 32ch; opacity: 0; animation: fadeUp .8s 2.1s var(--ease-out) forwards; }
.splash .skip { position: absolute; bottom: calc(24px + env(safe-area-inset-bottom)); left: 0; right: 0; font-size: 13px; color: var(--muted); opacity: 0; animation: fadeUp .6s 2.6s forwards, pulse 2s 3.2s ease-in-out infinite; }
.splash.out { animation: splashOut .8s ease-in forwards; }
@keyframes splashOut { to { opacity: 0; transform: scale(1.6); filter: blur(8px); } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 50% { opacity: .35; } }

/* ===== Tilt cards (classes, subjects, modes) ===== */
.tilt {
  --rx: 0deg; --ry: 0deg;
  transform: perspective(900px) rotateX(var(--rx)) rotateY(var(--ry));
  transition: transform .25s ease-out, box-shadow .3s, border-color .3s;
  transform-style: preserve-3d;
}
.tilt > * { transform: translateZ(0); }
.tilt .pop { transform: translateZ(40px); }

.class-card {
  --c: var(--accent);
  display: flex; align-items: center; gap: 22px; width: 100%; text-align: left;
  padding: 26px 24px; border-radius: var(--radius-lg);
  border: 1px solid color-mix(in srgb, var(--c) 40%, transparent);
  background:
    radial-gradient(120% 140% at 0% 0%, color-mix(in srgb, var(--c) 22%, transparent), transparent 60%),
    var(--glass);
  box-shadow: 0 30px 60px -30px color-mix(in srgb, var(--c) 60%, transparent);
  animation: rise .8s var(--ease-out) both;
}
.class-card .planet { --size: 96px; --c: var(--c); }
.class-card h2 { font-family: var(--display); font-weight: 800; font-size: clamp(26px, 7vw, 36px); margin: 0; line-height: 1.1; }
.class-card .meta { color: var(--muted); margin: 6px 0 0; font-size: 15px; }
.class-card .go { margin-top: 14px; display: inline-flex; align-items: center; gap: 8px; font-weight: 700; color: var(--c); }
@keyframes rise { from { opacity: 0; transform: translateY(40px) scale(.96); } }

.subjects { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.subject {
  --c: var(--accent);
  position: relative; display: grid; justify-items: center; gap: 14px;
  padding: 24px 12px 18px; border-radius: var(--radius-lg);
  border: 1px solid var(--line); background: var(--glass);
  animation: rise .7s var(--ease-out) both; animation-delay: calc(var(--i) * 60ms);
}
.subject .planet { --size: 82px; }
.subject .name { font-weight: 700; font-size: 16px; text-align: center; line-height: 1.25; }
.subject .state { font-size: 12px; color: var(--muted); }
.subject.open { border-color: color-mix(in srgb, var(--c) 55%, transparent); box-shadow: 0 24px 50px -28px var(--c); }
.subject.open .state { color: var(--c); font-weight: 700; }
.subject.locked { filter: grayscale(1); opacity: .42; cursor: not-allowed; }
.subject.locked .planet .body::after, .subject.locked .moon { animation: none; }
.subject .lock { position: absolute; top: 12px; right: 12px; width: 26px; height: 26px; display: grid; place-items: center; border-radius: 50%; background: rgba(0,0,0,.35); }
.subject.shake { animation: shake .45s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px) rotate(-2deg); } 40%, 80% { transform: translateX(8px) rotate(2deg); } }

/* ===== Modes ===== */
.modes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.mode {
  --c: var(--accent);
  position: relative; overflow: hidden; text-align: left;
  display: grid; align-content: start; gap: 8px;
  padding: 20px 18px; min-height: 172px; border-radius: var(--radius-lg);
  border: 1px solid color-mix(in srgb, var(--c) 35%, transparent);
  background: radial-gradient(140% 120% at 100% 0%, color-mix(in srgb, var(--c) 26%, transparent), transparent 55%), var(--glass);
  animation: rise .7s var(--ease-out) both; animation-delay: calc(var(--i) * 70ms);
}
.mode .ico { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; background: color-mix(in srgb, var(--c) 22%, transparent); color: var(--c); }
.mode h3 { margin: 6px 0 0; font-family: var(--display); font-weight: 700; font-size: 18px; line-height: 1.2; }
.mode p { margin: 0; color: var(--muted); font-size: 14px; }
.mode .count { margin-top: auto; padding-top: 8px; font-size: 13px; font-weight: 700; color: var(--c); }
.mode.mix .ico, .mode.mix h3, .mode.mix p { position: relative; }
.mode.mix .orbit-dots { position: absolute; right: -60px; top: 50%; width: 150px; height: 150px; opacity: .7; transform: translateY(-50%); border-radius: 50%; border: 1px dashed color-mix(in srgb, var(--c) 45%, transparent); animation: spin 18s linear infinite; }
.mode.mix .orbit-dots i { position: absolute; width: 14px; height: 14px; border-radius: 50%; }
.mode.mix .orbit-dots i:nth-child(1) { top: -7px; left: calc(50% - 7px); background: #4FD1FF; box-shadow: 0 0 12px #4FD1FF; }
.mode.mix .orbit-dots i:nth-child(2) { bottom: 18px; left: 6px; background: #C792FF; box-shadow: 0 0 12px #C792FF; }
.mode.mix .orbit-dots i:nth-child(3) { bottom: 18px; right: 6px; background: #FFC542; box-shadow: 0 0 12px #FFC542; }
@keyframes spin { to { transform: translateY(-50%) rotate(360deg); } }
.best { font-size: 12px; color: var(--muted); }

/* ===== Setup (chapters, count) ===== */
.panel { border: 1px solid var(--line); background: var(--glass); border-radius: var(--radius-lg); padding: 18px; margin-bottom: 16px; animation: rise .6s var(--ease-out) both; }
.panel h2 { font-family: var(--display); font-weight: 700; font-size: 17px; margin: 0 0 4px; }
.panel .hint { margin: 0 0 14px; color: var(--muted); font-size: 14px; }
.range-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin-bottom: 14px; font-size: 14px; color: var(--muted); }
.range-row select {
  font: inherit; font-weight: 700; color: var(--star); background: var(--ink-2);
  border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px;
}
.chip-btn {
  border: 1px solid var(--line); background: var(--glass); border-radius: 999px; padding: 8px 14px; font-size: 14px; font-weight: 700;
  transition: background .2s, border-color .2s, transform .2s var(--ease-spring);
}
.chip-btn:hover { background: var(--glass-hi); }
.chip-btn:active { transform: scale(.94); }
.units { display: grid; gap: 8px; }
.unit {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px;
  padding: 12px 14px; border-radius: var(--radius); border: 1px solid var(--line); background: rgba(255,255,255,.03);
  cursor: pointer; user-select: none; transition: border-color .2s, background .2s, transform .25s var(--ease-spring);
}
.unit:hover { background: rgba(255,255,255,.06); }
.unit input { position: absolute; opacity: 0; pointer-events: none; }
.unit .box { width: 26px; height: 26px; border-radius: 9px; border: 2px solid var(--muted); display: grid; place-items: center; transition: background .2s, border-color .2s, transform .3s var(--ease-spring); }
.unit .box svg { opacity: 0; transform: scale(.3) rotate(-30deg); transition: all .3s var(--ease-spring); }
.unit.on { border-color: color-mix(in srgb, var(--accent) 60%, transparent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.unit.on .box { background: var(--accent); border-color: var(--accent); transform: rotate(-6deg); }
.unit.on .box svg { opacity: 1; transform: none; }
.unit:has(input:focus-visible) { outline: 3px solid var(--key); outline-offset: 2px; }
.unit .u-no { font-size: 12px; color: var(--muted); font-weight: 700; }
.unit .u-title { font-weight: 700; line-height: 1.25; }
.unit .u-count { font-size: 13px; color: var(--muted); font-weight: 700; white-space: nowrap; }
.unit.empty { opacity: .45; }

.counts { display: flex; flex-wrap: wrap; gap: 10px; }
.count-chip {
  min-width: 64px; padding: 12px 16px; border-radius: 16px; font-weight: 800; font-family: var(--display); font-size: 16px;
  border: 1px solid var(--line); background: rgba(255,255,255,.04);
  transition: transform .3s var(--ease-spring), background .2s, border-color .2s;
}
.count-chip.on { background: var(--accent); color: var(--ink); border-color: var(--accent); transform: translateY(-3px) scale(1.06); box-shadow: 0 12px 24px -10px var(--accent); }
.count-chip:disabled { opacity: .35; cursor: not-allowed; }
.other-input { display: none; margin-top: 12px; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; }
.other-input.show { display: flex; }
.other-input input { width: 110px; font: inherit; font-weight: 800; font-size: 18px; color: var(--star); background: var(--ink-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }

.toggle { display: flex; align-items: center; justify-content: space-between; gap: 14px; cursor: pointer; }
.toggle .t-text b { display: block; font-weight: 700; }
.toggle .t-text span { color: var(--muted); font-size: 14px; }
.toggle input { position: absolute; opacity: 0; }
.toggle .sw { width: 52px; height: 30px; flex: none; border-radius: 999px; background: rgba(255,255,255,.14); position: relative; transition: background .25s; }
.toggle .sw::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .35s var(--ease-spring); }
.toggle input:checked + .sw { background: var(--accent); }
.toggle input:checked + .sw::after { transform: translateX(22px); }
.toggle:has(input:focus-visible) .sw { outline: 3px solid var(--key); outline-offset: 2px; }

.cta-bar { position: sticky; bottom: 0; padding: 14px 0 calc(6px + env(safe-area-inset-bottom)); background: linear-gradient(to top, var(--ink) 55%, transparent); z-index: 5; }
.btn {
  --c: var(--accent);
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  padding: 16px 22px; border: 0; border-radius: 18px; font-weight: 800; font-size: 17px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--c) 85%, white), var(--c));
  color: var(--ink);
  box-shadow: 0 16px 34px -14px var(--c), inset 0 -3px 0 rgba(0,0,0,.18);
  transition: transform .25s var(--ease-spring), box-shadow .25s, opacity .2s;
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(1px) scale(.97); }
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.btn.block { width: 100%; }
.btn.ghost { background: var(--glass); color: var(--star); border: 1px solid var(--line); box-shadow: none; }
.btn.small { padding: 11px 16px; font-size: 15px; border-radius: 14px; }

/* ===== Quiz ===== */
.quiz-top { display: grid; gap: 12px; margin: 6px 0 18px; }
.quiz-meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.qcount { font-family: var(--display); font-weight: 700; font-size: 15px; white-space: nowrap; }
.qcount span { color: var(--muted); font-weight: 500; }
.progress { height: 8px; border-radius: 999px; background: rgba(255,255,255,.1); overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--accent), #C792FF); box-shadow: 0 0 14px var(--accent); transition: width .6s var(--ease-out); }

.badges { display: flex; flex-wrap: wrap; gap: 8px; }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 800;
  background: color-mix(in srgb, var(--accent) 18%, transparent); color: color-mix(in srgb, var(--accent) 70%, white);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
}
.badge.year { background: rgba(255,197,66,.14); color: var(--key); border-color: rgba(255,197,66,.4); }
.badge.year.big { font-family: var(--display); font-size: 15px; padding: 8px 14px; }
.badge.src { background: rgba(255,255,255,.06); color: var(--muted); border-color: var(--line); }

.card-stage { position: relative; perspective: 1200px; min-height: 380px; }
.qcard {
  position: relative; padding: 24px 20px 20px; border-radius: var(--radius-lg);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--line));
  background:
    radial-gradient(120% 90% at 0% 0%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 55%),
    linear-gradient(180deg, rgba(255,255,255,.08), rgba(255,255,255,.035));
  box-shadow: 0 40px 80px -40px rgba(0,0,0,.8), 0 0 0 1px rgba(255,255,255,.03) inset;
  backdrop-filter: blur(8px);
  transform-style: preserve-3d;
}
.qcard .badges { margin-bottom: 16px; }
.qcard .q { font-size: clamp(18px, 4.6vw, 22px); font-weight: 700; line-height: 1.45; margin: 0 0 18px; }
.qcard .q-img { display: block; max-width: 100%; max-height: 220px; margin: 0 auto 18px; border-radius: 14px; background: #fff; padding: 6px; }
.options { display: grid; gap: 10px; }
.opt {
  display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 14px; text-align: left;
  width: 100%; padding: 14px 14px; border-radius: var(--radius);
  border: 1px solid var(--line); background: rgba(255,255,255,.04);
  font-size: 16px; font-weight: 600; line-height: 1.35;
  transition: transform .25s var(--ease-spring), background .2s, border-color .2s, box-shadow .25s;
  animation: optIn .5s var(--ease-out) both; animation-delay: calc(.15s + var(--i) * 60ms);
}
@keyframes optIn { from { opacity: 0; transform: translateY(16px) rotateX(-30deg); } }
.opt:hover { background: rgba(255,255,255,.08); transform: translateX(4px); }
.opt .key { width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; font-family: var(--display); font-weight: 700; font-size: 14px; background: rgba(255,255,255,.08); transition: background .2s, color .2s, transform .35s var(--ease-spring); }
.opt.picked { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, transparent); box-shadow: 0 0 0 1px var(--accent), 0 12px 30px -14px var(--accent); }
.opt.picked .key { background: var(--accent); color: var(--ink); transform: rotate(-8deg) scale(1.08); }

.quiz-nav { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 18px; }
.quiz-nav .spacer { flex: 1; }

/* card motion: enter from a random side, leave to the opposite */
.qcard.in-left   { animation: inLeft .6s var(--ease-out) both; }
.qcard.in-right  { animation: inRight .6s var(--ease-out) both; }
.qcard.in-up     { animation: inUp .6s var(--ease-out) both; }
.qcard.in-down   { animation: inDown .6s var(--ease-out) both; }
.qcard.out-left  { animation: outLeft .38s ease-in both; }
.qcard.out-right { animation: outRight .38s ease-in both; }
.qcard.out-up    { animation: outUp .38s ease-in both; }
.qcard.out-down  { animation: outDown .38s ease-in both; }
.qcard.leaving { position: absolute; top: 0; left: 0; right: 0; pointer-events: none; }
@keyframes inLeft  { from { opacity: 0; transform: translate3d(-110%, 0, -200px) rotateY(35deg); } }
@keyframes inRight { from { opacity: 0; transform: translate3d(110%, 0, -200px) rotateY(-35deg); } }
@keyframes inUp    { from { opacity: 0; transform: translate3d(0, -80%, -200px) rotateX(-40deg); } }
@keyframes inDown  { from { opacity: 0; transform: translate3d(0, 80%, -200px) rotateX(40deg); } }
@keyframes outLeft  { to { opacity: 0; transform: translate3d(-110%, 0, -200px) rotateY(35deg); } }
@keyframes outRight { to { opacity: 0; transform: translate3d(110%, 0, -200px) rotateY(-35deg); } }
@keyframes outUp    { to { opacity: 0; transform: translate3d(0, -70%, -200px) rotateX(-40deg); } }
@keyframes outDown  { to { opacity: 0; transform: translate3d(0, 70%, -200px) rotateX(40deg); } }

.dots { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 22px; justify-content: center; }
.dots button { width: 28px; height: 28px; border-radius: 9px; border: 1px solid var(--line); background: rgba(255,255,255,.04); font-size: 11px; font-weight: 800; color: var(--muted); padding: 0; }
.dots button.done { background: color-mix(in srgb, var(--accent) 30%, transparent); color: var(--star); border-color: transparent; }
.dots button.now { outline: 2px solid var(--accent); outline-offset: 1px; color: var(--star); }

/* ===== Results ===== */
.result-hero { display: grid; justify-items: center; text-align: center; gap: 12px; margin: 10px 0 28px; }
.ring-wrap { position: relative; width: min(68vw, 250px); aspect-ratio: 1; animation: ringPop 1s var(--ease-spring) both; }
@keyframes ringPop { from { transform: scale(.4) rotate(-90deg); opacity: 0; } }
.ring-wrap svg { width: 100%; height: 100%; transform: rotate(-90deg); overflow: visible; }
.ring-wrap .track { fill: none; stroke: rgba(255,255,255,.1); stroke-width: 14; }
.ring-wrap .bar { fill: none; stroke-width: 14; stroke-linecap: round; filter: drop-shadow(0 0 10px var(--rc)); stroke: var(--rc); transition: stroke-dashoffset 1.8s var(--ease-out); }
.ring-wrap .orbit-ring { fill: none; stroke: rgba(255,255,255,.18); stroke-width: 1; stroke-dasharray: 2 6; transform-origin: 50% 50%; animation: spinPlain 30s linear infinite; }
@keyframes spinPlain { to { transform: rotate(360deg); } }
.ring-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring-center .pct { font-family: var(--display); font-weight: 800; font-size: clamp(40px, 13vw, 64px); line-height: 1; }
.ring-center .of { color: var(--muted); font-weight: 700; margin-top: 6px; }
.result-hero h1 { font-family: var(--display); font-weight: 800; font-size: clamp(24px, 6vw, 32px); margin: 8px 0 0; line-height: 1.15; }
.result-hero p { margin: 0; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: 100%; max-width: 460px; margin-top: 6px; }
.stat { padding: 12px 8px; border-radius: 16px; background: var(--glass); border: 1px solid var(--line); }
.stat b { display: block; font-family: var(--display); font-size: 22px; }
.stat span { font-size: 13px; color: var(--muted); }
.stat.good b { color: var(--good); } .stat.bad b { color: var(--bad); } .stat.skip b { color: var(--muted); }
.result-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; max-width: 460px; margin-top: 8px; }
.result-actions .wide { grid-column: 1 / -1; }

.legend { display: flex; flex-wrap: wrap; gap: 8px 16px; font-size: 13px; color: var(--muted); margin: 0 0 14px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 4px; margin-right: 6px; vertical-align: -1px; }
.review-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin: 0 0 10px; }
.review-head h2 { font-family: var(--display); font-weight: 700; font-size: 20px; margin: 0; }
.filter { display: flex; gap: 6px; }
.filter .chip-btn { padding: 6px 12px; font-size: 13px; }
.filter .chip-btn.on { background: var(--star); color: var(--ink); }
.review { display: grid; gap: 12px; }
.rcard { padding: 18px 16px; border-radius: var(--radius-lg); background: var(--glass); border: 1px solid var(--line); border-left: 5px solid var(--muted); opacity: 0; transform: translateY(30px); transition: opacity .6s var(--ease-out), transform .6s var(--ease-out); }
.rcard.seen { opacity: 1; transform: none; }
.rcard.right { border-left-color: var(--good); }
.rcard.wrong { border-left-color: var(--bad); }
.rcard .top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.rcard .num { font-family: var(--display); font-weight: 700; font-size: 13px; color: var(--muted); }
.rcard .verdict { font-size: 13px; font-weight: 800; }
.rcard.right .verdict { color: var(--good); } .rcard.wrong .verdict { color: var(--bad); } .rcard.skipped .verdict { color: var(--muted); }
.rcard .q { font-weight: 700; margin: 10px 0 12px; line-height: 1.45; }
.rcard .q-img { max-width: 100%; border-radius: 12px; background: #fff; padding: 4px; margin-bottom: 10px; }
.ropts { display: grid; gap: 6px; }
.ropt { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; padding: 9px 12px; border-radius: 12px; font-size: 15px; background: rgba(255,255,255,.03); border: 1px solid transparent; color: var(--muted); }
.ropt .k { font-family: var(--display); font-size: 12px; font-weight: 700; }
.ropt .tag { font-size: 11px; font-weight: 800; white-space: nowrap; }
.ropt.good { color: var(--good); background: rgba(53,224,138,.1); border-color: rgba(53,224,138,.45); }
.ropt.bad  { color: var(--bad);  background: rgba(255,90,118,.1); border-color: rgba(255,90,118,.45); }
.ropt.key  { color: var(--key);  background: rgba(255,197,66,.1); border-color: rgba(255,197,66,.45); }
.rcard .explain { margin: 12px 0 0; font-size: 14px; color: var(--star); background: rgba(124,140,255,.1); border-radius: 12px; padding: 10px 12px; }
.rcard .ref { margin: 10px 0 0; font-size: 12px; color: var(--muted); }

/* stars burst on a great score */
.burst { position: fixed; inset: 0; pointer-events: none; z-index: 30; overflow: hidden; }
.burst i { position: absolute; left: 50%; top: 35%; width: 10px; height: 10px; border-radius: 2px; transform: translate(-50%, -50%); animation: burst 1.6s var(--ease-out) forwards; }
@keyframes burst { to { transform: translate(calc(-50% + var(--x)), calc(-50% + var(--y))) rotate(var(--r)); opacity: 0; } }

/* ===== Misc ===== */
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 40; transform: translate(-50%, calc(100% + 80px)); opacity: 0; padding: 12px 18px; border-radius: 14px; background: #fff; color: var(--ink); font-weight: 700; font-size: 15px; box-shadow: 0 20px 40px -12px rgba(0,0,0,.6); transition: transform .45s var(--ease-spring), opacity .3s; max-width: calc(100% - 32px); text-align: center; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.empty-state { text-align: center; color: var(--muted); padding: 40px 10px; }
.error-box { margin-top: 40px; padding: 22px; border-radius: var(--radius-lg); border: 1px solid rgba(255,90,118,.4); background: rgba(255,90,118,.08); }
.error-box code { background: rgba(255,255,255,.1); padding: 2px 6px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (max-width: 420px) {
  .modes { grid-template-columns: 1fr; }
  .mode { min-height: 0; }
  .subjects { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .class-card { flex-direction: column; text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .rcard { opacity: 1; transform: none; }
}
