:root {
  --bg:     #0b1220;
  --panel:  #121a2c;
  --ink:    #e8eefc;
  --muted:  #93a3c9;
  --bd:     rgba(255,255,255,.08);
  --accent: #7dd3fc;
  --ok:     #34d399;
  --warn:   #fbbf24;
  --err:    #fb7185;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

/* ── Layout ─────────────────────────────────────────────────────────────── */

.wrap {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px 40px;
}

.hidden { display: none !important; }

/* ── Back link ───────────────────────────────────────────────────────────── */

.back-btn {
  display: block;
  background: none;
  border: none;
  color: var(--muted);
  font: inherit;
  font-size: .78rem;
  font-weight: 700;
  cursor: pointer;
  padding: 6px 6px 6px 0;
  border-radius: 8px;
  text-decoration: none;
  transition: color .15s;
  white-space: nowrap;
  margin-bottom: 4px;
}
.back-btn:hover { color: var(--ink); }

/* ── Header ──────────────────────────────────────────────────────────────── */

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}
h1 { margin: 0; font-size: 20px; }

.btn {
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid var(--bd);
  background: #0e1729;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  transition: background .12s;
}
.btn:hover { background: #0f1a2f; }

.primary-btn {
  padding: 12px 28px;
  border-radius: 14px;
  border: none;
  background: var(--accent);
  color: #0b1220;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  font-size: 17px;
  transition: opacity .15s, transform .1s;
}
.primary-btn:hover  { opacity: .88; }
.primary-btn:active { transform: scale(.97); }

/* ── Panel base ──────────────────────────────────────────────────────────── */

.panel {
  background: var(--panel);
  border: 1px solid var(--bd);
  border-radius: 16px;
  padding: 16px;
}

/* ── Idle / start screen ─────────────────────────────────────────────────── */

.idle-panel {
  text-align: center;
  padding: 36px 24px 40px;
}
.idle-panel h2 {
  margin: 0 0 14px;
  font-size: 26px;
  font-weight: 800;
  line-height: 1.3;
}
.idle-rules {
  color: var(--muted);
  font-size: 15px;
  margin: 0 0 18px;
  line-height: 1.65;
}
.idle-best {
  font-size: 14px;
  color: var(--muted);
  margin: 0 0 28px;
}
.idle-best strong { color: var(--ink); }

/* ── HUD (inside game panel) ─────────────────────────────────────────────── */

.hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  gap: 6px;
  flex-wrap: wrap;
}
.lives { font-size: 17px; letter-spacing: 1px; }
.hud-right { display: flex; gap: 8px; align-items: center; }

.pill {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  padding: 4px 9px;
  border: 1px solid var(--bd);
  border-radius: 999px;
  background: #0e1729;
  font-size: 13px;
}
.pill strong { font-weight: 800; }

.chain-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--muted);
}
.chain-row strong { color: var(--ink); font-size: 15px; }

.mult {
  font-style: normal;
  font-size: 13px;
  font-weight: 700;
  color: var(--warn);
  min-width: 28px;
}

/* ── Timer bar ───────────────────────────────────────────────────────────── */

.timer-track {
  height: 4px;
  border-radius: 999px;
  background: rgba(255,255,255,.06);
  overflow: hidden;
  margin-bottom: 12px;
}
.timer-bar {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: var(--ok);
  transition: width .1s linear, background .25s ease;
}
.timer-bar.warn   { background: var(--warn); }
.timer-bar.danger { background: var(--err); }

@keyframes penaltyFlash {
  0%, 100% { background: rgba(255,255,255,.06); }
  40%      { background: rgba(251,113,133,.3); }
}
.timer-track.penalty-flash { animation: penaltyFlash .35s ease; }

/* ── Target card ─────────────────────────────────────────────────────────── */

.target {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin: 4px 0 10px;
  padding: 10px;
  border-radius: 14px;
  background: rgba(125,211,252,.05);
  border: 1px solid rgba(125,211,252,.15);
}
.label { font-size: 12px; color: var(--muted); }
.target .num {
  font-size: 48px;
  font-weight: 800;
  letter-spacing: .5px;
  line-height: 1;
}
.live {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
  padding: 4px 0;
}
.expr    { min-height: 20px; font-size: 14px; color: var(--muted); }
.total   { font-size: 20px; font-weight: 700; }
.delta   { font-size: 14px; color: var(--muted); transition: color .12s, transform .12s; }
.delta.exact { color: var(--ok); transform: scale(1.04); }
.delta.over  { color: var(--err); }

/* ── Number grid ─────────────────────────────────────────────────────────── */

.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 10px 0 8px;
}
.cell {
  height: 96px;
  border-radius: 16px;
  border: 1px solid var(--bd);
  background: rgba(255,255,255,.02);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 28px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform .1s ease, background .1s ease, border-color .1s ease, box-shadow .1s ease;
}
.cell:active { transform: scale(.97); }
.cell.sel {
  border-color: rgba(125,211,252,.75);
  background: rgba(125,211,252,.16);
  box-shadow: 0 0 0 2px rgba(125,211,252,.18), 0 8px 20px rgba(0,0,0,.3);
  transform: translateY(-1px);
}

@keyframes hitPulse  { 0%{transform:scale(1)} 50%{transform:scale(1.08)} 100%{transform:scale(1)} }
@keyframes overShake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-4px)} 75%{transform:translateX(4px)} }

.cell.hit  { animation: hitPulse  .18s ease; }
.cell.over { animation: overShake .18s ease; border-color: rgba(251,113,133,.45); }

/* ── Action buttons ──────────────────────────────────────────────────────── */

.actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 12px;
}
.actions button {
  padding: 10px 18px;
  border-radius: 12px;
  border: 1px solid var(--bd);
  background: #0e1729;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  transition: background .12s;
}
.actions button:hover { background: #0f1a2f; }

.skip-btn {
  border-color: rgba(251,113,133,.28) !important;
  color: var(--err) !important;
}
.skip-btn:hover { background: rgba(251,113,133,.07) !important; }

/* ── Toast ───────────────────────────────────────────────────────────────── */

.toast {
  height: 22px;
  text-align: center;
  font-size: 14px;
  color: var(--muted);
  margin-top: 10px;
}
.toast.ok  { color: var(--ok); }
.toast.err { color: var(--err); }

/* ── Result panel ────────────────────────────────────────────────────────── */

.result-panel {
  text-align: center;
  padding: 28px 20px 32px;
}
.result-header {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .1em;
  margin-bottom: 10px;
}
.result-score {
  font-size: 68px;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
  margin-bottom: 14px;
}
.result-stat {
  font-size: 15px;
  color: var(--muted);
  margin-bottom: 5px;
}
.result-stat strong { color: var(--ink); }
.result-best {
  display: inline-block;
  font-size: 13px;
  color: var(--muted);
  margin: 12px 0 22px;
  padding: 5px 14px;
  border-radius: 999px;
  border: 1px solid var(--bd);
}
.result-best.new-best {
  color: var(--ok);
  border-color: rgba(52,211,153,.3);
  background: rgba(52,211,153,.07);
}
.result-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-bottom: 18px;
}
.back-link {
  font-size: 13px;
  color: var(--muted);
  text-decoration: none;
  transition: color .15s;
}
.back-link:hover { color: var(--ink); }

/* ── Keyboard hint ───────────────────────────────────────────────────────── */

.kbd-hint {
  margin: 12px 4px 0;
  color: var(--muted);
  font-size: 12px;
  opacity: .65;
  text-align: center;
}
@media (max-width: 559px) { .kbd-hint { display: none; } }
@media (min-width: 560px) { .cell { height: 116px; } }
