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

:root {
  --bg: #1a1208;
  --bezel: #2a2a2a;
  --panel-bg: #0d1a0d;
  --text: #33ff33;
  --text-dim: #1a8c1a;
  --accent: #00ccff;
  --red: #ff3333;
  --amber: #ffaa00;
  --key-bg: #6b5c4a;
  --key-text: #f0e6d2;
  --border-color: #444;
}

body {
  background: var(--bg);
  background-image: 
    repeating-linear-gradient(90deg, transparent, transparent 39px, rgba(80,60,30,0.1) 39px, rgba(80,60,30,0.1) 40px),
    repeating-linear-gradient(0deg, transparent, transparent 39px, rgba(80,60,30,0.08) 39px, rgba(80,60,30,0.08) 40px);
  color: var(--text);
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  min-height: 100vh;
  overflow-x: hidden;
}

#app-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 10px;
}

header {
  text-align: center;
  padding: 12px 0 8px;
}

.title-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

header h1 {
  font-size: 18px;
  color: var(--accent);
  text-shadow: 0 0 10px var(--accent), 0 0 20px rgba(0,204,255,0.4);
}

.led {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 6px var(--amber);
  display: inline-block;
}
.led.running { background: #33ff33; box-shadow: 0 0 8px #33ff33; }
.led.stopped { background: var(--red); box-shadow: 0 0 8px var(--red); }

.subtitle {
  font-size: 8px;
  color: var(--text-dim);
  margin-top: 4px;
}

#main-layout {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

aside {
  flex: 0 0 220px;
  min-width: 0;
}

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

.panel {
  background: var(--panel-bg);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 10px;
}

.panel h2 { font-size: 11px; margin-bottom: 8px; color: var(--accent); }
.panel h3 { font-size: 9px; margin: 8px 0 4px; color: var(--amber); }

.helper-text { font-size: 7px; color: var(--text-dim); margin-bottom: 8px; line-height: 1.5; }

.rom-slot {
  margin-bottom: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.rom-slot label {
  font-size: 8px;
  color: var(--text);
}
.rom-slot label small {
  color: var(--text-dim);
  font-size: 7px;
}

.drop-zone {
  position: relative;
  border: 1px dashed var(--text-dim);
  border-radius: 4px;
  padding: 8px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s;
}
.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--accent);
}
.drop-zone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}
.drop-label { font-size: 8px; color: var(--text-dim); }

.rom-status {
  font-size: 12px;
  text-align: center;
}
.rom-status.loaded { color: #33ff33; }

#power-on-btn {
  width: 100%;
  padding: 10px;
  margin-top: 8px;
  font-family: 'Press Start 2P', monospace;
  font-size: 12px;
  background: #8b0000;
  color: #fff;
  border: 2px outset #cc3333;
  border-radius: 8px;
  cursor: pointer;
  text-shadow: 0 0 6px #ff0000;
  transition: all 0.15s;
}
#power-on-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  text-shadow: none;
}
#power-on-btn:not(:disabled):hover {
  background: #cc0000;
  box-shadow: 0 0 15px rgba(255,0,0,0.5);
}
#power-on-btn:not(:disabled):active {
  border-style: inset;
}

.drive-led {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #333;
  margin: 4px auto;
}
.drive-led.active { background: var(--red); box-shadow: 0 0 6px var(--red); }

.tape-controls {
  display: flex;
  gap: 4px;
  align-items: center;
  margin-top: 4px;
}
.tape-controls button {
  font-size: 12px;
  background: #333;
  color: #ccc;
  border: 1px solid #555;
  border-radius: 3px;
  padding: 2px 6px;
  cursor: pointer;
  font-family: inherit;
}
.tape-controls button:hover { background: #444; }

.tape-counter {
  font-size: 10px;
  color: var(--amber);
  background: #111;
  padding: 2px 6px;
  border-radius: 2px;
  font-family: 'Press Start 2P', monospace;
}

.motor-status {
  font-size: 7px;
  color: var(--red);
  margin-top: 4px;
}
.motor-status.on { color: #33ff33; }

/* CRT */
#crt-frame {
  background: linear-gradient(145deg, #3a3a3a 0%, #252525 50%, #1a1a1a 100%);
  border-radius: 20px;
  padding: 20px;
  box-shadow: 
    0 0 0 3px #555,
    0 0 0 6px #222,
    0 8px 32px rgba(0,0,0,0.8),
    inset 0 0 30px rgba(0,0,0,0.5);
}

#crt-bezel {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: inset 0 0 40px rgba(0,0,0,0.6);
}

#canvas {
  display: block;
  width: 640px;
  height: 480px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border-radius: 8px;
  background: #000;
}

#scanlines {
  position: absolute;
  inset: 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;
  border-radius: 8px;
}

/* Control bar */
#control-bar {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-top: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.ctrl-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  background: #333;
  color: #ccc;
  border: 1px solid #555;
  border-radius: 4px;
  padding: 6px 10px;
  cursor: pointer;
}
.ctrl-btn:hover { background: #444; color: #fff; }

#ctrl-speed {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  background: #222;
  color: var(--text);
  border: 1px solid #555;
  border-radius: 3px;
  padding: 4px;
}

/* Audio controls */
#audio-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
  flex-wrap: wrap;
  justify-content: center;
  font-size: 7px;
}
#audio-controls label {
  display: flex;
  align-items: center;
  gap: 3px;
}
#volume-slider { width: 60px; }

#waveform-canvas {
  background: #0a0a0a;
  border: 1px solid #333;
  border-radius: 3px;
}

/* Keyboard */
#keyboard-container {
  margin-top: 10px;
  background: linear-gradient(180deg, #5a4d3c 0%, #4a3f30 100%);
  border-radius: 8px;
  padding: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  max-width: 680px;
  width: 100%;
}

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

.kb-key {
  background: linear-gradient(180deg, var(--key-bg) 0%, #574a3a 100%);
  color: var(--key-text);
  border: 1px solid #3a3025;
  border-radius: 4px;
  padding: 4px 2px;
  min-width: 26px;
  height: 28px;
  font-family: 'Press Start 2P', monospace;
  font-size: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  box-shadow: 0 2px 0 #2a2015, inset 0 1px 0 rgba(255,255,255,0.1);
  transition: all 0.05s;
  user-select: none;
}
.kb-key:active, .kb-key.pressed {
  box-shadow: 0 0 0 #2a2015;
  transform: translateY(2px);
  background: #4a3f30;
}
.kb-key.fn-key {
  background: linear-gradient(180deg, #7a5a3a 0%, #6a4a2a 100%);
}
.kb-key.special-key {
  background: linear-gradient(180deg, #8b3a3a 0%, #6b2a2a 100%);
  color: #ffcccc;
}
.kb-key.wide { min-width: 44px; }
.kb-key.wider { min-width: 60px; }
.kb-key.space { min-width: 200px; }

/* Debug panel */
.debug-panel {
  font-size: 8px;
  max-height: 80vh;
  overflow-y: auto;
}
.reg-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  margin: 4px 0;
}
.reg-grid b { color: var(--accent); }

.flags-row {
  display: flex;
  gap: 4px;
  margin: 4px 0;
}
.flags-row span {
  padding: 2px 4px;
  background: #222;
  border-radius: 2px;
  color: #555;
}
.flags-row span.set {
  background: var(--accent);
  color: #000;
}

#disasm-line { color: var(--amber); margin: 4px 0; }

#vic-reg-list {
  font-size: 7px;
  line-height: 1.6;
}

#mem-addr-input, #bp-addr {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  background: #111;
  color: var(--text);
  border: 1px solid #444;
  border-radius: 3px;
  padding: 3px 6px;
  width: 80px;
}

#mem-dump {
  font-size: 7px;
  line-height: 1.4;
  color: var(--text-dim);
  max-height: 200px;
  overflow-y: auto;
  margin-top: 4px;
}

#bp-controls {
  display: flex;
  gap: 4px;
  align-items: center;
  margin-top: 6px;
  flex-wrap: wrap;
}
#bp-controls button {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  background: #333;
  color: #ccc;
  border: 1px solid #555;
  border-radius: 3px;
  padding: 3px 6px;
  cursor: pointer;
}

footer {
  text-align: center;
  padding: 16px;
  margin-top: 16px;
}
footer a {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 8px;
}
footer a:hover { color: var(--text); }

@media (max-width: 1024px) {
  #main-layout { flex-direction: column; }
  aside { flex: none; width: 100%; }
  #canvas { width: 100%; height: auto; }
  .kb-key { min-width: 20px; height: 24px; font-size: 5px; }
  .kb-key.space { min-width: 120px; }
}