:root {
  --paper: #faf6ee;
  --card: #ffffff;
  --ink: #14213d;
  --ink-2: #4a5470;
  --muted: #8a8fa3;
  --line: #e8e2d5;
  --red: #c8102e;
  --red-soft: #fde8eb;
  --blue: #0d5eaf;      /* Aegean blue */
  --blue-soft: #e5f0fb;
  --green: #1f8a4c;
  --green-soft: #e3f4ea;
  --amber: #d98a00;
  --amber-soft: #fff3dc;
  --radius: 18px;
  --shadow: 0 1px 0 rgba(20,33,61,.04), 0 6px 20px -8px rgba(20,33,61,.18);
  --head: "Fraunces", Georgia, "Times New Roman", serif;
  --body: "Nunito Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0f1626; --card: #172036; --ink: #f2efe8; --ink-2: #c3c8d6; --muted: #8790a8;
    --line: #26304a; --red: #ff5a6e; --red-soft: #3a1b25; --blue: #5aa9ff; --blue-soft: #16294a;
    --green: #4cd08a; --green-soft: #143327; --amber: #ffb84d; --amber-soft: #3a2c12;
    --shadow: 0 1px 0 rgba(0,0,0,.2), 0 8px 24px -10px rgba(0,0,0,.6);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--body); font-size: 17px; line-height: 1.45; }
body { min-height: 100dvh; }
main { max-width: 560px; margin: 0 auto; padding: 18px 16px calc(96px + var(--safe-b)); }
h1, h2, h3 { font-family: var(--head); font-weight: 800; letter-spacing: -0.01em; margin: 0; line-height: 1.15; }
h1 { font-size: 30px; }
h2 { font-size: 22px; }
h3 { font-size: 18px; font-weight: 600; }
p { margin: 0; }
a { color: inherit; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.stack > * + * { margin-top: 14px; }
.row { display: flex; align-items: center; gap: 12px; }
.spacer { flex: 1; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 26px 2px 10px; }
.section-title h2 { font-size: 20px; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 52px; padding: 0 22px;
  border-radius: 14px; font-weight: 800; font-size: 17px; background: var(--ink); color: var(--paper); transition: transform .08s; }
.btn:active { transform: scale(.98); }
.btn.block { width: 100%; }
.btn.red { background: var(--red); color: #fff; }
.btn.blue { background: var(--blue); color: #fff; }
.btn.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 2px var(--line); }
.btn[disabled] { opacity: .4; pointer-events: none; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; }
.icon-btn svg, .tabs svg, .ico { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* top bar */
.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.avatar { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-size: 24px; background: var(--blue-soft); flex: none; }
.greet small { display: block; color: var(--muted); font-size: 14px; }
.greet strong { font-family: var(--head); font-size: 22px; }

/* countdown hero */
.hero { position: relative; overflow: hidden; background: var(--ink); color: #fff; border-radius: 22px; padding: 20px; }
.hero::after { content: ""; position: absolute; right: -40px; top: -40px; width: 170px; height: 170px; border-radius: 50%;
  background: repeating-linear-gradient(45deg, rgba(255,255,255,.07) 0 10px, transparent 10px 20px); }
.hero .days { font-family: var(--head); font-size: 64px; line-height: 1; font-weight: 800; }
.hero .label { opacity: .8; font-size: 15px; }
.hero .meter { margin-top: 16px; height: 10px; border-radius: 10px; background: rgba(255,255,255,.15); overflow: hidden; }
.hero .meter > i { display: block; height: 100%; border-radius: 10px; background: linear-gradient(90deg, #ff7a8a, #fff); }
.hero .meta { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-top: 8px; font-size: 14px; opacity: .85; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; font-weight: 700; font-size: 14px; background: var(--card); box-shadow: var(--shadow); }
.chip.flame { color: var(--amber); }
.chip.good { color: var(--green); }

/* mode tiles */
.mode-main { display: flex; align-items: center; gap: 16px; background: var(--red); color: #fff; border-radius: 22px; padding: 20px; width: 100%; text-align: left; box-shadow: 0 10px 24px -12px rgba(200,16,46,.7); }
.mode-main h2 { color: #fff; }
.mode-main p { opacity: .9; font-size: 15px; }
.mode-main .go { margin-left: auto; width: 46px; height: 46px; border-radius: 50%; background: rgba(255,255,255,.2); display: grid; place-items: center; flex: none; }
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.tile { background: var(--card); border-radius: 16px; box-shadow: var(--shadow); padding: 14px 12px; text-align: left; min-height: 104px; display: flex; flex-direction: column; justify-content: space-between; }
.tile .ico { width: 26px; height: 26px; }
.tile b { display: block; font-size: 15px; }
.tile span { font-size: 13px; color: var(--muted); }
.tile.t-blue .ico { color: var(--blue); }
.tile.t-amber .ico { color: var(--amber); }
.tile.t-green .ico { color: var(--green); }

/* progress bars */
.bar { height: 10px; border-radius: 10px; background: var(--line); overflow: hidden; display: flex; }
.bar i { display: block; height: 100%; }
.bar .m { background: var(--green); }
.bar .l { background: var(--blue); }
.bar .w { background: var(--red); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

.chapter { display: block; width: 100%; text-align: left; }
.chapter + .chapter { margin-top: 10px; }
.chapter .row { margin-bottom: 10px; }
.chapter .pct { font-weight: 800; font-size: 15px; color: var(--ink-2); }

/* quiz */
.quiz-top { display: flex; align-items: center; gap: 8px; margin: -6px -6px 12px; }
.quiz-progress { flex: 1; height: 8px; border-radius: 8px; background: var(--line); overflow: hidden; }
.quiz-progress > i { display: block; height: 100%; background: var(--blue); border-radius: 8px; transition: width .25s; }
.timer { font-variant-numeric: tabular-nums; font-weight: 800; padding: 6px 10px; border-radius: 10px; background: var(--card); box-shadow: var(--shadow); font-size: 15px; }
.timer.low { color: var(--red); }
.qmeta { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: 14px; color: var(--muted); font-weight: 700; }
.tag { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 800; letter-spacing: .02em; background: var(--blue-soft); color: var(--blue); }
.tag.two { background: var(--amber-soft); color: var(--amber); }
.question { font-size: 21px; font-weight: 700; line-height: 1.35; white-space: pre-line; margin: 6px 0 18px; }
.question .quote { display: block; font-family: var(--head); font-weight: 600; font-size: 20px; margin-top: 10px; padding-left: 14px; border-left: 4px solid var(--blue); }
.options { display: grid; gap: 10px; }
.opt { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 60px; padding: 12px 14px; text-align: left; font-size: 17px; font-weight: 600;
  background: var(--card); border-radius: 14px; box-shadow: var(--shadow), inset 0 0 0 2px transparent; transition: box-shadow .15s, background .15s; }
.opt .letter { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; font-weight: 800; font-size: 15px; background: var(--paper); color: var(--ink-2); flex: none; }
.opt.sel { box-shadow: var(--shadow), inset 0 0 0 2px var(--blue); }
.opt.sel .letter { background: var(--blue); color: #fff; }
.opt.right { background: var(--green-soft); box-shadow: inset 0 0 0 2px var(--green); }
.opt.right .letter { background: var(--green); color: #fff; }
.opt.wrong { background: var(--red-soft); box-shadow: inset 0 0 0 2px var(--red); }
.opt.wrong .letter { background: var(--red); color: #fff; }
.opt.dim { opacity: .55; }
.opt[disabled] { cursor: default; }
.feedback { border-radius: 16px; padding: 16px; margin-top: 16px; animation: pop .25s ease-out; }
.feedback.ok { background: var(--green-soft); }
.feedback.no { background: var(--red-soft); }
.feedback h3 { margin-bottom: 4px; }
.feedback.ok h3 { color: var(--green); }
.feedback.no h3 { color: var(--red); }
.feedback p { color: var(--ink-2); font-size: 15px; }
.quiz-actions { position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 16px calc(12px + var(--safe-b)); background: linear-gradient(to top, var(--paper) 70%, transparent); }
.quiz-actions .inner { max-width: 560px; margin: 0 auto; display: flex; gap: 10px; }
.quiz-actions .inner .btn { flex: 1; }
.flag.on { color: var(--amber); }
.flag.on .ico { fill: currentColor; }

.grid-nav { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.grid-nav button { aspect-ratio: 1; border-radius: 12px; font-weight: 800; background: var(--card); box-shadow: var(--shadow); position: relative; }
.grid-nav button.done { background: var(--blue-soft); color: var(--blue); }
.grid-nav button.cur { box-shadow: inset 0 0 0 2px var(--ink); }
.grid-nav button.flagged::after { content: ""; position: absolute; top: 5px; right: 5px; width: 8px; height: 8px; border-radius: 50%; background: var(--amber); }

/* sheet */
.sheet-bg { position: fixed; inset: 0; background: rgba(10,15,30,.45); z-index: 20; display: flex; align-items: flex-end; animation: fade .2s; }
.sheet { width: 100%; max-width: 560px; margin: 0 auto; background: var(--paper); border-radius: 22px 22px 0 0; padding: 20px 16px calc(20px + var(--safe-b)); animation: up .25s ease-out; max-height: 88dvh; overflow: auto; }
.sheet .handle { width: 40px; height: 5px; border-radius: 5px; background: var(--line); margin: -8px auto 14px; }

/* results */
.score-ring { position: relative; width: 190px; height: 190px; margin: 6px auto 4px; }
.score-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.score-ring .val { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; }
.score-ring .val b { font-family: var(--head); font-size: 52px; line-height: 1; }
.score-ring .val span { display: block; color: var(--muted); font-weight: 700; font-size: 14px; }
.verdict { text-align: center; }
.verdict h1 { font-size: 32px; }
.verdict.pass h1 { color: var(--green); }
.verdict.fail h1 { color: var(--red); }
.badge { display: inline-flex; gap: 6px; align-items: center; padding: 6px 12px; border-radius: 999px; background: var(--amber-soft); color: var(--amber); font-weight: 800; font-size: 14px; }
.stats3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--card); border-radius: 14px; box-shadow: var(--shadow); padding: 12px; text-align: center; }
.stat b { display: block; font-family: var(--head); font-size: 24px; }
.stat span { font-size: 13px; color: var(--muted); font-weight: 700; }
.review-item { background: var(--card); border-radius: 14px; box-shadow: var(--shadow); padding: 14px; }
.review-item + .review-item { margin-top: 10px; }
.review-item .q { font-weight: 700; white-space: pre-line; }
.review-item .ans { margin-top: 8px; font-size: 15px; }
.review-item .ans div { padding: 4px 0; }
.review-item .yours { color: var(--red); }
.review-item .correct { color: var(--green); }
.review-item .why { margin-top: 8px; font-size: 14px; color: var(--ink-2); }

/* scores */
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .passline { stroke: var(--red); stroke-dasharray: 5 5; stroke-width: 1.5; }
.chart .line { fill: none; stroke: var(--blue); stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--blue); opacity: .08; }
.chart .dot { stroke: var(--card); stroke-width: 2; }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--body); font-weight: 700; }
.leader { display: flex; align-items: center; gap: 12px; }
.leader + .leader { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.leader .rank { font-family: var(--head); font-weight: 800; font-size: 20px; width: 22px; color: var(--muted); }
.hist-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; }
.hist-row + .hist-row { border-top: 1px solid var(--line); }
.pill { min-width: 64px; text-align: center; padding: 6px 10px; border-radius: 10px; font-weight: 800; font-size: 15px; font-variant-numeric: tabular-nums; }
.pill.pass { background: var(--green-soft); color: var(--green); }
.pill.fail { background: var(--red-soft); color: var(--red); }

/* donut */
.donut-wrap { display: flex; align-items: center; gap: 18px; }
.donut { width: 120px; height: 120px; flex: none; position: relative; }
.donut svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.donut .c { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; }
.donut .c b { font-family: var(--head); font-size: 26px; display: block; line-height: 1; }
.donut .c span { font-size: 12px; color: var(--muted); font-weight: 700; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 15px; }
.kv b { text-align: right; }

/* forms / who */
.who { padding-top: 6vh; text-align: center; }
.who .logo { width: 84px; height: 84px; margin: 0 auto 14px; }
.player-list { display: grid; gap: 10px; text-align: left; margin-top: 24px; }
.player-btn { display: flex; align-items: center; gap: 14px; padding: 14px; background: var(--card); border-radius: 16px; box-shadow: var(--shadow); width: 100%; text-align: left; }
.field { display: block; text-align: left; }
.field span { display: block; font-weight: 800; font-size: 14px; margin-bottom: 6px; color: var(--ink-2); }
.field input { width: 100%; min-height: 52px; padding: 0 14px; border-radius: 12px; border: 2px solid var(--line); background: var(--card); color: var(--ink); font: inherit; }
.field input:focus { outline: none; border-color: var(--blue); }
.emoji-pick { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.emoji-pick button { aspect-ratio: 1; font-size: 26px; border-radius: 12px; background: var(--card); box-shadow: var(--shadow); }
.emoji-pick button.sel { box-shadow: inset 0 0 0 3px var(--blue); }
.seg { display: flex; background: var(--line); border-radius: 12px; padding: 4px; }
.seg button { flex: 1; min-height: 40px; border-radius: 9px; font-weight: 800; color: var(--ink-2); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.empty { text-align: center; padding: 28px 12px; color: var(--muted); }
.empty .ico { width: 40px; height: 40px; margin-bottom: 8px; }

/* tabs */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; justify-content: space-around; background: var(--card);
  border-top: 1px solid var(--line); padding: 6px 8px calc(6px + var(--safe-b)); }
.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; text-decoration: none; font-size: 12px; font-weight: 800; color: var(--muted); border-radius: 12px; }
.tabs a.on { color: var(--ink); }
.tabs a.on svg { stroke: var(--red); }
.tabs[hidden] { display: none; }

.toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 12px; font-weight: 700; z-index: 30; animation: pop .2s; max-width: 90vw; text-align: center; }

#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 40; overflow: hidden; }
#confetti i { position: absolute; top: -12px; width: 9px; height: 14px; border-radius: 2px; animation: fall linear forwards; }

@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }
@keyframes pop { from { transform: scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } }
@keyframes shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }
.shake { animation: shake .35s; }
.view { animation: pop .2s ease-out; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
@media (min-width: 420px) { .tiles .tile b { font-size: 16px; } }
