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

:root {
  --bg-deep: #0a0a1a;
  --bg-panel: #12122a;
  --bg-surface: #1a1a3a;
  --border: #2a2a5a;
  --accent-cyan: #00e5cc;
  --accent-blue: #4488ff;
  --accent-yellow: #ffe066;
  --text: #d0d0e0;
  --text-dim: #6a6a8a;
  --bezel-dark: #2a2a2a;
  --bezel-mid: #3a3a3a;
  --key-brown: #c4a67a;
  --key-dark: #8a7050;
  --red: #ff4444;
  --green: #44ff66;
}

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

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

/* Header */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 15px;
  background: linear-gradient(135deg, var(--bg-panel), var(--bg-surface));
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 10px;
}
header h1 {
  font-family: 'Press Start 2P', monospace;
  font-size: 16px;
  color: var(--accent-cyan);
  text-shadow: 0 0 10px rgba(0,229,204,0.4);
}
.subtitle {
  font-size: 14px;
  color: var(--text-dim);
  margin-top: 4px;
}
.status-leds {
  display: flex;
  gap: 12px;
  font-size: 13px;
}
.led {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--text-dim);
}
.led-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  background: #333;
  box-shadow: 0 0 2px #111;
}
.led-dot.on {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
}
.led-dot.off {
  background: #552222;
}

/* Main Layout */
#main-content {
  display: flex;
  gap: 12px;
  margin-bottom: 10px;
}

/* CRT Screen */
#screen-area {
  flex: 1;
}
#crt-bezel {
  background: linear-gradient(145deg, #3a3a3a, #1a1a1a);
  border-radius: 20px;
  padding: 20px 24px 12px;
  box-shadow: 
    inset 0 2px 4px rgba(255,255,255,0.05),
    0 8px 32px rgba(0,0,0,0.8),
    0 0 0 2px #444;
  position: relative;
}
#crt-screen {
  position: relative;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  border: 3px solid #111;
  box-shadow: inset 0 0 40px rgba(0,0,0,0.8);
  aspect-ratio: 4/3;
}
#canvas {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
}
#scanlines {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 1px,
    rgba(0,0,0,0.15) 1px,
    rgba(0,0,0,0.15) 2px
  );
  pointer-events: none;
}
#bezel-label {
  text-align: center;
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  color: #888;
  margin-top: 8px;
  letter-spacing: 2px;
}

#status-bar {
  display: flex;
  justify-content: space-between;
  padding: 6px 10px;
  font-size: 13px;
  color: var(--text-dim);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  margin-top: 6px;
}

/* ROM Panel */
#rom-panel {
  width: 260px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  flex-shrink: 0;
}
#rom-panel h3 {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  color: var(--accent-cyan);
  margin-bottom: 10px;
}
.rom-slot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 6px;
}
.rom-icon {
  font-size: 18px;
  flex-shrink: 0;
}
.rom-info strong {
  display: block;
  font-size: 13px;
  color: var(--text);
}
.rom-info small {
  font-size: 11px;
  color: var(--text-dim);
}
#rom-message {
  text-align: center;
  color: var(--accent-yellow);
  font-size: 13px;
  margin-top: 10px;
  animation: blink 1.5s ease-in-out infinite;
}
@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Controls */
#controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 10px;
}
.ctrl-btn {
  font-family: 'VT323', monospace;
  font-size: 14px;
  padding: 8px 12px;
  background: linear-gradient(180deg, var(--bg-surface), var(--bg-deep));
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.1s;
  white-space: nowrap;
}
.ctrl-btn:hover {
  background: linear-gradient(180deg, #2a2a5a, var(--bg-surface));
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}
.ctrl-btn:active {
  transform: translateY(1px);
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.5);
}
.ctrl-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.power-btn {
  background: linear-gradient(180deg, #4a1515, #2a0808);
  border-color: var(--red);
  color: var(--red);
}
.power-btn:hover {
  background: linear-gradient(180deg, #6a2222, #4a1515);
  color: #ff6666;
}
.power-btn.on {
  background: linear-gradient(180deg, #154a15, #082a08);
  border-color: var(--green);
  color: var(--green);
  box-shadow: 0 0 8px rgba(68,255,102,0.3);
}

/* Virtual Keyboard */
#virtual-keyboard {
  padding: 10px;
  background: linear-gradient(145deg, #a08060, #8a6a4a);
  border: 2px solid #6a5030;
  border-radius: 10px;
  margin-bottom: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}
#virtual-keyboard .kb-row {
  display: flex;
  gap: 3px;
  margin-bottom: 3px;
  justify-content: center;
}
.vk-key {
  font-family: 'VT323', monospace;
  font-size: 13px;
  min-width: 32px;
  height: 28px;
  background: linear-gradient(180deg, #e8d5b5, #c4a67a);
  color: #2a1a0a;
  border: 1px solid #8a7050;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  box-shadow: 0 2px 0 #8a7050;
  transition: all 0.05s;
  user-select: none;
}
.vk-key:active, .vk-key.pressed {
  transform: translateY(2px);
  box-shadow: none;
  background: linear-gradient(180deg, #c4a67a, #a08060);
}
.vk-key.special {
  background: linear-gradient(180deg, #888, #666);
  color: #eee;
  border-color: #555;
  box-shadow: 0 2px 0 #444;
}
.vk-key.restore-key {
  background: linear-gradient(180deg, #cc4444, #993333);
  color: #fff;
  border-color: #772222;
  box-shadow: 0 2px 0 #661111;
}
.vk-key.wide {
  min-width: 48px;
}
.vk-key.wider {
  min-width: 64px;
}
.vk-key.space-key {
  min-width: 200px;
}

/* Debug Panel */
#debug-panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.debug-section h4 {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: var(--accent-cyan);
  margin-bottom: 6px;
}
#debug-regs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 15px;
  color: var(--accent-yellow);
  font-family: 'VT323', monospace;
}
#debug-flags {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}
.flag {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: bold;
  border-radius: 3px;
  background: #1a4a1a;
  color: var(--green);
  border: 1px solid #2a6a2a;
}
.flag.off {
  background: #3a1a1a;
  color: #884444;
  border-color: #552222;
}
.flag.dim {
  background: #2a2a2a;
  color: #555;
  border-color: #333;
}
.mono-scroll {
  font-family: 'VT323', monospace;
  font-size: 13px;
  color: var(--accent-cyan);
  background: #080818;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px;
  height: 120px;
  overflow-y: auto;
  white-space: pre;
  line-height: 1.4;
}
.debug-controls {
  grid-column: 1 / -1;
  display: flex;
  gap: 6px;
  align-items: center;
}
.debug-mem-controls {
  display: flex;
  gap: 4px;
  align-items: center;
  margin-bottom: 4px;
  font-size: 13px;
}
.debug-mem-controls input {
  width: 60px;
  font-family: 'VT323', monospace;
  font-size: 14px;
  background: #080818;
  color: var(--accent-cyan);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 2px 4px;
  text-transform: uppercase;
}
.small-btn {
  font-family: 'VT323', monospace;
  font-size: 13px;
  padding: 4px 10px;
  background: var(--bg-surface);
  color: var(--accent-cyan);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
}
.small-btn:hover {
  border-color: var(--accent-cyan);
}

/* Drop Overlay */
#drop-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,10,30,0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.drop-content {
  text-align: center;
  font-family: 'Press Start 2P', monospace;
  font-size: 16px;
  color: var(--accent-cyan);
  border: 3px dashed var(--accent-cyan);
  padding: 60px;
  border-radius: 20px;
  animation: pulse-border 1s ease-in-out infinite;
}
.drop-icon {
  font-size: 60px;
  margin-bottom: 20px;
}
@keyframes pulse-border {
  0%, 100% { border-color: var(--accent-cyan); }
  50% { border-color: var(--accent-yellow); }
}

/* Help Overlay */
#help-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,5,20,0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}
.help-content {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  max-width: 700px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
}
.help-content h2 {
  font-family: 'Press Start 2P', monospace;
  font-size: 14px;
  color: var(--accent-cyan);
  margin-bottom: 16px;
}
.help-content h3 {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  color: var(--accent-yellow);
  margin: 12px 0 6px;
}
.help-content p {
  font-size: 15px;
  margin: 4px 0;
  color: var(--text);
}
.help-content code, .help-content kbd {
  background: var(--bg-surface);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 14px;
  border: 1px solid var(--border);
}
.help-sections {
  display: flex;
  gap: 20px;
}
.help-col { flex: 1; }
.close-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
}

/* Toasts */
#toast-container {
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.toast {
  background: var(--bg-surface);
  border: 1px solid var(--accent-cyan);
  border-radius: 6px;
  padding: 10px 16px;
  font-family: 'VT323', monospace;
  font-size: 15px;
  color: var(--accent-cyan);
  animation: toast-in 0.3s ease-out;
  max-width: 350px;
}
.toast.error {
  border-color: var(--red);
  color: var(--red);
}
@keyframes toast-in {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.hidden { display: none !important; }

/* Footer */
footer {
  text-align: center;
  padding: 12px;
  font-size: 13px;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
  margin-top: 10px;
}
footer a {
  color: var(--accent-cyan);
  text-decoration: none;
  margin-left: 12px;
}
footer a:hover {
  text-decoration: underline;
}

/* Responsive */
@media (max-width: 768px) {
  #main-content {
    flex-direction: column;
  }
  #rom-panel {
    width: 100%;
  }
  #controls {
    justify-content: center;
  }
  #debug-panel {
    grid-template-columns: 1fr;
  }
  .help-sections {
    flex-direction: column;
  }
  header {
    flex-direction: column;
    gap: 8px;
  }
  .vk-key {
    min-width: 24px;
    height: 24px;
    font-size: 11px;
  }
  .vk-key.space-key {
    min-width: 120px;
  }
}