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

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

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

#header {
  text-align: center;
  margin-bottom: 4px;
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 10px 0 4px;
}

.title-block {
  display: flex;
  flex-direction: column;
  align-items: center;
}

#header h1 {
  font-family: 'Press Start 2P', monospace;
  font-size: 18px;
  color: #fff;
  text-shadow: 0 0 20px rgba(0,215,215,0.5), 2px 2px 0 #000;
  letter-spacing: 1px;
}

.subtitle {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: #00D7D7;
  margin-top: 4px;
  text-shadow: 0 0 10px rgba(0,215,215,0.3);
}

.berry-badge {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  background: rgba(255,255,255,0.1);
  padding: 4px 8px;
  border-radius: 4px;
  color: #ff6b9d;
}

.rainbow-stripe {
  display: flex;
  height: 6px;
  margin: 4px 0 8px;
  border-radius: 3px;
  overflow: hidden;
}
.rainbow-stripe span { flex: 1; }
.rainbow-stripe span:nth-child(1) { background: #D70000; }
.rainbow-stripe span:nth-child(2) { background: #FF6600; }
.rainbow-stripe span:nth-child(3) { background: #D7D700; }
.rainbow-stripe span:nth-child(4) { background: #00D700; }
.rainbow-stripe span:nth-child(5) { background: #00D7D7; }
.rainbow-stripe span:nth-child(6) { background: #0000D7; }
.rainbow-stripe span:nth-child(7) { background: #D700D7; }
.rainbow-stripe span:nth-child(8) { background: #8800AA; }

#toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: linear-gradient(180deg, #2a2a3e 0%, #1e1e30 100%);
  border: 1px solid #3a3a55;
  border-radius: 6px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

#toolbar button {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  padding: 6px 10px;
  border: 2px outset #555;
  background: linear-gradient(180deg, #4a4a6a 0%, #35355a 100%);
  color: #ddd;
  cursor: pointer;
  border-radius: 3px;
  white-space: nowrap;
  transition: all 0.1s;
}

#toolbar button:hover {
  background: linear-gradient(180deg, #5a5a7a 0%, #45456a 100%);
  color: #fff;
}

#toolbar button:active { border-style: inset; }

.speed-control {
  display: flex;
  align-items: center;
  gap: 4px;
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
}

.speed-control select {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  padding: 4px;
  background: #1a1a2e;
  color: #00D7D7;
  border: 1px solid #3a3a55;
  border-radius: 3px;
}

.accuracy-badge {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  color: #00FF00;
  background: rgba(0,255,0,0.1);
  padding: 3px 6px;
  border-radius: 3px;
  border: 1px solid rgba(0,255,0,0.3);
}

.status-running {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  margin-left: auto;
  white-space: nowrap;
}

#main-area {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

#display-container { flex-shrink: 0; }

#crt-wrapper {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  box-shadow:
    0 0 30px rgba(0, 0, 0, 0.8),
    0 0 60px rgba(0, 100, 200, 0.15),
    inset 0 0 30px rgba(0, 0, 0, 0.3);
  border: 3px solid #222;
  background: #000;
}

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

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

#debug-panel {
  flex: 1;
  min-width: 280px;
  max-width: 380px;
  background: #111122;
  border: 1px solid #2a2a44;
  border-radius: 6px;
  padding: 8px;
  max-height: 600px;
  overflow-y: auto;
  font-size: 11px;
}

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

.debug-section {
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid #222244;
}

.debug-section h3 {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: #00D7D7;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.flag-label {
  font-size: 6px;
  color: #666;
}

.reg-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2px 8px;
  font-size: 11px;
}

.reg-grid .reg-item {
  display: flex;
  justify-content: space-between;
  gap: 4px;
}

.reg-grid .reg-name { color: #888; }
.reg-grid .reg-val { color: #00FF00; font-weight: 700; }

.internal-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px 8px;
  font-size: 10px;
}

.internal-grid .reg-item {
  display: flex;
  justify-content: space-between;
  gap: 4px;
}

.internal-grid .reg-name { color: #D7D700; font-size: 9px; }
.internal-grid .reg-val { color: #00D7D7; font-weight: 700; }

.flag-grid {
  display: flex;
  gap: 4px;
  font-size: 10px;
  flex-wrap: wrap;
}

.flag-grid .flag-item {
  padding: 2px 4px;
  border-radius: 2px;
  font-size: 9px;
}
.flag-grid .flag-on { background: #003300; color: #00FF00; }
.flag-grid .flag-off { background: #1a1a2e; color: #444; }

.disasm-list { font-size: 10px; line-height: 1.5; }
.disasm-list .disasm-line { display: flex; gap: 8px; }
.disasm-list .disasm-addr { color: #D7D700; min-width: 40px; }
.disasm-list .disasm-bytes { color: #555; min-width: 70px; }
.disasm-list .disasm-mnem { color: #D7D7D7; }
.disasm-list .disasm-current { background: #222244; }

.mem-input {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  width: 50px;
  background: #1a1a2e;
  border: 1px solid #3a3a55;
  color: #00D7D7;
  padding: 2px 4px;
  border-radius: 2px;
  text-transform: uppercase;
}

.mem-dump {
  font-size: 9px;
  line-height: 1.4;
  white-space: pre;
  color: #aaa;
  overflow-x: auto;
}

.status-line {
  font-size: 9px;
  color: #888;
  font-family: 'JetBrains Mono', monospace;
}

#keyboard-container {
  margin-top: 8px;
  padding: 8px;
  background: linear-gradient(180deg, #2a2a2a 0%, #1a1a1a 100%);
  border-radius: 8px;
  border: 2px solid #333;
}

#keyboard {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-width: 700px;
  margin: 0 auto;
}

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

.kb-key {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  padding: 6px 4px;
  min-width: 42px;
  text-align: center;
  background: linear-gradient(180deg, #444 0%, #2a2a2a 100%);
  color: #ccc;
  border: 1px solid #555;
  border-radius: 4px;
  cursor: pointer;
  user-select: none;
  transition: all 0.05s;
  line-height: 1.3;
}

.kb-key:hover {
  background: linear-gradient(180deg, #555 0%, #3a3a3a 100%);
}

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

.kb-key .kb-main { display: block; font-size: 8px; }
.kb-key.wide { min-width: 70px; }
.kb-key.space { min-width: 200px; }

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

footer a {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: #555;
  text-decoration: none;
  transition: color 0.2s;
}
footer a:hover { color: #00D7D7; }

@media (max-width: 900px) {
  #canvas { width: 352px; height: 296px; }
  #main-area { flex-direction: column; align-items: stretch; }
  #debug-panel { max-width: 100%; }
  #header h1 { font-size: 12px; }
  .kb-key { min-width: 30px; font-size: 6px; padding: 4px 2px; }
  .kb-key .kb-main { font-size: 6px; }
  .kb-key.space { min-width: 120px; }
}

#debug-panel::-webkit-scrollbar { width: 6px; }
#debug-panel::-webkit-scrollbar-track { background: #111; }
#debug-panel::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }