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

:root {
  --bg: #0a0a1a;
  --bg-lighter: #12122a;
  --bg-panel: #1a1a35;
  --green: #21C842;
  --cyan: #42EBF5;
  --red: #FC5554;
  --yellow: #D4C154;
  --magenta: #C95BBA;
  --text: #CCCCCC;
  --text-dim: #666688;
  --border: #2a2a4a;
}

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

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

#header {
  text-align: center;
  padding: 16px 12px 8px;
  background: linear-gradient(180deg, #0f0f2a 0%, var(--bg) 100%);
  border-bottom: 2px solid var(--green);
}

#header h1 {
  font-family: 'Press Start 2P', cursive;
  font-size: 20px;
  color: var(--cyan);
  text-shadow: 0 0 20px rgba(66, 235, 245, 0.4), 2px 2px 0 #000;
  letter-spacing: 2px;
}

.subtitle {
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 6px;
  font-family: 'Press Start 2P', cursive;
}

#main-layout {
  display: flex;
  flex: 1;
  justify-content: center;
  gap: 16px;
  padding: 16px;
}

#display-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

#crt-bezel {
  background: linear-gradient(145deg, #2a2a3a, #1a1a2a);
  border-radius: 20px;
  padding: 20px 24px 12px;
  box-shadow:
    0 0 0 3px #333,
    0 0 0 5px #111,
    inset 0 0 30px rgba(0,0,0,0.5),
    0 8px 32px rgba(0,0,0,0.8);
  position: relative;
}

#crt-screen {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: inset 0 0 40px rgba(0,0,0,0.6);
  background: #000;
  line-height: 0;
}

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

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

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

#crt-label {
  text-align: center;
  font-family: 'Press Start 2P', cursive;
  font-size: 9px;
  color: var(--text-dim);
  margin-top: 8px;
  letter-spacing: 3px;
}

/* Controls */
#controls {
  width: 100%;
  max-width: 820px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.control-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

button {
  font-family: 'Press Start 2P', cursive;
  font-size: 9px;
  padding: 8px 14px;
  border: 2px solid var(--border);
  border-radius: 6px;
  background: linear-gradient(180deg, #2a2a4a, #1a1a35);
  color: var(--text);
  cursor: pointer;
  box-shadow: 0 2px 0 #111, inset 0 1px 0 rgba(255,255,255,0.05);
  transition: all 0.1s;
  white-space: nowrap;
}

button:hover {
  border-color: var(--cyan);
  color: var(--cyan);
}

button:active {
  transform: translateY(1px);
  box-shadow: 0 1px 0 #111;
}

button.active, .speed-btn.active {
  border-color: var(--green);
  color: var(--green);
  background: linear-gradient(180deg, #1a3a1a, #1a2a1a);
}

.control-row label {
  font-size: 9px;
  font-family: 'Press Start 2P', cursive;
  color: var(--text-dim);
}

input[type="range"] {
  -webkit-appearance: none;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  outline: none;
  flex: 0 0 100px;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--cyan);
  cursor: pointer;
}

#speed-label, #volume-label {
  font-size: 9px;
  font-family: 'Press Start 2P', cursive;
  color: var(--yellow);
  min-width: 40px;
}

/* ROM Drop Zone */
#rom-drop-zone {
  width: 100%;
  max-width: 820px;
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}

#rom-drop-zone:hover, #rom-drop-zone.dragover {
  border-color: var(--green);
  background: rgba(33, 200, 66, 0.05);
}

.drop-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-family: 'Press Start 2P', cursive;
  font-size: 10px;
  color: var(--text-dim);
}

.drop-icon { font-size: 28px; }
.drop-sub { font-size: 8px; color: var(--text-dim); opacity: 0.6; }

/* Gamepad */
#gamepad {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 40px;
  padding: 16px;
  width: 100%;
  max-width: 500px;
}

#dpad {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}

.dpad-middle {
  display: flex;
  align-items: center;
  gap: 0;
}

.dpad-btn {
  width: 44px;
  height: 44px;
  font-size: 14px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  background: linear-gradient(180deg, #333, #222);
  border: 2px solid #444;
  font-family: sans-serif;
}

.dpad-btn:active, .dpad-btn.pressed {
  background: linear-gradient(180deg, #222, #333);
  border-color: var(--cyan);
  color: var(--cyan);
}

.dpad-center {
  width: 44px;
  height: 44px;
  background: #222;
  border: 2px solid #333;
}

.gamepad-pause {
  font-size: 7px;
  padding: 6px 12px;
  border-radius: 10px;
}

.action-btn {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  font-size: 14px;
  font-family: 'Press Start 2P', cursive;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn1 {
  background: linear-gradient(180deg, var(--red), #a33);
  border-color: #d44;
  color: #fff;
}

.btn2 {
  background: linear-gradient(180deg, #5455ED, #3335aa);
  border-color: #7D76FC;
  color: #fff;
}

.action-btn:active, .action-btn.pressed {
  transform: scale(0.92);
}

#action-buttons {
  display: flex;
  gap: 12px;
  align-items: center;
}

/* Debug Panel */
#debug-panel {
  width: 380px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  font-size: 11px;
}

#debug-panel.hidden { display: none; }

#debug-panel h3 {
  font-family: 'Press Start 2P', cursive;
  font-size: 11px;
  color: var(--cyan);
  margin-bottom: 10px;
}

#debug-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.debug-tab {
  font-size: 7px;
  padding: 5px 8px;
}

.debug-tab.active {
  border-color: var(--cyan);
  color: var(--cyan);
  background: rgba(66,235,245,0.1);
}

.debug-tab-content { display: none; }
.debug-tab-content.active { display: block; }

#cpu-registers {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  line-height: 1.6;
}

.reg-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.reg-pair {
  color: var(--text-dim);
}

.reg-pair .val {
  color: var(--green);
  font-weight: bold;
}

#cpu-flags {
  margin-top: 8px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.flag {
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: bold;
  background: #111;
  color: #444;
  border: 1px solid #333;
}

.flag.set {
  color: var(--green);
  border-color: var(--green);
  background: rgba(33,200,66,0.15);
  text-shadow: 0 0 6px var(--green);
}

#breakpoint-input {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

#breakpoint-input input {
  width: 60px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  background: #111;
  border: 1px solid var(--border);
  color: var(--green);
  padding: 4px 6px;
  border-radius: 4px;
}

#breakpoint-input label {
  font-size: 9px;
  font-family: 'Press Start 2P', cursive;
}

#breakpoint-input button {
  font-size: 7px;
  padding: 4px 8px;
}

#disassembly {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  line-height: 1.5;
  max-height: 400px;
  overflow-y: auto;
  background: #0a0a15;
  padding: 8px;
  border-radius: 6px;
}

.disasm-line {
  padding: 1px 4px;
  white-space: pre;
}

.disasm-line.current {
  background: rgba(66,235,245,0.15);
  color: var(--cyan);
  border-left: 3px solid var(--cyan);
}

.disasm-line.breakpoint {
  background: rgba(252,85,84,0.15);
  border-left: 3px solid var(--red);
}

#vdp-registers {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  line-height: 1.5;
  margin-bottom: 10px;
}

#vram-viewer {
  width: 100%;
  image-rendering: pixelated;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #000;
}

#memory-dump {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  line-height: 1.4;
  max-height: 400px;
  overflow-y: auto;
  background: #0a0a15;
  padding: 6px;
  border-radius: 6px;
  white-space: pre;
  color: var(--text-dim);
}

#mem-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}

#mem-controls input {
  width: 60px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  background: #111;
  border: 1px solid var(--border);
  color: var(--green);
  padding: 4px 6px;
  border-radius: 4px;
}

#mem-controls label {
  font-size: 9px;
  font-family: 'Press Start 2P', cursive;
}

#palette-view {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.palette-swatch {
  aspect-ratio: 1;
  border-radius: 6px;
  border: 2px solid var(--border);
  display: flex;
  align-items: end;
  justify-content: center;
  padding-bottom: 4px;
  font-size: 8px;
  font-family: 'JetBrains Mono', monospace;
  text-shadow: 0 0 4px #000, 1px 1px 0 #000;
  min-height: 50px;
}

/* Status Bar */
#status-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 8px 16px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  font-size: 9px;
  font-family: 'Press Start 2P', cursive;
  color: var(--text-dim);
  flex-wrap: wrap;
}

#status-bar a {
  color: var(--cyan);
  text-decoration: none;
}

#status-bar a:hover {
  text-decoration: underline;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.hidden { display: none; }

.modal-content {
  background: var(--bg-panel);
  border: 2px solid var(--cyan);
  border-radius: 16px;
  padding: 24px;
  max-width: 500px;
  width: 90%;
  position: relative;
  font-size: 12px;
  line-height: 1.6;
}

.modal-content h2 {
  font-family: 'Press Start 2P', cursive;
  font-size: 13px;
  color: var(--cyan);
  margin-bottom: 16px;
}

.modal-content h3 {
  font-family: 'Press Start 2P', cursive;
  font-size: 10px;
  color: var(--green);
  margin: 12px 0 6px;
}

.modal-content ul {
  padding-left: 20px;
}

.modal-content li { margin: 4px 0; }

.fun-fact {
  margin-top: 12px;
  padding: 10px;
  background: rgba(66,235,245,0.1);
  border-left: 3px solid var(--cyan);
  border-radius: 4px;
}

.credits {
  margin-top: 12px;
  color: var(--text-dim);
  font-style: italic;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 14px;
  font-size: 16px;
  font-family: sans-serif;
  background: none;
  border: none;
  color: var(--text);
  box-shadow: none;
  padding: 4px 8px;
}

/* Responsive */
@media (max-width: 900px) {
  #canvas {
    width: 100%;
    height: auto;
    max-width: 512px;
  }
  
  #crt-bezel {
    padding: 12px 14px 8px;
    border-radius: 14px;
  }

  #main-layout {
    flex-direction: column;
    align-items: center;
  }

  #debug-panel {
    width: 100%;
    max-width: 520px;
    max-height: 50vh;
  }

  #header h1 { font-size: 14px; }
  .subtitle { font-size: 7px; }
}

@media (max-width: 550px) {
  #canvas {
    width: 100%;
    max-width: 100%;
  }

  #crt-bezel {
    padding: 8px 8px 6px;
    border-radius: 10px;
  }

  .control-row { gap: 4px; }
  button { padding: 6px 8px; font-size: 7px; }
}

/* Scrollbar styling */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--cyan); }