:root {
  --bg: #0b1020;
  --bg-2: #0f1426;
  --panel: #151a2d;
  --panel-2: #1a2140;
  --text: #e6e8ef;
  --muted: #a9afc6;
  --accent: #4f8cff;
  --accent-2: #4dffbd;
  --danger: #ff5c7a;
  --grid: rgba(255,255,255,0.05);
  --shadow: 0 6px 24px rgba(0,0,0,0.35);
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  color: var(--text);
  background: radial-gradient(1200px 800px at 20% -10%, #152042 0%, transparent 60%),
              radial-gradient(1200px 800px at 120% 20%, #142739 0%, transparent 55%),
              var(--bg);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Helvetica, Arial, sans-serif;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.app {
  min-height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  gap: 16px;
  padding: 20px clamp(16px, 4vw, 32px);
}

.header {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 16px;
  align-items: center;
}

.title {
  margin: 0;
  font-size: clamp(20px, 2.4vw, 28px);
  letter-spacing: 0.5px;
}

.scoreboard {
  display: flex;
  gap: 14px;
  padding: 10px 12px;
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: var(--muted);
}
.scoreboard strong { color: var(--text); }

.actions {
  display: inline-flex;
  gap: 10px;
}

.btn {
  appearance: none;
  border: 1px solid transparent;
  background: var(--panel-2);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 600;
  letter-spacing: 0.2px;
  cursor: pointer;
  transition: transform .06s ease, background .2s ease, border-color .2s ease, box-shadow .2s ease;
  box-shadow: 0 2px 10px rgba(0,0,0,0.25) inset, var(--shadow);
}
.btn:hover {
  transform: translateY(-1px);
  background: #212a55;
}
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(180deg, #5f96ff, #3f66ff);
  border-color: rgba(255,255,255,0.15);
  box-shadow: 0 2px 0 rgba(0,0,0,0.35) inset, 0 8px 24px rgba(79,140,255,0.45);
}
.btn.round {
  width: 54px;
  height: 54px;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  font-size: 18px;
  background: #1b2448;
}

.stage {
  display: grid;
  place-items: center;
}

.game-container {
  width: min(92vmin, 780px);
  aspect-ratio: 1 / 1;
  background: linear-gradient(180deg, #0b142e, #0a1024);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.07);
}

#game {
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(120% 80% at 50% 20%, rgba(3,6,12,0.6) 0%, rgba(3,6,12,0.85) 60%, rgba(3,6,12,0.95) 100%);
  color: var(--text);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}
.overlay[aria-hidden="false"] { opacity: 1; pointer-events: auto; }
.overlay .box {
  padding: 18px 22px;
  background: linear-gradient(180deg, #161d39, #101631);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  box-shadow: var(--shadow);
  font-weight: 600;
  letter-spacing: 0.3px;
}

.controls {
  display: none;
  justify-content: center;
}
.dpad {
  display: inline-grid;
  gap: 8px;
  padding: 10px;
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.07);
  box-shadow: var(--shadow);
}
.dpad .row { display: grid; grid-auto-flow: column; gap: 8px; }
.dpad .spacer { width: 54px; height: 54px; }

.hint {
  color: var(--muted);
  text-align: center;
}

/* Touch-first controls on narrow or coarse pointers */
@media (max-width: 820px), (pointer: coarse) {
  .header { grid-template-columns: 1fr; }
  .scoreboard { order: 2; }
  .actions { order: 3; }
  .controls { display: flex; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
