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

:root {
  --bg-dark: #0d0d1a;
  --bg-panel: #111128;
  --bg-panel-alt: #161636;
  --border: #1a1a4a;
  --ibm-blue: #0530ad;
  --ibm-blue-light: #1a5cff;
  --cga-cyan: #55FFFF;
  --cga-green: #55FF55;
  --cga-yellow: #FFFF55;
  --cga-red: #FF5555;
  --text: #c8c8d8;
  --text-dim: #6a6a8a;
  --text-bright: #e8e8ff;
  --monitor-bezel: #2a2a2e;
  --green-glow: #33ff33;
  --amber: #ffaa00;
}

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

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

/* Top Bar */
.top-bar {
  background: linear-gradient(180deg, #0a3cc2 0%, #0530ad 50%, #042a8f 100%);
  padding: 6px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 2px solid #1a50d0;
  flex-shrink: 0;
  gap: 8px;
  flex-wrap: wrap;
}

.top-bar-title {
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  letter-spacing: 0.5px;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-led {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #555;
  box-shadow: 0 0 4px #333;
  transition: all 0.3s;
}
.status-led.running { background: #33ff33; box-shadow: 0 0 8px #33ff33; }
.status-led.paused { background: #ffaa00; box-shadow: 0 0 8px #ffaa00; }
.status-led.halted { background: #ff3333; box-shadow: 0 0 8px #ff3333; }

.top-buttons {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.btn {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  font-weight: 500;
  padding: 4px 10px;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 3px;
  background: rgba(255,255,255,0.1);
  color: #fff;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn:hover { background: rgba(255,255,255,0.2); border-color: rgba(255,255,255,0.4); }
.btn:active { background: rgba(255,255,255,0.05); transform: scale(0.97); }
.btn.active { background: rgba(255,200,0,0.3); border-color: var(--amber); color: var(--amber); }

.berry-badge {
  font-size: 11px;
  color: rgba(255,255,255,0.6);
  white-space: nowrap;
}

/* Main Layout */
.main-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Sidebars */
.sidebar {
  width: 280px;
  flex-shrink: 0;
  overflow-y: auto;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sidebar.right {
  border-right: none;
  border-left: 1px solid var(--border);
}

.panel {
  background: var(--bg-panel-alt);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.panel-header {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  padding: 6px 10px;
  background: rgba(5,48,173,0.2);
  border-bottom: 1px solid var(--border);
  color: var(--cga-cyan);
  cursor: pointer;
  user-select: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.panel-body {
  padding: 8px;
  font-size: 12px;
}

/* Register display */
.reg-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px 12px;
}

.reg-row {
  display: flex;
  justify-content: space-between;
  padding: 1px 0;
  font-size: 11px;
  line-height: 1.6;
}

.reg-label {
  color: var(--text-dim);
  font-weight: 500;
  min-width: 24px;
}

.reg-value {
  color: var(--cga-green);
  font-weight: 600;
  transition: color 0.3s, background 0.3s;
}
.reg-value.changed {
  color: #111;
  background: var(--cga-yellow);
  border-radius: 2px;
  padding: 0 2px;
}

.flags-display {
  margin-top: 6px;
  font-size: 10px;
}
.flags-display .flag-labels,
.flags-display .flag-values {
  display: flex;
  gap: 4px;
  justify-content: center;
}
.flags-display .flag-labels span {
  width: 16px;
  text-align: center;
  color: var(--text-dim);
  font-weight: 600;
}
.flags-display .flag-values span {
  width: 16px;
  text-align: center;
  font-weight: 700;
}
.flag-on { color: var(--cga-green); }
.flag-off { color: #333; }

/* Disassembly */
.disasm-line {
  font-size: 10px;
  padding: 1px 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-radius: 2px;
  font-family: 'IBM Plex Mono', monospace;
}
.disasm-line.current {
  background: rgba(5,48,173,0.4);
  color: var(--cga-cyan);
  font-weight: 600;
}
.disasm-line .addr { color: var(--text-dim); }
.disasm-line .bytes { color: #666; }
.disasm-line .mnem { color: var(--cga-green); }

/* Center area */
.center-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 12px;
  overflow-y: auto;
  min-width: 0;
}

/* Monitor */
.monitor-bezel {
  background: linear-gradient(145deg, #3a3a3e, #222226);
  border-radius: 16px;
  padding: 20px 24px 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.05);
  position: relative;
  max-width: 100%;
}

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

.monitor-screen canvas {
  display: block;
  image-rendering: pixelated;
  width: 100%;
  height: auto;
}

/* Scanline overlay */
.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;
  border-radius: 8px;
}

.screen-glow {
  position: absolute;
  top: -2px; left: -2px; right: -2px; bottom: -2px;
  border-radius: 10px;
  box-shadow: inset 0 0 60px rgba(0,180,0,0.05);
  pointer-events: none;
}

.focus-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #aaa;
  font-size: 14px;
  cursor: pointer;
  border-radius: 8px;
  transition: opacity 0.3s;
}

.monitor-label {
  text-align: center;
  font-size: 10px;
  color: #777;
  margin-top: 8px;
  letter-spacing: 2px;
  font-weight: 500;
}

/* Bottom panel */
.bottom-panel {
  flex-shrink: 0;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  max-height: 220px;
}

.bottom-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
}

.bottom-tab {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  font-weight: 500;
  padding: 5px 12px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.bottom-tab.active {
  color: var(--cga-cyan);
  border-bottom-color: var(--cga-cyan);
}
.bottom-tab:hover { color: var(--text); }

.bottom-content {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
}

/* Debug log */
.debug-log {
  font-size: 11px;
  line-height: 1.5;
  color: var(--green-glow);
  font-family: 'IBM Plex Mono', monospace;
}
.debug-log .log-entry { padding: 1px 0; }
.log-cpu { color: var(--cga-cyan); }
.log-mem { color: var(--cga-green); }
.log-io { color: var(--cga-yellow); }
.log-int { color: var(--cga-red); }

/* Speed control */
.speed-control {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  font-size: 11px;
  border-bottom: 1px solid var(--border);
}
.speed-control input[type=range] {
  flex: 1;
  max-width: 200px;
  accent-color: var(--ibm-blue-light);
}
.speed-readout {
  color: var(--text-dim);
  font-size: 10px;
}
.cycle-counter {
  color: var(--cga-yellow);
  font-size: 10px;
  margin-left: auto;
}

/* Memory view */
.mem-view {
  font-size: 10px;
  line-height: 1.5;
  font-family: 'IBM Plex Mono', monospace;
}
.mem-row {
  white-space: nowrap;
}
.mem-addr { color: var(--text-dim); }
.mem-byte { color: var(--cga-green); padding: 0 1px; }
.mem-byte.written { color: var(--cga-yellow); background: rgba(255,255,0,0.1); }
.mem-ascii { color: #666; margin-left: 8px; }

.mem-jump-btns {
  display: flex;
  gap: 4px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.mem-jump-btn {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px;
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: rgba(255,255,255,0.03);
  color: var(--text-dim);
  cursor: pointer;
}
.mem-jump-btn:hover { border-color: var(--cga-cyan); color: var(--cga-cyan); }

.mem-addr-input {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  background: #0a0a1a;
  border: 1px solid var(--border);
  color: var(--cga-green);
  padding: 3px 6px;
  border-radius: 2px;
  width: 100px;
  margin-bottom: 6px;
}
.mem-addr-input:focus { outline: none; border-color: var(--cga-cyan); }

/* I/O monitor */
.io-entry {
  font-size: 10px;
  padding: 1px 0;
  font-family: 'IBM Plex Mono', monospace;
}
.io-cga { color: var(--cga-cyan); }
.io-kbd { color: var(--cga-green); }
.io-pic { color: var(--cga-red); }
.io-timer { color: var(--cga-yellow); }
.io-other { color: var(--text-dim); }

/* Devices panel */
.device-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  padding: 1px 0;
}
.device-led {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #333;
  flex-shrink: 0;
}
.device-led.active { background: var(--cga-green); box-shadow: 0 0 4px var(--cga-green); }
.device-name { color: var(--text-dim); }

/* Program loader / assembler */
.asm-textarea {
  width: 100%;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  background: #0a0a1a;
  color: var(--cga-green);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 6px;
  resize: vertical;
  min-height: 80px;
}
.asm-textarea:focus { outline: none; border-color: var(--cga-cyan); }

.preset-select {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  background: #0a0a1a;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 3px 6px;
  width: 100%;
}
.preset-select:focus { outline: none; border-color: var(--cga-cyan); }

/* Scrollbar styling */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-dark); }
::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #444; }

/* Footer */
.footer-link {
  text-align: center;
  padding: 4px;
  font-size: 10px;
}
.footer-link a {
  color: var(--text-dim);
  text-decoration: none;
}
.footer-link a:hover { color: var(--cga-cyan); }

/* Responsive */
@media (max-width: 1100px) {
  .sidebar { display: none; }
  .main-layout { flex-direction: column; }
  .center-area { padding: 8px; }
}

@media (max-width: 768px) {
  .top-bar { padding: 4px 8px; }
  .top-bar-title { font-size: 11px; }
  .btn { font-size: 10px; padding: 3px 6px; }
  .monitor-bezel { padding: 10px 12px 8px; border-radius: 10px; }
  .bottom-panel { max-height: 180px; }
}