:root {
  --bg-0: #0b0e17;
  --bg-1: #131826;
  --panel: rgba(255, 255, 255, 0.06);
  --panel-border: rgba(255, 255, 255, 0.1);
  --text: #e8ecf6;
  --text-dim: #8792a8;
  --accent: #6c8bff;
  --accent-2: #b06cff;
  --good: #4ade80;
  --warn: #fbbf24;
  --danger: #f87171;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: radial-gradient(circle at 30% -10%, var(--bg-1), var(--bg-0) 60%);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  height: 100dvh;
  padding: 12px;
  padding-top: max(12px, env(safe-area-inset-top));
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  padding-left: max(12px, env(safe-area-inset-left));
  padding-right: max(12px, env(safe-area-inset-right));
  gap: 10px;
  user-select: none;
  -webkit-user-select: none;
}

#topbar {
  width: 100%;
  max-width: 960px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 16px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  backdrop-filter: blur(10px);
  flex-wrap: wrap;
}

.stat {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
  min-width: 52px;
}

.stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}

.stat-value {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.ammo-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#ammoIcons {
  display: flex;
  gap: 4px;
  font-size: 20px;
}

#ammoIcons .ammo-icon {
  opacity: 0.35;
  filter: grayscale(1);
  transition: opacity 0.2s, filter 0.2s, transform 0.2s;
}

#ammoIcons .ammo-icon.active {
  opacity: 1;
  filter: none;
  transform: scale(1.15);
}

.spacer { flex: 1; }

.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  min-height: 44px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.2s;
}

.btn:active { transform: scale(0.95); }

.btn-ghost {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border: 1px solid var(--panel-border);
}

.btn-ghost:hover { background: rgba(255, 255, 255, 0.14); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  box-shadow: 0 4px 18px rgba(108, 139, 255, 0.45);
}

.btn-primary:hover { box-shadow: 0 6px 22px rgba(108, 139, 255, 0.6); }

.hidden { display: none !important; }

#stage {
  position: relative;
  width: 100%;
  max-width: 960px;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

#gameCanvas {
  width: 100%;
  height: auto;
  max-height: 100%;
  aspect-ratio: 960 / 540;
  border-radius: 16px;
  border: 1px solid var(--panel-border);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  touch-action: none;
  background: #0e1220;
}

#banner {
  position: absolute;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  padding: 14px 28px;
  border-radius: 12px;
  background: rgba(10, 12, 20, 0.75);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(8px);
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  animation: bannerIn 0.35s ease-out;
  pointer-events: none;
}

.banner-info { color: var(--warn); }

@keyframes bannerIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-14px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.hint {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 13px;
  color: var(--text-dim);
  pointer-events: none;
  transition: opacity 0.3s;
}

/* Rotate-to-landscape fallback for browsers without Fullscreen/Orientation Lock (iOS Safari) */
body.force-landscape {
  position: fixed;
  top: 0;
  left: 100%;
  width: 100vh;
  height: 100vw;
  transform-origin: top left;
  transform: rotate(90deg);
  overflow: hidden;
}

@media (orientation: landscape) {
  #rotateBtn { display: none; }
}

/* Mobile touch-friendliness */
@media (max-width: 640px), (max-height: 480px) {
  #topbar {
    gap: 10px;
    padding: 8px 10px;
    border-radius: 12px;
  }
  .stat { min-width: 40px; }
  .stat-label { font-size: 9px; }
  .stat-value { font-size: 16px; }
  #ammoIcons { font-size: 16px; }
  .btn {
    padding: 10px 12px;
    font-size: 13px;
    min-height: 44px;
  }
  .hint { font-size: 12px; }
}
