:root {
  --bg-top: #0d1b3d;
  --bg-bot: #0b1020;
  --accent: #ff7a29;
  --accent-2: #ffd166;
  --text: #f5f7ff;
  --muted: rgba(245, 247, 255, 0.65);
  --card: rgba(11, 16, 32, 0.78);
  --card-border: rgba(255, 255, 255, 0.12);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-bot);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-weight: 600;
  letter-spacing: 0.02em;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}

#game-root {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

#three-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#aim-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
}

/* ===== HUD ===== */
#hud {
  position: absolute;
  top: calc(12px + var(--safe-top));
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  z-index: 10;
  pointer-events: none;
}

.hud-pill {
  background: var(--card);
  border: 1px solid var(--card-border);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 14px;
  padding: 8px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 78px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.25);
}

.hud-pill .label {
  font-size: 10px;
  letter-spacing: 0.15em;
  color: var(--muted);
}

.hud-pill .value {
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.hud-pill .sub {
  font-size: 10px;
  color: var(--accent-2);
  letter-spacing: 0.08em;
  margin-top: 1px;
}

#hud-level { min-width: 110px; }

/* ===== Objective banner ===== */
#objective {
  position: absolute;
  top: calc(96px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 122, 41, 0.18);
  border: 1px solid rgba(255, 122, 41, 0.5);
  color: #ffd9b8;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12px;
  letter-spacing: 0.1em;
  z-index: 10;
  pointer-events: none;
  white-space: nowrap;
}

/* ===== Hint ===== */
#hint {
  position: absolute;
  bottom: calc(28px + var(--safe-bot));
  left: 50%;
  transform: translateX(-50%);
  font-size: 13px;
  color: var(--muted);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  z-index: 10;
  pointer-events: none;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

/* ===== Mute button ===== */
#mute-btn {
  position: absolute;
  bottom: calc(20px + var(--safe-bot));
  right: 16px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--card);
  border: 1px solid var(--card-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  cursor: pointer;
  z-index: 20;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: transform 0.15s ease;
}

#mute-btn:active { transform: scale(0.9); }

/* ===== Score popups ===== */
#popup-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 8;
}

.popup {
  position: absolute;
  left: 50%;
  top: 40%;
  transform: translate(-50%, -50%);
  font-size: 44px;
  font-weight: 900;
  letter-spacing: 0.04em;
  color: var(--accent-2);
  text-shadow: 0 4px 24px rgba(255, 209, 102, 0.6),
               0 2px 6px rgba(0,0,0,0.45);
  animation: popup-anim 1.1s cubic-bezier(0.2, 0.7, 0.2, 1) forwards;
}

.popup.swish {
  color: #fff;
  text-shadow: 0 0 30px rgba(122, 230, 255, 0.9),
               0 0 80px rgba(122, 230, 255, 0.5);
}

.popup.miss {
  color: #ff8181;
  font-size: 28px;
}

@keyframes popup-anim {
  0%   { opacity: 0; transform: translate(-50%, -30%) scale(0.6); }
  20%  { opacity: 1; transform: translate(-50%, -50%) scale(1.15); }
  40%  { transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -90%) scale(0.95); }
}

/* ===== Overlays ===== */
.overlay {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, rgba(13, 27, 61, 0.55), rgba(11, 16, 32, 0.85));
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  padding: 24px;
}

.overlay.hidden { display: none; }

.overlay-card {
  background: linear-gradient(160deg, rgba(20, 30, 60, 0.95), rgba(11, 16, 32, 0.95));
  border: 1px solid var(--card-border);
  border-radius: 22px;
  padding: 32px 28px;
  text-align: center;
  max-width: 380px;
  width: 100%;
  box-shadow: 0 30px 70px rgba(0,0,0,0.5),
              inset 0 1px 0 rgba(255,255,255,0.08);
  animation: card-in 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.overlay-card.hidden { display: none; }

@keyframes card-in {
  from { opacity: 0; transform: translateY(20px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.logo {
  font-size: 56px;
  font-weight: 900;
  margin: 0 0 4px;
  letter-spacing: 0.04em;
  color: var(--text);
  line-height: 1;
}

.logo span {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tagline {
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 14px;
  letter-spacing: 0.05em;
}

.overlay-card h2 {
  font-size: 28px;
  margin: 4px 0 12px;
  font-weight: 800;
}

.overlay-card p {
  margin: 6px 0;
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
}

.overlay-card p.muted { color: var(--muted); }
.overlay-card p.score-row { font-size: 18px; margin-top: 14px; }
.overlay-card p strong { color: var(--accent-2); font-weight: 800; }

.kicker {
  display: inline-block;
  font-size: 11px;
  letter-spacing: 0.25em;
  color: var(--accent);
  background: rgba(255, 122, 41, 0.12);
  border: 1px solid rgba(255, 122, 41, 0.3);
  padding: 4px 12px;
  border-radius: 999px;
  margin-bottom: 14px;
}

.primary-btn {
  display: block;
  width: 100%;
  margin: 20px auto 0;
  padding: 16px 20px;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: #0b1020;
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  border: none;
  border-radius: 14px;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(255, 122, 41, 0.35);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  font-family: inherit;
}

.primary-btn:active {
  transform: translateY(2px);
  box-shadow: 0 6px 14px rgba(255, 122, 41, 0.35);
}

.secondary-btn {
  display: block;
  width: 100%;
  margin: 10px auto 0;
  padding: 12px 18px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--card-border);
  border-radius: 12px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.12s ease, transform 0.12s ease;
}

.secondary-btn:hover { background: rgba(255,255,255,0.06); }
.secondary-btn:active { transform: translateY(1px); }

.level-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin: 18px 0 6px;
}

.level-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 14px 10px;
  border-radius: 12px;
  border: 1px solid var(--card-border);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  font-weight: 700;
  transition: transform 0.12s ease, background 0.12s ease;
}

.level-btn:hover { background: rgba(255,122,41,0.18); border-color: rgba(255,122,41,0.5); }
.level-btn:active { transform: translateY(2px); }

.level-btn .num {
  display: inline-block;
  font-size: 11px;
  letter-spacing: 0.2em;
  color: var(--accent-2);
}

.level-btn .lname {
  font-size: 14px;
  letter-spacing: 0.04em;
}

.level-btn.cleared { background: rgba(74, 222, 128, 0.12); border-color: rgba(74,222,128,0.4); }
.level-btn.cleared::after { content: '✓'; color: #4ade80; font-size: 12px; margin-top: 2px; }

.level-btn.locked {
  opacity: 0.35;
  cursor: not-allowed;
}
.level-btn.locked::after { content: '🔒'; font-size: 12px; margin-top: 2px; }
.level-btn.locked:hover { background: rgba(255,255,255,0.04); border-color: var(--card-border); transform: none; }

.how-to {
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--card-border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
  letter-spacing: 0.02em;
}

.how-to div { display: flex; align-items: center; gap: 10px; justify-content: center; }
.how-to span { font-size: 18px; }

.hidden { display: none !important; }

/* Smaller screens */
@media (max-width: 420px) {
  .logo { font-size: 44px; }
  .hud-pill { padding: 6px 10px; min-width: 64px; }
  .hud-pill .value { font-size: 18px; }
  #hud-level { min-width: 92px; }
  .popup { font-size: 36px; }
}
