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

body {
  background: #0a0a0e;
  color: #c0c0c0;
  font-family: 'Share Tech Mono', monospace;
  min-height: 100vh;
  overflow-x: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
}

#top-bar {
  width: 100%;
  max-width: 1200px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  background: #1a1a24;
  border-bottom: 1px solid #333;
  flex-wrap: wrap;
  gap: 8px;
}

#title-area h1 {
  font-size: 20px;
  color: #fff;
  letter-spacing: 2px;
  text-transform: uppercase;
}

#rainbow-stripe {
  height: 4px;
  margin-top: 4px;
  background: linear-gradient(90deg,
    #0000D7, #D70000, #D700D7, #00D700, #00D7D7, #D7D700, #D7D7D7
  );
  border-radius: 2px;
}

#toolbar {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

#toolbar button {
  background: #2a2a3a;
  color: #c0c0c0;
  border: 1px solid #444;
  padding: 4px 10px;
  font-family: 'Share Tech Mono', monospace;
  font-size: 12px;
  cursor: pointer;
  border-radius: 3px;
  transition: all 0.15s;
  white-space: nowrap;
}

#toolbar button:hover {
  background: #3a3a5a;
  color: #fff;
  border-color: #666;
}

#toolbar button.active {
  background: #D70000;
  color: #fff;
  border-color: #ff4444;
}

#main-area {
  display: flex;
  gap: 16px;
  padding: 16px;
  align-items: flex-start;
  justify-content: center;
  flex-wrap: wrap;
}

#screen-bezel {
  background: #1c1c1c;
  border: 8px solid #2a2a2a;
  border-radius: 12px;
  box-shadow:
    0 0 30px rgba(0,0,0,0.8),
    inset 0 0 20px rgba(0,0,0,0.5),
    0 0 60px rgba(50,50,80,0.15);
  position: relative;
  overflow: hidden;
  line-height: 0;
}

#canvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  width: 816px;
  height: 624px;
}

@media (max-width: 900px) {
  #canvas {
    width: 544px;
    height: 416px;
  }
}

@media (max-width: 600px) {
  #canvas {
    width: 272px;
    height: 208px;
  }
}

#crt-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 2px,
      rgba(0,0,0,0.08) 2px,
      rgba(0,0,0,0.08) 4px
    );
  mix-blend-mode: multiply;
  z-index: 2;
}

#crt-overlay.disabled {
  display: none;
}

/* Debug Panel */
#debug-panel {
  background: #0d0d0d;
  border: 1px solid #1a3a1a;
  border-radius: 4px;
  padding: 12px;
  width: 320px;
  max-height: 80vh;
  overflow-y: auto;
  color: #33ff33;
  font-size: 11px;
  line-height: 1.4;
}

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

#debug-panel h3 {
  color: #66ff66;
  margin: 8px 0 4px 0;
  font-size: 12px;
  border-bottom: 1px solid #1a3a1a;
  padding-bottom: 2px;
}

#debug-panel h3:first-child {
  margin-top: 0;
}

#debug-registers, #debug-flags, #debug-disasm, #debug-memory, #debug-counters {
  font-family: 'Share Tech Mono', monospace;
  white-space: pre;
  margin-bottom: 4px;
}

#debug-controls {
  display: flex;
  gap: 4px;
  margin: 8px 0;
}

#debug-controls button {
  background: #1a3a1a;
  color: #33ff33;
  border: 1px solid #336633;
  padding: 3px 8px;
  font-family: 'Share Tech Mono', monospace;
  font-size: 11px;
  cursor: pointer;
  border-radius: 2px;
}

#debug-controls button:hover {
  background: #2a5a2a;
}

#mem-addr {
  background: #0a0a0a;
  color: #33ff33;
  border: 1px solid #336633;
  padding: 3px 6px;
  font-family: 'Share Tech Mono', monospace;
  font-size: 11px;
  width: 100%;
  margin-bottom: 4px;
}

/* On-screen Keyboard */
#keyboard-overlay {
  width: 100%;
  max-width: 860px;
  padding: 8px 16px;
}

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

#spectrum-keyboard {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

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

.kb-key {
  background: linear-gradient(180deg, #4a4a4a, #2a2a2a);
  color: #fff;
  border: 1px solid #555;
  border-radius: 4px;
  padding: 4px 2px;
  min-width: 60px;
  text-align: center;
  cursor: pointer;
  user-select: none;
  font-family: 'Share Tech Mono', monospace;
  font-size: 13px;
  line-height: 1.2;
  transition: all 0.1s;
}

.kb-key:active, .kb-key.pressed {
  background: linear-gradient(180deg, #6a6a7a, #3a3a5a);
  transform: translateY(1px);
  border-color: #888;
}

.kb-key .main-label {
  font-weight: bold;
  font-size: 14px;
}

.kb-key .keyword-label {
  font-size: 8px;
  color: #D70000;
  display: block;
  margin-top: 1px;
}

.kb-key .symbol-label {
  font-size: 8px;
  color: #D70000;
  display: block;
}

/* Load Modal */
#load-modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

#load-modal.hidden {
  display: none;
}

#load-content {
  background: #1a1a24;
  border: 2px solid #444;
  border-radius: 8px;
  padding: 24px;
  max-width: 500px;
  width: 90%;
}

#load-content h3 {
  color: #fff;
  margin-bottom: 16px;
  font-size: 16px;
}

#demo-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.demo-btn {
  background: #2a2a3a;
  color: #c0c0c0;
  border: 1px solid #444;
  padding: 8px 12px;
  font-family: 'Share Tech Mono', monospace;
  font-size: 13px;
  cursor: pointer;
  border-radius: 4px;
  text-align: left;
}

.demo-btn:hover {
  background: #3a3a5a;
  color: #fff;
}

#file-drop-zone {
  border: 2px dashed #444;
  border-radius: 6px;
  padding: 20px;
  text-align: center;
  margin-bottom: 16px;
  color: #888;
}

#file-drop-zone.drag-over {
  border-color: #00D7D7;
  color: #00D7D7;
}

#file-input {
  margin-top: 8px;
}

#btn-close-load {
  background: #D70000;
  color: #fff;
  border: none;
  padding: 8px 20px;
  font-family: 'Share Tech Mono', monospace;
  cursor: pointer;
  border-radius: 4px;
}

footer {
  padding: 16px;
  text-align: center;
}

#remix-link {
  background: linear-gradient(90deg, #0000D7, #D70000, #D700D7, #00D700, #00D7D7, #D7D700, #D7D7D7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-decoration: none;
  font-family: 'Share Tech Mono', monospace;
  font-size: 13px;
}

#remix-link:hover {
  opacity: 0.8;
}

/* Power-on CRT animation */
@keyframes crt-poweron {
  0% {
    transform: scaleY(0.005) scaleX(0.3);
    filter: brightness(3);
  }
  30% {
    transform: scaleY(0.005) scaleX(1);
    filter: brightness(3);
  }
  50% {
    transform: scaleY(1) scaleX(1);
    filter: brightness(1.5);
  }
  100% {
    transform: scaleY(1) scaleX(1);
    filter: brightness(1);
  }
}

#canvas.poweron {
  animation: crt-poweron 0.8s ease-out;
}