:root {
  color-scheme: dark;
  --bg: #0b061b;
  --panel: rgba(27, 14, 59, 0.82);
  --panel-strong: #1a0d3a;
  --purple: #a855f7;
  --purple-bright: #cc6cff;
  --cyan: #42f5e6;
  --cyan-dark: #16cfc2;
  --white: #fbfaff;
  --muted: #aba2c1;
  --danger: #ff5d8f;
  --radius: 22px;
  font-family: "Nunito", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body { margin: 0; min-width: 320px; min-height: 100vh; min-height: 100dvh; color: var(--white); overflow-x: hidden; background: radial-gradient(circle at 50% 0%, #28124d 0, #0b061b 46%, #070412 100%); }
button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--cyan); outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.ambient { position: fixed; z-index: 0; border-radius: 50%; filter: blur(90px); opacity: .18; pointer-events: none; }
.ambient-one { width: 35vw; height: 35vw; background: var(--purple); top: -15vw; left: -8vw; }
.ambient-two { width: 28vw; height: 28vw; background: var(--cyan); right: -12vw; bottom: -12vw; opacity: .1; }
.app-shell { position: relative; z-index: 1; width: min(1180px, 100%); min-height: 100vh; min-height: 100dvh; margin: 0 auto; padding: clamp(18px, 3vw, 42px); display: grid; }
.screen { display: none; width: 100%; min-height: calc(100dvh - clamp(36px, 6vw, 84px)); animation: screen-in .4s ease both; }
.screen.is-active { display: flex; }
@keyframes screen-in { from { opacity: 0; transform: translateY(8px); } }

.brand-row { display: flex; align-items: center; gap: 16px; margin: 0 0 24px; }
.brand-mark { width: clamp(54px, 6vw, 70px); aspect-ratio: 1; display: grid; place-items: center; border: 2px solid var(--cyan); border-radius: 18px 7px 18px 7px; background: rgba(66,245,230,.08); box-shadow: 0 0 30px rgba(66,245,230,.2), inset 0 0 20px rgba(66,245,230,.08); transform: rotate(-4deg); }
.brand-mark span { color: var(--cyan); font: 700 clamp(34px, 4vw, 48px)/1 "Chakra Petch"; text-shadow: 0 0 15px var(--cyan); }
.brand-copy { flex: 1; }
.eyebrow { margin: 0 0 3px; color: var(--cyan); font: 700 11px/1.2 "Chakra Petch"; letter-spacing: .2em; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font: 700 clamp(25px, 4vw, 45px)/.95 "Chakra Petch"; letter-spacing: -.035em; }
h1 span { color: var(--purple-bright); text-shadow: 0 0 22px rgba(192, 78, 255, .45); }
.icon-button { width: 46px; height: 46px; flex: 0 0 auto; border: 1px solid rgba(255,255,255,.16); border-radius: 14px; background: rgba(255,255,255,.05); display: grid; place-items: center; cursor: pointer; transition: .2s ease; }
.icon-button:hover { border-color: var(--cyan); background: rgba(66,245,230,.1); }
.icon-button svg { width: 23px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.setup-screen { flex-direction: column; justify-content: center; }
.setup-card { position: relative; overflow: hidden; border: 1px solid rgba(177,102,255,.28); border-radius: var(--radius); background: linear-gradient(145deg, rgba(32,17,68,.92), rgba(14,8,32,.9)); box-shadow: 0 28px 80px rgba(0,0,0,.35); }
.setup-card::before { content: ""; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(90deg, transparent, rgba(66,245,230,.03), transparent); }
.setup-section { position: relative; padding: clamp(20px, 2.7vw, 32px); border-bottom: 1px solid rgba(255,255,255,.08); }
.player-section { display: grid; grid-template-columns: 1fr minmax(190px, 300px); align-items: center; gap: 24px; }
.section-heading { display: flex; align-items: center; gap: 15px; }
.section-heading h2 { margin: 0; font-size: clamp(17px, 2.2vw, 22px); line-height: 1.15; }
.step-number { color: rgba(202,188,230,.35); font: 700 27px/1 "Chakra Petch"; }
.initials-field { position: relative; display: block; }
.initials-field input { width: 100%; height: 66px; padding: 4px 95px 4px 18px; border: 1px solid rgba(66,245,230,.35); border-radius: 14px; color: var(--white); background: rgba(5,3,15,.5); font: 700 25px "Chakra Petch"; letter-spacing: .2em; text-transform: uppercase; }
.initials-field input::placeholder { color: rgba(255,255,255,.2); }
.initials-field span { position: absolute; right: 14px; top: 50%; color: var(--muted); font-size: 10px; transform: translateY(-50%); }
.mode-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 22px 0 18px; }
.mode-tab { min-height: 86px; padding: 13px; border: 1px solid rgba(255,255,255,.12); border-radius: 15px; background: rgba(255,255,255,.035); cursor: pointer; display: grid; grid-template-columns: auto 1fr; grid-template-rows: 1fr 1fr; column-gap: 12px; text-align: left; transition: .2s ease; }
.mode-tab:hover { border-color: rgba(168,85,247,.65); transform: translateY(-2px); }
.mode-tab.is-selected { border-color: var(--purple-bright); background: rgba(168,85,247,.14); box-shadow: inset 0 0 25px rgba(168,85,247,.08), 0 0 20px rgba(168,85,247,.1); }
.mode-icon { grid-row: 1/3; align-self: center; display: grid; place-items: center; width: 48px; height: 48px; border-radius: 12px; background: rgba(168,85,247,.18); color: var(--purple-bright); font: 700 18px "Chakra Petch"; }
.mode-tab strong { align-self: end; font-size: 15px; }
.mode-tab small { color: var(--muted); font-size: 11px; }
.picker-label { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .09em; }
.number-grid { display: grid; grid-template-columns: repeat(11, minmax(44px, 1fr)); gap: 8px; }
.number-button, .count-options button { min-height: 46px; border: 1px solid rgba(255,255,255,.12); border-radius: 11px; background: rgba(255,255,255,.04); font: 700 16px "Chakra Petch"; cursor: pointer; transition: .18s ease; }
.number-button:hover, .count-options button:hover { border-color: var(--cyan); }
.number-button.is-selected, .count-options button.is-selected { color: #081512; border-color: var(--cyan); background: var(--cyan); box-shadow: 0 0 18px rgba(66,245,230,.27); }
.text-button { padding: 5px; border: 0; color: var(--cyan); background: transparent; font-size: 12px; font-weight: 800; cursor: pointer; }
.squares-note { align-items: center; gap: 12px; margin-top: 20px; color: var(--purple-bright); font: 700 18px "Chakra Petch"; }
.squares-note:not([hidden]) { display: flex; }
.squares-note i { width: 75px; height: 1px; background: linear-gradient(90deg, var(--purple), var(--cyan)); }
.squares-note p { margin: 0 0 0 8px; color: var(--muted); font: 700 12px "Nunito"; }
.count-options { display: grid; grid-template-columns: repeat(5, 1fr); gap: 9px; margin-top: 20px; }
.start-row { display: flex; justify-content: flex-end; align-items: center; gap: 24px; padding: clamp(20px, 2.7vw, 32px); }
.best-preview { margin-right: auto; }
.best-preview span { display: block; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .12em; }
.best-preview strong { font: 700 18px "Chakra Petch"; color: var(--cyan); }
.primary-button, .secondary-button { min-height: 56px; padding: 0 24px; border-radius: 13px; font: 800 13px "Chakra Petch"; letter-spacing: .08em; cursor: pointer; }
.primary-button { border: 0; color: #0c0920; background: linear-gradient(120deg, var(--cyan), #8dfff5); box-shadow: 0 0 28px rgba(66,245,230,.22); display: flex; align-items: center; gap: 18px; transition: .2s ease; }
.primary-button:hover { transform: translateY(-2px); box-shadow: 0 0 38px rgba(66,245,230,.34); }
.primary-button svg { width: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; }
.secondary-button { border: 1px solid rgba(255,255,255,.2); color: var(--white); background: transparent; }
.form-error { min-height: 0; margin: -18px 32px 18px; color: var(--danger); font-size: 12px; text-align: right; }

.game-screen { flex-direction: column; }
.game-header { display: grid; grid-template-columns: auto auto minmax(140px, 1fr) auto; align-items: center; gap: clamp(10px, 2vw, 24px); }
.game-stat, .timer-card { padding: 8px 16px; }
.game-stat span, .timer-card span, .progress-label span { display: block; color: var(--muted); font-size: 9px; font-weight: 800; text-transform: uppercase; letter-spacing: .12em; }
.game-stat strong, .timer-card strong { font: 700 20px "Chakra Petch"; }
.game-stat strong { color: var(--cyan); letter-spacing: .1em; }
.timer-card { min-width: 142px; border: 1px solid rgba(168,85,247,.35); border-radius: 12px; background: rgba(168,85,247,.08); text-align: right; }
.progress-label { display: flex; justify-content: space-between; align-items: end; margin-bottom: 7px; }
.progress-label span { display: inline; }
.progress-label strong { font: 700 12px "Chakra Petch"; }
.progress-track { height: 6px; border-radius: 9px; background: rgba(255,255,255,.08); overflow: hidden; }
.progress-track i { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--purple), var(--cyan)); box-shadow: 0 0 10px var(--cyan); transition: width .3s ease; }
.game-board { flex: 1; width: min(100%, 980px); min-height: 480px; margin: auto; display: grid; grid-template: repeat(3, minmax(110px, 1fr)) / repeat(3, minmax(120px, 1fr)); align-items: center; justify-items: center; gap: clamp(4px, 1vw, 14px); }
.answer { position: relative; z-index: 3; width: clamp(112px, 15vw, 178px); aspect-ratio: 1.34; border: 1px solid rgba(168,85,247,.65); border-radius: 20px 8px 20px 8px; color: var(--white); background: linear-gradient(145deg, rgba(77,35,128,.7), rgba(29,14,64,.9)); box-shadow: 0 14px 30px rgba(0,0,0,.25), inset 0 0 18px rgba(178,85,247,.08); font: 700 clamp(25px, 4vw, 44px) "Chakra Petch"; cursor: pointer; transition: transform .14s ease, border-color .14s ease, background .14s ease; }
.answer::after { content: ""; position: absolute; inset: 6px; border: 1px solid rgba(255,255,255,.05); border-radius: 14px 5px 14px 5px; pointer-events: none; }
.answer:hover { transform: scale(1.06); border-color: var(--cyan); background: linear-gradient(145deg, rgba(39,115,125,.75), rgba(22,34,69,.95)); }
.answer:active { transform: scale(.98); }
.answer.is-wrong { animation: wrong .38s ease; border-color: var(--danger); background: rgba(150,20,74,.65); }
.answer.is-correct { animation: correct .38s ease; border-color: var(--cyan); background: rgba(18,133,119,.76); box-shadow: 0 0 32px rgba(66,245,230,.4); }
@keyframes wrong { 25%,75% { transform: translateX(-7px); } 50% { transform: translateX(7px); } }
@keyframes correct { 50% { transform: scale(1.12); } }
.answer-1 { grid-area: 1 / 1; } .answer-2 { grid-area: 1 / 3; } .answer-3 { grid-area: 2 / 1; }
.answer-4 { grid-area: 2 / 3; } .answer-5 { grid-area: 3 / 1; } .answer-6 { grid-area: 3 / 3; }
.question-core { position: relative; grid-area: 1 / 2 / 4 / 3; z-index: 2; width: clamp(150px, 22vw, 265px); aspect-ratio: 1; align-self: center; display: flex; flex-direction: column; justify-content: center; align-items: center; border: 2px solid var(--cyan); border-radius: 50%; background: radial-gradient(circle, #26144e 0, #12082d 67%, #0c071b 100%); box-shadow: 0 0 38px rgba(66,245,230,.22), inset 0 0 45px rgba(168,85,247,.22); }
.question-core::before, .question-core::after { content: ""; position: absolute; border-radius: 50%; border: 1px solid rgba(66,245,230,.17); }
.question-core::before { inset: -13px; } .question-core::after { inset: 10px; }
.orbit { position: absolute; inset: -20px; border: 1px dashed rgba(168,85,247,.25); border-radius: 50%; animation: spin 18s linear infinite; }
.orbit::before { content: ""; position: absolute; width: 8px; height: 8px; border-radius: 50%; background: var(--purple-bright); top: 17%; left: 5%; box-shadow: 0 0 15px var(--purple); }
.orbit-two { inset: -34px; animation-direction: reverse; animation-duration: 28s; border-color: rgba(66,245,230,.12); }
@keyframes spin { to { transform: rotate(360deg); } }
.question-core p { margin: 0 0 2px; color: var(--muted); font: 700 10px "Chakra Petch"; letter-spacing: .25em; }
.question-core h2 { margin: 0; font: 700 clamp(34px, 6vw, 70px)/1 "Chakra Petch"; letter-spacing: -.07em; text-shadow: 0 0 18px rgba(255,255,255,.16); }
.question-core > span { color: var(--cyan); font: 700 clamp(18px, 3vw, 30px) "Chakra Petch"; }
.game-hint { margin: -4px 0 0; color: var(--muted); font-size: 11px; text-align: center; text-transform: uppercase; letter-spacing: .12em; }

.results-screen { align-items: center; justify-content: center; }
.results-card { width: min(680px, 100%); padding: clamp(28px, 5vw, 55px); border: 1px solid rgba(168,85,247,.42); border-radius: 28px; background: linear-gradient(145deg, rgba(34,18,72,.95), rgba(12,7,29,.97)); box-shadow: 0 30px 90px rgba(0,0,0,.45), 0 0 50px rgba(168,85,247,.1); text-align: center; }
.result-burst { width: 88px; height: 88px; margin: 0 auto 20px; display: grid; place-items: center; border: 2px solid var(--cyan); border-radius: 50%; color: var(--cyan); background: rgba(66,245,230,.08); box-shadow: 0 0 30px rgba(66,245,230,.3); font-size: 38px; animation: pop .6s cubic-bezier(.2,1.6,.4,1); }
@keyframes pop { from { transform: scale(.2) rotate(-30deg); } }
.results-card h2 { margin: 4px 0 6px; font: 700 clamp(30px, 6vw, 55px) "Chakra Petch"; }
.result-message { color: var(--muted); }
.final-time { margin: 26px 0; }
.final-time span { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .15em; }
.final-time strong { display: block; color: var(--cyan); font: 700 clamp(42px, 9vw, 76px)/1.1 "Chakra Petch"; text-shadow: 0 0 24px rgba(66,245,230,.32); }
.final-time small { display: inline-block; margin-top: 8px; padding: 5px 10px; border-radius: 30px; color: #130524; background: var(--purple-bright); font-weight: 900; }
.result-stats { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid rgba(255,255,255,.1); border-radius: 14px; overflow: hidden; }
.result-stats div { padding: 15px 8px; }
.result-stats div + div { border-left: 1px solid rgba(255,255,255,.1); }
.result-stats span { display: block; color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: .12em; }
.result-stats strong { font: 700 16px "Chakra Petch"; }
.result-actions { display: flex; justify-content: center; gap: 12px; margin-top: 28px; }

.leaderboard-dialog { width: min(620px, calc(100% - 30px)); max-height: min(720px, calc(100dvh - 30px)); padding: 0; border: 1px solid rgba(168,85,247,.5); border-radius: 23px; color: var(--white); background: #150b31; box-shadow: 0 25px 100px #000; }
.leaderboard-dialog::backdrop { background: rgba(4,2,12,.8); backdrop-filter: blur(7px); }
.dialog-heading { display: flex; justify-content: space-between; align-items: center; padding: 24px; border-bottom: 1px solid rgba(255,255,255,.09); }
.dialog-heading h2 { margin: 0; font: 700 28px "Chakra Petch"; }
.dialog-heading .icon-button { font-size: 25px; }
.score-list { min-height: 180px; max-height: 480px; overflow-y: auto; padding: 10px 24px; }
.score-row { display: grid; grid-template-columns: 35px 55px 1fr auto; align-items: center; gap: 10px; padding: 13px 0; border-bottom: 1px solid rgba(255,255,255,.07); }
.score-rank { color: var(--muted); font: 700 13px "Chakra Petch"; }
.score-player { color: var(--cyan); font: 700 16px "Chakra Petch"; }
.score-detail strong, .score-detail span { display: block; }
.score-detail strong { font-size: 13px; }
.score-detail span { color: var(--muted); font-size: 10px; }
.score-time { font: 700 17px "Chakra Petch"; }
.empty-scores { padding: 55px 20px; color: var(--muted); text-align: center; }
.dialog-footer { display: flex; justify-content: space-between; align-items: center; padding: 16px 24px; border-top: 1px solid rgba(255,255,255,.09); }
.dialog-footer p { margin: 0; color: var(--muted); font-size: 10px; }
.text-button.danger { color: var(--danger); }

@media (max-width: 720px) {
  .app-shell { padding: 15px; }
  .screen { min-height: calc(100dvh - 30px); }
  .brand-row { margin-bottom: 14px; }
  .player-section { grid-template-columns: 1fr; gap: 16px; }
  .mode-tabs { gap: 7px; }
  .mode-tab { display: flex; min-height: 74px; flex-direction: column; align-items: center; justify-content: center; gap: 4px; text-align: center; }
  .mode-icon { width: auto; height: auto; background: none; font-size: 17px; }
  .mode-tab small { display: none; }
  .number-grid { grid-template-columns: repeat(6, 1fr); }
  .number-grid .number-button:last-child { grid-column: auto; }
  .start-row { gap: 12px; }
  .best-preview { display: none; }
  .primary-button { flex: 1; justify-content: center; }
  .game-header { grid-template-columns: auto 1fr auto; }
  .game-stat { display: none; }
  .timer-card { min-width: 111px; padding: 7px 10px; }
  .timer-card strong { font-size: 17px; }
  .game-board { min-height: 480px; grid-template-columns: minmax(88px, 1fr) minmax(105px, 1.15fr) minmax(88px, 1fr); grid-template-rows: repeat(3, 1fr); }
  .answer { width: clamp(82px, 27vw, 125px); border-radius: 15px 6px 15px 6px; font-size: clamp(22px, 8vw, 34px); }
  .question-core { width: clamp(112px, 34vw, 165px); }
  .question-core h2 { font-size: clamp(30px, 10vw, 46px); }
  .result-actions { flex-direction: column-reverse; }
  .result-actions button { width: 100%; justify-content: center; }
}

@media (max-width: 430px) {
  .brand-mark { width: 48px; border-radius: 14px 5px; }
  .brand-copy .eyebrow { display: none; }
  h1 { font-size: 23px; }
  .leaderboard-button { width: 42px; height: 42px; }
  .setup-section { padding: 18px 16px; }
  .section-heading { gap: 10px; }
  .step-number { font-size: 22px; }
  .section-heading h2 { font-size: 16px; }
  .mode-tabs { margin-top: 16px; }
  .mode-tab { padding: 8px 4px; }
  .mode-tab strong { font-size: 12px; }
  .number-button { min-height: 40px; }
  .count-options { gap: 5px; }
  .count-options button { min-height: 42px; }
  .start-row { padding: 16px; }
  .game-board { width: calc(100% + 4px); min-height: 420px; gap: 1px; }
  .answer { width: clamp(76px, 25vw, 102px); }
  .orbit-two { display: none; }
  .result-stats strong { font-size: 13px; }
}

@media (max-height: 720px) and (min-width: 721px) {
  .app-shell { padding-block: 16px; }
  .screen { min-height: calc(100dvh - 32px); }
  .brand-row { margin-bottom: 12px; }
  .brand-mark { width: 50px; }
  .setup-section { padding-block: 14px; }
  .mode-tabs { margin-block: 12px 10px; }
  .mode-tab { min-height: 66px; }
  .number-button, .count-options button { min-height: 38px; }
  .count-options { margin-top: 12px; }
  .start-row { padding-block: 14px; }
  .game-board { min-height: 400px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}
