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

:root {
  --wood1: #8B4513;
  --wood2: #A0522D;
  --wood3: #D2691E;
  --bezel: #1a1a1a;
  --screen-glow: rgba(0,255,100,0.15);
  --accent: #e8a020;
}

body {
  background: #0d0d0d;
  color: #ccc;
  font-family: 'Press Start 2P', monospace;
  min-height: 100vh;
  overflow-x: hidden;
}

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

/* Header */
#console-bar {
  background: linear-gradient(180deg, #6b3410 0%, #8B4513 20%, #A0522D 50%, #8B4513 80%, #6b3410 100%);
  border-radius: 8px 8px 0 0;
  padding: 2px 0;
  margin-top: 10px;
  border: 2px solid #5a2d0c;
  border-bottom: none;
}

.rainbow-stripe {
  height: 6px;
  background: linear-gradient(90deg, 
    #e04040 0%, #e04040 20%, 
    #e08020 20%, #e08020 40%, 
    #e0c020 40%, #e0c020 60%, 
    #40a040 60%, #40a040 80%, 
    #4060c0 80%, #4060c0 100%);
}

.header-content {
  text-align: center;
  padding: 12px 10px 8px;
}

.header-content h1 {
  font-size: 18px;
  color: #f0d090;
  text-shadow: 2px 2px 0 #3a1a00;
  letter-spacing: 3px;
}

.subtitle {
  font-size: 7px;
  color: #c09060;
  margin-top: 6px;
  letter-spacing: 1px;
}

/* Cartridge Slot */
#cartridge-slot {
  background: linear-gradient(180deg, #4a2808, #3a1a00);
  border: 2px solid #5a2d0c;
  border-top: none;
  padding: 10px 20px;
  text-align: center;
}

#cart-label {
  font-size: 10px;
  color: var(--accent);
  margin-bottom: 8px;
  letter-spacing: 2px;
}

#rom-input { display: none; }

#rom-label {
  display: inline-block;
  background: linear-gradient(180deg, #555, #333);
  color: #ddd;
  padding: 8px 20px;
  font-size: 8px;
  font-family: 'Press Start 2P', monospace;
  border: 2px solid #666;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
}

#rom-label:hover {
  background: linear-gradient(180deg, #666, #444);
  border-color: var(--accent);
  color: #fff;
}

#cart-info {
  font-size: 7px;
  color: #90c090;
  margin-top: 6px;
  text-align: left;
  background: #1a1a0a;
  padding: 6px;
  border-radius: 3px;
  word-break: break-all;
}

/* TV Bezel */
#tv-bezel {
  background: radial-gradient(ellipse at center, #2a2a2a, #111);
  border: 8px solid var(--bezel);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 
    inset 0 0 30px rgba(0,0,0,0.8),
    0 0 20px rgba(0,255,100,0.05);
  margin: 0;
}

#screen-container {
  position: relative;
  width: 100%;
  padding-top: 75%;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 0 40px var(--screen-glow);
}

#canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#scanline-overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    transparent 0px,
    transparent 2px,
    rgba(0,0,0,0.15) 2px,
    rgba(0,0,0,0.15) 4px
  );
  display: none;
}

#screen-container.crt #scanline-overlay { display: block; }
#screen-container.crt {
  border-radius: 20px;
  box-shadow: 
    0 0 60px rgba(0,255,100,0.1),
    inset 0 0 20px rgba(0,255,100,0.05);
}

#no-signal {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%,-50%);
  font-size: 14px;
  color: #555;
  animation: flicker 3s infinite;
  z-index: 2;
}

.static-noise {
  /* The canvas will show noise when no ROM */
}

@keyframes flicker {
  0%,100% { opacity: 0.6; }
  50% { opacity: 1; }
  92% { opacity: 0.6; }
  94% { opacity: 0; }
  96% { opacity: 0.8; }
}

/* Control Panel */
#control-panel {
  background: linear-gradient(180deg, #8B4513, #6b3410);
  border: 2px solid #5a2d0c;
  border-top: none;
  padding: 12px 10px;
  border-radius: 0 0 8px 8px;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.switch-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.switch-group label {
  font-size: 6px;
  color: #d0a060;
  letter-spacing: 1px;
}

.toggle-switch {
  width: 44px; height: 22px;
  background: #333;
  border-radius: 11px;
  cursor: pointer;
  position: relative;
  border: 2px solid #555;
  transition: background 0.2s;
}

.toggle-switch.small { width: 36px; height: 18px; }

.switch-handle {
  position: absolute;
  top: 2px; left: 2px;
  width: 14px; height: 14px;
  background: linear-gradient(180deg, #eee, #aaa);
  border-radius: 50%;
  transition: left 0.2s;
  box-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}

.toggle-switch.small .switch-handle {
  width: 10px; height: 10px; top: 2px;
}

.toggle-switch[data-state="on"] { background: #2a6a2a; }
.toggle-switch[data-state="on"] .switch-handle { left: calc(100% - 18px); }
.toggle-switch.small[data-state="on"] .switch-handle { left: calc(100% - 14px); }

.led {
  width: 8px; height: 8px;
  background: #331111;
  border-radius: 50%;
  border: 1px solid #444;
  transition: all 0.3s;
}

.led.on {
  background: #ff2020;
  box-shadow: 0 0 8px #ff0000, 0 0 16px #ff000066;
}

.console-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  background: linear-gradient(180deg, #555, #333);
  color: #ddd;
  border: 2px solid #666;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.1s;
}

.console-btn:active {
  transform: translateY(1px);
  background: linear-gradient(180deg, #444, #222);
}

.playback-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.playback-controls button,
.playback-controls select {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  background: #333;
  color: #ddd;
  border: 1px solid #555;
  padding: 4px 8px;
  border-radius: 3px;
  cursor: pointer;
}

.playback-controls select {
  font-size: 7px;
}

/* Input Info */
#input-info {
  display: flex;
  justify-content: center;
  gap: 14px;
  padding: 8px;
  font-size: 6px;
  color: #666;
  flex-wrap: wrap;
}

/* Debug Panel */
#debug-toggle {
  display: block;
  width: 100%;
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  background: #1a1a1a;
  color: #4a4;
  border: 1px solid #333;
  padding: 6px;
  cursor: pointer;
  text-align: center;
  margin-top: 4px;
}

#debug-panel {
  background: #0a0a0a;
  border: 1px solid #333;
  padding: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  max-height: 300px;
  overflow-y: auto;
}

.debug-section h3 {
  font-size: 7px;
  color: var(--accent);
  margin-bottom: 4px;
}

.debug-section pre {
  font-family: 'Courier New', monospace;
  font-size: 9px;
  color: #0f0;
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.4;
}

/* Footer */
footer {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  padding: 12px;
  font-size: 7px;
  color: #555;
  flex-wrap: wrap;
}

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

.disclaimer { font-size: 6px; color: #444; }

/* Touch Controls */
#touch-controls {
  position: fixed;
  bottom: 20px;
  left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 20px;
  pointer-events: none;
  z-index: 100;
}

#dpad {
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: auto;
}

.dpad-mid {
  display: flex;
  gap: 30px;
}

.dpad-btn {
  width: 44px; height: 44px;
  background: rgba(255,255,255,0.15);
  border: 2px solid rgba(255,255,255,0.3);
  border-radius: 8px;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.dpad-btn:active { background: rgba(255,255,255,0.35); }

#fire-btn {
  pointer-events: auto;
  width: 64px; height: 64px;
  background: rgba(255,50,50,0.4);
  border: 3px solid rgba(255,50,50,0.6);
  border-radius: 50%;
  color: #fff;
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

#fire-btn:active { background: rgba(255,50,50,0.7); }

@media (max-width: 600px) {
  .header-content h1 { font-size: 12px; }
  .subtitle { font-size: 6px; }
  #debug-panel { grid-template-columns: 1fr; }
  .switch-row { gap: 8px; }
}

@media (pointer: coarse) {
  #touch-controls { display: flex !important; }
}