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

:root {
  --bg: #0a0a1a;
  --panel-bg: #111128;
  --border-color: #2a2a4a;
  --text: #c0c0d0;
  --accent: #e0e020;
  --spec-blue: #0000D7;
  --spec-red: #D70000;
  --spec-magenta: #D700D7;
  --spec-green: #00D700;
  --spec-cyan: #00D7D7;
  --spec-yellow: #D7D700;
}

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

#app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

header {
  text-align: center;
  padding: 12px 0 6px;
}

header h1 {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(14px, 3vw, 22px);
  color: #fff;
  text-shadow: 0 0 20px rgba(0,215,215,0.4);
  letter-spacing: 2px;
}

.subtitle {
  font-size: clamp(8px, 1.5vw, 11px);
  color: #888;
  margin-top: 4px;
  font-family: 'JetBrains Mono', monospace;
}

.rainbow-bar {
  height: 4px;
  margin: 8px auto 0;
  width: min(400px, 80vw);
  background: linear-gradient(90deg,
    var(--spec-blue), var(--spec-red), var(--spec-magenta),
    var(--spec-green), var(--spec-cyan), var(--spec-yellow));
  border-radius: 2px;
}

#main-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

#screen-container {
  margin: 10px 0;
}

#crt-wrapper {
  position: relative;
  border: 3px solid #333;
  border-radius: 12px;
  overflow: hidden;
  box-shadow:
    0 0 30px rgba(0,215,215,0.15),
    inset 0 0 60px rgba(0,0,0,0.5);
  background: #000;
}

#screen {
  display: block;
  width: min(640px, 90vw);
  height: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

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

#controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  align-items: center;
  padding: 8px 12px;
  background: linear-gradient(180deg, #2a2a2a, #1a1a1a);
  border-radius: 8px;
  margin: 4px 0;
  width: min(640px, 90vw);
  border-top: 3px solid transparent;
  border-image: linear-gradient(90deg,
    var(--spec-blue), var(--spec-red), var(--spec-magenta),
    var(--spec-green), var(--spec-cyan), var(--spec-yellow)) 1;
}

.ctrl-group {
  display: flex;
  gap: 4px;
  align-items: center;
}

.ctrl-info {
  font-size: 10px;
  gap: 10px;
}

.ctrl-info span {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
}

#speed-indicator { color: var(--spec-green); }
#fps-display { color: var(--spec-cyan); }
#emu-status { color: var(--spec-yellow); }

button {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  padding: 6px 10px;
  background: #333;
  color: #ddd;
  border: 1px solid #555;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.1s;
  white-space: nowrap;
}

button:hover {
  background: #444;
  border-color: var(--spec-cyan);
  color: #fff;
}

button:active {
  background: #555;
  transform: scale(0.96);
}

#audio-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 11px;
  padding: 4px;
}

#audio-controls label { cursor: pointer; }

#audio-volume {
  width: 80px;
  accent-color: var(--spec-cyan);
}

#oscilloscope {
  background: #0a0a1a;
  border: 1px solid #333;
  border-radius: 3px;
}

#keyboard-container {
  margin: 10px 0;
  width: min(640px, 92vw);
  user-select: none;
  -webkit-user-select: none;
}

.kb-row {
  display: flex;
  justify-content: center;
  gap: 3px;
  margin-bottom: 3px;
}

.kb-key {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: clamp(36px, 8vw, 58px);
  height: clamp(36px, 7vw, 48px);
  background: linear-gradient(180deg, #3a3a3a, #222);
  border: 1px solid #555;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.05s;
  position: relative;
}

.kb-key:active, .kb-key.pressed {
  background: linear-gradient(180deg, #555, #444);
  border-color: var(--spec-cyan);
  transform: translateY(1px);
}

.kb-key .main-label {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(7px, 1.5vw, 10px);
  color: #fff;
}

.kb-key .keyword-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: clamp(5px, 1vw, 7px);
  color: #888;
  margin-top: 1px;
}

.kb-key.shift-key {
  width: clamp(54px, 12vw, 80px);
}

.kb-key.enter-key {
  width: clamp(54px, 12vw, 80px);
}

.kb-key.space-key {
  width: clamp(160px, 35vw, 260px);
}

#debug-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 320px;
  height: 100vh;
  background: rgba(10,10,26,0.97);
  border-left: 2px solid var(--border-color);
  padding: 12px;
  overflow-y: auto;
  z-index: 100;
  font-size: 11px;
  transition: transform 0.3s ease;
}

#debug-panel.hidden {
  transform: translateX(100%);
}

#debug-panel h3 {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  color: var(--spec-cyan);
  margin: 10px 0 4px;
  border-bottom: 1px solid #333;
  padding-bottom: 3px;
}

#registers, #flags, #cpu-info, #disassembly, #memory-view {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  line-height: 1.6;
  color: #aaa;
}

#disassembly {
  white-space: pre;
  font-size: 10px;
}

#memory-view {
  white-space: pre;
  font-size: 9px;
  overflow-x: auto;
}

#debug-panel input[type="text"] {
  background: #1a1a2e;
  border: 1px solid #444;
  color: var(--spec-green);
  padding: 3px 6px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  width: 100px;
  border-radius: 3px;
}

.flag-on { color: var(--spec-green); font-weight: bold; }
.flag-off { color: #555; }

.reg-pair {
  display: inline-block;
  margin-right: 12px;
}
.reg-name { color: var(--spec-yellow); }
.reg-val { color: var(--spec-green); }

footer {
  text-align: center;
  padding: 15px;
  margin-top: 10px;
}

footer a {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  text-decoration: none;
  background: linear-gradient(90deg,
    var(--spec-blue), var(--spec-red), var(--spec-magenta),
    var(--spec-green), var(--spec-cyan), var(--spec-yellow));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  opacity: 0.7;
  transition: opacity 0.2s;
}

footer a:hover { opacity: 1; }

@media (max-width: 600px) {
  #debug-panel { width: 100%; }
  .ctrl-info { display: none; }
}