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

body {
  background: #0d0d1a;
  color: #c0c0d0;
  font-family: 'JetBrains Mono', monospace;
  min-height: 100vh;
  overflow-x: hidden;
}

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

header {
  background: linear-gradient(135deg, #0a0a1a 0%, #1a1a3a 100%);
  border-bottom: 2px solid #21C842;
  padding: 10px 20px;
  text-align: center;
}

header h1 {
  font-family: 'Press Start 2P', cursive;
  font-size: 16px;
  color: #42EBF5;
  text-shadow: 0 0 10px rgba(66,235,245,0.5);
  letter-spacing: 2px;
}

.subtitle {
  font-size: 9px;
  color: #5EDC78;
  margin-top: 4px;
  font-family: 'Press Start 2P', cursive;
}

#mode-tabs {
  display: flex; justify-content: center; gap: 8px; margin-bottom: 8px;
}

.mode-tab {
  font-family: 'Press Start 2P', cursive; font-size: 10px;
  padding: 8px 16px; border-radius: 6px; cursor: pointer;
  background: linear-gradient(180deg, #1a1a30, #0f0f20);
  border: 2px solid #444; color: #888;
  transition: all 0.2s;
}

.mode-tab:hover { border-color: #666; color: #aaa; }

.mode-tab.active {
  background: linear-gradient(180deg, #2a3a5a, #1a2a4a);
  border-color: #42EBF5; color: #42EBF5;
  box-shadow: 0 0 12px rgba(66,235,245,0.3);
}

#main-layout { display: flex; flex: 1; gap: 0; }

#display-area {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; padding: 16px;
  background: radial-gradient(ellipse at center, #1a1a2e 0%, #0d0d1a 70%);
}

#crt-frame {
  background: linear-gradient(145deg, #2a2a3a, #1a1a25);
  border-radius: 20px; padding: 14px;
  box-shadow: 0 0 30px rgba(0,0,0,0.8), inset 0 0 20px rgba(0,0,0,0.5);
  border: 2px solid #333;
}

#crt-screen {
  position: relative; border-radius: 8px; overflow: hidden;
  background: #000; box-shadow: inset 0 0 40px rgba(0,0,0,0.8);
}

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

#scanlines {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  pointer-events: none;
  background: repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(0,0,0,0.15) 2px, rgba(0,0,0,0.15) 4px);
  opacity: 0; transition: opacity 0.3s;
}
#scanlines.active { opacity: 1; }

#controls {
  margin-top: 12px; display: flex; flex-direction: column;
  gap: 8px; width: 100%; max-width: 684px;
}

.control-row {
  display: flex; align-items: center; gap: 8px;
  flex-wrap: wrap; justify-content: center;
}

.sram-row {
  background: rgba(33, 176, 59, 0.08);
  border: 1px solid rgba(33, 176, 59, 0.25);
  border-radius: 6px; padding: 6px 10px;
}

.tape-row {
  background: rgba(212, 82, 77, 0.08);
  border: 1px solid rgba(212, 82, 77, 0.25);
  border-radius: 6px; padding: 6px 10px;
}

.tape-btn {
  background: linear-gradient(180deg, #3a2a1a, #2a1a0a) !important;
  border-color: #D4524D !important; color: #FF7978 !important; font-size: 10px !important;
}
.tape-btn:hover { background: #D4524D !important; color: #fff !important; }

.tape-status { font-size: 9px; color: #FF7978; font-family: 'Press Start 2P', cursive; }

.timing-row {
  background: rgba(66, 235, 245, 0.08);
  border: 1px solid rgba(66, 235, 245, 0.25);
  border-radius: 6px; padding: 6px 10px;
}

.corrupt-row {
  background: rgba(252, 85, 84, 0.08);
  border: 1px solid rgba(252, 85, 84, 0.25);
  border-radius: 6px; padding: 6px 10px;
}

.corrupt-btn {
  background: linear-gradient(180deg, #3a1a1a, #2a0a0a) !important;
  border-color: #FC5554 !important; color: #FF7978 !important; font-size: 10px !important;
}
.corrupt-btn:hover { background: #FC5554 !important; color: #fff !important; }

.corrupt-status { font-size: 9px; color: #FC5554; font-family: 'Press Start 2P', cursive; }

#corrupt-amount {
  background: #1a1a30; border: 1px solid #FC5554; color: #FF7978;
  padding: 4px 8px; border-radius: 4px;
  font-family: 'JetBrains Mono', monospace; font-size: 11px;
}

#tape-progress-container {
  width: 100%; max-width: 684px; margin-top: 4px; text-align: center;
}

#tape-progress-bar {
  width: 100%; height: 6px; background: #1a1a30; border-radius: 3px;
  border: 1px solid #333; overflow: hidden;
}

#tape-progress-fill {
  height: 100%; width: 0%; background: linear-gradient(90deg, #D4524D, #FF7978);
  transition: width 0.2s;
}

.tape-progress-text { font-size: 14px; }

.sram-btn {
  background: linear-gradient(180deg, #1a3a2a, #0a2a1a) !important;
  border-color: #21B03B !important; color: #5EDC78 !important; font-size: 10px !important;
}
.sram-btn:hover { background: #21B03B !important; color: #000 !important; }
.sram-status { font-size: 9px; color: #5EDC78; font-family: 'Press Start 2P', cursive; }

.file-btn {
  display: inline-flex; align-items: center; gap: 4px;
  background: linear-gradient(180deg, #2a4a3a, #1a3a2a);
  border: 2px solid #21C842; color: #5EDC78; padding: 6px 14px;
  border-radius: 6px; cursor: pointer;
  font-family: 'Press Start 2P', cursive; font-size: 9px; transition: all 0.15s;
}
.file-btn:hover { background: #21C842; color: #000; }

.ctrl-btn {
  background: linear-gradient(180deg, #2a2a40, #1a1a30);
  border: 2px solid #5455ED; color: #7D76FC; padding: 6px 12px;
  border-radius: 6px; cursor: pointer; font-size: 14px;
  transition: all 0.15s; font-family: 'JetBrains Mono', monospace;
}
.ctrl-btn:hover { background: #5455ED; color: #fff; }
.ctrl-btn:active { transform: translateY(1px); }

.ctrl-label {
  display: flex; align-items: center; gap: 6px;
  font-family: 'Press Start 2P', cursive; font-size: 8px; color: #888;
}

select, input[type="range"] {
  background: #1a1a30; border: 1px solid #444; color: #c0c0d0;
  padding: 4px; border-radius: 4px; font-family: 'JetBrains Mono', monospace;
}
input[type="range"] { width: 80px; accent-color: #42EBF5; }

#gamepads-container { margin-top: 14px; display: flex; align-items: flex-start; gap: 20px; justify-content: center; }
.gamepad-wrapper { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.gamepad-label {
  font-family: 'Press Start 2P', cursive; font-size: 10px; color: #42EBF5;
  padding: 2px 10px; border: 1px solid #42EBF5; border-radius: 4px; background: rgba(66,235,245,0.08);
}
#gamepad { display: flex; align-items: center; gap: 40px; }
#dpad { display: flex; flex-direction: column; align-items: center; }
.dpad-mid { display: flex; align-items: center; }
.dpad-btn {
  width: 44px; height: 44px; background: linear-gradient(180deg, #333, #222);
  border: 2px solid #555; color: #aaa; font-size: 16px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all 0.1s; user-select: none;
}
.dpad-btn:active, .dpad-btn.pressed { background: #5455ED; color: #fff; border-color: #7D76FC; }
.dpad-center { width: 44px; height: 44px; background: #2a2a2a; border: 2px solid #444; }
#action-btns { display: flex; gap: 16px; }
.action-btn {
  width: 56px; height: 56px; border-radius: 50%;
  background: linear-gradient(180deg, #D4524D, #a03030);
  border: 3px solid #FC5554; color: #fff;
  font-family: 'Press Start 2P', cursive; font-size: 12px;
  cursor: pointer; transition: all 0.1s; user-select: none;
}
.action-btn:active, .action-btn.pressed { background: #FC5554; box-shadow: 0 0 15px rgba(252,85,84,0.6); transform: scale(0.95); }

#spectrum-keyboard {
  margin-top: 14px;
  display: flex; flex-direction: column; gap: 4px;
  align-items: center;
  max-width: 680px;
}

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

.zx-key {
  min-width: 52px; height: 40px; padding: 2px 4px;
  background: linear-gradient(180deg, #444, #2a2a2a);
  border: 2px solid #666; border-radius: 4px;
  color: #eee; cursor: pointer; transition: all 0.1s;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  user-select: none; font-family: 'Press Start 2P', cursive;
}

.zx-key:active, .zx-key.pressed {
  background: #D70000; border-color: #FF0000; color: #fff;
  box-shadow: 0 0 8px rgba(215,0,0,0.5);
}

.zx-key-wide { min-width: 68px; }
.zx-key-space { min-width: 120px; }

.zx-shift:active, .zx-shift.pressed { background: #D700D7; border-color: #FF00FF; }
.zx-sym:active, .zx-sym.pressed { background: #0000D7; border-color: #0000FF; }

.zx-main { font-size: 9px; font-weight: bold; }
.zx-kw { font-size: 6px; color: #999; margin-top: 1px; }

#key-hints {
  margin-top: 8px; font-size: 8px; color: #666;
  font-family: 'Press Start 2P', cursive; text-align: center;
}

#debug-panel {
  width: 320px; background: #0f0f1f;
  border-left: 2px solid #333; overflow-y: auto;
  max-height: calc(100vh - 100px); flex-shrink: 0;
}

.debug-header {
  background: #1a1a30; padding: 10px 14px; cursor: pointer;
  display: flex; justify-content: space-between; align-items: center;
  font-family: 'Press Start 2P', cursive; font-size: 10px;
  color: #42EBF5; border-bottom: 1px solid #333;
  position: sticky; top: 0; z-index: 2;
}

#debug-content { padding: 10px; }
#debug-content.collapsed { display: none; }

.debug-section { margin-bottom: 12px; }
.debug-section h3 {
  font-family: 'Press Start 2P', cursive; font-size: 8px;
  color: #D4C154; margin-bottom: 6px; border-bottom: 1px solid #333; padding-bottom: 4px;
}
.debug-section pre {
  font-size: 10px; line-height: 1.5; color: #c0d0c0; white-space: pre-wrap; word-break: break-all;
}

#flags-display { display: flex; gap: 6px; flex-wrap: wrap; }
.flag-indicator {
  padding: 2px 6px; border-radius: 3px; font-size: 10px; font-weight: bold;
  border: 1px solid #444; background: #1a1a1a; color: #666;
}
.flag-indicator.active { background: #21C842; color: #000; border-color: #5EDC78; }

.bp-row { display: flex; gap: 6px; align-items: center; margin-bottom: 4px; }
#bp-input, #mem-addr {
  background: #1a1a30; border: 1px solid #444; color: #42EBF5;
  padding: 4px 8px; border-radius: 4px;
  font-family: 'JetBrains Mono', monospace; font-size: 12px; width: 60px;
}
#bp-status { font-size: 10px; color: #888; }
#mem-select { margin-bottom: 4px; font-size: 11px; }
#mem-display { font-size: 9px; max-height: 200px; overflow-y: auto; color: #aaa; }

#status-bar {
  background: #0a0a18; border-top: 2px solid #333;
  padding: 6px 16px; display: flex; gap: 16px;
  font-size: 9px; font-family: 'Press Start 2P', cursive; color: #666; flex-wrap: wrap;
}
#status-state { color: #FC5554; }
#status-state.running { color: #21C842; animation: pulse 1.5s infinite; }
#status-state.paused { color: #D4C154; }
#mem-map-info { color: #5455ED; font-size: 8px; }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.6; } }

footer {
  background: #0a0a18; padding: 10px 20px;
  text-align: center; font-size: 9px; color: #444;
  display: flex; justify-content: center; gap: 20px;
  font-family: 'Press Start 2P', cursive;
}
footer a { color: #42EBF5; text-decoration: none; }
footer a:hover { text-decoration: underline; }

.dis-addr { color: #21C842; }
.dis-hex { color: #7D76FC; }
.dis-mnemonic { color: #42EBF5; }
.dis-current { background: #2a2a40; display: block; }
.dis-label { color: #555; font-size: 10px; }

@media (max-width: 1100px) {
  #main-layout { flex-direction: column; }
  #debug-panel { width: 100%; border-left: none; border-top: 2px solid #333; max-height: 400px; }
  #screen { width: 100% !important; max-width: 512px; height: auto !important; }
}

@media (max-width: 600px) {
  header h1 { font-size: 11px; }
  .subtitle { font-size: 7px; }
  #display-area { padding: 8px; }
  #crt-frame { padding: 6px; border-radius: 10px; }
  #screen { max-width: 100% !important; }
  .mode-tab { font-size: 8px; padding: 6px 10px; }
  .zx-key { min-width: 28px; height: 32px; }
  .zx-key-wide { min-width: 40px; }
  .zx-key-space { min-width: 70px; }
  .zx-main { font-size: 7px; }
  .zx-kw { display: none; }
  #key-hints { display: none; }
  #status-bar { font-size: 7px; gap: 8px; }
}