:root {
  --bg-dark: #0a0a1a;
  --bg-mid: #1a1a2e;
  --orange: #e94560;
  --cyan: #0f3460;
  --yellow: #f5a623;
  --amber: #d4a853;
  --green: #39ff14;
  --wood-light: #8B6914;
  --wood-dark: #5C4033;
  --wood-grain: linear-gradient(90deg, #7a5a2e 0%, #8B6914 15%, #6b4e1f 30%, #8B6914 45%, #7a5a2e 60%, #9a7a3e 75%, #6b4e1f 90%, #8B6914 100%);
}

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

body {
  background: var(--bg-dark);
  color: #ddd;
  font-family: 'IBM Plex Mono', monospace;
  min-height: 100vh;
  overflow-x: hidden;
}

body::before {
  content: '';
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0,0,0,0.08) 2px,
    rgba(0,0,0,0.08) 4px
  );
  pointer-events: none;
  z-index: 9999;
}

#app {
  max-width: 800px;
  margin: 0 auto;
  padding: 16px;
}

header {
  text-align: center;
  padding: 24px 16px;
  background: var(--bg-mid);
  border-bottom: 3px solid var(--orange);
  margin-bottom: 20px;
}

header h1 {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(20px, 5vw, 36px);
  color: var(--yellow);
  text-shadow: 0 0 20px rgba(245,166,35,0.5), 3px 3px 0 var(--orange);
  letter-spacing: 4px;
}

.subtitle {
  font-size: clamp(8px, 2vw, 12px);
  color: var(--amber);
  margin-top: 10px;
  font-family: 'IBM Plex Mono', monospace;
}

.cartridge-slot {
  background: #111;
  border: 3px solid #333;
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s;
  box-shadow: inset 0 4px 20px rgba(0,0,0,0.8);
}

.cartridge-slot:hover, .cartridge-slot.drag-over {
  border-color: var(--yellow);
  box-shadow: inset 0 4px 20px rgba(0,0,0,0.8), 0 0 20px rgba(245,166,35,0.3);
}

.slot-label {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(10px, 2.5vw, 16px);
  color: var(--orange);
  margin-bottom: 10px;
}

#rom-info {
  font-size: 13px;
  color: var(--green);
}

#tv-container {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

#tv-bezel {
  background: var(--wood-grain);
  border-radius: 20px;
  padding: 28px 32px 20px;
  position: relative;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6), inset 0 2px 4px rgba(255,255,255,0.1);
  border: 2px solid #4a3a1a;
}

#tv-screen-wrap {
  position: relative;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: inset 0 0 30px rgba(0,0,0,0.9), 0 0 15px rgba(0,0,0,0.5);
  border: 3px solid #222;
}

#canvas {
  display: block;
  width: clamp(320px, 80vw, 640px);
  height: auto;
  aspect-ratio: 160 / 192;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
}

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

#power-led {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #333;
  position: absolute;
  bottom: 8px;
  left: 20px;
  transition: all 0.3s;
}

#power-led.on {
  background: var(--green);
  box-shadow: 0 0 8px var(--green), 0 0 16px var(--green);
  animation: pulse-led 2s ease-in-out infinite;
}

@keyframes pulse-led {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

#tv-brand {
  position: absolute;
  bottom: 6px;
  right: 20px;
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  color: rgba(0,0,0,0.4);
}

#console-panel {
  background: var(--wood-grain);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
  border: 2px solid #4a3a1a;
}

.console-switches, .speed-controls, .extra-controls, .palette-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-bottom: 10px;
}

.btn-console {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(7px, 1.5vw, 10px);
  background: #222;
  color: var(--amber);
  border: 2px solid #444;
  border-radius: 6px;
  padding: 8px 12px;
  cursor: pointer;
  transition: all 0.15s;
  text-transform: uppercase;
}

.btn-console:hover {
  background: #333;
  border-color: var(--yellow);
  color: var(--yellow);
}

.btn-console:active {
  transform: scale(0.95);
  background: #111;
}

.btn-console.active {
  background: var(--cyan);
  border-color: var(--yellow);
  color: var(--yellow);
}

#controls-help {
  text-align: center;
  margin-bottom: 16px;
  font-size: 11px;
  color: #888;
}

.key-map {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
}

kbd {
  background: #222;
  border: 1px solid #555;
  border-radius: 3px;
  padding: 2px 6px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  color: var(--amber);
}

#mobile-controls {
  display: none;
  justify-content: space-around;
  align-items: center;
  margin-bottom: 16px;
  padding: 16px;
}

@media (max-width: 768px) {
  #mobile-controls {
    display: flex;
  }
  #controls-help {
    display: none;
  }
}

#dpad {
  display: grid;
  grid-template-areas:
    ". up ."
    "left . right"
    ". down .";
  gap: 4px;
}

.dpad-btn {
  width: 48px;
  height: 48px;
  background: #333;
  border: 2px solid #555;
  border-radius: 8px;
  color: var(--amber);
  font-size: 20px;
  cursor: pointer;
  font-family: 'Press Start 2P', monospace;
}

.dpad-btn[data-dir="up"] { grid-area: up; }
.dpad-btn[data-dir="left"] { grid-area: left; }
.dpad-btn[data-dir="right"] { grid-area: right; }
.dpad-btn[data-dir="down"] { grid-area: down; }

#fire-btn {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--orange);
  border: 3px solid var(--yellow);
  color: #fff;
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  cursor: pointer;
}

#btn-debug {
  display: block;
  margin: 0 auto 12px;
}

#debug-panel {
  background: #001100;
  border: 2px solid #004400;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 16px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--green);
  max-height: 300px;
  overflow-y: auto;
}

#debug-panel div {
  margin-bottom: 6px;
}

#status-bar {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg-mid);
  border-radius: 6px;
  margin-bottom: 20px;
  font-size: 11px;
  color: #888;
}

footer {
  text-align: center;
  padding: 20px;
  font-size: 10px;
  color: #555;
  border-top: 1px solid #222;
}

footer a {
  color: var(--orange);
  text-decoration: none;
}

footer a:hover {
  color: var(--yellow);
}

.disclaimer {
  margin-top: 8px;
  font-style: italic;
  font-size: 9px;
}

@media (max-width: 500px) {
  #tv-bezel {
    padding: 16px;
    border-radius: 12px;
  }
  #console-panel {
    padding: 10px;
  }
  .btn-console {
    padding: 6px 8px;
  }
}