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

:root {
  --wood: #3E2723;
  --wood-light: #5D4037;
  --orange: #FF6F00;
  --cream: #FFF8E1;
  --red: #E53935;
  --chrome: #B0BEC5;
  --chrome-dark: #78909C;
  --green-glow: #00FF41;
  --amber: #FFB300;
  --bg-dark: #1a1008;
}

body {
  background: var(--bg-dark);
  background-image:
    repeating-linear-gradient(90deg, transparent, transparent 20px, rgba(62,39,35,0.3) 20px, rgba(62,39,35,0.3) 21px),
    repeating-linear-gradient(0deg, transparent, transparent 4px, rgba(62,39,35,0.15) 4px, rgba(62,39,35,0.15) 5px);
  color: var(--cream);
  font-family: 'Press Start 2P', monospace;
  min-height: 100vh;
  overflow-x: hidden;
}

.rainbow-stripe {
  height: 6px;
  background: linear-gradient(90deg, #E53935 0%, #E53935 16.6%, #FF6F00 16.6%, #FF6F00 33.3%, #FFD600 33.3%, #FFD600 50%, #43A047 50%, #43A047 66.6%, #1E88E5 66.6%, #1E88E5 83.3%, #8E24AA 83.3%, #8E24AA 100%);
}

#header { text-align: center; padding: 20px 10px 10px; }

.title {
  font-size: clamp(14px, 4vw, 28px);
  color: var(--orange);
  text-shadow: 0 0 20px rgba(255,111,0,0.6), 0 0 40px rgba(255,111,0,0.3), 2px 2px 0 #1a0a00;
  letter-spacing: 2px;
  margin-bottom: 8px;
}

.subtitle {
  font-size: clamp(6px, 1.5vw, 10px);
  color: var(--amber);
  text-shadow: 0 0 10px rgba(255,179,0,0.4);
  opacity: 0.8;
}

#main-area { display: flex; flex-direction: column; align-items: center; padding: 15px; gap: 15px; }

#tv-bezel {
  background: linear-gradient(145deg, #2a2a2a 0%, #111 50%, #1a1a1a 100%);
  border: 4px solid #333;
  border-radius: 20px;
  padding: 20px;
  box-shadow: inset 0 2px 4px rgba(255,255,255,0.1), 0 8px 32px rgba(0,0,0,0.8), 0 0 60px rgba(0,0,0,0.5);
}

#crt-container {
  position: relative;
  width: clamp(280px, 80vw, 640px);
  aspect-ratio: 160/192;
  border-radius: 8px;
  overflow: hidden;
  background: #000;
}

#screen {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
}

#scanline-overlay {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  background: repeating-linear-gradient(0deg, transparent 0px, transparent 2px, rgba(0,0,0,0.15) 2px, rgba(0,0,0,0.15) 4px);
  pointer-events: none; z-index: 2;
}

#crt-vignette {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  background: radial-gradient(ellipse at center, transparent 60%, rgba(0,0,0,0.6) 100%);
  pointer-events: none; z-index: 3;
}

#cartridge-slot { width: clamp(260px, 70vw, 500px); }

#drop-zone {
  border: 3px dashed var(--chrome-dark);
  border-radius: 8px;
  padding: 20px;
  text-align: center;
  background: rgba(62,39,35,0.4);
  transition: all 0.3s;
  cursor: pointer;
}

#drop-zone:hover, #drop-zone.drag-over {
  border-color: var(--orange);
  background: rgba(255,111,0,0.1);
  box-shadow: 0 0 20px rgba(255,111,0,0.2);
}

.slot-graphic { margin: 0 auto 10px; width: 120px; height: 8px; background: #111; border-radius: 2px; border: 2px solid var(--chrome-dark); }
.slot-label { font-size: 12px; color: var(--orange); margin-bottom: 5px; }
.slot-sub { font-size: 7px; color: var(--chrome); margin-bottom: 10px; }

.retro-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px; padding: 10px 20px;
  background: linear-gradient(180deg, var(--chrome) 0%, var(--chrome-dark) 100%);
  color: #111; border: 2px solid #555; border-radius: 4px; cursor: pointer;
  text-transform: uppercase;
  box-shadow: 0 3px 0 #444, 0 5px 10px rgba(0,0,0,0.3);
  transition: all 0.1s;
}
.retro-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #444; }

#rom-info {
  font-size: 8px; color: var(--green-glow); text-align: center;
  padding: 8px; background: rgba(0,0,0,0.5); border-radius: 4px; margin-top: 8px;
}

#console-switches {
  display: flex; justify-content: center; gap: 15px; padding: 15px; flex-wrap: wrap;
  background: linear-gradient(180deg, var(--wood) 0%, var(--wood-light) 50%, var(--wood) 100%);
  border-top: 2px solid rgba(255,255,255,0.05); border-bottom: 2px solid rgba(0,0,0,0.3);
}

.switch-group { display: flex; flex-direction: column; align-items: center; gap: 5px; }
.switch-group label { font-size: 6px; color: var(--cream); opacity: 0.7; }

.switch {
  width: 40px; height: 22px;
  background: linear-gradient(180deg, #666 0%, #444 100%);
  border-radius: 3px; border: 2px solid #333; cursor: pointer; position: relative;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.5);
}
.switch-lever {
  position: absolute; width: 16px; height: 16px;
  background: linear-gradient(180deg, #ddd 0%, #aaa 100%);
  border-radius: 2px; top: 1px; left: 1px; transition: left 0.15s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}
.switch[data-on="true"] .switch-lever { left: 20px; }
.switch[data-on="true"] { background: linear-gradient(180deg, #555 0%, #333 100%); }

.switch-btn {
  font-family: 'Press Start 2P', monospace; font-size: 6px; padding: 6px 10px;
  background: linear-gradient(180deg, var(--chrome) 0%, var(--chrome-dark) 100%);
  color: #222; border: 2px solid #555; border-radius: 3px; cursor: pointer;
  box-shadow: 0 2px 0 #444;
}
.switch-btn:active { transform: translateY(1px); box-shadow: 0 1px 0 #444; }

#controls-bar { padding: 10px 15px; background: rgba(0,0,0,0.3); }
.control-row { display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; }

.ctrl-btn {
  font-family: 'Press Start 2P', monospace; font-size: 8px; padding: 6px 10px;
  background: rgba(62,39,35,0.8); color: var(--cream); border: 1px solid var(--chrome-dark);
  border-radius: 4px; cursor: pointer; transition: all 0.15s;
}
.ctrl-btn:hover { background: var(--orange); color: #111; }
.ctrl-btn.small { padding: 4px 8px; font-size: 10px; }

.speed-control, .vol-control { display: flex; align-items: center; gap: 4px; font-size: 6px; }
.speed-control input, .vol-control input { width: 60px; accent-color: var(--orange); }
#speed-val { font-size: 7px; color: var(--amber); min-width: 25px; }

#virtual-controls { display: none; padding: 20px; justify-content: space-between; align-items: center; }
@media (max-width: 768px) { #virtual-controls { display: flex; } }

#dpad { position: relative; width: 120px; height: 120px; }
.dpad-btn {
  position: absolute; width: 40px; height: 40px;
  background: rgba(80,80,80,0.8); color: var(--cream); border: 2px solid #555;
  border-radius: 6px; font-size: 14px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  -webkit-user-select: none; user-select: none; touch-action: none;
}
.dpad-btn:active { background: var(--orange); }
.dpad-btn.up { top: 0; left: 40px; }
.dpad-btn.down { bottom: 0; left: 40px; }
.dpad-btn.left { top: 40px; left: 0; }
.dpad-btn.right { top: 40px; right: 0; }
.dpad-center { position: absolute; top: 40px; left: 40px; width: 40px; height: 40px; background: #444; border-radius: 4px; }

#fire-btn {
  width: 80px; height: 80px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ff5252, var(--red), #b71c1c);
  color: white; font-family: 'Press Start 2P', monospace; font-size: 10px;
  border: 3px solid #c62828; cursor: pointer;
  box-shadow: 0 4px 15px rgba(229,57,53,0.4);
  -webkit-user-select: none; user-select: none; touch-action: none;
}
#fire-btn:active { transform: scale(0.95); box-shadow: 0 2px 8px rgba(229,57,53,0.6); }

#debug-panel {
  background: rgba(0, 10, 0, 0.95); border: 1px solid var(--green-glow);
  border-radius: 4px; margin: 10px 15px; padding: 12px; max-height: 600px; overflow-y: auto;
}
#debug-panel h3 {
  font-size: 10px; color: var(--green-glow); margin-bottom: 10px;
  text-shadow: 0 0 8px rgba(0,255,65,0.5);
}
.debug-section { margin-bottom: 10px; }
.debug-section h4 { font-size: 8px; color: var(--amber); margin-bottom: 4px; }
.debug-section pre {
  font-family: 'Courier New', monospace; font-size: 9px; color: var(--green-glow);
  line-height: 1.4; text-shadow: 0 0 4px rgba(0,255,65,0.3); white-space: pre-wrap; word-break: break-all;
}

#keyboard-help { padding: 10px 15px; text-align: center; }
#keyboard-help details { display: inline-block; }
#keyboard-help summary { font-size: 8px; color: var(--chrome); cursor: pointer; }
.key-list { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 8px; font-size: 7px; color: var(--amber); }

#toast {
  position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%);
  background: var(--orange); color: #111; font-size: 8px; padding: 10px 20px;
  border-radius: 4px; z-index: 1000; box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  animation: toast-in 0.3s ease;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(20px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

footer { text-align: center; padding: 15px; margin-top: 20px; }
footer p { font-size: 7px; color: var(--chrome-dark); margin: 8px 0; }
footer a { font-size: 8px; color: var(--orange); text-decoration: none; }
footer a:hover { text-shadow: 0 0 8px var(--orange); }

@keyframes cartridge-insert {
  0% { transform: translateY(-40px); opacity: 0; }
  60% { transform: translateY(5px); }
  100% { transform: translateY(0); opacity: 1; }
}
.cart-insert-anim { animation: cartridge-insert 0.5s ease-out; }

@media (max-width: 480px) {
  #console-switches { gap: 8px; padding: 10px 5px; }
  .switch-group label { font-size: 5px; }
  .ctrl-btn { font-size: 6px; padding: 4px 6px; }
  #tv-bezel { padding: 10px; }
}