@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

:root {
  --bg-color: #050014;
  --panel-bg: #100a26;
  --neon-cyan: #00f3ff;
  --neon-pink: #bc13fe;
  --text-color: #e0e0e0;
  --hud-border: 4px solid var(--neon-cyan);
}

body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-color);
  color: var(--text-color);
  font-family: 'Press Start 2P', cursive;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  /* Starfield background effect */
  background-image:
    radial-gradient(white, rgba(255, 255, 255, .2) 2px, transparent 3px),
    radial-gradient(white, rgba(255, 255, 255, .15) 1px, transparent 2px),
    radial-gradient(white, rgba(255, 255, 255, .1) 2px, transparent 3px);
  background-size: 550px 550px, 350px 350px, 250px 250px;
  background-position: 0 0, 40px 60px, 130px 270px;
}

.container {
  max-width: 1200px;
  width: 100%;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative; /* Context for absolute positioning on large screens */
}

h1 {
  font-size: clamp(1.2rem, 4vw, 2rem);
  color: var(--neon-cyan);
  text-shadow: 2px 2px var(--neon-pink);
  margin-bottom: 2rem;
  text-align: center;
  line-height: 1.5;
  width: 100%;
}

/* Video / HUD Area */
.video-area {
  position: relative;
  width: 100%;
  max-width: 640px;
  aspect-ratio: 4 / 3;
  height: auto;
  background: #000;
  border: var(--hud-border);
  box-shadow: 0 0 20px var(--neon-cyan), inset 0 0 20px var(--neon-cyan);
  margin: 0 auto 20px auto;
  overflow: hidden;
}

/* CRT Scanline Effect */
.video-area::after {
  content: " ";
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.06), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.06));
  z-index: 10;
  background-size: 100% 2px, 3px 100%;
  pointer-events: none;
}

#video,
#output {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}


/* Game Layout */
.game-layout {
  display: flex;
  flex-direction: row;
  gap: 20px;
  align-items: flex-start;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

/* Stats Panel (HUD) */
.hud {
  /* Default Desktop Layout: Absolute Left */
  position: absolute;
  left: 20px;
  top: 120px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  background: var(--panel-bg);
  padding: 20px;
  border: 2px solid var(--neon-cyan);
  box-shadow: 4px 4px 0px var(--neon-cyan);
  width: 200px;
  z-index: 10;
  box-sizing: border-box;
}

.stat-box {
  background: rgba(0, 0, 0, 0.65);
  padding: 15px 25px;
  border-radius: 15px;
  text-align: left;
  border: 2px solid #ffffff55;
  margin-bottom: 0;
}

.stat-box .label {
  color: #888;
  font-size: 0.7rem;
  margin-bottom: 5px;
  display: block;
  text-align: left;
  font-weight: bold;
}

.stat-box .value {
  color: var(--neon-cyan);
  font-size: 2rem;
  font-weight: bold;
  text-align: left;
  word-wrap: break-word; /* Prevent overflow */
}

/* Controls */
#controlsArea {
  /* Default Desktop Layout: Absolute Right */
  position: absolute;
  right: 20px;
  top: 120px;
  width: 260px;
  background: rgba(0, 0, 0, 0.6);
  padding: 20px;
  border-radius: 12px;
  border: 2px solid #333;
  box-shadow: 0 0 15px rgba(255, 255, 255, 0.15);
  z-index: 20;
  box-sizing: border-box;
}

.controls {
  display: flex;
  gap: 15px;
  margin-bottom: 20px;
  width: 100%;
  justify-content: center;
}


button {
  background: var(--neon-pink);
  color: white;
  font-family: 'Press Start 2P', cursive;
  border: none;
  padding: 15px 20px;
  font-size: 0.9rem;
  cursor: pointer;
  box-shadow: 4px 4px 0px #6e009e;
  transition: transform 0.1s, box-shadow 0.1s;
}

button:active {
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0px #6e009e;
}

button:disabled {
  background: #555;
  box-shadow: 4px 4px 0px #333;
  cursor: not-allowed;
}

#startBtn {
  background: var(--neon-cyan);
  color: #000;
  box-shadow: 4px 4px 0px #008f96;
}

#startBtn:active {
  box-shadow: 2px 2px 0px #008f96;
}

#activeControls {
  display: flex;
  gap: 15px;
  flex-wrap: wrap;
  justify-content: center;
}

#infoBtn {
  background: #333;
  color: #fff;
  box-shadow: 4px 4px 0px #111;
  border: 1px solid #555;
}

#infoBtn:hover {
  background: #444;
}

/* Coach & Log */
.coach {
  width: 100%;
  border: 1px dashed var(--neon-cyan);
  padding: 15px;
  min-height: 60px;
  margin-bottom: 15px;
  background: rgba(0, 243, 255, 0.1);
  color: var(--neon-cyan);
  font-size: 0.8rem;
  line-height: 1.4;
  box-sizing: border-box;
}

#log {
  width: 100%;
  max-width: 640px;
  height: 150px;
  overflow-y: auto;
  font-size: 0.7rem;
  color: #888;
  border-top: 1px solid #333;
  padding-top: 10px;
  box-sizing: border-box;
}

#missionSelect h3 {
  text-align: center;
  font-size: 1rem;
}

.mission-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.mode-btn, .skin-btn {
  width: 100%;
  padding: 12px;
  background: #222;
  color: white;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: 0.25s;
  font-family: inherit; /* Ensure font matches */
  font-size: 0.8rem;
}

.mode-btn:hover, .skin-btn:hover {
  background: #dc8a0f;
  transform: scale(1.03);
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  z-index: 100;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.8);
  justify-content: center;
  align-items: center;
  padding: 20px; /* Prevent edge touching */
  box-sizing: border-box;
}

.modal-content {
  background-color: var(--panel-bg);
  border: 4px solid var(--neon-pink);
  padding: 30px;
  text-align: center;
  max-width: 500px;
  width: 100%;
  box-shadow: 0 0 30px var(--neon-pink);
  box-sizing: border-box;
}

.input-group {
  margin: 20px 0;
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

input[type="text"] {
  padding: 10px;
  font-family: inherit;
  font-size: 1rem;
  background: #000;
  color: #fff;
  border: 2px solid var(--neon-cyan);
  width: 80px;
  text-align: center;
  text-transform: uppercase;
}

.leaderboard {
  margin-top: 20px;
  border-top: 1px solid #333;
  padding-top: 20px;
}

.leaderboard ul {
  list-style: none;
  padding: 0;
}

.leaderboard li {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  color: #aaa;
  font-size: 0.8rem;
}

/* 
   RESPONSIVE BREAKPOINT 
   Switch from absolute sidebar layouts to stacked specific layout 
   when screen width is less than ~1200px (or smaller if preferred, 
   but 1200 covers tablets in landscape often)
*/
@media (max-width: 1200px) {
  .hud, #controlsArea {
    position: static; /* Remove absolute positioning */
    width: 100%;
    max-width: 600px; /* Keep them neat */
    margin: 10px auto; /* Center them */
  }

  .hud {
     flex-direction: row;
     flex-wrap: wrap;
     justify-content: center;
  }
  
  .stat-box {
    flex: 1 1 150px; /* Allow growing, shrinking, basis 150px */
    min-width: 140px;
  }

  .container {
    padding: 10px;
  }

  h1 {
     margin-bottom: 1rem;
  }
}

@media (max-width: 600px) {
  /* Smaller mobile specific tweaks */
  .hud {
    padding: 10px;
    gap: 10px;
  }

  .stat-box .value {
     font-size: 1.5rem;
  }
  
  button {
    padding: 12px 15px;
    font-size: 0.8rem;
  }
  
  .video-area {
     margin-bottom: 10px;
     border-width: 2px; /* Thinner border for small screens */
  }
}