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

:root {
  --phosphor: #33FF33;
  --phosphor-dim: #1a8a1a;
  --phosphor-glow: rgba(51, 255, 51, 0.3);
  --bezel-dark: #1a1a1a;
  --bezel-mid: #2a2a2a;
  --keyboard-bg: #c4a882;
  --key-bg: #e8e0d0;
  --key-special: #d0c8b8;
  --key-break: #cc3333;
  --key-text: #333;
  --panel-bg: #1e1e1e;
  --panel-border: #3a3a3a;
  --amber: #ffaa00;
  --led-green: #33ff33;
  --led-red: #ff3333;
  --led-off: #444;
  --body-bg: #111;
}

html, body {
  background: var(--body-bg);
  color: #ccc;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  overflow-x: hidden;
}

body::before {
  content: '';
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: 
    radial-gradient(ellipse at 30% 20%, rgba(50,40,20,0.15), transparent 60%),
    repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(255,255,255,0.008) 2px, rgba(255,255,255,0.008) 4px);
  pointer-events: none;
  z-index: 0;
}

#emulator-container {
  position: relative;
  z-index: 1;
  max-width: 780px;
  margin: 0 auto;
  padding: 10px;
}

/* Control Panel */
#control-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(180deg, #2c2c2c, #1e1e1e);
  border: 1px solid #3a3a3a;
  border-radius: 6px 6px 0 0;
  padding: 8px 14px;
  gap: 8px;
}

.brand-label {
  font-family: 'VT323', monospace;
  font-size: 20px;
  color: var(--amber);
  letter-spacing: 2px;
}

.model-label {
  display: block;
  font-size: 10px;
  color: #888;
  letter-spacing: 1px;
}

.panel-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.ctrl-btn {
  background: linear-gradient(180deg, #444, #333);
  color: #ddd;
  border: 1px solid #555;
  border-radius: 4px;
  padding: 4px 10px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
}
.ctrl-btn:hover { background: linear-gradient(180deg, #555, #444); }
.ctrl-btn:active { transform: scale(0.96); }

.power-btn {
  background: linear-gradient(180deg, #2a4a2a, #1a3a1a);
  border-color: #3a5a3a;
  color: #8f8;
  font-weight: 600;
  position: relative;
  padding-right: 28px;
}
.power-btn.on {
  background: linear-gradient(180deg, #1a5a1a, #0a3a0a);
  box-shadow: 0 0 8px rgba(51,255,51,0.3);
}

.break-btn {
  background: linear-gradient(180deg, #6a2222, #4a1111);
  border-color: #8a3333;
  color: #faa;
  font-weight: 600;
}

.led {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
}
.led-off { background: var(--led-off); }
.led-on { background: var(--led-green); box-shadow: 0 0 6px var(--led-green); }

.ctrl-group {
  display: flex;
  align-items: center;
  gap: 4px;
}
.ctrl-group label {
  font-size: 10px;
  color: #888;
  text-transform: uppercase;
}
.ctrl-group select, .ctrl-group input[type="range"] {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  background: #222;
  color: #ccc;
  border: 1px solid #444;
  border-radius: 3px;
  padding: 2px 4px;
}

.vol-slider {
  width: 60px;
  accent-color: var(--amber);
}

input[type="checkbox"] {
  accent-color: var(--amber);
}

/* CRT Housing */
#crt-housing {
  background: linear-gradient(180deg, #1a1a1a, #0e0e0e);
  border: 1px solid #3a3a3a;
  border-top: none;
  padding: 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}

#crt-bezel {
  position: relative;
  background: #0a0a0a;
  border-radius: 20px;
  padding: 16px;
  box-shadow: 
    inset 0 0 40px rgba(0,0,0,0.8),
    0 0 2px #333,
    0 0 20px rgba(51,255,51,0.05);
  border: 3px solid #222;
}

#crt-screen {
  display: block;
  border-radius: 8px;
  background: #000;
  image-rendering: pixelated;
  width: 512px;
  height: 512px;
  max-width: calc(100vw - 100px);
  max-height: calc(100vw - 100px);
}

.crt-active #crt-screen {
  box-shadow: 0 0 30px var(--phosphor-glow), 0 0 60px rgba(51,255,51,0.08);
}

#scanline-overlay {
  position: absolute;
  top: 16px; left: 16px; right: 16px; bottom: 16px;
  border-radius: 8px;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 1px,
    rgba(0,0,0,0.15) 1px,
    rgba(0,0,0,0.15) 2px
  );
  pointer-events: none;
  z-index: 2;
}

#crt-vignette {
  position: absolute;
  top: 16px; left: 16px; right: 16px; bottom: 16px;
  border-radius: 8px;
  background: radial-gradient(ellipse at center, transparent 60%, rgba(0,0,0,0.6) 100%);
  pointer-events: none;
  z-index: 3;
}

#crt-reflection {
  position: absolute;
  top: 20px; left: 20px;
  width: 40%; height: 30%;
  border-radius: 50%;
  background: radial-gradient(ellipse at 30% 30%, rgba(255,255,255,0.03), transparent 70%);
  pointer-events: none;
  z-index: 4;
}

.no-fx #scanline-overlay,
.no-fx #crt-vignette,
.no-fx #crt-reflection { display: none; }
.no-fx #crt-bezel { border-radius: 4px; }
.no-fx #crt-screen { border-radius: 2px; box-shadow: none; }

#no-rom-msg {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  font-family: 'VT323', monospace;
  color: var(--phosphor-dim);
  font-size: 18px;
  z-index: 5;
  pointer-events: none;
}
#no-rom-msg .sub { font-size: 13px; color: #555; margin-top: 6px; }

/* Keyboard */
#keyboard-surround {
  background: linear-gradient(180deg, var(--keyboard-bg), #a89070);
  border: 1px solid #3a3a3a;
  border-top: none;
  padding: 12px 10px;
  border-radius: 0 0 6px 6px;
}

#keyboard {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 700px;
  margin: 0 auto;
}

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

.kb-key {
  background: linear-gradient(180deg, var(--key-bg), #d5cfc0);
  color: var(--key-text);
  border: 1px solid #aaa;
  border-radius: 4px;
  padding: 4px 2px;
  min-width: 34px;
  height: 34px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 0 #999, 0 3px 3px rgba(0,0,0,0.2);
  transition: all 0.08s;
  flex-shrink: 0;
}

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

.kb-key.special {
  background: linear-gradient(180deg, var(--key-special), #c0b8a8);
  font-size: 8px;
  min-width: 50px;
}

.kb-key.break-key {
  background: linear-gradient(180deg, #e04040, #c03030);
  color: #fff;
  border-color: #a02020;
}

.kb-key.space-key {
  flex-grow: 1;
  min-width: 250px;
}

/* ROM Loader Panel */
#loader-panel {
  margin-top: 8px;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  overflow: hidden;
}

.accordion-header {
  background: linear-gradient(180deg, #2a2a2a, #1e1e1e);
  padding: 8px 14px;
  cursor: pointer;
  font-family: 'VT323', monospace;
  font-size: 16px;
  color: var(--amber);
  display: flex;
  justify-content: space-between;
  user-select: none;
}
.accordion-header:hover { background: #333; }

.accordion-body {
  display: none;
  background: var(--panel-bg);
  padding: 12px;
}
.accordion-body.open { display: block; }

.rom-uploads {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rom-zone {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #252525;
  border: 2px dashed #444;
  border-radius: 6px;
  padding: 8px 12px;
  transition: border-color 0.2s;
}
.rom-zone.drag-over { border-color: var(--amber); background: #2a2a20; }

.rom-led {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--led-off);
  flex-shrink: 0;
}
.rom-led.loaded { background: var(--led-green); box-shadow: 0 0 6px var(--led-green); }
.rom-led.loading { background: var(--amber); box-shadow: 0 0 6px var(--amber); }

.rom-info strong { color: #ddd; display: block; font-size: 12px; }
.rom-info span { color: #888; font-size: 10px; }

.rom-file-input { display: none; }
.rom-browse {
  background: #3a3a3a;
  color: #ccc;
  border: 1px solid #555;
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 11px;
  cursor: pointer;
  font-family: 'IBM Plex Mono', monospace;
  margin-left: auto;
  flex-shrink: 0;
}
.rom-browse:hover { background: #4a4a4a; }

.rom-preview {
  font-size: 9px;
  color: #777;
  font-family: 'IBM Plex Mono', monospace;
  display: none;
  margin-top: 4px;
}
.rom-preview.visible { display: block; }

.rom-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

/* Cassette */
.cassette-section {
  margin-top: 14px;
  border-top: 1px solid #333;
  padding-top: 12px;
}

.cassette-header {
  font-family: 'VT323', monospace;
  font-size: 15px;
  color: var(--amber);
  margin-bottom: 8px;
}

.cassette-deck {
  background: #252525;
  border: 1px solid #3a3a3a;
  border-radius: 6px;
  padding: 10px;
}

.tape-visual {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin-bottom: 8px;
}

.tape-reel {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 3px solid #666;
  background: #333;
  position: relative;
  transition: transform 0.1s;
}
.tape-reel.spinning { animation: spin 1s linear infinite; }

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.tape-line {
  width: 60px;
  height: 2px;
  background: #666;
}

.cassette-controls {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.cassette-btn {
  background: #3a3a3a;
  color: #ccc;
  border: 1px solid #555;
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 11px;
  cursor: pointer;
  font-family: 'IBM Plex Mono', monospace;
}
.cassette-btn:hover:not(:disabled) { background: #4a4a4a; }
.cassette-btn:disabled { opacity: 0.4; cursor: not-allowed; }
#cassette-file-input { display: none; }

.cassette-info {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: #888;
}

.cassette-progress {
  margin-top: 6px;
  height: 4px;
  background: #333;
  border-radius: 2px;
  overflow: hidden;
}
.progress-bar {
  width: 0%;
  height: 100%;
  background: var(--amber);
  transition: width 0.3s;
}

/* Status Bar */
#status-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  background: #151515;
  border: 1px solid #2a2a2a;
  border-radius: 4px;
  padding: 5px 10px;
  margin-top: 6px;
  font-size: 11px;
  font-family: 'VT323', monospace;
  color: var(--phosphor-dim);
}

#cpu-state { flex: 1; min-width: 300px; }
#clock-speed { color: var(--amber); }
#emu-status { color: #888; }

/* Debug Panel */
#debug-panel {
  margin-top: 6px;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  overflow: hidden;
}

.debug-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-bottom: 8px;
}
.debug-controls label { font-size: 10px; color: #888; }
.debug-controls input[type="text"] {
  width: 60px;
  background: #222;
  color: var(--phosphor);
  border: 1px solid #444;
  border-radius: 3px;
  padding: 3px 6px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
}

.debug-views {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.debug-disasm, .debug-memory {
  flex: 1;
  min-width: 250px;
  background: #0a0a0a;
  border: 1px solid #2a2a2a;
  border-radius: 4px;
  padding: 6px;
  font-family: 'VT323', monospace;
  font-size: 13px;
  color: var(--phosphor);
  max-height: 200px;
  overflow-y: auto;
  white-space: pre;
  line-height: 1.4;
}

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

.modal-content {
  background: #1e1e1e;
  border: 1px solid #444;
  border-radius: 8px;
  padding: 24px;
  max-width: 560px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
}

.modal-content h2 {
  font-family: 'VT323', monospace;
  color: var(--amber);
  font-size: 24px;
  margin-bottom: 16px;
}
.modal-content h3 {
  color: var(--phosphor);
  font-size: 14px;
  margin-top: 14px;
  margin-bottom: 6px;
}
.modal-content p, .modal-content li {
  color: #bbb;
  font-size: 12px;
  line-height: 1.6;
}
.modal-content code {
  background: #333;
  padding: 1px 4px;
  border-radius: 2px;
  color: var(--phosphor);
}
.modal-content ol, .modal-content ul {
  padding-left: 20px;
}

.modal-close {
  position: absolute;
  top: 10px; right: 14px;
  background: none;
  border: none;
  color: #888;
  font-size: 20px;
  cursor: pointer;
}
.modal-close:hover { color: #fff; }

/* Footer */
#footer {
  text-align: center;
  padding: 14px;
  font-size: 11px;
  color: #555;
  font-family: 'VT323', monospace;
}
#footer a { color: var(--amber); text-decoration: none; }
#footer a:hover { text-decoration: underline; }

/* Responsive */
@media (max-width: 600px) {
  #crt-screen { width: 100%; height: auto; }
  .kb-key { min-width: 24px; height: 28px; font-size: 8px; padding: 2px 1px; }
  .kb-key.special { min-width: 36px; font-size: 7px; }
  .kb-key.space-key { min-width: 150px; }
  #control-panel { flex-direction: column; }
  .panel-controls { justify-content: center; }
  #status-bar { font-size: 9px; }
  .debug-views { flex-direction: column; }
}

/* Scrollbar styling */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: #111; }
::-webkit-scrollbar-thumb { background: #444; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #555; }