:root {
  --bg: #0b0f1a;
  --bg2: #131a2e;
  --card: #171f36;
  --line: #26304f;
  --text: #eef2ff;
  --muted: #8a95b8;
  --l: #34d399;   /* left pad green */
  --r: #38bdf8;   /* right pad blue */
  --accent: #fbbf24;
  --danger: #fb7185;
  --gold: #fcd34d;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%;
  background: radial-gradient(120% 90% at 50% -10%, #1a2340 0%, var(--bg) 60%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overscroll-behavior: none;
  user-select: none; -webkit-user-select: none;
}
body { touch-action: manipulation; }
#app { max-width: 520px; margin: 0 auto; min-height: 100%; position: relative; }

.screen { display: none; padding: max(18px, env(safe-area-inset-top)) 18px 24px; min-height: 100dvh; flex-direction: column; }
.screen.active { display: flex; }

/* ---------------- HOME ---------------- */
.brand { text-align: center; margin: 8px 0 14px; }
.logo { font-size: 44px; font-weight: 900; letter-spacing: -1.5px; margin: 0; }
.logo span { color: var(--r); }
.logo em { font-style: normal; }
.tagline { color: var(--muted); font-size: 14px; margin: 6px 0 0; }

.home-stats { display: flex; gap: 10px; margin: 6px 0 18px; }
.stat {
  flex: 1; background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 12px 6px; text-align: center; color: var(--text);
  display: flex; flex-direction: column; gap: 2px; font: inherit; cursor: default;
}
.stat.streak { cursor: pointer; }
.stat-val { font-size: 24px; font-weight: 800; line-height: 1; }
.stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }

.btn-play {
  border: 0; border-radius: 22px; padding: 22px; font-size: 26px; font-weight: 900; letter-spacing: 1px;
  color: #05231b; cursor: pointer; margin: 4px 0 16px;
  background: linear-gradient(135deg, var(--l), #22d3ee);
  box-shadow: 0 12px 30px -8px rgba(52,211,153,.6), inset 0 -4px 0 rgba(0,0,0,.15);
  transition: transform .08s ease, box-shadow .2s ease;
}
.btn-play:active { transform: translateY(3px) scale(.99); box-shadow: 0 6px 16px -8px rgba(52,211,153,.6); }
.btn-play.compact { padding: 16px; font-size: 20px; border-radius: 18px; }

.identity { display: flex; gap: 10px; margin-bottom: 16px; }
.name-input, .country-select {
  background: var(--card); border: 1px solid var(--line); color: var(--text);
  border-radius: 14px; padding: 12px 14px; font-size: 15px; outline: none; width: 100%;
}
.name-input { flex: 2; } .country-select { flex: 1; min-width: 90px; }
.name-input:focus, .country-select:focus { border-color: var(--r); }

.badges { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; min-height: 4px; }
.badge {
  font-size: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 11px; display: inline-flex; gap: 5px; align-items: center;
}
.badge.locked { opacity: .35; filter: grayscale(1); }
.badge.new { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(252,211,77,.25); animation: pop .4s ease; }

.board-card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 12px; margin-bottom: 16px; }
.board-tabs { display: flex; gap: 6px; margin-bottom: 8px; }
.tab {
  flex: 1; background: transparent; border: 1px solid var(--line); color: var(--muted);
  border-radius: 999px; padding: 8px 4px; font-size: 12px; font-weight: 700; cursor: pointer;
}
.tab.active { background: var(--r); border-color: var(--r); color: #04263a; }
.board { list-style: none; margin: 0; padding: 0; min-height: 60px; }
.board li {
  display: grid; grid-template-columns: 26px 1fr auto; align-items: center; gap: 8px;
  padding: 9px 6px; border-bottom: 1px solid var(--line); font-size: 15px;
}
.board li:last-child { border-bottom: 0; }
.board .rk { color: var(--muted); font-weight: 800; text-align: center; }
.board li:nth-child(1) .rk { color: var(--gold); }
.board li:nth-child(2) .rk { color: #cbd5e1; }
.board li:nth-child(3) .rk { color: #d6a67a; }
.board .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .flag { margin-right: 6px; }
.board .sc { font-weight: 800; color: var(--l); }
.board .empty { color: var(--muted); text-align: center; padding: 18px 0; font-size: 14px; }
.board li.me { background: rgba(56,189,248,.12); border-radius: 8px; }

.btn-ghost {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  border-radius: 12px; padding: 10px 14px; font-size: 14px; cursor: pointer; font-weight: 600;
}
.btn-ghost:active { background: var(--bg2); }
#btn-refresh { width: 100%; margin-top: 8px; }

.foot { text-align: center; color: var(--muted); font-size: 13px; margin-top: auto; padding-top: 12px; }
.link { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 13px; padding: 4px; }
.link:active { color: var(--text); }
.dot { opacity: .5; margin: 0 2px; }

/* ---------------- GAME ---------------- */
.game { padding: 0; }
.hud { padding: max(12px, env(safe-area-inset-top)) 16px 6px; }
.timebar-wrap { height: 10px; background: var(--bg2); border-radius: 99px; overflow: hidden; }
.timebar { height: 100%; width: 100%; background: linear-gradient(90deg, var(--l), var(--accent), var(--danger)); transition: width .1s linear; }
.hud-row { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.hud-score { font-size: 40px; font-weight: 900; min-width: 60px; }
.hud-time { font-size: 18px; color: var(--muted); font-weight: 700; min-width: 60px; text-align: right; }
.hud-combo { font-size: 20px; font-weight: 900; color: var(--accent); text-align: center; min-height: 24px; transition: transform .1s; }
.hud-combo.bump { transform: scale(1.35); }

.pads { flex: 1; display: flex; gap: 12px; padding: 12px; }
.pad {
  flex: 1; border: 0; border-radius: 26px; cursor: pointer; position: relative;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  background: #1a2036; color: rgba(255,255,255,.15); transition: background .08s, box-shadow .12s, transform .05s;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.03);
}
.pad-glyph { font-size: 64px; font-weight: 900; transition: color .1s, transform .08s; }
.pad-l.active { background: radial-gradient(120% 120% at 50% 30%, #4bf0b0, var(--l)); box-shadow: 0 0 60px -6px var(--l), inset 0 0 0 3px rgba(255,255,255,.25); }
.pad-r.active { background: radial-gradient(120% 120% at 50% 30%, #6fd4ff, var(--r)); box-shadow: 0 0 60px -6px var(--r), inset 0 0 0 3px rgba(255,255,255,.25); }
.pad.active .pad-glyph { color: rgba(255,255,255,.95); }
.pad.hit { transform: scale(.97); }
.pad.wrong { animation: wrong .3s ease; }
@keyframes wrong { 0%,100%{transform:translateX(0)} 20%{transform:translateX(-10px)} 40%{transform:translateX(10px)} 60%{transform:translateX(-6px)} 80%{transform:translateX(6px)} }

.prestart {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; pointer-events: none; background: rgba(11,15,26,.55); backdrop-filter: blur(2px); gap: 6px;
}
.prestart-title { font-size: 24px; font-weight: 800; margin: 0; }
.prestart-sub { color: var(--muted); margin: 0; }
.prestart-go { margin-top: 18px; font-size: 15px; color: var(--accent); font-weight: 700; animation: pulse 1.1s ease-in-out infinite; }
.prestart.hidden { display: none; }

.fx { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 5; }

/* ---------------- RESULT ---------------- */
.result { align-items: center; justify-content: center; }
.result-card { background: var(--card); border: 1px solid var(--line); border-radius: 24px; padding: 26px 22px; width: 100%; text-align: center; z-index: 6; }
.result-kicker { color: var(--muted); text-transform: uppercase; letter-spacing: 2px; font-size: 13px; margin: 0; }
.result-score { font-size: 84px; font-weight: 900; line-height: 1; margin: 4px 0; background: linear-gradient(135deg, var(--l), var(--r)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.result-record { color: var(--gold); font-weight: 800; margin: 0 0 6px; animation: pop .5s ease; }
.result-grid { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 8px; margin: 18px 0; }
.result-grid > div { background: var(--bg2); border-radius: 12px; padding: 10px 4px; display: flex; flex-direction: column; }
.result-grid b { font-size: 22px; } .result-grid span { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.result-rank { font-size: 15px; color: var(--text); font-weight: 700; min-height: 20px; margin: 4px 0; }
.result-rank b { color: var(--accent); }
.result-badges { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 8px 0 16px; }
.result-actions { display: flex; flex-direction: column; gap: 10px; }
.result-actions-row { display: flex; gap: 10px; }
.result-actions-row .btn-ghost { flex: 1; }

/* ---------------- MODAL ---------------- */
.modal { position: fixed; inset: 0; background: rgba(4,7,15,.7); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50; }
[hidden] { display: none !important; }
.modal-card { background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 24px; max-width: 440px; }
.modal-card h2 { margin: 0 0 14px; }
.modal-card ul { margin: 0 0 18px; padding-left: 20px; color: var(--text); line-height: 1.7; font-size: 15px; }
.modal-card b { color: var(--accent); }

@keyframes pop { 0%{transform:scale(.6);opacity:0} 60%{transform:scale(1.1)} 100%{transform:scale(1);opacity:1} }
@keyframes pulse { 0%,100%{opacity:.5} 50%{opacity:1} }

.shake { animation: shake .25s ease; }
@keyframes shake { 0%,100%{transform:translate(0,0)} 25%{transform:translate(-4px,2px)} 75%{transform:translate(4px,-2px)} }
