:root {
  color-scheme: dark;
  --bg-1: #061826;
  --bg-2: #102b45;
  --card: rgba(8, 21, 34, 0.78);
  --card-strong: rgba(10, 30, 48, 0.92);
  --line: rgba(255, 255, 255, 0.14);
  --text: #f4fbff;
  --muted: #a6c3d7;
  --accent: #ffd15c;
  --accent-2: #64e0ff;
  --danger: #ff6f7d;
  --green: #7ce48f;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  display: grid;
  place-items: center;
  padding: clamp(14px, 3vw, 32px);
  color: var(--text);
  background:
    radial-gradient(circle at 18% 10%, rgba(100, 224, 255, 0.24), transparent 28%),
    radial-gradient(circle at 84% 0%, rgba(255, 209, 92, 0.16), transparent 26%),
    linear-gradient(135deg, var(--bg-1), var(--bg-2));
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  border-radius: 999px;
  padding: 0.72rem 1rem;
  color: #092033;
  background: linear-gradient(180deg, #ffe08a, var(--accent));
  box-shadow: 0 8px 22px rgba(255, 209, 92, 0.18), inset 0 -2px 0 rgba(0, 0, 0, 0.18);
  cursor: pointer;
  font-weight: 800;
  transition: transform 140ms ease, filter 140ms ease, opacity 140ms ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

button:active:not(:disabled) {
  transform: translateY(1px) scale(0.99);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.shell {
  display: grid;
  grid-template-columns: minmax(300px, 530px) minmax(260px, 340px);
  gap: clamp(16px, 3vw, 28px);
  width: min(100%, 930px);
  align-items: start;
}

.game-card,
.leaderboard-card {
  border: 1px solid var(--line);
  border-radius: 28px;
  background: var(--card);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(18px);
}

.game-card {
  padding: clamp(14px, 2.4vw, 22px);
}

.leaderboard-card {
  padding: 22px;
}

.topbar,
.leaderboard-heading {
  display: flex;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.4rem, 4vw, 2.25rem);
  line-height: 1;
}

h2 {
  font-size: 1.35rem;
}

.eyebrow {
  margin-bottom: 0.18rem;
  color: var(--accent-2);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, auto);
  gap: 8px;
}

.stats span {
  min-width: 72px;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0.55rem 0.7rem;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.06);
  text-align: center;
  font-size: 0.8rem;
}

.stats strong {
  display: block;
  color: var(--text);
  font-size: 1.35rem;
  line-height: 1;
}

.canvas-wrap {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 22px;
  background: #79d8ff;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
  touch-action: manipulation;
}

canvas {
  display: block;
  width: 100%;
  aspect-ratio: 9 / 16;
  max-height: min(72vh, 768px);
  object-fit: contain;
}

.message-panel {
  position: absolute;
  left: 50%;
  top: 44%;
  width: min(84%, 330px);
  transform: translate(-50%, -50%);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 22px;
  padding: 1.1rem;
  background: rgba(6, 24, 38, 0.74);
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.24);
  text-align: center;
  pointer-events: none;
  backdrop-filter: blur(12px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.message-panel.hidden {
  opacity: 0;
  transform: translate(-50%, -45%) scale(0.96);
}

.message-panel p {
  margin-top: 0.45rem;
  color: var(--muted);
}

.controls {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 14px;
}

#pauseButton {
  background: linear-gradient(180deg, #9ff0ff, var(--accent-2));
}

#muteButton,
.ghost {
  color: var(--text);
  background: rgba(255, 255, 255, 0.09);
  box-shadow: inset 0 0 0 1px var(--line);
}

.help {
  margin-top: 12px;
  color: var(--muted);
  text-align: center;
  font-size: 0.9rem;
}

.leaderboard-list {
  display: grid;
  gap: 8px;
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
  counter-reset: rank;
}

.leaderboard-list li {
  display: grid;
  grid-template-columns: 2.2rem 1fr auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0.7rem;
  background: rgba(255, 255, 255, 0.06);
}

.leaderboard-list li::before {
  counter-increment: rank;
  content: counter(rank);
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  color: #062033;
  background: var(--accent);
  font-weight: 900;
}

.leaderboard-list .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

.leaderboard-list .score {
  color: var(--green);
  font-weight: 900;
}

.empty-scores {
  color: var(--muted);
  text-align: center;
  padding: 1rem 0.5rem;
}

.score-dialog {
  width: min(92vw, 380px);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 0;
  color: var(--text);
  background: var(--card-strong);
  box-shadow: 0 32px 80px rgba(0, 0, 0, 0.52);
}

.score-dialog::backdrop {
  background: rgba(0, 0, 0, 0.58);
  backdrop-filter: blur(4px);
}

.score-dialog form {
  display: grid;
  gap: 12px;
  padding: 24px;
}

.score-dialog label {
  color: var(--muted);
  font-weight: 700;
}

.score-dialog input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.78rem 0.9rem;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  outline: none;
  text-transform: uppercase;
}

.score-dialog input:focus {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 4px rgba(100, 224, 255, 0.16);
}

.score-dialog menu {
  margin: 4px 0 0;
  padding: 0;
}

.score-dialog menu button {
  width: 100%;
}

@media (max-width: 820px) {
  body {
    align-items: start;
  }

  .shell {
    grid-template-columns: 1fr;
  }

  .leaderboard-card {
    order: 2;
  }
}

@media (max-width: 460px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .stats,
  .controls {
    width: 100%;
  }

  .controls {
    grid-template-columns: 1fr;
  }
}
