:root {
  color-scheme: dark;
  --bg: #101216; --panel: #181b21; --panel2: #1f232b; --ink: #e9ecf2;
  --dim: #98a1b0; --line: #2a2f39; --accent: #6aa9ff; --warn: #e8a33d; --bad: #e2604f;
  --ok: #58c07a;
}
* { box-sizing: border-box; }

/* The `hidden` attribute must beat our own display rules.
 *
 * `[hidden] { display: none }` lives in the browser's UA stylesheet, and ANY author
 * rule setting `display` overrides it. `.modal { display: flex }` therefore left a
 * full-screen 72%-opaque overlay permanently on top of the app — a close button
 * floating in the middle of a greyed-out page. Same trap for .demobar and .boot. */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column;
}

header {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 18px; border-bottom: 1px solid var(--line); background: var(--panel);
}
h1 { margin: 0; font-size: 15px; font-weight: 650; letter-spacing: .02em; }
.hdr { font-variant-numeric: tabular-nums; color: var(--dim); font-size: 13px; }
.grow { flex: 1; }
.dim { color: var(--dim); }
.tiny { font-size: 12px; }

.layouts { display: flex; gap: 4px; }
.layouts button { padding: 4px 10px; font-size: 13px; }
.layouts button.on { background: var(--accent); color: #0a0d12; border-color: var(--accent); }

main { flex: 1; display: flex; gap: 16px; padding: 16px; min-height: 0; align-items: flex-start; }
.stage { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 12px; }

.panes { display: grid; gap: 12px; }
.panes.one  { grid-template-columns: 1fr; max-width: min(640px, 62vh); }
.panes.two  { grid-template-columns: 1fr 1fr; }
.panes.grid { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

.pane {
  position: relative; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px;
}
.pane.focused { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.pane canvas {
  display: block; width: 100%; aspect-ratio: 1; height: auto;
  image-rendering: pixelated; border-radius: 50%; background: #000; cursor: crosshair;
}
.pane .cap {
  display: flex; align-items: center; gap: 8px; margin-top: 8px;
}
.pane select { flex: 1; }

/* The dish and its thumbnail column sit side by side. The strip used to run
 * horizontally UNDER the dish, which on a laptop pushed the transport controls off the
 * bottom of the viewport — vertical space is the scarce axis here, horizontal is not. */
.board { display: flex; gap: 12px; align-items: flex-start; min-height: 0; }
.thumbs {
  display: flex; flex-direction: column; gap: 8px; flex: none; width: 96px;
  /* Independently scrollable: overlays appear as compounds enter play, so this column
   * grows during a match and must never be what pushes the controls off screen. */
  max-height: min(72vh, 640px); overflow-y: auto; overflow-x: hidden;
  scrollbar-width: thin;
}
.panes { flex: 1; min-width: 0; }
.thumb {
  background: var(--panel); border: 1px solid var(--line); border-radius: 9px;
  padding: 6px; cursor: pointer; width: 96px; flex: none;
}
.thumb.on { border-color: var(--accent); }
.thumb canvas {
  display: block; width: 82px; height: 82px; image-rendering: pixelated;
  border-radius: 50%; background: #000;
}
.thumb span { display: block; font-size: 10px; color: var(--dim); text-align: center;
  margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.transport { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.transport input[type=range] { flex: 1; min-width: 160px; accent-color: var(--accent); }
.t { font-variant-numeric: tabular-nums; min-width: 72px; text-align: right; }

aside {
  width: 320px; flex: none; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 14px 16px; max-height: calc(100vh - 90px);
  overflow-y: auto;
}
aside h2 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .09em; color: var(--dim);
  margin: 16px 0 8px; font-weight: 650;
}
aside h2:first-child { margin-top: 0; }

button, select {
  background: var(--panel2); color: var(--ink); border: 1px solid var(--line);
  border-radius: 7px; padding: 6px 11px; font-size: 13px; font-family: inherit;
  cursor: pointer;
}
button:hover:not(:disabled), select:hover { background: #262c36; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); color: #0a0d12; border-color: var(--accent); font-weight: 600; }
button.live { color: var(--bad); }
button.live.on { background: var(--bad); color: #fff; border-color: var(--bad); }
.info {
  width: 26px; height: 26px; padding: 0; border-radius: 50%; flex: none;
  font-style: italic; font-weight: 700; line-height: 1;
}
.row { display: flex; gap: 8px; align-items: center; }
.row select { flex: 1; min-width: 0; }
.row.small { margin-top: 6px; font-size: 12px; }
.row.small label { color: var(--dim); }
.mode { display: flex; gap: 14px; margin: 10px 0 4px; font-size: 13px; }
.mode label { display: flex; align-items: center; gap: 5px; cursor: pointer; }
.chk { display: flex; align-items: center; gap: 6px; margin-top: 7px; font-size: 12px; color: var(--dim); }
aside > select { width: 100%; }

.hint { font-size: 12px; color: var(--dim); margin-top: 6px; min-height: 1.2em; }
.hint.bad { color: var(--bad); }
.hint.warn { color: var(--warn); }

.faction { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 13px; }
.sw { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.faction .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.faction .v { color: var(--dim); font-variant-numeric: tabular-nums; font-size: 12px; }

.log { max-height: 150px; overflow-y: auto; font-variant-numeric: tabular-nums; }
.log div { padding: 1px 0; }

.badge {
  display: inline-block; padding: 1px 7px; border-radius: 20px; font-size: 11px;
  border: 1px solid currentColor; margin-right: 6px;
}
.badge.spec { color: var(--ok); }
.badge.estimated { color: var(--warn); }
.badge.bad { color: var(--bad); }

.modal {
  position: fixed; inset: 0; background: rgba(6,8,11,.72); display: flex;
  align-items: center; justify-content: center; padding: 24px; z-index: 40;
}
.sheet {
  position: relative; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 22px 26px; max-width: 640px; max-height: 84vh;
  overflow-y: auto;
}
.sheet h3 { margin: 0 0 2px; font-size: 18px; }
.sheet .sub { color: var(--dim); font-size: 13px; margin-bottom: 14px; }
.sheet h4 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--dim);
  margin: 16px 0 6px;
}
.sheet p { margin: 0 0 8px; white-space: pre-wrap; }
.sheet table { border-collapse: collapse; width: 100%; font-size: 13px; }
.sheet td { padding: 3px 10px 3px 0; vertical-align: top; }
.sheet td:first-child { color: var(--dim); white-space: nowrap; }
.close { position: absolute; top: 12px; right: 12px; border-radius: 50%; width: 28px; height: 28px; padding: 0; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--panel2); border: 1px solid var(--line); border-radius: 9px;
  padding: 9px 16px; z-index: 50; font-size: 13px; max-width: 70vw;
}
.toast.bad { border-color: var(--bad); color: #ffd9d3; }

/* --- boot progress and the autoplay demo ---------------------------------- */
.demobar {
  display: flex; align-items: center; gap: 14px; padding: 9px 14px;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 10px;
}
.demobar span { flex: 1; font-size: 13px; }
.boot { display: flex; align-items: center; gap: 12px; font-size: 12px; color: var(--dim); }
.boot .bar { flex: 1; height: 4px; background: var(--panel2); border-radius: 3px; overflow: hidden; }
.boot .bar > div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.boot.failed .bar > div { background: var(--bad); }
.badge-draft {
  background: var(--warn); color: #14161a; padding: 1px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 650; margin-left: 8px;
}

.narration {
  padding: 10px 14px; border-radius: 10px; font-size: 14px; line-height: 1.45;
  background: rgba(106,169,255,.10); border: 1px solid rgba(106,169,255,.35);
}
.narration b { color: var(--accent); font-weight: 600; }
