:root {
  --bg: #F7F3EC; --surface: #FFFFFF; --ink: #23201C; --muted: #6B645B; --line: #EAE3D8;
  --accent: #C8432A; --accent-ink: #B53A23; --accent-soft: #FBE6DF;
  --indigo: #3B3F99; --indigo-soft: #ECEDF9;
  --good: #1F7A4D; --good-ink: #155C38; --good-soft: #E5F3EA;
  --bad: #B42318; --bad-soft: #FDECEA;
  --r: 22px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font-family: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif; font-size: 16px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: var(--accent-ink); font-weight: 700; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--indigo); outline-offset: 2px; }

.screen { max-width: 560px; margin: 0 auto; padding: 24px 20px 32px; display: flex; flex-direction: column; gap: 16px; min-height: 100vh; }
.screen.with-nav { padding-bottom: 104px; min-height: 0; }
.screen.admin { max-width: 960px; }
.center { display: flex; justify-content: center; padding: 64px 0; }
.center-col { display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; padding-top: 48px; }

.brand { font-weight: 800; color: var(--accent-ink); letter-spacing: .02em; }
.title { margin: 0; font-size: 27px; font-weight: 800; line-height: 1.2; }
.h2 { margin: 0; font-size: 18px; font-weight: 800; }
.muted { color: var(--muted); }
.strong { font-weight: 800; }
.tiny { font-size: 13px; }
.small { font-size: 14px; }
.big { font-size: 22px; font-weight: 800; line-height: 1; }
.big-num { font-size: 40px; font-weight: 800; margin: 0; }
.msg { margin: 0; padding: 12px 14px; border-radius: 14px; background: var(--indigo-soft); color: var(--indigo); font-weight: 600; }

.card { background: var(--surface); border-radius: var(--r); padding: 18px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack-s { display: flex; flex-direction: column; gap: 4px; }
.stack-0 { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; gap: 12px; }
.row.wrap { flex-wrap: wrap; gap: 8px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grow { flex: 1 1 auto; min-width: 0; }

label { font-weight: 700; font-size: 14px; }
input, select, textarea { width: 100%; min-height: 48px; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 14px; background: #fff; }
textarea { min-height: 88px; resize: vertical; }
input.code { font-size: 26px; letter-spacing: .35em; text-align: center; font-weight: 800; }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 600; }
.check input { width: 22px; min-height: 22px; height: 22px; margin-top: 1px; accent-color: var(--accent); flex-shrink: 0; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-weight: 700; font-size: 14px; margin-bottom: 6px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 20px; border-radius: 999px; border: 0; font-weight: 800; cursor: pointer; text-decoration: none; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.indigo { background: var(--indigo); color: #fff; }
.btn.ghost { background: transparent; border: 1.5px solid #D9CEBE; color: var(--ink); }
.btn.small { min-height: 40px; padding: 0 14px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: default; }
.big-btn { min-height: 60px; font-size: 19px; width: 100%; }
.link { background: none; border: 0; color: var(--accent-ink); font-weight: 800; cursor: pointer; padding: 8px 0; min-height: 44px; display: inline-flex; align-items: center; gap: 6px; }
.icon-btn { width: 44px; height: 44px; border-radius: 22px; border: 0; background: #fff; display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; }

.notice { background: var(--bg); border-radius: 16px; padding: 14px; font-size: 14px; }
.notice ul { margin: 8px 0 12px; padding-left: 18px; color: #4A443D; }
.notice li { margin-bottom: 4px; }

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.seg-opt { position: relative; }
.seg-opt input { position: absolute; opacity: 0; }
.seg-opt span { display: flex; align-items: center; justify-content: center; min-height: 48px; border-radius: 14px; border: 1.5px solid var(--line); background: #fff; font-weight: 700; cursor: pointer; }
.seg-opt input:checked + span { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); }
.seg-opt input:focus-visible + span { outline: 3px solid var(--indigo); }

/* home */
.hello { display: flex; justify-content: space-between; align-items: center; }
.avatar { width: 46px; height: 46px; border-radius: 23px; border: 0; background: var(--accent-soft); color: #8F2C1A; font-weight: 800; cursor: pointer; }
.goal { display: flex; align-items: center; gap: 16px; }
.ring { width: 96px; height: 96px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.ring-in { width: 74px; height: 74px; border-radius: 50%; background: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 700; padding: 4px 10px; border-radius: 12px; background: var(--bg); }
.install { display: flex; align-items: center; gap: 10px; font-size: 14px; background: var(--indigo-soft); color: var(--indigo); }
.medals { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.medal-card { background: #fff; border-radius: 18px; padding: 12px 4px; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.medal-name { font-size: 12px; font-weight: 800; line-height: 1.2; }
.medal { border-radius: 50%; border: 3px solid; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 800; flex-shrink: 0; }

/* topics */
.topic { display: flex; flex-direction: column; gap: 12px; }
.bar { height: 10px; border-radius: 6px; background: #EADFCF; overflow: hidden; }
.bar > div { height: 100%; border-radius: 6px; background: var(--accent); transition: width .3s; }
.seg3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.seg-btn { min-height: 44px; border-radius: 12px; border: 1.5px solid var(--line); background: #fff; font-weight: 700; cursor: pointer; font-size: 14px; }
.seg-btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); }
.seg-btn:disabled { opacity: .45; cursor: not-allowed; }

/* ranking */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 40px; padding: 0 16px; border-radius: 20px; border: 0; background: #fff; font-weight: 700; cursor: pointer; }
.chip.on { background: var(--ink); color: #fff; }
.chip.alt.on { background: var(--indigo); color: #fff; }
.podium { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: end; gap: 6px; }
.pod { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; min-width: 0; }
.pod-name { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.pod-av { width: 52px; height: 52px; border-radius: 50%; border: 3px solid #E2D9CB; background: var(--bg); display: flex; align-items: center; justify-content: center; font-weight: 800; }
.pod-av.gold { width: 62px; height: 62px; background: #FFF3CF; border-color: #D9A520; color: #6B4A00; }
.pod-av.silver { background: #F0F1F4; border-color: #A3AAB6; color: #3D4452; }
.pod-av.bronze { background: #FBE9DC; border-color: #C27A45; color: #6E3A12; }
.pod-step { width: 86%; border-radius: 12px 12px 4px 4px; padding-top: 6px; font-weight: 800; font-size: 14px; }
.pod-step.s1 { height: 76px; background: #FFF3CF; color: #6B4A00; }
.pod-step.s2 { height: 56px; background: #F0F1F4; color: #3D4452; }
.pod-step.s3 { height: 42px; background: #FBE9DC; color: #6E3A12; }
.lb { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.lb-row { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-radius: 20px; background: #fff; }
.lb-row .tiny { color: var(--muted); }
.lb-row.me { background: var(--accent); color: #fff; }
.lb-row.me .tiny { color: #FBE6DF; }
.rk { width: 24px; font-weight: 800; }
.staff { color: var(--indigo); vertical-align: -2px; }
.lb-row.me .staff { color: #fff; }

/* round */
.round-top { display: flex; align-items: center; gap: 12px; }
.qcard { display: flex; flex-direction: column; gap: 12px; }
.question { margin: 0; font-size: 23px; line-height: 1.3; font-weight: 800; }
.tag { font-size: 13px; font-weight: 800; padding: 5px 12px; border-radius: 14px; background: var(--indigo-soft); color: var(--indigo); }
.tag.soft { background: var(--bg); color: var(--muted); }
.answers { display: flex; flex-direction: column; gap: 10px; }
.answer { min-height: 58px; padding: 14px 20px; border-radius: 28px; border: 2px solid transparent; background: #fff; text-align: left; font-weight: 700; display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer; }
.answer:not(:disabled):hover { border-color: #D9CEBE; }
.answer.right { background: var(--good); color: #fff; }
.answer.wrong { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.answer.dim { color: var(--muted); font-weight: 600; }
.answer:disabled { cursor: default; }
.feedback { border-radius: var(--r); padding: 16px 18px; display: flex; flex-direction: column; gap: 8px; }
.feedback p { margin: 0; font-size: 15px; }
.feedback.ok { background: var(--good-soft); color: #2D3B33; }
.feedback.ok .h2 { color: var(--good-ink); }
.feedback.bad { background: var(--bad-soft); color: #4A2A26; }
.feedback.bad .h2 { color: var(--bad); }
.pts { font-weight: 800; padding: 4px 12px; border-radius: 14px; background: #fff; color: var(--good-ink); }
.result-badge { width: 96px; height: 96px; border-radius: 50%; background: #FFF3CF; border: 4px solid #D9A520; color: #6B4A00; display: flex; align-items: center; justify-content: center; }

/* nav */
.nav { position: fixed; left: 0; right: 0; bottom: 0; height: calc(72px + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: #fff; border-radius: 24px 24px 0 0; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); box-shadow: 0 -1px 0 var(--line); }
.nav-item { border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; color: var(--muted); font-size: 12px; font-weight: 700; cursor: pointer; }
.nav-item.on { color: var(--accent-ink); font-weight: 800; }
@media (min-width: 600px) { .nav { max-width: 560px; margin: 0 auto; } }

/* overlay */
.overlay { position: fixed; inset: 0; background: rgba(35, 32, 28, .45); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.sheet { background: #fff; width: 100%; max-width: 560px; border-radius: 24px 24px 0 0; padding: 22px 20px calc(22px + env(safe-area-inset-bottom)); }

/* admin */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.kpi { display: flex; flex-direction: column; gap: 6px; }
.qrow { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; cursor: pointer; font-weight: 400; font-size: 15px; }
.qrow input { width: 22px; height: 22px; min-height: 22px; margin-top: 2px; accent-color: var(--accent); flex-shrink: 0; }
.sticky-actions { position: sticky; top: 0; background: var(--bg); padding: 8px 0; z-index: 2; }
.admin select { width: auto; min-width: 160px; }

.spinner { width: 36px; height: 36px; border-radius: 50%; border: 4px solid #EADFCF; border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } .bar > div { transition: none; } }
@media (max-width: 380px) { .medals { grid-template-columns: repeat(3, minmax(0, 1fr)); } .row2 { grid-template-columns: 1fr; } }

/* My questions */
.seg2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.star-badge { width: 42px; height: 42px; background: #FFF3CF; border-color: #D9A520; color: #D9A520; }
.saved-card { border: 1.5px solid #F1DFA8; }
.star-tag { display: inline-flex; align-items: center; gap: 4px; background: #FFF3CF; color: #6B4A00; }
.save-btn { align-self: flex-start; display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 8px 14px; border-radius: 22px;
  border: 1.5px solid var(--line); background: #fff; font: inherit; font-weight: 700; font-size: 14px; color: var(--ink); cursor: pointer; }
.save-btn.on { background: #FFF3CF; border-color: #D9A520; color: #6B4A00; }
.save-btn svg { color: #D9A520; }
.saved-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.saved-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); font-size: 14px; }
.icon-btn.star { color: #D9A520; }
.fb-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding-top: 12px; border-top: 1px solid rgba(0,0,0,.08); }
.fb-actions .save-btn { min-height: 40px; padding: 6px 14px; }

/* keep content from scrolling under the iPhone status bar */
body::before { content: ''; position: fixed; top: 0; left: 0; right: 0; height: env(safe-area-inset-top); background: var(--bg); z-index: 50; }
body { padding-top: env(safe-area-inset-top); }

/* ---------------------------------------------------------------- levels */
.lv-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.lv-chip { min-height: 52px; border-radius: 14px; border: 1.5px dashed var(--line); background: #fff; cursor: pointer; font: inherit;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 6px 4px; color: var(--muted); }
.lv-chip.on { border-style: solid; border-color: var(--indigo); background: var(--indigo-soft); color: var(--indigo); }
.lv-chip.soon { opacity: .55; cursor: not-allowed; }
.lv-top { display: inline-flex; align-items: center; gap: 5px; font-weight: 800; font-size: 14px; }
.lv-sub { font-size: 12px; font-weight: 700; }
.lv-dot { width: 11px; height: 11px; border-radius: 50%; border: 2px solid; display: inline-block; }
.ready-chip { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; border-radius: 22px; border: 0; cursor: pointer;
  font: inherit; font-weight: 800; font-size: 14px; background: linear-gradient(90deg, #FFF3CF, #FBE9DC); color: #6B4A00; animation: breathe 2.4s ease-in-out infinite; }

/* ---------------------------------------------------------------- celebration */
.celebrate { align-items: center; padding: 16px; }
.celebrate .sheet { border-radius: 24px; text-align: center; animation: rise .45s cubic-bezier(.2, .9, .3, 1.3) both; position: relative; z-index: 2; }
.lvl-badge { width: 92px; height: 92px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #FFF8DE, #F5C842); border: 4px solid #D9A520;
  color: #6B4A00; display: flex; flex-direction: column; align-items: center; justify-content: center; font-weight: 900; font-size: 20px;
  animation: bounce-in .8s cubic-bezier(.2, .9, .3, 1.4) .15s both; box-shadow: 0 0 0 0 rgba(217, 165, 32, .5); }
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 1; }
.confetti i { position: absolute; top: -20px; border-radius: 2px; animation-name: confetti-fall; animation-timing-function: cubic-bezier(.3, .6, .5, 1); animation-fill-mode: both; }
.toast { position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: #fff;
  padding: 12px 18px; border-radius: 16px; font-weight: 700; font-size: 14px; z-index: 20; max-width: calc(100% - 32px); text-align: center;
  animation: toast-in .35s ease-out both; }

/* ---------------------------------------------------------------- one-shot animations (class .animate only on the first render after loading) */
@property --p { syntax: '<percentage>'; inherits: false; initial-value: 0%; }
.animate .ring { animation: ring-fill 1.1s cubic-bezier(.3, .7, .3, 1) both; }
.animate .bar > div { transform-origin: left center; animation: grow-x .9s cubic-bezier(.3, .7, .3, 1) both; }
.animate .medal-card, .animate .topic { animation: rise .45s ease-out both; animation-delay: calc(var(--i, 0) * 50ms); }
.animate .medal-card .medal { animation: pop .5s cubic-bezier(.2, .9, .3, 1.5) both; animation-delay: calc(200ms + var(--i, 0) * 60ms); }
.animate .pod-step { transform-origin: bottom center; animation: grow-y .8s cubic-bezier(.2, .9, .3, 1.2) both; animation-delay: calc(var(--i, 0) * 120ms); }
.animate .pod-av { animation: pop .5s cubic-bezier(.2, .9, .3, 1.5) both; animation-delay: calc(450ms + var(--i, 0) * 120ms); }
.animate .lb-row { animation: slide-in .45s ease-out both; animation-delay: calc(250ms + var(--i, 0) * 45ms); }
.feedback.enter { animation: rise .35s ease-out both; }
.pts { position: relative; }
.pts.pop { animation: pop .5s cubic-bezier(.2, .9, .3, 1.6) both; }
.float-pts { position: absolute; right: 8px; top: -6px; color: var(--good-ink); font-weight: 900; pointer-events: none; animation: float-up 1.1s ease-out both; }
.answer.right { animation: glow .9s ease-out; }
.result-badge { animation: bounce-in .8s cubic-bezier(.2, .9, .3, 1.4) both; }
.new-medals { display: flex; flex-direction: column; gap: 10px; width: 100%; }
.new-medal { display: flex; align-items: center; gap: 12px; background: #fff; border-radius: 18px; padding: 12px 14px; text-align: left;
  animation: rise .45s ease-out both; animation-delay: calc(300ms + var(--i, 0) * 150ms); }
.medal.pop { animation: pop .6s cubic-bezier(.2, .9, .3, 1.6) both; animation-delay: calc(450ms + var(--i, 0) * 150ms); }

@keyframes ring-fill { from { --p: 0%; } }
@keyframes grow-x { from { transform: scaleX(0); } }
@keyframes grow-y { from { transform: scaleY(0); } }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }
@keyframes slide-in { from { opacity: 0; transform: translateX(-18px); } }
@keyframes pop { 0% { transform: scale(.3); opacity: 0; } 70% { transform: scale(1.12); opacity: 1; } 100% { transform: scale(1); } }
@keyframes bounce-in { 0% { transform: scale(.2) rotate(-12deg); opacity: 0; } 60% { transform: scale(1.15) rotate(4deg); opacity: 1; } 100% { transform: scale(1) rotate(0); } }
@keyframes float-up { 0% { opacity: 0; transform: translateY(0) scale(.8); } 20% { opacity: 1; } 100% { opacity: 0; transform: translateY(-38px) scale(1.15); } }
@keyframes glow { 0% { box-shadow: 0 0 0 0 rgba(46, 125, 79, .55); } 100% { box-shadow: 0 0 0 14px rgba(46, 125, 79, 0); } }
@keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.03); } }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 12px); } }
@keyframes confetti-fall {
  0% { transform: translate(0, 0) rotate(var(--r)); opacity: 1; }
  100% { transform: translate(var(--dx), 105vh) rotate(calc(var(--r) + 540deg)); opacity: .9; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .confetti { display: none; }
}
.seg-btn.locked { color: var(--muted); background: #FAF7F2; border-style: dashed; display: inline-flex; align-items: center; justify-content: center; gap: 5px; }
.focus-hint { margin: -4px 0 0; }
.seg3 .seg-btn { font-size: 13px; padding: 4px 6px; line-height: 1.2; }
.seg-btn.locked svg { flex-shrink: 0; }

/* ---------------------------------------------------------------- answer streaks */
.flame { display: inline-flex; line-height: 0; position: relative; }
.flame.t1 { color: #F0A43A; }
.flame.t2 { color: #EA6A1F; filter: drop-shadow(0 0 3px rgba(234, 106, 31, .45)); }
.flame.t3 { color: #D62F1F; filter: drop-shadow(0 0 5px rgba(214, 47, 31, .6)); animation: flicker 1.2s ease-in-out infinite; }
.flame.t4 { color: #6A3DE8; filter: drop-shadow(0 0 7px rgba(106, 61, 232, .7)); animation: flicker .8s ease-in-out infinite; }
.flame.t4 path + path { fill: #BFE3FF; }
.streak-pill.t2 { background: #FDEBDD; color: #8A3A0B; }
.streak-pill.t3 { background: #FCE1DC; color: #8E1E12; }
.streak-pill.t4 { background: #ECE5FD; color: #3E1F99; }
.streak-chip { align-self: flex-start; display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px 5px 8px; border-radius: 16px;
  background: #FFF3E3; color: #8A3A0B; font-weight: 800; font-size: 14px; }
.streak-chip.t3 { background: #FCE1DC; color: #8E1E12; }
.streak-chip.t4 { background: #ECE5FD; color: #3E1F99; }
.streak-chip.pop { animation: pop .5s cubic-bezier(.2, .9, .3, 1.6) both; }
.streak-burst { position: fixed; left: 50%; top: 38%; transform: translate(-50%, -50%); z-index: 30; pointer-events: none;
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 22px 28px; border-radius: 28px;
  background: rgba(255, 255, 255, .96); box-shadow: 0 18px 50px rgba(35, 32, 28, .25); text-align: center;
  animation: burst 1.9s ease-out forwards; }
.streak-burst strong { font-size: 26px; font-weight: 900; }
.streak-burst span { font-weight: 800; color: var(--accent-ink); }
.stats { display: flex; flex-direction: column; gap: 14px; }
.best-streak { display: flex; align-items: center; gap: 14px; }
.big-num-s { font-size: 24px; font-weight: 900; }
.stat-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.stat-grid > div { background: var(--bg); border-radius: 14px; padding: 10px; display: flex; flex-direction: column; gap: 2px; }
.stat-grid strong { font-size: 18px; }
@keyframes flicker { 0%, 100% { transform: scale(1) rotate(0); } 30% { transform: scale(1.06, .96) rotate(-2deg); } 60% { transform: scale(.97, 1.05) rotate(2deg); } }
@keyframes burst { 0% { opacity: 0; transform: translate(-50%, -50%) scale(.4); } 15% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  25% { transform: translate(-50%, -50%) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -60%) scale(.95); } }
.streak-burst { width: max-content; max-width: 86vw; }
.streak-burst strong, .streak-burst span { white-space: nowrap; }

/* medal = progress ring around the percentage */
.medal.ring-m { border: 0; padding: 4px; background: conic-gradient(var(--c) 0 var(--p), #EDE5D8 var(--p) 100%); }
.medal.ring-m > span { width: 100%; height: 100%; border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.animate .medal.ring-m { animation: pop .5s cubic-bezier(.2, .9, .3, 1.5) both, ring-fill 1.2s cubic-bezier(.3, .7, .3, 1) both; animation-delay: calc(150ms + var(--i, 0) * 60ms); }

/* leaderboard filters: what (big tabs) + period (small tabs) */
.scope-tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; background: #fff; padding: 4px; border-radius: 18px; }
.scope-btn { min-height: 52px; border: 0; border-radius: 14px; background: transparent; font: inherit; font-weight: 800; font-size: 14px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; cursor: pointer; }
.scope-btn.on { background: var(--indigo); color: #fff; }
.period-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.period-tabs { display: inline-flex; background: #EFE8DD; border-radius: 14px; padding: 3px; }
.period-btn { min-height: 36px; border: 0; background: transparent; border-radius: 11px; padding: 0 12px; font: inherit; font-weight: 700; font-size: 13px; color: var(--muted); cursor: pointer; }
.period-btn.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.gear { color: var(--muted); }
.ver-badge { font-size: 12px; font-weight: 800; padding: 4px 10px; border-radius: 12px; background: var(--indigo-soft); color: var(--indigo); }
.changes { margin: 8px 0 0; padding-left: 18px; font-size: 14px; display: flex; flex-direction: column; gap: 4px; }
details summary { cursor: pointer; min-height: 32px; display: flex; align-items: center; }
.notice ul { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.card.notice { background: var(--surface); padding: 18px 20px; border: 0; }

/* weekly ring: keeps filling in a new colour after the goal is reached */
.ring { position: relative; background: conic-gradient(var(--c1, var(--accent)) 0 var(--p), var(--c0, #F1E9DD) var(--p) 100%); }
.lap-badge { position: absolute; top: -4px; right: -6px; color: #fff; font-size: 12px; font-weight: 900; padding: 3px 7px; border-radius: 10px;
  border: 2px solid #fff; animation: pop .5s cubic-bezier(.2, .9, .3, 1.6) .9s both; }

/* ---------------------------------------------------------------- duels (indigo) */
.nav-ic { position: relative; display: inline-flex; }
.nav-badge { position: absolute; top: -6px; right: -10px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent);
  color: #fff; font-size: 11px; font-weight: 900; display: flex; align-items: center; justify-content: center; border: 2px solid #fff; animation: pop .5s both; }
.nav-item.duels.on { color: var(--indigo); }
.nav-item { font-size: 11px; }
.duel-home { display: flex; align-items: center; gap: 12px; border: 0; background: var(--indigo); color: #fff; text-align: left; cursor: pointer; font: inherit;
  animation: breathe 2.4s ease-in-out infinite; }
.duel-home .tiny { color: #D8DAF5; }
.record { display: inline-flex; gap: 6px; align-items: center; font-weight: 800; font-size: 13px; background: #fff; padding: 6px 12px; border-radius: 14px; color: var(--muted); }
.record .w { color: var(--good); } .record .l { color: var(--accent); }
.duel-card { display: flex; flex-direction: column; gap: 12px; }
.duel-card.turn { border: 2px solid var(--indigo); }
.duel-card.plain { border: 0; text-align: left; font: inherit; color: inherit; cursor: pointer; width: 100%; }
.duel-card.plain .row > svg { transform: rotate(180deg); color: var(--muted); }
.duel-av { width: 42px; height: 42px; border-radius: 21px; background: var(--bg); color: var(--ink); display: flex; align-items: center; justify-content: center; font-weight: 900; flex-shrink: 0; }
.duel-av.indigo { background: var(--indigo-soft); color: var(--indigo); }
.score { font-weight: 900; font-size: 18px; margin-right: 8px; }
.res { font-size: 12px; font-weight: 800; padding: 4px 10px; border-radius: 10px; background: var(--bg); color: var(--muted); }
.res.won { background: var(--good-soft); color: var(--good-ink); } .res.lost { background: var(--accent-soft); color: var(--accent-ink); }
.res.draw { background: var(--indigo-soft); color: var(--indigo); }
.animate .duel-card { animation: rise .4s ease-out both; animation-delay: calc(var(--i, 0) * 60ms); }
.pick-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.pick { width: 100%; display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: 18px; border: 0; background: #fff; font: inherit; color: inherit; text-align: left; cursor: pointer; min-height: 60px; }
.pick:disabled { opacity: .55; cursor: not-allowed; }
.pick svg { color: var(--indigo); }
.duel-play .timer { min-width: 54px; height: 44px; border-radius: 22px; background: var(--indigo); color: #fff; font-weight: 900; display: flex; align-items: center; justify-content: center; }
.duel-play .timer.stopped { background: var(--indigo-soft); color: var(--indigo); }
.timebar { height: 8px; border-radius: 4px; background: var(--indigo-soft); overflow: hidden; }
.timebar > div { height: 100%; background: var(--indigo); border-radius: 4px; transition: width .2s linear, background .3s; }
.timebar > div.hurry { background: var(--accent); }
.duel-result { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.duel-result.won { background: linear-gradient(180deg, #FFF3CF, #fff); }
.big-emoji { font-size: 44px; line-height: 1; animation: bounce-in .7s both; }
.scoreline { display: flex; align-items: center; gap: 18px; }
.scoreline b { font-size: 40px; font-weight: 900; }
.scoreline .colon { font-size: 30px; font-weight: 900; color: var(--muted); }
.duel-marks { display: flex; gap: 18px; font-size: 14px; font-weight: 700; }
.duel-marks > div { display: inline-flex; align-items: center; gap: 6px; }
.mk { width: 22px; height: 22px; border-radius: 11px; display: inline-flex; align-items: center; justify-content: center; color: #fff; }
.mk.ok { background: var(--good); } .mk.bad { background: var(--accent); }
.duel-record { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 14px; color: var(--indigo); font-weight: 700; }
.duel-record b { font-weight: 800; color: var(--muted); } .duel-record b.w { color: var(--good-ink); } .duel-record b.l { color: var(--accent-ink); }

/* Stardust: shimmering top medal */
.medal.ring-m.stardust { background: conic-gradient(#8E5BE8, #E36FD0, #F5C842, #5BC0EB, #8E5BE8); animation: spin-glow 6s linear infinite; box-shadow: 0 0 12px rgba(142, 91, 232, .45); }
.medal.ring-m.stardust > span { background: radial-gradient(circle at 30% 30%, #fff, #F3ECFF) !important; }
@keyframes spin-glow { to { filter: hue-rotate(360deg); } }
.duel-btn { width: 36px; height: 36px; background: var(--indigo-soft); color: var(--indigo); margin-left: 6px; }
.lb-row.me .duel-btn { display: none; }
.pod-duel { border: 0; background: var(--indigo-soft); color: var(--indigo); font: inherit; font-size: 12px; font-weight: 800; border-radius: 12px; padding: 4px 10px; display: inline-flex; align-items: center; gap: 4px; cursor: pointer; margin: 2px 0 4px; }
.medal-trophy { display: inline-flex; margin-top: auto; }
.trophy.stardust { filter: drop-shadow(0 0 3px rgba(142, 91, 232, .5)); }
.topic-sub { display: inline-flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.animate .medal-trophy { animation: pop .5s cubic-bezier(.2, .9, .3, 1.6) both; animation-delay: calc(500ms + var(--i, 0) * 60ms); }

/* ---------------------------------------------------------------- glossary */
.gl { display: inline; border: 0; padding: 0; margin: 0; background: none; font: inherit; color: inherit; cursor: pointer;
  text-decoration: underline dotted; text-decoration-color: var(--indigo); text-decoration-thickness: 2px; text-underline-offset: 4px; }
.gl:hover, .gl:focus-visible { color: var(--indigo); }
.answer .gl { pointer-events: none; text-decoration: none; }
.term-sheet .term-def { font-size: 16px; line-height: 1.5; margin: 0; }
.term-sheet .row svg { color: var(--indigo); }
.gl-card { display: flex; align-items: center; gap: 12px; border: 0; font: inherit; color: inherit; text-align: left; cursor: pointer; width: 100%; }
.gl-card > svg:first-child { color: var(--indigo); }
.gl-card > svg:last-child { transform: rotate(180deg); color: var(--muted); }
.gl-letter { font-size: 14px; font-weight: 900; color: var(--indigo); margin: 8px 0 0; }
.gl-item { display: flex; align-items: center; gap: 10px; border: 0; font: inherit; color: inherit; text-align: left; cursor: pointer; width: 100%; padding: 12px 16px; }

/* ---------------------------------------------------------------- new medals on the result screen: one after another */
.new-medal { position: relative; overflow: hidden; gap: 16px; padding: 14px 16px; border: 2px solid transparent;
  background: linear-gradient(#fff, #fff) padding-box, linear-gradient(120deg, var(--fill), var(--rim)) border-box;
  animation: nm-in .6s cubic-bezier(.2, .9, .3, 1.25) both; animation-delay: calc(400ms + var(--i, 0) * 900ms); }
.new-medal::after { content: ''; position: absolute; inset: 0; background: linear-gradient(100deg, transparent 30%, rgba(255, 255, 255, .8) 50%, transparent 70%);
  transform: translateX(-120%); animation: nm-shine 1.1s ease-out both; animation-delay: calc(1200ms + var(--i, 0) * 900ms); pointer-events: none; }
.nm-badge { position: relative; width: 58px; height: 58px; border-radius: 50%; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 35% 30%, #fff, var(--fill)); border: 3px solid var(--rim);
  animation: nm-drop .7s cubic-bezier(.2, .9, .3, 1.5) both; animation-delay: calc(650ms + var(--i, 0) * 900ms); }
.nm-glow { position: absolute; inset: -3px; border-radius: 50%; box-shadow: 0 0 0 0 var(--rim); opacity: .6;
  animation: nm-glow 1.2s ease-out both; animation-delay: calc(1100ms + var(--i, 0) * 900ms); }
.spark { position: absolute; left: 50%; top: 50%; width: 6px; height: 6px; margin: -3px; border-radius: 50%; background: var(--rim); opacity: 0;
  animation: nm-spark .8s ease-out both; animation-delay: calc(1050ms + var(--i, 0) * 900ms); }
.spark:nth-of-type(even) { background: #F5C842; width: 5px; height: 5px; }
.nm-kicker { text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-size: 11px; }
.nm-title { font-size: 20px; font-weight: 900; line-height: 1.15; }
.nm-next { color: var(--indigo); font-weight: 700; margin-top: 2px; }
.new-medals.shown .new-medal, .new-medals.shown .new-medal::after, .new-medals.shown .nm-badge, .new-medals.shown .nm-glow, .new-medals.shown .spark { animation: none; }
.confetti.mini i { animation-duration: 2.2s !important; }
@keyframes nm-in { 0% { opacity: 0; transform: translateX(60px) scale(.9); } 100% { opacity: 1; transform: none; } }
@keyframes nm-drop { 0% { opacity: 0; transform: translateY(-40px) scale(.3) rotate(-25deg); } 70% { opacity: 1; transform: translateY(4px) scale(1.12) rotate(6deg); } 100% { transform: none; } }
@keyframes nm-glow { 0% { box-shadow: 0 0 0 0 var(--rim); opacity: .7; } 100% { box-shadow: 0 0 0 18px var(--rim); opacity: 0; } }
@keyframes nm-shine { to { transform: translateX(120%); } }
@keyframes nm-spark { 0% { opacity: 1; transform: rotate(var(--a)) translateX(10px) scale(1); } 100% { opacity: 0; transform: rotate(var(--a)) translateX(46px) scale(.4); } }

/* ---------------------------------------------------------------- big "+points" burst after a correct answer */
.pts-burst { position: fixed; left: 50%; top: 42%; z-index: 40; pointer-events: none; width: 0; height: 0; }
.pts-burst b { position: absolute; left: 0; top: 0; transform: translate(-50%, -50%); font-size: 54px; font-weight: 900; white-space: nowrap;
  color: var(--good); text-shadow: 0 4px 0 #fff, 0 8px 24px rgba(31, 122, 77, .35); animation: pts-pop 1.4s cubic-bezier(.2, .9, .3, 1.2) forwards; }
.pts-burst i { position: absolute; left: -5px; top: -5px; width: 10px; height: 10px; border-radius: 50%; background: #F5C842; opacity: 0;
  animation: pts-spark .9s ease-out .1s forwards; }
.pts-burst i:nth-child(odd) { background: var(--good); width: 7px; height: 7px; }
@keyframes pts-pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.3); }
  25% { opacity: 1; transform: translate(-50%, -50%) scale(1.25); }
  45% { transform: translate(-50%, -50%) scale(1); }
  75% { opacity: 1; transform: translate(-50%, -80%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -160%) scale(.7); }
}
@keyframes pts-spark { 0% { opacity: 1; transform: rotate(var(--a)) translateX(20px); } 100% { opacity: 0; transform: rotate(var(--a)) translateX(95px) scale(.4); } }
.pts.pop { animation: pts-pill 1.1s cubic-bezier(.2, .9, .3, 1.6) .35s both; }
@keyframes pts-pill { 0% { transform: scale(.4); opacity: 0; } 50% { transform: scale(1.25); opacity: 1; background: #FFF3CF; } 100% { transform: scale(1); } }

/* ---------------------------------------------------------------- favorite star */
.save-star { position: relative; display: inline-flex; }
.save-btn.just-saved { animation: fav-btn .6s cubic-bezier(.2, .9, .3, 1.5); }
.save-btn.just-saved .save-star svg { animation: fav-star .8s cubic-bezier(.2, .9, .3, 1.4); }
.save-star i { position: absolute; left: 50%; top: 50%; width: 5px; height: 5px; margin: -2.5px; border-radius: 50%; background: #D9A520; opacity: 0;
  animation: fav-spark .7s ease-out .15s forwards; }
.save-btn.just-unsaved .save-star svg { animation: fav-off .35s ease-in; }
@keyframes fav-btn { 0% { transform: scale(1); } 35% { transform: scale(1.12); background: #FFE8A3; } 100% { transform: scale(1); } }
@keyframes fav-star { 0% { transform: scale(.4) rotate(-90deg); } 60% { transform: scale(1.6) rotate(20deg); } 100% { transform: scale(1) rotate(0); } }
@keyframes fav-spark { 0% { opacity: 1; transform: rotate(var(--a)) translateX(6px); } 100% { opacity: 0; transform: rotate(var(--a)) translateX(24px) scale(.5); } }
@keyframes fav-off { 50% { transform: scale(.6); } 100% { transform: scale(1); } }

/* status bar: a cream band behind the iPhone status bar. It starts above the visible page, because iOS draws
   scrolled content under the status bar even where the page itself reports no safe area. */
body::before { top: -120px; height: calc(120px + env(safe-area-inset-top)); }
html { background: var(--bg); }
@media (prefers-reduced-motion: reduce) { .pts-burst { display: none; } }

/* ---------------------------------------------------------------- feedback sequence (about 2 s in total)
   0.0 s answer glows · 0.05 s big +points · 0.55 s points pill counts up · 1.0 s streak chip · 1.25 s streak milestone */
.pts-burst b { animation-duration: .95s; }
.pts-burst i { animation-duration: .7s; animation-delay: .1s; }
.pts.pop { animation: pts-pill .6s cubic-bezier(.2, .9, .3, 1.6) .55s both; }
.streak-chip.pop { animation: pop .5s cubic-bezier(.2, .9, .3, 1.6) 1s both; }
.streak-burst { animation: burst 1.6s ease-out 1.25s both; }

/* ---------------------------------------------------------------- calmer timing (about 3 s) and a badge behind +points
   0.1 s +points badge (1.5 s) · 1.0 s pill counts up · 1.7 s streak chip · 2.1 s streak milestone */
.pts-burst b { padding: 10px 26px; border-radius: 26px; background: #fff; border: 3px solid var(--good-soft);
  box-shadow: 0 12px 34px rgba(35, 32, 28, .22); text-shadow: none; font-size: 46px;
  animation: pts-pop 1.5s cubic-bezier(.2, .9, .3, 1.2) .1s both; }
.pts-burst i { animation: pts-spark .8s ease-out .25s forwards; }
.pts.pop { animation: pts-pill .7s cubic-bezier(.2, .9, .3, 1.6) 1s both; }
.streak-chip.pop { animation: pop .55s cubic-bezier(.2, .9, .3, 1.6) 1.7s both; }
.streak-burst { animation: burst 1.8s ease-out 2.1s both; }
@keyframes pts-pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.3); }
  22% { opacity: 1; transform: translate(-50%, -50%) scale(1.15); }
  38% { transform: translate(-50%, -50%) scale(1); }
  75% { opacity: 1; transform: translate(-50%, -60%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -130%) scale(.75); }
}
@keyframes pts-spark { 0% { opacity: 1; transform: rotate(var(--a)) translateX(78px); } 100% { opacity: 0; transform: rotate(var(--a)) translateX(140px) scale(.4); } }

/* ---------------------------------------------------------------- smoother feedback motion
   Only transform and opacity are animated (runs on the graphics chip, no jank), with soft "ease-out" curves. */
.answer { position: relative; }
.answer.right { animation: right-in .45s cubic-bezier(.22, 1, .36, 1); }
.answer.right::after { content: ''; position: absolute; inset: -2px; border-radius: inherit; border: 3px solid var(--good); opacity: 0;
  pointer-events: none; animation: right-ring .9s cubic-bezier(.22, 1, .36, 1) both; }
@keyframes right-in { 0% { transform: scale(.97); } 60% { transform: scale(1.02); } 100% { transform: scale(1); } }
@keyframes right-ring { 0% { opacity: .55; transform: scale(1); } 100% { opacity: 0; transform: scale(1.06, 1.25); } }

.pts-burst b, .pts-burst i, .pts.pop, .streak-chip.pop, .feedback.enter { will-change: transform, opacity; backface-visibility: hidden; }
.pts-burst b { animation: pts-pop2 1.6s linear .1s both; }
@keyframes pts-pop2 {
  0%   { opacity: 0; transform: translate3d(-50%, -50%, 0) scale(.5); animation-timing-function: cubic-bezier(.34, 1.56, .64, 1); }
  20%  { opacity: 1; transform: translate3d(-50%, -50%, 0) scale(1); animation-timing-function: linear; }
  62%  { opacity: 1; transform: translate3d(-50%, -54%, 0) scale(1); animation-timing-function: cubic-bezier(.55, 0, .45, 1); }
  100% { opacity: 0; transform: translate3d(-50%, -125%, 0) scale(.85); }
}
.pts-burst i { animation: pts-spark2 .9s cubic-bezier(.22, 1, .36, 1) .3s both; }
@keyframes pts-spark2 { 0% { opacity: 0; transform: rotate(var(--a)) translate3d(70px, 0, 0) scale(1); } 15% { opacity: 1; }
  100% { opacity: 0; transform: rotate(var(--a)) translate3d(135px, 0, 0) scale(.3); } }

.pts.pop { animation: pts-pill2 .75s cubic-bezier(.34, 1.56, .64, 1) 1s both; }
@keyframes pts-pill2 { 0% { opacity: 0; transform: scale(.6); } 100% { opacity: 1; transform: scale(1); } }
.streak-chip.pop { animation: chip-in .6s cubic-bezier(.34, 1.56, .64, 1) 1.7s both; }
@keyframes chip-in { 0% { opacity: 0; transform: translate3d(-12px, 0, 0) scale(.85); } 100% { opacity: 1; transform: none; } }
.feedback.enter { animation: fb-in .5s cubic-bezier(.22, 1, .36, 1) both; }
@keyframes fb-in { 0% { opacity: 0; transform: translate3d(0, 16px, 0); } 100% { opacity: 1; transform: none; } }
