:root {
  --bg: #0a0f14;
  --panel: rgba(8, 12, 18, 0.82);
  --accent: #4ac1ff;
  --accent-2: #ffb347;
  --danger: #ff4d4d;
  --text: #e9f1ff;
  --muted: #9fb3c9;
  --safe-top: env(safe-area-inset-top);
  --safe-right: env(safe-area-inset-right);
  --safe-bottom: env(safe-area-inset-bottom);
  --safe-left: env(safe-area-inset-left);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: radial-gradient(1400px 900px at 70% -10%, #1a3a5b, #0a0f14 60%);
  font-family: "Orbitron", "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--text);
  touch-action: none;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game-root {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

body.force-portrait #game-root {
  width: min(100vw, calc(100vh * 9 / 16));
  height: min(100vh, calc(100vw * 16 / 9));
  aspect-ratio: 9 / 16;
}

#c {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(800px 600px at 50% 35%, rgba(60, 110, 160, 0.35), rgba(3, 6, 12, 0.88));
  z-index: 30;
  backdrop-filter: blur(4px);
  padding: calc(16px + var(--safe-top)) calc(16px + var(--safe-right))
    calc(16px + var(--safe-bottom)) calc(16px + var(--safe-left));
}

.overlay.hidden {
  display: none;
}

.panel {
  text-align: center;
  background: linear-gradient(180deg, rgba(12, 18, 28, 0.92), rgba(8, 12, 18, 0.82));
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 24px;
  border-radius: 14px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  min-width: 260px;
}

.panel .title {
  font-size: 28px;
  letter-spacing: 2px;
  font-weight: 700;
}

.panel .subtitle {
  font-size: 13px;
  opacity: 0.75;
  margin-top: 8px;
}

#last-score {
  letter-spacing: 1px;
  color: #a7c6ff;
}

#model-status {
  letter-spacing: 1px;
  color: #9fb3c9;
}

#model-status[data-state="loading"] {
  color: #ffd36b;
}

#model-status[data-state="ok"] {
  color: #9fe1ff;
}

#model-status[data-state="error"] {
  color: #ff9aa2;
}

.panel .row {
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 12px;
}

.panel .row label {
  color: var(--muted);
  font-weight: 600;
}

.panel .row select,
.panel .row input[type="range"] {
  width: 140px;
}

.panel .row.toggle {
  justify-content: space-between;
  max-width: 220px;
  margin: 10px auto 0;
}

.panel button {
  margin-top: 14px;
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: linear-gradient(135deg, #1b6b9d, #4ac1ff);
  color: #fff;
  font-weight: 700;
  letter-spacing: 1px;
}

.panel button:disabled {
  background: linear-gradient(135deg, #2a3a4a, #3a4a5a);
  color: rgba(255, 255, 255, 0.4);
  cursor: not-allowed;
}

#home-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 10px;
  width: 100%;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  text-decoration: none;
  color: var(--text);
  font-weight: 700;
  letter-spacing: 1px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02));
}

.panel .hint {
  margin-top: 8px;
  font-size: 11px;
  color: var(--muted);
}

#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  padding: calc(10px + var(--safe-top)) calc(10px + var(--safe-right))
    calc(10px + var(--safe-bottom)) calc(10px + var(--safe-left));
}

.hud-top {
  display: flex;
  gap: 12px;
  align-items: center;
}

.hp {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  background: rgba(8, 12, 18, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 6px 8px;
}

.hp span {
  color: var(--muted);
  font-weight: 600;
}

.bar {
  flex: 1;
  height: 10px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

#hp-bar {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #39f, #4ac1ff 60%, #9fe1ff);
}

.stats {
  display: flex;
  gap: 10px;
  font-size: 11px;
  color: var(--muted);
  background: rgba(8, 12, 18, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 6px 8px;
}

.stats span {
  color: var(--text);
  font-weight: 700;
}

#pause {
  position: absolute;
  top: calc(14px + var(--safe-top));
  right: calc(14px + var(--safe-right));
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(8, 12, 18, 0.7);
  color: var(--text);
  font-weight: 700;
  font-size: 16px;
  pointer-events: auto;
  z-index: 12;
}

#crosshair {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 24px;
  height: 24px;
  margin-left: -12px;
  margin-top: -12px;
  z-index: 8;
  pointer-events: none;
}

#crosshair::before,
#crosshair::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  background: rgba(255, 255, 255, 0.7);
  transform: translate(-50%, -50%);
}

#crosshair::before {
  width: 2px;
  height: 18px;
}

#crosshair::after {
  width: 18px;
  height: 2px;
}

#powerup {
  position: absolute;
  left: calc(12px + var(--safe-left));
  top: calc(64px + var(--safe-top));
  background: rgba(8, 12, 18, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 6px 8px;
  font-size: 11px;
  pointer-events: none;
}

#powerup-label {
  font-weight: 700;
  color: var(--accent);
}

#powerup-bar {
  height: 6px;
  margin-top: 4px;
  width: 120px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  overflow: hidden;
}

#powerup-bar::after {
  content: "";
  display: block;
  height: 100%;
  width: var(--powerup-fill, 0%);
  background: linear-gradient(90deg, #4ac1ff, #9fe1ff);
}

#joystick {
  position: absolute;
  left: calc(16px + var(--safe-left));
  bottom: calc(16px + var(--safe-bottom));
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.18);
  z-index: 10;
  touch-action: none;
  box-shadow: inset 0 0 18px rgba(255, 255, 255, 0.08);
}

#stick {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 56px;
  height: 56px;
  margin-left: -28px;
  margin-top: -28px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.35);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
}

#fire {
  position: absolute;
  right: calc(16px + var(--safe-right));
  bottom: calc(16px + var(--safe-bottom));
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: none;
  background: radial-gradient(circle at 30% 30%, #ff8b8b, #ff3b3b 60%, #b40000);
  color: #fff;
  font-weight: 700;
  font-size: 18px;
  z-index: 10;
  box-shadow: 0 10px 24px rgba(255, 80, 80, 0.45), inset 0 0 10px rgba(255, 255, 255, 0.2);
  touch-action: none;
  pointer-events: auto;
}

#fire:active {
  transform: scale(0.96);
}

.left-handed #joystick {
  left: auto;
  right: calc(16px + var(--safe-right));
}

.left-handed #fire {
  right: auto;
  left: calc(16px + var(--safe-left));
}

#rotate .panel {
  min-width: 220px;
}

@media (max-width: 420px) {
  #fire {
    width: 104px;
    height: 104px;
    font-size: 16px;
  }
}
