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

:root {
  --bg-dark: #1a1209;
  --bg-wood: #2a1f0e;
  --bezel-color: #3a3028;
  --bezel-light: #5a4a38;
  --cream: #d4c8a0;
  --cream-dark: #a09070;
  --green-led: #00ff44;
  --red-led: #ff2200;
  --vic-blue: #352879;
  --text-green: #33ff33;
  --text-amber: #ffaa00;
  --border-color: #4a3a28;
}

body {
  background: var(--bg-dark);
  background-image:
    repeating-linear-gradient(90deg, transparent, transparent 48px, rgba(0,0,0,0.05) 48px, rgba(0,0,0,0.05) 50px),
    repeating-linear-gradient(0deg, transparent, transparent 48px, rgba(0,0,0,0.03) 48px, rgba(0,0,0,0.03) 50px),
    linear-gradient(135deg, #2a1f0e 0%, #1a1209 50%, #0f0a04 100%);
  color: var(--cream);
  font-family: 'IBM Plex Mono', monospace;
  min-height: 100vh;
  overflow-x: hidden;
}

#app-container {
  max-width: 900px;
  margin: 0 auto;
  padding: 16px;
}

header {
  text-align: center;
  padding: 20px 0 10px;
}

.logo-area {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.logo-c {
  font-family: 'VT323', monospace;
  font-size: 48px;
  color: #fff;
  background: var(--vic-blue);
  padding: 2px 12px;
  border-radius: 6px;
  line-height: 1;
}

.logo-text {
  font-family: 'VT323', monospace;
  font-size: 32px;
  color: var(--cream);
  letter-spacing: 2px;
}

.logo-sub {
  font-size: 14px;
  color: var(--cream-dark);
  opacity: 0.7;
}

/* ROM Panel */
#rom-panel {
  background: rgba(42, 31, 14, 0.8);
  border: 2px solid var(--border-color);
  border-radius: 8px;
  padding: 16px;
  margin: 16px 0;
}

#rom-panel h2 {
  font-family: 'VT323', monospace;
  font-size: 22px;
  color: var(--text-amber);
  margin-bottom: 4px;
}

.rom-hint {
  font-size: 12px;
  color: var(--cream-dark);
  margin-bottom: 12px;
}

#rom-slots {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rom-slot {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(0,0,0,0.3);
  padding: 10px 14px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  transition: border-color 0.3s;
}

.rom-slot.loaded {
  border-color: var(--green-led);
  box-shadow: 0 0 8px rgba(0, 255, 68, 0.15);
}

.rom-slot.dragover {
  border-color: var(--text-amber);
  background: rgba(255, 170, 0, 0.1);
}

.rom-status {
  font-size: 20px;
  min-width: 28px;
  text-align: center;
}

.rom-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.rom-info strong {
  font-family: 'VT323', monospace;
  font-size: 16px;
  color: var(--cream);
}

.rom-addr {
  font-size: 11px;
  color: var(--text-green);
  opacity: 0.7;
}

.rom-file {
  font-size: 11px;
  color: var(--cream-dark);
}

.rom-upload-btn {
  background: var(--bezel-light);
  color: var(--cream);
  padding: 6px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  border: 1px solid var(--border-color);
  transition: all 0.2s;
  white-space: nowrap;
}

.rom-upload-btn:hover {
  background: var(--cream-dark);
  color: var(--bg-dark);
}

.rom-upload-btn input[type="file"] {
  display: none;
}

.rom-auto-detect {
  margin-top: 12px;
  text-align: center;
}

.auto-detect-btn {
  font-size: 14px;
  padding: 10px 20px;
  background: var(--vic-blue);
  border-color: #5a48a9;
}

.auto-detect-btn:hover {
  background: #5a48a9;
}

/* CRT Display */
#main-area {
  display: flex;
  gap: 16px;
  margin: 16px 0;
  flex-wrap: wrap;
  justify-content: center;
}

#crt-container {
  flex-shrink: 0;
}

#crt-bezel {
  background: linear-gradient(145deg, #4a4038, #2a2420, #3a3028);
  border-radius: 20px;
  padding: 20px;
  box-shadow:
    0 0 0 3px #1a1008,
    0 8px 32px rgba(0,0,0,0.6),
    inset 0 1px 0 rgba(255,255,255,0.05);
  position: relative;
}

#crt-power-led {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #333;
  position: absolute;
  top: 10px;
  right: 24px;
  transition: all 0.3s;
}

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

#crt-screen-wrap {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
  box-shadow: inset 0 0 40px rgba(0,0,0,0.8);
}

#canvas {
  display: block;
  width: 528px;
  height: 552px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border-radius: 8px;
}

#scanline-overlay {
  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;
}

#scanline-overlay.hidden { display: none; }

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

#crt-glow.hidden { display: none; }

#crt-label {
  text-align: center;
  font-family: 'VT323', monospace;
  font-size: 14px;
  color: var(--cream-dark);
  margin-top: 8px;
  letter-spacing: 3px;
}

/* Controls Panel */
#controls-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 180px;
}

.ctrl-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ctrl-group label {
  font-size: 12px;
  color: var(--cream-dark);
  font-family: 'VT323', monospace;
  font-size: 16px;
}

.ctrl-group.toggles label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
}

.hw-button {
  font-family: 'VT323', monospace;
  font-size: 18px;
  padding: 8px 16px;
  border: 2px solid var(--border-color);
  border-radius: 6px;
  background: linear-gradient(180deg, #5a4a38, #3a3028);
  color: var(--cream);
  cursor: pointer;
  transition: all 0.15s;
  box-shadow: 0 3px 0 #1a1008, 0 4px 8px rgba(0,0,0,0.3);
  text-align: center;
}

.hw-button:hover:not(:disabled) {
  background: linear-gradient(180deg, #6a5a48, #4a3a28);
  transform: translateY(-1px);
  box-shadow: 0 4px 0 #1a1008, 0 5px 10px rgba(0,0,0,0.3);
}

.hw-button:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #1a1008;
}

.hw-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.hw-button.small {
  font-size: 14px;
  padding: 4px 10px;
}

.power-btn:not(:disabled) {
  border-color: var(--green-led);
  color: var(--green-led);
}

#speed-select, #volume-slider {
  background: #1a1008;
  color: var(--cream);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 4px 8px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
}

#volume-slider {
  -webkit-appearance: none;
  height: 6px;
  background: var(--border-color);
  border-radius: 3px;
  padding: 0;
}

#volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--cream);
  cursor: pointer;
}

/* Peripherals */
#peripherals {
  display: flex;
  gap: 16px;
  margin: 16px 0;
  flex-wrap: wrap;
}

.peripheral-box {
  flex: 1;
  min-width: 260px;
  background: linear-gradient(160deg, #c8b888, #b0a070, #a09060);
  border: 2px solid #8a7a5a;
  border-radius: 10px;
  padding: 14px;
  color: #2a2008;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.peripheral-box h3 {
  font-family: 'VT323', monospace;
  font-size: 16px;
  margin-bottom: 8px;
  color: #3a2a08;
}

.drive-slot {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.drive-led {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #600;
  border: 1px solid #400;
  transition: all 0.2s;
}

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

#floppy-file, #tape-file {
  font-size: 11px;
  flex: 1;
  color: #4a3a18;
}

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

#tape-counter {
  font-family: 'VT323', monospace;
  font-size: 22px;
  background: #222;
  color: #ddd;
  padding: 2px 8px;
  border-radius: 3px;
  letter-spacing: 3px;
  min-width: 52px;
  text-align: center;
}

.tape-reels {
  display: flex;
  gap: 6px;
}

.tape-reel {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #333;
  border: 3px solid #555;
  position: relative;
}

.tape-reel::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  width: 6px; height: 6px;
  background: #222;
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.tape-reel.spinning {
  animation: spin 1s linear infinite;
}

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

.tape-buttons {
  display: flex;
  gap: 4px;
}

.tape-btn {
  width: 30px;
  height: 26px;
  border: 1px solid #8a7a5a;
  border-radius: 3px;
  background: linear-gradient(180deg, #aaa, #888);
  color: #333;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tape-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.tape-btn:hover:not(:disabled) { background: linear-gradient(180deg, #ccc, #aaa); }

/* Virtual Keyboard */
#keyboard-container {
  margin: 16px 0;
  overflow-x: auto;
}

#virtual-keyboard {
  display: flex;
  flex-direction: column;
  gap: 3px;
  background: linear-gradient(160deg, #6a5a3a, #4a3a28);
  border: 2px solid #3a2a18;
  border-radius: 8px;
  padding: 10px;
  min-width: 700px;
}

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

.kb-key {
  font-family: 'VT323', monospace;
  font-size: 13px;
  min-width: 32px;
  height: 28px;
  border: 1px solid #2a1a0a;
  border-radius: 3px;
  background: linear-gradient(180deg, #c8b888, #a09060);
  color: #2a1a08;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 0 #5a4a2a;
  transition: all 0.1s;
  padding: 0 4px;
  user-select: none;
}

.kb-key:hover { background: linear-gradient(180deg, #d8c898, #b0a070); }
.kb-key:active, .kb-key.pressed {
  transform: translateY(2px);
  box-shadow: 0 0 0 #5a4a2a;
  background: linear-gradient(180deg, #a09060, #8a7a4a);
}

.kb-key.wide { min-width: 60px; }
.kb-key.wider { min-width: 80px; }
.kb-key.space { min-width: 240px; }
.kb-key.fn-key { background: linear-gradient(180deg, #887858, #6a5a3a); color: #ddd; }

/* Status Bar */
#status-bar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  background: #0a0a0a;
  border: 1px solid #222;
  border-radius: 4px;
  padding: 6px 12px;
  font-family: 'VT323', monospace;
  font-size: 14px;
  color: var(--text-green);
  flex-wrap: wrap;
}

#perf-status {
  color: var(--text-amber);
}

/* Debug Panel */
#debug-panel {
  margin: 16px 0;
  background: rgba(0,0,0,0.5);
  border: 1px solid var(--border-color);
  border-radius: 6px;
}

#debug-panel summary {
  padding: 8px 14px;
  cursor: pointer;
  font-family: 'VT323', monospace;
  font-size: 18px;
  color: var(--text-amber);
}

#debug-content {
  padding: 12px;
}

#debug-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

#debug-controls label {
  font-size: 13px;
  color: var(--cream-dark);
}

#debug-controls input[type="text"] {
  width: 52px;
  background: #0a0a0a;
  color: var(--text-green);
  border: 1px solid #333;
  border-radius: 3px;
  padding: 2px 6px;
  font-family: 'VT323', monospace;
  font-size: 16px;
  text-transform: uppercase;
}

#debug-views {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.debug-box {
  flex: 1;
  min-width: 260px;
}

.debug-box h4 {
  font-family: 'VT323', monospace;
  font-size: 16px;
  color: var(--text-amber);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.debug-box h4 input {
  width: 48px;
  background: #0a0a0a;
  color: var(--text-green);
  border: 1px solid #333;
  border-radius: 3px;
  padding: 2px 6px;
  font-family: 'VT323', monospace;
  font-size: 14px;
  text-transform: uppercase;
}

.debug-box pre {
  background: #0a0a0a;
  color: var(--text-green);
  font-family: 'VT323', monospace;
  font-size: 14px;
  padding: 8px;
  border-radius: 4px;
  height: 200px;
  overflow-y: auto;
  border: 1px solid #222;
  line-height: 1.4;
}

/* Footer */
footer {
  text-align: center;
  padding: 20px 0;
  border-top: 1px solid var(--border-color);
  margin-top: 20px;
}

footer a {
  font-family: 'VT323', monospace;
  font-size: 18px;
  color: var(--vic-blue);
  text-decoration: none;
  background: var(--cream);
  padding: 4px 16px;
  border-radius: 4px;
  transition: all 0.2s;
}

footer a:hover {
  background: #fff;
  color: #000;
}

/* Demo blink */
@keyframes blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

.blink { animation: blink 1s step-end infinite; }

/* Responsive */
@media (max-width: 700px) {
  #canvas {
    width: 352px;
    height: 368px;
  }
  #crt-bezel { padding: 12px; }
  #main-area { flex-direction: column; align-items: center; }
  #controls-panel { flex-direction: row; flex-wrap: wrap; justify-content: center; }
  #virtual-keyboard { min-width: 500px; transform: scale(0.85); transform-origin: top left; }
  .rom-slot { flex-wrap: wrap; }
}