:root {
  /* HUD: smoked glass over the bright room, in both colour schemes. */
  --glass: rgb(24 22 18 / 0.74);
  --glass-strong: rgb(24 22 18 / 0.9);
  --glass-line: rgb(255 248 235 / 0.12);
  --glass-ink: #f3ece0;
  --glass-muted: #b8ad9c;
  --glass-hover: rgb(255 248 235 / 0.08);
  --amber: #d9a46a;
  --amber-ink: #1b150e;
  /* Sheets follow the colour scheme. */
  --paper: #f3efe7;
  --surface: #fbf9f4;
  --sunk: #e8e2d6;
  --ink: #221e18;
  --muted: #6b6255;
  --line: #d9d0c1;
  --accent: #8a5a3c;
  --warn: #a3412b;
  --ok: #2f6b4f;
  --s-measured: #2e6b55; --s-reconciled: #6b5aa0; --s-derived: #40668c; --s-interpreted: #8c6d2f;
  --s-conflict: #b23b2e; --s-estimate: #b0742a; --s-source: #55606b; --s-design: #8a5a3c; --s-verify: #9a6a12;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --top-h: 54px;
  --r: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #171512; --surface: #1f1c18; --sunk: #2a2620; --ink: #ede6da; --muted: #a89d8c; --line: #38322a;
    --accent: #d39b72; --warn: #e5876c; --ok: #79c09d;
    --s-measured: #6fb79a; --s-reconciled: #a797d6; --s-derived: #82a8cf; --s-interpreted: #c9a866;
    --s-conflict: #e2786a; --s-estimate: #dfa260; --s-source: #9aa6b1; --s-design: #c99572; --s-verify: #e0b45a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: #16140f; color: var(--ink); font: 15px/1.5 var(--sans); -webkit-font-smoothing: antialiased; overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--accent); text-underline-offset: 2px; }
:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
[hidden] { display: none !important; }

.app { position: relative; height: 100vh; height: 100dvh; display: flex; flex-direction: column; }

/* ---------------------------------------------------------------- top bar */
.top {
  height: var(--top-h); flex: none; display: flex; align-items: center; gap: 18px; padding: 0 14px 0 16px;
  background: #16140f; color: var(--glass-ink); border-bottom: 1px solid var(--glass-line); z-index: 6;
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; flex: none; }
.brand b { display: block; font: 600 18px/1.1 var(--serif); letter-spacing: .01em; }
.brand small { display: block; font-size: 11.5px; color: var(--glass-muted); }
.sections { display: flex; gap: 2px; margin: 0 auto; background: rgb(255 248 235 / .06); padding: 3px; border-radius: 999px; overflow-x: auto; scrollbar-width: none; }
.sections::-webkit-scrollbar { display: none; }
.sections button { border: 0; background: none; color: var(--glass-muted); padding: 6px 14px; border-radius: 999px; font-size: 13.5px; white-space: nowrap; }
.sections button:hover { color: var(--glass-ink); }
.sections button[aria-current="page"] { background: var(--glass-ink); color: #16140f; }
.top-actions { display: flex; gap: 4px; flex: none; }
.icon-btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--glass-line); background: none; color: var(--glass-ink); border-radius: 999px; padding: 6px 12px; font-size: 13px; }
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn:hover { background: var(--glass-hover); }

/* ---------------------------------------------------------------- stage */
.stage { position: relative; flex: 1; min-height: 0; overflow: hidden; background: #e7e2d8; }
#viewport { position: absolute; inset: 0; outline: none; }
#viewport canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.lbl { position: absolute; left: 0; top: 0; font: 500 11.5px/1.2 var(--sans); white-space: nowrap; padding: 3px 7px; border-radius: 6px; background: rgb(251 248 242 / .94); color: #2a251e; border-left: 3px solid var(--s-design); box-shadow: 0 1px 3px rgb(0 0 0 / .16); }
.lbl.k-tag { border-left-color: #6c6457; }
.lbl.k-pinch { border-left-color: #c6463a; background: #fff1ec; font-weight: 600; }
.lbl.k-tight { border-left-color: #c98a2e; }
.lbl.k-ok { border-left-color: #3f8a62; }
.lbl.k-cable { border-left-color: #2f6fae; }
.lbl.s-measured { border-left-color: #2e6b55; } .lbl.s-reconciled { border-left-color: #6b5aa0; }
.lbl.s-derived { border-left-color: #40668c; } .lbl.s-interpreted { border-left-color: #8c6d2f; }
.lbl.s-conflict { border-left-color: #b23b2e; background: #fff1ee; } .lbl.s-estimate { border-left-color: #b0742a; border-left-style: dashed; }

.hud { position: absolute; z-index: 3; display: flex; gap: 8px; align-items: center; }
.hud-tl { top: 12px; left: 12px; flex-wrap: wrap; max-width: calc(100% - 24px); }
.hud-tr { top: 12px; right: 64px; flex-direction: column; align-items: flex-end; gap: 6px; max-width: min(380px, 45vw); }
.ab, .mode { display: flex; background: var(--glass); backdrop-filter: blur(14px) saturate(1.2); -webkit-backdrop-filter: blur(14px) saturate(1.2); border: 1px solid var(--glass-line); border-radius: 999px; padding: 3px; }
.ab button, .mode button { border: 0; background: none; color: var(--glass-muted); border-radius: 999px; padding: 5px 12px; font-size: 13px; min-width: 34px; }
.ab button[aria-checked="true"], .mode button[aria-checked="true"] { background: var(--glass-ink); color: #16140f; font-weight: 600; }
.pill-toggle { display: inline-flex; align-items: center; gap: 8px; background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border: 1px solid var(--glass-line); color: var(--glass-ink); border-radius: 999px; padding: 6px 12px 6px 8px; font-size: 13px; cursor: pointer; }
.pill-toggle input { appearance: none; width: 30px; height: 18px; border-radius: 999px; background: rgb(255 248 235 / .2); position: relative; margin: 0; cursor: pointer; transition: background .2s; }
.pill-toggle input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--glass-ink); transition: transform .2s; }
.pill-toggle input:checked { background: var(--amber); }
.pill-toggle input:checked::after { transform: translateX(12px); background: #fff; }

.chip-stat { display: inline-flex; align-items: center; gap: 8px; background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border: 1px solid var(--glass-line); color: var(--glass-ink); border-radius: 12px; padding: 6px 10px; font-size: 12.5px; text-align: left; }
.chip-stat b { font-weight: 600; font-variant-numeric: tabular-nums; }
.chip-stat small { color: var(--glass-muted); font-size: 11.5px; }
.chip-stat i { width: 8px; height: 8px; border-radius: 50%; flex: none; background: #79c09d; }
.chip-stat.warn i { background: #e0b45a; } .chip-stat.bad i { background: #e2786a; }
.chip-stat:hover { background: var(--glass-strong); }

.views { position: absolute; z-index: 3; top: 12px; right: 12px; display: flex; flex-direction: column; gap: 4px; background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border: 1px solid var(--glass-line); border-radius: 14px; padding: 4px; }
.views button { position: relative; width: 38px; height: 34px; border: 0; background: none; color: var(--glass-muted); border-radius: 10px; display: grid; place-items: center; }
.views button svg { width: 20px; height: 20px; }
.views button:hover, .views button[aria-pressed="true"] { color: var(--glass-ink); background: var(--glass-hover); }
.views button[aria-pressed="true"] { color: var(--amber); }
.views button span { position: absolute; right: 46px; top: 50%; transform: translateY(-50%); background: var(--glass-strong); color: var(--glass-ink); font-size: 12px; padding: 4px 8px; border-radius: 6px; white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity .15s; }
.views button:hover span, .views button:focus-visible span { opacity: 1; }

.survey-key { display: none; position: absolute; top: 56px; left: 12px; gap: 4px; flex-wrap: wrap; max-width: calc(100% - 24px); z-index: 2; }
body.survey .survey-key { display: flex; }
.survey-key span { font-size: 11.5px; padding: 3px 8px; border-radius: 6px; background: rgb(251 248 242 / .94); color: #2a251e; border-left: 3px solid; }
.survey-key .s-measured { border-color: #2e6b55; } .survey-key .s-reconciled { border-color: #6b5aa0; } .survey-key .s-derived { border-color: #40668c; }
.survey-key .s-interpreted { border-color: #8c6d2f; } .survey-key .s-conflict { border-color: #b23b2e; } .survey-key .s-estimate { border-color: #b0742a; border-left-style: dashed; }

/* ---------------------------------------------------------------- dock */
.dock { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 4; width: min(1080px, calc(100% - 24px)); display: flex; flex-direction: column; gap: 8px; align-items: center; }
.dock-bar { display: flex; gap: 2px; padding: 4px; background: var(--glass); backdrop-filter: blur(18px) saturate(1.2); -webkit-backdrop-filter: blur(18px) saturate(1.2); border: 1px solid var(--glass-line); border-radius: 16px; max-width: 100%; overflow-x: auto; scrollbar-width: none; box-shadow: 0 10px 30px rgb(0 0 0 / .25); }
.dock-bar::-webkit-scrollbar { display: none; }
.dock-bar button { flex: none; display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 66px; border: 0; background: none; color: var(--glass-muted); border-radius: 12px; padding: 6px 8px 5px; font-size: 11.5px; }
.dock-bar button svg { width: 22px; height: 22px; }
.dock-bar button:hover { color: var(--glass-ink); background: var(--glass-hover); }
.dock-bar button[aria-selected="true"] { color: var(--amber-ink); background: var(--amber); }
.dock-bar button .dot { width: 5px; height: 5px; border-radius: 50%; background: var(--amber); margin-top: 1px; opacity: 0; }
.dock-bar button.diff .dot { opacity: 1; }
.dock-bar button[aria-selected="true"] .dot { background: var(--amber-ink); }
.dock-bar .sep { width: 1px; background: var(--glass-line); margin: 6px 3px; flex: none; }

.tray { width: 100%; background: var(--glass-strong); backdrop-filter: blur(22px) saturate(1.3); -webkit-backdrop-filter: blur(22px) saturate(1.3); color: var(--glass-ink); border: 1px solid var(--glass-line); border-radius: 18px; padding: 14px 16px 12px; box-shadow: 0 16px 40px rgb(0 0 0 / .32); max-height: min(56vh, 460px); overflow: auto; animation: rise .22s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.tray-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.tray-head h2 { font: 600 17px/1.2 var(--serif); margin: 0; }
.tray-head p { margin: 0; font-size: 12.5px; color: var(--glass-muted); }
.tray-head .x { border: 0; background: none; color: var(--glass-muted); font-size: 20px; line-height: 1; padding: 2px 6px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
.card { position: relative; display: flex; flex-direction: column; gap: 4px; text-align: left; border: 1px solid var(--glass-line); background: rgb(255 248 235 / .04); color: var(--glass-ink); border-radius: 12px; padding: 10px 10px 9px; min-height: 120px; transition: border-color .15s, background .15s; }
.card:hover { background: rgb(255 248 235 / .08); }
.card[aria-pressed="true"] { border-color: var(--amber); background: rgb(217 164 106 / .14); }
.card .glyph { height: 46px; display: flex; align-items: center; justify-content: center; border-radius: 8px; background: rgb(255 248 235 / .05); overflow: hidden; margin-bottom: 4px; }
.card .glyph svg { width: 100%; height: 100%; }
.card .glyph.swatch { background-size: cover; background-position: center; }
.card b { font-size: 13px; font-weight: 600; line-height: 1.25; }
.card small { font-size: 11.5px; color: var(--glass-muted); line-height: 1.35; }
.card .meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; padding-top: 4px; }
.tag { font-size: 10.5px; padding: 2px 6px; border-radius: 999px; border: 1px solid var(--glass-line); color: var(--glass-muted); white-space: nowrap; }
.tag.src { color: #a9c3d6; border-color: rgb(169 195 214 / .35); }
.tag.own { color: #8fd1ae; border-color: rgb(143 209 174 / .35); }
.tag.new { color: var(--amber); border-color: rgb(217 164 106 / .45); }
.tag.verify { color: #e0b45a; border-color: rgb(224 180 90 / .4); }
.tag.bad { color: #ef9a88; border-color: rgb(239 154 136 / .45); }
.card .badge { position: absolute; top: 8px; right: 8px; font-size: 10px; color: var(--amber); }
.tray-row { display: flex; flex-wrap: wrap; gap: 14px 22px; align-items: center; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--glass-line); }
.tray-row .lab { font-size: 12px; color: var(--glass-muted); margin-right: 6px; }
.segs { display: inline-flex; background: rgb(255 248 235 / .06); border-radius: 999px; padding: 2px; }
.segs button { border: 0; background: none; color: var(--glass-muted); border-radius: 999px; padding: 4px 11px; font-size: 12.5px; }
.segs button[aria-pressed="true"] { background: var(--glass-ink); color: #16140f; }
.slider { display: inline-flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--glass-muted); }
.slider input { width: 150px; accent-color: var(--amber); }
.slider output { color: var(--glass-ink); font-variant-numeric: tabular-nums; min-width: 52px; }
.toggles { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; }
.toggle { display: flex; align-items: flex-start; gap: 10px; padding: 9px 10px; border-radius: 10px; border: 1px solid var(--glass-line); background: rgb(255 248 235 / .03); cursor: pointer; }
.toggle input { accent-color: var(--amber); margin: 2px 0 0; width: 16px; height: 16px; flex: none; }
.toggle b { display: block; font-size: 13px; font-weight: 600; }
.toggle small { display: block; font-size: 11.5px; color: var(--glass-muted); line-height: 1.35; }
.readout { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px 14px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--glass-line); }
.readout div { font-size: 12px; color: var(--glass-muted); }
.readout b { display: block; color: var(--glass-ink); font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.flags { margin-top: 10px; display: grid; gap: 6px; }
.flag { font-size: 12.5px; padding: 7px 10px; border-radius: 9px; background: rgb(255 248 235 / .05); border-left: 3px solid var(--glass-muted); }
.flag.warn { border-left-color: #e0b45a; } .flag.bad { border-left-color: #e2786a; } .flag.ok { border-left-color: #79c09d; }
.tiers { display: grid; gap: 4px; margin-top: 6px; }
.tier { display: grid; grid-template-columns: 112px 1fr; gap: 10px; align-items: center; font-size: 12.5px; }
.tier .h { color: var(--glass-muted); }
.tier .slots { display: flex; gap: 4px; flex-wrap: wrap; }
.tier .unit { padding: 3px 8px; border-radius: 6px; background: rgb(255 248 235 / .08); font-size: 12px; }
.tier .unit.on { background: var(--amber); color: var(--amber-ink); }

.split { position: absolute; top: 0; bottom: 0; width: 0; z-index: 2; pointer-events: none; }
.split::before { content: ""; position: absolute; top: 0; bottom: 0; left: -1px; width: 2px; background: rgb(255 255 255 / .9); box-shadow: 0 0 0 1px rgb(0 0 0 / .15); }
.split-handle { position: absolute; top: 50%; left: -20px; width: 40px; height: 40px; margin-top: -20px; border-radius: 50%; border: 1px solid rgb(0 0 0 / .15); background: #fbf8f2; pointer-events: auto; touch-action: none; box-shadow: 0 2px 8px rgb(0 0 0 / .2); }
.split-handle::before { content: "‹ ›"; font: 600 15px/1 var(--sans); color: #3a332a; letter-spacing: 2px; }
.split-tag { position: absolute; top: 56px; font: 600 13px/1 var(--sans); padding: 6px 9px; border-radius: 6px; background: rgb(24 22 18 / .82); color: #f6efe2; }
.split-tag.a { right: 12px; } .split-tag.b { left: 12px; }

.info { position: absolute; right: 64px; top: 140px; width: min(340px, calc(100% - 24px)); z-index: 5; background: var(--glass-strong); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); color: var(--glass-ink); border: 1px solid var(--glass-line); border-radius: var(--r); padding: 14px 16px 12px; box-shadow: 0 12px 34px rgb(0 0 0 / .3); max-height: calc(100% - 260px); overflow: auto; }
.info .x { position: absolute; right: 6px; top: 4px; border: 0; background: none; font-size: 22px; line-height: 1; padding: 6px 8px; color: var(--glass-muted); }
.info h2 { font: 600 16px/1.25 var(--serif); margin: 0 26px 6px 0; }
.info dl { margin: 10px 0 8px; display: grid; gap: 4px; }
.info dl div { display: grid; grid-template-columns: 42% 1fr; gap: 8px; font-size: 12.5px; }
.info dt { color: var(--glass-muted); } .info dd { margin: 0; }
.info p { font-size: 12px; color: var(--glass-muted); margin: 8px 0 0; }
.loading { position: absolute; inset: 0; display: grid; place-items: center; background: #e7e2d8; z-index: 8; color: #4b443a; font: 500 15px var(--serif); text-align: center; padding: 24px; }

/* status chips used on dark glass */
.st { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; padding: 2px 7px 2px 6px; border-radius: 999px; border: 1px solid var(--glass-line); color: var(--glass-muted); white-space: nowrap; }
.st i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* ---------------------------------------------------------------- sheets */
.sheet { position: absolute; inset: var(--top-h) 0 0 0; z-index: 7; overflow: auto; background: var(--paper); color: var(--ink); animation: fade .18s ease-out; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.doc { max-width: 1120px; margin: 0 auto; padding: 28px 24px 80px; }
.doc h1 { font: 600 30px/1.15 var(--serif); margin: 0 0 6px; }
.doc h2 { font: 600 20px/1.25 var(--serif); margin: 34px 0 10px; }
.doc h3 { font: 600 15.5px/1.3 var(--serif); margin: 22px 0 8px; }
.doc p { margin: 0 0 10px; }
.lede { color: var(--muted); font-size: 15px; max-width: 760px; }
.meta { color: var(--muted); font-size: 13px; }
.notice { border: 1px solid var(--line); border-left: 4px solid var(--s-verify); background: var(--surface); border-radius: 10px; padding: 10px 14px; font-size: 13.5px; margin: 14px 0; }
.notice.bad { border-left-color: var(--warn); }
.notice.ok { border-left-color: var(--ok); }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.btn { border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 7px 12px; border-radius: 9px; font-size: 13.5px; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.seg-doc { display: inline-flex; background: var(--sunk); border-radius: 999px; padding: 3px; }
.seg-doc button { border: 0; background: none; color: var(--muted); border-radius: 999px; padding: 5px 12px; font-size: 13px; }
.seg-doc button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin: 16px 0; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.kpi small { display: block; color: var(--muted); font-size: 12px; }
.kpi b { display: block; font: 600 22px/1.2 var(--serif); font-variant-numeric: tabular-nums; }
.kpi.ok b { color: var(--ok); } .kpi.bad b { color: var(--warn); }
table.t { width: 100%; border-collapse: collapse; font-size: 13px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
table.t th, table.t td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--sunk); position: sticky; top: 0; }
table.t td.num, table.t th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.t tr.group td { background: var(--paper); font-weight: 600; font-family: var(--serif); }
table.t tr.total td { font-weight: 700; background: var(--sunk); }
.tablewrap { overflow-x: auto; border-radius: 10px; }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; color: var(--muted); padding: 2px 7px 2px 6px; border: 1px solid var(--line); border-radius: 999px; white-space: nowrap; vertical-align: middle; }
.chip i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip.s-measured i { background: var(--s-measured); } .chip.s-reconciled i { background: var(--s-reconciled); } .chip.s-derived i { background: var(--s-derived); }
.chip.s-interpreted i { background: var(--s-interpreted); } .chip.s-conflict { color: var(--s-conflict); border-color: var(--s-conflict); } .chip.s-conflict i { background: var(--s-conflict); }
.chip.s-estimate i { background: var(--s-estimate); } .chip.s-source i { background: var(--s-source); } .chip.s-design i { background: var(--s-design); } .chip.s-verify i { background: var(--s-verify); }
.chip.ok i { background: var(--ok); } .chip.warn i { background: var(--s-verify); } .chip.bad { color: var(--warn); border-color: var(--warn); } .chip.bad i { background: var(--warn); }
.legend { list-style: none; padding: 0; margin: 10px 0; display: grid; gap: 6px; }
.legend li { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--muted); }
.legend .chip { min-width: 108px; }
.facts { margin: 0; display: grid; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.facts div { display: grid; grid-template-columns: 34% 1fr; gap: 10px; background: var(--surface); padding: 8px 12px; font-size: 13.5px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.facts small { flex-basis: 100%; color: var(--muted); font-size: 12.5px; line-height: 1.4; }
.plain { padding-left: 18px; margin: 0 0 10px; font-size: 14px; }
.plain li { margin: 3px 0; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 18px; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.gallery.pages { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
.gallery figure { margin: 0; }
.thumb { display: block; width: 100%; padding: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--sunk); aspect-ratio: 4 / 3; }
.pages .thumb { aspect-ratio: 935 / 1210; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .3s; }
.pages .thumb img { object-fit: contain; background: #fff; }
.thumb:hover img { transform: scale(1.03); }
.gallery figcaption { font-size: 12px; color: var(--muted); margin-top: 5px; line-height: 1.35; }
.gallery figcaption b { color: var(--ink); font-weight: 600; }
.timeline { list-style: none; padding: 0; margin: 0; font-size: 14px; display: grid; gap: 10px; max-width: 820px; }
.timeline li { padding-left: 14px; border-left: 2px solid var(--line); }
.timeline b { display: block; font-size: 12.5px; color: var(--muted); font-weight: 600; }

/* wiring diagram */
.diagram { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 8px; overflow-x: auto; }
.diagram svg { display: block; min-width: 980px; width: 100%; height: auto; }
.dg-box { fill: var(--paper); stroke: var(--line); }
.dg-title { font: 600 13px var(--sans); fill: var(--ink); }
.dg-sub { font: 11px var(--sans); fill: var(--muted); }
.dg-port { font: 10.5px var(--sans); fill: var(--muted); }
.dg-port.used { fill: var(--ink); }
.dg-zone { fill: none; stroke: var(--line); stroke-dasharray: 4 4; }
.dg-zone-l { font: 600 11px var(--sans); fill: var(--muted); letter-spacing: .06em; text-transform: uppercase; }
.wire { fill: none; stroke-width: 1.6; opacity: .9; }
.wire.audio { stroke: #3c7fbf; } .wire.mic { stroke: #b24f8e; } .wire.monitor { stroke: #2f8a5c; }
.wire.data { stroke: #8a6ad0; } .wire.power { stroke: #c9822a; stroke-dasharray: 5 4; } .wire.midi { stroke: #6f7b86; stroke-dasharray: 2 3; }
.wire.proposed { stroke-dasharray: 6 4; }
.keyline { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12.5px; color: var(--muted); margin: 8px 0; }
.keyline span { display: inline-flex; align-items: center; gap: 6px; }
.keyline svg { width: 26px; height: 8px; }

#toast { position: fixed; left: 50%; bottom: 110px; transform: translate(-50%, 20px); opacity: 0; background: #16140f; color: #f6efe2; padding: 9px 14px; border-radius: 10px; font-size: 13.5px; transition: .25s; pointer-events: none; z-index: 20; }
#toast.on { opacity: 1; transform: translate(-50%, 0); }
dialog#lightbox { border: 0; padding: 0; background: var(--surface); color: var(--ink); border-radius: 12px; max-width: min(1100px, 94vw); max-height: 92vh; overflow: hidden; }
dialog#lightbox::backdrop { background: rgb(20 18 15 / .76); }
#lightbox img { display: block; max-width: 100%; max-height: calc(92vh - 60px); margin: 0 auto; background: #fff; }
.lb-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; }
.lb-foot p { margin: 0; font-size: 13px; color: var(--muted); }
.noscript { padding: 16px; color: #fff; }

/* ---------------------------------------------------------------- shared additions */
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.section-select { display: none; }
.icon-btn:disabled { opacity: .35; cursor: default; }
.status-one { display: inline-flex; align-items: center; gap: 10px; background: var(--glass); backdrop-filter: blur(14px) saturate(1.2); -webkit-backdrop-filter: blur(14px) saturate(1.2); border: 1px solid var(--glass-line); color: var(--glass-ink); border-radius: 999px; padding: 6px 12px 6px 10px; font-size: 12.5px; box-shadow: 0 6px 18px rgb(0 0 0 / .18); }
.status-one i { width: 8px; height: 8px; border-radius: 50%; background: #79c09d; flex: none; }
.status-one.warn i { background: #e0b45a; } .status-one.bad i { background: #e2786a; }
.status-one button { border: 0; background: none; color: inherit; padding: 2px 0; font: inherit; display: inline-flex; gap: 5px; align-items: baseline; }
.status-one button small { color: var(--glass-muted); font-size: 11.5px; }
.status-one button b { font-weight: 600; font-variant-numeric: tabular-nums; }
.status-one .sepdot { width: 3px; height: 3px; border-radius: 50%; background: var(--glass-line); }
.subtabs { display: none; }
.viewgrid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.viewgrid button { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 6px; border-radius: 12px; border: 1px solid var(--glass-line); background: rgb(255 248 235 / .04); color: var(--glass-ink); font-size: 12.5px; min-height: 64px; }
.viewgrid button[aria-pressed="true"] { border-color: var(--amber); background: rgb(217 164 106 / .14); }
.viewgrid svg { width: 22px; height: 22px; }
.session { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.session button { flex: 1 1 120px; min-height: 44px; border-radius: 12px; border: 1px solid var(--glass-line); background: rgb(255 248 235 / .05); color: var(--glass-ink); font-size: 13.5px; }
.session button[aria-pressed="true"] { border-color: var(--amber); color: var(--amber); }
.session button:disabled { opacity: .4; }

/* ---------------------------------------------------------------- small screens */
@media (max-width: 860px) {
  :root { --top-h: 50px; }
  .top { gap: 8px; padding: 0 8px 0 10px; padding-top: env(safe-area-inset-top); }
  .brand span { display: none; }
  .sections { display: none; }
  .section-select { display: block; margin-right: auto; }
  .section-select select { appearance: none; -webkit-appearance: none; background: rgb(255 248 235 / .08) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23d8d0c2' stroke-width='1.4'/%3E%3C/svg%3E") no-repeat right 10px center/10px 6px; color: var(--glass-ink); border: 1px solid var(--glass-line); border-radius: 10px; font: 600 15px var(--sans); padding: 8px 30px 8px 12px; min-height: 40px; }
  .icon-btn { min-width: 40px; min-height: 40px; justify-content: center; padding: 0 8px; }
  .icon-btn span { display: none; }
  .hud-tl { top: 8px; left: 8px; gap: 6px; }
  .hud-tl .pill-toggle, .hud-tl .mode { display: none; }
  .ab button { min-width: 40px; min-height: 36px; font-size: 14px; }
  .hud-tr { top: 8px; right: 8px; left: auto; bottom: auto; max-width: calc(100% - 120px); flex-direction: row; overflow: visible; }
  .status-one { padding: 5px 10px 5px 9px; font-size: 12px; gap: 8px; }
  .status-one .opt { display: none; }
  .views { display: none; }
  .survey-key { top: 52px; }
  .dock { bottom: calc(8px + env(safe-area-inset-bottom)); width: calc(100% - 16px); gap: 6px; }
  .dock-bar { width: 100%; justify-content: space-between; padding: 4px; border-radius: 18px; }
  .dock-bar button { flex: 1 1 0; min-width: 0; min-height: 52px; font-size: 12px; padding: 6px 2px; }
  .dock-bar button svg { width: 24px; height: 24px; }
  .dock-bar .sep { display: none; }
  .tray { position: static; max-height: min(44vh, 380px); padding: 8px 12px 12px; border-radius: 18px; overscroll-behavior: contain; touch-action: pan-x pan-y; }
  .tray .grab { display: block; width: 38px; height: 4px; border-radius: 4px; background: var(--glass-line); margin: 0 auto 8px; }
  .subtabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; margin: 0 -4px 8px; padding: 0 4px; }
  .subtabs::-webkit-scrollbar { display: none; }
  .subtabs button { flex: none; min-height: 38px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--glass-line); background: none; color: var(--glass-muted); font-size: 13.5px; }
  .subtabs button[aria-selected="true"] { background: var(--glass-ink); color: #16140f; border-color: var(--glass-ink); }
  .tray-head { margin-bottom: 8px; }
  .tray-head h2 { font-size: 15.5px; }
  .tray-head p { display: none; }
  .tray-head .x { min-width: 40px; min-height: 40px; }
  .cards { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; gap: 8px; margin: 0 -12px; padding: 0 12px 4px; scrollbar-width: none; }
  .cards::-webkit-scrollbar { display: none; }
  .card { flex: 0 0 156px; scroll-snap-align: start; min-height: 0; }
  .card .glyph { height: 40px; }
  .card small { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .tray-row { gap: 10px 14px; }
  .segs button { min-height: 38px; padding: 6px 12px; font-size: 13px; }
  .slider { width: 100%; }
  .slider input { flex: 1; width: auto; min-height: 32px; }
  .toggles { grid-template-columns: 1fr; }
  .toggle { min-height: 48px; }
  .readout { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tiers .tier { grid-template-columns: 92px 1fr; }
  .info { right: 8px; left: 8px; top: auto; bottom: calc(76px + env(safe-area-inset-bottom)); width: auto; max-height: 40%; overflow: auto; }
  .doc { padding: 20px 16px 60px; }
  .doc h1 { font-size: 24px; }
  .split-tag { top: 96px; }
  #toast { bottom: calc(84px + env(safe-area-inset-bottom)); max-width: calc(100% - 24px); }
  .lbl { font-size: 11px; }
}
@media (max-width: 860px) and (orientation: landscape) and (max-height: 500px) {
  .tray { max-height: 58vh; }
  .dock { left: auto; right: 8px; transform: none; width: min(460px, 60%); }
  .dock-bar button { min-height: 44px; flex-direction: row; gap: 6px; }
  .hud-tr { max-width: 40%; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* Shareable selected-plan review */
#share-dialog { width:min(640px,calc(100% - 24px)); max-height:90dvh; overflow:auto; border:1px solid #bfb8a8; border-radius:18px; background:#f5f1e8; color:#28251e; padding:24px; }
#share-dialog::backdrop { background:#111b; }
#share-dialog h2 { margin:4px 0 14px; }
#share-dialog p { line-height:1.5; }
#share-dialog label { display:block; margin-bottom:8px; font-weight:600; }
#builder-link { width:100%; resize:vertical; min-height:72px; padding:10px; border:1px solid #aaa08c; border-radius:8px; font:13px monospace; background:#fff; color:#222; }
.share-close { float:right; }
.builder-actions { display:flex; flex-wrap:wrap; gap:8px; margin:16px 0; }
.builder-actions .btn { min-height:44px; }
#part-hover { position:fixed; z-index:30; max-width:260px; pointer-events:none; background:#211f19ed; color:#fff8eb; padding:10px 12px; border:1px solid #ffffff40; border-radius:10px; font-size:13px; box-shadow:0 8px 30px #0003; }
#part-hover small { display:block; margin-top:4px; color:#d2c8b5; }
#builder-banner { position:absolute; bottom:14px; left:50%; transform:translateX(-50%); z-index:12; width:max-content; max-width:calc(100% - 24px); padding:10px 14px; border-radius:14px; background:#211f19ed; color:#fff8eb; border:1px solid #ffffff35; display:flex; align-items:center; gap:12px; flex-wrap:wrap; font-size:13px; }
#builder-banner[hidden] { display:none; }
#builder-banner button { min-height:40px; color:inherit; border:1px solid #ffffff50; border-radius:8px; padding:6px 12px; background:#ffffff10; }
body.builder-review #dock, body.builder-review .hud-tl, body.builder-review #undo, body.builder-review #redo { display:none; }
.builder-components { display:grid; grid-template-columns:repeat(auto-fit,minmax(250px,1fr)); gap:10px; }
.builder-component { padding:14px; border:1px solid #bdb3a3; border-radius:10px; background:#ffffff55; }
.builder-component summary { cursor:pointer; font-weight:600; min-height:36px; }
.builder-component dl { font-size:14px; }
.builder-component dd { margin:0 0 10px; }
.builder-notice { border-left:3px solid #a6742c; padding:10px 14px; background:#a6742c0d; }
@media(max-width:860px) { #builder-banner { gap:6px; bottom:8px; justify-content:center; width:calc(100% - 16px); } #builder-banner span { display:none; } body.builder-review .info { bottom:112px; } #share-dialog { padding:18px; } .builder-actions .btn { flex:1 1 140px; } }

/* Room controls occupy their own space, never the middle of the render. */
.stage { --panel-width: 320px; --panel-side-reserve: 344px; --panel-footer-space: 80px; --panel-bottom-reserve: 0px; }
.stage > .tray, .stage > .info { overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: #8b8171 transparent; }
.stage > .tray .tray-head { position: sticky; top: -14px; z-index: 2; background: #211e18; margin: -14px -16px 10px; padding: 12px 12px 8px 16px; align-items: center; border-bottom: 1px solid var(--glass-line); }
.stage > .tray .tray-head .x, .stage > .info .x { min-width: 44px; min-height: 44px; flex: none; border-radius: 8px; }
.stage > .info .x { position: sticky; float: right; top: 0; margin: -6px -8px 0 4px; }
.stage > .info h2 { min-height: 36px; display: flex; align-items: center; }
.stage > .info dl div { grid-template-columns: 1fr; gap: 2px; padding: 7px 0; border-bottom: 1px solid var(--glass-line); }
.stage > .info dd, .stage > .info p { overflow-wrap: anywhere; }

@media (min-width: 861px) {
  .stage > .tray, .stage > .info { position: absolute; inset: 12px 12px auto auto; width: var(--panel-width); max-height: calc(100% - 24px); padding: 14px 16px 12px; z-index: 5; border-radius: 14px; box-shadow: 0 8px 26px #0002; }
  .stage > .tray { height: calc(100% - 24px); }
  .stage > .tray .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stage > .tray .card { min-width: 0; min-height: 116px; padding: 9px; }
  .stage > .tray .card .tag { white-space: normal; }
  .stage > .tray .tray-row { gap: 10px; }
  .stage > .tray .tray-row > span { max-width: 100%; }
  .stage > .tray .lab { display: block; margin-bottom: 6px; }
  .stage > .tray .segs { max-width: 100%; flex-wrap: wrap; border-radius: 12px; }
  .stage > .tray .segs button { min-height: 36px; padding: 5px 9px; }
  .stage > .tray .slider { width: 100%; flex-wrap: wrap; gap: 6px; }
  .stage > .tray .slider input { flex: 1; min-width: 70px; max-width: 150px; }
  .stage > .tray .toggles { grid-template-columns: 1fr; }
  .stage > .tray .readout { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stage > .tray .tier { grid-template-columns: 82px 1fr; }
  .stage.panel-open #viewport, .stage.panel-open > .labels { right: var(--panel-side-reserve); }
  .stage.panel-open .views { right: calc(var(--panel-side-reserve) + 12px); }
  .stage.panel-open .hud-tr { right: calc(var(--panel-side-reserve) + 64px); top: 58px; max-width: calc(100% - var(--panel-side-reserve) - 88px); }
  .stage.panel-open .hud-tr .opt { display: none; }
  .stage.panel-open .hud-tl, .stage.panel-open .survey-key { max-width: calc(100% - var(--panel-side-reserve) - 24px); }
  .stage.panel-open .dock { left: calc((100% - var(--panel-side-reserve)) / 2); width: min(1080px, calc(100% - var(--panel-side-reserve) - 24px)); }
  .stage.panel-open #builder-banner { left: calc((100% - var(--panel-side-reserve)) / 2); max-width: calc(100% - var(--panel-side-reserve) - 24px); justify-content: center; }
}

@media (max-width: 860px) {
  .stage > .tray, .stage > .info, body.builder-review .stage > .info { position: absolute; inset: auto 8px var(--panel-footer-space) 8px; width: auto; height: auto; max-height: min(30vh, 280px); max-height: min(30dvh, 280px); padding: 8px 12px 12px; border-radius: 14px; z-index: 5; }
  .stage.panel-open #viewport, .stage.panel-open > .labels { bottom: var(--panel-bottom-reserve); }
  .stage.panel-open .split { bottom: var(--panel-bottom-reserve); }
  .stage > .tray .tray-head { top: -8px; margin: -8px -12px 8px; padding: 4px 6px 4px 12px; }
  .stage > .tray .grab { display: none; }
  .stage > .tray .subtabs { margin: 0 -4px 12px; }
  .stage > .info { font-size: 13px; }
  .stage > .info h2 { margin-bottom: 2px; }
  .stage > .info dl { margin-top: 4px; }
  .stage > .info dl div { grid-template-columns: 38% 1fr; gap: 8px; }
  .stage > .info .x { top: 0; }
  .stage.panel-open #builder-banner { font-size: 12px; }
  .stage.panel-open #builder-banner b { display: none; }
}

#share-disclosure { border:1px solid #c2b8a7; border-radius:10px; padding:12px; margin:16px 0; display:grid; gap:8px; }
#share-disclosure label { display:flex; align-items:center; gap:10px; min-height:36px; font-size:14px; }
#share-disclosure input { width:18px; height:18px; accent-color:#8a6336; }
.builder-full-spec { margin:24px 0; }
.builder-full-spec > summary { min-height:44px; cursor:pointer; padding:12px 0; font-weight:600; }
.builder-full-spec table { border-collapse:collapse; width:100%; font-size:13px; }
.builder-full-spec td,.builder-full-spec th { border-bottom:1px solid #c9c0b4; padding:8px; text-align:left; overflow-wrap:anywhere; }
.builder-full-spec { overflow-x:auto; }

/* ------------------------------------------------ round 2: inspection aids */
/* Keyboard-wall shelf stops: a compact stepper inside the visible canvas. */
.keystops { position: absolute; z-index: 4; top: 60px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; max-width: calc(100% - 24px); }
.keystops .row { pointer-events: auto; display: flex; gap: 2px; padding: 3px; background: var(--glass); backdrop-filter: blur(14px) saturate(1.2); -webkit-backdrop-filter: blur(14px) saturate(1.2); border: 1px solid var(--glass-line); border-radius: 999px; box-shadow: 0 6px 18px rgb(0 0 0 / .2); max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.keystops .row::-webkit-scrollbar { display: none; }
.keystops button { flex: none; border: 0; background: none; color: var(--glass-muted); border-radius: 999px; padding: 6px 13px; min-height: 36px; font: 500 13px var(--sans); font-variant-numeric: tabular-nums; }
.keystops button:hover { color: var(--glass-ink); }
.keystops button[aria-pressed="true"] { background: var(--glass-ink); color: #16140f; }
.keystops p { margin: 0; font-size: 12px; line-height: 1.35; color: var(--glass-ink); background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border: 1px solid var(--glass-line); padding: 5px 11px; border-radius: 10px; max-width: min(560px, 100%); text-align: center; }
/* Inspector: status and the frame action share one row. */
.info-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 2px 0 6px; }
.frame-btn { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--glass-line); background: rgb(255 248 235 / .06); color: var(--glass-ink); font: 500 13px var(--sans); }
.frame-btn svg { width: 15px; height: 15px; flex: none; }
.frame-btn:hover { background: rgb(255 248 235 / .12); }
@media (min-width: 861px) {
  .stage.panel-open .keystops { left: calc((100% - var(--panel-side-reserve)) / 2); max-width: calc(100% - var(--panel-side-reserve) - 24px); top: 104px; }
}
/* Mid-width desktops: keep every section visible by dropping button captions. */
@media (min-width: 861px) and (max-width: 1240px) {
  .top { gap: 10px; }
  .icon-btn span { display: none; }
  .icon-btn { min-width: 38px; justify-content: center; }
  .sections button { padding: 6px 10px; }
  .brand small { display: none; }
}
@media (max-width: 860px) {
  .keystops { top: 52px; width: calc(100% - 16px); }
  .keystops button { min-height: 40px; padding: 6px 11px; }
  .keystops p { font-size: 11.5px; }
  .frame-btn { min-height: 40px; }
}

/* Phones: one-line status chip so the shelf stepper below it never collides. */
@media (max-width: 420px) {
  .status-one { white-space: nowrap; font-size: 11.5px; gap: 6px; padding: 5px 9px 5px 8px; }
  .status-one button { gap: 4px; }
  .status-one button[data-sheet-open="budget"] > small:first-child { display: none; }
  .status-one button small { font-size: 10.5px; }
}

/* ------------------------------------------------ round 3: captions and touch */
/* Neutral camera note for shared, framed or custom (non-preset) cameras. */
.camnote { position: absolute; z-index: 4; top: 60px; left: 50%; transform: translateX(-50%); margin: 0; pointer-events: none; font-size: 12px; line-height: 1.35; color: var(--glass-ink); background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border: 1px solid var(--glass-line); padding: 6px 12px; border-radius: 10px; max-width: min(520px, calc(100% - 24px)); text-align: center; box-shadow: 0 6px 18px rgb(0 0 0 / .18); }
@media (min-width: 861px) {
  .stage.panel-open .camnote { left: calc((100% - var(--panel-side-reserve)) / 2); max-width: calc(100% - var(--panel-side-reserve) - 24px); top: 104px; }
}
/* Touch: 44px targets for the shelf stepper and the inspector's Frame action. */
@media (max-width: 860px), (pointer: coarse) {
  .keystops button { min-height: 44px; min-width: 44px; padding: 6px 12px; }
  .frame-btn { min-height: 44px; padding: 0 14px; }
}
@media (max-width: 860px) {
  .camnote { top: 52px; width: max-content; max-width: calc(100% - 16px); font-size: 11.5px; }
}
/* Short landscape phones: keep 44px targets, but a one-line caption so the
   stepper does not cover the instruments it is framing. */
@media (max-width: 860px) and (orientation: landscape) and (max-height: 500px) {
  .keystops { top: 50px; }
  .keystops p { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .camnote { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}
