:root {
  --bg: #0e1013;
  --panel: #13161b;
  --surface: #1a1e24;
  --surface-2: #222730;
  --line: #2a3039;
  --line-2: #363d48;
  --text: #e7e9ec;
  --muted: #949ca7;
  --accent: #63d2be;
  --accent-ink: #06231e;
  --accent-soft: rgba(99, 210, 190, 0.14);
  --bad: #f07171;
  --bad-soft: rgba(240, 113, 113, 0.14);
  --warn: #e3b65f;
  --radius: 12px;
  --top: 52px;
  --panel-w: 384px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text); font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased; overflow: hidden; overscroll-behavior: none;
}
button, input, select { font: inherit; color: inherit; }
code { font-family: var(--mono); font-size: 0.92em; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.subtle { color: var(--muted); font-size: 13px; margin: 6px 0; }
[hidden] { display: none !important; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- top bar ---------- */
.topbar {
  height: var(--top); display: flex; align-items: center; gap: 14px; padding: 0 14px;
  padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right));
  border-bottom: 1px solid var(--line); background: var(--panel); position: relative; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; letter-spacing: 0.2px; }
.brand svg { color: var(--accent); width: 22px; height: 22px; }
.roomtitle { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1; }
.roomtitle b { color: var(--text); font-weight: 600; }
.seg { display: flex; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button {
  border: 0; background: transparent; padding: 5px 14px; border-radius: 7px; cursor: pointer; color: var(--muted); font-weight: 550;
}
.seg button.on { background: var(--surface-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-2); }
.seg button:hover { color: var(--text); }
.actions { display: flex; gap: 6px; align-items: center; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 12px;
  border-radius: 9px; border: 1px solid var(--line-2); background: var(--surface); cursor: pointer; white-space: nowrap;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--surface); }
.btn.accent { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.accent:hover { filter: brightness(1.06); }
.btn.small { height: 28px; padding: 0 10px; font-size: 13px; }
.btn.icon { width: 38px; padding: 0; }
.btn.icon span { font-size: 12px; font-weight: 600; }
.btn.danger:hover { color: var(--bad); border-color: var(--bad); }
select.btn { appearance: none; padding-right: 12px; }
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }

/* ---------- layout ---------- */
main { display: flex; height: calc(100% - var(--top)); }
#viewport { position: relative; flex: 1; min-width: 0; overflow: hidden; background: #0b0d10; touch-action: none; }
#plan, #three { position: absolute; inset: 0; width: 100%; height: 100%; }
/* own stacking context: 3D labels (z-indexed by three.js) can never float over the panel */
#three { isolation: isolate; z-index: 0; overflow: hidden; }
#plan { display: block; cursor: default; }
#three canvas { display: block; }
#panel {
  width: var(--panel-w); flex: none; overflow-y: auto; background: var(--panel); border-left: 1px solid var(--line);
  padding: 12px 12px 24px; padding-bottom: max(24px, env(safe-area-inset-bottom));
}
.sheet-handle { display: none; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card-h { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.9px; color: var(--muted); margin: 0; font-weight: 650; }
.foot { padding: 4px 6px; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.stat .k { font-size: 11.5px; color: var(--muted); }
.stat .v { font-size: 16px; font-weight: 620; font-variant-numeric: tabular-nums; }
.stat .v small { font-size: 12px; color: var(--muted); font-weight: 500; }
.meter { height: 4px; border-radius: 3px; background: var(--line); margin-top: 6px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--accent); }

.qa { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.qa .q { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; padding: 8px 10px; border-radius: 9px; background: var(--panel); border: 1px solid var(--line); }
.qa .q.warn { border-color: rgba(227, 182, 95, 0.4); }
.qa .q .dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex: none; background: var(--muted); }
.qa .q.warn .dot { background: var(--warn); }
.qa .q.info .dot { background: var(--accent); }
.qa .tag { font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--warn); font-weight: 650; }

.measure { margin-top: 10px; }
.measure summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.measure table { width: 100%; border-collapse: collapse; margin-top: 6px; font-size: 13px; font-variant-numeric: tabular-nums; }
.measure td { padding: 4px 2px; border-bottom: 1px solid var(--line); }
.measure td:last-child { text-align: right; color: var(--muted); }
.measure tr.hl td { color: var(--accent); }

.urlrow { display: flex; gap: 6px; }
input[type=url], input[type=number], input:not([type]), select:not(.btn) {
  width: 100%; height: 36px; border-radius: 9px; border: 1px solid var(--line-2); background: var(--panel); padding: 0 10px; min-width: 0;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.urlrow input { flex: 1; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 4px; }
.chip {
  border: 1px solid var(--line-2); background: var(--panel); border-radius: 999px; padding: 5px 11px; cursor: pointer; font-size: 13px;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip small { color: var(--muted); margin-left: 4px; }

.items { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.items li { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; overflow: hidden; }
.items li.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.items li.bad { border-color: rgba(240, 113, 113, 0.55); }
.items .ih { display: flex; align-items: center; gap: 10px; padding: 9px 10px; cursor: pointer; }
.items .sw { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.items .nm { flex: 1; min-width: 0; }
.items .nm b { font-weight: 600; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.items .nm small { color: var(--muted); font-variant-numeric: tabular-nums; }
.items .st { font-size: 11.5px; font-weight: 650; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.st.ok { color: var(--accent); background: var(--accent-soft); }
.st.no { color: var(--bad); background: var(--bad-soft); }
.st.flat { color: var(--warn); background: rgba(227, 182, 95, 0.13); }
.items .body { padding: 0 10px 10px; border-top: 1px solid var(--line); }
.verdict { margin-top: 10px; padding: 10px; border-radius: 9px; background: var(--surface); border: 1px solid var(--line); }
.verdict.ok { border-color: rgba(99, 210, 190, 0.45); }
.verdict.no { border-color: rgba(240, 113, 113, 0.5); }
.verdict.flat { border-color: rgba(227, 182, 95, 0.5); }
.verdict .t { font-weight: 620; display: flex; gap: 8px; align-items: center; }
.verdict .t .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: 0.7px; color: var(--muted); font-weight: 650; }
.verdict p { margin: 4px 0 0; color: #c9ced5; font-size: 13px; }
.verdict .doors { margin: 6px 0 0; padding: 0; list-style: none; font-size: 12.5px; color: var(--muted); }
.verdict .doors li { border: 0; background: none; display: flex; justify-content: space-between; gap: 8px; border-radius: 0; }
.problems { margin: 8px 0 0; padding: 0; list-style: none; }
.problems li { border: 0 !important; background: var(--bad-soft) !important; color: var(--bad); padding: 6px 9px; font-size: 13px; border-radius: 8px !important; margin-bottom: 4px; }
.row { display: flex; align-items: center; }
.row.gap { gap: 8px; }
.row.end { justify-content: flex-end; }
.row.wrap { flex-wrap: wrap; }
.mt { margin-top: 10px; }

.field { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; font-size: 12.5px; color: var(--muted); }
.field.row { flex-direction: row; align-items: center; gap: 10px; }
.field.row span { white-space: nowrap; }
.tog { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; user-select: none; font-size: 13px; }
.tog input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }

.order { margin: 10px 0 0; padding: 0; list-style: none; counter-reset: step; }
.order li { display: flex; gap: 10px; padding: 9px 4px; border-top: 1px solid var(--line); }
.order li:first-child { border-top: 0; }
.order .n {
  width: 24px; height: 24px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 12.5px;
  display: grid; place-items: center; flex: none;
}
.order li.now .n { background: var(--accent); color: var(--accent-ink); }
.order li.warn .n { background: var(--bad-soft); color: var(--bad); }
.order b { display: block; }
.order p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

/* ---------- viewport overlays ---------- */
.vtools {
  position: absolute; left: 12px; bottom: 12px; display: flex; gap: 14px; flex-wrap: wrap; align-items: center;
  background: rgba(19, 22, 27, 0.86); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--line); border-radius: 11px; padding: 8px 12px; z-index: 2;
}
.view-plan .only3d { display: none; }
.itemtools {
  position: absolute; right: 12px; bottom: 12px; display: flex; gap: 6px; z-index: 2;
  background: rgba(19, 22, 27, 0.86); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--line); border-radius: 11px; padding: 6px;
}
.hint-pill {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 3; font-size: 13px; color: var(--text); display: flex; align-items: center; gap: 8px;
  background: rgba(19, 22, 27, 0.86); border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; pointer-events: none; white-space: nowrap;
}
#crosshair { position: absolute; left: 50%; top: 50%; width: 6px; height: 6px; margin: -3px; border-radius: 50%; background: rgba(255,255,255,0.7); pointer-events: none; z-index: 2; }
#joystick {
  position: absolute; left: 24px; bottom: 76px; width: 124px; height: 124px; border-radius: 50%; z-index: 3;
  background: rgba(19, 22, 27, 0.55); border: 1px solid rgba(255, 255, 255, 0.14); touch-action: none;
}
#joystick .knob {
  position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px; border-radius: 50%;
  background: rgba(99, 210, 190, 0.8); box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
}
.playbar {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 4; display: flex; gap: 12px; align-items: center;
  background: rgba(19, 22, 27, 0.92); border: 1px solid var(--accent); border-radius: 999px; padding: 5px 6px 5px 16px; font-size: 13px;
}

body.no-room #panel, body.no-room .vtools, body.no-room #viewTabs, body.no-room #btnExport, body.no-room #btnShot { display: none !important; }
body.no-room .brand { display: flex !important; }
body.no-room .actions { margin-left: auto; }
.empty { position: absolute; inset: 0; display: grid; place-items: center; z-index: 6; padding: 16px; overflow-y: auto; background: radial-gradient(1200px 600px at 50% 20%, #151a20, #0b0d10); }
.empty-card { max-width: 560px; width: 100%; }
.empty h1 { font-size: 30px; letter-spacing: -0.4px; margin: 0 0 8px; font-weight: 680; }
.empty p { color: var(--muted); margin: 0 0 20px; font-size: 15px; }
.drop {
  border: 1.5px dashed var(--line-2); border-radius: 14px; padding: 22px; display: flex; flex-direction: column; align-items: center; gap: 10px;
  color: var(--muted); background: rgba(26, 30, 36, 0.5);
}
.drop svg { width: 28px; height: 28px; color: var(--accent); }
.samples { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 18px; }
.samples > span { grid-column: 1 / -1; font-size: 13px; }
.sample {
  text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 12px; cursor: pointer;
  display: flex; flex-direction: column; gap: 2px;
}
.sample:hover { border-color: var(--accent); }
.sample small { color: var(--muted); font-size: 12px; }
.drophint { position: absolute; inset: 10px; border: 2px dashed var(--accent); border-radius: 16px; display: grid; place-items: center; background: rgba(14, 16, 19, 0.75); z-index: 8; font-size: 18px; color: var(--accent); pointer-events: none; }

#toasts { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 9; width: min(380px, calc(100% - 24px)); pointer-events: none; }
.toast { background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 10px; padding: 9px 12px; font-size: 13px; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35); animation: tin 0.18s ease-out; }
.toast.bad { border-color: var(--bad); }
.toast.ok { border-color: var(--accent); }
@keyframes tin { from { opacity: 0; transform: translateY(-4px); } }

/* 3D labels */
.lbl3d { font: 600 12px/1.2 var(--font); color: var(--text); background: rgba(14, 16, 19, 0.78); border: 1px solid rgba(255,255,255,0.1); padding: 2px 7px; border-radius: 6px; white-space: nowrap; pointer-events: none; font-variant-numeric: tabular-nums; }
.lbl3d.dim { color: #cfe9e3; }
.lbl3d.dim small { color: var(--muted); font-weight: 500; }
.lbl3d.item { background: rgba(14, 16, 19, 0.6); }
.lbl3d.bad { border-color: var(--bad); color: #ffd6d6; }
.lbl3d.room { background: transparent; border: 0; color: rgba(231, 233, 236, 0.7); font-weight: 600; text-shadow: 0 1px 4px #000; }

/* dialog */
dialog { border: 1px solid var(--line-2); background: var(--surface); color: var(--text); border-radius: 16px; padding: 0; width: min(440px, calc(100% - 24px)); max-height: calc(100% - 24px); }
dialog::backdrop { background: rgba(5, 6, 8, 0.65); }
.dlg { padding: 18px; overflow-y: auto; }
.dlg h3 { margin: 0 0 4px; font-size: 17px; }
.dims { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pkg { display: grid; grid-template-columns: repeat(4, 1fr) 28px; gap: 6px; margin: 6px 0; align-items: center; }
.pkg input { height: 32px; padding: 0 6px; }
.pkg button { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 18px; }

/* ---------- scan upload + coach ---------- */
:root { --ok: #63d2be; --ok-soft: rgba(99, 210, 190, 0.12); --warn-soft: rgba(227, 182, 95, 0.12); --info: #7fb2f0; --info-soft: rgba(127, 178, 240, 0.12); }
.btn.hero .short { display: none; }
.btn.wide { width: 100%; height: 40px; }
.herobig {
  width: 100%; height: auto; min-height: 64px; padding: 12px 18px; margin-bottom: 14px; border-radius: 14px; gap: 12px; justify-content: flex-start;
  box-shadow: 0 8px 30px rgba(99, 210, 190, 0.18);
}
.herobig svg { width: 28px; height: 28px; stroke-width: 2; }
.herobig span { display: flex; flex-direction: column; align-items: flex-start; text-align: left; }
.herobig b { font-size: 17px; }
.herobig small { font-weight: 500; font-size: 12.5px; opacity: 0.78; white-space: normal; }

.uploadbox { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 16px; background: rgba(5, 6, 8, 0.7); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.up-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line-2); border-radius: 16px; padding: 18px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5); }
.up-h { display: flex; align-items: center; gap: 10px; font-size: 16px; }
.up-file { color: var(--muted); font-size: 13px; margin: 4px 0 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-bar { height: 8px; border-radius: 5px; background: var(--line); overflow: hidden; position: relative; }
.up-bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 5px; transition: width 0.15s linear; }
.up-bar.indet i { width: 35% !important; position: absolute; animation: indet 1.3s ease-in-out infinite; }
.up-bar.bad i { background: var(--bad); width: 100% !important; }
@keyframes indet { from { left: -35%; } to { left: 100%; } }
.up-meta { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); margin-top: 6px; font-variant-numeric: tabular-nums; min-height: 18px; }
.up-card .subtle { margin: 10px 0 12px; }
.up-card.bad .up-h { color: var(--bad); }
.spin { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line-2); border-top-color: var(--accent); animation: spin 0.8s linear infinite; flex: none; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

.scancard { border-color: rgba(99, 210, 190, 0.35); }
.qa .tag.info { color: var(--accent); }
.qa .tag .link { font-size: inherit; text-transform: none; letter-spacing: 0; color: inherit; }
.coach { scroll-margin-top: 36px; margin-top: 12px; padding: 12px; border-radius: 11px; border: 1px solid var(--line-2); background: var(--panel); }
.coach .ct { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 14.5px; flex-wrap: wrap; }
.coach .badge { font-size: 11px; text-transform: uppercase; letter-spacing: 0.7px; padding: 2px 8px; border-radius: 999px; font-weight: 700; }
.coach p { margin: 8px 0 0; color: #c9ced5; font-size: 13.5px; }
.coach p.big { font-size: 15px; color: var(--text); }
.coach p.instr { font-size: 19px; line-height: 1.35; font-weight: 620; color: var(--text); margin: 10px 0 4px; }
.coach p.why { font-size: 13px; color: var(--muted); }
.coach p.why b { color: #c9ced5; font-weight: 600; }
.coach .sub, .attempts .sub { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.7px; color: var(--muted); font-weight: 650; margin-top: 10px; }
.coach .caveats { margin: 4px 0 0; padding-left: 18px; font-size: 13px; color: #c9ced5; }
.coach .caveats li { margin: 3px 0; }
.coach .btn.wide { margin-top: 12px; }
.coach.accept { border-color: rgba(99, 210, 190, 0.6); background: var(--ok-soft); }
.coach.accept .badge { background: var(--ok); color: var(--accent-ink); }
.coach.rescan { border-color: rgba(227, 182, 95, 0.65); background: var(--warn-soft); }
.coach.rescan .badge { background: var(--warn); color: #2a1d04; }
.coach.ask { border-color: rgba(127, 178, 240, 0.6); background: var(--info-soft); }
.coach.ask .badge { background: var(--info); color: #071a33; }
.coach.err { border-color: rgba(240, 113, 113, 0.5); }
.coach.err .ct { color: var(--bad); }
.coach.pending .sub { text-transform: none; letter-spacing: 0; font-weight: 500; font-size: 13px; }
.wallchip { border: 1px solid var(--warn); color: var(--warn); background: transparent; border-radius: 999px; padding: 1px 9px; font-size: 12px; font-weight: 650; cursor: pointer; }
.wallchip:hover { background: rgba(227, 182, 95, 0.15); }

.trace { margin-top: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.trace summary { cursor: pointer; padding: 9px 11px; font-size: 13px; font-weight: 600; }
.trace summary .muted { font-weight: 500; }
.trace ol { list-style: none; margin: 0; padding: 0 11px 6px; }
.trace li { display: flex; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.trace li .n { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; flex: none; background: var(--surface-2); color: var(--muted); }
.trace li .n svg { width: 15px; height: 15px; }
.trace li b { font-weight: 600; font-size: 13.5px; }
.trace li p { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }
.trace li.final.accept .n { background: var(--ok); color: var(--accent-ink); }
.trace li.final.rescan .n { background: var(--warn); color: #2a1d04; }
.trace li.final.ask .n { background: var(--info); color: #071a33; }

.attempts ol { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-direction: column; gap: 5px; }
.attempts button {
  width: 100%; display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; text-align: left; cursor: pointer;
  background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 7px 10px; font-size: 13px; font-variant-numeric: tabular-nums;
}
.attempts button:hover:not(:disabled) { border-color: var(--line-2); }
.attempts li.cur button { border-color: var(--accent); cursor: default; }
.attempts .an { font-weight: 650; }
.attempts .cov { color: var(--muted); }
.attempts .dec { font-size: 11.5px; font-weight: 650; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.attempts .dec.accept { color: var(--ok); background: var(--ok-soft); }
.attempts .dec.rescan { color: var(--warn); background: var(--warn-soft); }
.attempts .dec.ask { color: var(--info); background: var(--info-soft); }
.attempts .dec.none { color: var(--muted); background: var(--surface-2); }

/* ---------- polish: menu, fit button, peek, QA groups, first run ---------- */
#btnMore { display: none; }
.menu {
  position: absolute; top: calc(var(--top) - 4px); right: 10px; z-index: 40; min-width: 230px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: 14px; box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
  display: flex; flex-direction: column; animation: tin 0.14s ease-out;
}
.menu button {
  display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 12px; border: 0; border-radius: 9px; background: none;
  cursor: pointer; text-align: left; font-size: 14.5px;
}
.menu button:hover, .menu button:focus-visible { background: var(--surface-2); }
.menu button small { margin-left: auto; color: var(--muted); font-size: 12px; padding-left: 10px; }
.menu-h { font-size: 11px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--muted); font-weight: 650; padding: 10px 12px 4px; border-top: 1px solid var(--line); margin-top: 4px; }
body.no-room .menu .needs-room { display: none; }

.fitbtn {
  position: absolute; top: 12px; right: 12px; z-index: 3; width: 44px; height: 44px;
  background: rgba(19, 22, 27, 0.86); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); border-color: var(--line);
}
.tog .short { display: none; }
.peek { display: none; }

/* QA grouped by room */
.qa-group { display: flex; flex-direction: column; gap: 6px; }
.qa-group + .qa-group { margin-top: 8px; }
.qa-room { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; font-size: 13px; padding: 2px 2px 0; }
.qa-room b { font-weight: 650; }
.qa-room span { color: var(--muted); font-size: 12px; }
.qa .q > div { min-width: 0; }
.qa .tag { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 4px; }
.qa .tag .link { font-weight: 650; text-decoration-thickness: 1px; }
.qa .wid { color: var(--muted); font-weight: 500; text-transform: none; letter-spacing: 0; font-family: var(--mono); font-size: 10.5px; }
.qa-more summary { cursor: pointer; list-style: none; color: var(--accent); font-size: 13px; font-weight: 600; padding: 6px 2px; display: inline-flex; align-items: center; gap: 8px; min-height: 32px; }
.qa-more summary::-webkit-details-marker { display: none; }
.qa-more summary::before { content: ""; width: 6px; height: 6px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg) translateY(-2px); transition: transform 0.15s; }
.qa-more[open] summary::before { transform: rotate(-135deg) translateY(-1px); }
.qa-more .when-open, .qa-more[open] .when-closed { display: none; }
.qa-more[open] .when-open { display: inline; }
.qa-rest { display: flex; flex-direction: column; gap: 6px; }

/* first run */
.eyebrow { display: none; align-items: center; gap: 8px; color: var(--accent); font-weight: 650; letter-spacing: 0.3px; margin-bottom: 14px; }
.eyebrow svg { width: 22px; height: 22px; }
.empty .pitch { font-size: 17px; line-height: 1.5; color: #c4cad2; margin: 0 0 22px; max-width: 34em; }
.cta { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.cta .herobig { margin-bottom: 0; }
.herobig.second { background: var(--surface); border-color: var(--line-2); box-shadow: none; color: var(--text); }
.herobig.second:hover { border-color: var(--accent); background: var(--surface-2); }
.herobig.second svg { color: var(--accent); fill: currentColor; stroke: none; }
.sample.herobig { flex-direction: row; align-items: center; text-align: left; padding: 12px 18px; }
.boot-card { display: none; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.boot-card b { font-size: 17px; }
.spin.big { width: 34px; height: 34px; border-width: 3px; }
body.booting .boot-card { display: flex; }
body.booting .empty-card { display: none; }
body.busy .empty-card { opacity: 0.55; pointer-events: none; transition: opacity 0.2s; }
body.booting .topbar .actions, body.booting #viewTabs { visibility: hidden; }

/* ---------- phones ---------- */
@media (max-width: 820px) {
  :root { --top: 56px; --peek-h: 104px; }
  .topbar { gap: 8px; padding: 0 8px; padding-left: max(8px, env(safe-area-inset-left)); padding-right: max(8px, env(safe-area-inset-right)); }
  .roomtitle { display: none; }
  .brand span { display: none; }
  .seg { flex: 1; justify-content: center; padding: 3px; }
  .seg button { flex: 1; min-height: 44px; padding: 0 6px; font-size: 15px; }
  .actions { gap: 4px; }
  .actions .btn { height: 44px; }
  #btnOpen, #sampleSel, #btnExport, #btnShot, .brand { display: none; }
  #btnMore { display: inline-flex; width: 44px; }
  body.no-room .brand { display: flex !important; }
  body.no-room .brand span { display: inline !important; }
  body.no-room #btnScan { display: none; }
  .actions .btn.hero { padding: 0 14px; }
  .actions .btn.hero svg { display: none; }
  .actions .btn.hero .short { display: inline; }
  .actions .btn.hero .full { display: none; }

  main { display: block; position: relative; }
  #viewport { position: absolute; inset: 0; }

  /* bottom sheet: peek (title + primary action) / half / full */
  body { --sheet-h: var(--peek-h); }
  body[data-sheet="half"] { --sheet-h: 52%; }
  body[data-sheet="full"] { --sheet-h: calc(100% - 8px); }
  #panel {
    position: absolute; left: 0; right: 0; bottom: 0; width: auto; height: var(--sheet-h); z-index: 7;
    border-left: 0; border-top: 1px solid var(--line); border-radius: 18px 18px 0 0; padding: 0 12px 24px;
    padding-bottom: max(24px, env(safe-area-inset-bottom));
    box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.45); transition: height 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
    overscroll-behavior: contain;
  }
  body.sheet-dragging #panel { transition: none; }
  body[data-sheet="peek"] #panel { overflow: hidden; }
  .sheet-top {
    display: block; position: sticky; top: 0; z-index: 2; background: var(--panel); margin: 0 -12px 10px; padding: 0 16px 10px;
    border-bottom: 1px solid var(--line); touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none;
  }
  body[data-sheet="peek"] .sheet-top { border-bottom-color: transparent; }
  .sheet-handle {
    display: flex; justify-content: center; align-items: center; width: 100%; height: 22px; border: 0; background: transparent; cursor: inherit; padding: 0;
  }
  .sheet-handle span { width: 40px; height: 5px; border-radius: 3px; background: var(--line-2); }
  .peek { display: flex; align-items: center; gap: 12px; min-height: 52px; }
  .peek-t { flex: 1; min-width: 0; display: flex; flex-direction: column; }
  .peek-t b { font-size: 16px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .peek-t small { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .peek .btn { height: 44px; padding: 0 16px; flex: none; }
  body.no-room #panel { display: none; }

  /* view toggles move to the top, as compact chips */
  #viewport .vtools {
    top: 10px; left: 10px; right: 64px; bottom: auto; gap: 6px; padding: 0; background: none; border: 0; border-radius: 0; backdrop-filter: none; -webkit-backdrop-filter: none;
    flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none;
  }
  #viewport .vtools::-webkit-scrollbar { display: none; }
  #viewport .vtools .tog {
    flex: none; min-height: 44px; padding: 0 12px; border-radius: 999px; gap: 7px; font-size: 13px;
    background: rgba(19, 22, 27, 0.88); border: 1px solid var(--line); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  }
  #viewport .vtools .tog .full { display: none; }
  #viewport .vtools .tog .short { display: inline; }
  /* on/off pills instead of checkboxes, to fit four in a row */
  #viewport .vtools .tog { position: relative; padding: 0 14px; color: var(--muted); }
  #viewport .vtools .tog input { position: absolute; opacity: 0; pointer-events: none; }
  #viewport .vtools .tog:has(input:checked) { color: var(--accent); border-color: rgba(99, 210, 190, 0.55); background: rgba(14, 40, 36, 0.9); }
  #viewport .vtools .tog:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 1px; }

  .fitbtn { top: 10px; right: 10px; }
  #viewport .itemtools { top: auto; left: auto; right: 10px; bottom: calc(var(--sheet-h) + 10px); }
  .itemtools .btn.icon { width: 44px; height: 44px; }
  body[data-sheet="full"] #viewport .vtools, body[data-sheet="full"] #viewport .itemtools, body[data-sheet="full"] .fitbtn { display: none; }
  body.view-walk #viewport .vtools { display: none; }
  #joystick { bottom: calc(var(--sheet-h) + 28px); left: 22px; }
  .hint-pill { top: 10px; max-width: calc(100% - 24px); white-space: normal; text-align: center; }
  #loading3d { top: 64px; }
  .playbar { top: 62px; max-width: calc(100% - 20px); }
  #toasts { top: 62px; }

  /* first run */
  .empty { place-items: start center; padding: 28px 18px; padding-bottom: max(28px, env(safe-area-inset-bottom)); }
  .empty h1 { font-size: 28px; }
  .empty .pitch { font-size: 16.5px; }
  .cta { grid-template-columns: 1fr; }
  .drop { display: none; }
  .samples { grid-template-columns: 1fr; }
  .coach p.instr { font-size: 18px; }
}

/* ---------- touch: 44 px tap targets ---------- */
@media (pointer: coarse) {
  .btn { min-height: 44px; }
  .btn.small { min-height: 40px; height: auto; padding: 0 14px; }
  .chip { min-height: 44px; padding: 0 14px; display: inline-flex; align-items: center; }
  .tog { min-height: 44px; }
  .tog input { width: 20px; height: 20px; }
  input[type=url], input[type=number], input:not([type]), select:not(.btn) { height: 44px; font-size: 16px; }
  .items .ih { min-height: 56px; }
  .attempts button { min-height: 44px; }
  .measure summary, .trace summary { min-height: 44px; display: flex; align-items: center; }
  .qa-more summary { min-height: 44px; }
  .link.small, .row .link { min-height: 44px; display: inline-flex; align-items: center; }
  .wallchip { min-height: 32px; padding: 4px 12px; }
  .sample { min-height: 56px; }
  /* inline links: grow the hit area to 44 px without moving the text */
  .qa .tag .link { display: inline-flex; align-items: center; min-height: 44px; margin: -10px -4px; padding: 0 4px; }
  .subtle .link { display: inline-block; padding: 13px 2px; margin: -13px -2px; }
}

body.booting .empty { place-items: center; }
