:root {
  --bg-0: #060814;
  --bg-1: #0d1330;
  --panel: #121a3a;
  --panel-border: rgba(120, 170, 255, 0.18);
  --cyan: #5be6ff;
  --violet: #a35bff;
  --magenta: #ff5bd6;
  --green: #4dff9e;
  --pink: #ff5b9e;
  --gold: #ffd25b;
  --text: #eaf2ff;
  --text-dim: #93a3d1;
  --radius: 16px;
  --safe-touch: 44px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-0);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
  overscroll-behavior: none;
  touch-action: manipulation;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(ellipse at 20% -10%, rgba(163, 91, 255, 0.18), transparent 55%),
    radial-gradient(ellipse at 90% 110%, rgba(91, 230, 255, 0.14), transparent 55%),
    var(--bg-0);
}

/* Standing GameCMB fix: an author display: rule on any element beats the
   browser's own [hidden]{display:none} UA rule regardless of specificity,
   so every overlay/modal/screen in this game relies on this one global
   override rather than a per-component fix. */
[hidden] { display: none !important; }

a { color: var(--cyan); }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  max-width: 720px;
  margin: 0 auto;
}
.brand {
  font-weight: 700;
  letter-spacing: 0.04em;
  font-size: 13px;
  color: var(--text-dim);
}
.brand span { opacity: 0.5; margin: 0 4px; }
.header-icons { display: flex; gap: 6px; }
.icon-btn {
  width: var(--safe-touch);
  height: var(--safe-touch);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--panel-border);
  font-size: 18px;
}
.icon-btn:hover { background: rgba(255,255,255,0.09); }

main#app {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 14px 24px;
}

.screen { display: block; }

/* ---------------- Start screen ---------------- */
#start-screen {
  text-align: center;
  padding: 36px 8px 12px;
}
.game-title {
  font-size: clamp(32px, 9vw, 52px);
  margin: 0.2em 0 0;
  letter-spacing: 0.03em;
  background: linear-gradient(90deg, var(--cyan), var(--violet) 60%, var(--magenta));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 40px rgba(91,230,255,0.25);
}
.subtitle {
  color: var(--text-dim);
  letter-spacing: 0.08em;
  font-size: 13px;
  margin: 6px 0 28px;
}
.btn {
  display: block;
  width: 100%;
  max-width: 320px;
  margin: 0 auto 12px;
  padding: 15px 18px;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.03em;
  min-height: var(--safe-touch);
  transition: transform 0.12s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: linear-gradient(135deg, var(--cyan), var(--violet));
  color: #06101c;
  box-shadow: 0 8px 30px rgba(91,230,255,0.25);
}
.btn-secondary {
  background: rgba(163,91,255,0.14);
  border: 1px solid rgba(163,91,255,0.4);
  color: var(--text);
}
.btn-ghost {
  background: transparent;
  border: 1px solid var(--panel-border);
  color: var(--text-dim);
}
.profile-line {
  margin-top: 22px;
  font-size: 13px;
  color: var(--text-dim);
}
.link-btn {
  color: var(--cyan);
  text-decoration: underline;
  font-size: 13px;
  padding: 6px;
}

/* ---------------- Game screen ---------------- */
#game-screen.screen { display: block; }
.hud {
  display: flex;
  justify-content: space-between;
  padding: 6px 6px 0;
}
.hud-label { font-size: 10px; letter-spacing: 0.1em; color: var(--text-dim); }
.hud-value { font-size: 20px; font-weight: 800; }
.hud-center { text-align: center; }
.hud-right { text-align: right; }
#hud-combo { color: var(--gold); }

.hud2 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 6px 10px;
  gap: 10px;
}
.lives { font-size: 16px; letter-spacing: 2px; }
.timer-wrap { position: relative; width: 60px; height: 60px; flex-shrink: 0; }
.timer-wrap svg { width: 60px; height: 60px; transform: rotate(-90deg); }
#timer-ring-bg { fill: none; stroke: rgba(255,255,255,0.08); stroke-width: 5; }
#timer-ring-fg {
  fill: none;
  stroke: var(--cyan);
  stroke-width: 5;
  stroke-linecap: round;
  transition: stroke 0.2s ease;
}
#timer-ring-fg.timer-low { stroke: var(--pink); }
#timer-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 16px;
}
#timer-text.timer-low { color: var(--pink); animation: pulseTimer 0.6s infinite; }
@keyframes pulseTimer { 0%,100% { transform: scale(1); } 50% { transform: scale(1.15); } }

.board-wrap {
  position: relative;
  display: flex;
  justify-content: center;
  margin: 4px auto 10px;
}
#game-canvas {
  border-radius: var(--radius);
  box-shadow: 0 0 0 1px var(--panel-border), 0 20px 60px rgba(0,0,0,0.5);
  touch-action: none;
  max-width: 100%;
}

.toast {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(10,14,30,0.88);
  border: 1px solid var(--panel-border);
  padding: 8px 16px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.03em;
  pointer-events: none;
  animation: toastPop 0.25s ease;
  z-index: 5;
}
@keyframes toastPop { from { opacity: 0; transform: translate(-50%, -6px); } to { opacity: 1; transform: translate(-50%, 0); } }
.toast-hit { color: var(--cyan); border-color: rgba(91,230,255,0.5); }
.toast-perfect { color: var(--gold); border-color: rgba(255,210,91,0.6); }
.toast-miss { color: var(--pink); border-color: rgba(255,91,158,0.5); }
.toast-warn { color: var(--gold); }

.play-hint {
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.6;
  margin: 4px 0 0;
}
.play-hint span { display: block; font-size: 11px; opacity: 0.8; }

/* ---------------- Overlays ---------------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(4,6,16,0.72);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 40;
}
.overlay-panel {
  background: linear-gradient(160deg, var(--panel), #0a1026);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 22px 20px;
  width: 100%;
  max-width: 400px;
  max-height: 86vh;
  overflow-y: auto;
  box-shadow: 0 30px 80px rgba(0,0,0,0.55);
}
.overlay-title {
  font-size: 20px;
  font-weight: 800;
  margin: 0 0 12px;
  letter-spacing: 0.03em;
}
.overlay-close {
  float: right;
  font-size: 20px;
  width: 36px;
  height: 36px;
}

.howto-steps { padding-left: 20px; margin: 0 0 14px; line-height: 1.7; font-size: 14px; }
.howto-steps li { margin-bottom: 6px; }

/* Game over */
.go-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 16px 0;
}
.go-stat { background: rgba(255,255,255,0.04); border-radius: 12px; padding: 10px; text-align: center; }
.go-stat-label { font-size: 10px; color: var(--text-dim); letter-spacing: 0.08em; }
.go-stat-value { font-size: 22px; font-weight: 800; }
#go-final-score { color: var(--cyan); }
.new-best-badge {
  text-align: center;
  color: #06101c;
  background: linear-gradient(135deg, var(--gold), var(--magenta));
  font-weight: 800;
  border-radius: 10px;
  padding: 8px;
  margin-bottom: 12px;
  animation: bestPop 0.5s ease;
}
@keyframes bestPop { from { transform: scale(0.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* Leaderboard */
.lb-tabs { display: flex; gap: 8px; margin-bottom: 10px; }
.lb-mode-tab, .lb-scope-tab {
  flex: 1;
  padding: 9px 6px;
  border-radius: 10px;
  background: rgba(255,255,255,0.05);
  border: 1px solid transparent;
  font-size: 12px;
  font-weight: 700;
}
.lb-mode-tab.active, .lb-scope-tab.active {
  background: rgba(91,230,255,0.16);
  border-color: rgba(91,230,255,0.5);
  color: var(--cyan);
}
#lb-scope-tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.lb-list { list-style: none; margin: 0; padding: 0; }
.lb-row, .lb-empty {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  gap: 8px;
  padding: 9px 6px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  font-size: 14px;
  align-items: center;
}
.lb-empty { text-align: center; color: var(--text-dim); display: block; }
.lb-rank { color: var(--text-dim); font-weight: 700; }
.lb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-weight: 800; color: var(--cyan); }
.lb-row-you { background: rgba(163,91,255,0.12); border-radius: 8px; }
#lb-you {
  margin-top: 10px;
  text-align: center;
  padding: 8px;
  border-radius: 10px;
  background: rgba(255,255,255,0.05);
  font-weight: 700;
}
.lb-you-rank { color: var(--gold); margin-left: 6px; }

/* Nickname modal */
#nickname-input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: rgba(255,255,255,0.05);
  color: var(--text);
  font-size: 16px;
  margin-bottom: 6px;
}
#nickname-error { color: var(--pink); font-size: 12px; min-height: 16px; margin-bottom: 10px; }
.nickname-actions { display: flex; gap: 10px; }
.nickname-actions .btn { margin: 0; }

/* ---------------- Below-the-fold SEO content ---------------- */
.seo-content {
  max-width: 720px;
  margin: 28px auto 0;
  padding: 0 14px 40px;
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.7;
}
.seo-content h2 { color: var(--text); font-size: 18px; margin: 22px 0 8px; }
.seo-content ul { padding-left: 20px; }
.ad-slot {
  max-width: 720px;
  margin: 18px auto;
  padding: 14px;
  text-align: center;
  color: var(--text-dim);
  font-size: 11px;
  border: 1px dashed var(--panel-border);
  border-radius: 12px;
}
.related-games { display: flex; flex-wrap: wrap; gap: 10px; padding: 0; list-style: none; }
.related-games li a {
  display: block;
  padding: 10px 14px;
  background: rgba(255,255,255,0.04);
  border-radius: 10px;
  text-decoration: none;
  font-size: 13px;
}

footer.site-footer {
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  padding: 20px 14px 40px;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

@media (max-width: 420px) {
  .go-stats { grid-template-columns: 1fr 1fr; }
  .overlay-panel { padding: 18px 14px; }
}
