/* =====================================================
   SURVIVAL MAZE: DARK LAB — Stylesheet
   ===================================================== */

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

:root {
  --green-glow: #00ff88;
  --red-danger: #ff2222;
  --amber: #ffaa00;
  --battery-full: #44ff44;
  --battery-mid: #aaff00;
  --battery-low: #ffaa00;
  --battery-crit: #ff4400;
  --ui-bg: rgba(0, 0, 0, 0.85);
  --ui-border: rgba(0, 255, 136, 0.25);
  --ui-text: #ccddcc;
  --ui-text-bright: #eeffee;
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #000;
  font-family: 'Courier New', Courier, monospace;
  color: var(--ui-text);
  user-select: none;
  -webkit-user-select: none;
}

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

/* =====================================================
   CANVAS
   ===================================================== */
#game-canvas {
  display: block;
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  image-rendering: pixelated;
}

/* =====================================================
   SCREENS
   ===================================================== */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.screen.hidden { display: none; }
.screen.active { display: flex; }

/* =====================================================
   START SCREEN
   ===================================================== */
#start-screen {
  background: #000;
  flex-direction: column;
}

#start-flicker-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 50% 30%, rgba(0,60,20,0.35) 0%, transparent 70%),
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 2px,
      rgba(0,255,100,0.015) 2px,
      rgba(0,255,100,0.015) 4px
    );
  animation: scanlines 8s linear infinite;
  pointer-events: none;
}

@keyframes scanlines {
  0% { background-position: 0 0; }
  100% { background-position: 0 400px; }
}

#start-content {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
  padding: 40px 20px;
  max-width: 600px;
  width: 100%;
}

#title-container {
  position: relative;
  text-align: center;
}

.title-lab-label {
  font-size: 11px;
  letter-spacing: 6px;
  color: var(--red-danger);
  text-transform: uppercase;
  margin-bottom: 10px;
  opacity: 0.7;
  animation: blink-slow 3s infinite;
}

@keyframes blink-slow {
  0%, 90%, 100% { opacity: 0.7; }
  95% { opacity: 0.2; }
}

#game-title {
  font-size: clamp(32px, 7vw, 64px);
  font-weight: 900;
  letter-spacing: 4px;
  line-height: 1.1;
  color: #e8ffe8;
  text-shadow:
    0 0 20px rgba(0,255,100,0.6),
    0 0 60px rgba(0,255,100,0.3),
    0 0 100px rgba(0,255,100,0.1);
  animation: title-flicker 6s infinite;
}

#game-title span {
  font-size: 0.65em;
  color: var(--amber);
  text-shadow:
    0 0 20px rgba(255,160,0,0.8),
    0 0 50px rgba(255,160,0,0.4);
  letter-spacing: 12px;
  display: block;
  margin-top: 4px;
}

@keyframes title-flicker {
  0%, 19%, 21%, 23%, 25%, 54%, 56%, 100% {
    text-shadow:
      0 0 20px rgba(0,255,100,0.6),
      0 0 60px rgba(0,255,100,0.3),
      0 0 100px rgba(0,255,100,0.1);
  }
  20%, 24%, 55% {
    text-shadow: none;
    opacity: 0.8;
  }
}

#title-flicker-light {
  position: absolute;
  top: -30px; left: 50%;
  transform: translateX(-50%);
  width: 4px; height: 30px;
  background: rgba(200,255,200,0.6);
  border-radius: 2px;
  animation: flicker-light 4s infinite;
  box-shadow: 0 0 20px 10px rgba(200,255,200,0.2);
}

@keyframes flicker-light {
  0%,100% { opacity:1; height: 30px; }
  10% { opacity:0.4; height: 20px; }
  11% { opacity:1; height: 30px; }
  50% { opacity:0.8; }
  51% { opacity:0.3; height: 15px; }
  52% { opacity:1; height: 30px; }
}

/* Difficulty Select */
#difficulty-select {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.diff-label {
  font-size: 11px;
  letter-spacing: 5px;
  color: rgba(200,255,200,0.5);
}

.diff-buttons {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
}

.diff-btn {
  flex: 1;
  min-width: 140px;
  max-width: 180px;
  padding: 14px 12px;
  background: rgba(0,20,10,0.8);
  border: 1px solid rgba(0,255,100,0.2);
  color: var(--ui-text);
  font-family: inherit;
  font-size: 11px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: all 0.2s;
  border-radius: 3px;
}

.diff-btn:hover, .diff-btn.active {
  background: rgba(0,50,25,0.9);
  border-color: var(--green-glow);
  box-shadow: 0 0 15px rgba(0,255,100,0.3), inset 0 0 10px rgba(0,255,100,0.05);
  color: #fff;
}

.diff-btn.active .diff-name {
  color: var(--green-glow);
}

.diff-btn[data-diff="hard"].active .diff-name { color: var(--amber); }
.diff-btn[data-diff="nightmare"].active .diff-name { color: var(--red-danger); }
.diff-btn[data-diff="hard"]:hover { border-color: var(--amber); }
.diff-btn[data-diff="nightmare"]:hover { border-color: var(--red-danger); }

.diff-name {
  font-size: 14px;
  font-weight: bold;
  letter-spacing: 2px;
}

.diff-desc {
  font-size: 10px;
  opacity: 0.6;
  letter-spacing: 1px;
}

/* Start Button */
#start-btn {
  padding: 16px 48px;
  background: rgba(0,30,15,0.9);
  border: 2px solid var(--green-glow);
  color: var(--green-glow);
  font-family: inherit;
  font-size: 18px;
  font-weight: bold;
  letter-spacing: 4px;
  cursor: pointer;
  text-transform: uppercase;
  transition: all 0.2s;
  box-shadow: 0 0 20px rgba(0,255,100,0.3), inset 0 0 20px rgba(0,255,100,0.05);
  border-radius: 3px;
  animation: pulse-btn 2.5s infinite;
}

@keyframes pulse-btn {
  0%, 100% { box-shadow: 0 0 20px rgba(0,255,100,0.3), inset 0 0 20px rgba(0,255,100,0.05); }
  50% { box-shadow: 0 0 35px rgba(0,255,100,0.5), inset 0 0 30px rgba(0,255,100,0.1); }
}

#start-btn:hover {
  background: rgba(0,60,30,0.95);
  transform: scale(1.03);
}

#controls-hint {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
  font-size: 10px;
  letter-spacing: 2px;
  opacity: 0.4;
}

/* =====================================================
   HUD
   ===================================================== */
#hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 52px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.9) 0%, transparent 100%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  z-index: 50;
  border-bottom: 1px solid rgba(0,255,100,0.1);
}

#hud.hidden { display: none; }

#hud-left, #hud-right, #hud-center {
  display: flex;
  align-items: center;
  gap: 16px;
}

.hud-label {
  font-size: 9px;
  letter-spacing: 3px;
  opacity: 0.5;
  display: block;
  margin-bottom: 2px;
}

#hp-hearts {
  display: flex;
  gap: 4px;
}

.hp-heart {
  width: 18px; height: 18px;
  position: relative;
  display: inline-block;
}

.hp-heart svg {
  width: 100%; height: 100%;
  filter: drop-shadow(0 0 4px rgba(255,50,50,0.8));
}

.hp-heart.empty svg { opacity: 0.2; filter: none; }

#floor-display {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

#floor-num {
  font-size: 22px;
  font-weight: bold;
  color: var(--green-glow);
  text-shadow: 0 0 10px rgba(0,255,100,0.7);
}

#floor-total { font-size: 12px; opacity: 0.5; }

#key-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

#keys-found {
  font-size: 18px;
  font-weight: bold;
  color: #ffdd44;
  text-shadow: 0 0 10px rgba(255,220,0,0.7);
}

/* Battery */
#battery-display {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

#battery-bar-container {
  width: 80px;
  height: 12px;
  background: rgba(0,0,0,0.6);
  border: 1px solid rgba(0,255,100,0.3);
  border-radius: 2px;
  overflow: hidden;
  position: relative;
}

#battery-bar {
  height: 100%;
  width: 100%;
  background: linear-gradient(to right, var(--battery-full), var(--battery-mid));
  border-radius: 2px;
  transition: width 0.3s, background-color 0.5s;
}

#battery-bar.mid {
  background: linear-gradient(to right, var(--battery-mid), var(--battery-low));
}

#battery-bar.low {
  background: linear-gradient(to right, var(--battery-low), var(--battery-crit));
  animation: battery-pulse 0.8s infinite;
}

#battery-bar.critical {
  background: var(--battery-crit);
  animation: battery-pulse 0.3s infinite;
}

@keyframes battery-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

#battery-pct {
  font-size: 9px;
  opacity: 0.6;
  letter-spacing: 1px;
}

/* =====================================================
   MINIMAP
   ===================================================== */
#minimap-container {
  position: absolute;
  top: 60px; right: 12px;
  z-index: 50;
  background: rgba(0,0,0,0.85);
  border: 1px solid rgba(0,255,100,0.2);
  border-radius: 3px;
  padding: 4px;
  box-shadow: 0 0 10px rgba(0,0,0,0.8);
}

#minimap-container.hidden { display: none; }

#minimap-canvas {
  display: block;
  border-radius: 2px;
}

#minimap-label {
  text-align: center;
  font-size: 8px;
  letter-spacing: 3px;
  opacity: 0.4;
  margin-top: 2px;
}

/* =====================================================
   DETECTION ARROWS
   ===================================================== */
#detection-arrows {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 45;
}

.detection-arrow {
  position: absolute;
  width: 0; height: 0;
  border-style: solid;
  opacity: 0;
  transition: opacity 0.3s;
  filter: drop-shadow(0 0 6px rgba(255,0,0,0.8));
}

/* =====================================================
   OVERLAYS
   ===================================================== */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 80;
}

.overlay.hidden { display: none; }

.overlay-text {
  font-size: clamp(28px, 5vw, 56px);
  font-weight: 900;
  letter-spacing: 6px;
  text-align: center;
  color: #fff;
  text-shadow: 0 0 30px rgba(255,255,255,0.5);
}

.overlay-text.danger {
  color: var(--red-danger);
  text-shadow:
    0 0 20px rgba(255,0,0,0.8),
    0 0 60px rgba(255,0,0,0.4);
}

.overlay-text.gold {
  color: #ffdd44;
  text-shadow:
    0 0 20px rgba(255,220,0,0.8),
    0 0 60px rgba(255,220,0,0.4);
}

/* Floor Clear */
#floor-clear-overlay {
  background: rgba(0,0,0,0.7);
  flex-direction: column;
  gap: 20px;
}

#floor-clear-flash {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  animation: none;
}

#floor-clear-flash.flash {
  animation: white-flash 0.5s ease-out forwards;
}

@keyframes white-flash {
  0% { opacity: 1; }
  100% { opacity: 0; }
}

#floor-clear-content {
  text-align: center;
  position: relative;
  z-index: 1;
}

#floor-clear-stats {
  font-size: 14px;
  opacity: 0.7;
  margin-top: 12px;
  letter-spacing: 2px;
  color: var(--green-glow);
}

/* Game Over */
#gameover-screen {
  background: rgba(0,0,0,0.95);
}

#static-canvas {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  opacity: 0.15;
}

#gameover-content {
  position: relative;
  z-index: 2;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

#gameover-floor {
  font-size: 14px;
  letter-spacing: 3px;
  opacity: 0.6;
}

#gameover-buttons {
  display: flex;
  gap: 16px;
}

/* Victory */
#victory-screen {
  background: #000;
  flex-direction: column;
  text-align: center;
}

#victory-light {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, rgba(255,255,200,0.15) 0%, transparent 70%);
  animation: victory-glow 3s ease-in-out infinite;
}

@keyframes victory-glow {
  0%, 100% { opacity: 0.5; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.1); }
}

#victory-content {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

#victory-sub {
  font-size: 14px;
  letter-spacing: 3px;
  opacity: 0.7;
  max-width: 400px;
}

#victory-score {
  font-size: 20px;
  color: var(--amber);
  text-shadow: 0 0 15px rgba(255,160,0,0.7);
}

/* =====================================================
   BUTTONS (generic)
   ===================================================== */
button {
  font-family: 'Courier New', Courier, monospace;
  cursor: pointer;
  border-radius: 3px;
  transition: all 0.15s;
  text-transform: uppercase;
  letter-spacing: 2px;
}

#retry-btn, #menu-btn, #victory-menu-btn {
  padding: 12px 28px;
  background: rgba(0,20,10,0.9);
  border: 1px solid rgba(0,255,100,0.4);
  color: var(--green-glow);
  font-size: 14px;
}

#retry-btn:hover, #menu-btn:hover, #victory-menu-btn:hover {
  background: rgba(0,50,25,0.95);
  border-color: var(--green-glow);
  box-shadow: 0 0 15px rgba(0,255,100,0.3);
}

.icon-btn {
  background: none;
  border: 1px solid rgba(0,255,100,0.2);
  color: rgba(200,255,200,0.6);
  font-size: 18px;
  width: 36px; height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  padding: 0;
  letter-spacing: 0;
}

.icon-btn:hover {
  background: rgba(0,50,25,0.5);
  color: rgba(200,255,200,1);
}

#sound-toggle-start {
  position: absolute;
  bottom: 20px;
  right: 20px;
}

/* =====================================================
   VIGNETTE / DANGER OVERLAYS
   ===================================================== */
#vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center,
    transparent 40%,
    rgba(0,0,0,0.4) 70%,
    rgba(0,0,0,0.85) 100%
  );
  pointer-events: none;
  z-index: 40;
  transition: opacity 0.3s;
}

#danger-pulse {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center,
    transparent 30%,
    rgba(180,0,0,0.0) 70%,
    rgba(180,0,0,0.3) 100%
  );
  pointer-events: none;
  z-index: 41;
  opacity: 0;
  transition: opacity 0.2s;
}

#danger-pulse.active {
  animation: danger-throb 0.8s ease-in-out infinite;
}

@keyframes danger-throb {
  0%, 100% { opacity: 0; }
  50% { opacity: 1; }
}

/* =====================================================
   MOBILE JOYSTICK
   ===================================================== */
#joystick-container {
  position: absolute;
  bottom: 40px;
  left: 40px;
  z-index: 55;
  pointer-events: none;
}

#joystick-base {
  width: 100px; height: 100px;
  background: rgba(0,255,100,0.08);
  border: 2px solid rgba(0,255,100,0.3);
  border-radius: 50%;
  position: relative;
  pointer-events: auto;
  touch-action: none;
}

#joystick-knob {
  width: 44px; height: 44px;
  background: rgba(0,255,100,0.3);
  border: 2px solid rgba(0,255,100,0.6);
  border-radius: 50%;
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  transition: transform 0.05s;
  pointer-events: none;
}

/* =====================================================
   RESPONSIVE
   ===================================================== */
@media (max-width: 600px) {
  #hud {
    font-size: 11px;
    height: 48px;
    padding: 6px 10px;
  }
  #floor-num { font-size: 18px; }
  #battery-bar-container { width: 60px; }
  .diff-buttons { flex-direction: column; align-items: stretch; }
  .diff-btn { max-width: none; }
}

/* =====================================================
   SCROLLBAR
   ===================================================== */
::-webkit-scrollbar { width: 0; }
