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

:root {
  --wood-dark: #3E2415;
  --wood-med: #5C3A1E;
  --wood-light: #7A4F2B;
  --black: #111;
  --chrome: #b0b0b0;
  --chrome-light: #d8d8d8;
  --green-term: #33ff33;
  --bg: #1a1410;
  --red: #e74c3c;
  --orange: #f39c12;
  --yellow: #f1c40f;
  --green: #2ecc71;
  --blue: #3498db;
  --indigo: #6a3fbf;
}

body {
  background: var(--bg);
  background-image:
    repeating-linear-gradient(90deg, transparent 0, transparent 2px, rgba(0,0,0,.03) 2px, rgba(0,0,0,.03) 4px);
  color: #ddd;
  font-family: 'VT323', monospace;
  min-height: 100vh;
  overflow-x: hidden;
}

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

/* HEADER */
#header {
  text-align: center;
  margin-bottom: 15px;
}
#header h1 {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(14px, 3vw, 22px);
  color: #f5f5f5;
  text-shadow: 0 0 20px rgba(255,100,0,.4);
  margin: 8px 0 4px;
  letter-spacing: 1px;
}
#header .subtitle {
  font-family: 'VT323', monospace;
  font-size: clamp(14px, 2.5vw, 18px);
  color: #999;
  margin-bottom: 8px;
}

.rainbow-bar {
  height: 8px;
  background: linear-gradient(90deg, var(--red), var(--orange), var(--yellow), var(--green), var(--blue), var(--indigo));
  border-radius: 2px;
}
.rainbow-bar.thin { height: 4px; }

/* CART SLOT */
.cart-slot {
  margin: 10px auto;
  max-width: 400px;
}
.cart-slot-inner {
  background: linear-gradient(180deg, #222 0%, #1a1a1a 100%);
  border: 3px solid #444;
  border-radius: 6px 6px 0 0;
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: all .2s;
  position: relative;
  overflow: hidden;
}
.cart-slot-inner::before {
  content: '';
  position: absolute;
  top: 0; left: 50%;
  transform: translateX(-50%);
  width: 60%;
  height: 4px;
  background: #555;
  border-radius: 0 0 4px 4px;
}
.cart-slot-inner:hover, .cart-slot-inner.dragover {
  border-color: var(--orange);
  background: linear-gradient(180deg, #2a2a2a 0%, #222 100%);
  box-shadow: 0 0 20px rgba(243,156,18,.2);
}
.cart-icon {
  font-size: 28px;
  color: var(--orange);
  margin-bottom: 6px;
  animation: bob 2s ease-in-out infinite;
}
@keyframes bob { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-5px)} }
.cart-text {
  font-family: 'Press Start 2P', monospace;
  font-size: 12px;
  color: #ccc;
  margin-bottom: 4px;
}
.cart-subtext { font-size: 14px; color: #777; }

.rom-info {
  background: #1e1e1e;
  border: 2px solid #333;
  border-top: none;
  border-radius: 0 0 6px 6px;
  padding: 8px 12px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: var(--green-term);
  text-align: center;
}

/* CONSOLE FRAME */
#console-frame {
  margin: 15px auto;
  max-width: 700px;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 8px 40px rgba(0,0,0,.6), 0 0 60px rgba(100,50,0,.1);
}

.woodgrain-top, .woodgrain-bottom {
  height: 30px;
  background: linear-gradient(180deg,
    var(--wood-dark) 0%, var(--wood-med) 20%, var(--wood-light) 40%,
    var(--wood-med) 60%, var(--wood-dark) 80%, var(--wood-med) 100%);
  background-size: 100% 8px;
  position: relative;
}
.woodgrain-top::after, .woodgrain-bottom::before {
  content: '';
  position: absolute;
  left: 0; right: 0;
  height: 6px;
  background: linear-gradient(180deg, #111 0%, #222 50%, #111 100%);
}
.woodgrain-top::after { bottom: 0; }
.woodgrain-bottom::before { top: 0; }

.screen-area {
  background: #0a0a0a;
  padding: 20px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.crt-frame {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  box-shadow:
    0 0 30px rgba(200,200,255,.05),
    inset 0 0 60px rgba(0,0,0,.5);
}

#canvas {
  display: block;
  width: 640px;
  height: 480px;
  max-width: 90vw;
  max-height: 60vw;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
  background: #000;
  border-radius: 8px;
}

.scanlines {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: repeating-linear-gradient(
    0deg,
    rgba(0,0,0,.15) 0px,
    rgba(0,0,0,.15) 1px,
    transparent 1px,
    transparent 3px
  );
  pointer-events: none;
  border-radius: 8px;
}

.crt-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: radial-gradient(ellipse at center, transparent 60%, rgba(0,0,0,.5) 100%);
  pointer-events: none;
  border-radius: 8px;
}

/* SWITCH PANEL */
#switch-panel {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin: 15px auto;
  max-width: 700px;
  background: linear-gradient(180deg, #1a1a1a, #111);
  border: 2px solid #333;
  border-radius: 8px;
  padding: 12px 16px;
}
.switch-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.switch-group label {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: #888;
  letter-spacing: 1px;
}

.atari-switch {
  cursor: pointer;
  user-select: none;
}
.switch-track {
  width: 50px;
  height: 24px;
  background: linear-gradient(180deg, #555, #333);
  border-radius: 3px;
  position: relative;
  border: 1px solid #666;
  box-shadow: inset 0 2px 4px rgba(0,0,0,.5);
}
.switch-knob {
  width: 22px;
  height: 20px;
  background: linear-gradient(180deg, var(--chrome-light), var(--chrome), #999);
  border-radius: 2px;
  position: absolute;
  top: 1px;
  left: 1px;
  transition: left .15s;
  box-shadow: 0 1px 3px rgba(0,0,0,.5);
}
.atari-switch[data-state="on"] .switch-knob {
  left: 26px;
}

.atari-button {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  background: linear-gradient(180deg, #444, #222);
  color: #aaa;
  border: 1px solid #555;
  border-radius: 4px;
  padding: 6px 12px;
  cursor: pointer;
  transition: all .1s;
}
.atari-button:hover { background: linear-gradient(180deg, #555, #333); }
.atari-button:active {
  transform: scale(.95);
  background: linear-gradient(180deg, #333, #1a1a1a);
}

/* CONTROLS INFO */
#controls-info {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 20px;
  margin: 15px auto;
  max-width: 600px;
  font-size: 14px;
  color: #777;
}
#controls-info h3 {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  color: var(--orange);
  margin-bottom: 4px;
}
.control-col { text-align: center; }

/* DEBUG */
#debug-toggle {
  display: block;
  margin: 10px auto;
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  background: #1a1a1a;
  color: var(--green-term);
  border: 2px solid #333;
  border-radius: 4px;
  padding: 8px 20px;
  cursor: pointer;
  transition: all .2s;
}
#debug-toggle:hover {
  border-color: var(--green-term);
  box-shadow: 0 0 10px rgba(51,255,51,.2);
}

#debug-panel {
  max-width: 700px;
  margin: 10px auto;
  background: #0a0f0a;
  border: 2px solid #1a3a1a;
  border-radius: 8px;
  padding: 12px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.debug-section {
  background: #050a05;
  border: 1px solid #1a2a1a;
  border-radius: 4px;
  padding: 8px;
}
.debug-section h3 {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: var(--green-term);
  margin-bottom: 6px;
  opacity: .7;
}
.debug-mono {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--green-term);
  line-height: 1.5;
  white-space: pre;
}
.debug-mem-scroll {
  max-height: 120px;
  overflow-y: auto;
  font-size: 10px;
}
.debug-controls {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
  justify-content: center;
}
.debug-controls button {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  background: #0a0a0a;
  color: var(--green-term);
  border: 1px solid #1a3a1a;
  border-radius: 3px;
  padding: 6px 14px;
  cursor: pointer;
}
.debug-controls button:hover { background: #1a2a1a; }

/* MOBILE CONTROLS */
#mobile-controls {
  display: none;
  justify-content: space-around;
  align-items: center;
  margin: 15px auto;
  max-width: 400px;
}
.dpad {
  display: grid;
  grid-template-columns: 50px 50px 50px;
  grid-template-rows: 50px 50px 50px;
  gap: 2px;
}
.dpad-btn {
  background: #333;
  color: #aaa;
  border: 1px solid #555;
  border-radius: 4px;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.dpad-btn:active { background: #555; }
.dpad-center { background: transparent; border: none; }
.fire-btn {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: radial-gradient(circle, #c0392b, #96281b);
  color: #fff;
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  border: 3px solid #e74c3c;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(192,57,43,.5);
}
.fire-btn:active { transform: scale(.92); }

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

/* FOOTER */
#footer {
  text-align: center;
  margin-top: 20px;
  padding: 15px 0;
  color: #666;
  font-size: 13px;
}
#footer a {
  color: var(--orange);
  text-decoration: none;
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  display: inline-block;
  margin-top: 6px;
}
#footer a:hover { text-decoration: underline; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: #0a0a0a; }
::-webkit-scrollbar-thumb { background: #1a3a1a; border-radius: 3px; }

@media (max-width: 600px) {
  #canvas { width: 100%; height: auto; }
  .screen-area { padding: 10px; }
  #switch-panel { gap: 6px; padding: 8px; }
  #debug-panel { grid-template-columns: 1fr; }
  .switch-group label { font-size: 6px; }
}