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

:root {
  --bg: #111;
  --bg2: #1a1a1a;
  --text: #ccc;
  --accent: #e0e0e0;
  --zx-blue: #0000D7;
  --zx-red: #D70000;
  --zx-magenta: #D700D7;
  --zx-green: #00D700;
  --zx-cyan: #00D7D7;
  --zx-yellow: #D7D700;
  --zx-white: #D7D7D7;
  --zx-bblue: #0000FF;
  --zx-bred: #FF0000;
  --zx-bmagenta: #FF00FF;
  --zx-bgreen: #00FF00;
  --zx-bcyan: #00FFFF;
  --zx-byellow: #FFFF00;
  --zx-bwhite: #FFFFFF;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'JetBrains Mono', monospace;
  min-height: 100vh;
  overflow-x: hidden;
}

#app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 8px;
}

/* HEADER */
#header {
  text-align: center;
  padding: 12px 0 4px;
}
#header h1 {
  font-family: 'Press Start 2P', monospace;
  font-size: 20px;
  color: #fff;
  letter-spacing: 2px;
}
#header .model {
  color: var(--zx-cyan);
}
.rainbow-bar {
  display: flex;
  justify-content: center;
  gap: 0;
  margin-top: 6px;
  height: 6px;
}
.rb { flex: 1; max-width: 80px; }
.rb-blue { background: var(--zx-blue); }
.rb-red { background: var(--zx-red); }
.rb-magenta { background: var(--zx-magenta); }
.rb-green { background: var(--zx-green); }
.rb-cyan { background: var(--zx-cyan); }
.rb-yellow { background: var(--zx-yellow); }

/* TOOLBAR */
#toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 0;
  justify-content: center;
  border-bottom: 1px solid #333;
  margin-bottom: 8px;
}
#toolbar button, #toolbar select {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  background: #222;
  color: #ddd;
  border: 1px solid #444;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}
#toolbar button:hover, #toolbar select:hover {
  background: #333;
  border-color: var(--zx-cyan);
  color: #fff;
}
#toolbar button:active {
  background: #444;
  transform: scale(0.97);
}
#toolbar select { background: #222; }
#toolbar button.active {
  border-color: var(--zx-green);
  color: var(--zx-green);
}

/* MAIN AREA */
#main-area {
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: flex-start;
}

/* SCREEN */
#screen-wrap {
  position: relative;
  background: #000;
  border: 3px solid #333;
  border-radius: 6px;
  overflow: hidden;
  line-height: 0;
  flex-shrink: 0;
}
#screen {
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  width: 704px;
  height: 592px;
  display: block;
}
.scanlines {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
  background: repeating-linear-gradient(
    0deg,
    rgba(0,0,0,0) 0px,
    rgba(0,0,0,0) 1px,
    rgba(0,0,0,0.15) 1px,
    rgba(0,0,0,0.15) 2px
  );
  background-size: 100% 2px;
}
.crt-on .scanlines { opacity: 1; }
.crt-on #screen {
  filter: contrast(1.05) brightness(1.02);
}

/* DEBUG PANEL */
#debug-panel {
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 6px;
  padding: 10px;
  font-size: 11px;
  width: 280px;
  max-height: 592px;
  overflow-y: auto;
  flex-shrink: 0;
}
#debug-panel.hidden { display: none; }
#debug-panel h3 {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  color: var(--zx-yellow);
  margin: 8px 0 4px;
  border-bottom: 1px solid #333;
  padding-bottom: 4px;
}
#debug-panel h3:first-child { margin-top: 0; }
#debug-panel pre {
  font-size: 11px;
  line-height: 1.5;
  color: var(--zx-green);
  white-space: pre;
}
#flags-display {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.flag-ind {
  display: inline-block;
  padding: 2px 6px;
  font-size: 10px;
  font-weight: bold;
  border-radius: 3px;
  background: #333;
  color: #666;
}
.flag-ind.set {
  background: var(--zx-green);
  color: #000;
}
#debug-controls {
  display: flex;
  gap: 4px;
  margin-top: 8px;
}
#debug-controls button {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  background: #222;
  color: #ddd;
  border: 1px solid #444;
  padding: 4px 8px;
  border-radius: 3px;
  cursor: pointer;
}
#debug-controls button:hover {
  background: #333;
  border-color: var(--zx-cyan);
}

/* KEYBOARD */
#keyboard {
  margin-top: 10px;
  padding: 10px;
  background: #222;
  border-radius: 8px;
  border: 2px solid #333;
}
.kb-row {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin-bottom: 4px;
}
.kb-key {
  position: relative;
  width: 60px;
  height: 48px;
  background: #333;
  border: 1px solid #555;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding: 2px 3px 5px;
  user-select: none;
  transition: all 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.kb-key:hover { background: #444; border-color: #777; }
.kb-key:active, .kb-key.pressed {
  background: #555;
  border-color: var(--zx-cyan);
  transform: scale(0.96);
}
.kb-key .kw {
  font-size: 6px;
  color: #aaa;
  position: absolute;
  top: 2px;
  text-align: center;
  font-family: 'JetBrains Mono', monospace;
}
.kb-key .main-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  color: #fff;
}
.kb-key .sym {
  font-size: 7px;
  color: var(--zx-red);
  position: absolute;
  bottom: 1px;
  right: 3px;
  font-family: 'JetBrains Mono', monospace;
}
.kb-key.wide { width: 80px; }
.kb-key.shift-key { width: 72px; }

/* STATUS BAR */
#status-bar {
  display: flex;
  gap: 16px;
  justify-content: center;
  padding: 6px;
  font-size: 11px;
  color: #888;
  border-top: 1px solid #333;
  margin-top: 8px;
}
#status-cpu { color: var(--zx-green); }

/* FOOTER */
footer {
  text-align: center;
  padding: 16px 0;
  font-size: 11px;
  color: #555;
}
footer a {
  color: var(--zx-cyan);
  text-decoration: none;
}
footer a:hover { text-decoration: underline; }
footer .disclaimer {
  font-size: 9px;
  color: #444;
  margin-top: 4px;
}

/* DROP ZONE */
.drop-active #screen-wrap {
  border-color: var(--zx-cyan) !important;
  box-shadow: 0 0 20px rgba(0,215,215,0.3);
}

/* RESPONSIVE */
@media (max-width: 900px) {
  #screen { width: 100%; height: auto; }
  #screen-wrap { width: 100%; }
  #debug-panel { display: none !important; }
  .kb-key { width: 9vw; min-width: 28px; height: 40px; }
  .kb-key .main-label { font-size: 8px; }
  .kb-key .kw { font-size: 5px; }
  .kb-key.wide, .kb-key.shift-key { width: 12vw; }
}
@media (max-width: 500px) {
  #header h1 { font-size: 14px; }
  #toolbar { gap: 3px; }
  #toolbar button, #toolbar select { font-size: 10px; padding: 4px 6px; }
  .kb-key { height: 35px; }
}