@font-face {
  font-family: 'Press Start 2P';
  src: url(../fonts/press-start-2p.woff2) format('woff2');
  font-display: block;
}

:root {
  --bg: #0b0420;
  --cyan: #00f0ff;
  --mag: #ff2bd6;
  --yel: #ffe600;
  --lime: #39ff14;
  --red: #ff2050;
  --orange: #ff8a00;
  --white: #f4f0ff;
  --dim: #8a7ab8;
  --panel: rgba(8, 2, 24, 0.72);
  --gutter: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--white);
  font-family: 'Press Start 2P', ui-monospace, monospace;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  -webkit-font-smoothing: none;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}

#bg, #fx { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#bg { z-index: 0; }
#fx { z-index: 5; pointer-events: none; }

#crt {
  position: fixed; inset: 0; z-index: 6; pointer-events: none;
  background:
    radial-gradient(ellipse at center, transparent 62%, rgba(0, 0, 0, 0.6) 100%),
    repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0.22) 0 1px, transparent 1px 3px);
  animation: flicker 4s infinite steps(1);
}
@keyframes flicker { 0%, 100% { opacity: 1; } 47% { opacity: 0.93; } 48% { opacity: 1; } 81% { opacity: 0.96; } }

#app {
  position: fixed; inset: 0; z-index: 2;
  max-width: 520px; margin: 0 auto;
}
#app.shake { animation: shake 0.32s steps(8); }
@keyframes shake {
  0% { transform: translate(0, 0); }
  15% { transform: translate(-9px, 4px); }
  30% { transform: translate(8px, -5px); }
  45% { transform: translate(-6px, -3px); }
  60% { transform: translate(5px, 4px); }
  75% { transform: translate(-3px, 2px); }
  100% { transform: translate(0, 0); }
}

/* ---------- screens ---------- */
.screen {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column; align-items: center; justify-content: center; justify-content: safe center;
  gap: 14px;
  overflow-y: auto;
  padding: calc(env(safe-area-inset-top) + 16px) var(--gutter) calc(env(safe-area-inset-bottom) + 16px);
  text-align: center;
}
.screen.active { display: flex; animation: screen-in 0.22s steps(4); }
@keyframes screen-in { from { opacity: 0; transform: scale(1.04); } to { opacity: 1; transform: none; } }

h2 {
  font-size: 18px; line-height: 1.5;
  color: var(--yel);
  text-shadow: 0 0 6px var(--yel), 3px 3px 0 #7a1fa0;
}
.hint { font-size: 9px; line-height: 1.8; color: var(--dim); }
.row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.blink { animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- logo ---------- */
.logo { display: flex; flex-direction: column; align-items: center; line-height: 1; transform: skew(-8deg); }
.logo span { display: block; font-size: clamp(44px, 15vw, 76px); letter-spacing: 2px; }
.logo .l1 {
  color: var(--cyan);
  text-shadow: 0 0 8px var(--cyan), 0 0 24px var(--cyan), 5px 5px 0 #0a3a8a;
}
.logo .l2 {
  margin-top: 6px;
  background: linear-gradient(#fff 0%, #ffe600 42%, #ff8a00 50%, #ff2bd6 58%, #7a00ff 100%);
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 10px rgba(255, 43, 214, 0.8)) drop-shadow(5px 5px 0 #3a0060);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse { 50% { filter: drop-shadow(0 0 18px rgba(255, 43, 214, 1)) drop-shadow(5px 5px 0 #3a0060); } }
.logo.small span { font-size: clamp(28px, 9vw, 40px); }
.sub { font-size: 10px; color: var(--mag); letter-spacing: 2px; text-shadow: 0 0 6px var(--mag); margin-top: 8px; }
.press { margin-top: 48px; font-size: 14px; color: var(--white); text-shadow: 0 0 8px #fff; }
.credit { position: absolute; bottom: calc(env(safe-area-inset-bottom) + 20px); font-size: 9px; color: var(--dim); }

/* ---------- buttons ---------- */
.btn {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  min-width: 240px;
  padding: 14px 18px;
  font-size: 13px;
  color: var(--cyan);
  background: var(--panel);
  border: 3px solid currentColor;
  box-shadow: 0 0 10px rgba(0, 240, 255, 0.35), inset 0 0 10px rgba(0, 240, 255, 0.15), 4px 4px 0 rgba(0, 0, 0, 0.6);
  text-shadow: 0 0 6px currentColor;
  transition: transform 0.05s;
}
.btn small { font-size: 8px; color: var(--yel); text-shadow: none; }
.btn small:empty { display: none; }
.btn:focus-visible, .btn.sel { outline: none; background: rgba(0, 240, 255, 0.18); }
.btn:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 rgba(0, 0, 0, 0.6); }
.btn.big { font-size: 18px; padding: 18px; color: var(--yel); box-shadow: 0 0 14px rgba(255, 230, 0, 0.45), inset 0 0 10px rgba(255, 230, 0, 0.15), 4px 4px 0 rgba(0, 0, 0, 0.6); }
.btn.hard { color: var(--red); box-shadow: 0 0 12px rgba(255, 32, 80, 0.45), 4px 4px 0 rgba(0, 0, 0, 0.6); }
.btn.go { color: var(--lime); box-shadow: 0 0 12px rgba(57, 255, 20, 0.4), 4px 4px 0 rgba(0, 0, 0, 0.6); }
.btn.small { min-width: 0; font-size: 11px; padding: 12px 16px; color: var(--mag); box-shadow: 0 0 8px rgba(255, 43, 214, 0.35), 4px 4px 0 rgba(0, 0, 0, 0.6); }
.menu { display: flex; flex-direction: column; gap: 12px; align-items: stretch; }
.player-btn { flex-direction: row; justify-content: center; gap: 10px; font-size: 11px; color: var(--dim); min-width: 0; padding: 10px 14px; border-width: 2px; box-shadow: none; }
.player-btn b { font-weight: normal; font-size: 16px; }
.toggles { margin-top: 6px; }
.tog { font-size: 9px; padding: 10px; color: var(--dim); border: 2px solid currentColor; }
.tog.on { color: var(--lime); text-shadow: 0 0 6px currentColor; }

/* ---------- players ---------- */
.list { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 320px; max-height: 50dvh; overflow-y: auto; }
.prow { display: flex; gap: 8px; }
.prow .btn { flex: 1; min-width: 0; flex-direction: row; justify-content: space-between; font-size: 20px; }
.prow .btn small { font-size: 8px; }
.prow .del { display: none; width: 52px; color: var(--red); border: 3px solid currentColor; font-size: 16px; }
.list.editing .del { display: block; }

.initials { display: flex; gap: 14px; margin: 8px 0; }
.initials span {
  width: 56px; height: 66px;
  display: flex; align-items: center; justify-content: center;
  font-size: 36px; color: var(--yel);
  border-bottom: 4px solid var(--dim);
  text-shadow: 0 0 10px var(--yel);
}
.initials span.cur { border-color: var(--yel); animation: blink 0.8s steps(1) infinite; }
.letters { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; width: 100%; max-width: 380px; }
.letters button {
  height: 46px; font-size: 16px; color: var(--cyan);
  border: 2px solid rgba(0, 240, 255, 0.5); background: var(--panel);
}
.letters button.wide { grid-column: span 2; color: var(--mag); border-color: rgba(255, 43, 214, 0.6); font-size: 11px; }
.letters button.pressed { background: var(--cyan); color: #000; }

/* ---------- practice ---------- */
.tables { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: 100%; max-width: 360px; }
.tables button {
  aspect-ratio: 1.15;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  font-size: 24px; color: var(--cyan);
  border: 3px solid currentColor; background: var(--panel);
  text-shadow: 0 0 8px currentColor;
}
.tables button.x { color: var(--red); }
.tables button:active { transform: translate(2px, 2px); }
.stars { display: flex; gap: 3px; }
.stars img { width: 14px; height: 14px; image-rendering: pixelated; }

/* ---------- game ---------- */
#s-game { justify-content: flex-start; gap: 0; padding-bottom: calc(env(safe-area-inset-bottom) + 12px); }
.hud { width: 100%; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }
.hud-l { text-align: left; }
.hud-r { text-align: right; }
.lbl { font-size: 8px; color: var(--dim); letter-spacing: 1px; }
.val { font-size: 18px; color: var(--yel); text-shadow: 0 0 8px var(--yel); margin-top: 6px; }
.val.bump { animation: bump 0.18s steps(3); }
@keyframes bump { 50% { transform: scale(1.25); color: #fff; } }
.lives { display: flex; gap: 4px; justify-content: center; min-height: 18px; margin-bottom: 6px; }
.lives img { width: 21px; height: 18px; image-rendering: pixelated; }
.lives img.lost { opacity: 0.18; }
.lives img.gain { animation: bump 0.4s steps(4) 2; }
.pause { width: 46px; height: 40px; font-size: 14px; color: var(--dim); border: 2px solid currentColor; }

.combo-row { width: 100%; display: flex; justify-content: space-between; align-items: center; margin-top: 12px; min-height: 26px; }
.combo { font-size: 16px; color: var(--dim); }
.combo.c2 { color: var(--cyan); text-shadow: 0 0 8px var(--cyan); }
.combo.c3 { color: var(--lime); text-shadow: 0 0 8px var(--lime); }
.combo.c4 { color: var(--yel); text-shadow: 0 0 10px var(--yel); }
.combo.c5 { color: var(--orange); text-shadow: 0 0 12px var(--orange); }
.combo.c6 { color: var(--mag); text-shadow: 0 0 14px var(--mag); animation: bump 0.5s steps(2) infinite; }
.streak { font-size: 9px; color: var(--dim); }

.stage { position: relative; flex: 1; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px; min-height: 0; }
.question {
  font-size: clamp(34px, 12vw, 68px);
  color: var(--white);
  text-shadow: 0 0 10px var(--cyan), 0 0 28px rgba(0, 240, 255, 0.6), 4px 4px 0 #3a0a8a;
  white-space: nowrap;
}
.question.pop { animation: qpop 0.16s steps(4); }
@keyframes qpop { from { transform: scale(0.4); opacity: 0; } to { transform: none; opacity: 1; } }
.question.reveal { color: var(--yel); text-shadow: 0 0 12px var(--yel), 4px 4px 0 #6a3a00; font-size: clamp(18px, 6.4vw, 34px); }
.answer { display: flex; }
.answer .field {
  min-width: calc(3em + 40px); height: clamp(60px, 18vw, 78px);
  padding: 0 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(34px, 11vw, 48px);
  color: var(--yel);
  background: rgba(0, 0, 0, 0.5);
  border: 3px solid var(--yel);
  box-shadow: 0 0 12px rgba(255, 230, 0, 0.4);
  text-shadow: 0 0 10px var(--yel);
}
.answer .caret { display: inline-block; width: 0.7em; height: 5px; background: var(--yel); align-self: flex-end; margin: 0 0 18px 2px; animation: blink 0.6s steps(1) infinite; }
.answer.ok .caret, .answer.bad .caret { display: none; }
.answer.ok .field { color: var(--lime); border-color: var(--lime); text-shadow: 0 0 12px var(--lime); box-shadow: 0 0 16px var(--lime); }
.answer.bad .field { color: var(--red); border-color: var(--red); text-shadow: 0 0 12px var(--red); text-decoration: line-through; box-shadow: none; }

.floats { position: absolute; inset: 0; pointer-events: none; }
.float {
  position: absolute; left: 50%; top: 58%;
  font-size: 16px; white-space: nowrap;
  transform: translate(-50%, 0);
  animation: floatup 0.9s ease-out forwards;
}
.float.big { font-size: 22px; }
@keyframes floatup {
  0% { opacity: 0; transform: translate(-50%, 10px) scale(0.6); }
  15% { opacity: 1; transform: translate(-50%, 0) scale(1.15); }
  100% { opacity: 0; transform: translate(-50%, -90px) scale(1); }
}

.timer { width: 100%; height: 16px; border: 2px solid var(--dim); background: rgba(0, 0, 0, 0.5); margin: 10px 0 14px; padding: 2px; }
.timer .bar { height: 100%; width: 100%; transform-origin: left center; background: var(--tc, var(--lime)); box-shadow: 0 0 10px var(--tc, var(--lime)); }
.timer.danger { border-color: var(--red); animation: blink 0.3s steps(1) infinite; }
.timer.off { visibility: hidden; }

.keypad { width: 100%; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.key {
  height: clamp(54px, 9.6dvh, 76px);
  font-size: 24px; color: var(--cyan);
  background: var(--panel);
  border: 3px solid rgba(0, 240, 255, 0.75);
  box-shadow: inset 0 0 12px rgba(0, 240, 255, 0.2), 0 4px 0 rgba(0, 120, 160, 0.9);
  text-shadow: 0 0 8px currentColor;
}
.key.zero { grid-column: span 2; }
.key.del { color: var(--mag); border-color: rgba(255, 43, 214, 0.75); font-size: 14px; box-shadow: inset 0 0 12px rgba(255, 43, 214, 0.2), 0 4px 0 rgba(140, 0, 110, 0.9); }
.key.pressed { transform: translateY(4px); box-shadow: 0 0 0 transparent; background: var(--cyan); color: #000; text-shadow: none; }
.key.del.pressed { background: var(--mag); }

.banner {
  position: absolute; left: 0; right: 0; top: 34%;
  font-size: 30px; color: var(--yel);
  text-shadow: 0 0 12px var(--yel), 4px 4px 0 #a01f60;
  pointer-events: none; opacity: 0;
}
.banner.show { animation: banner 1s steps(10) forwards; }
.banner.hold { animation: banner-hold 1.6s steps(10) forwards; }
.banner.mag { color: var(--mag); text-shadow: 0 0 12px var(--mag), 4px 4px 0 #3a0060; }
.banner.red { color: var(--red); font-size: 34px; text-shadow: 0 0 16px var(--red), 4px 4px 0 #3a0010; }
.banner.lime { color: var(--lime); text-shadow: 0 0 14px var(--lime), 4px 4px 0 #0a3a00; }
@keyframes banner {
  0% { opacity: 0; transform: scale(2.2); }
  15% { opacity: 1; transform: scale(1); }
  75% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(0.8); }
}
@keyframes banner-hold {
  0% { opacity: 0; transform: scale(3); }
  12% { opacity: 1; transform: scale(1); }
  100% { opacity: 1; transform: scale(1); }
}

.overlay {
  position: absolute; inset: 0; z-index: 3;
  display: none; flex-direction: column; align-items: center; justify-content: center; gap: 22px;
  background: rgba(5, 1, 15, 0.94);
}
.overlay.on { display: flex; }

/* ---------- results ---------- */
#s-results { gap: 12px; }
.tally { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 10px; }
.tally div { display: flex; justify-content: space-between; font-size: 11px; animation: screen-in 0.15s steps(3); }
.tally div span:first-child { color: var(--dim); }
.tally div span:last-child { color: var(--white); }
.tally div.bonus span:last-child { color: var(--lime); }
.total { font-size: clamp(30px, 10vw, 44px); color: var(--yel); text-shadow: 0 0 14px var(--yel), 4px 4px 0 #7a1fa0; min-height: 48px; margin-top: 4px; }
.badges { display: flex; flex-direction: column; gap: 10px; align-items: center; min-height: 20px; }
.badge { font-size: 12px; line-height: 1.6; animation: screen-in 0.2s steps(3); }
.badge.pb { font-size: 15px; color: var(--mag); text-shadow: 0 0 10px var(--mag); animation: blink 0.5s steps(1) 6; }
.badge.gold { color: var(--yel); text-shadow: 0 0 10px var(--yel); }
.badge.cyan { color: var(--cyan); }
.badge.dim { color: var(--dim); font-size: 10px; }
.badge .stars img { width: 26px; height: 26px; }
.missed { font-size: 10px; color: var(--dim); line-height: 1.9; max-width: 360px; }
.missed b { color: var(--yel); font-weight: normal; }
#r-buttons { visibility: hidden; margin-top: 6px; }
#r-buttons.on { visibility: visible; animation: screen-in 0.2s steps(3); }
#r-buttons .btn { min-width: 0; }

/* ---------- high scores ---------- */
.tabs { display: flex; gap: 8px; }
.tab { font-size: 10px; padding: 9px 12px; color: var(--dim); border: 2px solid currentColor; }
.tab.on { color: var(--yel); text-shadow: 0 0 6px var(--yel); background: rgba(255, 230, 0, 0.08); }
.scores { list-style: none; width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 9px; min-height: 280px; }
.scores li { display: grid; grid-template-columns: 34px 52px 1fr auto; gap: 8px; align-items: baseline; font-size: 12px; text-align: left; }
.scores li .rk { color: var(--dim); }
.scores li .sc { text-align: right; color: var(--white); }
.scores li .mt { font-size: 7px; color: var(--dim); text-align: right; min-width: 64px; }
.scores li:nth-child(1) .rk, .scores li:nth-child(1) .sc { color: var(--yel); text-shadow: 0 0 8px var(--yel); }
.scores li:nth-child(2) .sc { color: var(--cyan); }
.scores li:nth-child(3) .sc { color: var(--mag); }
.scores li.fresh { background: rgba(255, 230, 0, 0.14); outline: 2px solid rgba(255, 230, 0, 0.6); outline-offset: 3px; animation: fresh 0.4s steps(1) 8; }
@keyframes fresh { 50% { background: transparent; outline-color: transparent; } }
.scores .empty { display: block; text-align: center; color: var(--dim); font-size: 10px; line-height: 2; margin-top: 40px; }

/* ---------- stats ---------- */
.grid { display: grid; gap: 2px; width: 100%; max-width: 420px; }
.grid div { aspect-ratio: 1; display: flex; align-items: center; justify-content: center; font-size: clamp(6px, 2vw, 9px); background: rgba(255, 255, 255, 0.05); color: rgba(255, 255, 255, 0.35); }
.grid div.h { background: none; color: var(--cyan); font-size: clamp(7px, 2.4vw, 11px); }
.grid .c-ace, .legend .c-ace { background: #1f9e2c; color: #eaffea; }
.grid .c-ok, .legend .c-ok { background: #9a8a10; color: #fff8c0; }
.grid .c-slow, .legend .c-slow { background: #b05a00; color: #ffe2c0; }
.grid .c-bad, .legend .c-bad { background: #b0103a; color: #ffd0dc; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; font-size: 8px; color: var(--dim); }
.legend span { display: flex; align-items: center; gap: 5px; }
.legend i { display: inline-block; width: 12px; height: 12px; }

@media (max-height: 640px) {
  .screen { gap: 10px; }
  .btn { padding: 11px 16px; }
  .btn.big { padding: 13px; }
  .logo.small span { font-size: 26px; }
  .key { font-size: 20px; }
  .answer .field { height: 54px; }
}

@media (prefers-reduced-motion: reduce) {
  #crt { animation: none; }
  .logo .l2 { animation: none; }
}
.prow .btn.cur { background: rgba(255, 255, 255, 0.1); outline: 2px dashed currentColor; outline-offset: 4px; }

@media (pointer: fine) {
  .key { height: clamp(44px, 7dvh, 58px); font-size: 20px; }
}

/* ---------- global board ---------- */
.badge.join { color: var(--cyan); margin-top: 6px; }
.badge.join .row { justify-content: center; gap: 12px; margin: 8px 0 4px; }
.badge.join small { display: block; color: var(--dim); font-size: 9px; }
