:root {
  --pcb: #0e3826; --bg: #050505; --panel: #0a0a0c; --text: #d8d8d8; --dim: #888;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100vh; width: 100vw;
  background: var(--bg); color: var(--text);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px; overflow: hidden; }
header {
  height: 44px; padding: 0 14px;
  background: linear-gradient(180deg, #1a1a1a, #0a0a0a);
  border-bottom: 1px solid #222;
  display: flex; align-items: center; gap: 14px;
}
header h1 { font-size: 14px; margin: 0; font-weight: 600; letter-spacing: 0.06em; }
header h1 span { color: #00ff88; }
header .status { margin-left: auto; color: #aaa; font-size: 12px; }
header .status.ok { color: #00ff88; }
header .status.err { color: #ff6b6b; }
header button {
  background: #1a1a1a; color: #ddd; border: 1px solid #333;
  padding: 5px 12px; border-radius: 3px; cursor: pointer;
  font-family: inherit; font-size: 12px;
}
header button:hover { background: #2a2a2a; }

main { display: grid; grid-template-columns: 1fr 440px;
       grid-template-rows: 1fr 116px;
       height: calc(100vh - 44px); }
.control-panel {
  grid-column: 1 / -1;
  background: #050505;
  border-top: 1px solid #1a1a1a;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.control-panel svg { width: 100%; max-width: 1000px; height: 110px; }
.control-panel .ctl-key {
  cursor: pointer;
  transition: filter 0.08s;
}
.control-panel .ctl-key:hover { filter: brightness(1.3); }
.control-panel .ctl-key.held { filter: brightness(1.6) drop-shadow(0 0 6px #00ff88); }
.board { position: relative; overflow: hidden; background: var(--pcb);
  background-image:
    radial-gradient(circle at 20% 30%, rgba(255,255,255,0.03), transparent 40%),
    radial-gradient(circle at 80% 70%, rgba(0,0,0,0.2), transparent 50%);
}
.board canvas#pcb { position: absolute; inset: 0; width: 100%; height: 100%; }
.chips { position: absolute; inset: 0; pointer-events: none; }

/* Live CRT monitor floating over the PCB (upper-right area) */
.crt-monitor {
  position: absolute;
  top: 6%; right: 4%;
  width: 16%;
  z-index: 5;
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center;
  pointer-events: auto;
  transition: transform 0.12s, filter 0.12s;
}
.crt-monitor:hover { transform: scale(1.02); filter: brightness(1.08); }
.crt-frame {
  width: 100%;
  background: #050505;
  border: 2px solid #1a1a1a;
  border-radius: 4px;
  box-shadow: 0 0 14px rgba(0,0,0,0.6), inset 0 0 12px rgba(0,0,0,0.6);
  padding: 8px;
}
.crt-frame canvas#crt-canvas {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
}
.crt-label {
  margin-top: 6px;
  color: #888;
  font-size: 10px;
  letter-spacing: 0.04em;
  text-align: center;
}
.chip {
  position: absolute; pointer-events: auto;
  background: linear-gradient(180deg, #1f1f1f, #0a0a0a);
  border: 1px solid #2a2a2a; color: #e6e6e6;
  font-family: inherit; font-size: 10px; line-height: 1.15;
  padding: 6px 6px 4px; cursor: pointer; border-radius: 2px;
  text-align: center; box-shadow: 2px 3px 0 rgba(0,0,0,0.4);
  transition: border-color 0.12s, box-shadow 0.12s;
}
.chip:hover { border-color: #555; }
.chip.selected {
  border-color: #00ff88;
  box-shadow: 2px 3px 0 rgba(0,0,0,0.4), 0 0 12px rgba(0,255,136,0.4);
}
.chip.active {
  border-color: #ffd56b;
  box-shadow: 2px 3px 0 rgba(0,0,0,0.4), 0 0 14px rgba(255,213,107,0.6);
}
.chip.write {
  border-color: #ff6b6b;
  box-shadow: 2px 3px 0 rgba(0,0,0,0.4), 0 0 14px rgba(255,107,107,0.6);
}
.chip.missing { color: #555; border-style: dashed; cursor: not-allowed; }
.chip .name { font-weight: 600; color: #f0f0f0; }
.chip .role { color: #888; margin-top: 2px; font-size: 9px; }
.chip .size { color: #6ab7ff; font-size: 9px; margin-top: 1px; }
.chip.missing .name, .chip.missing .role, .chip.missing .size { color: #444; }
.chip .led {
  width: 5px; height: 5px; border-radius: 50%;
  background: #1a3a2a; position: absolute; top: 4px; right: 4px;
}
.chip.loaded .led { background: #00ff88; box-shadow: 0 0 6px #00ff88; }
.chip .pins-top, .chip .pins-bot {
  position: absolute; left: 6px; right: 6px; height: 4px;
  display: flex; justify-content: space-between;
}
.chip .pins-top { top: -4px; } .chip .pins-bot { bottom: -4px; }
.chip .pin { width: 3px; height: 4px; background: #c0c0c0; }

aside.detail {
  background: var(--panel); border-left: 1px solid #1a1a1a;
  display: flex; flex-direction: column; overflow: hidden;
}
aside.detail header.dh {
  height: 40px; padding: 0 14px; background: #050505;
  border-bottom: 1px solid #1a1a1a;
  display: flex; align-items: center; gap: 8px;
}
aside.detail header.dh h2 { font-size: 12px; margin: 0; color: #00ff88; font-weight: 600; }
aside.detail header.dh .sub { color: #888; font-size: 11px; }
aside.detail .body { flex: 1; overflow: auto; padding: 12px 14px; }
aside.detail .body h3 {
  color: #ddd; font-size: 11px; margin: 0 0 8px; font-weight: 600;
  letter-spacing: 0.05em; text-transform: uppercase;
}
aside.detail .body p { color: #aaa; font-size: 11.5px; line-height: 1.5; margin: 6px 0 14px; }
aside.detail .body code { background: #1a1a1a; padding: 1px 4px; border-radius: 2px;
  color: #ffd56b; font-size: 11px; }
aside.detail .swatch { display: inline-block; width: 28px; height: 28px; margin: 2px;
  border: 1px solid #000; vertical-align: middle; position: relative; }
aside.detail .swatch .ix { position: absolute; top: -1px; left: 2px; font-size: 8px;
  color: rgba(255,255,255,0.7); text-shadow: 0 0 2px #000; }
aside.detail .hex {
  font-family: ui-monospace, monospace; font-size: 10.5px;
  color: #ccc; white-space: pre; line-height: 1.4;
  background: #050505; padding: 8px; border-radius: 3px;
  border: 1px solid #1a1a1a; max-height: 380px; overflow: auto;
}
aside.detail canvas { background: #050505; border: 1px solid #1a1a1a;
  image-rendering: pixelated; image-rendering: crisp-edges; }
aside.detail .toolbar {
  display: flex; gap: 6px; align-items: center; margin: 4px 0 10px;
  flex-wrap: wrap; font-size: 11px; color: #aaa;
}
aside.detail .toolbar select, aside.detail .toolbar button {
  background: #1a1a1a; color: #ddd; border: 1px solid #333;
  padding: 3px 8px; border-radius: 2px; font-family: inherit; font-size: 11px;
}

.drop-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: none; align-items: center; justify-content: center;
  z-index: 1000; pointer-events: none;
  border: 4px dashed #00ff88;
  color: #00ff88; font-size: 24px; font-weight: 600;
}
.drop-overlay.active { display: flex; }
.empty-state {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: #aaa; font-size: 14px; text-align: center;
  background: rgba(0,0,0,0.5); pointer-events: none;
}
.empty-state.hidden { display: none; }
.empty-state .inner {
  background: #0a0a0a; padding: 30px 40px; border-radius: 6px;
  border: 1px solid #333; max-width: 480px;
}
.empty-state .inner h2 { color: #00ff88; margin-top: 0; font-size: 16px; }
.empty-state .inner code { color: #ffd56b; background: #1a1a1a; padding: 1px 6px; border-radius: 3px; }
.empty-state .inner .hint { color: #888; font-size: 12px; margin-top: 14px; }

.z80-live { display: grid; gap: 10px; }
.z80-live .ctl {
  display: flex; gap: 6px; align-items: center; flex-wrap: wrap;
  padding: 8px; background: #050505; border-radius: 3px; border: 1px solid #1a1a1a;
}
.z80-live .ctl button {
  background: #1a1a1a; color: #ddd; border: 1px solid #333;
  padding: 4px 10px; border-radius: 2px; cursor: pointer;
  font-family: inherit; font-size: 11px;
}
.z80-live .ctl button.run { background: #00ff88; color: #000; border-color: #00ff88; }
.z80-live .ctl input[type=range] { width: 120px; }
.z80-live .regs {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px;
  font-size: 11.5px; background: #050505; padding: 8px;
  border-radius: 3px; border: 1px solid #1a1a1a;
}
.z80-live .regs .r { display: flex; justify-content: space-between; }
.z80-live .regs .name { color: #888; }
.z80-live .regs .val { color: #ffd56b; font-weight: 600; }
.z80-live .flags { display: flex; gap: 4px; font-size: 10px;
  background: #050505; padding: 6px 8px; border-radius: 3px; border: 1px solid #1a1a1a; }
.z80-live .flag { padding: 2px 5px; border-radius: 2px; background: #1a1a1a; color: #555; }
.z80-live .flag.on { background: #00ff88; color: #000; font-weight: 600; }
.z80-live .disasm {
  background: #050505; padding: 8px; border-radius: 3px; border: 1px solid #1a1a1a;
  font-size: 11px; line-height: 1.45; white