:root {
  --bg1: #081019;
  --bg2: #10233a;
  --panel: rgba(7, 15, 27, 0.78);
  --line: rgba(255, 255, 255, 0.1);
  --text: #f5f7ff;
  --muted: #afbdd3;
  --accent: #80f5be;
  --accent-strong: #25cf8b;
  --accent-2: #7bb6ff;
  --danger: #ff7272;
  --gold: #ffd86b;
  --button-dark: #14253a;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top, rgba(123, 182, 255, 0.22), transparent 24%),
    radial-gradient(circle at 20% 20%, rgba(128, 245, 190, 0.11), transparent 20%),
    linear-gradient(180deg, var(--bg2), var(--bg1));
  color: var(--text);
  touch-action: manipulation;
  overscroll-behavior: none;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  min-height: 100svh;
  padding:
    max(12px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(100%, 460px);
  min-height: calc(100vh - 24px);
  min-height: calc(100svh - 24px);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.hud-top,
.bottom-bar {
  display: flex;
  gap: 10px;
}

.hud-pill,
.control-btn {
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 10px 12px;
  backdrop-filter: blur(10px);
  text-align: center;
  box-shadow: 0 10px 25px rgba(0,0,0,0.25);
}

.hud-pill .label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
}

.hud-pill span:last-child {
  display: block;
  font-size: 1.2rem;
  font-weight: 800;
  margin-top: 2px;
}

.center-pill {
  border-color: rgba(116, 240, 193, 0.28);
}

.game-wrap {
  flex: 1;
  position: relative;
  display: flex;
  align-items: stretch;
  background: rgba(3, 10, 20, 0.45);
  border: 1px solid var(--line);
  border-radius: 28px;
  overflow: hidden;
  box-shadow: 0 28px 60px rgba(0,0,0,0.35);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  aspect-ratio: 420 / 760;
  max-height: min(78vh, 78svh);
  background: linear-gradient(180deg, #153458 0%, #081426 100%);
  touch-action: none;
}

.game-banner {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 16px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 16px;
  background: rgba(5, 13, 22, 0.62);
  border: 1px solid rgba(255,255,255,0.08);
  backdrop-filter: blur(10px);
  pointer-events: none;
  font-size: 0.84rem;
}

#statusText {
  color: #dce8fb;
}

.coin-readout {
  color: var(--gold);
  white-space: nowrap;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  background: rgba(2, 7, 15, 0.62);
  backdrop-filter: blur(8px);
}

.overlay.hidden { display: none !important; }
.overlay.visible { display: flex; }

.card {
  width: 100%;
  background: rgba(7, 16, 31, 0.94);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 24px;
  padding: 22px;
  box-shadow: 0 24px 40px rgba(0,0,0,0.3);
  text-align: center;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.74rem;
  font-weight: 700;
}

h1, h2 { margin: 0 0 12px; }
.subcopy {
  margin: 0 auto 14px;
  color: var(--muted);
  line-height: 1.45;
  max-width: 34ch;
}

.instructions {
  display: grid;
  gap: 8px;
  margin: 18px 0;
  font-size: 0.95rem;
  color: #d5e2f4;
}

.primary-btn,
.upgrade-btn,
.control-btn {
  border: none;
  border-radius: 18px;
  padding: 14px 18px;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  color: #04111e;
  background: linear-gradient(180deg, var(--accent), #47d7a3);
  box-shadow: 0 12px 25px rgba(71, 215, 163, 0.35);
}

.control-btn {
  padding: 12px 14px;
  background: linear-gradient(180deg, #f2f8ff, #d9e7f9);
  color: #071423;
  box-shadow: 0 8px 20px rgba(0,0,0,0.18);
  min-height: 48px;
  touch-action: manipulation;
}

.secondary-btn {
  background: linear-gradient(180deg, #213549, var(--button-dark));
  color: #eff6ff;
  box-shadow: none;
}

.control-btn:active,
.primary-btn:active,
.upgrade-btn:active {
  transform: translateY(1px) scale(0.99);
}

.upgrade-choices {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.upgrade-btn {
  text-align: left;
  background: linear-gradient(180deg, #f5f8ff, #dfe9ff);
  color: #102548;
  box-shadow: none;
}

.upgrade-btn strong,
.upgrade-btn span {
  display: block;
}

.upgrade-btn span {
  margin-top: 4px;
  font-size: 0.9rem;
  color: #334766;
  font-weight: 600;
}

.hero-card h1,
.upgrade-card h2,
.over-card h2 {
  letter-spacing: 0.02em;
}

@media (max-width: 480px) {
  body {
    padding:
      max(8px, env(safe-area-inset-top))
      max(8px, env(safe-area-inset-right))
      max(8px, env(safe-area-inset-bottom))
      max(8px, env(safe-area-inset-left));
  }
  .app-shell {
    width: 100%;
    min-height: calc(100vh - 16px);
    min-height: calc(100svh - 16px);
  }
  .hud-top, .bottom-bar { gap: 8px; }
  .bottom-bar {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
  }
  .hud-pill, .control-btn { padding: 9px 10px; border-radius: 15px; }
  .card { padding: 18px; }
  .game-wrap {
    border-radius: 22px;
  }
  canvas {
    max-height: none;
  }
  .game-banner {
    left: 12px;
    right: 12px;
    bottom: 12px;
    padding: 9px 10px;
    font-size: 0.78rem;
  }
}

@media (max-width: 420px) {
  .hud-top {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
  }
  .control-btn {
    min-height: 52px;
    font-size: 0.95rem;
  }
  .game-banner {
    flex-direction: column;
    align-items: flex-start;
  }
}
