:root {
  --panel: rgba(7, 13, 22, 0.86);
  --panel-soft: rgba(7, 13, 22, 0.68);
  --line: rgba(148, 201, 255, 0.24);
  --text: #eaf6ff;
  --muted: #9ab0c6;
  --accent: #ffd45e;
  --accent-teal: #46e2d0;
  --danger: #ff6b7a;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #6db6d9;
  color: var(--text);
  font-family: "Trebuchet MS", system-ui, sans-serif;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
}

/* ── Overlays ─────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: calc(var(--safe-t) + 14px) 14px calc(var(--safe-b) + 14px);
}

.overlay.hidden { display: none; }

.overlay-card {
  width: min(480px, 100%);
  max-height: min(94svh, 860px);
  overflow: auto;
  background: linear-gradient(160deg, rgba(19, 35, 52, 0.94), rgba(6, 11, 18, 0.96));
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 24px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.48);
  color: var(--text);
}

h1, h2, h3 {
  letter-spacing: 0.01em;
}

.title-wordmark {
  font-size: clamp(2.2rem, 8vw, 4.3rem);
  font-weight: 900;
  line-height: 0.92;
  text-transform: uppercase;
  margin-bottom: 8px;
  color: #fff7d6;
  text-shadow: 0 3px 0 #a95d16, 0 8px 28px rgba(0, 0, 0, 0.5);
}

.title-sub {
  color: var(--accent-teal);
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  margin-bottom: 18px;
}

.menu-btn {
  display: block;
  width: 100%;
  min-height: 50px;
  margin: 9px 0;
  padding: 12px 18px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  font-weight: 900;
  font-size: 1rem;
  cursor: pointer;
  letter-spacing: 0.03em;
  transition: transform 0.12s ease, background 0.12s ease, border 0.12s ease;
}

.menu-btn:active { transform: translateY(1px) scale(0.99); }
.menu-btn.primary {
  background: linear-gradient(180deg, #ffd76e, #f4a135);
  color: #2b1701;
  border-color: #ffe0a1;
}
.menu-btn.ghost { background: rgba(255,255,255,0.03); }
.menu-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.menu-note {
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 10px;
  text-align: center;
}

.button-row {
  display: flex;
  gap: 10px;
}

.button-row .menu-btn { flex: 1; }

/* ── HUD ──────────────────────────────────────── */
#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

.hud-top {
  position: absolute;
  top: calc(var(--safe-t) + 8px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  width: min(96vw, 760px);
  pointer-events: none;
}

.hud-pill {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--text);
  text-shadow: 0 1px 2px #000;
  white-space: nowrap;
}

.hud-pill.danger { border-color: rgba(255, 107, 122, 0.55); }

.hud-center {
  position: absolute;
  top: calc(var(--safe-t) + 52px);
  left: 50%;
  transform: translateX(-50%);
  width: min(92vw, 520px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
}

.hud-message {
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 7px 12px;
  font-size: 0.86rem;
  font-weight: 900;
  color: #fff5cf;
  text-shadow: 0 1px 3px #000;
}

.hud-message.fade-in { animation: rise 2.2s ease forwards; }
@keyframes rise {
  0% { opacity: 0; transform: translateY(6px); }
  15% { opacity: 1; transform: translateY(0); }
  80% { opacity: 1; }
  100% { opacity: 0; }
}

.player-hud {
  position: absolute;
  left: max(14px, env(safe-area-inset-left));
  right: max(14px, env(safe-area-inset-right));
  bottom: calc(var(--safe-b) + 18px);
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}

.health-panel {
  width: min(210px, 34vw);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px;
  margin-bottom: 8px;
}

.health-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  font-weight: 900;
  margin-bottom: 4px;
}

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

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #3ee07a, #a1f56b);
  transition: width 0.16s ease;
}

.bar-fill.danger { background: linear-gradient(90deg, #ff6b7a, #ffb35c); }

.cooldown-row { margin-top: 6px; }

/* ── Touch controls ────────────────────────────── */
#touch-controls {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 14;
}

#joystick-zone {
  position: absolute;
  left: max(18px, env(safe-area-inset-left));
  bottom: calc(var(--safe-b) + 18px);
  width: 148px;
  height: 148px;
  pointer-events: auto;
  touch-action: none;
}

#joystick-base {
  position: absolute;
  inset: 10px;
  border-radius: 50%;
  background: rgba(6, 12, 20, 0.56);
  border: 2px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
}

#joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 62px;
  height: 62px;
  margin: -31px 0 0 -31px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff9de, #f6a938);
  border: 2px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 5px 14px rgba(0, 0, 0, 0.4);
  transition: transform 0.08s ease;
}

#dash-button {
  position: absolute;
  right: max(18px, env(safe-area-inset-right));
  bottom: calc(var(--safe-b) + 38px);
  width: 104px;
  height: 104px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.72);
  background: radial-gradient(circle at 35% 28%, #88ffea, #168c85);
  color: #062c2c;
  font-weight: 900;
  font-size: 1.1rem;
  pointer-events: auto;
  touch-action: none;
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.36);
  letter-spacing: 0.05em;
}

#dash-button.is-down { transform: scale(0.94); background: radial-gradient(circle at 35% 28%, #c7fff5, #42e2d0); }

/* ── Gallery ───────────────────────────────────── */
#gallery-viewer {
  width: 100%;
  height: 250px;
  border-radius: 14px;
  background: #0b141f;
  border: 1px solid var(--line);
}

#gallery-role {
  min-height: 22px;
  color: #fff7d6;
  font-weight: 900;
  margin: 10px 0;
}

#gallery-license {
  margin-top: 12px;
  padding: 10px;
  background: rgba(255,255,255,0.045);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.4;
  white-space: pre-wrap;
}

.gallery-nav {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.gallery-nav button { flex: 1; }

/* ── Loading ───────────────────────────────────── */
#loading-screen {
  background: linear-gradient(180deg, #6db6d9 0%, #17283a 100%);
}

.loading-box {
  width: min(420px, 92vw);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px;
  text-align: center;
}

.loading-title { font-size: 1.2rem; font-weight: 900; margin-bottom: 14px; }

.progress-track {
  height: 12px;
  background: rgba(255,255,255,0.12);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #4be2c7, #ffd45e);
  transition: width 0.2s ease;
}

.loading-status { margin-top: 10px; font-size: 0.82rem; color: var(--muted); }

.asset-error { color: var(--danger); margin-top: 10px; font-size: 0.82rem; }

/* ── Disconnect ────────────────────────────────── */
#disconnect-screen { background: rgba(4, 8, 14, 0.72); }

/* ── Responsive helpers ────────────────────────── */
@media (max-width: 520px) {
  .overlay-card { padding: 18px; }
  .menu-btn { min-height: 46px; }
  #joystick-zone { width: 132px; height: 132px; }
  #dash-button { width: 92px; height: 92px; }
}

.hidden { display: none !important; }
