:root {
  color-scheme: dark;
  --bg: #080c18;
  --panel: rgba(17, 24, 39, 0.88);
  --panel-2: rgba(30, 41, 59, 0.86);
  --line: rgba(148, 163, 184, 0.2);
  --text: #f8fafc;
  --muted: #aebbd0;
  --accent: #66e3ff;
  --accent-2: #9a7cff;
  --danger: #ff7a90;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 20% 0%, rgba(102, 227, 255, 0.12), transparent 34rem),
    radial-gradient(circle at 100% 20%, rgba(154, 124, 255, 0.14), transparent 28rem),
    linear-gradient(180deg, #0b1020, var(--bg));
  color: var(--text);
}

button { font: inherit; }

.page-shell {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 28px 0 48px;
  display: grid;
  gap: 22px;
}

.game-card,
.leaderboard-card {
  background: linear-gradient(180deg, rgba(25, 35, 55, 0.94), rgba(13, 20, 34, 0.94));
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.game-card { padding: clamp(16px, 2.5vw, 28px); }

.game-header {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: end;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.17em;
}

h1, h2, p { margin-top: 0; }

h1 {
  margin-bottom: 6px;
  font-size: clamp(2rem, 5vw, 3.55rem);
  line-height: 0.95;
  letter-spacing: -0.045em;
}

.subtitle,
.leaderboard-card p,
.instructions span {
  color: var(--muted);
}

.subtitle { margin-bottom: 0; }

.header-right {
  display: grid;
  justify-items: end;
  gap: 8px;
}

.sound-toggle {
  min-height: 36px;
  padding: 0 12px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.11);
  font-size: 0.78rem;
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(4, minmax(72px, 1fr));
  gap: 8px;
  min-width: min(100%, 430px);
}

.stat {
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 10px 12px;
  text-align: center;
}

.stat-label {
  display: block;
  color: var(--muted);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.stat strong {
  display: block;
  margin-top: 3px;
  font-size: 1.25rem;
}

.power-stat strong {
  font-size: 0.78rem;
  line-height: 1.3rem;
  white-space: normal;
  max-width: 150px;
}

.game-stage-wrap {
  position: relative;
  overflow: hidden;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  background: #050812;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 3 / 2;
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(4, 8, 18, 0.62);
  transition: opacity 160ms ease;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.overlay-panel {
  width: min(440px, 100%);
  padding: 28px;
  text-align: center;
  border-radius: 22px;
  background: rgba(16, 24, 42, 0.93);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.42);
}

.overlay-kicker {
  margin-bottom: 6px;
  color: var(--accent);
  font-weight: 800;
  letter-spacing: 0.16em;
  font-size: 0.74rem;
}

.overlay-panel h2 {
  margin-bottom: 10px;
  font-size: clamp(1.9rem, 5vw, 3rem);
  letter-spacing: -0.035em;
}

.overlay-panel p:not(.overlay-kicker) {
  color: var(--muted);
  line-height: 1.55;
}

.button,
.touch-button {
  border: 0;
  border-radius: 13px;
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease, background 120ms ease;
}

.button:hover,
.touch-button:hover { filter: brightness(1.08); }
.button:active,
.touch-button:active { transform: translateY(1px) scale(0.99); }
.button:focus-visible,
.touch-button:focus-visible { outline: 3px solid rgba(102, 227, 255, 0.38); outline-offset: 3px; }

.button {
  min-height: 44px;
  padding: 0 18px;
  font-weight: 800;
}

.primary {
  color: #06101a;
  background: linear-gradient(135deg, var(--accent), #b1f5ff);
}

.secondary {
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.11);
}

.controls-row {
  margin-top: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.instructions {
  display: flex;
  flex-direction: column;
  gap: 4px;
  line-height: 1.45;
}

.power-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 14px;
  padding: 11px 13px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 13px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.035);
  font-size: 0.78rem;
  line-height: 1.35;
}

.power-legend b { color: var(--text); }

.touch-controls {
  display: none;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 14px;
}

.touch-button {
  min-height: 54px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.11);
  font-size: 1.25rem;
  font-weight: 900;
  user-select: none;
  -webkit-user-select: none;
}

.leaderboard-card {
  display: grid;
  grid-template-columns: minmax(220px, 0.65fr) minmax(0, 1.35fr);
  gap: 24px;
  align-items: start;
  padding: clamp(18px, 2.5vw, 28px);
}

.leaderboard-card h2 { margin-bottom: 8px; }
.leaderboard-card p { margin-bottom: 0; line-height: 1.5; }

#mis-leaderboard {
  min-height: 76px;
  border-radius: 16px;
}

@media (max-width: 780px) {
  .page-shell { width: min(100% - 18px, 1180px); padding-top: 10px; }
  .game-card, .leaderboard-card { border-radius: 18px; }
  .game-header { align-items: stretch; flex-direction: column; gap: 16px; }
  .header-right { justify-items: stretch; }
  .sound-toggle { width: 100%; }
  .scoreboard { min-width: 0; width: 100%; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .controls-row { align-items: stretch; flex-direction: column; }
  .button.secondary { width: 100%; }
  .touch-controls { display: grid; }
  .leaderboard-card { grid-template-columns: 1fr; }
}

@media (pointer: coarse) {
  .touch-controls { display: grid; }
}
