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

:root {
  --bg-dark: #0d0d1a;
  --bg-panel: #141428;
  --bg-section: #1a1a35;
  --amber: #FFB347;
  --amber-dim: #cc8a2e;
  --green: #00FF41;
  --green-dim: #00aa2a;
  --red: #ff4444;
  --cream: #e8dcc8;
  --cream-dark: #c4b8a4;
  --bezel: #2a2a2a;
  --bezel-light: #3a3a3a;
  --text: #d4d4d4;
  --text-dim: #888;
}

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

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

header {
  background: linear-gradient(180deg, #1a1a35 0%, #0d0d1a 100%);
  border-bottom: 2px solid var(--amber);
  padding: 12px 20px;
  position: relative;
}
header::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(0deg,transparent,transparent 2px,rgba(255,179,71,0.03) 2px,rgba(255,179,71,0.03) 4px);
  pointer-events: none;
}
.header-content {
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: 1600px;
  margin: 0 auto;
  position: relative;
  z-index: 1;
}
.header-content h1 {
  font-family: 'Press Start 2P', monospace;
  font-size: 16px;
  color: var(--amber);
  text-shadow: 0 0 10px rgba(255,179,71,0.5);
}
.tagline {
  font-family: 'VT323', monospace;
  font-size: 16px;
  color: var(--text-dim);
  margin-left: auto;
}
.power-led {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #333;
  border: 1px solid #555;
  transition: all 0.3s;
}
.power-led.on {
  background: #00ff41;
  box-shadow: 0 0 8px #00ff41, 0 0 16px rgba(0,255,65,0.4);
}

#main-layout {
  display: flex;
  flex: 1;
  max-width: 1600px;
  margin: 0 auto;
  width: 100%;
  padding: 12px;
  gap: 12px;
}

#left-panel {
  width: 240px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.panel-section {
  background: var(--bg-panel);
  border: 1px solid #2a2a40;
  border-radius: 8px;
  padding: 12px;
}
.panel-section h3 {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  color: var(--amber);
  margin-bottom: 10px;
  text-transform: uppercase;
}

#drop-zone {
  border: 2px dashed #444;
  border-radius: 8px;
  padding: 16px 8px;
  text-align: center;
  transition: all 0.3s;
  margin-bottom: 8px;
  cursor: pointer;
}
#drop-zone:hover, #drop-zone.dragover {
  border-color: var(--amber);
  background: rgba(255,179,71,0.05);
}
.cassette-icon { font-size: 28px; margin-bottom: 4px; }
#drop-zone p { font-family: 'VT323', monospace; font-size: 14px; color: var(--text-dim); }
#drop-zone small { font-size: 11px; color: #666; }

.retro-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  padding: 8px 12px;
  border: 2px solid var(--amber-dim);
  background: linear-gradient(180deg, #2a2a40, #1a1a30);
  color: var(--amber);
  border-radius: 4px;
  cursor: pointer;
  box-shadow: 0 3px 0 #111, 0 4px 8px rgba(0,0,0,0.3);
  transition: all 0.1s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.retro-btn:hover { background: linear-gradient(180deg, #3a3a50, #2a2a40); }
.retro-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #111; }
.retro-btn.reset { border-color: var(--red); color: var(--red); width: 100%; justify-content: center; margin-top: 4px; }
.retro-btn.default { font-size: 7px; width: 100%; justify-content: center; }
.retro-btn.small { font-size: 7px; padding: 6px 8px; }
.retro-btn.tiny { font-size: 7px; padding: 4px 6px; }
.btn-row { margin-bottom: 4px; }
.btn-row .retro-btn { width: 100%; justify-content: center; }

.rom-info { margin-top: 8px; font-size: 10px; background: #0a0a1a; border-radius: 4px; padding: 8px; }
.rom-detail { color: var(--green); margin-bottom: 2px; font-family: 'VT323', monospace; font-size: 13px; }
.rom-hex { font-size: 9px; color: var(--text-dim); word-break: break-all; margin-top: 4px; max-height: 60px; overflow-y: auto; }

.retro-select {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  padding: 6px 8px;
  background: #0a0a1a;
  color: var(--text);
  border: 1px solid #333;
  border-radius: 4px;
  width: 100%;
  cursor: pointer;
}
.retro-select.small { width: auto; }

.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 11px;
}
.control-row label { color: var(--text-dim); white-space: nowrap; }

.retro-slider {
  -webkit-appearance: none;
  height: 6px;
  background: #333;
  border-radius: 3px;
  flex: 1;
  max-width: 100px;
}
.retro-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: var(--amber);
  border-radius: 50%;
  cursor: pointer;
}

.switch { position: relative; width: 36px; height: 18px; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider-toggle {
  position: absolute; cursor: pointer; inset: 0;
  background: #333; border-radius: 18px; transition: 0.3s;
}
.slider-toggle::before {
  content: ''; position: absolute; width: 14px; height: 14px;
  left: 2px; bottom: 2px; background: #888;
  border-radius: 50%; transition: 0.3s;
}
.switch input:checked + .slider-toggle { background: var(--green-dim); }
.switch input:checked + .slider-toggle::before { transform: translateX(18px); background: var(--green); }

#center-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#screen-bezel {
  background: linear-gradient(145deg, #3a3a3a, #1a1a1a);
  border-radius: 16px;
  padding: 16px;
  box-shadow: inset 0 2px 4px rgba(255,255,255,0.05), 0 8px 32px rgba(0,0,0,0.6);
  border: 1px solid #444;
}
#screen-inner {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  background: #000;
  border: 2px solid #111;
}
#screen {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  width: 480px;
  height: 448px;
}
.crt-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(0deg,rgba(0,0,0,0.15) 0px,rgba(0,0,0,0.15) 1px,transparent 1px,transparent 3px);
  z-index: 2;
}
.crt-overlay.off { display: none; }
.phosphor-glow {
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: 8px;
  box-shadow: inset 0 0 60px rgba(0,255,65,0.03);
  z-index: 1;
}

#status-bar {
  display: flex;
  gap: 12px;
  padding: 6px 12px;
  font-family: 'VT323', monospace;
  font-size: 14px;
  color: var(--green);
  background: var(--bg-panel);
  border: 1px solid #2a2a40;
  border-radius: 0 0 8px 8px;
  width: 512px;
  justify-content: center;
  flex-wrap: wrap;
}
#status-bar span {
  padding: 0 6px;
  border-right: 1px solid #2a2a40;
}
#status-bar span:last-child { border-right: none; }

#keyboard-debug {
  display: flex;
  gap: 16px;
  padding: 4px 12px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: #888;
  background: #0a0a15;
  border: 1px solid #1a1a30;
  border-radius: 4px;
  margin: 4px 0;
}

#exec-controls {
  display: flex;
  gap: 8px;
  margin: 8px 0;
}
.exec-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid #444;
  background: linear-gradient(180deg, #2a2a40, #1a1a2a);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 0 #111;
  transition: all 0.1s;
}
.exec-btn:hover { background: linear-gradient(180deg, #3a3a50, #2a2a3a); }
.exec-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #111; }
.exec-btn.run { border-color: var(--green-dim); color: var(--green); }
.exec-btn.pause { border-color: var(--amber-dim); color: var(--amber); }
.exec-btn.reset-small { border-color: var(--red); color: var(--red); }

#keyboard {
  background: linear-gradient(180deg, #d4cbb8, #bfb5a0);
  border-radius: 12px;
  padding: 12px 16px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.3);
  border: 1px solid #a09880;
  margin-top: 8px;
  max-width: 580px;
}
.kb-row {
  display: flex;
  justify-content: center;
  gap: 3px;
  margin-bottom: 3px;
}
.kb-key {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  min-width: 34px;
  height: 32px;
  background: linear-gradient(180deg, #f0e8d8, #ddd4c0);
  border: 1px solid #b0a890;
  border-radius: 4px;
  color: #333;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 0 #a09880, 0 3px 4px rgba(0,0,0,0.2);
  transition: all 0.05s;
  user-select: none;
  padding: 0 4px;
  position: relative;
}
.kb-key:hover {
  background: linear-gradient(180deg, #fff8e8, #f0e8d0);
}
.kb-key:active, .kb-key.pressed {
  transform: translateY(2px);
  box-shadow: 0 0 0 #a09880;
  background: linear-gradient(180deg, #ffe8a0, #ffd870);
}
.kb-key.wide { min-width: 52px; }
.kb-key.wider { min-width: 70px; }
.kb-key.space { min-width: 180px; }
.kb-key .mod-led {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #888;
}
.kb-key .mod-led.active {
  background: var(--green);
  box-shadow: 0 0 4px var(--green);
}

#right-panel {
  width: 260px;
  flex-shrink: 0;
}
.debug-toggle { width: 100%; margin-bottom: 8px; justify-content: center; }
.debug-panel {
  background: var(--bg-panel);
  border: 1px solid #2a2a40;
  border-radius: 8px;
  padding: 8px;
  max-height: calc(100vh - 140px);
  overflow-y: auto;
}
.debug-section {
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid #1a1a30;
}
.debug-section:last-child { border-bottom: none; }
.debug-section h4 {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  color: var(--amber);
  margin-bottom: 6px;
}
.reg-display {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--green);
  background: #0a0a12;
  padding: 6px;
  border-radius: 4px;
  line-height: 1.6;
  white-space: pre;
}
.reg-display.small { font-size: 9px; line-height: 1.4; }
.flag-display {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: var(--green);
  background: #0a0a12;
  padding: 6px;
  border-radius: 4px;
  display: flex;
  gap: 4px;
}
.flag-display .flag-bit {
  width: 18px; height: 18px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid #333; border-radius: 2px;
}
.flag-display .flag-bit.set { background: var(--green-dim); color: #fff; }
.disasm-view {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--green);
  background: #0a0a12;
  padding: 6px;
  border-radius: 4px;
  line-height: 1.5;
  max-height: 180px;
  overflow-y: auto;
}
.disasm-view .current { color: var(--amber); font-weight: bold; }
.mem-controls { display: flex; gap: 4px; margin-bottom: 4px; }
.retro-input {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  padding: 4px 6px;
  background: #0a0a12;
  color: var(--green);
  border: 1px solid #333;
  border-radius: 3px;
  width: 80px;
}
.mem-dump {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  color: var(--green);
  background: #0a0a12;
  padding: 6px;
  border-radius: 4px;
  line-height: 1.4;
  max-height: 150px;
  overflow-y: auto;
  white-space: pre;
}
.bp-status { font-family: 'VT323', monospace; font-size: 13px; color: var(--red); margin-top: 4px; }
.console-log {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  color: var(--green);
  background: #0a0a12;
  padding: 6px;
  border-radius: 4px;
  max-height: 100px;
  overflow-y: auto;
  line-height: 1.4;
}

footer {
  background: var(--bg-panel);
  border-top: 1px solid #2a2a40;
  padding: 12px;
  text-align: center;
}
.footer-content { display: flex; flex-direction: column; gap: 4px; align-items: center; }
.footer-content span { font-family: 'VT323', monospace; font-size: 16px; color: var(--text-dim); }
.footer-content a { color: var(--amber); text-decoration: none; }
.footer-content a:hover { text-decoration: underline; }
.footer-content small { font-size: 11px; color: #555; font-style: italic; }

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: #0a0a12; }
::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #555; }

@media (max-width: 1100px) {
  #main-layout { flex-direction: column; align-items: center; }
  #left-panel { width: 100%; max-width: 580px; flex-direction: row; flex-wrap: wrap; }
  #left-panel .panel-section { flex: 1; min-width: 200px; }
  #right-panel { width: 100%; max-width: 580px; }
  .tagline { display: none; }
}
@media (max-width: 600px) {
  #screen { width: 320px; height: 298px; }
  #status-bar { width: 352px; }
  .kb-key { min-width: 24px; height: 26px; font-size: 5px; }
  .kb-key.wide { min-width: 36px; }
  .kb-key.wider { min-width: 48px; }
  .kb-key.space { min-width: 120px; }
  #keyboard { padding: 8px; }
  .header-content h1 { font-size: 11px; }
}