:root {
  --bg-deep: #0a0a14;
  --bg-dark: #1a1a2e;
  --bg-mid: #16213e;
  --sega-red: #d32f2f;
  --sega-blue: #1565c0;
  --accent-glow: #ff4444;
  --text-pri: #e0e0e0;
  --text-sec: #888;
  --text-dim: #555;
  --border: #2a2a3e;
  --panel-bg: #12122a;
}

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

body {
  background: var(--bg-deep);
  color: var(--text-pri);
  font-family: 'JetBrains Mono', monospace;
  min-height: 100vh;
  overflow-x: hidden;
}

#emulator-root {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px;
  gap: 8px;
  max-width: 1400px;
  margin: 0 auto;
}

/* Toolbar */
#toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  width: 100%;
  max-width: 900px;
}

#toolbar button {
  background: var(--bg-mid);
  border: 1px solid var(--border);
  color: var(--text-pri);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  padding: 5px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
#toolbar button:hover { background: #1e2d50; border-color: var(--sega-blue); }
#toolbar button.active { border-color: var(--sega-red); color: var(--sega-red); }

.toolbar-sep {
  width: 1px; height: 24px;
  background: var(--border);
  margin: 0 2px;
}

#vol-label {
  display: flex; align-items: center; gap: 4px; font-size: 12px;
}
#vol-slider {
  width: 60px; accent-color: var(--sega-red);
}

#btn-power.on { color: #4caf50; border-color: #4caf50; }

/* Main area */
#main-area {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  justify-content: center;
  width: 100%;
}

/* Console Shell */
#console-shell {
  background: linear-gradient(145deg, #1c1c2e 0%, #111122 100%);
  border-radius: 16px;
  padding: 16px;
  box-shadow:
    0 8px 32px rgba(0,0,0,0.6),
    inset 0 1px 0 rgba(255,255,255,0.05);
  border: 1px solid #2a2a3a;
  position: relative;
}

#console-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  padding: 0 4px;
}

#power-led {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #333;
  box-shadow: none;
  transition: all 0.4s;
}
#power-led.on {
  background: var(--accent-glow);
  box-shadow: 0 0 8px var(--accent-glow), 0 0 20px rgba(255,68,68,0.3);
}

#sega-brand {
  font-family: 'Press Start 2P', cursive;
  font-size: 14px;
  color: var(--sega-blue);
  letter-spacing: 4px;
  text-shadow: 0 0 10px rgba(21,101,192,0.4);
}
.brand-sub {
  font-size: 7px;
  display: block;
  text-align: center;
  color: var(--text-sec);
  letter-spacing: 2px;
  margin-top: 2px;
}

#cart-slot {
  width: 60px; height: 6px;
  background: #0a0a12;
  border-radius: 2px;
  border: 1px solid #2a2a3a;
}

#screen-bezel {
  background: #080810;
  border-radius: 12px;
  padding: 12px;
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 2px 12px rgba(0,0,0,0.8);
}

#screen {
  display: block;
  width: 768px;
  height: 576px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border-radius: 6px;
  background: #000;
}

#scanline-overlay {
  position: absolute;
  top: 12px; left: 12px; right: 12px; bottom: 12px;
  border-radius: 6px;
  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
  );
  z-index: 2;
}
#scanline-overlay.off { display: none; }

#red-stripe {
  height: 4px;
  background: linear-gradient(90deg, transparent, var(--sega-red), transparent);
  margin-top: 10px;
  border-radius: 2px;
}

/* Debug Panel */
#debug-panel {
  width: 320px;
  min-width: 280px;
  max-height: 620px;
  overflow-y: auto;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  font-size: 11px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
#debug-panel.hidden { display: none; }

.debug-section {
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}
.debug-section:last-child { border-bottom: none; }
.debug-section h3 {
  font-family: 'Press Start 2P', cursive;
  font-size: 8px;
  color: var(--sega-red);
  margin-bottom: 6px;
  letter-spacing: 1px;
}
.debug-section pre {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: #aaddaa;
  line-height: 1.5;
  white-space: pre;
}

.debug-bp-row {
  display: flex; gap: 4px; margin-bottom: 6px;
}
.debug-bp-row input {
  background: #0a0a18;
  border: 1px solid var(--border);
  color: var(--text-pri);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  padding: 3px 6px;
  width: 70px;
  border-radius: 3px;
}
.debug-bp-row button, .debug-controls button {
  background: var(--bg-mid);
  border: 1px solid var(--border);
  color: var(--text-pri);
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 3px;
  cursor: pointer;
  font-family: 'JetBrains Mono', monospace;
}
.debug-controls { display: flex; gap: 4px; }

#dbg-psg {
  display: flex; gap: 4px;
}
.psg-channel {
  flex: 1;
  background: #0a0a18;
  border-radius: 4px;
  padding: 4px;
  text-align: center;
}
.psg-channel canvas {
  width: 100%;
  height: 24px;
  display: block;
  margin-top: 2px;
}
.psg-channel .ch-label {
  font-size: 8px;
  color: var(--sega-blue);
}
.psg-channel .ch-info {
  font-size: 8px;
  color: #88aa88;
}

/* Controller */
#controller {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 40px;
  padding: 12px 20px;
  background: linear-gradient(145deg, #1c1c2e, #111122);
  border-radius: 12px;
  border: 1px solid var(--border);
  max-width: 700px;
  width: 100%;
}

/* D-Pad */
#dpad {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}
#dpad-mid {
  display: flex;
  align-items: center;
  gap: 0;
}
.dpad-btn {
  width: 42px; height: 42px;
  background: #222;
  border: 2px solid #333;
  color: #666;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.1s;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}
.dpad-btn:active, .dpad-btn.pressed {
  background: #444;
  color: #fff;
  border-color: var(--sega-blue);
}
#dpad-up { border-radius: 6px 6px 0 0; }
#dpad-down { border-radius: 0 0 6px 6px; }
#dpad-left { border-radius: 6px 0 0 6px; }
#dpad-right { border-radius: 0 6px 6px 0; }
#dpad-center {
  width: 42px; height: 42px;
  background: #1a1a1a;
  border: 2px solid #333;
}

/* Console buttons */
#console-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.console-btn {
  background: #2a2a2a;
  border: 1px solid #444;
  color: var(--text-sec);
  font-family: 'Press Start 2P', cursive;
  font-size: 7px;
  padding: 6px 14px;
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.1s;
  -webkit-user-select: none;
  user-select: none;
}
.console-btn:active { background: #444; color: #fff; }

/* Action buttons */
#action-buttons {
  display: flex;
  gap: 16px;
}
.action-btn {
  width: 52px; height: 52px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #c62828, #8b0000);
  border: 3px solid #5a0000;
  color: #ffcccc;
  font-family: 'Press Start 2P', cursive;
  font-size: 14px;
  cursor: pointer;
  box-shadow: 0 3px 8px rgba(0,0,0,0.5);
  transition: all 0.1s;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}
.action-btn:active, .action-btn.pressed {
  transform: scale(0.92);
  box-shadow: 0 1px 4px rgba(0,0,0,0.5);
  background: radial-gradient(circle at 30% 30%, #e53935, #b71c1c);
}

/* Key legend */
#key-legend {
  font-size: 9px;
  color: var(--text-dim);
  text-align: center;
  padding: 4px;
}

/* Status bar */
#status-bar {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
  font-size: 10px;
  color: var(--text-sec);
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 12px;
  width: 100%;
  max-width: 900px;
}

/* Footer */
#berrry-footer {
  text-align: center;
  padding: 16px;
  margin-top: 8px;
}
#berrry-footer a {
  color: var(--text-dim);
  font-size: 11px;
  text-decoration: none;
  transition: color 0.2s;
}
#berrry-footer a:hover { color: var(--sega-red); }

/* Responsive */
@media (max-width: 1100px) {
  #debug-panel { display: none !important; }
}

@media (max-width: 850px) {
  #screen {
    width: 512px;
    height: 384px;
  }
  #console-shell { padding: 10px; }
}

@media (max-width: 560px) {
  #screen {
    width: 320px;
    height: 240px;
  }
  #screen-bezel { padding: 6px; }
  #console-shell { padding: 8px; border-radius: 10px; }
  #sega-brand { font-size: 10px; letter-spacing: 2px; }
  #toolbar { font-size: 10px; padding: 4px 6px; }
  #toolbar button { font-size: 9px; padding: 4px 6px; }
  #controller { gap: 20px; padding: 10px; }
  .dpad-btn { width: 36px; height: 36px; font-size: 12px; }
  #dpad-center { width: 36px; height: 36px; }
  .action-btn { width: 44px; height: 44px; font-size: 12px; }
  #key-legend { display: none; }
}

/* Animations */
@keyframes powerOn {
  from { opacity: 0; filter: brightness(2); }
  to { opacity: 1; filter: brightness(1); }
}
.power-on-anim { animation: powerOn 0.5s ease-out; }

@keyframes cartInsert {
  0% { transform: translateY(-20px); opacity: 0; }
  100% { transform: translateY(0); opacity: 1; }
}
.cart-insert-anim { animation: cartInsert 0.3s ease-out; }