:root {
  --primary-accent: #ff3344;
  --secondary-accent: #00e5ff;
  --gold-wall: #eab308;
  --gold-glow: rgba(234, 179, 8, 0.45);
  --bg-dark: #070913;
  --panel-bg: rgba(15, 23, 42, 0.85);
  --panel-border: rgba(255, 255, 255, 0.12);
  --text-main: #f8fafc;
  --text-dim: #94a3b8;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-dark);
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--text-main);
  touch-action: none;
}

#game-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: radial-gradient(circle at center, #0f172a 0%, #05070e 100%);
  overflow: hidden;
}

/* Top HUD */
#top-hud {
  height: 58px;
  min-height: 58px;
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--panel-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 20;
}

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

.hud-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 4px 10px;
  border-radius: 8px;
}

.hud-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(2, 132, 199, 0.15);
  border: 1px solid rgba(56, 189, 248, 0.3);
  padding: 4px 12px;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  transition: all 0.2s;
}

.hud-btn:hover {
  background: rgba(2, 132, 199, 0.35);
  border-color: #38bdf8;
  transform: translateY(-1px);
}

.badge-label {
  font-size: 11px;
  font-weight: 800;
  color: var(--text-dim);
  letter-spacing: 1px;
}

.badge-val {
  font-size: 16px;
  font-weight: 900;
  color: #fff;
  font-family: 'Teko', sans-serif;
  letter-spacing: 0.5px;
}

.score-badge .badge-val {
  color: #fbbf24;
}

.nitro-badge {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nitro-bar-wrap {
  width: 50px;
  height: 10px;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(0, 229, 255, 0.3);
  border-radius: 5px;
  overflow: hidden;
}

#nitro-fill {
  height: 100%;
  background: linear-gradient(90deg, #0284c7, #00e5ff);
  box-shadow: 0 0 8px #00e5ff;
  transition: width 0.1s linear;
}

.objective-tracker {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 229, 255, 0.12);
  border: 1px solid rgba(0, 229, 255, 0.3);
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 800;
  color: #e0f2fe;
  letter-spacing: 0.5px;
}

.obj-icon {
  font-size: 15px;
  animation: pulse-glow 1.5s infinite alternate;
}

.icon-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #f8fafc;
  border-radius: 8px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.25);
  transform: translateY(-1px);
}

.heart-icon {
  font-size: 16px;
  filter: drop-shadow(0 0 4px rgba(239, 68, 68, 0.8));
  transition: transform 0.2s ease;
}

.heart-icon.lost {
  opacity: 0.2;
  filter: grayscale(1);
}

.hidden {
  display: none !important;
}

/* Canvas Area */
#canvas-wrapper {
  flex: 1;
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#gameCanvas {
  display: block;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
  border-radius: 8px;
}

/* Bottom Cinematic Subtitle Bar */
#subtitles-banner {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: 0 4px 25px rgba(0, 0, 0, 0.6);
  border-radius: 24px;
  padding: 8px 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 90%;
  z-index: 15;
  pointer-events: none;
}

.subtitle-alert-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ef4444;
  box-shadow: 0 0 12px #ef4444;
  animation: blink-dot 1s infinite;
  flex-shrink: 0;
}

#subtitle-content {
  font-size: 13px;
  font-weight: 800;
  color: #f8fafc;
  letter-spacing: 0.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Mobile & Tablet Controls */
#touch-controls {
  display: none;
  position: absolute;
  bottom: 24px;
  left: 0;
  width: 100%;
  padding: 0 28px;
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none;
  z-index: 30;
}

@media (pointer: coarse), (max-width: 1200px) {
  #touch-controls {
    display: flex;
  }
}

#dpad {
  position: relative;
  width: 144px;
  height: 144px;
  pointer-events: auto;
}

.dpad-btn {
  position: absolute;
  width: 48px;
  height: 48px;
  background: rgba(30, 41, 59, 0.88);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #fff;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  cursor: pointer;
  transition: all 0.1s ease;
  touch-action: none;
}

.dpad-btn:active {
  background: rgba(0, 229, 255, 0.5);
  border-color: #00e5ff;
  transform: scale(0.95);
}

.dpad-up { top: 0; left: 48px; }
.dpad-down { bottom: 0; left: 48px; }
.dpad-left { top: 48px; left: 0; }
.dpad-right { top: 48px; right: 0; }
.dpad-center { top: 48px; left: 48px; width: 48px; height: 48px; opacity: 0.25; border-radius: 50%; }

#touch-actions {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.action-btn {
  position: relative;
  background: linear-gradient(135deg, #ef4444, #b91c1c);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: white;
  padding: 14px 22px;
  border-radius: 30px;
  font-family: 'Outfit', sans-serif;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 1px;
  box-shadow: 0 4px 15px rgba(239, 68, 68, 0.5);
  cursor: pointer;
  touch-action: none;
}

.action-btn:active {
  transform: scale(0.95);
  background: #dc2626;
}

/* Specific Mobile Portrait & Landscape Adaptations */
@media (max-width: 768px) {
  #top-hud {
    height: 50px;
    min-height: 50px;
    padding: 0 8px;
  }
  .hud-badge {
    padding: 3px 6px;
    gap: 4px;
  }
  .hud-btn {
    padding: 3px 8px;
    gap: 4px;
  }
  .badge-label {
    font-size: 9px;
  }
  .badge-val {
    font-size: 14px;
  }
  .objective-tracker {
    font-size: 11px;
    padding: 4px 10px;
  }
  #subtitles-banner {
    bottom: 8px;
    padding: 6px 14px;
    font-size: 11px;
  }
  #touch-controls {
    bottom: 12px;
    padding: 0 12px;
  }
  #dpad {
    width: 120px;
    height: 120px;
  }
  .dpad-btn {
    width: 40px;
    height: 40px;
    font-size: 15px;
    border-radius: 8px;
  }
  .dpad-up { top: 0; left: 40px; }
  .dpad-down { bottom: 0; left: 40px; }
  .dpad-left { top: 40px; left: 0; }
  .dpad-right { top: 40px; right: 0; }
  .dpad-center { top: 40px; left: 40px; width: 40px; height: 40px; }
  .action-btn {
    padding: 12px 18px;
    font-size: 11px;
  }
}

/* Mobile Landscape Orientation */
@media (max-height: 500px) and (orientation: landscape) {
  #top-hud {
    height: 42px;
    min-height: 42px;
    padding: 0 10px;
  }
  .objective-tracker {
    display: none; /* Hide center tracker in landscape to maximize vertical canvas space */
  }
  #subtitles-banner {
    display: none; /* Hide subtitle banner in ultra-compact landscape */
  }
  #touch-controls {
    bottom: 8px;
    padding: 0 16px;
  }
  #dpad {
    width: 110px;
    height: 110px;
  }
  .dpad-btn {
    width: 36px;
    height: 36px;
    font-size: 14px;
  }
  .dpad-up { top: 0; left: 37px; }
  .dpad-down { bottom: 0; left: 37px; }
  .dpad-left { top: 37px; left: 0; }
  .dpad-right { top: 37px; right: 0; }
  .dpad-center { top: 37px; left: 37px; width: 36px; height: 36px; }
  .action-btn {
    padding: 10px 16px;
    font-size: 11px;
  }
}

/* Modal Overlay & Level Selector */
#modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(3, 7, 18, 0.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

#modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: rgba(17, 24, 39, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.9), 0 0 35px rgba(239, 68, 68, 0.25);
  border-radius: 20px;
  width: 90%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 16px;
  transform: scale(0.95);
  transition: transform 0.3s ease;
}

#modal-overlay.active .modal-card {
  transform: scale(1);
}

.modal-header h1 {
  font-size: 32px;
  font-weight: 900;
  font-family: 'Teko', sans-serif;
  letter-spacing: 1.5px;
  background: linear-gradient(135deg, #ff4d4d, #f59e0b, #38bdf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.modal-header p {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: 1.5px;
  margin-top: 2px;
}

.mission-brief-card {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
}

.brief-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brief-tag {
  font-size: 11px;
  font-weight: 800;
  color: #38bdf8;
  background: rgba(56, 189, 248, 0.12);
  padding: 2px 8px;
  border-radius: 6px;
  white-space: nowrap;
}

.brief-info {
  font-size: 12px;
  color: #cbd5e1;
  line-height: 1.3;
}

/* Level Grid */
#level-select-container {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.level-select-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 800;
  color: var(--text-dim);
  letter-spacing: 1px;
}

.text-btn {
  background: none;
  border: none;
  color: #f87171;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.2s;
}

.text-btn:hover {
  text-decoration: underline;
  opacity: 0.8;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.level-slot {
  position: relative;
  aspect-ratio: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: 'Teko', sans-serif;
  font-size: 20px;
  font-weight: 800;
  color: #94a3b8;
  cursor: pointer;
  transition: all 0.2s ease;
}

.level-slot.unlocked {
  background: rgba(14, 165, 233, 0.15);
  border-color: rgba(56, 189, 248, 0.4);
  color: #f8fafc;
}

.level-slot.unlocked:hover {
  background: rgba(14, 165, 233, 0.35);
  border-color: #38bdf8;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(56, 189, 248, 0.4);
}

.level-slot.current {
  border-color: #f59e0b;
  background: rgba(245, 158, 11, 0.25);
  color: #fbbf24;
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.5);
}

.level-slot.locked {
  opacity: 0.35;
  cursor: not-allowed;
  border-style: dashed;
}

.level-slot .lock-icon {
  font-size: 14px;
}

.level-slot .star-badge {
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 10px;
  color: #fbbf24;
}

.modal-footer {
  display: flex;
  justify-content: center;
}

.primary-btn {
  position: relative;
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: white;
  border: none;
  border-radius: 30px;
  padding: 14px 40px;
  font-size: 16px;
  font-weight: 800;
  font-family: 'Outfit', sans-serif;
  letter-spacing: 1.5px;
  cursor: pointer;
  box-shadow: 0 8px 25px rgba(239, 68, 68, 0.5);
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
}

.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 30px rgba(239, 68, 68, 0.7);
}

.primary-btn:active {
  transform: translateY(1px);
}

@keyframes blink-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

@keyframes pulse-glow {
  0% { transform: scale(1); filter: drop-shadow(0 0 2px #00e5ff); }
  100% { transform: scale(1.15); filter: drop-shadow(0 0 8px #00e5ff); }
}
