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

:root {
  --bg: #0d0d0d;
  --bezel: #2a2a2a;
  --bezel-inner: #1a1a1a;
  --phosphor: #33ff33;
  --phosphor-dim: #0a5c0a;
  --screen-bg: #020802;
  --key-bg: #d8d0c0;
  --key-text: #1a1a1a;
  --key-special: #8b7d6b;
  --accent-green: #00cc00;
  --accent-red: #cc3333;
  --text: #c0c0c0;
  --text-dim: #666;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Mono', monospace;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 10px;
}

#emulator-container {
  max-width: 920px;
  width: 100%;
}

#top-bar {
  text-align: center;
  padding: 16px 0 8px;
}

#title {
  font-family: 'Press Start 2P', monospace;
  font-size: 18px;
  color: var(--phosphor);
  text-shadow: 0 0 10px var(--phosphor), 0 0 30px var(--phosphor-dim);
  letter-spacing: 3px;
}

#status-bar {
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  font-family: 'VT323', monospace;
  font-size: 18px;
}

#power-led {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #330000;
  border: 1px solid #550000;
  display: inline-block;
  transition: all 0.3s;
}

#power-led.on {
  background: #ff2222;
  box-shadow: 0 0 6px #ff2222, 0 0 12px #ff0000;
}

#status-text { color: #ffaa00; }
#ram-label { color: var(--text-dim); }

#monitor-bezel {
  background: linear-gradient(145deg, #3a3a3a, #222);
  border-radius: 20px;
  padding: 20px;
  margin: 12px auto;
  box-shadow: 0 4px 30px rgba(0,0,0,0.8), inset 0 1px 0 rgba(255,255,255,0.05);
  max-width: 720px;
}

#screen-wrapper {
  position: relative;
  background: var(--screen-bg);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: inset 0 0 60px rgba(0,0,0,0.9), 0 0 20px rgba(51,255,51,0.05);
  aspect-ratio: 640/400;
}

#screen {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
}

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

/* Controls Panel */
#controls-panel {
  max-width: 720px;
  margin: 0 auto;
  background: #161616;
  border-radius: 10px;
  overflow: hidden;
}

#controls-tabs {
  display: flex;
  background: #111;
  border-bottom: 1px solid #333;
  overflow-x: auto;
}

.tab-btn {
  flex: 1;
  min-width: 80px;
  padding: 10px 12px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: 'VT323', monospace;
  font-size: 16px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  color: var(--phosphor);
  border-bottom-color: var(--phosphor);
}

.tab-content { display: none; padding: 16px; }
.tab-content.active { display: block; }

/* ROM Dropzone */
#rom-dropzone {
  border: 2px dashed #444;
  border-radius: 8px;
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s;
  margin-bottom: 12px;
  position: relative;
}

#rom-dropzone:hover, #rom-dropzone.dragover {
  border-color: var(--phosphor);
}

#rom-dropzone p { font-family: 'VT323', monospace; font-size: 16px; }
#rom-dropzone .hint { font-size: 13px; color: var(--text-dim); margin-top: 4px; }
#rom-input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

#rom-checklist {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 16px;
  font-family: 'VT323', monospace;
  font-size: 14px;
}

.rom-item { display: flex; align-items: center; gap: 6px; }
.rom-item .icon { font-size: 14px; }
.rom-item.loaded .icon { color: var(--accent-green); }
.rom-item.missing .icon { color: var(--accent-red); }

/* Power Controls */
.power-controls {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.ctrl-btn {
  font-family: 'VT323', monospace;
  font-size: 18px;
  padding: 10px 20px;
  border: 1px solid #444;
  border-radius: 6px;
  background: #222;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
}
.ctrl-btn:hover { background: #333; }
.ctrl-btn.small-btn { font-size: 15px; padding: 6px 12px; }

.power-btn { border-color: var(--accent-green); color: var(--accent-green); }
.power-btn:hover { background: #0a2a0a; }
.reset-btn { border-color: #cc8800; color: #cc8800; }
.stop-btn { border-color: var(--accent-red); color: var(--accent-red); }

/* RAM Selector */
.ram-selector {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
}

.ram-option {
  font-family: 'VT323', monospace;
  font-size: 20px;
  cursor: pointer;
  padding: 8px 16px;
  border: 1px solid #444;
  border-radius: 6px;
  transition: all 0.15s;
}
.ram-option:has(input:checked) {
  border-color: var(--phosphor);
  color: var(--phosphor);
  background: #0a1a0a;
}
.ram-option input { display: none; }

/* Peripherals */
.periph-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
  font-size: 14px;
}
.periph-row label { min-width: 180px; font-family: 'VT323', monospace; font-size: 16px; }
.periph-row input[type="file"] { max-width: 200px; font-size: 12px; }
.file-info { color: var(--text-dim); font-size: 12px; }

/* Debug */
#debug-registers {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  margin-bottom: 8px;
}
#debug-registers b { color: var(--phosphor); margin-left: 2px; }
#dbg-flags { letter-spacing: 2px; color: #888; }
#debug-disasm { font-size: 13px; color: #aaa; margin-bottom: 8px; }
#debug-controls { display: flex; gap: 8px; margin-bottom: 10px; }

#memory-inspector {
  font-size: 13px;
}
#mem-addr {
  width: 50px;
  background: #111;
  border: 1px solid #444;
  color: var(--phosphor);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  padding: 3px 5px;
  border-radius: 3px;
}
#mem-dump {
  margin-top: 8px;
  background: #0a0a0a;
  padding: 8px;
  border-radius: 4px;
  font-size: 11px;
  color: var(--phosphor);
  overflow-x: auto;
  max-height: 200px;
  overflow-y: auto;
  white-space: pre;
  font-family: 'IBM Plex Mono', monospace;
}

/* Virtual Keyboard */
#virtual-keyboard {
  max-width: 720px;
  margin: 12px auto;
  background: #2a261e;
  border-radius: 10px;
  padding: 12px;
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.5);
}

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

.kb-key {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  background: var(--key-bg);
  color: var(--key-text);
  border: none;
  border-radius: 3px;
  padding: 6px 4px;
  min-width: 28px;
  min-height: 28px;
  cursor: pointer;
  box-shadow: 0 2px 0 #999, 0 3px 4px rgba(0,0,0,0.3);
  transition: all 0.05s;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.2;
  user-select: none;
}

.kb-key:active, .kb-key.pressed {
  transform: translateY(2px);
  box-shadow: 0 0 0 #999, 0 1px 2px rgba(0,0,0,0.3);
}

.kb-key.special {
  background: var(--key-special);
  color: #f0ead0;
  min-width: 42px;
}

.kb-key.wide { min-width: 56px; }
.kb-key.space { min-width: 160px; }
.kb-sep { width: 12px; }

.kb-numpad {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.kb-numrow {
  display: flex;
  gap: 3px;
}

/* Footer */
footer {
  text-align: center;
  padding: 16px;
  font-size: 13px;
}
footer a { color: var(--text-dim); text-decoration: none; }
footer a:hover { color: var(--phosphor); }

/* Responsive */
@media (max-width: 600px) {
  #title { font-size: 12px; letter-spacing: 1px; }
  #monitor-bezel { padding: 10px; border-radius: 12px; }
  .kb-key { min-width: 20px; min-height: 22px; font-size: 5px; padding: 3px 2px; }
  .kb-key.special { min-width: 30px; }
  .kb-key.wide { min-width: 38px; }
  .kb-key.space { min-width: 80px; }
  .kb-sep { width: 6px; }
  #rom-checklist { grid-template-columns: 1fr; }
  .periph-row label { min-width: auto; }
}