/* Quizzly — playful mobile-first quiz site.
   Tokens drive light/dark; per-topic accent set inline via --c1/--c2. */

:root {
  --bg: #eef1ff;
  --bg2: #f7f2ff;
  --surface: #ffffff;
  --surface-2: #f5f6ff;
  --ink: #1c1b33;
  --ink-soft: #55547a;
  --ink-faint: #8a89a8;
  --line: #e6e6f5;
  --brand: #6d5cf5;
  --brand-ink: #ffffff;
  --good: #16a34a;
  --good-bg: #e5f7ec;
  --bad: #e11d48;
  --bad-bg: #fdeaee;
  --shadow: 0 18px 40px -22px rgba(40, 30, 90, .45);
  --shadow-sm: 0 8px 22px -14px rgba(40, 30, 90, .4);
  --radius: 22px;
  --radius-sm: 15px;
  --c1: #6366f1;
  --c2: #8b5cf6;
  color-scheme: light;
}

:root[data-theme="dark"], html[data-auto-dark] {
  --bg: #0e0d1c;
  --bg2: #14122a;
  --surface: #1b1930;
  --surface-2: #232043;
  --ink: #f2f1ff;
  --ink-soft: #b9b7dc;
  --ink-faint: #8684ad;
  --line: #2c2950;
  --brand: #8b7cff;
  --brand-ink: #0e0d1c;
  --good: #34d399;
  --good-bg: #123227;
  --bad: #fb7185;
  --bad-bg: #341620;
  --shadow: 0 22px 46px -20px rgba(0, 0, 0, .7);
  --shadow-sm: 0 10px 26px -16px rgba(0, 0, 0, .6);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e0d1c;
    --bg2: #14122a;
    --surface: #1b1930;
    --surface-2: #232043;
    --ink: #f2f1ff;
    --ink-soft: #b9b7dc;
    --ink-faint: #8684ad;
    --line: #2c2950;
    --brand: #8b7cff;
    --brand-ink: #0e0d1c;
    --good: #34d399;
    --good-bg: #123227;
    --bad: #fb7185;
    --bad-bg: #341620;
    --shadow: 0 22px 46px -20px rgba(0, 0, 0, .7);
    --shadow-sm: 0 10px 26px -16px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: 'Nunito', system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1100px 600px at 15% -8%, color-mix(in srgb, var(--brand) 22%, transparent), transparent 60%),
    radial-gradient(900px 520px at 100% 0%, color-mix(in srgb, #ec4899 18%, transparent), transparent 55%),
    linear-gradient(180deg, var(--bg2), var(--bg));
  background-attachment: fixed;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

h1, h2, .brand-text, .hero-title, .scorewheel-num { font-family: 'Fredoka', system-ui, sans-serif; }

/* floating background orbs */
.bg-orbs { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.bg-orbs span {
  position: absolute; border-radius: 50%; filter: blur(40px); opacity: .5;
  animation: drift 22s ease-in-out infinite;
}
.bg-orbs span:nth-child(1) { width: 260px; height: 260px; left: -60px; top: 12%; background: #8b5cf6; }
.bg-orbs span:nth-child(2) { width: 220px; height: 220px; right: -50px; top: 42%; background: #ec4899; animation-delay: -7s; }
.bg-orbs span:nth-child(3) { width: 200px; height: 200px; left: 30%; bottom: -60px; background: #38bdf8; animation-delay: -14s; }
@keyframes drift {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(20px, -26px) scale(1.12); }
}

/* topbar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top)) 18px 12px;
  backdrop-filter: blur(10px);
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.brand-badge {
  width: 38px; height: 38px; display: grid; place-items: center; font-size: 20px;
  border-radius: 12px; background: linear-gradient(135deg, #6d5cf5, #b06cf5);
  box-shadow: var(--shadow-sm);
}
.brand-text { font-size: 1.35rem; font-weight: 700; letter-spacing: .2px; }
.theme-toggle {
  width: 44px; height: 44px; border-radius: 13px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-size: 18px; line-height: 1;
  display: grid; place-items: center; color: var(--ink); transition: transform .15s, background .2s;
}
.theme-toggle:active { transform: scale(.92); }
.tt-moon { display: none; }
:root[data-theme="dark"] .tt-sun { display: none; }
:root[data-theme="dark"] .tt-moon { display: inline; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .tt-sun { display: none; }
  :root:not([data-theme="light"]) .tt-moon { display: inline; }
}

/* layout */
#app { max-width: 940px; margin: 0 auto; padding: 8px 16px calc(40px + env(safe-area-inset-bottom)); }
.view { animation: viewIn .4s cubic-bezier(.2, .8, .2, 1); }
@keyframes viewIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* hero */
.hero { text-align: center; padding: 26px 6px 20px; }
.kicker {
  display: inline-block; margin: 0 0 12px; font-weight: 800; font-size: .72rem;
  letter-spacing: .18em; text-transform: uppercase; color: var(--brand);
  background: color-mix(in srgb, var(--brand) 14%, transparent);
  padding: 6px 12px; border-radius: 999px;
}
.hero-title { margin: 0; font-size: clamp(1.9rem, 8vw, 3rem); line-height: 1.08; font-weight: 700; text-wrap: balance; }
.hero-sub { max-width: 30ch; margin: 14px auto 0; color: var(--ink-soft); font-size: 1.02rem; line-height: 1.5; }
.hero-stats { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin-top: 20px; }
.hero-stats .stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 9px 14px; box-shadow: var(--shadow-sm); font-weight: 700; font-size: .92rem;
}
.hero-stats .stat b { color: var(--brand); }

/* topic grid */
.grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px; margin-top: 26px;
}
.topic {
  position: relative; text-align: left; cursor: pointer;
  border: none; border-radius: var(--radius); padding: 18px 16px 16px;
  color: #fff; background: linear-gradient(150deg, var(--c1), var(--c2));
  box-shadow: var(--shadow); overflow: hidden; isolation: isolate;
  transition: transform .18s cubic-bezier(.2, .8, .2, 1), box-shadow .18s;
  min-height: 150px; display: flex; flex-direction: column;
}
.topic::after {
  content: ""; position: absolute; inset: 0; z-index: -1;
  background: radial-gradient(120px 90px at 85% 12%, rgba(255, 255, 255, .35), transparent 70%);
}
.topic:hover { transform: translateY(-4px) rotate(-.4deg); box-shadow: 0 26px 46px -20px rgba(40, 30, 90, .6); }
.topic:active { transform: translateY(-1px) scale(.98); }
.topic:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
.topic .t-emoji {
  font-size: 2rem; width: 54px; height: 54px; display: grid; place-items: center;
  background: rgba(255, 255, 255, .2); border-radius: 15px; margin-bottom: auto;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .25);
}
.topic .t-name { font-family: 'Fredoka', sans-serif; font-weight: 700; font-size: 1.16rem; margin: 14px 0 2px; line-height: 1.15; }
.topic .t-blurb { font-size: .82rem; opacity: .9; font-weight: 600; }
.topic .t-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; font-size: .78rem; font-weight: 700; }
.topic .t-count { opacity: .9; }
.topic .t-best {
  background: rgba(0, 0, 0, .22); padding: 3px 9px; border-radius: 999px;
  display: inline-flex; align-items: center; gap: 4px;
}
.topic .t-best.empty { display: none; }

.foot-note { text-align: center; color: var(--ink-faint); font-size: .84rem; margin-top: 30px; font-weight: 600; }

/* quiz */
.view-quiz { max-width: 620px; margin: 0 auto; }
.quiz-bar { display: flex; align-items: center; gap: 12px; padding: 14px 2px 8px; }
.icon-btn {
  flex: none; width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font-size: 16px; cursor: pointer;
  display: grid; place-items: center; transition: transform .15s;
}
.icon-btn:active { transform: scale(.9); }
.progress { flex: 1; height: 12px; border-radius: 999px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--line); }
.progress span {
  display: block; height: 100%; width: 0%; border-radius: 999px;
  background: linear-gradient(90deg, var(--c1), var(--c2)); transition: width .45s cubic-bezier(.2, .8, .2, 1);
}
.qcounter { flex: none; font-weight: 800; font-size: 1rem; font-variant-numeric: tabular-nums; color: var(--ink-soft); }
.qcounter #qNow { color: var(--ink); }
.qsep { margin: 0 2px; color: var(--ink-faint); }

.quiz-meta { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 2px 14px; }
.pill { font-size: .82rem; font-weight: 800; padding: 6px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); }
.topic-pill { background: linear-gradient(150deg, var(--c1), var(--c2)); color: #fff; border: none; }
.streak-pill { color: var(--ink); }
.score-pill { color: var(--ink); }

.question-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px 18px; box-shadow: var(--shadow);
}
.question { margin: 0 0 18px; font-size: clamp(1.2rem, 5vw, 1.5rem); line-height: 1.3; font-weight: 700; text-wrap: balance; }
.options { display: grid; gap: 11px; }
.opt {
  position: relative; text-align: left; width: 100%; cursor: pointer;
  font-family: inherit; font-size: 1.04rem; font-weight: 700; color: var(--ink);
  background: var(--surface-2); border: 2px solid var(--line); border-radius: var(--radius-sm);
  padding: 15px 48px 15px 16px; min-height: 56px;
  display: flex; align-items: center; gap: 12px;
  transition: transform .12s, border-color .18s, background .18s;
}
.opt .opt-key {
  flex: none; width: 28px; height: 28px; border-radius: 9px; display: grid; place-items: center;
  background: var(--surface); border: 1px solid var(--line); font-size: .9rem; font-weight: 800; color: var(--ink-soft);
}
.opt:not([disabled]):hover { border-color: color-mix(in srgb, var(--c1) 55%, var(--line)); }
.opt:not([disabled]):active { transform: scale(.985); }
.opt:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }
.opt .opt-mark { position: absolute; right: 14px; font-size: 1.15rem; opacity: 0; transform: scale(.5); transition: .2s; }
.opt.correct { border-color: var(--good); background: var(--good-bg); color: var(--good); }
.opt.correct .opt-key { background: var(--good); color: #fff; border-color: var(--good); }
.opt.correct .opt-mark { opacity: 1; transform: scale(1); }
.opt.wrong { border-color: var(--bad); background: var(--bad-bg); color: var(--bad); }
.opt.wrong .opt-key { background: var(--bad); color: #fff; border-color: var(--bad); }
.opt.wrong .opt-mark { opacity: 1; transform: scale(1); }
.opt[disabled] { cursor: default; }
.opt.dim { opacity: .55; }
.opt.shake { animation: shake .4s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}
.opt.pop { animation: pop .4s; }
@keyframes pop {
  0% { transform: scale(1); } 40% { transform: scale(1.035); } 100% { transform: scale(1); }
}

.quiz-actions { margin-top: 18px; }
.btn {
  font-family: 'Fredoka', sans-serif; font-weight: 600; font-size: 1.08rem; cursor: pointer;
  border: none; border-radius: 15px; padding: 15px 22px; min-height: 54px; width: 100%;
  transition: transform .14s, box-shadow .2s, opacity .2s;
}
.btn:active { transform: translateY(1px) scale(.99); }
.btn-next, .btn-primary {
  color: var(--brand-ink); background: linear-gradient(135deg, var(--c1, var(--brand)), var(--c2, var(--brand)));
  box-shadow: var(--shadow);
}
.btn-next:disabled { opacity: .4; cursor: default; box-shadow: none; filter: saturate(.6); }
.btn-ghost { background: var(--surface); color: var(--ink); border: 1px solid var(--line); box-shadow: var(--shadow-sm); }

/* results */
.view-result { max-width: 520px; margin: 0 auto; position: relative; }
.confetti { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 5; pointer-events: none; }
.result-card {
  position: relative; z-index: 6; text-align: center; margin-top: 20px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 30px 22px 24px; box-shadow: var(--shadow);
}
.result-emoji { font-size: 3.6rem; line-height: 1; animation: bounceIn .6s cubic-bezier(.2, 1.4, .4, 1); }
@keyframes bounceIn { 0% { transform: scale(0) rotate(-30deg); } 60% { transform: scale(1.25); } 100% { transform: scale(1); } }
.result-topic { margin: 6px 0 14px; font-weight: 800; color: var(--ink-soft); font-size: .95rem; }
.scorewheel { position: relative; width: 168px; height: 168px; margin: 0 auto; }
.scorewheel svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.sw-track { fill: none; stroke: var(--surface-2); stroke-width: 12; }
.sw-fill {
  fill: none; stroke: var(--brand); stroke-width: 12; stroke-linecap: round;
  stroke-dasharray: 327; stroke-dashoffset: 327; transition: stroke-dashoffset 1s cubic-bezier(.2, .8, .2, 1);
}
.scorewheel-num { position: absolute; inset: 0; display: grid; place-content: center; line-height: 1; }
.scorewheel-num span { font-size: 3rem; font-weight: 700; }
.scorewheel-num small { font-size: 1.1rem; color: var(--ink-faint); font-weight: 700; }
.result-pct { margin: 16px 0 4px; font-weight: 800; font-size: 1.05rem; }
.result-pct span { color: var(--brand); }
.result-msg { margin: 4px 0 0; color: var(--ink-soft); font-size: 1.05rem; font-weight: 700; }
.result-best {
  margin: 14px auto 0; display: inline-block; font-weight: 800; font-size: .86rem;
  background: color-mix(in srgb, #f59e0b 16%, transparent); color: #b45309; padding: 7px 14px; border-radius: 999px;
}
:root[data-theme="dark"] .result-best { color: #fbbf24; }
.result-actions { display: grid; gap: 10px; margin-top: 22px; }
.link-btn {
  margin-top: 14px; background: none; border: none; cursor: pointer; color: var(--brand);
  font-family: inherit; font-weight: 800; font-size: .92rem; padding: 8px; text-decoration: underline;
  text-underline-offset: 3px;
}

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); font-weight: 700; font-size: .9rem;
  padding: 12px 18px; border-radius: 999px; z-index: 50; opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s; box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (min-width: 560px) {
  .result-actions { grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
  .bg-orbs { display: none; }
}
