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

:root {
  --zx-black: #000000;
  --zx-blue: #0000D7;
  --zx-red: #D70000;
  --zx-magenta: #D700D7;
  --zx-green: #00D700;
  --zx-cyan: #00D7D7;
  --zx-yellow: #D7D700;
  --zx-white: #D7D7D7;
  --zx-bright-blue: #0000FF;
  --zx-bright-red: #FF0000;
  --zx-bright-magenta: #FF00FF;
  --zx-bright-green: #00FF00;
  --zx-bright-cyan: #00FFFF;
  --zx-bright-yellow: #FFFF00;
  --zx-bright-white: #FFFFFF;
  --bg: #0e0e0e;
  --bg2: #1a1a1a;
  --bg3: #252525;
}

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

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

/* Header */
header {
  text-align: center;
  padding: 16px 0 0 0;
}

.title-area h1 {
  font-family: 'Press Start 2P', monospace;
  font-size: 22px;
  color: #fff;
  letter-spacing: 2px;
  text-shadow: 0 0 20px rgba(0,215,215,0.3);
}

.title-48k {
  color: var(--zx-cyan);
}

.subtitle {
  font-size: 11px;
  color: #666;
  margin-top: 4px;
  font-weight: 300;
}

.rainbow-bar {
  display: flex;
  height: 6px;
  margin: 12px auto 0;
  max-width: 400px;
  border-radius: 3px;
  overflow: hidden;
  box-shadow: 0 0 12px rgba(0,215,215,0.15);
}

.rb { flex: 1; }
.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); }

/* Screen */
.screen-section {
  margin-top: 16px;
}

.crt-bezel {
  background: #111;
  border: 3px solid #222;
  border-radius: 16px;
  padding: 16px;
  margin: 0 auto;
  max-width: fit-content;
  box-shadow: 
    inset 0 0 60px rgba(0,0,0,0.8),
    0 0 30px rgba(0,0,0,0.5),
    0 4px 20px rgba(0,0,0,0.7);
}

.crt-inner {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  background: #000;
}

#screen {
  display: block;
  width: 704px;
  height: 592px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

@media (max-width: 760px) {
  #screen {
    width: 352px;
    height: 296px;
  }
  .crt-bezel { padding: 8px; }
}

@media (max-width: 400px) {
  #screen {
    width: 100%;
    height: auto;
  }
}

.scanlines {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0,0,0,0.08) 2px,
    rgba(0,0,0,0.08) 4px
  );
  pointer-events: none;
  z-index: 2;
}

.scanlines.disabled {
  display: none;
}

.crt-bezel.crt-on .crt-inner {
  box-shadow: inset 0 0 40px rgba(0,215,0,0.03);
}

/* Controls Bar */
.controls-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
  justify-content: center;
  align-items: center;
}

.ctrl-btn {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 700;
  padding: 6px 12px;
  border: 1px solid #333;
  background: linear-gradient(180deg, #2a2a2a, #1a1a1a);
  color: #aaa;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.ctrl-btn:hover {
  background: linear-gradient(180deg, #3a3a3a, #2a2a2a);
  color: #fff;
  border-color: var(--zx-cyan);
}

.ctrl-btn:active {
  transform: scale(0.96);
}

.ctrl-btn.active {
  border-color: var(--zx-cyan);
  color: var(--zx-cyan);
  box-shadow: 0 0 8px rgba(0,215,215,0.2);
}

.file-label {
  display: inline-block;
}

.ctrl-select {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  padding: 6px 8px;
  background: #1a1a1a;
  color: #aaa;
  border: 1px solid #333;
  border-radius: 4px;
  cursor: pointer;
}

.speed-ind {
  font-size: 12px;
  font-weight: 800;
  color: var(--zx-green);
  min-width: 45px;
  text-align: center;
}

/* Virtual Keyboard */
.keyboard-section {
  margin-top: 14px;
  background: #1a1a1a;
  border: 2px solid #252525;
  border-radius: 10px;
  padding: 10px;
}

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

.kb-key {
  position: relative;
  width: 68px;
  height: 50px;
  background: linear-gradient(180deg, #2e2e2e, #1e1e1e);
  border: 1px solid #3a3a3a;
  border-bottom: 3px solid #111;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: all 0.08s;
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden;
}

.kb-key:active, .kb-key.pressed {
  background: linear-gradient(180deg, #1e1e1e, #0e0e0e);
  border-bottom: 1px solid #111;
  transform: translateY(2px);
}

.kb-key .key-keyword {
  font-family: 'JetBrains Mono', monospace;
  font-size: 7px;
  color: var(--zx-green);
  font-weight: 700;
  line-height: 1;
  margin-bottom: 1px;
}

.kb-key .key-main {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  color: #fff;
  line-height: 1;
}

.kb-key .key-symbol {
  font-family: 'JetBrains Mono', monospace;
  font-size: 7px;
  color: var(--zx-red);
  font-weight: 700;
  line-height: 1;
  margin-top: 1px;
}

.kb-key.key-wide {
  width: 90px;
}

.kb-key.key-shift {
  background: linear-gradient(180deg, #3a2020, #2a1515);
  border-color: #4a2020;
}

.kb-key.key-shift .key-main {
  font-size: 7px;
}

.kb-key.key-enter {
  background: linear-gradient(180deg, #203a20, #152a15);
  border-color: #204a20;
}

@media (max-width: 760px) {
  .kb-key {
    width: calc((100% - 36px) / 10);
    min-width: 28px;
    height: 42px;
  }
  .kb-key.key-wide {
    width: calc((100% - 36px) / 10 * 1.2);
  }
  .kb-key .key-keyword { font-size: 5px; }
  .kb-key .key-main { font-size: 7px; }
  .kb-key .key-symbol { font-size: 5px; }
}

/* Debug Section */
.debug-section {
  margin-top: 10px;
  text-align: center;
}

.debug-panel {
  margin-top: 8px;
  background: #111;
  border: 1px solid #222;
  border-radius: 6px;
  padding: 10px;
  font-size: 11px;
  text-align: left;
  max-height: 300px;
  overflow-y: auto;
}

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

.debug-registers {
  color: var(--zx-cyan);
  margin-bottom: 6px;
  word-break: break-all;
}

.debug-flags {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
}

.debug-flags .flag {
  padding: 2px 6px;
  border-radius: 3px;
  font-weight: 700;
  font-size: 10px;
}

.flag.on { background: var(--zx-green); color: #000; }
.flag.off { background: #222; color: #444; }

.debug-disasm {
  color: var(--zx-yellow);
  margin-bottom: 6px;
}

.debug-memory {
  color: #666;
  font-size: 10px;
  max-height: 120px;
  overflow-y: auto;
}

/* Footer */
footer {
  text-align: center;
  padding: 20px 0;
}

footer a {
  color: var(--zx-cyan);
  text-decoration: none;
  font-size: 12px;
  opacity: 0.6;
  transition: opacity 0.2s;
}

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

/* Loading animation */
@keyframes loading-stripes {
  0% { background-position: 0 0; }
  100% { background-position: 40px 0; }
}

.loading-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: repeating-linear-gradient(
    90deg,
    var(--zx-red) 0px,
    var(--zx-red) 4px,
    var(--zx-yellow) 4px,
    var(--zx-yellow) 8px,
    var(--zx-green) 8px,
    var(--zx-green) 12px,
    var(--zx-cyan) 12px,
    var(--zx-cyan) 16px,
    var(--zx-blue) 16px,
    var(--zx-blue) 20px
  );
  animation: loading-stripes 0.5s linear infinite;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
}

.loading-overlay span {
  background: #000;
  padding: 8px 16px;
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  color: #fff;
}