:root {
  --bg: #120e22;
  --panel: #1c1633;
  --key: #2e2652;
  --key-edge: #1a1433;
  --key-text: #f4f0ff;
  --fire: #39b85a;
  --fire-edge: #1f7a38;
  --del: #6a3a52;
  --del-edge: #42213a;
  --good: #5fe08a;
  --bad: #ff5d6c;
  --muted: #a99fcf;
  --accent: #ffd34d;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--key-text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#app {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  overflow: hidden;
}

/* HUD */
#hud {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 2px solid #000;
}
.stat { display: flex; flex-direction: column; min-width: 58px; }
.stat .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.stat span:last-child { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.hud-btns { margin-left: auto; display: flex; gap: 6px; }
.hud-btns button {
  width: 40px; height: 40px;
  border: 0; border-radius: 10px;
  background: var(--key); color: var(--key-text);
  font-size: 18px;
}

/* Stage */
#stage { position: relative; flex: 1 1 auto; min-height: 180px; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#streak {
  position: absolute; top: 10px; left: 0; right: 0;
  text-align: center; font-weight: 800; font-size: 18px;
  color: var(--accent); text-shadow: 0 2px 0 #000;
  pointer-events: none; opacity: 0; transition: opacity .2s;
}
#streak.show { opacity: 1; }

/* Question + keypad */
#panel {
  flex: 0 0 auto;
  background: var(--panel);
  border-top: 2px solid #000;
  padding: 10px 16px 12px;
}
#qrow {
  display: flex; justify-content: center; align-items: baseline; gap: 12px;
  font-size: clamp(30px, 9vw, 44px); font-weight: 900;
  font-variant-numeric: tabular-nums;
}
#answer {
  min-width: 2.2em; text-align: center;
  padding: 0 .2em;
  border-bottom: 4px solid var(--accent);
  color: var(--accent);
}
#qrow.good #answer { color: var(--good); border-color: var(--good); }
#qrow.bad { animation: shake .35s; }
#qrow.bad #answer { color: var(--bad); border-color: var(--bad); }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-10px); }
  40% { transform: translateX(10px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}
#hint {
  height: 22px; margin: 4px 0 6px;
  text-align: center; font-weight: 700; font-size: 16px;
  color: var(--bad);
}

#keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  transition: opacity .2s;
}
#keypad.off { opacity: .45; pointer-events: none; }
#keypad button {
  height: clamp(46px, 7.5dvh, 66px);
  border: 0;
  border-radius: 14px;
  background: var(--key);
  box-shadow: 0 5px 0 var(--key-edge);
  color: var(--key-text);
  font-size: 26px; font-weight: 800;
  font-family: inherit;
  touch-action: manipulation;
}
#keypad button.pressed { transform: translateY(4px); box-shadow: 0 1px 0 var(--key-edge); }
#keypad .fire { background: var(--fire); box-shadow: 0 5px 0 var(--fire-edge); font-size: 22px; letter-spacing: .05em; }
#keypad .fire.pressed { box-shadow: 0 1px 0 var(--fire-edge); }
#keypad .del { background: var(--del); box-shadow: 0 5px 0 var(--del-edge); }
#keypad .del.pressed { box-shadow: 0 1px 0 var(--del-edge); }

/* Overlay */
#overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  background: rgba(8, 5, 18, .72);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 10;
}
#overlay[hidden] { display: none; }
.card {
  width: 100%; max-width: 380px;
  background: var(--panel);
  border: 2px solid #3a2f66;
  border-radius: 20px;
  padding: 22px 20px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,.5);
}
.card h1 { margin: 0 0 10px; font-size: 32px; font-weight: 900; color: var(--accent); }
#ovBody { color: #ddd6f7; font-size: 16px; line-height: 1.45; }
#ovBody p { margin: 8px 0; }
#ovBody .big { font-size: 28px; font-weight: 900; color: #fff; }
#ovBody .new { color: var(--good); font-weight: 800; }
#ovButtons { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.btn {
  border: 0; border-radius: 14px;
  padding: 14px; font-size: 20px; font-weight: 800; font-family: inherit;
  background: var(--key); color: var(--key-text);
  box-shadow: 0 4px 0 var(--key-edge);
}
.btn.primary { background: var(--fire); box-shadow: 0 4px 0 var(--fire-edge); }
.btn:active { transform: translateY(3px); box-shadow: none; }

.modes { display: flex; gap: 6px; justify-content: center; margin: 12px 0 4px; }
.modes button {
  flex: 1; border: 2px solid #3a2f66; border-radius: 12px;
  padding: 10px 4px; background: transparent; color: var(--key-text);
  font-size: 16px; font-weight: 800; font-family: inherit;
}
.modes button.on { background: var(--accent); color: #1a1433; border-color: var(--accent); }
