:root {
  --bg: #0e1020;
  --bg-2: #15182e;
  --panel: rgba(20, 23, 44, 0.92);
  --ink: #eef1ff;
  --muted: #8a90b8;
  --accent: #5cf2c2;
  --accent-2: #ff5c8a;
  --line: rgba(255, 255, 255, 0.08);
  --radius: 16px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(1200px 700px at 50% -10%, var(--bg-2), var(--bg));
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

.layout {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100vh;
  gap: 14px;
  padding: 14px;
}

/* --- Ads ------------------------------------------------------------------ */
.ad-rail {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 90px;
}
.ad-slot { width: 100%; max-width: 728px; }
.ad-placeholder {
  width: 100%;
  max-width: 728px;
  min-height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed var(--line);
  border-radius: 12px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  background: rgba(255, 255, 255, 0.02);
}
/* When a real ad is present, hide the placeholder next to it. */
.ad-rail.ad-live .ad-placeholder { display: none; }
.ad-rail:not(.ad-live) .ad-slot { display: none !important; }

/* --- Stage ---------------------------------------------------------------- */
.stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 18px;
  align-items: start;
  max-width: 1240px;
  width: 100%;
  margin: 0 auto;
}
@media (max-width: 880px) {
  .stage { grid-template-columns: 1fr; }
}

.game-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 5 / 3;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  border: 1px solid var(--line);
}
#game {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(180deg, #11142a 0%, #0c0e1d 100%);
  touch-action: none;
}

/* --- Overlay -------------------------------------------------------------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 10, 22, 0.62);
  backdrop-filter: blur(3px);
  transition: opacity 0.2s ease;
}
.overlay.hidden { opacity: 0; pointer-events: none; }

.panel {
  width: min(420px, 86%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px 26px;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}
.logo {
  margin: 0 0 6px;
  font-size: clamp(28px, 5vw, 40px);
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1;
}
.logo span { color: var(--accent); }
.msg { color: var(--muted); font-size: 14px; line-height: 1.5; margin: 0 0 18px; }
kbd {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 5px;
  padding: 1px 6px;
  font-size: 12px;
}

.score-summary { margin-bottom: 14px; }
.big-score { font-size: 56px; font-weight: 800; color: var(--accent); line-height: 1; }
.rank-line { color: var(--muted); font-size: 14px; margin-top: 6px; }

.name-row { display: flex; gap: 8px; margin-bottom: 16px; }
#name-input {
  flex: 1;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  padding: 10px 12px;
  font-size: 15px;
  outline: none;
}
#name-input:focus { border-color: var(--accent); }

.btn {
  border: none;
  border-radius: 12px;
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.06s ease, filter 0.15s ease;
}
.btn:active { transform: translateY(1px); }
.btn--primary {
  width: 100%;
  background: linear-gradient(135deg, var(--accent), #43c0ff);
  color: #06241c;
}
.btn--primary:hover { filter: brightness(1.05); }
.btn--ghost {
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  white-space: nowrap;
}
.hint { margin-top: 12px; color: var(--muted); font-size: 13px; }

.hidden { display: none !important; }

/* --- HUD ------------------------------------------------------------------ */
.hud {
  position: absolute;
  top: 8px;
  left: 16px;
  font-size: 24px;
  font-weight: 800;
  color: rgba(238, 241, 255, 0.82);
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

.mute-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 5;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(20, 23, 44, 0.7);
  color: var(--ink);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  transition: filter 0.15s ease, transform 0.06s ease;
}
.mute-btn:hover { filter: brightness(1.25); }
.mute-btn:active { transform: scale(0.94); }
.mute-btn.is-muted { opacity: 0.6; }

/* --- Leaderboard ---------------------------------------------------------- */
.leaderboard {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.leaderboard h2 {
  margin: 0 0 12px;
  font-size: 16px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
#leaderboard-list {
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: rank;
}
#leaderboard-list li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
#leaderboard-list li:last-child { border-bottom: none; }
#leaderboard-list li:not(.lb-empty)::before {
  counter-increment: rank;
  content: counter(rank);
  width: 26px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.lb-name { flex: 1; margin: 0 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.lb-empty { color: var(--muted); justify-content: center !important; }
li.is-you { color: var(--accent); }
li.is-you .lb-name::after { content: " (you)"; color: var(--muted); font-size: 12px; }
