@font-face {
  font-family: "LS Mono";
  src: url("fonts/DejaVuSansMono-Bold.ttf") format("truetype");
  font-weight: bold;
  font-display: block;
}

:root {
  --page: #0b0e13;
  --panel: #161b24;
  --panel-2: #1b212c;
  --ink: #e8ebf0;
  --muted: #9aa3b2;
  --line: #2a3140;
  --accent: #5fa8ff;
  --screen-bg: #14181f;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  --pc: #3a3410;
  --pc-ink: #f2e35b;
  --bp: #e5484d;
  --changed: #5a2a12;
  --ok: #7ee787;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  min-width: 1100px;          /* desktop browsers only */
  background: var(--page);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
}
.top h1 { margin: 0; font-size: 18px; font-weight: 700; white-space: nowrap; }
.top h1 span { color: var(--muted); font-weight: 400; }
.buttons { display: flex; gap: 8px; }
.acct { flex: 1; margin: 0; font-size: 14px; color: var(--muted); text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acct.on { color: var(--ok); }

button {
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 14px;
  cursor: pointer;
  white-space: nowrap;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.45; cursor: default; }
button[aria-pressed="true"] { background: #1f3354; border-color: #3b6ff0; }
button.primary { background: #1d4ed8; border-color: #3b6ff0; }
button.primary:hover:not(:disabled) { background: #2458e8; }

main {
  flex: 1;
  display: flex;
  min-height: 0;
  padding: 12px 16px 12px;
}

.workspace { flex: 1; display: flex; gap: 14px; min-height: 0; min-width: 0; }
.screen-side { flex: 1; min-width: 420px; display: flex; flex-direction: column; gap: 8px; }

.monitor {
  position: relative;
  flex: 1;
  min-height: 240px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--page);
}
.monitor:fullscreen { background: #000; }

#screen {
  display: block;
  background: var(--screen-bg);
  border-radius: 4px;
  outline: none;
  box-shadow: 0 0 0 1px var(--line);
}
.monitor:focus-within #screen { box-shadow: 0 0 0 2px var(--accent); }

/* The keyboard: an invisible text box over the screen that collects keys and pasted text. */
#keyboard {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  resize: none;
  border: 0;
  padding: 0;
  font-size: 16px;
  caret-color: transparent;
  cursor: default;
}

.power {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  padding: 16px;
}
.power p { margin: 0; color: var(--muted); }
.power p:only-of-type { max-width: 32em; }
.power:has(#btn-start[hidden]) { background: rgba(11, 14, 19, 0.85); }   /* CPU halted: readable over the screen */
.power:has(#btn-start[hidden]) p { color: var(--ink); }
#btn-start {
  font-size: 20px;
  padding: 14px 28px;
  background: #1d4ed8;
  border-color: #3b6ff0;
}
#btn-start:hover { background: #2458e8; }

.focus-hint {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  padding: 4px 12px;
  border-radius: 4px;
  font-size: 14px;
  pointer-events: none;
}

.keys { margin: 0; color: var(--muted); font-size: 14px; text-align: center; }
kbd {
  font: 12px/1 var(--mono);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 2px 5px;
  color: var(--ink);
}

/* ---------- Machine Code Workbench ---------- */
.workbench {
  flex: none;
  width: clamp(640px, 54vw, 980px);
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  font: 13px/1.45 var(--mono);
}
.wb-tabs { display: flex; gap: 4px; }
.wb-tabs button { padding: 4px 16px; font: 600 13px system-ui, -apple-system, "Segoe UI", sans-serif; border-radius: 6px 6px 0 0; }
.wb-tabs button[aria-selected="true"] { background: #1f3354; border-color: #3b6ff0; }
.wb-grid { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- Fieldbus ---------- */
.fieldbus { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; }
.fb-connect { flex: none; }
.fb-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.fb-row label { display: flex; align-items: center; gap: 5px; color: var(--muted); font: 13px system-ui, -apple-system, "Segoe UI", sans-serif; }
.fb-row input, .fb-row select {
  font: 13px var(--mono); color: var(--ink); background: var(--page);
  border: 1px solid var(--line); border-radius: 4px; padding: 3px 6px;
}
#fb-host { width: 13em; } #fb-port { width: 5em; } #fb-unit { width: 3.5em; }
.fb-row input:disabled { opacity: 0.45; }
.fb-row button { padding: 4px 12px; font-size: 13px; }
.fb-light { width: 12px; height: 12px; border-radius: 50%; background: #3a4252; box-shadow: 0 0 0 1px #000 inset; }
.fb-light.ok { background: #3fb950; box-shadow: 0 0 8px #3fb950; }
.fb-light.busy { background: #f2c94c; }
.fb-light.bad { background: #e5484d; box-shadow: 0 0 8px #e5484d; }
.fb-status { font-weight: 700; }
.fb-polls b { color: var(--ok); }
.fb-tables { flex: 3 1 0; min-height: 0; display: grid; grid-template-columns: 3fr 2fr; gap: 10px; }
.fb-table { width: 100%; border-collapse: collapse; font: 12px/1.35 var(--mono); }
.fb-table th { position: sticky; top: 0; background: var(--panel); text-align: left; color: var(--muted); font-weight: 400; padding: 2px 6px; border-bottom: 1px solid var(--line); }
.fb-table td { padding: 1px 6px; border-bottom: 1px solid #1a202b; white-space: nowrap; }
.fb-table td.num { text-align: right; }
.fb-table tr.named td:last-child { color: #cfe3ff; }
.fb-table tr.flash td { background: #2b3a1c; }
.fb-table .on { color: var(--ok); font-weight: 700; }
.fb-log-panel { flex: 2 1 0; }
.fb-log { flex: 1; min-height: 0; margin: 0; overflow: auto; border-top: 1px solid var(--line); font: 12px/1.45 var(--mono); white-space: pre; color: #c8cfdb; }
.fb-log .req { color: #9cc3ff; }
.fb-log .rep { color: #9be38f; }
.fb-log .exc { color: #ff8a8a; }
.wb-col { display: flex; flex-direction: column; gap: 10px; min-height: 0; min-width: 0; }
.wb-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.wb-head { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; flex-wrap: wrap; }
.wb-head h2 { margin: 0 6px 0 0; font: 600 14px/1.3 system-ui, -apple-system, "Segoe UI", sans-serif; }
.wb-head button { padding: 3px 10px; font-size: 13px; }
.hint { color: var(--muted); font: 12px/1.3 system-ui, -apple-system, "Segoe UI", sans-serif; }

.source-panel { flex: 5 1 0; }
.listing-panel { flex: 3 1 0; }
.stack-panel { flex: 2 1 0; }
.debugger-panel { flex: none; }
.disasm-panel { flex: 4 1 0; }
.memory-panel { flex: 3 1 0; }

.src-name, .mem-addr {
  font: 13px var(--mono);
  color: var(--ink);
  background: var(--page);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 3px 6px;
  width: 9em;
}
.mem-addr { width: 7em; }

.editor {
  flex: 1;
  min-height: 0;
  display: flex;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--page);
  overflow: hidden;
}
.gutter, #source {
  margin: 0;
  font: 13px/18px var(--mono);
  padding: 6px 0;
}
.gutter {
  flex: none;
  width: 3.6em;
  padding-right: 8px;
  text-align: right;
  color: #56607a;
  background: #10141b;
  border-right: 1px solid var(--line);
  overflow: hidden;
  user-select: none;
}
.gutter .err { color: #fff; background: #7a1f24; display: inline-block; width: 100%; }
.gutter .pc { color: var(--pc-ink); background: var(--pc); display: inline-block; width: 100%; }
#source {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: none;
  resize: none;
  color: var(--ink);
  background: transparent;
  padding-left: 8px;
  white-space: pre;
  overflow: auto;
  tab-size: 8;
}
.asm-msg { margin-top: 6px; font: 12px/1.4 var(--mono); white-space: pre-wrap; max-height: 6.5em; overflow: auto; }
.asm-msg .err { color: #ff8a8a; cursor: pointer; }
.asm-msg .err:hover { text-decoration: underline; }
.asm-msg .warn { color: #f2c94c; }
.asm-msg .ok { color: var(--ok); }

.rows { flex: 1; min-height: 0; overflow: auto; border-top: 1px solid var(--line); }
.row { display: grid; padding: 0 4px; white-space: pre; cursor: default; border-bottom: 1px solid #1a202b; }
.row.code { cursor: pointer; }
.row.code:hover { background: #1c2330; }
.row .bp { color: transparent; }
.row.has-bp .bp { color: var(--bp); }
.row.code:hover:not(.has-bp) .bp { color: #5a2a2c; }
.row.at-pc { background: var(--pc); color: var(--pc-ink); }
.row .addr { color: var(--muted); }
.row.at-pc .addr { color: var(--pc-ink); }
.row .label { color: #7fa4ff; }
.row .cmt { color: #6b7488; }
#listing .row { grid-template-columns: 1.2em 3.6em 7.2em 1fr; }
#disasm .row { grid-template-columns: 1.2em 3.6em 6.6em 1fr; }
#stack-rows .row { grid-template-columns: 4.2em 3em 3em 1fr; }
#stack-rows .row.sp { color: var(--pc-ink); }
#stack-rows .row.sp .val, #stack-rows .row.sp .dec { opacity: 0.45; }

.dbg-status { font: 600 12px var(--mono); padding: 1px 8px; border-radius: 10px; background: #232a36; color: var(--muted); }
.dbg-status.paused { background: var(--pc); color: var(--pc-ink); }
.dbg-status.running { background: #13361f; color: var(--ok); }
.dbg-status.wait { background: #1f3354; color: #9cc3ff; }
.controls { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.controls button { padding: 4px 10px; font-size: 13px; }
.regs { display: grid; grid-template-columns: repeat(5, auto); justify-content: start; gap: 2px 14px; }
.regs span { cursor: help; }
.regs b { color: var(--muted); font-weight: 400; }
.flags { display: flex; gap: 4px; margin: 8px 0 6px; }
.flags span {
  width: 1.9em;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 3px;
  color: #4a5368;
  padding: 1px 0;
}
.flags span.on { background: #1f4d2b; border-color: #3fb950; color: #c9f7d0; font-weight: 700; }
.cycles { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.cycles span { color: var(--ink); min-width: 7em; }
.cycles button { padding: 2px 8px; font-size: 12px; }

.memory { flex: 1; min-height: 0; overflow: hidden; border-top: 1px solid var(--line); white-space: pre; user-select: text; }
.memory .mrow { padding: 0 4px; }
.memory .addr { color: var(--muted); }
.memory .chg { background: var(--changed); color: #ffd2a8; }
.memory .asc { color: #9be38f; }
.memory .pcb { outline: 1px solid var(--pc-ink); }

/* ---------- dialogs ---------- */
.panel {
  width: min(640px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px 20px 20px;
}
.panel::backdrop { background: rgba(0, 0, 0, 0.6); }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin: 0; }
.panel-head h2 { margin: 0; font-size: 18px; }
.panel-head button { font-size: 20px; line-height: 1; padding: 2px 10px; }
.panel code { font-family: var(--mono); color: #cfe3ff; }
.muted { color: var(--muted); font-size: 14px; }
a { color: var(--accent); }
.guest-note { font-size: 14px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 8px 12px; }
.join-actions { display: flex; gap: 10px; margin: 18px 0 12px; }
a.button { display: inline-block; font-size: 14px; color: var(--ink); text-decoration: none; background: var(--panel);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 14px; }
a.button:hover { border-color: var(--accent); }
a.button.primary { background: #1d4ed8; border-color: #3b6ff0; }

.file-list { width: 100%; border-collapse: collapse; font-size: 14px; }
.file-list th { text-align: left; color: var(--muted); font-weight: 400; border-bottom: 1px solid var(--line); padding: 4px 6px; }
.file-list td { border-bottom: 1px solid var(--line); padding: 6px; }
.file-list td:first-child { font-family: var(--mono); }
.file-list td:last-child { text-align: right; white-space: nowrap; }
.file-list td button { padding: 3px 10px; font-size: 13px; margin-left: 4px; }
.file-list:not(:has(tbody tr)) { display: none; }

.upload { display: inline-block; margin-top: 14px; font-size: 14px; }
.upload input { display: block; margin-top: 6px; color: var(--muted); }

.license {
  font: 12px/1.45 var(--mono);
  white-space: pre-wrap;
  background: var(--page);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  max-height: 50vh;
  overflow: auto;
}
.top h1 a { color: inherit; text-decoration: none; }
