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

:root {
  --bg-dark: #0a0a1a;
  --bg-panel: #1a1a2e;
  --bg-darker: #0d0d1a;
  --green: #00ff41;
  --green-dim: #00aa2a;
  --amber: #ffb000;
  --cyan: #0ff;
  --red: #ff3333;
  --text: #e0e0e0;
  --key-bg: #3a3a3a;
  --key-border: #555;
  --key-active: #00ff4133;
}

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

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

/* Header */
.header {
  text-align: center;
  padding: 15px 0 10px;
  border-bottom: 1px solid #333;
  margin-bottom: 10px;
}
.header h1 {
  font-family: 'Press Start 2P', monospace;
  font-size: 20px;
  color: var(--green);
  text-shadow: 0 0 10px var(--green), 0 0 20px var(--green-dim);
  letter-spacing: 2px;
  margin-bottom: 6px;
}
.header .subtitle {
  font-size: 10px;
  color: var(--amber);
  letter-spacing: 1px;
  opacity: 0.8;
}

/* Toolbar */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 8px 12px;
  background: var(--bg-panel);
  border-radius: 6px;
  margin-bottom: 10px;
  border: 1px solid #333;
}
.toolbar button, .toolbar label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  padding: 6px 14px;
  border: 1px solid #555;
  border-radius: 4px;
  background: linear-gradient(180deg, #444, #2a2a2a);
  color: var(--green);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.toolbar button:hover, .toolbar label:hover {
  background: linear-gradient(180deg, #555, #3a3a3a);
  border-color: var(--green);
  box-shadow: 0 0 5px var(--green-dim);
}
.toolbar button:active {
  transform: scale(0.97);
}
.toolbar button.active {
  background: linear-gradient(180deg, #003300, #001a00);
  border-color: var(--green);
  box-shadow: 0 0 8px var(--green-dim);
}
.toolbar .info {
  font-size: 10px;
  color: #999;
  margin-left: auto;
}
.toolbar .mode-badge {
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 3px;
  background: #222;
  border: 1px solid var(--amber);
  color: var(--amber);
}

/* Toast */
.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 10px 18px;
  background: #1a3a1a;
  border: 1px solid var(--green);
  border-radius: 6px;
  color: var(--green);
  font-size: 12px;
  z-index: 999;
  animation: toastIn 0.3s ease, toastOut 0.3s ease 2.5s forwards;
  box-shadow: 0 0 15px rgba(0, 255, 65, 0.2);
}
@keyframes toastIn { from { opacity: 0; transform: translateX(30px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; } }

/* CRT Screen */
.crt-container {
  position: relative;
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
}
.crt-frame {
  position: relative;
  background: #111;
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 0 30px rgba(0, 255, 65, 0.08), inset 0 0 40px rgba(0, 0, 0, 0.8);
  border: 2px solid #2a2a2a;
}
.crt-frame canvas {
  display: block;
  border-radius: 8px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.crt-overlay {
  position: absolute;
  top: 16px; left: 16px; right: 16px; bottom: 16px;
  border-radius: 8px;
  pointer-events: none;
  background:
    repeating-linear-gradient(0deg, rgba(0,0,0,0.12) 0px, rgba(0,0,0,0.12) 1px, transparent 1px, transparent 3px),
    radial-gradient(ellipse at center, transparent 60%, rgba(0,0,0,0.4) 100%);
  z-index: 2;
}

/* Keyboard */
.keyboard {
  background: #2a2a2a;
  border-radius: 10px;
  padding: 12px;
  border: 2px solid #444;
  margin-bottom: 10px;
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.5);
}
.keyboard-row {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin-bottom: 4px;
}
.key {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 500;
  min-width: 36px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #4a4a4a, #333);
  border: 1px solid #666;
  border-bottom: 3px solid #222;
  border-radius: 4px;
  color: #e0e0e0;
  cursor: pointer;
  user-select: none;
  transition: all 0.08s;
  padding: 0 6px;
}
.key:hover {
  background: linear-gradient(180deg, #5a5a5a, #444);
}
.key.pressed {
  background: linear-gradient(180deg, #333, #4a4a4a);
  border-bottom: 1px solid #222;
  border-top: 3px solid #222;
  box-shadow: 0 0 8px var(--green-dim);
  color: var(--green);
}
.key.wide { min-width: 56px; }
.key.wider { min-width: 72px; }
.key.space { min-width: 220px; }

/* Debug Panel */
.debug-toggle {
  text-align: center;
  margin-bottom: 8px;
}
.debug-toggle button {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  padding: 5px 20px;
  border: 1px solid #444;
  border-radius: 4px;
  background: var(--bg-panel);
  color: var(--amber);
  cursor: pointer;
}
.debug-panel {
  background: var(--bg-darker);
  border: 1px solid #333;
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 12px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  font-size: 11px;
  color: var(--green);
  max-height: 400px;
  overflow-y: auto;
}
.debug-section {
  background: #0a0a14;
  border: 1px solid #2a2a2a;
  border-radius: 4px;
  padding: 8px;
}
.debug-section h3 {
  font-size: 11px;
  color: var(--amber);
  margin-bottom: 6px;
  border-bottom: 1px solid #333;
  padding-bottom: 4px;
}
.debug-section .reg {
  display: inline-block;
  margin-right: 10px;
  white-space: nowrap;
}
.debug-section .reg .label { color: #888; }
.debug-section .reg .value { color: var(--green); }
.debug-section .flags span { margin-right: 4px; }
.debug-section .flags .set { color: var(--green); font-weight: 700; }
.debug-section .flags .clear { color: #444; }

.disasm-line {
  white-space: pre;
  font-size: 10px;
  line-height: 1.5;
}
.disasm-line.current {
  background: #002200;
  color: var(--green);
}

.memory-input {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  background: #111;
  border: 1px solid #444;
  color: var(--green);
  padding: 3px 6px;
  border-radius: 3px;
  width: 80px;
  margin-bottom: 6px;
}
.hex-dump {
  font-size: 9px;
  line-height: 1.4;
  white-space: pre;
  overflow-x: auto;
  max-height: 200px;
}

/* Memory Map */
.memmap {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 12px;
}
.memmap-bar {
  height: 8px;
  border-radius: 2px;
  position: relative;
}
.memmap-label {
  font-size: 8px;
  color: #888;
}

/* Footer */
.footer {
  text-align: center;
  padding: 15px;
  font-size: 11px;
  color: #555;
  border-top: 1px solid #222;
}
.footer a {
  color: var(--green);
  text-decoration: none;
}
.footer a:hover { text-decoration: underline; }

/* Breakpoint input */
.bp-input {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  background: #111;
  border: 1px solid #444;
  color: var(--amber);
  padding: 3px 6px;
  border-radius: 3px;
  width: 80px;
}
.bp-btn {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  background: #222;
  border: 1px solid #555;
  color: var(--amber);
  padding: 2px 8px;
  border-radius: 3px;
  cursor: pointer;
  margin-left: 4px;
}

@media (max-width: 768px) {
  .header h1 { font-size: 14px; }
  .debug-panel { grid-template-columns: 1fr; }
  .key { min-width: 28px; height: 28px; font-size: 9px; }
  .key.wide { min-width: 42px; }
  .key.wider { min-width: 56px; }
  .key.space { min-width: 140px; }
  .crt-frame { padding: 8px; }
}