/* Math Facts Arcade — styles. A bright page like the other kids' games, a
   purple bar with 70s stripes, and a colourful arcade cabinet with a glowing
   screen and big round buttons. */
:root {
  --bg: #fdf6e3;
  --panel: #ffffff;
  --text: #2a2420;
  --muted: #6b625a;
  --line: #e4dccb;
  --purple: #7b2ff2;
  --purple-dark: #4b1aa8;
  --purple-soft: #f1e9fe;
  --go: #e2622c;
  --go-dark: #b84a1c;
  --mustard: #f2b134;
  --right: #2fa35a;
  --wrong: #d0402e;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text); display: flex; flex-direction: column; min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button {
  font: inherit; font-weight: 700; border: 2px solid var(--line); background: var(--panel); color: var(--text);
  border-radius: 12px; padding: 8px 16px; cursor: pointer; touch-action: manipulation;
}
button:disabled { opacity: .45; cursor: default; }
button.go { background: var(--go); border-color: var(--go-dark); color: #fff; font-size: 18px; padding: 10px 22px; }
button.go:not(:disabled):hover { background: var(--go-dark); }
button.secondary { background: #fff; }
button.danger { color: var(--wrong); border-color: #f0c4be; }
button.icon { width: 42px; height: 42px; padding: 0; border-radius: 50%; font-size: 20px; }
button.plain { border: none; background: none; }
.small { color: var(--muted); font-size: 13px; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 14px; background: var(--purple); color: #fff;
}
.brand { font-size: 22px; font-weight: 800; letter-spacing: .3px; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand-mark { font-size: 22px; background: #fff; border-radius: 8px; padding: 0 4px; line-height: 1.3; }
.top-right { display: flex; gap: 8px; align-items: center; }
.top-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.apps-link {
  display: inline-flex; align-items: center; gap: 6px; min-height: 42px; box-sizing: border-box; padding: 6px 14px;
  border-radius: 999px; background: rgba(255, 255, 255, .16); border: 1px solid rgba(255, 255, 255, .5);
  color: #fff; text-decoration: none; font-weight: 700; font-size: 16px;
}
.apps-link:hover { background: rgba(255, 255, 255, .3); }
.apps-link svg { fill: currentColor; flex: none; }
.player-chip { background: rgba(255, 255, 255, .16); color: #fff; border-color: rgba(255, 255, 255, .5); padding: 6px 14px; }
.topbar button.icon { background: rgba(255, 255, 255, .16); color: #fff; border-color: rgba(255, 255, 255, .5); }
.topbar, .stripes, .update-note { flex-shrink: 0; }
.stripes { height: 9px; background: linear-gradient(var(--mustard) 0 3px, var(--go) 3px 6px, #8a4b2a 6px 9px); }
.update-note {
  display: flex; gap: 10px; align-items: center; justify-content: center; padding: 8px; background: #fff4d6;
  border-bottom: 1px solid #f0d58a; font-weight: 600;
}

/* ---------- home ---------- */
.home { max-width: 1100px; width: 100%; margin: 0 auto; padding: 12px 14px 0; display: flex; flex-direction: column; gap: 12px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 12px 16px; }
.home h2 { margin: 0 0 10px; font-size: 18px; color: var(--purple-dark); display: flex; align-items: baseline; gap: 10px; }
.home-total { margin-left: auto; color: #c48a00; font-size: 16px; }
.players { display: flex; flex-wrap: wrap; gap: 10px; }
.player { display: flex; align-items: center; gap: 8px; padding: 6px 14px 6px 6px; border-radius: 30px; border: 3px solid var(--line); }
.player-emoji { font-size: 28px; line-height: 1; width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; background: #f6f1e4; }
.player.on { border-color: var(--pc, var(--purple)); background: color-mix(in srgb, var(--pc, var(--purple)) 10%, #fff); }
.player.add { color: var(--muted); border-style: dashed; }
.player-badges { font-size: 18px; letter-spacing: 1px; margin-left: 2px; }
.tracks { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.track { border: 3px solid color-mix(in srgb, var(--tc) 55%, #fff); border-radius: 16px; padding: 8px; background: color-mix(in srgb, var(--tc) 7%, #fff); }
.track-head { display: flex; align-items: center; gap: 8px; font-weight: 900; font-size: 19px; color: color-mix(in srgb, var(--tc) 55%, #000); }
.track-icon { font-size: 24px; }
.track-badge { margin: 4px 0 8px; }
.track-levels { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.lvl { display: flex; flex-direction: column; align-items: center; padding: 5px 4px; border-width: 3px; min-width: 0; background: #fff; }
.lvl-name { font-size: 13.5px; line-height: 1.15; text-align: center; }
.lvl-stars { color: #f2b705; letter-spacing: 1px; font-size: 14px; }
.lvl.on { border-color: var(--go); background: #fff1e8; }
.lvl.locked { background: #f4f1ea; color: var(--muted); border-style: dashed; }
.lvl.locked .lvl-stars { opacity: .4; }
.level-about { margin: 10px 2px 0; color: var(--muted); font-weight: 600; }
.home-go {
  display: flex; justify-content: space-between; align-items: center; gap: 10px; position: sticky; bottom: 0; z-index: 2;
  padding: 10px 0 12px; background: linear-gradient(rgba(253, 246, 227, 0), var(--bg) 30%);
}
.home-go .go { font-size: 22px; padding: 12px 36px; }

/* ---------- the arcade cabinet ---------- */
.play { flex: 1; display: grid; grid-template-rows: auto 1fr; gap: 6px; padding: 6px 10px 10px; min-height: 0; max-width: 1180px; width: 100%; margin: 0 auto; }
.play-bar { display: flex; align-items: center; gap: 12px; min-height: 44px; }
.bar-title { font-weight: 800; font-size: 18px; color: var(--purple-dark); flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.progress { display: flex; gap: 5px; }
.pip { width: 14px; height: 14px; border-radius: 50%; background: #e6dfcc; border: 2px solid #d8cfb8; }
.pip.done { background: var(--right); border-color: #23824a; }
.pip.now { background: #fff; border-color: var(--go); box-shadow: 0 0 0 3px #ffd9c4; }

.cabinet {
  --tc: #7b2ff2;
  display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 0; min-height: 0;
  border-radius: 26px 26px 18px 18px; overflow: hidden;
  background: linear-gradient(135deg, var(--tc), color-mix(in srgb, var(--tc) 70%, #000));
  border: 4px solid color-mix(in srgb, var(--tc) 55%, #000); box-shadow: 0 8px 0 color-mix(in srgb, var(--tc) 45%, #000), 0 14px 30px rgba(0, 0, 0, .2);
}
.cab-main { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px 12px; min-height: 0; }
.marquee {
  text-align: center; font: 900 20px/1.4 ui-monospace, Menlo, Consolas, monospace; letter-spacing: 4px; color: #fff7d1;
  background: #1b0f3a; border-radius: 12px; padding: 3px 8px; text-shadow: 0 0 6px #ffd23f, 0 0 14px #ff6fb5;
  border: 5px dotted #ffd23f; box-shadow: 0 0 0 2px #1b0f3a, inset 0 0 12px rgba(255, 210, 63, .35);
  animation: bulbs 1.2s steps(2) infinite;
}
@keyframes bulbs { 50% { border-color: #ff9fce; } }
.screen {
  position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: radial-gradient(ellipse at center, #1a1f4d 0%, #0b0d26 75%); border-radius: 22px; padding: 10px 16px;
  border: 8px solid #20222b; box-shadow: inset 0 0 40px rgba(0, 0, 0, .7), 0 0 0 3px #3a3d4a; overflow: hidden;
  font-family: ui-monospace, Menlo, Consolas, monospace; color: #e8ecff;
}
.screen::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; border-radius: 14px;
  background: repeating-linear-gradient(rgba(255, 255, 255, .035) 0 2px, transparent 2px 4px);
}
.hud { width: 100%; display: flex; justify-content: space-between; align-items: center; font-size: 15px; letter-spacing: 1px; color: #aab0e0; }
.hud b { color: #ffd23f; text-shadow: 0 0 6px rgba(255, 210, 63, .6); font-size: 18px; }
.combo { color: #ff6fb5; font-weight: 900; font-size: 18px; text-shadow: 0 0 8px rgba(255, 111, 181, .8); }
.combo.bump { animation: pop .35s ease-out; }
.timer { width: 100%; height: 10px; background: #262a52; border-radius: 6px; overflow: hidden; }
.timer-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #3ff5d0, #ffd23f); border-radius: 6px; }
.timer.late .timer-fill { background: #5a5f93; }
.fact {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: .32em; font-size: clamp(44px, 9vw, 92px); font-weight: 900;
  min-height: 0; transition: font-size .2s;
}
.fact .num { color: #ffd23f; text-shadow: 0 0 10px rgba(255, 210, 63, .7), 0 0 26px rgba(255, 210, 63, .35); }
.fact .op { color: #3ff5d0; text-shadow: 0 0 10px rgba(63, 245, 208, .7); }
.fact .slot {
  min-width: 1.6em; text-align: center; padding: 0 .12em; border-bottom: .08em solid #ff6fb5; color: #fff;
  text-shadow: 0 0 10px rgba(255, 255, 255, .6);
}
.fact .slot.empty { color: #ff6fb5; }
.fact .slot.live.empty { animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .25; } }
.fact.right .slot { color: #3ff5d0; border-color: #3ff5d0; text-shadow: 0 0 14px #3ff5d0; }
.fact.shown .slot { color: #ffb347; border-color: #ffb347; text-shadow: 0 0 14px #ffb347; }
.fact.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { translate: -10px 0; } 40%, 80% { translate: 10px 0; } }
.say { min-height: 1.4em; font-size: 22px; font-weight: 900; letter-spacing: 2px; }
.say.good { color: #3ff5d0; text-shadow: 0 0 10px #3ff5d0; animation: pop .35s ease-out; }
.say.bad { color: #ff6f6f; text-shadow: 0 0 10px #ff6f6f; }
.say.shown { color: #ffb347; text-shadow: 0 0 10px #ffb347; }
.say.late { color: #aab0e0; }
.screen.helping .fact { flex: none; font-size: clamp(30px, 5vw, 50px); }
.screen.helping .say { min-height: 0; font-size: 17px; }
.helpbox { width: 100%; flex: 1; min-height: 0; overflow: auto; display: flex; align-items: center; justify-content: center; }
.help-body { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
.help-svg { max-width: 100%; max-height: 100%; height: auto; display: block; font-family: ui-monospace, Menlo, Consolas, monospace; }
.tip { font: 600 19px/1.45 system-ui, sans-serif; color: #e8ecff; max-width: 640px; margin: 0; padding: 4px 8px; }
.tip b { color: #ffd23f; }
.help-note { font: 600 17px system-ui, sans-serif; color: #aab0e0; }
.help-tabs { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.htab {
  font-size: 15px; padding: 7px 12px; border-radius: 999px; border: 3px solid rgba(255, 255, 255, .7); background: rgba(255, 255, 255, .92);
  box-shadow: 0 3px 0 rgba(0, 0, 0, .25);
}
.htab.on { background: #ffd23f; border-color: #fff; }
.help-tabs.nudge .htab { animation: nudge 1s ease-in-out 2; }
@keyframes nudge { 50% { translate: 0 -4px; box-shadow: 0 7px 0 rgba(0, 0, 0, .25); } }

/* the control panel: the number buttons, and (set apart) rub out and the check */
.pad {
  display: flex; flex-direction: column; justify-content: center; gap: 14px; padding: 14px 18px 18px;
  background: linear-gradient(#2b2440, #1b1530); border-left: 4px solid color-mix(in srgb, var(--tc) 45%, #000);
}
.numpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; justify-items: center; }
.numpad .abtn[data-k="0"] { grid-column: 2; }
.controls {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-top: 14px;
  border-top: 3px dashed rgba(255, 255, 255, .18);
}
.abtn {
  aspect-ratio: 1; border-radius: 50%; border: none; padding: 0; font: 900 30px/1 system-ui, sans-serif; color: #fff; position: relative;
  display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--bc) 55%, #fff), var(--bc) 55%, color-mix(in srgb, var(--bc) 60%, #000));
  box-shadow: 0 6px 0 color-mix(in srgb, var(--bc) 45%, #000), 0 8px 12px rgba(0, 0, 0, .45); text-shadow: 0 2px 0 rgba(0, 0, 0, .35);
  width: 100%; max-width: 72px;
}
.abtn svg { width: 58%; height: 58%; filter: drop-shadow(0 2px 0 rgba(0, 0, 0, .3)); }
.abtn:active, .abtn.down { translate: 0 4px; box-shadow: 0 2px 0 color-mix(in srgb, var(--bc) 45%, #000), 0 3px 6px rgba(0, 0, 0, .45); }
.abtn:disabled { opacity: .55; }
.abtn.c0 { --bc: #ff4d6d; }
.abtn.c1 { --bc: #ffb703; }
.abtn.c2 { --bc: #3fa9f5; }
.abtn.c3 { --bc: #c77dff; }
.abtn.back-btn { --bc: #8d8aa3; max-width: 60px; flex: none; }
.abtn.go-btn {
  --bc: #22b35e; aspect-ratio: auto; border-radius: 999px; height: 72px; max-width: none; flex: 1;
}
.abtn.go-btn svg { width: auto; height: 62%; }
.abtn.go-btn:not(.ready) { filter: saturate(.35) brightness(.8); }
.abtn.go-btn.ready { animation: readyGlow 1.2s ease-in-out infinite; }
@keyframes readyGlow { 50% { box-shadow: 0 6px 0 color-mix(in srgb, var(--bc) 45%, #000), 0 0 18px 4px rgba(63, 245, 140, .6); } }

.result {
  position: absolute; inset: 0; margin: auto; width: min(440px, 94%); height: fit-content; z-index: 3; text-align: center;
  background: rgba(11, 13, 38, .94); border: 3px solid #ffd23f; border-radius: 18px; padding: 14px 18px; box-shadow: 0 0 30px rgba(255, 210, 63, .35);
}
.result-title { font-size: 30px; font-weight: 900; letter-spacing: 3px; color: #3ff5d0; text-shadow: 0 0 12px #3ff5d0; }
.result-stars { font-size: 42px; color: #ffd23f; letter-spacing: 4px; text-shadow: 0 0 12px rgba(255, 210, 63, .7); }
.result-score { font-size: 22px; font-weight: 900; color: #ffd23f; }
.result-detail { color: #aab0e0; font: 600 15px system-ui, sans-serif; margin: 4px 0 8px; }
.result .result-rewards { margin: 0 0 10px; color: #ffe9a8; font-family: system-ui, sans-serif; }
.result .result-rewards li { background: rgba(255, 210, 63, .12); }
.result-buttons { display: flex; gap: 10px; justify-content: center; }
.arc-small { font: 900 16px system-ui, sans-serif; border-radius: 999px; padding: 9px 16px; }
.arc-small.go2 { background: #ff7a1a; border-color: #c75a0c; color: #fff; }

/* ---------- dialogs ---------- */
.dialog { max-width: 460px; width: calc(100% - 28px); border: none; box-shadow: 0 10px 40px rgba(0, 0, 0, .3); }
.dialog.wide { max-width: 760px; }
.dialog::backdrop { background: rgba(40, 20, 70, .45); }
.dialog h2 { margin: 0 0 12px; color: var(--purple-dark); }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 700; margin-bottom: 12px; }
.field.check { flex-direction: row; align-items: center; gap: 10px; }
.field input[type=text], .field select { font: inherit; font-weight: 500; padding: 8px 10px; border: 2px solid var(--line); border-radius: 10px; }
.field input[type=checkbox] { width: 22px; height: 22px; flex: none; }
.field-label { font-weight: 700; margin-bottom: 6px; }
.emoji-pick { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; margin-bottom: 14px; }
.emoji-pick button { font-size: 26px; padding: 4px 0; border-radius: 10px; }
.emoji-pick button.on { border-color: var(--purple); background: var(--purple-soft); }
.dialog-buttons { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.spacer { flex: 1; }
.help li { margin-bottom: 8px; line-height: 1.45; }
.scores { border-collapse: collapse; width: 100%; font-size: 15px; }
.scores th, .scores td { padding: 6px 5px; border-bottom: 1px solid var(--line); text-align: center; }
.scores th { font-size: 22px; }
.scores .who { text-align: left; white-space: nowrap; font-weight: 700; }
.scores small { color: #f2b705; margin-left: 4px; }
.scores td.top { font-weight: 900; color: #b45309; }
.scores .hs-track td { font-weight: 900; background: #f6f1ff; text-align: left; }
.scores .lvl-cell { text-align: left; }
#scores { overflow-x: auto; }

/* ---------- rewards: streaks, badges, celebrations ---------- */
.streak {
  font-weight: 900; font-size: 18px; color: #c2410c; background: #fff1e0; border: 2px solid #f6b98a; border-radius: 999px;
  padding: 2px 12px; white-space: nowrap;
}
.streak.bump { animation: pop .35s ease-out; }
.track-badge {
  font-size: 11.5px; font-weight: 800; color: #a59a88; border: 2px dashed #ddd3bf; border-radius: 999px; padding: 1px 8px;
  width: fit-content; white-space: nowrap;
}
.track-badge.won { color: #7a5200; background: linear-gradient(#fff3c4, #f7d36a); border: 2px solid #d9a521; box-shadow: 0 1px 0 #c08f12; }
.player-badges { font-size: 18px; letter-spacing: 1px; margin-left: 2px; }
.result-rewards { list-style: none; padding: 0; margin: -6px 0 14px; display: flex; flex-direction: column; gap: 4px; font-weight: 800; color: #7a4a00; }
.result-rewards li { background: #fff6dc; border-radius: 10px; padding: 4px 10px; }
.result-rewards:empty { display: none; }

.toast {
  position: fixed; left: 50%; top: 84px; transform: translateX(-50%); z-index: 20; pointer-events: none;
  background: #c2410c; color: #fff; font-weight: 900; font-size: 20px; padding: 8px 20px; border-radius: 999px;
  box-shadow: 0 6px 20px rgba(194, 65, 12, .35);
}
.toast.show { animation: toastIn 2.2s ease-out forwards; }
@keyframes toastIn {
  0% { opacity: 0; translate: 0 -12px; scale: .8; } 12% { opacity: 1; translate: 0 0; scale: 1.08; } 20% { scale: 1; }
  80% { opacity: 1; } 100% { opacity: 0; translate: 0 -8px; }
}

.celebrate { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; background: rgba(50, 20, 90, .45); overflow: hidden; }
.cel-card {
  position: relative; z-index: 2; background: #fff; border-radius: 22px; border: 4px solid var(--mustard); padding: 22px 28px 20px;
  width: min(420px, 90%); text-align: center; box-shadow: 0 16px 50px rgba(50, 20, 90, .4); animation: celIn .5s cubic-bezier(.2, 1.6, .4, 1);
}
.cel-icon { font-size: 72px; line-height: 1.1; animation: wiggle 1.2s ease-in-out .4s 2; }
.celebrate.badge .cel-icon {
  width: 120px; height: 120px; margin: 0 auto 6px; display: grid; place-items: center; font-size: 62px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff8d6, #f7d36a 60%, #d9a521); border: 5px solid #c08f12;
  box-shadow: 0 0 0 6px #fff3c4, 0 0 30px 10px rgba(247, 211, 106, .7);
}
.cel-title { font-size: 30px; font-weight: 900; color: var(--purple-dark); margin-top: 4px; }
.cel-text { color: var(--muted); font-weight: 600; margin: 8px 0 16px; line-height: 1.4; }
@keyframes celIn { from { scale: .4; opacity: 0; } to { scale: 1; opacity: 1; } }
@keyframes wiggle { 0%, 100% { rotate: 0deg; } 25% { rotate: -12deg; } 75% { rotate: 12deg; } }
.confetti { position: absolute; inset: 0; pointer-events: none; }
.confetti i {
  position: absolute; top: -20px; width: 10px; height: 16px; border-radius: 2px; opacity: 0;
  animation-name: fall; animation-timing-function: cubic-bezier(.3, .6, .6, 1); animation-fill-mode: forwards;
}
.confetti i.round { width: 12px; height: 12px; border-radius: 50%; }
@keyframes fall {
  0% { opacity: 1; transform: translate(0, 0) rotate(0); }
  100% { opacity: .9; transform: translate(var(--drift), 105vh) rotate(var(--spin)); }
}
/* ---------- smaller screens ---------- */
@media (max-height: 700px) {
  .home { gap: 8px; }
  .panel { padding: 8px 12px; }
  .marquee { font-size: 16px; padding: 2px 8px; }
  .cab-main { gap: 6px; padding: 8px 10px 10px; }
  .pad { gap: 10px; padding: 10px 16px 14px; }
  .numpad { gap: 9px; }
  .controls { padding-top: 10px; }
  .abtn { max-width: 62px; font-size: 26px; }
  .abtn.back-btn { max-width: 54px; }
  .abtn.go-btn { height: 62px; }
  .htab { font-size: 14px; padding: 5px 10px; }
  .tip { font-size: 17px; }
}
@media (max-width: 900px) {
  .tracks { grid-template-columns: 1fr; }
  .track-levels { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
}
@media (max-width: 760px), (max-aspect-ratio: 1/1) {
  .cabinet { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .pad { border-left: none; border-top: 4px solid color-mix(in srgb, var(--tc) 45%, #000); flex-direction: row; align-items: center; }
  .numpad { flex: 1; grid-template-columns: repeat(5, 1fr); }
  .numpad .abtn[data-k="0"] { grid-column: auto; }
  .controls { flex-direction: column-reverse; border-top: none; padding-top: 0; padding-left: 14px; border-left: 3px dashed rgba(255, 255, 255, .18); width: 128px; }
  .abtn.go-btn { width: 100%; flex: none; }
  .abtn { max-width: 64px; }
} .abtn[data-k="⌫"] { order: 11; } .abtn[data-k="GO"] { order: 12; }
}
@media (max-width: 700px) {
  .apps-link span { display: none; }
  .brand { font-size: 18px; }
  .progress { display: none; }
}
@media (max-width: 420px) {
  .brand { display: none; }
}
@keyframes pop { 0% { scale: .7; } 70% { scale: 1.12; } 100% { scale: 1; } }
