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

body {
  background: #111;
  color: #aaa;
  font-family: 'VT323', 'Courier New', monospace;
  min-height: 100vh;
  overflow-x: hidden;
}

#app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 10px 15px;
}

header {
  text-align: center;
  padding: 15px 0 10px;
  border-bottom: 1px solid #333;
  margin-bottom: 15px;
}

header h1 {
  font-family: 'Press Start 2P', monospace;
  font-size: 18px;
  color: #33ff33;
  text-shadow: 0 0 10px rgba(51,255,51,0.5);
  letter-spacing: 2px;
}

.subtitle {
  font-size: 16px;
  color: #777;
  margin-top: 5px;
}

#status-led {
  margin-top: 8px;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.led {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #550000;
  box-shadow: 0 0 3px #330000;
  transition: all 0.3s;
}

.led.running {
  background: #33ff33;
  box-shadow: 0 0 8px #33ff33, 0 0 15px rgba(51,255,51,0.5);
  animation: blink-led 1s ease-in-out infinite;
}

.led.stopped {
  background: #ff3333;
  box-shadow: 0 0 8px #ff3333;
}

@keyframes blink-led {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.panel {
  background: #1a1a1a;
  border: 2px solid #444;
  border-radius: 4px;
  padding: 12px;
  margin-bottom: 12px;
}

.panel-title {
  font-size: 16px;
  color: #33ff33;
  margin-bottom: 10px;
  text-align: center;
}

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

.rom-slot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 6px;
  background: #222;
  border: 1px solid #333;
  border-radius: 3px;
}

.rom-slot label {
  font-size: 15px;
  color: #aaa;
  min-width: 250px;
}

.rom-input {
  font-family: 'VT323', monospace;
  font-size: 14px;
  color: #ccc;
  background: #1a1a1a;
  border: 1px solid #555;
  padding: 3px 6px;
  border-radius: 2px;
  max-width: 220px;
}

.rom-input::file-selector-button {
  font-family: 'VT323', monospace;
  font-size: 14px;
  background: linear-gradient(#555, #333);
  color: #ccc;
  border: 2px outset #666;
  padding: 2px 8px;
  cursor: pointer;
  border-radius: 2px;
}

.rom-input::file-selector-button:active {
  border-style: inset;
}

.rom-status {
  font-size: 15px;
}

.power-controls {
  display: flex;
  gap: 12px;
  margin-top: 12px;
  justify-content: center;
}

.btn-power {
  font-family: 'Press Start 2P', monospace;
  font-size: 12px;
  padding: 10px 24px;
  background: linear-gradient(#2a6e2a, #1a4e1a);
  color: #33ff33;
  border: 3px outset #3a8e3a;
  cursor: pointer;
  border-radius: 4px;
  text-shadow: 0 0 5px rgba(51,255,51,0.5);
  transition: all 0.1s;
}

.btn-power:disabled {
  background: linear-gradient(#333, #222);
  color: #555;
  border-color: #444;
  cursor: not-allowed;
  text-shadow: none;
}

.btn-power:not(:disabled):hover {
  background: linear-gradient(#3a8e3a, #2a6e2a);
}

.btn-power:not(:disabled):active {
  border-style: inset;
}

.btn-power.powered-on {
  background: linear-gradient(#6e2a2a, #4e1a1a);
  color: #ff3333;
  border-color: #8e3a3a;
  text-shadow: 0 0 5px rgba(255,51,51,0.5);
}

.btn-reset {
  font-family: 'VT323', monospace;
  font-size: 18px;
  padding: 8px 18px;
  background: linear-gradient(#555, #333);
  color: #ffaa00;
  border: 3px outset #666;
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.1s;
}

.btn-reset:disabled {
  color: #555;
  cursor: not-allowed;
}

.btn-reset:not(:disabled):active {
  border-style: inset;
}

#main-area {
  display: flex;
  gap: 15px;
  flex-wrap: wrap;
  justify-content: center;
}

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

#crt-bezel {
  background: #0a0a0a;
  border: 12px solid #222;
  border-radius: 20px;
  padding: 8px;
  box-shadow:
    inset 0 0 30px rgba(0,0,0,0.8),
    0 0 20px rgba(0,0,0,0.5),
    0 0 40px rgba(51,255,51,0.08);
}

#crt-screen {
  position: relative;
  width: 512px;
  height: 512px;
  overflow: hidden;
  border-radius: 10px;
  background: #000;
}

#canvas {
  width: 512px;
  height: 512px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
}

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

@keyframes flicker {
  0% { opacity: 1; }
  5% { opacity: 0.98; }
  10% { opacity: 1; }
  50% { opacity: 0.99; }
  100% { opacity: 1; }
}

#crt-screen {
  animation: flicker 0.15s infinite;
}

#color-toggle {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
}

.color-btn {
  font-family: 'VT323', monospace;
  font-size: 15px;
  padding: 3px 10px;
  background: #222;
  color: #888;
  border: 1px solid #444;
  cursor: pointer;
  border-radius: 2px;
}

.color-btn.active {
  color: #fff;
  border-color: #888;
  background: #333;
}

#side-panels {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 250px;
}

#cassette-info {
  font-size: 14px;
  color: #888;
  margin: 6px 0;
}

#tape-counter {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  color: #33ff33;
  background: #000;
  padding: 4px 8px;
  border: 1px solid #333;
  text-align: center;
  margin: 6px 0;
  letter-spacing: 2px;
}

.cassette-controls {
  display: flex;
  gap: 6px;
  justify-content: center;
}

.tape-btn {
  font-size: 18px;
  padding: 5px 12px;
  background: linear-gradient(#555, #333);
  color: #ccc;
  border: 2px outset #666;
  cursor: pointer;
  border-radius: 3px;
}

.tape-btn:disabled {
  color: #555;
  cursor: not-allowed;
}

.tape-btn:not(:disabled):active {
  border-style: inset;
}

.baud-toggle, .audio-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 15px;
}

.baud-btn {
  font-family: 'VT323', monospace;
  font-size: 15px;
  padding: 2px 8px;
  background: #222;
  color: #888;
  border: 1px solid #444;
  cursor: pointer;
  border-radius: 2px;
}

.baud-btn.active {
  color: #fff;
  border-color: #888;
  background: #333;
}

#volume {
  width: 100px;
  accent-color: #33ff33;
}

/* Keyboard */
#keyboard-panel {
  max-width: 750px;
  margin: 0 auto 12px;
}

#keyboard {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
}

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

.kb-key {
  font-family: 'VT323', monospace;
  font-size: 14px;
  min-width: 36px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(#d0d0d0, #b0b0b0);
  color: #222;
  border: 2px outset #ddd;
  border-radius: 4px;
  cursor: pointer;
  padding: 0 5px;
  user-select: none;
  box-shadow: 0 2px 3px rgba(0,0,0,0.3);
  transition: all 0.05s;
  white-space: nowrap;
}

.kb-key:active, .kb-key.pressed {
  border-style: inset;
  background: linear-gradient(#999, #aaa);
  box-shadow: 0 0 1px rgba(0,0,0,0.3);
  transform: translateY(1px);
}

.kb-key.break-key {
  background: linear-gradient(#cc4444, #aa2222);
  color: #fff;
  border-color: #dd5555;
}

.kb-key.shift-lock-active {
  border-style: inset;
  background: linear-gradient(#999, #aaa);
}

.kb-key.space-key {
  min-width: 300px;
}

/* Debug */
#debug-toggle-bar {
  text-align: center;
  margin: 6px 0;
}

#btn-debug-toggle {
  font-family: 'VT323', monospace;
  font-size: 16px;
  padding: 4px 16px;
  background: #222;
  color: #888;
  border: 1px solid #444;
  cursor: pointer;
  border-radius: 3px;
}

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

.debug-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
}

.debug-section h3 {
  font-size: 16px;
  color: #33ff33;
  margin-bottom: 6px;
}

#reg-display, #flags-display, #current-instr, #clock-speed {
  font-size: 15px;
  color: #33ff33;
  line-height: 1.6;
}

#flags-display { color: #ffaa00; }
#current-instr { color: #88ccff; margin-top: 4px; }
#clock-speed { color: #aaa; margin-top: 4px; }

.dbg-btn {
  font-family: 'VT323', monospace;
  font-size: 15px;
  padding: 3px 10px;
  background: linear-gradient(#555, #333);
  color: #ccc;
  border: 2px outset #666;
  cursor: pointer;
  border-radius: 2px;
  margin: 2px;
}

.dbg-btn:disabled { color: #555; cursor: not-allowed; }
.dbg-btn:active { border-style: inset; }

.break-input, .mem-input {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 15px;
  flex-wrap: wrap;
}

.break-input input, .mem-input input {
  font-family: 'VT323', monospace;
  font-size: 15px;
  width: 60px;
  background: #111;
  color: #33ff33;
  border: 1px solid #444;
  padding: 2px 4px;
}

#mem-dump {
  font-family: 'VT323', monospace;
  font-size: 13px;
  color: #33ff33;
  background: #0a0a0a;
  border: 1px solid #333;
  padding: 6px;
  margin-top: 6px;
  max-height: 200px;
  overflow-y: auto;
  white-space: pre;
  line-height: 1.4;
}

footer {
  text-align: center;
  padding: 15px 0;
  margin-top: 20px;
  border-top: 1px solid #333;
  font-size: 15px;
  color: #666;
}

footer a {
  color: #33ff33;
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

.disclaimer {
  font-size: 13px;
  color: #555;
  margin-top: 4px;
}

/* Responsive */
@media (max-width: 800px) {
  #crt-screen, #canvas {
    width: 320px;
    height: 320px;
  }
  #crt-bezel {
    border-width: 8px;
    padding: 5px;
  }
  #main-area {
    flex-direction: column;
    align-items: center;
  }
  #side-panels { min-width: unset; width: 100%; }
  .debug-grid {
    grid-template-columns: 1fr;
  }
  .kb-key {
    min-width: 26px;
    height: 28px;
    font-size: 11px;
    padding: 0 2px;
  }
  .kb-key.space-key { min-width: 200px; }
  .rom-slot label { min-width: unset; }
  header h1 { font-size: 13px; }
}