/* Times Table Legends */
@font-face { font-family: "Cinzel"; src: url("fonts/cinzel.woff2") format("woff2"); font-weight: 400 900; font-display: swap; }
@font-face { font-family: "Inter"; src: url("fonts/inter.woff2") format("woff2"); font-weight: 400 800; font-display: swap; }

:root {
  --navy-950: #050818; --navy-900: #080c22; --navy-800: #0e1538; --navy-700: #16215a; --navy-600: #1f2f7a;
  --gold-200: #fff3c4; --gold-300: #ffe08a; --gold-400: #ffd166; --gold-500: #f5b93a; --gold-600: #d9951f; --gold-800: #7a4a08;
  --green: #3ddc84; --green-d: #0f7a3d; --red: #ff4d5e; --red-d: #8f1424; --purple: #8b6cff; --ice: #7fd4ff;
  --text: #eef1ff; --muted: #a9b2dc;
  --title: "Cinzel", "Trajan Pro", Georgia, serif; --body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px); --sal: env(safe-area-inset-left, 0px); --sar: env(safe-area-inset-right, 0px);
  --ease-out: cubic-bezier(.2, .9, .25, 1); --spring: cubic-bezier(.3, 1.6, .5, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html { font-size: clamp(14px, 1.1vw + 1.1vh, 22px); -webkit-text-size-adjust: 100%; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--navy-950); overscroll-behavior: none; }
body {
  position: fixed; inset: 0; color: var(--text); font-family: var(--body); font-weight: 600;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; touch-action: manipulation; }
svg { display: block; fill: currentColor; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
h1, h2, p { margin: 0; }
b { font-weight: inherit; } i { font-style: normal; }

#app { position: absolute; inset: 0; overflow: hidden; }

/* ================= Scene ================= */
.scene { position: absolute; inset: 0; overflow: hidden; }
.sky { position: absolute; inset: 0; background:
  radial-gradient(120% 60% at 12% 72%, rgba(255, 150, 90, .55), transparent 60%),
  radial-gradient(90% 55% at 80% 30%, rgba(140, 100, 255, .38), transparent 65%),
  linear-gradient(180deg, #050818 0%, #0d1242 28%, #2a1f7a 52%, #6a3fa0 70%, #c0688c 84%, #2a1b55 100%); }
#bg, #fx { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#fx { z-index: 60; }
.aurora { position: absolute; inset: -20% -10% 40% -10%; background:
  radial-gradient(40% 50% at 30% 40%, rgba(110, 200, 255, .16), transparent 70%),
  radial-gradient(35% 45% at 70% 30%, rgba(190, 120, 255, .18), transparent 70%);
  filter: blur(20px); animation: drift 18s ease-in-out infinite alternate; }
@keyframes drift { to { transform: translate3d(4%, 3%, 0) scale(1.08); } }
.mountains { position: absolute; left: 0; bottom: 0; width: 100%; height: 100%; }

.castle-wrap, .hero-wrap { position: absolute; transition: opacity .6s ease, transform .8s var(--ease-out), filter .6s ease; will-change: transform, opacity; }
.castle-wrap { left: 50%; top: 21dvh; width: min(74vw, 44dvh); margin-left: calc(min(74vw, 44dvh) / -2 + 4vw); }
.castle { width: 100%; height: auto; overflow: visible; animation: float 7s ease-in-out infinite; filter: drop-shadow(0 0 26px rgba(184, 132, 255, .45)); }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-2.2%); } }
.ring-spin { transform-origin: 250px 215px; animation: spin 60s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.windows { animation: flicker 3.2s ease-in-out infinite; }
@keyframes flicker { 0%, 100% { opacity: 1; } 45% { opacity: .72; } 60% { opacity: .95; } }

.hero-wrap { left: 50%; bottom: 0; top: 37dvh; width: 28dvh; margin-left: -17dvh; overflow: hidden; }
.hero { position: absolute; left: 0; top: 0; width: 100%; height: 84dvh; overflow: visible; filter: drop-shadow(-6px 6px 18px rgba(0, 0, 0, .55)); }
.cape { transform-origin: 216px 122px; animation: cape 4.6s ease-in-out infinite; }
@keyframes cape { 0%, 100% { transform: skewX(0) scaleX(1); } 35% { transform: skewX(3deg) scaleX(1.05); } 70% { transform: skewX(-2deg) scaleX(.97); } }

@media (orientation: landscape) {
  .castle-wrap { left: auto; right: 9vw; top: 3dvh; width: min(44vw, 66dvh); margin-left: 0; }
  .hero-wrap { left: auto; right: calc(9vw + min(44vw, 66dvh) * .38); top: 34dvh; width: 50dvh; margin-left: 0; }
  .hero { height: 150dvh; }
}

/* Painted backdrops: menu key art, and a calmer arena for every other screen. */
.art { position: absolute; inset: 0; overflow: hidden; }
.art img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .7s ease; }
.art-menu { object-position: 88% 18%; transform-origin: 75% 12%; animation: kenburns 36s ease-in-out infinite alternate; }
.art-arena { object-position: 50% 50%; }
@media (orientation: portrait) {
  .art-menu { object-position: 50% 50%; transform-origin: 50% 40%; }
  .art-arena { object-position: 10% 50%; }
}
@keyframes kenburns { from { transform: scale(1); } to { transform: scale(1.07); } }
#app.has-art[data-screen="menu"] .art-menu, #app.has-art:not([data-screen="menu"]) .art-arena { opacity: 1; }
#app.has-art .mountains, #app.has-art .castle-wrap, #app.has-art .hero-wrap, #app.has-art .aurora { display: none; }
#app.has-art:not([data-screen="menu"]) .vignette { background-color: rgba(5, 8, 24, .28); }
#app.has-art[data-screen="menu"] .vignette { background: radial-gradient(130% 100% at 50% 45%, transparent 60%, rgba(3, 5, 16, .6) 100%), linear-gradient(180deg, rgba(5, 8, 24, .35), transparent 30%, transparent 62%, rgba(5, 8, 24, .55)); }

/* Low-time warning: red glow at the screen edges. */
#app.danger .vignette { box-shadow: inset 0 0 110px rgba(255, 40, 60, .6); animation: dangerPulse 1s ease-in-out infinite; }
@keyframes dangerPulse { 50% { box-shadow: inset 0 0 60px rgba(255, 40, 60, .3); } }

.vignette { position: absolute; inset: 0; background: radial-gradient(120% 90% at 50% 45%, transparent 55%, rgba(3, 5, 16, .78) 100%); transition: background-color .5s ease; }
#app:not([data-screen="menu"]) .vignette { background-color: rgba(5, 8, 24, .62); }
#app:not([data-screen="menu"]) .hero-wrap { opacity: 0; transform: translateY(6%); }
#app:not([data-screen="menu"]) .castle-wrap { opacity: .32; filter: blur(3px); transform: scale(1.12); }

/* ================= Screens ================= */
#stage { position: absolute; inset: 0; z-index: 10; }
.screen {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  padding: calc(var(--sat) + .9rem) calc(var(--sar) + 1rem) calc(var(--sab) + .9rem) calc(var(--sal) + 1rem);
  opacity: 0; visibility: hidden; pointer-events: none; transform: scale(1.03);
  transition: opacity .32s ease, transform .42s var(--ease-out), visibility 0s linear .42s;
}
.screen.active { opacity: 1; visibility: visible; pointer-events: auto; transform: none; transition-delay: .08s, .08s, 0s; }

.title { font-family: var(--title); font-weight: 800; font-size: 1.55rem; letter-spacing: .02em; text-align: center;
  background: linear-gradient(180deg, var(--gold-200), var(--gold-400) 45%, var(--gold-600)); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 2px 0 rgba(40, 20, 0, .8)) drop-shadow(0 0 14px rgba(255, 180, 60, .35)); }

.panel {
  position: relative; border-radius: 18px; border: 1.5px solid rgba(245, 185, 58, .6);
  background: linear-gradient(180deg, rgba(22, 33, 90, .82), rgba(8, 12, 34, .92));
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .6), 0 18px 50px rgba(0, 0, 0, .55), inset 0 1px 0 rgba(255, 255, 255, .12), inset 0 0 40px rgba(60, 90, 220, .18);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
.panel::before, .panel::after { content: ""; position: absolute; width: 22px; height: 22px; border: 2.5px solid var(--gold-400); pointer-events: none; }
.panel::before { left: 7px; top: 7px; border-right: 0; border-bottom: 0; border-radius: 8px 0 0 0; }
.panel::after { right: 7px; bottom: 7px; border-left: 0; border-top: 0; border-radius: 0 0 8px 0; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: .8rem; margin-bottom: .8rem; flex: none; }
.topbar-spacer { width: 3rem; }

/* ================= Buttons ================= */
.btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: .6rem;
  min-height: 3rem; padding: .55rem 1.3rem; border-radius: 14px; overflow: hidden;
  font-weight: 800; font-size: 1.05rem; letter-spacing: .01em; color: var(--text);
  background: linear-gradient(180deg, #223070, #111a47 60%, #0b1132);
  border: 1.5px solid rgba(245, 185, 58, .75);
  box-shadow: 0 4px 0 #04061a, 0 10px 22px rgba(0, 0, 0, .5), inset 0 1px 0 rgba(255, 255, 255, .22), inset 0 0 18px rgba(80, 110, 255, .22);
  text-shadow: 0 2px 2px rgba(0, 0, 0, .6);
  transition: transform .09s ease, box-shadow .09s ease, filter .15s ease;
}
.btn svg { width: 1.35rem; height: 1.35rem; color: var(--gold-400); flex: none; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .6)); }
.btn:active, .btn.pressed { transform: translateY(3px); box-shadow: 0 1px 0 #04061a, 0 4px 10px rgba(0, 0, 0, .5), inset 0 1px 0 rgba(255, 255, 255, .2); filter: brightness(1.15); }
.btn-primary {
  color: #2b1600; text-shadow: 0 1px 0 rgba(255, 255, 255, .45);
  background: linear-gradient(180deg, #fff0b0 0%, var(--gold-400) 22%, var(--gold-500) 55%, #c9871b 100%);
  border-color: #fff1bd;
  box-shadow: 0 4px 0 var(--gold-800), 0 0 26px rgba(255, 190, 70, .55), 0 10px 22px rgba(0, 0, 0, .5), inset 0 2px 0 rgba(255, 255, 255, .7), inset 0 -6px 12px rgba(150, 80, 0, .35);
}
.btn-primary svg { color: #3a2000; filter: none; }
.btn-primary:active { box-shadow: 0 1px 0 var(--gold-800), 0 0 18px rgba(255, 190, 70, .5), inset 0 2px 0 rgba(255, 255, 255, .6); }
.btn-primary::after { content: ""; position: absolute; top: 0; bottom: 0; left: -60%; width: 40%; transform: skewX(-20deg);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .75), transparent); animation: shine 3.6s ease-in-out infinite; }
@keyframes shine { 0%, 55% { left: -60%; } 80%, 100% { left: 130%; } }
.btn-xl { width: 100%; min-height: 3.4rem; font-size: 1.3rem; justify-content: flex-start; padding-left: 1.6rem; gap: 1.1rem; }
.btn-xl svg { width: 1.7rem; height: 1.7rem; }
.btn-wide { width: 100%; }
.btn-danger { border-color: rgba(255, 110, 120, .8); background: linear-gradient(180deg, #7a1c2c, #3d0c16); min-height: 2.6rem; font-size: .95rem; }
.btn-danger.confirm { background: linear-gradient(180deg, #ff5a6a, #b01c30); }

.icon-btn { width: 3rem; height: 3rem; flex: none; display: grid; place-items: center; border-radius: 12px; color: var(--gold-400);
  background: linear-gradient(180deg, #223070, #0b1132); border: 1.5px solid rgba(245, 185, 58, .75);
  box-shadow: 0 3px 0 #04061a, inset 0 1px 0 rgba(255, 255, 255, .22); transition: transform .09s ease; }
.icon-btn svg { width: 1.5rem; height: 1.5rem; }
.icon-btn:active { transform: translateY(3px); filter: brightness(1.2); }
.link-btn { color: var(--muted); font-size: .95rem; padding: .8rem 1rem; text-decoration: underline; text-underline-offset: 4px; }

.hex { display: grid; place-items: center; width: 2.7rem; height: 2.7rem; flex: none; color: #3a2000;
  background: linear-gradient(180deg, #fff0b0, var(--gold-500) 60%, #c9871b);
  clip-path: polygon(50% 0, 95% 25%, 95% 75%, 50% 100%, 5% 75%, 5% 25%); }
.hex svg { width: 1.4rem; height: 1.4rem; }

/* ================= Menu ================= */
#screen-menu { align-items: center; }
.menu-col { flex: 1; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: space-between; min-height: 0; }
.logo { display: flex; flex-direction: column; align-items: center; text-align: center; margin-top: 2.5dvh; font-family: var(--title); line-height: .92; animation: logoIn 1.1s var(--ease-out) both; }
@keyframes logoIn { from { opacity: 0; transform: translateY(-18px) scale(.94); filter: blur(6px); } }
.crest { width: 5.2rem; height: 2.6rem; margin-bottom: -.35rem; filter: drop-shadow(0 0 10px rgba(127, 212, 255, .9)); animation: pulse 3s ease-in-out infinite; }
@keyframes pulse { 50% { filter: drop-shadow(0 0 20px rgba(127, 212, 255, 1)); transform: scale(1.05); } }
.logo .l1, .logo .l2 { display: block; font-weight: 900; text-transform: uppercase;
  background: linear-gradient(180deg, #fff6cf 0%, #ffd980 28%, #f0a82e 58%, #8a4f0c 100%); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 3px 0 #3a1f00) drop-shadow(0 6px 4px rgba(0, 0, 0, .6)) drop-shadow(0 0 22px rgba(255, 170, 50, .5)); }
.logo .l1 { font-size: clamp(2rem, 10.5vw, 3.6rem); letter-spacing: .01em; }
.logo .l2 { font-size: clamp(2.8rem, 15vw, 5.2rem); letter-spacing: .02em; }
.logo .tag { margin-top: .7rem; font-family: var(--body); font-weight: 700; font-size: .78rem; letter-spacing: .2em; text-transform: uppercase; color: #e6e9ff; text-shadow: 0 2px 6px #000; }
.logo .tag i { color: var(--gold-400); margin: 0 .3em; }
.menu-buttons { width: min(100%, 19rem); display: flex; flex-direction: column; gap: .7rem; margin-bottom: 1.5dvh; }
.menu-buttons .btn { animation: riseIn .6s var(--ease-out) both; }
.menu-buttons .btn:nth-child(1) { animation-delay: .25s; } .menu-buttons .btn:nth-child(2) { animation-delay: .33s; }
.menu-buttons .btn:nth-child(3) { animation-delay: .41s; } .menu-buttons .btn:nth-child(4) { animation-delay: .49s; }
@keyframes riseIn { from { opacity: 0; transform: translateY(22px); } }

.rank-chip { position: absolute; z-index: 2; top: calc(var(--sat) + .8rem); right: calc(var(--sar) + .9rem); display: flex; align-items: center; gap: .5rem;
  padding: .3rem .9rem .3rem .35rem; border-radius: 999px; background: rgba(8, 12, 34, .72); border: 1.5px solid rgba(245, 185, 58, .6); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.rank-chip .hex { width: 2.2rem; height: 2.2rem; } .rank-chip .hex svg { width: 1.1rem; height: 1.1rem; }
.rank-text, .level-text { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; }
.rank-text b, .level-text b { font-size: .9rem; font-weight: 800; color: var(--gold-300); }
.rank-text i, .level-text i { font-size: .72rem; color: var(--muted); }

@media (orientation: portrait) {
  .rank-chip { display: none; }
}
@media (orientation: landscape) {
  #screen-menu { align-items: flex-start; }
  .menu-col { width: min(46vw, 34rem); justify-content: center; gap: 2.2rem; margin-left: 3vw; }
  .logo { margin-top: 0; }
  .logo .l1 { font-size: clamp(1.8rem, 5vw, 3.6rem); } .logo .l2 { font-size: clamp(2.5rem, 7.2vw, 5.2rem); }
}
@media (orientation: landscape) and (max-height: 520px) {
  .menu-col { gap: 1rem; }
  .crest { width: 3.6rem; height: 1.8rem; }
  .logo .l1 { font-size: 1.9rem; } .logo .l2 { font-size: 2.7rem; }
  .menu-buttons { width: min(100%, 26rem); display: grid; grid-template-columns: 1fr 1fr; gap: .55rem; }
  .menu-buttons .btn:first-child { grid-column: 1 / -1; justify-content: center; padding-left: 1.3rem; }
  .btn-xl { min-height: 3rem; font-size: 1.05rem; padding-left: 1rem; gap: .7rem; }
}

/* ================= Table select ================= */
.tables-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 1rem; padding: 1.2rem; width: min(100%, 46rem); align-self: center; }
.table-grid { flex: 1; min-height: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: .7rem; }
.table-btn { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .15rem; border-radius: 14px; min-height: 3.2rem;
  font-family: var(--title); font-weight: 900; font-size: 1.7rem; color: var(--gold-300);
  background: linear-gradient(180deg, #1d2a66, #0b1132); border: 1.5px solid rgba(245, 185, 58, .55);
  box-shadow: 0 4px 0 #04061a, inset 0 1px 0 rgba(255, 255, 255, .18), inset 0 0 20px rgba(80, 110, 255, .2); text-shadow: 0 2px 3px #000;
  transition: transform .09s ease, filter .12s ease; animation: popIn .45s var(--spring) both; }
.table-btn:active { transform: translateY(3px) scale(.97); filter: brightness(1.3); }
.table-btn.mastered { border-color: var(--gold-300); box-shadow: 0 4px 0 #04061a, 0 0 18px rgba(255, 200, 80, .5), inset 0 0 22px rgba(255, 190, 70, .28); }
.mini-stars { display: flex; gap: 2px; } .mini-stars svg { width: .8rem; height: .8rem; color: rgba(255, 255, 255, .16); }
.mini-stars svg.on { color: var(--gold-400); filter: drop-shadow(0 0 4px rgba(255, 200, 80, .9)); }
@keyframes popIn { from { opacity: 0; transform: scale(.6); } }
@media (orientation: landscape) { .table-grid { grid-template-columns: repeat(4, 1fr); } .table-btn { font-size: 1.9rem; } }
@media (orientation: landscape) and (max-height: 520px) { .table-grid { grid-template-columns: repeat(6, 1fr); } .tables-panel { padding: .8rem; gap: .6rem; } .topbar { margin-bottom: .4rem; } }

/* ================= Game ================= */
.hud { display: flex; align-items: center; gap: .8rem; flex: none; }
.level-badge { display: flex; align-items: center; gap: .5rem; padding: .25rem .9rem .25rem .3rem; border-radius: 999px; background: rgba(8, 12, 34, .78); border: 1.5px solid rgba(245, 185, 58, .6); }
.hud-score { margin-left: auto; display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; }
.hud-score span { font-size: .65rem; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.hud-score b { font-size: 1.25rem; font-weight: 800; color: var(--gold-300); font-variant-numeric: tabular-nums; }
.hearts { display: flex; gap: .25rem; }
.hearts svg { width: 1.7rem; height: 1.7rem; color: var(--red); filter: drop-shadow(0 0 6px rgba(255, 60, 80, .8)) drop-shadow(0 2px 1px #000); transition: transform .3s var(--spring), color .3s, filter .3s; }
.hearts svg.lost { color: #2a2f55; filter: none; transform: scale(.8); }
.hearts svg.break { animation: heartBreak .5s ease; }
@keyframes heartBreak { 30% { transform: scale(1.5) rotate(-12deg); } }

.qbar { position: relative; flex: none; height: .9rem; margin-top: .7rem; border-radius: 999px; background: rgba(5, 8, 24, .8); border: 1px solid rgba(245, 185, 58, .45); overflow: hidden; }
.qbar-fill { height: 100%; width: 0; border-radius: 999px; background: linear-gradient(90deg, #f5b93a, #fff0b0); box-shadow: 0 0 12px rgba(255, 200, 80, .8); transition: width .5s var(--ease-out); }
.qbar span { position: absolute; inset: 0; display: grid; place-items: center; font-size: .62rem; font-weight: 800; letter-spacing: .08em; color: #fff; text-shadow: 0 1px 2px #000; }

.arena { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1.2rem; }
.combo { height: 1.6rem; font-family: var(--title); font-weight: 900; font-size: 1.25rem; color: #ffb347; text-shadow: 0 0 14px rgba(255, 140, 40, .9), 0 2px 0 #3a1f00; opacity: 0; transform: scale(.6); transition: opacity .2s, transform .3s var(--spring); }
.combo.show { opacity: 1; transform: scale(1); }
.question { font-family: var(--title); font-weight: 900; font-size: clamp(3.2rem, 15vmin, 7.5rem); line-height: 1; letter-spacing: .02em; color: #fff; white-space: nowrap;
  text-shadow: 0 4px 0 #1a1440, 0 0 30px rgba(140, 170, 255, .65), 0 10px 20px rgba(0, 0, 0, .6); }
.question.enter { animation: qIn .45s var(--spring) both; }
.question .op { color: var(--gold-400); margin: 0 .12em; } .question .qm { color: var(--ice); }
@keyframes qIn { from { opacity: 0; transform: translateY(16px) scale(.8); } }
.arena.waiting .play-row { opacity: 0; }
.play-row { transition: opacity .25s ease; width: 100%; display: flex; flex-direction: column-reverse; align-items: center; gap: 1.2rem; }
.answers { width: min(100%, 30rem); display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.answer { min-height: 4.4rem; border-radius: 16px; font-size: 2.2rem; font-weight: 800; color: #fff; font-variant-numeric: tabular-nums;
  background: linear-gradient(180deg, #24327a, #0e1540 65%, #0a0f30); border: 2px solid rgba(245, 185, 58, .7);
  box-shadow: 0 5px 0 #04061a, 0 12px 24px rgba(0, 0, 0, .5), inset 0 1px 0 rgba(255, 255, 255, .25), inset 0 0 24px rgba(80, 110, 255, .25);
  text-shadow: 0 2px 3px #000; transition: transform .09s ease, filter .12s ease, opacity .25s ease; }
.answer.enter { animation: popIn .4s var(--spring) both; }
.answer:active { transform: translateY(4px); filter: brightness(1.3); }
.answer.right { background: linear-gradient(180deg, #5cf0a0, #1aa35a 60%, #0f7a3d); border-color: #c9ffe0; box-shadow: 0 5px 0 #06401f, 0 0 34px rgba(61, 220, 132, .85); animation: rightPop .45s var(--spring); }
.answer.wrong { background: linear-gradient(180deg, #ff7381, #c2283a 60%, #8f1424); border-color: #ffd0d5; box-shadow: 0 5px 0 #4a0810, 0 0 30px rgba(255, 77, 94, .8); animation: shakeX .4s ease; }
.answer.dim { opacity: .35; }
@keyframes rightPop { 40% { transform: scale(1.12); } }
@keyframes shakeX { 20% { transform: translateX(-9px); } 40% { transform: translateX(8px); } 60% { transform: translateX(-6px); } 80% { transform: translateX(4px); } }

.timer { position: relative; width: 5.2rem; height: 5.2rem; flex: none; }
.timer svg { width: 100%; height: 100%; transform: rotate(-90deg); fill: none; }
.timer-track { stroke: rgba(5, 8, 24, .85); stroke-width: 9; fill: rgba(8, 12, 34, .8); }
.timer-ring { stroke: var(--gold-400); stroke-width: 7; stroke-linecap: round; stroke-dasharray: 270.2; stroke-dashoffset: 0; filter: drop-shadow(0 0 6px rgba(255, 200, 80, .9)); transition: stroke .3s; }
.timer b { position: absolute; inset: 0; display: grid; place-items: center; font-size: 1.9rem; font-weight: 800; font-variant-numeric: tabular-nums; text-shadow: 0 2px 3px #000; }
.timer.low .timer-ring { stroke: var(--red); filter: drop-shadow(0 0 8px rgba(255, 77, 94, 1)); }
.timer.low b { color: #ffb3ba; animation: tick 1s ease infinite; }
.timer.off { opacity: .45; }
@keyframes tick { 0%, 100% { transform: scale(1); } 12% { transform: scale(1.22); } }

@media (orientation: portrait) and (min-height: 700px) {
  .arena { gap: 1.6rem; } .answers { gap: 1rem; }
  .answer { min-height: 5.4rem; font-size: 2.5rem; } .timer { width: 6rem; height: 6rem; }
}
@media (orientation: landscape) {
  .play-row { flex-direction: row; justify-content: center; gap: 1.6rem; }
  .answers { width: min(62%, 34rem); }
  .timer { width: 6.4rem; height: 6.4rem; }
  .arena { gap: 1rem; }
}
@media (orientation: landscape) and (max-height: 520px) {
  .arena { gap: .35rem; } .combo { height: 1.1rem; font-size: 1rem; }
  .question { font-size: 3.4rem; } .answer { min-height: 3.2rem; font-size: 1.7rem; } .answers { gap: .55rem; }
  .qbar { margin-top: .4rem; } .timer { width: 5rem; height: 5rem; }
}

#stage.shake { animation: shake .45s ease; }
@keyframes shake { 15% { transform: translate(-10px, 4px) rotate(-.6deg); } 30% { transform: translate(9px, -3px) rotate(.5deg); } 45% { transform: translate(-7px, 2px); } 60% { transform: translate(5px, -2px); } 80% { transform: translate(-2px, 1px); } }

/* ================= Overlays ================= */
.overlay { position: absolute; inset: 0; z-index: 40; display: grid; place-items: center; padding: calc(var(--sat) + 1rem) 1.2rem calc(var(--sab) + 1rem);
  background: rgba(4, 6, 20, .72); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  opacity: 0; visibility: hidden; pointer-events: none; transition: opacity .22s ease, visibility 0s linear .22s; }
.overlay.show { opacity: 1; visibility: visible; pointer-events: auto; transition-delay: 0s; }
.feedback.good { background: radial-gradient(90% 70% at 50% 50%, rgba(30, 170, 90, .6), rgba(3, 26, 14, .9) 75%); }
.feedback.bad { background: radial-gradient(90% 70% at 50% 50%, rgba(190, 30, 50, .6), rgba(30, 4, 10, .92) 75%); }
.feedback-card { position: relative; width: min(100%, 27rem); display: flex; flex-direction: column; align-items: center; gap: 1.2rem; padding: 2.6rem 1.4rem 1.5rem; border-radius: 20px;
  background: linear-gradient(180deg, rgba(10, 16, 44, .9), rgba(5, 8, 24, .95)); border: 2px solid var(--green);
  box-shadow: 0 0 50px rgba(61, 220, 132, .55), inset 0 0 40px rgba(61, 220, 132, .2); transform: scale(.7); opacity: 0; }
.feedback.bad .feedback-card { border-color: var(--red); box-shadow: 0 0 50px rgba(255, 77, 94, .55), inset 0 0 40px rgba(255, 77, 94, .2); }
.overlay.show .feedback-card, .overlay.show .pause-card { animation: cardIn .4s var(--spring) forwards; }
@keyframes cardIn { to { transform: scale(1); opacity: 1; } }

.ribbon { position: relative; padding: .5rem 2.2rem .6rem; font-family: var(--title); font-weight: 900; font-size: 1.9rem; white-space: nowrap; color: #fff7d6;
  background: linear-gradient(180deg, #3fd486, #128a47); border-radius: 6px; box-shadow: 0 6px 14px rgba(0, 0, 0, .5), inset 0 2px 0 rgba(255, 255, 255, .4), inset 0 -3px 0 rgba(0, 0, 0, .25);
  text-shadow: 0 2px 0 rgba(0, 0, 0, .45); --tail: #0b5a2d; }
.ribbon::before, .ribbon::after { content: ""; position: absolute; top: .55rem; z-index: -1; width: 2.2rem; height: 100%; background: var(--tail); }
.ribbon::before { left: -1.3rem; clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, 35% 50%); }
.ribbon::after { right: -1.3rem; clip-path: polygon(0 0, 100% 0, 65% 50%, 100% 100%, 0 100%); }
.ribbon.red { background: linear-gradient(180deg, #ff6676, #b3192d); --tail: #6d0d19; }
.ribbon.gold { background: linear-gradient(180deg, #d83b4b, #8f1424); --tail: #5a0b15; color: var(--gold-300); }
.feedback-card .ribbon { position: absolute; top: -1.5rem; }

.fb-body { display: flex; align-items: center; gap: 1.2rem; }
.fb-icon { width: 5rem; height: 5rem; flex: none; display: grid; place-items: center; border-radius: 50%; color: #fff;
  background: radial-gradient(circle at 35% 30%, #7dffb8, #17a55a 60%, #0a5c30); border: 3px solid #d6ffe8; box-shadow: 0 0 34px rgba(61, 220, 132, .95); }
.feedback.bad .fb-icon { background: radial-gradient(circle at 35% 30%, #ff9aa5, #d52c40 60%, #7c0f1d); border-color: #ffd9dd; box-shadow: 0 0 34px rgba(255, 77, 94, .95); }
.fb-icon svg { width: 2.9rem; height: 2.9rem; }
.overlay.show .fb-icon { animation: stamp .5s var(--spring) .1s both; }
@keyframes stamp { from { transform: scale(2.2) rotate(-25deg); opacity: 0; } }
.fb-text { display: flex; flex-direction: column; align-items: flex-start; gap: .4rem; }
.fb-eq { font-family: var(--title); font-weight: 900; font-size: 2.3rem; white-space: nowrap; text-shadow: 0 3px 0 rgba(0, 0, 0, .5); }
.fb-eq s { color: #ff9aa5; text-decoration-thickness: 3px; }
.fb-note { font-size: 1rem; color: #e6e9ff; }
.fb-note.xp { padding: .2rem .9rem; border-radius: 999px; font-weight: 800; color: var(--gold-300); background: rgba(0, 0, 0, .45); border: 1.5px solid rgba(245, 185, 58, .7); }
.fb-note strong { color: var(--gold-300); font-size: 1.2em; }

.fb-hint { max-width: 17rem; font-size: .88rem; font-weight: 600; line-height: 1.35; color: var(--ice); }
.fb-hint:empty { display: none; }

/* Level intro banner */
.intro { position: absolute; inset: 0; z-index: 30; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .5rem; pointer-events: none; opacity: 0; text-align: center; }
.intro b { font-family: var(--title); font-weight: 900; font-size: clamp(3rem, 13vmin, 6.5rem); line-height: 1;
  background: linear-gradient(180deg, #fff6cf 0%, #ffd980 30%, #f0a82e 62%, #8a4f0c 100%); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 3px 0 #3a1f00) drop-shadow(0 0 26px rgba(255, 170, 50, .65)); }
.intro i { font-size: 1rem; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; color: #e6e9ff; text-shadow: 0 2px 6px #000; }
.intro.show { animation: introIn 1.5s var(--ease-out) both; }
@keyframes introIn { 0% { opacity: 0; transform: scale(.55); } 16% { opacity: 1; transform: scale(1.06); } 26% { transform: scale(1); } 78% { opacity: 1; transform: scale(1); } 100% { opacity: 0; transform: scale(1.35); } }

/* Points that float up from a correct answer */
.float-text { position: absolute; z-index: 65; pointer-events: none; transform: translate(-50%, -50%); font-family: var(--title); font-weight: 900; font-size: 2rem; color: var(--gold-300);
  text-shadow: 0 2px 0 #3a1f00, 0 0 16px rgba(255, 190, 70, .9); animation: floatUp 1.2s var(--ease-out) forwards; }
@keyframes floatUp { 0% { opacity: 0; transform: translate(-50%, -20%) scale(.6); } 18% { opacity: 1; transform: translate(-50%, -90%) scale(1.15); } 100% { opacity: 0; transform: translate(-50%, -330%) scale(1); } }

.pause-card { width: min(100%, 21rem); display: flex; flex-direction: column; gap: .8rem; padding: 1.6rem 1.4rem; transform: scale(.7); opacity: 0; }
.pause-card .title { margin-bottom: .4rem; }

/* ================= Results ================= */
#screen-results { align-items: center; justify-content: center; }
.results { isolation: isolate; width: min(100%, 30rem); display: flex; flex-direction: column; align-items: center; gap: 1.1rem; }
.stars { display: flex; align-items: flex-end; gap: .5rem; margin-top: .2rem; }
.star { width: 4rem; height: 4rem; color: rgba(255, 255, 255, .13); stroke: rgba(255, 255, 255, .25); stroke-width: .6; transform: scale(.85); }
.star.big { width: 5.2rem; height: 5.2rem; margin-bottom: .6rem; }
.star.on { color: var(--gold-400); stroke: #fff3c4; filter: drop-shadow(0 0 16px rgba(255, 200, 80, .95)) drop-shadow(0 3px 0 #7a4a08); animation: starIn .6s var(--spring) both; }
@keyframes starIn { from { transform: scale(3) rotate(-50deg); opacity: 0; } to { transform: scale(1) rotate(0); opacity: 1; } }
.results-sub { color: #e6e9ff; font-size: 1rem; text-align: center; min-height: 1.3em; text-shadow: 0 2px 4px #000; }
.stat-row { width: 100%; display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; }
.stat { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .15rem; padding: .7rem .4rem; border-radius: 12px; background: rgba(8, 12, 34, .82); border: 1.5px solid rgba(245, 185, 58, .45); box-shadow: inset 0 0 20px rgba(60, 90, 220, .2); }
.stat span { text-align: center; font-size: .72rem; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.stat b { font-size: 1.55rem; font-weight: 800; color: #fff; font-variant-numeric: tabular-nums; }
.btn-row { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
@media (orientation: landscape) and (max-height: 520px) {
  .results { gap: .5rem; } .star { width: 2.6rem; height: 2.6rem; } .star.big { width: 3.3rem; height: 3.3rem; margin-bottom: .3rem; }
  .ribbon { font-size: 1.4rem; } .stat { padding: .35rem; } .link-btn { padding: .3rem 1rem; }
}

/* ================= Map ================= */
.star-count { display: flex; align-items: center; gap: .35rem; min-width: 3rem; justify-content: flex-end; color: var(--gold-300); font-size: 1.1rem; font-weight: 800; }
.star-count svg { width: 1.3rem; height: 1.3rem; color: var(--gold-400); }
.map-panel { flex: 1; min-height: 0; overflow: hidden;
  background: radial-gradient(60% 50% at 30% 70%, rgba(40, 140, 90, .5), transparent 70%), radial-gradient(50% 50% at 75% 25%, rgba(60, 120, 200, .4), transparent 70%), linear-gradient(180deg, rgba(18, 40, 70, .88), rgba(8, 22, 30, .94)); }
.map { position: absolute; inset: 0; }
.map svg.path { position: absolute; inset: 0; width: 100%; height: 100%; fill: none; }
.map .trail { stroke: rgba(255, 255, 255, .22); stroke-width: 5; stroke-dasharray: 3 13; stroke-linecap: round; }
.map .trail-done { stroke: var(--gold-400); stroke-width: 6; stroke-linecap: round; filter: drop-shadow(0 0 6px rgba(255, 200, 80, .9)); }
.node { position: absolute; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; transform: translate(-50%, -50%);
  width: var(--node); height: var(--node); font-family: var(--title); font-weight: 900; font-size: calc(var(--node) * .34); color: #2b1600;
  transition: transform .12s ease; animation: nodeIn .5s var(--spring) both; }
@keyframes nodeIn { from { opacity: 0; transform: translate(-50%, -50%) scale(.3); } }
.node::before { content: ""; position: absolute; inset: 0; z-index: -1; clip-path: polygon(50% 0, 95% 25%, 95% 75%, 50% 100%, 5% 75%, 5% 25%);
  background: linear-gradient(180deg, #fff0b0, var(--gold-500) 55%, #b9791a); }
.node::after { content: ""; position: absolute; inset: -14%; z-index: -2; border-radius: 50%; background: radial-gradient(circle, rgba(255, 200, 80, .55), transparent 65%); }
.node:active { transform: translate(-50%, -50%) scale(.92); }
.node .mini-stars svg { width: calc(var(--node) * .17); height: calc(var(--node) * .17); color: rgba(60, 30, 0, .3); }
.node .mini-stars svg.on { color: #fff; filter: drop-shadow(0 1px 0 #7a4a08); }
.node.locked { color: #8d97c9; } .node.locked::before { background: linear-gradient(180deg, #3a4480, #161c48); } .node.locked::after { display: none; }
.node.locked svg.lock { width: 42%; height: 42%; }
.node.current::after { animation: beacon 1.6s ease-in-out infinite; background: radial-gradient(circle, rgba(127, 212, 255, .8), transparent 65%); }
.node.boss::before { background: linear-gradient(180deg, #ffb3f0, #b784ff 55%, #5a2fb0); } .node.boss { color: #fff; }
.node.boss.locked::before { background: linear-gradient(180deg, #4a3a80, #1c1648); }
@keyframes beacon { 50% { transform: scale(1.35); opacity: .5; } }

/* ================= Progress ================= */
.progress-panel { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding: 1.2rem; display: flex; flex-direction: column; gap: 1rem; width: min(100%, 52rem); align-self: center; }
.progress-top { display: grid; grid-template-columns: auto 1fr 1fr; gap: .7rem; align-items: stretch; }
.mastery-ring { position: relative; width: 6rem; height: 6rem; }
.mastery-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); fill: none; }
.ring-track { stroke: rgba(255, 255, 255, .1); stroke-width: 9; }
.ring-fill { stroke: var(--green); stroke-width: 9; stroke-linecap: round; stroke-dasharray: 263.9; stroke-dashoffset: 263.9; filter: drop-shadow(0 0 7px rgba(61, 220, 132, .9)); transition: stroke-dashoffset 1.2s var(--ease-out); }
.mastery-ring b { position: absolute; inset: 0; display: grid; place-items: center; font-size: 1.45rem; font-weight: 800; }
.progress-top .stat b { color: var(--ice); font-size: 1.35rem; } .trophy { width: 1.8rem; height: 1.8rem; color: var(--gold-400); filter: drop-shadow(0 0 8px rgba(255, 200, 80, .8)); }
.xp-label { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: .35rem; font-size: .85rem; }
.xp-label b { color: var(--gold-300); font-weight: 800; } .xp-label span { color: var(--muted); }
.xp-bar { height: .8rem; border-radius: 999px; background: rgba(5, 8, 24, .8); border: 1px solid rgba(245, 185, 58, .45); overflow: hidden; }
#xp-fill { height: 100%; width: 0; border-radius: 999px; background: linear-gradient(90deg, #f5b93a, #fff0b0); box-shadow: 0 0 12px rgba(255, 200, 80, .8); transition: width 1s var(--ease-out); }
.badges { display: grid; grid-template-columns: repeat(4, 1fr); gap: .6rem; }
.badge { display: flex; flex-direction: column; align-items: center; gap: .3rem; text-align: center; font-size: .68rem; color: var(--muted); }
.badge .disc { width: 3.1rem; height: 3.1rem; display: grid; place-items: center; border-radius: 50%; color: #5a6294; background: #121a44; border: 2px solid #2a3470; }
.badge .disc svg { width: 1.6rem; height: 1.6rem; }
.badge.on { color: var(--text); }
.badge.on .disc { color: #fff; border-color: var(--gold-300); background: radial-gradient(circle at 35% 30%, var(--c1), var(--c2)); box-shadow: 0 0 16px var(--c1); }
.grid-caption { font-size: .85rem; color: var(--muted); text-align: center; margin-bottom: .5rem; min-height: 1.3em; }
.grid-caption strong { color: var(--gold-300); font-size: 1.15em; }
.fact-grid { display: grid; grid-template-columns: repeat(13, 1fr); gap: 3px; width: min(100%, 30rem); margin: 0 auto; }
.fact-grid > * { aspect-ratio: 1; display: grid; place-items: center; border-radius: 5px; font-size: .62rem; font-weight: 800; }
.fact-grid .hd { color: var(--gold-300); }
.fact-grid .cell { background: #131b4a; border: 1px solid rgba(255, 255, 255, .06); color: transparent; }
.fact-grid .cell.l1 { background: #5b3f1c; } .fact-grid .cell.l2 { background: #a8721d; }
.fact-grid .cell.l3 { background: linear-gradient(180deg, #fff0b0, #f5b93a); box-shadow: 0 0 6px rgba(255, 200, 80, .7); }
.fact-grid .cell.weak { background: #7c1f30; }
.fact-grid .cell.sel { outline: 2px solid #fff; outline-offset: 1px; }

/* ================= Settings ================= */
.settings-panel { width: min(100%, 34rem); align-self: center; padding: .6rem 1.3rem 1.1rem; overflow-y: auto; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .95rem 0; border-bottom: 1px solid rgba(255, 255, 255, .08); }
.setting > span:first-child { display: flex; flex-direction: column; gap: .15rem; }
.setting b { font-size: 1.05rem; font-weight: 800; } .setting i { font-size: .8rem; color: var(--muted); font-weight: 500; }
.setting input { position: absolute; opacity: 0; pointer-events: none; }
.switch { position: relative; flex: none; width: 3.6rem; height: 2rem; border-radius: 999px; background: #0a0f30; border: 1.5px solid rgba(245, 185, 58, .5); transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 50%; left: .2rem; width: 1.5rem; height: 1.5rem; border-radius: 50%; transform: translateY(-50%); background: #6b74a8; transition: left .22s var(--spring), background .2s; box-shadow: 0 2px 4px rgba(0, 0, 0, .6); }
input:checked + .switch { background: linear-gradient(180deg, #1aa35a, #0f7a3d); }
input:checked + .switch::after { left: 1.8rem; background: #fff; }
input:focus-visible + .switch, button:focus-visible { outline: 3px solid var(--ice); outline-offset: 2px; }
.fineprint { margin-top: 1rem; font-size: .8rem; font-weight: 500; color: var(--muted); text-align: center; }

.toast { position: absolute; z-index: 70; left: 50%; bottom: calc(var(--sab) + 1.4rem); transform: translate(-50%, 30px); padding: .6rem 1.2rem; border-radius: 999px; font-size: .9rem; white-space: nowrap;
  background: rgba(8, 12, 34, .94); border: 1.5px solid var(--gold-400); box-shadow: 0 0 20px rgba(255, 200, 80, .4); opacity: 0; pointer-events: none; transition: opacity .3s, transform .4s var(--spring); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  /* These two end their animation invisible, so show them statically instead. Script removes them on a timer. */
  .intro.show { animation: none !important; opacity: 1; }
  .float-text { animation: none !important; opacity: 1; transform: translate(-50%, -150%); }
}
