:root {
  color-scheme: light dark;
  --bg: #0b0e14;
  --fg: #e6e1cf;
  --accent: #5de4c7;
  --muted: #8a9199;
  --danger: #ff6b6b;
}
html, body { overscroll-behavior: none; }
body.theme-light {
  --bg: #f6f7fb;
  --fg: #0b0e14;
  --muted: #5b636b;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid #111827;
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 600; }
.topbar .back { color: var(--accent); text-decoration: none; }

.stage-wrap {
  position: relative;
  margin: 0 auto;
  padding: 12px;
  width: min(100%, 1100px);
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

canvas#game {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid #1f2937;
  background: linear-gradient(#0b1320, #0b0e14 60%);
  box-shadow: 0 2px 16px rgba(0,0,0,0.3);
  touch-action: none;
}

.hud {
  position: absolute;
  top: 20px;
  left: 20px;
  right: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  text-shadow: 0 1px 0 rgba(0,0,0,0.6);
  z-index: 300;
}
.hud .right { color: var(--muted); }

.help {
  position: absolute;
  bottom: 12px;
  width: 100%;
  text-align: center;
  color: var(--muted);
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.55);
  color: var(--fg);
  font-size: 20px;
  text-align: center;
  padding: 24px;
  z-index: 1000;
}
.overlay.hidden { display: none; }
.overlay .panel {
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid #1f2937;
  border-radius: 12px;
  padding: 24px 28px;
  max-width: 560px;
}
.overlay h2 { margin-top: 0; }
.overlay .actions { margin-top: 16px; display: flex; gap: 12px; justify-content: center; }
.overlay button {
  background: var(--accent);
  color: #112;
  border: none;
  font-weight: 700;
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
}
.overlay button.secondary { background: #334155; color: var(--fg); }

/* Touch controls: hidden on precise pointers, shown on coarse (mobile) */
.touch-controls { position: absolute; inset: 0; display: none; z-index: 200; pointer-events: auto; }
.touch-controls .joystick, .touch-controls .pad, .touch-controls .joystick .stick { pointer-events: auto; touch-action: none; }
.pad {
  width: 64px; height: 64px;
  border-radius: 50%;
  border: 1px solid #1f2937;
  background: #0f172a;
  color: var(--fg);
  font-size: 24px;
  font-weight: 700;
  box-shadow: 0 6px 16px rgba(0,0,0,0.25);
}
.pad.fire { position: absolute; bottom: 18px; right: 18px; }
.pad.primary { background: var(--accent); color: #112; }

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

/* Responsive sizing for small screens */
@media (max-width: 480px) {
  .joystick { width: 140px; height: 140px; left: 12px; bottom: 12px; }
  .joystick .stick { width: 64px; height: 64px; margin-left: -32px; margin-top: -32px; }
  .pad.fire { width: 80px; height: 80px; bottom: 12px; right: 12px; font-size: 26px; }
}
@media (max-width: 360px) {
  .joystick { width: 160px; height: 160px; left: 8px; bottom: 8px; }
  .joystick .stick { width: 72px; height: 72px; margin-left: -36px; margin-top: -36px; }
  .pad.fire { width: 88px; height: 88px; bottom: 10px; right: 10px; font-size: 28px; }
}

.icon-btn {
  background: transparent;
  border: 1px solid #1f2937;
  color: var(--fg);
  border-radius: 8px;
  padding: 4px 8px;
  cursor: pointer;
  margin-right: 8px;
}
.muted { color: var(--muted); }

/* Joystick */
.joystick {
  position: absolute;
  left: 18px; bottom: 18px;
  width: 120px; height: 120px;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid #1f2937;
}
.joystick .stick {
  position: absolute;
  left: 50%; top: 50%;
  width: 54px; height: 54px;
  margin-left: -27px; margin-top: -27px;
  border-radius: 50%;
  background: #111827;
  border: 1px solid #1f2937;
}
