:root {
  --bg: #0a0a0d;
  --panel-bg: #14141a;
  --panel-bg-2: #1c1c24;
  --border: #2a2a34;
  --text: #e8e8ec;
  --text-dim: #8a8a96;
  --accent: #ffb347;
  --accent-2: #4fc3f7;
  --green: #6fdc8c;
  --red: #ff6b6b;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  overflow: hidden;
}

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

#toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--panel-bg); border-bottom: 1px solid var(--border);
  flex-wrap: wrap; gap: 10px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--green); box-shadow: 0 0 8px var(--green); }
.brand h1 { font-size: 16px; margin: 0; letter-spacing: 0.5px; font-family: 'Courier New', monospace; }
.brand .subtitle { font-size: 12px; color: var(--text-dim); }

.controls { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.controls button, .tab-btn, .file-btn {
  background: var(--panel-bg-2); color: var(--text); border: 1px solid var(--border);
  padding: 7px 12px; border-radius: 6px; cursor: pointer; font-size: 13px; transition: 0.15s;
}
.controls button:hover, .tab-btn:hover, .file-btn:hover { border-color: var(--accent); color: var(--accent); }
.controls button:disabled { opacity: 0.4; cursor: not-allowed; }
#btnPause.active { border-color: var(--red); color: var(--red); }
#btnStep:not(:disabled) { border-color: var(--accent-2); color: var(--accent-2); }
.range-control, .check-control { font-size: 12px; color: var(--text-dim); display: flex; align-items: center; gap: 6px; }
.speed-label { font-family: 'Courier New', monospace; min-width: 62px; display: inline-block; }
.panel-tabs { display: flex; gap: 6px; margin-left: 8px; padding-left: 12px; border-left: 1px solid var(--border); }
.tab-btn.active { border-color: var(--accent-2); color: var(--accent-2); }

main { flex: 1; display: flex; position: relative; min-height: 0; min-width: 0; }
/* min-width:0 is load-bearing, not tidiness. A flex item defaults to
   min-width:auto, which means it refuses to shrink below its content size -
   and this canvas asks for width:100% of its parent. The two together let the
   canvas claim the full row and squeeze the side panel to nothing, so opening
   a panel appeared to do nothing at all: it WAS opening, just with no width
   left to draw in. */
#scene { flex: 1 1 0; min-width: 0; display: block; width: 100%; height: 100%; cursor: grab; }
#scene:active { cursor: grabbing; }

.hint-overlay {
  position: absolute; left: 14px; bottom: 14px; z-index: 4; pointer-events: none;
  background: rgba(20, 20, 26, 0.82); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 14px; font-size: 12px; line-height: 1.7; color: var(--text-dim);
  max-width: 360px; backdrop-filter: blur(2px);
}
.hint-overlay .hint-line strong { color: var(--accent-2); font-weight: 600; margin-right: 4px; }
.hint-overlay .hint-warn {
  display: none; margin-top: 4px; padding-top: 6px; border-top: 1px solid var(--border);
  color: var(--accent);
}
.build-stamp { margin-left: auto; color: var(--accent-2); font-family: monospace; font-size: 11px; opacity: 0.85; }
.startup-error {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 999; display: none;
  background: #4a1113; color: #ffd9da; border-top: 1px solid var(--red);
  padding: 8px 14px; font-family: monospace; font-size: 12px;
}
.mon-row { display: flex; align-items: center; gap: 6px; margin: 8px 0; flex-wrap: wrap; }
.mon-row label { min-width: 58px; color: var(--muted); font-size: 12px; }
.mon-prefix { color: var(--muted); font-family: monospace; }
.mon-hex {
  font-family: monospace; font-size: 15px; letter-spacing: 2px; text-transform: uppercase;
  width: 5.5em; padding: 5px 7px; background: #10131a; color: #7fe3a4;
  border: 1px solid #2a2f3a; border-radius: 4px;
}
.mon-hex[maxlength="2"] { width: 3.5em; }
.mon-text {
  flex: 1; min-width: 8em; font-family: monospace; padding: 5px 7px;
  background: #10131a; color: #7fe3a4; border: 1px solid #2a2f3a; border-radius: 4px;
}
.mon-status { font-size: 12px; color: var(--muted); min-height: 1.2em; margin: 6px 0; }
.mon-status.mon-error { color: var(--red); }
.hint-overlay .hint-warn.show { display: block; }

#sidepanel {
  /* Fixed basis, no growing and no shrinking - the panel must keep its width
     whatever the canvas beside it wants. */
  flex: 0 0 420px;
  width: 420px; max-width: 42vw; background: var(--panel-bg); border-left: 1px solid var(--border);
  padding: 18px; overflow-y: auto; position: relative; z-index: 6;
}
#sidepanel.hidden { display: none; }
.panel.hidden { display: none; }
.panel h2 { margin-top: 4px; font-size: 15px; color: var(--accent); }
.panel h3 { font-size: 13px; color: var(--accent-2); margin-bottom: 4px; }
.panel .hint { font-size: 12px; color: var(--text-dim); line-height: 1.5; }
.panel-close {
  position: absolute; top: 10px; right: 10px; background: none; border: none; color: var(--text-dim);
  font-size: 20px; cursor: pointer; line-height: 1;
}
.panel-close:hover { color: var(--red); }

#asmSource {
  width: 100%; height: 260px; background: #0d0d11; color: #d6f2d6; border: 1px solid var(--border);
  border-radius: 6px; font-family: 'Courier New', monospace; font-size: 12.5px; padding: 10px; resize: vertical;
}
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.btn-row button, .btn-row .file-btn { flex: 0 0 auto; }
#btnBurn { border-color: var(--accent); }
#exampleSelect {
  background: var(--panel-bg-2); color: var(--text); border: 1px solid var(--border);
  padding: 7px 12px; border-radius: 6px; cursor: pointer; font-size: 13px; width: 100%;
}
#exampleSelect:hover { border-color: var(--accent); }
.file-btn { position: relative; overflow: hidden; }
.file-btn input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.log {
  background: #0d0d11; border: 1px solid var(--border); border-radius: 6px; padding: 10px;
  font-size: 12px; max-height: 160px; overflow-y: auto; white-space: pre-wrap; color: var(--text-dim);
}
.log.mono-small { font-size: 10.5px; line-height: 1.4; max-height: 320px; }
.log .ok { color: var(--green); }
.log .err { color: var(--red); }

#refContent table { width: 100%; border-collapse: collapse; margin-bottom: 16px; font-size: 12px; }
#refContent th, #refContent td { text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--border); }
#refContent th { color: var(--accent-2); font-weight: 600; }
#refContent h3 { margin-top: 18px; }
#refContent .swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }

#infoContent table { width: 100%; border-collapse: collapse; font-size: 12px; }
#infoContent td { padding: 3px 4px; border-bottom: 1px solid var(--border); }
#infoContent td:first-child { color: var(--accent-2); width: 42px; }

#statusbar {
  display: flex; gap: 18px; padding: 6px 16px; background: var(--panel-bg); border-top: 1px solid var(--border);
  font-family: 'Courier New', monospace; font-size: 12px; color: var(--text-dim); align-items: center; flex-wrap: wrap;
}
#statusbar span:not(.hint) { color: var(--accent); }
#statusbar .hint { margin-left: auto; color: var(--text-dim); font-family: inherit; }

#toast {
  position: fixed; bottom: 46px; left: 50%; transform: translateX(-50%);
  background: var(--panel-bg-2); border: 1px solid var(--accent); color: var(--text);
  padding: 8px 16px; border-radius: 8px; font-size: 13px; opacity: 0; pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

@media (max-width: 800px) {
  #sidepanel { position: absolute; right: 0; top: 0; bottom: 0; max-width: 88vw; z-index: 5; }
}

/* Program library - the shelf of BASIC programs kept in localStorage.
   Laid out as name-over-detail on the left and the two actions on the right,
   so a long program name can wrap without pushing the buttons off the panel. */
.lib-list { list-style: none; margin: 6px 0 0; padding: 0; max-height: 220px; overflow-y: auto;
  border: 1px solid var(--border); border-radius: 6px; background: rgba(0,0,0,0.2); }
.lib-list li { padding: 7px 9px; border-bottom: 1px solid var(--border); }
.lib-list li:last-child { border-bottom: none; }
.lib-empty { color: var(--text-dim); font-size: 12px; font-style: italic; }
.lib-item { display: flex; align-items: center; gap: 8px; }
.lib-meta { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.lib-name { font-weight: 600; font-size: 13px; word-break: break-word; }
.lib-sub { font-size: 11px; color: var(--text-dim); }
.lib-btns { flex: 0 0 auto; display: flex; gap: 5px; }
.lib-btns button { padding: 3px 9px; font-size: 11px; }
.lib-btns .lib-del:hover { border-color: var(--red); color: var(--red); }
