* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg-dark: #1a1a1a;
  --console-body: #2D2D2D;
  --console-accent: #444;
  --console-highlight: #555;
  --lcd-bg: #8a9c3a;
  --lcd-shade0: #9BBC0F;
  --lcd-shade1: #8BAC0F;
  --lcd-shade2: #306230;
  --lcd-shade3: #0F380F;
  --neon-green: #00ff41;
  --amber: #ffb347;
  --debug-bg: #0d0d1a;
  --debug-text: #00ff41;
  --panel-bg: #111122;
}

html, body {
  height: 100%;
  overflow-x: hidden;
  font-family: 'Share Tech Mono', monospace;
}

body {
  background: var(--bg-dark);
  background-image: 
    radial-gradient(ellipse at 50% 0%, #2a2015 0%, transparent 60%),
    repeating-linear-gradient(
      90deg,
      #1a1510 0px, #1a1510 2px,
      #1d1812 2px, #1d1812 4px
    );
  color: #ccc;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100vh;
}

#app-container {
  width: 100%;
  max-width: 1200px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px;
}

/* Control Bar */
#control-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: linear-gradient(180deg, #333 0%, #222 100%);
  border-radius: 8px 8px 0 0;
  border: 1px solid #444;
  border-bottom: none;
  width: 100%;
  max-width: 760px;
  flex-wrap: wrap;
  justify-content: center;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

#power-switch {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}

.power-track {
  width: 40px;
  height: 20px;
  background: #111;
  border-radius: 10px;
  border: 2px solid #555;
  position: relative;
  transition: background 0.3s;
}

.power-knob {
  width: 16px;
  height: 16px;
  background: linear-gradient(180deg, #888, #555);
  border-radius: 50%;
  position: absolute;
  top: 0;
  left: 0;
  transition: left 0.2s;
  box-shadow: 0 0 4px rgba(0,0,0,0.5);
}

#power-switch.power-on .power-track {
  background: #1a3a1a;
  border-color: var(--neon-green);
  box-shadow: 0 0 8px rgba(0,255,65,0.3);
}

#power-switch.power-on .power-knob {
  left: 20px;
  background: linear-gradient(180deg, var(--neon-green), #00aa2a);
}

.power-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: #888;
}

.speed-btn, .turbo-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  padding: 4px 8px;
  background: #333;
  color: #888;
  border: 1px solid #555;
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.15s;
}

.speed-btn.active {
  background: #1a3a1a;
  color: var(--neon-green);
  border-color: var(--neon-green);
  box-shadow: 0 0 6px rgba(0,255,65,0.2);
}

.turbo-btn.active {
  background: #3a1a1a;
  color: #ff4444;
  border-color: #ff4444;
  box-shadow: 0 0 6px rgba(255,68,68,0.2);
  animation: turbo-pulse 0.5s infinite;
}

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

.ctrl-btn {
  font-size: 12px;
  padding: 4px 8px;
  background: #333;
  color: #aaa;
  border: 1px solid #555;
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: 'Share Tech Mono', monospace;
}

.ctrl-btn:hover {
  background: #444;
  color: #fff;
}

.ctrl-btn.active {
  background: #1a3a1a;
  color: var(--neon-green);
  border-color: var(--neon-green);
}

.reset-pin {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  font-size: 8px;
  padding: 0;
  background: #222;
  border: 2px solid #444;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.5);
}

.volume-group {
  gap: 4px;
}

.vol-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  color: #888;
}

.vol-slider {
  width: 60px;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: #333;
  border-radius: 3px;
  outline: none;
}

.vol-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: linear-gradient(180deg, #888, #555);
  border-radius: 50%;
  cursor: pointer;
  border: 1px solid #666;
}

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

/* Panels */
.panel {
  width: 280px;
  background: var(--panel-bg);
  border: 1px solid #333;
  border-radius: 6px;
  overflow: hidden;
  flex-shrink: 0;
}

.panel.hidden {
  display: none;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  background: #1a1a2e;
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: var(--neon-green);
  border-bottom: 1px solid #333;
}

.panel-close {
  background: none;
  border: none;
  color: #666;
  font-size: 16px;
  cursor: pointer;
}

.panel-close:hover {
  color: #ff4444;
}

/* Debug Panel */
.debug-content {
  padding: 8px;
  font-family: 'Fira Code', monospace;
  font-size: 11px;
  color: var(--debug-text);
  max-height: 600px;
  overflow-y: auto;
}

.reg-title {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  color: var(--amber);
  margin-bottom: 4px;
  margin-top: 8px;
  border-bottom: 1px solid #333;
  padding-bottom: 2px;
}

.reg-title:first-child {
  margin-top: 0;
}

.reg-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}

.reg {
  display: flex;
  justify-content: space-between;
  background: #0a0a15;
  padding: 2px 6px;
  border-radius: 2px;
  border: 1px solid #222;
}

.reg-wide {
  grid-column: span 3;
}

.reg-name {
  color: #888;
}

.reg-val {
  color: var(--neon-green);
}

.flags-display {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  align-items: center;
}

.flag-title {
  font-size: 9px;
  color: #888;
}

.flag {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0a0a15;
  border: 1px solid #333;
  border-radius: 2px;
  font-size: 9px;
  color: #555;
}

.flag.set {
  color: var(--neon-green);
  border-color: var(--neon-green);
  background: #0a1a0a;
  text-shadow: 0 0 4px var(--neon-green);
}

.flag.dim {
  color: #333;
}

.disasm-lines {
  background: #0a0a15;
  border: 1px solid #222;
  border-radius: 2px;
  padding: 4px;
  max-height: 120px;
  overflow-y: auto;
  font-size: 10px;
  line-height: 1.5;
}

.disasm-line {
  white-space: nowrap;
}

.disasm-line.current {
  background: #1a2a1a;
  color: #fff;
}

.debug-controls {
  display: flex;
  gap: 4px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.dbg-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  padding: 4px 8px;
  background: #1a1a2e;
  color: var(--neon-green);
  border: 1px solid #333;
  border-radius: 3px;
  cursor: pointer;
}

.dbg-btn:hover {
  background: #2a2a4e;
}

.bp-input {
  display: flex;
  gap: 4px;
}

.bp-input input, .mem-nav input {
  font-family: 'Fira Code', monospace;
  font-size: 10px;
  width: 60px;
  padding: 3px 6px;
  background: #0a0a15;
  color: var(--neon-green);
  border: 1px solid #333;
  border-radius: 2px;
  outline: none;
}

.mem-nav {
  display: flex;
  gap: 4px;
  margin-bottom: 4px;
}

.mem-dump {
  background: #0a0a15;
  border: 1px solid #222;
  border-radius: 2px;
  padding: 4px;
  font-size: 9px;
  line-height: 1.4;
  max-height: 140px;
  overflow-y: auto;
  white-space: pre;
  color: var(--neon-green);
}

.memory-viewer {
  margin-top: 4px;
}

/* Console Body */
#console-body {
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Cartridge Slot */
#cart-slot {
  width: 100%;
  max-width: 520px;
  background: linear-gradient(180deg, #222, #2a2a2a);
  border: 1px solid #444;
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  padding: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  overflow: hidden;
}

#cart-indicator {
  position: absolute;
  top: -2px;
  left: 50%;
  transform: translateX(-50%);
}

#cart-indicator .cart-tab {
  width: 80px;
  height: 14px;
  background: linear-gradient(180deg, #666, #444);
  border-radius: 0 0 4px 4px;
  border: 1px solid #777;
  border-top: none;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
  animation: cart-insert 0.4s ease-out;
}

@keyframes cart-insert {
  from { transform: translateY(-20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

#cart-label {
  cursor: pointer;
  padding: 6px 20px;
  background: linear-gradient(180deg, #1a1a1a, #111);
  border: 2px dashed #555;
  border-radius: 4px;
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: #888;
  transition: all 0.2s;
  text-align: center;
}

#cart-label:hover {
  border-color: var(--amber);
  color: var(--amber);
  background: #1a1510;
}

#rom-info {
  font-family: 'Share Tech Mono', monospace;
  font-size: 10px;
  color: #888;
  margin-top: 4px;
}

#rom-info.hidden {
  display: none;
}

/* Console Shell */
#console-shell {
  background: linear-gradient(180deg, #3a3a3a 0%, var(--console-body) 10%, #252525 100%);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 
    0 8px 32px rgba(0,0,0,0.6),
    inset 0 1px 0 rgba(255,255,255,0.05),
    inset 0 -2px 0 rgba(0,0,0,0.3);
  width: 100%;
  max-width: 520px;
  border: 1px solid #444;
}

.console-logo {
  text-align: center;
  font-family: 'Press Start 2P', monospace;
  font-size: 12px;
  color: #555;
  letter-spacing: 6px;
  margin-bottom: 12px;
  text-shadow: 0 1px 0 #222, 0 -1px 0 #444;
}

/* Screen */
#screen-bezel {
  background: #1a1a1a;
  border-radius: 6px;
  padding: 12px;
  margin: 0 auto;
  width: fit-content;
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.8), 0 1px 0 rgba(255,255,255,0.05);
  border: 2px solid #333;
}

#screen-wrapper {
  position: relative;
  width: 480px;
  height: 480px;
  background: var(--lcd-shade0);
  border-radius: 2px;
  overflow: hidden;
  image-rendering: pixelated;
}

#lcd-canvas {
  width: 480px;
  height: 480px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
}

#scanline-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 480px;
  height: 480px;
  pointer-events: none;
  opacity: 0.08;
}

#power-off-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #0a0a0a;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  color: #333;
  transition: opacity 0.8s;
}

#power-off-overlay.off {
  opacity: 0;
  pointer-events: none;
}

/* Gamepad */
#gamepad-area {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 20px;
  padding: 0 10px;
}

/* D-Pad */
#dpad-container {
  flex-shrink: 0;
}

.dpad {
  display: grid;
  grid-template-columns: 44px 44px 44px;
  grid-template-rows: 44px 44px 44px;
  gap: 0;
}

.dpad-btn {
  background: #1a1a1a;
  border: 1px solid #444;
  color: #888;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.08s;
  user-select: none;
  -webkit-user-select: none;
}

.dpad-btn:active, .dpad-btn.pressed {
  background: #333;
  color: #fff;
  transform: scale(0.95);
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.5);
}

.dpad-up { border-radius: 6px 6px 0 0; grid-column: 2; grid-row: 1; }
.dpad-left { border-radius: 6px 0 0 6px; grid-column: 1; grid-row: 2; }
.dpad-center { background: #222; grid-column: 2; grid-row: 2; border: 1px solid #333; }
.dpad-right { border-radius: 0 6px 6px 0; grid-column: 3; grid-row: 2; }
.dpad-down { border-radius: 0 0 6px 6px; grid-column: 2; grid-row: 3; }

#btn-mid {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
}

.sys-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 6px;
  padding: 6px 14px;
  background: #333;
  color: #888;
  border: 1px solid #555;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.08s;
  user-select: none;
  -webkit-user-select: none;
}

.sys-btn:active, .sys-btn.pressed {
  background: #555;
  color: #fff;
  transform: scale(0.95);
}

#ab-container {
  display: flex;
  gap: 12px;
  flex-shrink: 0;
}

.action-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(180deg, #8B0000, #5a0000);
  color: #ddd;
  font-family: 'Press Start 2P', monospace;
  font-size: 12px;
  border: 2px solid #aa2222;
  cursor: pointer;
  box-shadow: 0 3px 6px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.1);
  transition: all 0.08s;
  user-select: none;
  -webkit-user-select: none;
}

.action-btn:active, .action-btn.pressed {
  transform: translateY(2px);
  box-shadow: 0 1px 2px rgba(0,0,0,0.4), inset 0 2px 4px rgba(0,0,0,0.3);
  background: linear-gradient(180deg, #6a0000, #4a0000);
}

/* Audio Panel */
.audio-content {
  padding: 8px;
}

.audio-channel {
  margin-bottom: 8px;
  background: #0a0a15;
  border: 1px solid #222;
  border-radius: 4px;
  padding: 6px;
}

.ch-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  color: var(--neon-green);
  margin-bottom: 4px;
}

.ch-mute {
  background: none;
  border: none;
  font-size: 14px;
  cursor: pointer;
  opacity: 0.8;
}

.ch-mute.muted {
  opacity: 0.3;
}

.wave-canvas {
  width: 100%;
  height: 60px;
  background: #050510;
  border-radius: 2px;
  display: block;
}

.ch-info {
  display: flex;
  justify-content: space-between;
  font-family: 'Fira Code', monospace;
  font-size: 9px;
  color: #666;
  margin-top: 4px;
}

/* Status Bar */
#status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  max-width: 760px;
  padding: 6px 16px;
  background: linear-gradient(180deg, #222, #1a1a1a);
  border-radius: 0 0 8px 8px;
  border: 1px solid #333;
  border-top: none;
  font-size: 10px;
}

.status-left, .status-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.status-tag {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  padding: 2px 8px;
  border-radius: 3px;
  background: #333;
  color: #888;
}

.status-tag.running {
  background: #1a3a1a;
  color: var(--neon-green);
}

.status-tag.paused {
  background: #3a3a1a;
  color: var(--amber);
}

.sv-wordmark {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  color: #444;
  letter-spacing: 2px;
}

.remix-link {
  font-size: 9px;
  color: #555;
  text-decoration: none;
}

.remix-link:hover {
  color: var(--amber);
}

/* Drop Overlay */
#drop-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

#drop-overlay.hidden {
  display: none;
}

.drop-content {
  text-align: center;
  color: var(--neon-green);
  font-family: 'Press Start 2P', monospace;
  font-size: 14px;
  border: 3px dashed var(--neon-green);
  padding: 60px;
  border-radius: 12px;
  animation: drop-pulse 1s infinite;
}

.drop-cart-icon {
  font-size: 60px;
  margin-bottom: 20px;
}

@keyframes drop-pulse {
  0%, 100% { border-color: var(--neon-green); }
  50% { border-color: transparent; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: #111; }
::-webkit-scrollbar-thumb { background: #444; border-radius: 2px; }

/* Responsive */
@media (max-width: 600px) {
  #screen-wrapper, #lcd-canvas, #scanline-overlay {
    width: 320px;
    height: 320px;
  }
  
  #console-shell {
    padding: 10px;
  }
  
  .console-logo {
    font-size: 9px;
    letter-spacing: 3px;
  }
  
  .panel {
    width: 100%;
    position: fixed;
    bottom: 0;
    left: 0;
    z-index: 500;
    border-radius: 8px 8px 0 0;
    max-height: 50vh;
    overflow-y: auto;
  }
  
  #main-area {
    flex-direction: column;
    align-items: center;
  }
  
  #control-bar {
    font-size: 9px;
  }
  
  .dpad {
    grid-template-columns: 38px 38px 38px;
    grid-template-rows: 38px 38px 38px;
  }
  
  .action-btn {
    width: 46px;
    height: 46px;
    font-size: 10px;
  }
}

@media (max-width: 400px) {
  #screen-wrapper, #lcd-canvas, #scanline-overlay {
    width: 280px;
    height: 280px;
  }
}