/* multi-cpu-emu IDE — "bench instrument" theme.
 *
 * Design intent: a workbench instrument, not a SaaS dashboard.
 * One memorable element: the phosphor-green PC trace (gutter + editor +
 * register change highlights all speak the same green). Everything else
 * stays quiet: deep charcoal panels, hairline borders, flat controls.
 * Type: system UI for chrome, one mono stack for all machine data.
 */
:root {
  color-scheme: dark;
  --bg: #0c0e11;
  --bg-2: #101318;
  --panel: #14171d;
  --panel-2: #191d25;
  --inset: #0b0d11;
  --border: #242a34;
  --border-soft: #1c212a;
  --text: #cfd6e0;
  --bright: #eef2f7;
  --muted: #7d8694;
  --faint: #4c545f;
  --accent: #4c9aff;
  --trace: #43ff8f;
  --trace-dim: rgba(67, 255, 143, .10);
  --changed: #f0a93a;
  --red: #ff5d5d;
  --yellow: #e3c14b;
  --radius: 8px;
  --radius-sm: 5px;
  --font-ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "Cascadia Code", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui); font-size: 13.5px; line-height: 1.5;
  display: flex; flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
/* machine-data surfaces stay monospace */
#editor, #gutter, #hl, .screen, .hex, #disasmView, .rreg .v, .watchrow,
#memview, .flag, kbd, .about code, #ac .w, #romload input, #memmap,
.dev .mono, #ports .port, #peripherals .sfr, #statusbar b, #watchInput, #memaddr, #z80memBase {
  font-family: var(--mono);
}

/* ================= toolbar ================= */
header {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 7px 14px; background: var(--panel); border-bottom: 1px solid var(--border);
  row-gap: 8px;
}
.run-group { margin-inline: auto; }
.util-group { margin-left: auto; }
.run-group + .util-group { margin-left: 0; }
.docs-link { font-size: 12px; padding: 4px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--muted); text-decoration: none; }
.docs-link:hover { color: var(--bright); border-color: var(--faint); }
@media (max-width: 900px) {
  .run-group, .util-group { margin-left: 0; }
}
header > * { flex: none; }
header .logo { font-weight: 700; color: var(--bright); font-size: 13.5px; margin-right: 6px; white-space: nowrap; }
header .logo small { color: var(--faint); font-weight: 400; }
@media (max-width: 560px) { header .logo small { display: none; } }
.hgroup { display: flex; align-items: center; gap: 5px; }
.hsep { width: 1px; height: 22px; background: var(--border); margin: 0 4px; flex: none; }
select, button, input {
  font: inherit; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 4px 10px; cursor: pointer;
  font-size: 12.5px;
}
button:hover:not(:disabled) { border-color: var(--faint); color: var(--bright); }
header label { font-size: 11.5px; color: var(--muted); display: flex; align-items: center; gap: 5px; }
header select { padding: 3px 6px; font-size: 12px; }
button:disabled { opacity: .35; cursor: default; }
/* Run controls read as one instrument cluster: Run is the single filled key. */
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover:not(:disabled) { background: #63a8ff; border-color: #63a8ff; color: #fff; }
#runBtn:not(:disabled) { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
#runBtn:not(:disabled):hover { background: #63a8ff; }
button.danger { background: var(--red); border-color: var(--red); color: #fff; }
header .spacer { flex: 1; }
[id^="intrBar"] { align-items: center; gap: 4px; white-space: nowrap; }
/* Visible IRQ bars lay out as a flex row; an inline display:none (set by
   app.js when switching ISAs) still wins because this rule is not !important. */
[id^="intrBar"]:not([style*="none"]) { display: inline-flex; }
#statusbar {
  padding: 5px 14px; background: var(--panel); border-top: 1px solid var(--border);
  display: flex; gap: 20px; font-size: 12px; color: var(--muted); flex-wrap: wrap;
}
#statusbar b { color: var(--text); font-weight: 600; font-family: var(--mono); font-size: 11.5px; }

body { overflow-x: hidden; }
main {
  flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 480px;
  gap: 10px; padding: 10px 14px; min-height: 0; max-width: 1720px; width: 100%; margin: 0 auto;
  overflow-x: clip;
}
@media (max-width: 1100px) { main { grid-template-columns: minmax(0, 1fr) 420px; } }
@media (max-width: 960px) { main { grid-template-columns: 1fr; overflow-y: auto; } }
@media (max-width: 768px) {
  header { gap: 4px; }
  main { padding: 8px; }
  .tabs { overflow-x: auto; flex-wrap: nowrap; }
  .tabs .tab { flex: none; padding: 6px 10px; }
  #edwrap { min-height: 300px; }
  #gutter { width: 96px; }
}
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.panel h2 {
  margin: 0; padding: 9px 14px; font-size: 11px; letter-spacing: 1.2px; text-transform: uppercase;
  color: var(--muted); border-bottom: 1px solid var(--border-soft);
  display: flex; align-items: center; gap: 8px; font-weight: 600;
}
.panel h2 .hint { margin-left: auto; font-weight: 400; letter-spacing: 0; text-transform: none; font-size: 11.5px; }

/* ================= editor ================= */
#edwrap { position: relative; flex: 1; display: flex; min-height: 420px; }
#gutter {
  width: 150px; overflow: hidden; background: var(--inset); border-right: 1px solid var(--border-soft);
  color: var(--faint); text-align: right; padding: 10px 8px 10px 4px; user-select: none; flex: none;
  font-family: var(--mono);
}
#gutter div { height: 21px; line-height: 21px; font-size: 11.5px; white-space: nowrap; }
#gutter div.err { background: var(--red); color: #fff; border-radius: 4px 0 0 4px; font-weight: 700; }
#gutter div[data-addr] { cursor: pointer; }
#gutter div[data-addr]:hover { background: rgba(255,255,255,.05); }
#gutter div.bp { box-shadow: inset 3px 0 0 var(--red); }
#gutter div.cbp { box-shadow: inset 3px 0 0 var(--changed); }
#gutter div.cpc { background: var(--trace-dim); }
#gutter div.cpc .n { color: var(--trace); }
#gutter .n[data-addr] { cursor: pointer; }
#gutter .n[data-addr]:hover { color: var(--accent); }
#gutter .n { color: var(--faint); }
#gutter .c { margin-left: 8px; color: #3f6b4f; font-size: 10.5px; }
#gutter div.err .c { color: #ffd9d9; }
#edbox { position: relative; flex: 1; display: flex; min-width: 0; background: var(--inset); }
/* The PC trace: editor line, gutter cell and disassembly row share one green. */
#hl {
  position: absolute; inset: 0; margin: 0; padding: 10px 14px; overflow: hidden;
  line-height: 21px; font-size: 13px; font-family: var(--mono); white-space: pre;
  pointer-events: none; color: #9fb3c8;
}
#hl .c { color: var(--faint); font-style: italic; }
#hl .s { color: #e3c07d; }
#hl .n { color: #e8934b; }
#hl .m { color: #8fb8e8; }
#hl .r { color: #b394e6; }
#hl .l { color: #6fce82; }
#hl .y { color: #5f6b7d; }
#hl .hl { height: 21px; line-height: 21px; }
#hl .hl.pc { background: var(--trace-dim); box-shadow: inset 3px 0 0 var(--trace); }
#editor {
  position: relative; flex: 1; resize: none; background: transparent; border: none; outline: none;
  color: transparent; caret-color: var(--trace);
  padding: 10px 14px; line-height: 21px; font-size: 13px; font-family: var(--mono); white-space: pre;
}
#editor::selection { background: rgba(76, 154, 255, .25); }
#errors {
  border-top: 1px solid var(--border); max-height: 90px; overflow-y: auto;
  padding: 8px 14px; font-size: 12.5px; display: none;
}
#errors .errline { color: var(--red); font-family: var(--mono); }
#errors .errmsg { color: var(--text); }

/* ================= right column ================= */
.right { display: flex; flex-direction: column; gap: 10px; min-height: 0; overflow-y: auto; min-width: 0; }
/* Tabs read as one segmented strip, not separate pills. */
.tabs { display: flex; gap: 0; flex: none; padding: 3px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
.tabs .tab {
  background: transparent; border: none; border-radius: var(--radius-sm);
  padding: 6px 4px; color: var(--muted); font-size: 12px; font-weight: 500; flex: 1; text-align: center;
}
.tabs .tab:hover { color: var(--text); }
.tabs .tab.active { background: var(--panel-2); color: var(--bright); box-shadow: inset 0 0 0 1px var(--border); }
.tabs .tab.hidden { display: none; }
.tabgroup { display: none; flex-direction: column; gap: 10px; min-height: 0; }
.tabgroup.active { display: flex; }
.rgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 12px; }
@media (max-width: 480px) { .rgrid { grid-template-columns: repeat(2, 1fr); } }
/* Register groups share one card style; the group label carries the meaning. */
.rgrid .rlabel { grid-column: 1 / -1; font-size: 10px; letter-spacing: 1.2px; text-transform: uppercase; color: var(--faint); margin: 6px 0 -2px; }
.rgrid .rlabel:first-child { margin-top: 0; }
#ports { display: flex; flex-wrap: wrap; gap: 5px; padding: 12px; }
#ports .port {
  font: 600 11px/1.9 var(--mono); padding: 0 7px; border-radius: 4px;
  background: var(--inset); border: 1px solid var(--border);
  color: var(--muted); cursor: pointer; user-select: none;
}
#ports .port:hover { border-color: var(--accent); color: var(--accent); }
#ports .port.set { color: var(--trace); border-color: rgba(67, 255, 143, .4); }
.led { display: inline-block; padding: 1px 7px; border-radius: 4px; font-family: var(--mono); font-size: 11px; color: var(--muted); border: 1px solid var(--border); background: var(--inset); }
.led.on { color: #0b0d11; background: var(--trace); border-color: var(--trace); }
#sidBtn.on, #irqTrap.on { color: #0b0d11; background: var(--trace); border-color: var(--trace); }
.hex { width: 100%; font-family: var(--mono); font-size: 12px; line-height: 1.4; background: var(--inset); color: var(--text); border: 1px solid var(--border); border-radius: 4px; }
#peripherals { display: flex; flex-wrap: wrap; gap: 5px; padding: 12px; }
#peripherals .sfr {
  font: 600 11px/1.9 var(--mono); padding: 0 7px; border-radius: 4px;
  background: var(--inset); border: 1px solid var(--border);
  color: var(--muted); cursor: pointer; user-select: none;
}
#peripherals .sfr:hover { border-color: var(--accent); color: var(--accent); }
#peripherals .hint { font-weight: 400; color: var(--muted); width: 100%; font-size: 12px; }
.rreg { background: var(--inset); border: 1px solid var(--border-soft); border-radius: 6px; padding: 6px 9px; min-width: 0; }
.rreg .n { color: var(--muted); font-size: 10.5px; letter-spacing: .6px; }
.rreg .v { font-size: 15px; font-weight: 600; color: var(--bright); letter-spacing: .5px; }
.rreg .v.sub { font-size: 10px; color: var(--faint); font-weight: 400; }
.rreg.pc { border-color: rgba(67, 255, 143, .45); }
.rreg.pc .v { color: var(--trace); }
.rreg.changed { border-color: var(--changed); }
.rreg.changed .v { color: var(--changed); }
#disasmView { margin: 0; padding: 8px; max-height: 340px; overflow: auto; font-size: 12px; line-height: 1.55; cursor: text; }
#disasmView .drow { white-space: pre; padding: 1px 8px; border-radius: 4px; }
#disasmView .drow .daddr { color: var(--faint); min-width: 7ch; display: inline-block; }
#disasmView .drow .dbytes { color: #5f6b7d; }
#disasmView .drow .dtext { color: var(--text); }
#disasmView .drow.cur { background: var(--trace-dim); box-shadow: inset 3px 0 0 var(--trace); }
#disasmView .drow.cur .daddr { color: var(--trace); }
#disasmView .drow.bp { box-shadow: inset 3px 0 0 var(--red); }
#disasmView .drow.cbp { box-shadow: inset 3px 0 0 var(--changed); }
#disasmView .drow:hover { background: rgba(255,255,255,.04); }
#watchList { padding: 6px 12px 10px; font-size: 12px; }
.watchrow { display: flex; justify-content: space-between; gap: 10px; padding: 4px 2px; border-bottom: 1px solid var(--border-soft); }
.watchrow .wn { color: var(--accent); }
.watchrow .wv { color: var(--bright); font-weight: 600; }
.watchrow .wv.changed { color: var(--changed); }
.watchrow .wdel { color: var(--faint); cursor: pointer; }
.watchrow .wdel:hover { color: var(--red); }
#flags { display: flex; gap: 6px; flex-wrap: wrap; padding: 10px 12px; border-top: 1px solid var(--border-soft); }
.flag {
  padding: 3px 11px; border-radius: 999px; font-size: 11px; font-weight: 700;
  background: transparent; color: var(--faint); border: 1px solid var(--border);
}
.flag.on { background: var(--trace-dim); color: var(--trace); border-color: rgba(67, 255, 143, .45); }
#memview { padding: 10px 12px; overflow: auto; font-size: 12px; line-height: 19px; white-space: pre; color: #9fb3c8; max-height: 340px; }
#memview .hl { background: var(--trace); color: #06130c; border-radius: 3px; }
#memview .addr { color: var(--faint); }
#memview .mb { cursor: pointer; border-radius: 2px; }
#memview .mb:hover { background: rgba(76, 154, 255, .25); }
#memview .mb.ch { background: var(--changed); color: #1b1f24; }
#memtools, #z80memtools { display: flex; gap: 6px; padding: 8px 12px; align-items: center; border-bottom: 1px solid var(--border-soft); }
#memtools input { width: 110px; font-family: var(--mono); }
#memtools .info { color: var(--faint); font-size: 11.5px; margin-left: auto; }
#output { flex: 1; padding: 10px 14px; overflow: auto; white-space: pre-wrap; word-break: break-all; min-height: 80px; font-size: 13px; color: var(--bright); }
.screen { margin: 0; padding: 10px 12px; background: #020604; color: var(--trace); font-family: var(--mono); font-size: 13px; line-height: 15px; white-space: pre; overflow: auto; min-height: 384px; letter-spacing: 1px; text-shadow: 0 0 5px rgba(67,255,143,.35); }
.screen .cur { background: var(--trace); color: #000; }
#errpop {
  display: none; position: fixed; right: 16px; bottom: 44px; max-width: min(420px, calc(100vw - 32px));
  background: #17130a; border: 1px solid var(--changed); border-radius: 8px;
  padding: 10px 14px; font-size: 12.5px; z-index: 10; color: var(--text);
}
kbd { background: var(--panel-2); border: 1px solid var(--border); border-radius: 3px; padding: 1px 5px; font-size: 10.5px; color: var(--text); font-family: var(--mono); }
#helps { padding: 8px 14px; color: var(--faint); font-size: 11.5px; border-top: 1px solid var(--border-soft); line-height: 1.6; display: flex; align-items: center; gap: 0; flex-wrap: wrap; }
#helps .help-keys { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
#helps .help-sep { color: var(--border); margin: 0 8px; }
#helps .help-conv { color: var(--faint); font-size: 11px; }
#helps b { color: var(--muted); font-weight: 600; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex;
         align-items: center; justify-content: center; z-index: 50; }
.modal-box { background: var(--panel); border: 1px solid var(--border);
             border-radius: 8px; padding: 18px 22px; width: min(420px, 90vw); }
.modal-box h3 { margin: 0 0 8px; font-size: 15px; color: var(--bright); }
.modal-box p { margin: 0 0 12px; color: var(--muted); font-size: 13px; }
.modal-box input { width: 100%; box-sizing: border-box; padding: 8px; margin-bottom: 12px;
                   background: var(--inset); color: var(--text);
                   border: 1px solid var(--border); border-radius: 4px; font-size: 14px; }
.modal-buttons { display: flex; gap: 8px; }
.modal-buttons button { flex: 1; }

/* ================= devices ================= */
.dgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; padding: 12px; }
.dev {
  background: var(--panel);
  border: 1px solid var(--border-soft); border-radius: var(--radius);
  padding: 10px 12px;
}
.dev h3 {
  margin: 0 0 10px; padding-bottom: 8px; font-size: 12px; color: var(--text); font-weight: 600;
  display: flex; align-items: center; gap: 6px;
  border-bottom: 1px solid var(--border-soft);
}
.dev h3 .p { margin-left: auto; font-weight: 400; color: var(--faint); font-size: 10px; font-family: var(--mono);
  background: var(--inset); border: 1px solid var(--border-soft); padding: 1px 7px; border-radius: 999px; }
.dev-pop { margin-left: 6px; display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; border: 1px solid var(--border); background: var(--panel-2); color: var(--muted); border-radius: var(--radius-sm); cursor: pointer; font-size: 11px; line-height: 1; flex: 0 0 auto; }
.dev-pop:hover { border-color: var(--accent); color: var(--accent); }

/* popped-out device floaters */
.floater { position: fixed; z-index: 60; width: 252px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 12px 32px rgba(0,0,0,.6); }
.floater-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--border-soft); font-size: 12px; font-weight: 600; color: var(--bright); gap: 8px; }
.floater-head .fl-close { width: 20px; height: 20px; border: none; background: transparent; color: var(--muted); cursor: pointer; font-size: 13px; border-radius: var(--radius-sm); flex: 0 0 auto; }
.floater-head .fl-close:hover { background: var(--red); color: #fff; }
.floater-body { padding: 12px; max-height: 70vh; overflow: auto; }
.floater-body .dev { border: none; background: transparent; padding: 0; box-shadow: none; }
.dev .mono { font-family: var(--mono); font-size: 11px; color: #9fb3c8; line-height: 1.55; }
#romload { margin-top: 8px; font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
#romload input { width: 76px; background: var(--inset); color: var(--text); border: 1px solid var(--border); border-radius: 4px; padding: 3px 6px; font-family: var(--mono); font-size: 12px; }
#memmap { font-family: var(--mono); font-size: 11px; color: #9fb3c8; line-height: 1.6; padding: 2px 0; }
.traffic { display: flex; flex-direction: column; gap: 8px; align-items: center; padding: 6px 0; }
.lamp { width: 22px; height: 22px; border-radius: 50%; background: #22262e; box-shadow: inset 0 0 4px #000; }
.lamp.on.red { background: #ff4d4d; box-shadow: 0 0 10px #ff4d4d; }
.lamp.on.yel { background: #ffd24d; box-shadow: 0 0 10px #ffd24d; }
.lamp.on.grn { background: var(--trace); box-shadow: 0 0 10px var(--trace); }
.segs { display: flex; gap: 8px; justify-content: center; }
.sg { stroke-width: 4; stroke-linecap: round; }
.sg.on { stroke: #ff5a5a; }
.sg.off { stroke: #262b33; }
.stepper { text-align: center; }
.stp-ring { fill: none; stroke: var(--border); stroke-width: 2; }
.stp-rot { fill: var(--accent); }
.stepper .lbl { font-size: 11px; color: var(--muted); margin-top: 4px; font-family: var(--mono); }
.printer { background: #000; color: #c8ffd0; font-family: var(--mono); font-size: 12px; min-height: 60px; max-height: 90px; overflow: auto; margin: 0; padding: 6px 8px; white-space: pre-wrap; word-break: break-all; border-radius: 4px; }
.matrix { display: grid; grid-template-columns: repeat(8, 13px); grid-auto-rows: 13px; gap: 2px; justify-content: center; }
.px { background: #1a2029; border-radius: 2px; }
.px.on { background: var(--trace); box-shadow: 0 0 4px rgba(67,255,143,.7); }
.robot { display: grid; grid-template-columns: repeat(16, 10px); grid-auto-rows: 10px; gap: 1px; justify-content: center; }
.rob { background: #1a2029; border-radius: 1px; }
.rob.tr { background: #3a6ea5; }
.rob.on { background: #ffd24d; box-shadow: 0 0 5px #ffd24d; }
.gfx { image-rendering: pixelated; background: #000; border: 1px solid var(--border); border-radius: 4px; max-width: 100%; }

/* ================= about ================= */
.about { width: min(680px, 92vw); max-height: 86vh; display: flex; flex-direction: column; }
.about-head { display: flex; align-items: center; justify-content: space-between;
              border-bottom: 1px solid var(--border); padding-bottom: 10px; margin-bottom: 4px; }
.about-head h3 { margin: 0; }
.about .x { padding: 2px 10px; line-height: 1; border-radius: 6px; }
.about-body { overflow-y: auto; padding-right: 6px; }
.about-body section { margin-bottom: 16px; }
.about-body h4 { margin: 0 0 6px; color: var(--accent); font-size: 12px; letter-spacing: 1px; text-transform: uppercase; }
.about-body p, .about-body li, .about-body td, .about-body th { color: var(--text); font-size: 13px; line-height: 1.55; }
.about-body code { background: var(--inset); border: 1px solid var(--border); border-radius: 4px; padding: 0 5px;
                   font-family: var(--mono); font-size: 12px; color: #8fb8e8; }
.about-body ol, .about-body ul { margin: 6px 0; padding-left: 20px; }
.about-body .ab-tbl { width: 100%; border-collapse: collapse; margin: 6px 0; }
.about-body .ab-tbl th, .about-body .ab-tbl td { text-align: left; padding: 4px 8px;
                   border-bottom: 1px solid var(--border); vertical-align: top; }
.about-body .ab-tbl th { color: var(--muted); font-weight: 600; font-size: 11px;
                   text-transform: uppercase; letter-spacing: .5px; }
.about-body .ab-keys td:first-child { color: var(--accent); font-family: var(--mono);
                   white-space: nowrap; width: 110px; }
#ac { position: absolute; z-index: 50; background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 6px 18px rgba(0,0,0,.5); max-height: 200px; overflow: auto; min-width: 150px; font-size: 12px; }
#ac .aci { display: flex; justify-content: space-between; gap: 12px; padding: 3px 10px; cursor: pointer; }
#ac .aci .w { color: var(--bright); font-family: var(--mono); }
#ac .aci .d { color: var(--muted); }
#ac .aci.sel, #ac .aci:hover { background: var(--accent); }
#ac .aci.sel .w, #ac .aci:hover .w { color: #fff; }
#ac .aci.sel .d, #ac .aci:hover .d { color: #dbe7ff; }

/* accessibility */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 5px; }
::selection { background: rgba(76, 154, 255, .3); }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: #242a34; border-radius: 6px; border: 2px solid var(--bg); }
*::-webkit-scrollbar-thumb:hover { background: #333c4b; }
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
