:root {
  --accent: #4fd1c5;
  --accent-dim: #2c7a7b;
  --danger: #f56565;
  --warn: #f6ad55;
  --bg: #0a0e12;
  --panel: rgba(10, 16, 22, 0.82);
  --text: #e2e8f0;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  overscroll-behavior: none;
}

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

.hidden { display: none !important; }

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

#crosshair {
  position: absolute;
  left: 50%; top: 50%;
  width: 22px; height: 22px;
  transform: translate(-50%, -50%);
  opacity: 0.85;
}
#crosshair::before, #crosshair::after {
  content: ""; position: absolute; background: var(--accent);
  box-shadow: 0 0 4px rgba(0,0,0,0.8);
}
#crosshair::before { left: 50%; top: 0; width: 2px; height: 100%; transform: translateX(-50%); }
#crosshair::after  { top: 50%; left: 0; height: 2px; width: 100%; transform: translateY(-50%); }

#status-bar {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  gap: 14px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.55), transparent);
}
.stat { display: flex; flex-direction: column; gap: 3px; }
#stat-objective { margin-left: auto; text-align: right; }
.stat-label {
  font-size: 10px; letter-spacing: 1.5px; text-transform: uppercase;
  color: var(--accent); opacity: 0.85; font-weight: 700;
}
.stat-value { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.bar-track {
  width: 160px; max-width: 38vw; height: 12px;
  background: rgba(255,255,255,0.12);
  border-radius: 6px; overflow: hidden;
  border: 1px solid rgba(255,255,255,0.15);
}
.bar-fill {
  height: 100%; width: 100%;
  background: linear-gradient(90deg, #48bb78, #9ae6b4);
  transition: width 0.18s ease, background 0.3s ease;
}

#prompt {
  position: absolute;
  left: 50%; bottom: 22%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--accent-dim);
  padding: 8px 16px; border-radius: 8px;
  font-size: 15px; font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}
#prompt kbd {
  background: var(--accent); color: #04110f;
  padding: 1px 7px; border-radius: 4px; font-weight: 800;
}

#toast {
  position: absolute;
  left: 50%; top: 18%;
  transform: translateX(-50%);
  background: var(--panel);
  border-left: 3px solid var(--accent);
  padding: 10px 18px; border-radius: 6px;
  font-size: 15px; font-weight: 600;
  max-width: 80vw; text-align: center;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  transition: opacity 0.4s ease;
}

#damage-flash {
  position: absolute; inset: 0;
  background: radial-gradient(circle at center, transparent 40%, rgba(245,101,101,0.55) 100%);
  opacity: 0; transition: opacity 0.12s ease;
}

/* ---------- Touch controls ---------- */
#touch-ui { position: absolute; inset: 0; }
.joystick {
  position: absolute;
  bottom: max(28px, env(safe-area-inset-bottom));
  width: 120px; height: 120px;
  border-radius: 50%;
  background: rgba(255,255,255,0.06);
  border: 2px solid rgba(255,255,255,0.18);
  pointer-events: auto;
}
#move-stick { left: 26px; }
#look-stick { right: 26px; }
.joystick-knob {
  position: absolute;
  left: 50%; top: 50%;
  width: 52px; height: 52px;
  margin: -26px 0 0 -26px;
  border-radius: 50%;
  background: rgba(79,209,197,0.5);
  border: 2px solid var(--accent);
  transition: opacity 0.15s ease;
}

.touch-btn {
  position: absolute;
  pointer-events: auto;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: rgba(79,209,197,0.18);
  color: var(--text);
  font-weight: 800; font-size: 14px; letter-spacing: 1px;
  font-family: var(--font);
}
#btn-fire {
  right: 160px; bottom: max(60px, calc(env(safe-area-inset-bottom) + 32px));
  width: 86px; height: 86px;
}
#btn-fire:active { background: rgba(245,101,101,0.4); }
.touch-btn-fix {
  right: 160px; bottom: max(160px, calc(env(safe-area-inset-bottom) + 132px));
  width: 86px; height: 86px;
  border-color: var(--warn);
  background: rgba(246,173,85,0.22);
}
.touch-btn-fix:active { background: rgba(246,173,85,0.5); }

/* ---------- Overlays / menus ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background:
    radial-gradient(circle at 50% 30%, rgba(44,122,123,0.25), transparent 60%),
    linear-gradient(160deg, #060a0e, #0d141b);
}
.menu-card {
  max-width: 540px; width: 100%;
  background: var(--panel);
  border: 1px solid rgba(79,209,197,0.3);
  border-radius: 16px;
  padding: 32px 28px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
  backdrop-filter: blur(6px);
}
.menu-card h1 {
  font-size: clamp(30px, 8vw, 48px);
  letter-spacing: 4px;
  background: linear-gradient(90deg, var(--accent), #9ae6b4);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 6px;
}
.subtitle { color: var(--accent); letter-spacing: 2px; font-size: 13px; text-transform: uppercase; margin-bottom: 18px; }
.briefing { font-size: 15px; line-height: 1.6; color: #cbd5e0; margin-bottom: 18px; }
.briefing strong { color: var(--accent); }
.controls-help { list-style: none; font-size: 13px; line-height: 1.8; color: #a0aec0; margin-bottom: 24px; text-align: left; }
.controls-help kbd {
  background: rgba(255,255,255,0.12); border: 1px solid rgba(255,255,255,0.2);
  padding: 1px 6px; border-radius: 4px; font-size: 12px;
}
.big-btn {
  font-family: var(--font);
  font-size: 18px; font-weight: 800; letter-spacing: 2px;
  color: #04110f;
  background: linear-gradient(90deg, var(--accent), #9ae6b4);
  border: none; border-radius: 10px;
  padding: 14px 28px; cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.2s ease;
  box-shadow: 0 6px 20px rgba(79,209,197,0.35);
}
.big-btn:hover { transform: translateY(-2px); box-shadow: 0 10px 28px rgba(79,209,197,0.5); }
.big-btn:active { transform: translateY(0); }
.big-btn:disabled { opacity: 0.5; cursor: default; transform: none; box-shadow: none; }
.hint { margin-top: 14px; font-size: 12px; color: #718096; }

#end-message { font-size: 16px; line-height: 1.5; margin-bottom: 16px; color: #cbd5e0; }
#end-stats { font-size: 14px; line-height: 1.9; color: #a0aec0; margin-bottom: 24px; }
#end-stats .num { color: var(--accent); font-weight: 700; }
#end-title.victory {
  background: linear-gradient(90deg, #48bb78, #9ae6b4);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
#end-title.defeat {
  background: linear-gradient(90deg, var(--danger), #fc8181);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}

/* ---------- Rotate-to-landscape hint ---------- */
#rotate-hint {
  position: fixed; inset: 0; z-index: 100;
  display: none;
  flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; padding: 30px; text-align: center;
  background: linear-gradient(160deg, #060a0e, #0d141b);
  color: var(--text);
}
#rotate-hint p { font-size: 18px; font-weight: 600; max-width: 280px; }
.rotate-icon {
  font-size: 64px; color: var(--accent);
  animation: rotate-spin 2s ease-in-out infinite;
}
@keyframes rotate-spin {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(90deg); }
}
/* Show only while playing, on touch devices held in portrait. */
@media (pointer: coarse) and (orientation: portrait) {
  body.playing #rotate-hint { display: flex; }
}

@media (max-width: 480px) {
  .stat-value { font-size: 15px; }
  .bar-track { width: 120px; }
}
