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

:root {
  --chassis: #C8B889;
  --chassis-dark: #A89060;
  --chassis-shadow: #7A6840;
  --screen-bg: #001100;
  --phosphor: #33FF33;
  --phosphor-dim: #115511;
  --key-bg: #2A2A2A;
  --key-text: #E8E8E8;
  --key-active: #444;
  --panel-bg: #B8A878;
  --accent-orange: #D4841A;
  --accent-brown: #6B4C2A;
  --led-red: #FF2020;
  --led-green: #33FF33;
}

body {
  background: #1A1A1A;
  font-family: 'VT323', monospace;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  padding: 20px 10px;
  color: #ddd;
}

#pet-chassis {
  background: linear-gradient(145deg, var(--chassis) 0%, #B8A070 100%);
  border-radius: 20px;
  padding: 20px;
  max-width: 900px;
  width: 100%;
  box-shadow:
    0 4px 20px rgba(0,0,0,0.5),
    inset 0 1px 0 rgba(255,255,255,0.3),
    inset 0 -2px 0 var(--chassis-shadow);
  border: 3px solid var(--chassis-dark);
}

#top-label {
  text-align: center;
  padding: 5px 0 15px;
  font-size: 14px;
  letter-spacing: 6px;
  text-transform: uppercase;
}

#top-label .brand {
  color: var(--accent-brown);
  font-family: 'Share Tech Mono', monospace;
  font-size: 28px;
  font-weight: bold;
  letter-spacing: 8px;
}

#top-label .model {
  color: var(--chassis-shadow);
  font-size: 16px;
  margin-left: 15px;
}

#crt-housing {
  background: #222;
  border-radius: 15px;
  padding: 20px;
  position: relative;
  box-shadow:
    inset 0 3px 15px rgba(0,0,0,0.8),
    0 2px 0 var(--chassis-dark);
  margin-bottom: 15px;
}

#power-led {
  position: absolute;
  top: 8px;
  right: 15px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #333;
  box-shadow: none;
  transition: all 0.3s;
  z-index: 5;
}

#power-led.led-on {
  background: var(--led-green);
  box-shadow: 0 0 8px var(--led-green), 0 0 20px rgba(51,255,51,0.3);
}

#crt-bezel {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  background: var(--screen-bg);
  box-shadow:
    0 0 40px rgba(51,255,51,0.08),
    inset 0 0 80px rgba(0,17,0,0.5);
}

#screen {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  background: var(--screen-bg);
}

#scanlines {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  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-bezel::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: radial-gradient(ellipse at center, transparent 60%, rgba(0,0,0,0.4) 100%);
  pointer-events: none;
  z-index: 3;
}

/* Control Panel */
#control-panel {
  display: flex;
  gap: 15px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.panel-section {
  background: var(--panel-bg);
  border-radius: 8px;
  padding: 10px 15px;
  border: 2px solid var(--chassis-dark);
  flex: 1;
  min-width: 120px;
}

.panel-section h3 {
  font-family: 'Share Tech Mono', monospace;
  font-size: 12px;
  color: var(--accent-brown);
  letter-spacing: 3px;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.toggle-container {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.toggle-switch {
  position: relative;
  width: 50px;
  height: 26px;
  display: inline-block;
}

.toggle-switch input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: #555;
  border-radius: 13px;
  cursor: pointer;
  transition: 0.3s;
  border: 2px solid #333;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 2px;
  bottom: 2px;
  background: #ddd;
  border-radius: 50%;
  transition: 0.3s;
}

.toggle-switch input:checked + .toggle-slider {
  background: #448844;
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(24px);
}

.toggle-label {
  font-size: 14px;
  color: var(--accent-brown);
  font-weight: bold;
}

.retro-btn {
  font-family: 'Share Tech Mono', monospace;
  background: #555;
  color: #ddd;
  border: 2px solid #333;
  border-radius: 4px;
  padding: 4px 12px;
  cursor: pointer;
  font-size: 13px;
  letter-spacing: 1px;
  text-transform: uppercase;
  transition: all 0.1s;
}

.retro-btn:hover { background: #666; }
.retro-btn:active { transform: translateY(1px); background: #444; }
.retro-btn.small { padding: 2px 8px; font-size: 11px; }

#ram-selector {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.ram-opt {
  font-size: 13px;
  color: var(--accent-brown);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 3px;
}

.ram-opt input { accent-color: var(--accent-orange); }

#speed-controls {
  display: flex;
  gap: 5px;
}

.speed-btn {
  font-family: 'VT323', monospace;
  background: #555;
  color: #ccc;
  border: 2px solid #333;
  border-radius: 4px;
  padding: 3px 10px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.1s;
}

.speed-btn.active {
  background: var(--accent-orange);
  color: #fff;
}

.speed-btn:hover { background: #666; }

/* ROM Panel */
#rom-panel {
  background: var(--panel-bg);
  border-radius: 8px;
  padding: 12px 15px;
  border: 2px solid var(--chassis-dark);
  margin-bottom: 12px;
}

#rom-panel h3 {
  font-family: 'Share Tech Mono', monospace;
  font-size: 12px;
  color: var(--accent-brown);
  letter-spacing: 3px;
  margin-bottom: 8px;
}

#rom-drop-zone {
  border: 2px dashed var(--chassis-dark);
  border-radius: 6px;
  padding: 15px;
  text-align: center;
  cursor: pointer;
  color: var(--accent-brown);
  font-size: 14px;
  margin-bottom: 10px;
  transition: background 0.2s;
  position: relative;
}

#rom-drop-zone:hover, #rom-drop-zone.drag-over {
  background: rgba(0,0,0,0.1);
  border-color: var(--accent-orange);
}

#rom-drop-zone input {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  opacity: 0;
  cursor: pointer;
}

#rom-status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 5px;
  font-size: 12px;
}

.rom-slot {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 6px;
  background: rgba(0,0,0,0.1);
  border-radius: 3px;
}

.rom-slot .indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.rom-slot .indicator.loaded { background: var(--led-green); box-shadow: 0 0 4px var(--led-green); }
.rom-slot .indicator.missing { background: var(--led-red); box-shadow: 0 0 4px var(--led-red); }

.rom-slot .label { color: var(--accent-brown); font-family: 'Share Tech Mono', monospace; }

/* Peripheral Panel */
#peripheral-panel {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.periph-section {
  background: var(--panel-bg);
  border-radius: 8px;
  padding: 10px;
  border: 2px solid var(--chassis-dark);
  flex: 1;
  min-width: 130px;
  text-align: center;
}

.periph-section h4 {
  font-family: 'Share Tech Mono', monospace;
  font-size: 10px;
  color: var(--accent-brown);
  letter-spacing: 2px;
  margin-bottom: 5px;
}

.periph-icon { font-size: 24px; margin-bottom: 3px; }

.drop-target {
  border: 1px dashed var(--chassis-dark);
  border-radius: 4px;
  padding: 8px 5px;
  cursor: pointer;
  position: relative;
  font-size: 11px;
  color: var(--accent-brown);
  transition: background 0.2s;
  margin-bottom: 5px;
}

.drop-target:hover { background: rgba(0,0,0,0.1); }

.drop-target input {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  opacity: 0;
  cursor: pointer;
}

.periph-status {
  font-size: 10px;
  color: #665530;
  font-family: 'Share Tech Mono', monospace;
}

.progress-bar {
  height: 4px;
  background: #555;
  border-radius: 2px;
  margin-top: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--led-green);
  transition: width 0.3s;
}

.drive-led {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #333;
  margin: 4px auto 0;
}

.drive-led.active {
  background: var(--led-red);
  box-shadow: 0 0 6px var(--led-red);
}

/* Keyboard */
#keyboard-container {
  background: #1E1E1E;
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 10px;
  border: 2px solid #111;
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.5);
  overflow-x: auto;
}

#keyboard {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 700px;
}

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

.kb-key {
  font-family: 'VT323', monospace;
  font-size: 12px;
  background: var(--key-bg);
  color: var(--key-text);
  border: 1px solid #444;
  border-radius: 3px;
  padding: 4px 2px;
  min-width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  transition: all 0.08s;
  text-align: center;
  line-height: 1.1;
}

.kb-key:hover { background: #3A3A3A; }
.kb-key:active, .kb-key.pressed {
  background: var(--key-active);
  transform: translateY(1px);
  border-color: #555;
}

.kb-key.wide { min-width: 55px; font-size: 10px; }
.kb-key.wider { min-width: 70px; font-size: 10px; }
.kb-key.space { min-width: 160px; }
.kb-key.numpad { background: #333; border-color: #555; }
.kb-key.separator { width: 15px; background: transparent; border: none; cursor: default; min-width: 15px; }

/* Status Bar */
#status-bar {
  display: flex;
  justify-content: space-between;
  font-family: 'Share Tech Mono', monospace;
  font-size: 12px;
  color: var(--phosphor-dim);
  padding: 5px 10px;
  background: rgba(0,0,0,0.2);
  border-radius: 5px;
  gap: 10px;
  flex-wrap: wrap;
}

/* Debug Panel */
#debug-toggle {
  position: fixed;
  top: 10px;
  right: 10px;
  background: #333;
  border: 2px solid #555;
  color: #ddd;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

#debug-toggle:hover { background: #444; }

#debug-panel {
  position: fixed;
  top: 55px;
  right: 10px;
  background: #111;
  border: 2px solid var(--phosphor-dim);
  border-radius: 8px;
  padding: 12px;
  width: 280px;
  max-height: 80vh;
  overflow-y: auto;
  z-index: 99;
  font-family: 'Share Tech Mono', monospace;
  font-size: 13px;
  color: var(--phosphor);
}

#debug-panel.hidden { display: none; }

#debug-panel h3 {
  text-align: center;
  font-size: 14px;
  letter-spacing: 4px;
  color: var(--phosphor);
  margin-bottom: 10px;
  border-bottom: 1px solid var(--phosphor-dim);
  padding-bottom: 5px;
}

#debug-registers {
  margin-bottom: 8px;
}

.reg {
  display: inline-block;
  margin: 2px 8px 2px 0;
}

.reg span { color: #5F5; }

.reg.flags { display: block; margin-top: 5px; }
.reg.flags span { margin-right: 6px; }

#debug-instr {
  background: #0A0A0A;
  padding: 4px 8px;
  border-radius: 3px;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--phosphor-dim);
}

#debug-controls {
  display: flex;
  gap: 5px;
  margin-bottom: 10px;
}

#mem-viewer label {
  display: block;
  margin-bottom: 5px;
  font-size: 12px;
}

#mem-addr {
  background: #0A0A0A;
  border: 1px solid var(--phosphor-dim);
  color: var(--phosphor);
  font-family: 'Share Tech Mono', monospace;
  font-size: 13px;
  width: 50px;
  padding: 2px 4px;
  border-radius: 3px;
}

#mem-dump {
  background: #0A0A0A;
  padding: 6px;
  border-radius: 3px;
  font-size: 11px;
  color: var(--phosphor-dim);
  max-height: 200px;
  overflow-y: auto;
  white-space: pre;
  line-height: 1.4;
}

footer {
  margin-top: 20px;
  font-size: 14px;
}

footer a {
  color: var(--phosphor-dim);
  text-decoration: none;
}

footer a:hover { color: var(--phosphor); text-decoration: underline; }

/* Screen flicker animation */
@keyframes flicker {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.985; }
}

#crt-bezel { animation: flicker 0.1s infinite; }

/* Responsive */
@media (max-width: 700px) {
  #pet-chassis { padding: 10px; border-radius: 12px; }
  #crt-housing { padding: 10px; }
  #control-panel { flex-direction: column; }
  #peripheral-panel { flex-direction: column; }
  .kb-key { min-width: 26px; height: 28px; font-size: 10px; }
  .kb-key.space { min-width: 100px; }
  #keyboard { min-width: 550px; }
  #debug-panel { width: 240px; font-size: 11px; }
}