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

body {
  background: #0d0d0d;
  color: #aaa;
  font-family: 'VT323', 'Courier New', monospace;
  min-height: 100vh;
  overflow-x: hidden;
  background-image:
    radial-gradient(ellipse at 50% 0%, rgba(51,255,51,0.03) 0%, transparent 60%),
    linear-gradient(180deg, #0d0d0d 0%, #111 100%);
}

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

header {
  text-align: center;
  padding: 15px 0 10px;
  border-bottom: 1px solid #2a2a2a;
  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), 0 0 30px rgba(51,255,51,0.15);
  letter-spacing: 2px;
}

.subtitle {
  font-size: 16px;
  color: #666;
  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: #440000;
  box-shadow: 0 0 3px #220000;
  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: #161616;
  border: 2px solid #3a3a3a;
  border-radius: 4px;
  padding: 12px;
  margin-bottom: 12px;
}

.panel-title {
  font-size: 16px;
  color: #33ff33;
  margin-bottom: 10px;
  text-align: center;
  text-shadow: 0 0 5px rgba(51,255,51,0.3);
}

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

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

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

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

.rom-input::file-selector-button {
  font-family: 'VT323', monospace;
  font-size: 14px;
  background: linear-gradient(#4a4a4a, #2a2a2a);
  color: #ccc;
  border: 2px outset #555;
  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(#2a2a2a, #1a1a1a);
  color: #444;
  border-color: #333;
  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(#4a4a4a, #2a2a2a);
  color: #ffaa00;
  border: 3px outset #555;
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.1s;
}

.btn-reset:disabled {
  color: #444;
  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: #080808;
  border: 12px solid #1a1a1a;
  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),
    0 4px 20px rgba(0,0,0,0.6);
}

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

#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.12) 1px,
    rgba(0,0,0,0.12) 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; }
}

#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: #1a1a1a;
  color: #666;
  border: 1px solid #333;
  cursor: pointer;
  border-radius: 2px;
  transition: all 0.15s;
}

.color-btn.active {
  color: #fff;
  border-color: #666;
  background: #2a2a2a;
}

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

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

#tape-counter {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  color: #33ff33;
  background: #050505;
  padding: 4px 8px;
  border: 1px solid #2a2a2a;
  text-align: center;
  margin: 6px 0;
  letter-spacing: 2px;
  text-shadow: 0 0 4px rgba(51,255,51,0.4);
}

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

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

.tape-btn:disabled {
  color: #444;
  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: #1a1a1a;
  color: #666;
  border: 1px solid #333;
  cursor: pointer;
  border-radius: 2px;
}

.baud-btn.active {
  color: #fff;
  border-color: #666;
  background: #2a2a2a;
}

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

/* Keyboard */
#keyboard-panel {
  max-width: 800px;
  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(#c8c8c8, #a0a0a0);
  color: #1a1a1a;
  border: 2px outset #d8d8d8;
  border-radius: 4px;
  cursor: pointer;
  padding: 0 5px;
  user-select: none;
  box-shadow: 0 2px 3px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.3);
  transition: all 0.05s;
  white-space: nowrap;
}

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

.kb-key.break-key {
  background: linear-gradient(#cc3333, #992222);
  color: #fff;
  border-color: #dd4444;
  min-width: 60px;
}

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

.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: #1a1a1a;
  color: #666;
  border: 1px solid #333;
  cursor: pointer;
  border-radius: 3px;
}

#btn-debug-toggle:hover {
  color: #999;
  border-color: #555;
}

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

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

.debug-section h3 {
  font-size: 16px;
  color: #33ff33;
  margin-bottom: 6px;
  text-shadow: 0 0 4px rgba(51,255,51,0.3);
}

#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: #888; margin-top: 4px; }

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

.dbg-btn:disabled { color: #444; 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: #080808;
  color: #33ff33;
  border: 1px solid #333;
  padding: 2px 4px;
}

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

/* Keyboard Matrix Debug Table */
#matrix-row-select {
  font-size: 14px;
  color: #ffaa00;
  margin-bottom: 6px;
  font-family: 'VT323', monospace;
}

#matrix-table {
  border-collapse: collapse;
  font-size: 11px;
  font-family: 'VT323', monospace;
  width: 100%;
}

#matrix-table th, #matrix-table td {
  border: 1px solid #333;
  padding: 2px 4px;
  text-align: center;
  color: #666;
  min-width: 30px;
}

#matrix-table th {
  background: #1a1a1a;
  color: #888;
}

.matrix-row-label {
  background: #1a1a1a;
  color: #888 !important;
  font-weight: bold;
}

.matrix-cell {
  background: #0a0a0a;
  transition: background 0.1s, color 0.1s;
}

.matrix-selected-row {
  background: #1a1a00 !important;
  color: #aa8800 !important;
}

.matrix-key-pressed {
  background: #002200 !important;
  color: #33ff33 !important;
}

.matrix-active {
  background: #33ff33 !important;
  color: #000 !important;
  font-weight: bold;
}

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

footer a {
  color: #33ff33;
  text-decoration: none;
  text-shadow: 0 0 4px rgba(51,255,51,0.3);
}

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

.disclaimer {
  font-size: 13px;
  color: #444;
  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; }
}