:root {
  --bg: #0e1116;
  --panel: #161b22;
  --fg: #c9d1d9;
  --muted: #8b949e;
  --accent: #58a6ff;
  --border: #30363d;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--fg);
  font: 14px/1.4 -apple-system, "Segoe UI", system-ui, sans-serif; }
body { display: flex; flex-direction: column; overflow-x: hidden; max-width: 100vw; }
header { display: flex; align-items: baseline; gap: 1rem; padding: .6rem 1rem;
  border-bottom: 1px solid var(--border); flex: 0 0 auto; }
header h1 { margin: 0; font-size: 1.1rem; color: var(--accent); }
/* Floating settings toggle (FAB) — fixed bottom-right, over the content. */
#sidebar-toggle { position: fixed; bottom: 1.25rem; right: 1.25rem; z-index: 50;
  width: 3rem; height: 3rem; border-radius: 50%; padding: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent); color: #0d1117; border: 0; font-size: 1.4rem;
  box-shadow: 0 3px 12px rgba(0, 0, 0, .5); }
#sidebar-toggle:hover { filter: brightness(1.08); }
body.sidebar-hidden #sidebar-toggle { background: var(--panel); color: var(--fg);
  border: 1px solid var(--border); }
.status { color: var(--muted); font-family: ui-monospace, monospace; }
.status.running { color: #3fb950; }
.status.error { color: #f85149; }

/* Layout: wide content stage on the LEFT + collapsible settings on the RIGHT
   (the stage is first in the DOM; `order:1` floats the sidebar to the right). */
main { flex: 1 1 auto; display: flex; gap: 1rem; padding: 1rem; min-height: 0; }
#controls { order: 1; flex: 0 0 340px; display: flex; flex-direction: column; gap: .75rem;
  overflow-y: auto; padding-right: .25rem; }
body.sidebar-hidden #controls { display: none; }

#stage { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: .75rem; }

/* The page has ONE working area at a time, switched by the header button:
   • mode-fleet (default) — the virtual-LAN lab (lan.html) fills the whole stage:
     several networked VMs, a focused console on the left, the VM list on the
     right. The primary experience.
   • mode-single — the classic single-VM workspace (terminal/canvas + the
     settings sidebar: image boot, snapshots, recipes, keys).
   No cramped panels, no empty duplicate terminal — just one big area. */
#fleet { order: 0; flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column;
  min-height: 0; border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
  background: var(--panel); }
.fleet-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  padding: .4rem .6rem; border-bottom: 1px solid var(--border); font-size: .85rem; }
.fleet-head small { color: var(--muted); }
.fleet-head a { color: var(--accent); text-decoration: none; font-size: .8rem; }
/* Quick-demo launcher in the (default) Fleet header → jumps to the single-VM
   workspace with the chosen preset applied. */
.fleet-demo { display: inline-flex; align-items: center; gap: .35rem; }
.fleet-demo select { font-size: .8rem; max-width: 14rem; background: #0d1117; color: var(--fg);
  border: 1px solid var(--border); border-radius: 4px; padding: .15rem .3rem; }
.fleet-demo button { font-size: .8rem; padding: .2rem .55rem; }
#fleet-frame { flex: 1 1 auto; width: 100%; border: 0; min-height: 0; background: var(--bg); }
#fleet-toggle { margin-left: auto; align-self: center; font: inherit; font-size: .82rem;
  cursor: pointer; background: var(--panel); color: var(--fg); border: 1px solid var(--border);
  border-radius: 6px; padding: .25rem .6rem; }
#fleet-toggle:hover { border-color: var(--accent); }

/* Mode visibility (default body class = mode-fleet, set in index.html). */
body.mode-fleet #stage,
body.mode-fleet #controls,
body.mode-fleet #sidebar-toggle { display: none; }
body.mode-single #fleet { display: none; }

/* Canvas: hidden until the guest produces a framebuffer (body.has-fb). Bounded
   so it shares the column with the terminal; the UART grows to fill when absent. */
#canvas-pane { display: none; flex: 0 1 auto; min-height: 0; flex-direction: column;
  gap: .35rem; }
body.has-fb #canvas-pane { display: flex; }
#canvas-bar { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
#canvas-wrap { position: relative; flex: 1 1 auto; min-height: 0; display: flex;
  align-items: center; justify-content: center; background: #000;
  border: 1px solid var(--border); border-radius: 6px; overflow: hidden; max-height: 58vh; }
#fb { max-width: 100%; max-height: 100%; image-rendering: pixelated; display: block; }
#canvas-wrap:fullscreen { max-height: none; background: #000; }
#canvas-wrap:fullscreen #fb { max-height: 100vh; }
.hint { position: absolute; bottom: .5rem; left: 50%; transform: translateX(-50%);
  background: rgba(13, 17, 23, .82); color: var(--muted); border: 1px solid var(--border);
  border-radius: 999px; padding: .15rem .7rem; font: 12px ui-monospace, monospace;
  pointer-events: none; opacity: 0; transition: opacity .3s; }
.hint.active { color: #3fb950; border-color: #3fb950; }

#terminal-pane { position: relative; flex: 1 1 0; min-height: 120px; background: black;
  border: 1px solid var(--border); border-radius: 6px; padding: .5rem; overflow: hidden; }
#terminal { width: 100%; height: 100%; }
.term-fs { position: absolute; top: 6px; right: 6px; z-index: 5; width: 1.8rem; height: 1.8rem;
  padding: 0; border-radius: 4px; font-size: .85rem; background: rgba(22, 27, 34, .85);
  color: var(--fg); border: 1px solid var(--border); }

/* Bottom: Autorun | Send command + result. Fixed height so the cells have a
   definite size — the result/textarea then FILL their cell (flex:1) and their
   scrollbars sit at the very bottom of the panel. min-width/height:0 lets cells
   shrink so a long line can't force page overflow. */
#bottom { flex: 0 0 auto; height: 24vh; display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
#bottom > fieldset { min-width: 0; min-height: 0; }
#autorun-box, #command-box { display: flex; flex-direction: column; gap: .4rem; }
#autorun { flex: 1 1 0; min-height: 0; resize: none; }
.cmd-row { display: flex; gap: .5rem; }
.cmd-row input { flex: 1; }

fieldset { border: 1px solid var(--border); border-radius: 6px;
  background: var(--panel); padding: .5rem .75rem; margin: 0; }
legend { color: var(--muted); padding: 0 .25rem; }
label { display: inline-block; }
/* In the narrow sidebar, stack each label on its own line and never let a
   control spill past the panel (was: the fb checkbox + "res:" sat side by side
   and overflowed the browser edge). */
#controls { overflow-x: hidden; }
#controls label { display: block; margin: .2rem 0; }
#controls select, #controls input[type=text] { max-width: 100%; }
#controls select { width: 100%; }
textarea, input[type=text] { width: 100%; background: #0d1117; color: var(--fg);
  border: 1px solid var(--border); border-radius: 4px; padding: .35rem;
  font-family: ui-monospace, monospace; }
button { background: var(--accent); color: #0d1117; border: 0;
  border-radius: 4px; padding: .4rem .75rem; cursor: pointer; font-weight: 600; }
button:disabled { opacity: .5; cursor: not-allowed; }
pre { margin: 0; max-height: 8rem; overflow: auto;
  font-family: ui-monospace, monospace; color: var(--muted); }
#vga { max-height: 14rem; font-size: 11px; line-height: 1.15; color: #c9d1d9; white-space: pre; }
/* Bound the result box so a big output (e.g. `ls -l`) scrolls inside it instead
   of growing the bottom panel and squishing the UART above. Click it to expand
   into a large scrollable overlay (close: click outside / Esc). */
#last-result { flex: 1 1 0; min-height: 0; max-height: none; overflow: auto; cursor: zoom-in; }
#last-result.expanded { position: fixed; inset: 6vh 8vw; max-height: none; z-index: 100;
  margin: 0; padding: 1rem; background: var(--panel); color: var(--fg);
  border: 1px solid var(--border); border-radius: 8px; overflow: auto; cursor: auto;
  box-shadow: 0 8px 40px rgba(0, 0, 0, .6); white-space: pre-wrap; word-break: break-word; }
#result-backdrop { position: fixed; inset: 0; z-index: 99; background: rgba(0, 0, 0, .55);
  display: none; }
#result-backdrop.show { display: block; }
.snapshot-row { display: flex; gap: .5rem; margin: .25rem 0; }
.snapshot-row button { flex: 1; }
#snapshot-status { display: block; margin-top: .25rem; }

/* Collapsed "Advanced" section: hides the rarely-used fieldsets (built-in
   guests, send-keys, snapshots, diagnostics) behind one disclosure so the
   demo presets + image boot are what a newcomer sees first. The wrapper has
   no box of its own — the inner fieldsets keep their look; we just restore the
   inter-fieldset spacing the parent flex `gap` doesn't reach inside <details>. */
details.advanced > summary { color: var(--accent); cursor: pointer; user-select: none;
  font-weight: 600; padding: .3rem 0; }
details.advanced[open] > summary { margin-bottom: .5rem; }
details.advanced > fieldset { margin-bottom: .75rem; }

/* First-run welcome overlay (shown once; main.js toggles the `hidden` attr). */
#welcome { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center;
  justify-content: center; background: rgba(0, 0, 0, .6); padding: 1rem; }
#welcome[hidden] { display: none; } /* override the flex display above when hidden */
.welcome-card { max-width: 31rem; background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; padding: 1.25rem 1.5rem; box-shadow: 0 8px 40px rgba(0, 0, 0, .6); }
.welcome-card h2 { margin: 0 0 .5rem; color: var(--accent); font-size: 1.15rem; }
.welcome-card p { margin: .4rem 0; }
.welcome-card ul { padding-left: 1.1rem; margin: .5rem 0; }
.welcome-card li { margin: .35rem 0; }
.welcome-actions { display: flex; gap: .5rem; margin-top: 1rem; flex-wrap: wrap; }
.welcome-card button.secondary { background: var(--panel); color: var(--fg);
  border: 1px solid var(--border); font-weight: 500; }

/* "Send keys to VM": quick-combo buttons wrap; composer is a tidy row. */
.key-combos { display: flex; flex-wrap: wrap; gap: .3rem; margin-bottom: .4rem; }
.key-combos button { flex: 0 0 auto; font-size: .8rem; padding: .2rem .45rem; }
.key-composer { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; }
.key-composer label { display: inline-flex; align-items: center; gap: .15rem; font-size: .8rem; }
.key-composer select { min-width: 4.5rem; }
#kc-status { display: block; margin-top: .3rem; }
