:root {
  --bg: #f7f6f3;
  --panel: #ffffff;
  --canvas: #ecebe7;
  --ink: #1d1d1b;
  --ink-2: #5d5b56;
  --ink-3: #8f8c85;
  --line: #e4e2dc;
  --accent: #2f6fed;
  --accent-ink: #ffffff;
  --accent-soft: #e8efff;
  --ok: #1f8a57;
  --ok-soft: #e4f4ea;
  --warn: #b26a00;
  --warn-soft: #fff3dc;
  --err: #cd2b31;
  --err-soft: #fde8e8;
  --info: #2b6cb0;
  --radius: 10px;
  --shadow: 0 6px 24px rgba(20, 20, 18, 0.12), 0 1px 3px rgba(20, 20, 18, 0.08);
  --side: 340px;
  --wall-cap: #3a3936;
  --font: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-head: var(--font);
  --head-weight: 600;
  --btn-radius: 8px;
  --chip-radius: 999px;
  --brand: linear-gradient(135deg, #6d5dfc, #2f6fed);
  --brand-ink: #ffffff;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161615;
    --panel: #1f1f1d;
    --canvas: #262624;
    --ink: #f1efe9;
    --ink-2: #b9b6ae;
    --ink-3: #85827b;
    --line: #34332f;
    --accent: #5b8cff;
    --accent-soft: #1d2a48;
    --ok-soft: #173426;
    --warn-soft: #3a2c12;
    --err-soft: #3d1a1b;
    --ok: #4cc38a;
    --warn: #f5b44a;
    --err: #ff6b6f;
    --wall-cap: #8d8a83;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.4 var(--font);
  display: grid;
  grid-template-columns: var(--side) 1fr;
  grid-template-rows: 52px auto minmax(0, 1fr);
  grid-template-areas: "top top" "ribbon ribbon" "side stage";
  overflow: hidden;
}

button, input, select { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: var(--btn-radius);
  padding: 6px 12px;
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--ink-3); }
button:disabled { opacity: 0.4; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.icon { padding: 4px 9px; font-size: 16px; line-height: 1; }
button.link { border: 0; background: none; padding: 0; color: var(--accent); }
button.danger, .chip.danger { color: var(--err); }
input, select {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 7px;
  padding: 6px 8px;
  min-width: 0;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
kbd { font: 11px ui-monospace, monospace; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; background: var(--panel); }

/* ---------- header ---------- */
.top {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.brand { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.logo { font: var(--head-weight) 18px/1 var(--font-head); letter-spacing: -0.02em; display: inline-flex; align-items: center; gap: 7px; }
.logo img { height: 24px; width: auto; display: block; }
h3, .insp-name, .ds-head h3, .b-head h3, .ep-verdict b, .empty-stage strong, .pm-head h3 { font-family: var(--font-head); }
/* Logo: the mark on a tile in the theme's brand colour, then the wordmark. */
.logo { color: var(--ink); text-decoration: none; gap: 9px; }
.logo:hover { text-decoration: none; }
.logo-mark { width: 32px; height: 32px; flex: none; border-radius: 9px; background: var(--brand); display: grid; place-items: center; box-shadow: 0 2px 6px color-mix(in srgb, var(--accent) 30%, transparent); }
.logo-mark svg { width: 72%; height: 72%; display: block; margin-top: 1px; }
/* The outlined wordmark: "sofa" in the ink colour, "plot" in the accent. */
.logo-word { height: 21px; width: auto; display: block; flex: none; }
.logo-word .w-sofa { fill: var(--ink); }
.logo-word .w-plot { fill: var(--accent); }
#room-name { border-color: transparent; font-weight: 600; width: min(260px, 100%); background: transparent; }
#room-name:hover { border-color: var(--line); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; padding: 2px; background: var(--bg); }
.seg button { border: 0; background: none; padding: 5px 16px; border-radius: 7px; }
.seg button.seg-icon { display: grid; place-items: center; padding: 4px 12px; }
.seg-icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linejoin: round; }
.seg button.on { background: var(--panel); box-shadow: 0 1px 3px rgba(0,0,0,.12); font-weight: 600; }
.actions { display: flex; gap: 8px; flex: 1; justify-content: flex-end; }
.actions button, .brand button { white-space: nowrap; }
@media (max-width: 1000px) { #design-btn .lbl { display: none; } #design-btn { padding: 5px 11px; } }

/* ---------- sidebar ---------- */
.sheet-grip { display: none; }
.sidebar { grid-area: side; display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); background: var(--panel); }
.tabs { display: flex; border-bottom: 1px solid var(--line); padding: 0 8px; }
.tabs button { border: 0; border-radius: 0; background: none; padding: 12px 10px 10px; color: var(--ink-2); border-bottom: 2px solid transparent; font-weight: 500; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent); }
.tabs .count:not(:empty) { background: var(--accent); color: var(--accent-ink); border-radius: 10px; padding: 0 6px; font-size: 11px; margin-left: 2px; }
.side-body { flex: 1; overflow: auto; min-height: 0; }

.catalog { display: flex; flex-direction: column; min-height: 100%; }
.search { padding: 12px 12px 8px; }
.search input { width: 100%; padding: 9px 12px; }
.chips, .presets { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px 8px; }
.presets { padding: 4px 0 0; }
.chip { border-radius: var(--chip-radius); padding: 4px 11px; font-size: 13px; background: var(--bg); }
.chip.on { background: var(--ink); color: var(--panel); border-color: var(--ink); }
.filters { margin: 0 12px 6px; border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 10px; }
.filters summary { cursor: pointer; color: var(--ink-2); font-size: 13px; }
.filter-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 8px 0 4px; }
.filter-grid label, .row3 label, .insp-grid label, dialog label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--ink-2); }
.filter-grid label.check { flex-direction: row; align-items: center; grid-column: 1 / -1; font-size: 13px; color: var(--ink); }
.spot-banner { margin: 0 12px 8px; padding: 8px 10px; border-radius: var(--radius); background: var(--accent-soft); color: var(--ink); font-size: 12.5px; display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.spot-banner strong { color: var(--accent); }
.results-meta { padding: 2px 12px 6px; font-size: 12px; color: var(--ink-3); }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 0 12px 12px; flex: 1; align-content: start; }
.card { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; cursor: pointer; background: var(--panel); transition: border-color .12s, transform .12s; }
.card:hover { border-color: var(--accent); transform: translateY(-1px); }
.thumb { aspect-ratio: 1376 / 864; background: #fff; display: grid; place-items: center; }
.thumb img { width: 100%; height: 100%; object-fit: contain; }
.card-body { padding: 7px 8px 8px; display: flex; flex-direction: column; gap: 2px; }
.card-name { font-size: 12.5px; font-weight: 500; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-dims { font-size: 11.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.card-foot { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; margin-top: 2px; }
.price { font-weight: 600; font-size: 13px; }
.price s { color: var(--ink-3); font-weight: 400; font-size: 11.5px; }
.badge { font-size: 10.5px; border-radius: 5px; padding: 1px 5px; font-weight: 600; }
.badge.bad { background: var(--err-soft); color: var(--err); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.in { background: var(--accent-soft); color: var(--accent); }
.empty { color: var(--ink-3); grid-column: 1 / -1; text-align: center; padding: 20px 8px; }
.empty.pad { padding: 32px 24px; }
.import { border-top: 1px solid var(--line); padding: 10px 12px 14px; position: sticky; bottom: 0; background: var(--panel); }
.import form { display: flex; gap: 6px; }
.import input { flex: 1; }
.import-links { font-size: 12px; color: var(--ink-3); margin-top: 6px; }
.import-links .link { font-size: 12px; }

/* room form */
.room-form section { padding: 14px 14px 10px; border-bottom: 1px solid var(--line); }
.room-form h3, dialog h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); }
/* Collapsible groups (js/collapse.js): the heading is the toggle, and the body
   eases open and shut by animating its grid row. */
.cg-h { display: flex; align-items: center; gap: 8px; width: 100%; margin: 0 0 8px; padding: 4px 2px; min-height: 32px; background: none; border: 0; border-radius: 6px; cursor: pointer; text-align: left; font: inherit; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); font-weight: 600; }
.cg-h:hover { color: var(--ink); }
.cg-h:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.cg-t { flex: 1; min-width: 0; }
.cg-sum { font-size: 12px; text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--ink-3); opacity: 0; transition: opacity .2s; white-space: nowrap; }
.cg.shut .cg-sum { opacity: 1; }
.cg-chev { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: transform .22s ease; }
.cg.shut .cg-chev { transform: rotate(-90deg); }
.cg-b { display: grid; grid-template-rows: 1fr; transition: grid-template-rows .24s ease; }
.cg.shut .cg-b { grid-template-rows: 0fr; }
.cg-in { min-height: 0; overflow: hidden; padding: 3px; margin: -3px; transition: opacity .2s; }
.cg.shut .cg-in { opacity: 0; visibility: hidden; transition: opacity .2s, visibility 0s .24s; }
.room-form section.cg.shut { padding-bottom: 6px; }
.room-form section.cg.shut .cg-h { margin-bottom: 0; }
.b-sec .cg-h.b-group { margin: 0; padding: 8px 6px 4px; min-height: 0; font-size: 11px; color: var(--ink-3); }
.b-sec .cg-h.b-group:hover { color: var(--ink); }
.b-sec .cg-sum { display: none; }
@media (prefers-reduced-motion: reduce) { .cg-b, .cg-in, .cg-chev { transition: none; } }
.row3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 8px; }
.row3 small { color: var(--ink-3); }
.opening { border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; margin-bottom: 8px; }
.op-head { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; color: var(--ink-2); }
.op-head select:last-of-type { flex: 1; }
.shape-tools { padding: 0 0 10px; }
.chip.primary-chip { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.walls-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 6px; }
.walls-list label { display: grid; grid-template-columns: 1fr 90px; align-items: center; gap: 8px; font-size: 12.5px; color: var(--ink-2); }
.hint { color: var(--ink-2); font-size: 12.5px; margin: 0 0 8px; }

/* shopping list */
.list { padding: 8px 12px 16px; }
.list-row { display: grid; grid-template-columns: 64px 1fr auto; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; align-items: start; }
.list-row img, .list-row .ph { width: 64px; aspect-ratio: 1376/864; object-fit: contain; background: #fff; border-radius: 6px; border: 1px solid var(--line); }
.list-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 12px; margin-top: 3px; color: var(--ink-2); }
.list-total { font-weight: 600; font-variant-numeric: tabular-nums; }
.list-sum { display: flex; justify-content: space-between; padding: 12px 0; font-size: 15px; }

/* ---------- stage ---------- */
.stage-wrap { grid-area: stage; position: relative; min-width: 0; min-height: 0; }
#stage { position: absolute; inset: 0; overflow: hidden; }
#stage canvas { display: block; touch-action: none; position: relative; }
.photo-bg { position: absolute; object-fit: fill; pointer-events: none; user-select: none; }
.labels { position: absolute; inset: 0; pointer-events: none; }
.dim-label {
  font: 600 11.5px var(--font);
  background: var(--accent); color: #fff;
  padding: 1px 6px; border-radius: 5px;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.dim-label.tight { background: #f5a524; color: #1d1d1b; }
.dim-label.room { background: transparent; color: var(--ink-2); font-weight: 500; }
.dim-label.room.fixture { background: rgba(255,255,255,.75); color: #3a3936; font-size: 10.5px; }
.item-label {
  font: 500 11px var(--font);
  color: #1d1d1b; background: rgba(255, 255, 255, .82);
  border-radius: 4px; padding: 0 5px; white-space: nowrap;
  opacity: 0; transition: opacity .15s;
}
.item-label.active { opacity: 1; }
.item-label[data-status="error"] { opacity: 1; background: #fde8e8; color: #a3161b; }

/* layouts & compare */
.layouts { position: absolute; top: 12px; left: 12px; display: flex; gap: 6px; flex-wrap: wrap; max-width: calc(100% - 360px); z-index: 2; }
.layout-tab { display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border-radius: 999px; font-size: 13px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.layout-tab.on { border-color: var(--ink); font-weight: 600; }
.layout-tab.cmp { border-style: dashed; border-color: var(--accent); }
.layout-tab.add { color: var(--accent); }
.layouts { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.layouts::-webkit-scrollbar { display: none; }
.layout-tab { flex: none; }
.layout-tab .lname { max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layout-tab .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.layout-tab .dot.error { background: var(--err); }
.layout-tab .x { color: var(--ink-3); font-size: 11px; margin-left: 2px; }
.layout-tab .x:hover { color: var(--err); }
.lname-edit { width: 110px; padding: 0 4px; border-radius: 4px; font-size: 13px; }
#stage2 { position: absolute; top: 0; bottom: 0; left: 50%; right: 0; overflow: hidden; border-left: 2px solid var(--line); }
.stage-wrap.compare #stage { right: 50%; }
.stage-wrap.compare .inspector { right: calc(50% + 14px); }
.stage-wrap.compare .issues { left: 25%; }
.stage-wrap.compare .layouts { max-width: calc(50% - 24px); }
#compare-cards { position: absolute; inset: 0; pointer-events: none; }
.cmp-card { position: absolute; max-width: calc(50% - 24px); background: var(--panel); border-radius: 12px; box-shadow: var(--shadow); padding: 7px 12px; pointer-events: auto; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; }
.cmp-card.left { left: 12px; top: 52px; }
.cmp-card.right { left: calc(50% + 12px); top: 12px; }
.cmp-title { font-size: 13px; }
.cmp-title select { font-weight: 600; }
.hint-inline { color: var(--ink-3); font-size: 12px; }
.cmp-stats { display: flex; flex-wrap: wrap; gap: 2px 12px; font-size: 12.5px; color: var(--ink-2); }
.cmp-stats b { color: var(--ink); font-variant-numeric: tabular-nums; }
.cmp-stats .win b { color: var(--ok); }
.cmp-stats .win::after { content: " ✓"; color: var(--ok); }

.issues { position: absolute; left: 50%; bottom: 46px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 8px; max-width: min(560px, calc(100% - 32px)); }
.pill { border-radius: 999px; padding: 7px 16px; font-weight: 600; box-shadow: var(--shadow); border: 0; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.error { background: var(--err-soft); color: var(--err); }
.issue-list, .insp-issues { list-style: none; margin: 0; padding: 0; }
.issue-list { order: -1; background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); max-height: 40vh; overflow: auto; width: 100%; }
.issue-list li, .insp-issues li { padding: 8px 12px 8px 30px; position: relative; border-bottom: 1px solid var(--line); font-size: 13px; }
.issue-list li { cursor: pointer; }
.issue-list li:hover { background: var(--bg); }
.issue-list li::before, .insp-issues li::before { content: ""; position: absolute; left: 12px; top: 13px; width: 8px; height: 8px; border-radius: 50%; }
li.error::before { background: var(--err); }
li.warn::before { background: #f5a524; }
li.info::before { background: var(--info); }
.empty-stage { background: var(--panel); box-shadow: var(--shadow); border-radius: 14px; padding: 16px 20px; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; max-width: 420px; }
.empty-stage span { color: var(--ink-2); }
.empty-stage { position: relative; }
.empty-stage .es-close { position: absolute; top: 10px; right: 10px; width: 30px; height: 30px; padding: 0; display: grid; place-items: center; border-radius: 50%; color: var(--ink-3); background: transparent; border-color: transparent; }
.empty-stage .es-close:hover { color: var(--ink); background: var(--bg); }
.empty-stage > strong { padding-right: 34px; }
.start-pill { background: var(--panel); color: var(--ink); }

.inspector {
  position: absolute; top: 14px; right: 14px; width: 320px; max-height: calc(100% - 28px); overflow: auto;
  background: var(--panel); border-radius: 14px; box-shadow: var(--shadow); padding: 12px;
}
.insp-head { display: grid; grid-template-columns: 76px 1fr auto; gap: 10px; align-items: start; }
.insp-head img { width: 76px; aspect-ratio: 1376/864; object-fit: contain; background: #fff; border-radius: 6px; border: 1px solid var(--line); }
.insp-name { font-weight: 600; line-height: 1.25; }
.insp-sub { font-size: 12.5px; color: var(--ink-2); margin-top: 2px; }
.insp-link { font-size: 12.5px; }
.insp-dims { margin: 10px 0 6px; font-variant-numeric: tabular-nums; font-weight: 500; }
.fit { font-size: 12.5px; border-radius: 7px; padding: 6px 8px; }
.fit.ok { background: var(--ok-soft); color: var(--ok); }
.fit.tight { background: var(--warn-soft); color: var(--warn); }
.fit.tilt { background: var(--accent-soft); color: var(--info); }
.fit.no { background: var(--err-soft); color: var(--err); }
.fit.na { background: var(--bg); color: var(--ink-2); }
.card-vars { font-size: 11px; color: var(--accent); }
.variants { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }
.v-row { display: grid; grid-template-columns: 42px 1fr; gap: 6px; align-items: start; }
.v-label { font-size: 12px; color: var(--ink-2); padding-top: 4px; }
.v-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.v-chips .chip { font-size: 12px; padding: 3px 9px; text-transform: capitalize; }
.chip.color { display: inline-flex; align-items: center; gap: 5px; padding-left: 4px; }
.v-swatch { width: 16px; height: 16px; border-radius: 50%; object-fit: cover; }
.suggest { width: 100%; margin-top: 10px; background: var(--accent-soft); color: var(--accent); border-color: transparent; font-weight: 600; text-align: left; }
.insp-grid { display: grid; grid-template-columns: 1fr 1fr 0.8fr; gap: 8px; margin: 10px 0; }
.insp-grid input, .row3 input, .row3 select, .filter-grid input, .filter-grid select { width: 100%; }
.insp-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.insp-actions button { padding: 5px 10px; font-size: 13px; }
.swatch { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 8px; padding: 2px 8px 2px 3px; font-size: 13px; cursor: pointer; }
.swatch input { width: 26px; height: 24px; padding: 0; border: 0; background: none; }
.insp-issues { margin-top: 10px; border-top: 1px solid var(--line); }
.all-good { margin-top: 10px; color: var(--ok); font-size: 13px; }

.draw-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); border: 2px solid #fff; box-shadow: 0 0 0 1px var(--accent); }
.draw-dot.first { width: 16px; height: 16px; background: #fff; border: 3px solid var(--accent); }
.draw-dot.cursor { background: #fff; }
.wall-handle { pointer-events: auto; cursor: grab; border-radius: 50%; background: #fff; border: 2px solid var(--accent); box-shadow: 0 1px 4px rgba(0,0,0,.25); }
.wall-handle.corner { width: 16px; height: 16px; }
.wall-handle.mid { width: 12px; height: 12px; border-radius: 3px; background: var(--accent); }
.wall-handle:active { cursor: grabbing; }
.drawbar { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 3; background: var(--panel); box-shadow: var(--shadow); border-radius: 12px; padding: 8px 10px 8px 14px; display: flex; gap: 10px; align-items: center; font-size: 13px; max-width: calc(100% - 24px); flex-wrap: wrap; }
.drawbar .tips { color: var(--ink-2); }
.drawbar .tips b { color: var(--ink); }
.drawbar button { padding: 4px 10px; font-size: 13px; }
.drawbar input#calib-len { width: 110px; }
.drawbar .opacity input { width: 80px; vertical-align: middle; }
.draw-dot.calib { background: #e5484d; box-shadow: 0 0 0 1px #e5484d; }

/* No WebGL: a banner across the top of the room view, above the welcome card. */
.no-gl { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 6; width: min(560px, calc(100% - 24px)); display: flex; flex-direction: column; gap: 2px; padding: 10px 14px; border-radius: 12px; background: var(--warn-soft); border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent); color: var(--ink-2); font-size: 13px; box-shadow: var(--shadow); }
.no-gl strong { color: var(--ink); }
.stage-wrap:has(.no-gl) .issues:has(.empty-stage) { top: 92px; }
.stage-wrap:has(.no-gl) .layouts { visibility: hidden; }

.keys { position: absolute; left: 12px; bottom: 10px; font-size: 12px; color: var(--ink-3); pointer-events: none; }

.toast {
  position: fixed; bottom: 86px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--panel); padding: 9px 16px; border-radius: 9px; box-shadow: var(--shadow);
  max-width: min(520px, calc(100% - 32px)); z-index: 10; font-size: 13.5px;
}

/* catalog & disclaimer */
.demo-banner { margin: 0 12px 8px; padding: 8px 10px; border-radius: var(--radius); background: var(--warn-soft); color: var(--ink); font-size: 12.5px; }
.thumb img.gen { opacity: 0; } .thumb img { transition: opacity .2s; }
.v-dot { width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgba(0,0,0,.15); flex: none; }
.disclaimer { font-size: 11.5px; color: var(--ink-3); margin: 10px 0 0; line-height: 1.4; }
.disclaimer a { color: var(--ink-2); text-decoration: underline; }
.empty-stage .disclaimer { margin-top: 2px; }
.import-links { font-size: 12.5px; }

/* builder */
.chip.build { background: var(--accent-soft); color: var(--accent); border-color: transparent; font-weight: 600; }
.badge.mine { background: var(--bg); color: var(--ink-2); }
.del-piece { margin-left: auto; padding: 0 5px; font-size: 11px; color: var(--ink-3); border: 0; }
.ph-label { color: var(--ink-3); font-size: 12px; }
.insp-head .ph, .list-row .ph { width: 76px; aspect-ratio: 1376/864; border-radius: 6px; background: var(--bg); border: 1px solid var(--line); }
/* Build mode: replaces the main viewport. */
.builder-view { position: absolute; inset: 0; z-index: 9; background: var(--bg); display: flex; animation: panel-in .22s; }
.bv { display: flex; flex-direction: column; width: 100%; min-height: 0; }
.bv-head { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; }
.bv-title { display: flex; align-items: baseline; gap: 10px; flex: 1; min-width: 0; }
.bv-title h3 { margin: 0; font-size: 17px; text-transform: none; letter-spacing: 0; color: var(--ink); white-space: nowrap; }
.bv-title .hint { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bv-actions { display: flex; align-items: center; gap: 8px; }
.bv-actions .check { display: flex; gap: 6px; align-items: center; font-size: 13px; color: var(--ink); margin-right: 6px; }
.bv-actions .primary { padding: 8px 18px; }
.bv-body { flex: 1; display: grid; grid-template-columns: 168px minmax(0, 1fr) 340px; min-height: 0; }
.bv-body .b-templates { border-right: 1px solid var(--line); padding: 8px; overflow: auto; background: var(--panel); }
.b-group { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); padding: 8px 6px 4px; }
.b-tpl { display: flex; align-items: center; gap: 8px; width: 100%; border: 0; background: none; padding: 7px 6px; border-radius: 8px; text-align: left; font-size: 13px; }
.b-tpl svg { width: 20px; height: 20px; fill: var(--ink-2); flex: none; }
.b-tpl:hover { background: var(--bg); }
.b-tpl.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.b-tpl.on svg { fill: var(--accent); }
.b-form label.wide { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--ink-2); }
.b-form .row3 { margin: 0; }
.b-form label.check { flex-direction: row; align-items: center; gap: 6px; font-size: 13px; color: var(--ink); padding-top: 16px; }
.b-form input[type=color] { height: 34px; padding: 2px; width: 100%; }
.bv-stage { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.bv-toolbar { display: flex; align-items: center; gap: 8px; padding: 10px 14px; flex-wrap: wrap; }
.bv-toolbar .grow { flex: 1; }
.bv-toolbar button { font-size: 13px; padding: 6px 11px; }
.tb-toggle { display: inline-flex; align-items: center; gap: 6px; }
.tb-toggle svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; }
.tb-toggle.on { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.bv-top { flex: 1; min-height: 0; margin: 0 14px; border: 1px solid var(--line); border-radius: 14px; overflow: hidden;
  background: repeating-linear-gradient(0deg, transparent 0 23px, rgba(0,0,0,.035) 23px 24px), repeating-linear-gradient(90deg, transparent 0 23px, rgba(0,0,0,.035) 23px 24px), var(--panel); }
.bv-top .cmp-svg { width: 100%; height: 100%; }
.bv-stage .b-preview { flex: 1; min-height: 0; margin: 0 14px; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; display: flex; background: linear-gradient(var(--bg), var(--panel)); }
.bv-stage .b-canvas { flex: 1; min-height: 0; }
.bv-stage .b-foot { padding: 8px 16px 12px; font-size: 12.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.bv-body > .b-form { border-left: 1px solid var(--line); background: var(--panel); padding: 14px 16px 24px; display: flex; flex-direction: column; gap: 12px; overflow: auto; max-height: none; }
.cmp-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; height: 100%; color: var(--ink-3); }
.cmp-empty b { color: var(--ink); }
.cmp-sel-h { display: flex; justify-content: space-between; align-items: baseline; }
.cmp-sel .check { display: flex; gap: 6px; align-items: center; font-size: 13px; }
.cmp-sel-row .grow { flex: 1; }
.m-tiles.compact { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.m-tiles.compact .m-tile { min-height: 64px; }
.bv-pop { position: absolute; z-index: 3; width: 300px; max-width: calc(100% - 16px); background: var(--panel); border-radius: 14px; box-shadow: var(--shadow); padding: 10px; animation: panel-in .16s; }
.bv-pop-h { display: flex; justify-content: space-between; align-items: center; font-weight: 600; font-size: 13px; margin-bottom: 8px; }
/* Drawing details, sized in inches (the viewBox). */
.cmp-svg * { vector-effect: non-scaling-stroke; }
.cmp-svg text { font-family: var(--font); font-weight: 600; text-anchor: middle; pointer-events: none; }
.cmp-svg .m-num-t { fill: #fff; }
.cmp-svg .dims { cursor: pointer; }
.cmp-svg .dim-l { stroke: var(--accent); stroke-width: 1.3; }
.cmp-svg .dim-bg { fill: var(--panel); stroke: var(--accent); stroke-width: 1; }
.cmp-svg .dim-t { fill: var(--accent); }
.cmp-svg .overall .dim-l, .cmp-svg .overall .dim-bg { stroke: var(--ink-2); }
.cmp-svg .dim-t.total { fill: var(--ink); }
/* Inside lengths: teal, dashed, drawn over the seats. */
.cmp-svg .in .dim-l { stroke: var(--in-color, #0f8a7e); stroke-dasharray: 4 2; }
.cmp-svg .in .dim-bg { fill: var(--panel); stroke: var(--in-color, #0f8a7e); }
.cmp-svg .in .dim-t { fill: var(--in-color, #0f8a7e); }
.tb-toggle.in-toggle.on { color: var(--in-color, #0f8a7e); border-color: var(--in-color, #0f8a7e); background: color-mix(in srgb, var(--in-color, #0f8a7e) 10%, var(--panel)); }
.cmp-inside { display: grid; gap: 4px; padding: 10px 12px; border-radius: 10px; background: color-mix(in srgb, var(--in-color, #0f8a7e) 8%, var(--panel)); border: 1px solid color-mix(in srgb, var(--in-color, #0f8a7e) 30%, var(--line)); font-size: 13px; }
.cmp-inside b { color: var(--in-color, #0f8a7e); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.cmp-inside div { display: flex; justify-content: space-between; gap: 8px; }
.cmp-inside span:last-child { font-weight: 600; font-variant-numeric: tabular-nums; }
.cmp-svg .joint { cursor: pointer; }
.cmp-svg .joint circle { fill: var(--panel); stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 3 2; }
.cmp-svg .joint .joint-t { fill: var(--accent); font-weight: 700; }
.cmp-svg .joint:hover circle { fill: var(--accent-soft); stroke-dasharray: none; }
.cmp-svg .m-del { cursor: pointer; }
.cmp-svg .m-del circle { fill: var(--err); stroke: #fff; stroke-width: 2; }
.cmp-svg .m-del-t { fill: #fff; }
body.building .layouts, body.building .issues, body.building .tool-btns, body.building .inspector, body.building #compare-cards, body.building .stage-max-btn, body.building .side-toggle { visibility: hidden; }
@media (max-width: 820px) { .b-form .row3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

/* photo */
.photobar { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 3; display: flex; gap: 6px; background: var(--panel); padding: 6px; border-radius: 12px; box-shadow: var(--shadow); }
.photobar button { padding: 4px 10px; font-size: 13px; }
dialog.photo-match { width: min(1180px, calc(100% - 32px)); height: min(760px, calc(100% - 32px)); padding: 0; display: none; flex-direction: column; }
dialog.photo-match[open] { display: flex; }
.pm-head { display: flex; gap: 12px; align-items: baseline; padding: 14px 18px 10px; border-bottom: 1px solid var(--line); }
.pm-head h3 { margin: 0; font-size: 17px; white-space: nowrap; }
.pm-head .hint { margin: 0; flex: 1; }
.pm-body { flex: 1; display: grid; grid-template-columns: 1.4fr 1fr; min-height: 0; }
.pm-pane { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); }
.pm-pane:last-child { border-right: 0; }
.pm-label { padding: 8px 14px; font-size: 12.5px; color: var(--ink-2); display: flex; gap: 10px; align-items: center; }
.pm-canvas { flex: 1; position: relative; min-height: 0; background: var(--bg); }
.pm-canvas canvas { position: absolute; inset: 0; cursor: crosshair; touch-action: none; }
.pm-empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 30px; color: var(--ink-2); background: var(--bg); }
.pm-foot { display: flex; gap: 8px; align-items: center; padding: 10px 18px; border-top: 1px solid var(--line); }
.pm-status { flex: 1; font-size: 13px; color: var(--ink-2); }
@media (max-width: 820px) { .pm-body { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; } .pm-head .hint { display: none; } }

dialog { border: 0; border-radius: 14px; box-shadow: var(--shadow); padding: 18px; width: min(420px, calc(100% - 32px)); background: var(--panel); color: var(--ink); }
dialog::backdrop { background: rgba(0, 0, 0, .3); }
dialog form { display: flex; flex-direction: column; gap: 10px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* measure & tools */
.tool-btns { position: absolute; right: 12px; bottom: 12px; z-index: 2; display: flex; flex-direction: column; gap: 6px; }
.tool-btns button { box-shadow: 0 1px 4px rgba(0,0,0,.14); font-size: 13px; }
.tool-btns button.on { background: var(--ink); color: var(--panel); border-color: var(--ink); }
.measure-end { width: 9px; height: 9px; border-radius: 50%; background: #e5484d; border: 2px solid #fff; box-shadow: 0 0 0 1px #e5484d; }
.measure-end.live { background: #f5a524; box-shadow: 0 0 0 1px #f5a524; }
.dim-label.measure { background: #e5484d; font-size: 12.5px; padding: 2px 7px; }
.dim-label.measure.live { background: #f5a524; color: #1d1d1b; }
.print-btn { width: 100%; margin: 4px 0 10px; }

/* print */
#print-sheet { display: none; }
@media print {
  @page { margin: 12mm; }
  body { display: block; height: auto; overflow: visible; background: #fff; color: #111; }
  body > *:not(#print-sheet) { display: none !important; }
  #print-sheet { display: block; font: 11pt/1.35 Inter, system-ui, sans-serif; }
  .pr-head { display: flex; justify-content: space-between; align-items: flex-end; border-bottom: 2px solid #111; padding-bottom: 6px; margin-bottom: 10px; }
  .pr-head h1 { margin: 0; font-size: 20pt; }
  .pr-sub { color: #555; font-size: 9.5pt; }
  .pr-total { text-align: right; } .pr-total span { display: block; color: #555; font-size: 9pt; } .pr-total strong { font-size: 16pt; }
  .pr-plan img { width: 100%; max-height: 52vh; object-fit: contain; display: block; margin: 0 auto 8px; }
  .pr-facts { font-size: 9.5pt; color: #333; display: grid; gap: 2px; margin-bottom: 10px; }
  #print-sheet h2 { font-size: 12pt; margin: 12px 0 6px; break-after: avoid; }
  .pr-table { width: 100%; border-collapse: collapse; font-size: 9.5pt; }
  .pr-table th { text-align: left; border-bottom: 1px solid #111; padding: 4px; }
  .pr-table td { border-bottom: 1px solid #ddd; padding: 5px 4px; vertical-align: top; }
  .pr-table tr { break-inside: avoid; }
  .pr-num { font-weight: 700; color: #2f6fed; }
  .pr-name { font-weight: 600; } .pr-meta { color: #666; font-size: 8.5pt; }
  .pr-note { color: #666; font-size: 8.5pt; }
  .pr-issues { margin: 0; padding-left: 16px; font-size: 9.5pt; } .pr-issues li { margin: 2px 0; break-inside: avoid; }
  .pr-disclaimer { margin-top: 14px; padding-top: 8px; border-top: 1px solid #ccc; font-size: 8.5pt; color: #444; break-inside: avoid; }
}

/* ---------- ribbon ---------- */
.ribbon { grid-area: ribbon; background: var(--panel); border-bottom: 1px solid var(--line); position: relative; z-index: 6; }
.rb-tabs { display: flex; align-items: flex-end; gap: 2px; padding: 0 10px; height: 34px; }
.rb-tab { border: 0; background: none; border-radius: 8px 8px 0 0; padding: 7px 14px 6px; font-weight: 500; color: var(--ink-2); position: relative; }
.rb-tab:hover { color: var(--ink); background: var(--bg); }
.rb-tab.on { color: var(--accent); font-weight: 600; }
.rb-tab.on::after { content: ""; position: absolute; left: 10px; right: 10px; bottom: 0; height: 2px; border-radius: 2px; background: var(--accent); }
.rb-grow { flex: 1; }
.rb-collapse { border: 0; background: none; padding: 4px 6px; margin-bottom: 4px; color: var(--ink-3); }
.rb-collapse .ri { transition: transform .25s; transform: rotate(180deg); }
.ribbon.collapsed .rb-collapse .ri { transform: none; }
.rb-panel { display: grid; grid-template-rows: 1fr; transition: grid-template-rows .26s cubic-bezier(.2,.7,.2,1); border-top: 1px solid var(--line); background: linear-gradient(var(--panel), var(--bg)); }
.ribbon.collapsed .rb-panel { grid-template-rows: 0fr; border-top-color: transparent; }
.rb-inner { overflow: hidden; min-height: 0; display: flex; align-items: stretch; padding: 0 8px; }
.ribbon:not(.collapsed) .rb-inner { padding: 5px 8px 3px; }
.rb-group { display: flex; flex-direction: column; align-items: center; padding: 0 4px; }
.rb-items { display: flex; gap: 2px; }
.rb-glabel { font-size: 10.5px; color: var(--ink-3); padding: 1px 0 2px; white-space: nowrap; }
.rb-sep { width: 1px; background: var(--line); margin: 4px 6px 6px; }
.rb-btn { display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 62px; padding: 5px 6px 4px; border: 1px solid transparent; background: none; border-radius: 8px; font-size: 11.5px; color: var(--ink); line-height: 1.15; }
.rb-btn span { white-space: nowrap; }
.rb-btn:hover:not(:disabled) { background: var(--panel); border-color: var(--line); box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.rb-btn.on { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.rb-btn.accent .ri { color: var(--accent); }
.rb-btn:disabled { opacity: .35; }
.ri { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* Theme picker. */
.logo.custom::before { display: none; }
.theme-menu { width: 320px; max-width: calc(100vw - 16px); }
.theme-opt { display: grid !important; grid-template-columns: 64px 1fr; gap: 10px; align-items: center; padding: 8px !important; }
.theme-opt.on { background: var(--accent-soft) !important; }
.theme-swatch { position: relative; width: 64px; height: 44px; border-radius: 8px; border: 1px solid; overflow: hidden; display: block; }
.theme-swatch span { position: absolute; left: 6px; top: 6px; width: 30px; height: 30px; border-radius: 5px; display: grid; place-items: center; font-weight: 600; font-size: 13px; box-shadow: 0 1px 2px rgba(0,0,0,.1); }
.theme-swatch i { position: absolute; right: 6px; bottom: 7px; width: 18px; height: 10px; }
.theme-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.theme-text small { color: var(--ink-3); font-size: 11.5px; line-height: 1.3; white-space: normal; }

/* Room switcher and menus. */
.room-switch { display: inline-flex; align-items: center; gap: 6px; border-color: transparent; background: none; font-weight: 600; max-width: 260px; padding: 5px 8px; }
.room-switch:hover { background: var(--bg); border-color: var(--line); }
.rs-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rs-caret { color: var(--ink-3); font-size: 11px; }
.menu { position: fixed; z-index: 50; min-width: 240px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; animation: panel-in .16s; }
.menu button { display: flex; align-items: center; gap: 8px; width: 100%; border: 0; background: none; text-align: left; padding: 7px 10px; border-radius: 8px; }
.menu button:hover { background: var(--bg); }
.menu button.on { font-weight: 600; }
.menu button small { margin-left: auto; color: var(--ink-3); }
.menu button span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu .ri { width: 18px; height: 18px; color: var(--ink-2); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 5px 4px; }
.menu .menu-title { font-size: 11.5px; color: var(--ink-3); padding: 4px 10px 2px; }

/* Your rooms. */
.rooms-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.room-card { border: 1px solid var(--line); border-radius: 14px; overflow: hidden; display: flex; flex-direction: column; background: var(--panel); }
.room-card.current { border-color: var(--accent); }
.room-card.new { align-items: center; justify-content: center; gap: 8px; min-height: 220px; border-style: dashed; color: var(--accent); background: var(--bg); }
.room-card.new .ri { width: 34px; height: 34px; }
.rc-plan { background: #fff; aspect-ratio: 4/3; display: grid; place-items: center; border-bottom: 1px solid var(--line); }
.rc-plan img { max-width: 100%; max-height: 100%; }
.rc-body { padding: 10px 12px 4px; display: flex; flex-direction: column; gap: 2px; font-size: 12.5px; color: var(--ink-2); }
.rc-body b { color: var(--ink); font-size: 14px; }
.rc-actions { display: flex; gap: 6px; padding: 8px 12px 12px; }
.rc-actions .primary { flex: 1; }
.rc-actions .ri { width: 18px; height: 18px; }

/* New room wizard. */
.nr-body.with-preview { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 380px); gap: 18px; }
.nr-form { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.nr-form label.wide { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-2); }
.nr-form label.wide input { font-size: 16px; padding: 9px 12px; }
.nr-types { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.nr-types .ds-type { min-height: 0; align-items: center; text-align: center; padding: 14px 8px; }
.nr-shapes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.nr-shapes .ds-type { min-height: 0; padding: 12px; }
.nr-preview { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 8px; align-self: start; position: sticky; top: 0; }
.nr-preview img { width: 100%; display: block; }
.nr-facts { text-align: center; font-size: 12.5px; color: #555; padding: 4px; }
.nr-openings { display: flex; flex-direction: column; gap: 6px; }
.nr-op { display: grid; grid-template-columns: 110px minmax(0, 1fr) minmax(0, 1fr) 70px auto; gap: 6px; align-items: center; }
.nr-then { display: flex; align-items: center; gap: 6px; font-size: 13px; }

/* ---------- polish ---------- */
body { transition: grid-template-columns .28s cubic-bezier(.2,.7,.2,1), grid-template-rows .3s cubic-bezier(.2,.7,.2,1); }
button { transition: background-color .15s, border-color .15s, color .15s, box-shadow .15s, transform .1s; }
button:active:not(:disabled) { transform: translateY(1px); }
button.design { background: var(--brand); color: var(--brand-ink); border: 0; font-weight: 600; box-shadow: 0 2px 10px color-mix(in srgb, var(--accent) 30%, transparent); }
button.design:hover { box-shadow: 0 4px 16px rgba(47,111,237,.45); }

/* Collapsible side panel. */
.sidebar { overflow: hidden; min-width: 0; }
.sidebar > * { min-width: var(--side); transition: opacity .2s; }
body.side-collapsed { grid-template-columns: 0 1fr; }
body.side-collapsed .sidebar > * { opacity: 0; pointer-events: none; }
/* Centered with margins, not a transform: pressed buttons get a 1px transform
   nudge, which would otherwise replace the centering and drop it half its height. */
.side-toggle { position: absolute; left: 0; top: 50%; margin-top: -28px; z-index: 3; width: 18px; height: 56px; padding: 0; border-radius: 0 9px 9px 0; border-left: 0; box-shadow: 2px 0 6px rgba(0,0,0,.08); display: grid; place-items: center; color: var(--ink-2); transition: width .15s, color .15s, background-color .15s; }
.side-toggle:active:not(:disabled) { transform: none; }
.side-toggle span { display: inline-block; transition: transform .28s; font-size: 16px; line-height: 1; }
body.side-collapsed .side-toggle span { transform: rotate(180deg); }
.side-toggle:hover { color: var(--accent); width: 22px; }

/* Item panel minimizes smoothly. */
.insp-btns { display: flex; gap: 4px; }
.part-head { grid-template-columns: 44px 1fr auto; }
.part-ic { width: 44px; height: 44px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.part-ic .ri { width: 26px; height: 26px; }
.inspector .row3 { margin: 10px 0 0; }
#wall-menu { min-width: 260px; }
.insp-body { display: grid; grid-template-rows: 1fr; transition: grid-template-rows .26s cubic-bezier(.2,.7,.2,1), opacity .2s; }
.insp-body > div { overflow: hidden; min-height: 0; }
.inspector.min .insp-body { grid-template-rows: 0fr; opacity: 0; }
.inspector { animation: panel-in .22s cubic-bezier(.2,.7,.2,1); }
@keyframes panel-in { from { opacity: 0; transform: translateY(-6px) scale(.98); } }

/* Toasts slide in and can carry an action. */
.toast { display: flex; align-items: center; gap: 12px; }
.toast.in { animation: toast-in .22s cubic-bezier(.2,.7,.2,1); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }
.ds-foot label.check { flex-direction: row; align-items: center; gap: 6px; color: var(--ink); font-size: 13px; }
.toast-action { background: transparent; border: 1px solid rgba(255,255,255,.35); color: inherit; padding: 3px 10px; font-weight: 600; }

/* First-run paths. */
.empty-stage { max-width: 560px; padding: 20px 22px; gap: 10px; animation: panel-in .3s; }
.empty-stage strong { font-size: 17px; }
.start-paths { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; width: 100%; margin-top: 4px; }
/* The welcome card uses the width it's given instead of shrinking to its text. */
.issues:has(.empty-stage) { width: min(560px, calc(100% - 32px)); }
.issues:has(.empty-stage) .empty-stage { width: 100%; box-sizing: border-box; }
.start { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 12px; border-radius: 12px; text-align: left; background: var(--bg); }
.start b { font-size: 14px; }
.start small { color: var(--ink-2); font-size: 12px; line-height: 1.35; }
.start:hover { border-color: var(--accent); background: var(--accent-soft); }
.start.primary-start { background: var(--brand); color: var(--brand-ink); border: 0; }
.start.primary-start small { color: rgba(255,255,255,.85); }

/* Catalog cards say what a click does. */
.thumb { position: relative; }
.card .thumb::after { content: "+ Add to room"; position: absolute; inset: auto 8px 8px auto; background: var(--accent); color: #fff; font-size: 11.5px; font-weight: 600; padding: 3px 8px; border-radius: 6px; opacity: 0; transform: translateY(4px); transition: opacity .15s, transform .15s; }
.card:hover .thumb::after { opacity: 1; transform: none; }

/* Designer. */
dialog.designer { width: min(1180px, calc(100% - 32px)); max-height: calc(100% - 32px); padding: 0; display: none; flex-direction: column; }
dialog.designer[open] { display: flex; animation: panel-in .25s cubic-bezier(.2,.7,.2,1); }
.ds-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 16px 20px 6px; }
.ds-head h3 { margin: 0; font-size: 19px; text-transform: none; letter-spacing: 0; color: var(--ink); }
.ds-head .hint { margin: 2px 0 0; }
.ds-steps { display: flex; gap: 6px; padding: 6px 20px 12px; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.ds-steps span { padding: 3px 10px; border-radius: 999px; background: var(--bg); color: var(--ink-3); }
.ds-steps span.on { background: var(--accent); color: #fff; font-weight: 600; }
.ds-steps span.done { color: var(--accent); background: var(--accent-soft); }
.ds-body { padding: 18px 20px; overflow: auto; flex: 1; min-height: 0; }
.ds-foot { display: flex; gap: 8px; align-items: center; padding: 12px 20px; border-top: 1px solid var(--line); }
.ds-foot .grow { flex: 1; }
button.big { padding: 9px 18px; font-size: 15px; }
.ds-room { color: var(--ink-2); margin-bottom: 14px; }
.ds-types { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.ds-type { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 18px 16px; border-radius: 14px; text-align: left; min-height: 130px; }
.ds-type:hover, .ds-type.on { border-color: var(--accent); background: var(--accent-soft); }
.ds-type b { font-size: 15px; }
.ds-type span:last-child { color: var(--ink-2); font-size: 12.5px; }
.ds-emoji { font-size: 28px; line-height: 1; margin-bottom: 6px; }
.ds-keep { display: flex; gap: 8px; align-items: center; margin-top: 16px; }
.ds-needs { display: flex; flex-direction: column; gap: 18px; max-width: 720px; }
.ds-picked { display: flex; align-items: center; gap: 10px; font-size: 15px; }
.ds-picked .ds-emoji { font-size: 22px; margin: 0; }
.ds-field { display: grid; grid-template-columns: 130px 1fr; gap: 12px; align-items: center; }
.ds-label { color: var(--ink-2); font-size: 13px; }
.ds-field .chips { padding: 0; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; width: max-content; }
.stepper button { border: 0; border-radius: 0; width: 40px; height: 36px; font-size: 18px; }
.stepper output { min-width: 44px; text-align: center; font-weight: 600; font-size: 16px; font-variant-numeric: tabular-nums; }
.seg-pick { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; padding: 2px; background: var(--bg); width: max-content; }
.seg-pick button { border: 0; background: none; padding: 6px 14px; border-radius: 8px; }
.seg-pick button.on { background: var(--panel); box-shadow: 0 1px 3px rgba(0,0,0,.12); font-weight: 600; }
.ds-budget { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.ds-budget input { width: 110px; font-size: 15px; font-weight: 600; }
.ds-dollar { color: var(--ink-3); }
.ds-working, .ds-none { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; min-height: 320px; text-align: center; color: var(--ink-2); }
.ds-working b, .ds-none b { color: var(--ink); font-size: 16px; }
.ds-none ul { text-align: left; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--accent-soft); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.ds-results { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.ds-card { border: 1px solid var(--line); border-radius: 14px; overflow: hidden; display: flex; flex-direction: column; background: var(--panel); animation: panel-in .3s both; }
.ds-card:nth-child(2) { animation-delay: .06s; } .ds-card:nth-child(3) { animation-delay: .12s; }
.ds-card:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.ds-plan { background: #fff; aspect-ratio: 4 / 3; display: grid; place-items: center; border-bottom: 1px solid var(--line); }
.ds-plan img { max-width: 100%; max-height: 100%; object-fit: contain; }
.ds-card-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.ds-card-title { font-weight: 600; display: flex; gap: 8px; align-items: center; }
.ds-num { width: 22px; height: 22px; border-radius: 50%; background: var(--ink); color: var(--panel); display: grid; place-items: center; font-size: 12px; flex: none; }
.ds-stats { display: flex; gap: 10px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-2); }
.ds-stats .ok { color: var(--ok); font-weight: 600; }
.ds-budgetbar { height: 6px; border-radius: 3px; background: var(--bg); overflow: hidden; }
.ds-budgetbar span { display: block; height: 100%; background: linear-gradient(90deg, var(--ok), var(--accent)); border-radius: 3px; }
.ds-total { font-size: 13px; color: var(--ink-2); } .ds-total b { color: var(--ink); font-size: 17px; }
.ds-thumbs { display: flex; gap: 4px; flex-wrap: wrap; }
.ds-thumbs img { width: 46px; aspect-ratio: 1376/864; object-fit: contain; background: #fff; border: 1px solid var(--line); border-radius: 5px; }
.ds-card .primary { margin-top: auto; padding: 8px; }

/* Piece-by-piece composer. */
.b-form > * { flex-shrink: 0; } /* the form scrolls; nothing in it gets squeezed */
.cmp-presets { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.cmp-presets .ds-label { margin-right: 4px; }
.m-tiles { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.m-tile { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 4px; border-radius: 12px; font-size: 11.5px; line-height: 1.15; text-align: center; min-height: 72px; touch-action: manipulation; }
.m-tile svg { width: 36px; height: 36px; fill: var(--accent-soft); stroke: var(--accent); stroke-width: 1.4; }
.m-tile:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.m-tile:active:not(:disabled) { transform: scale(.96); }
.cmp-stage { position: relative; border: 1px solid var(--line); border-radius: 14px; background: repeating-linear-gradient(0deg, transparent 0 19px, rgba(0,0,0,.035) 19px 20px), repeating-linear-gradient(90deg, transparent 0 19px, rgba(0,0,0,.035) 19px 20px), var(--bg); min-height: 200px; }
.cmp-svg { display: block; touch-action: manipulation; user-select: none; }
.cmp-svg .mod { cursor: pointer; }
.cmp-svg .m-base { fill: var(--panel); stroke: var(--ink-2); stroke-width: 1.2; }
.cmp-svg .m-back, .cmp-svg .m-arm { fill: var(--line); stroke: var(--ink-2); stroke-width: 1; }
.cmp-svg .m-console { fill: #c9b79c; stroke: var(--ink-2); }
.cmp-svg .m-seam { fill: none; stroke: var(--ink-3); stroke-dasharray: 3 3; }
.cmp-svg .m-num { fill: var(--ink-3); }
.cmp-svg .mod.sel .m-base { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 2.4; }
.cmp-svg .mod.sel .m-num { fill: var(--accent); }
.cmp-sel { border: 1px solid var(--accent); background: var(--accent-soft); border-radius: 12px; padding: 10px; display: flex; flex-direction: column; gap: 8px; animation: panel-in .18s; }
.cmp-sel-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.cmp-sel-row > button { min-width: 44px; min-height: 40px; background: var(--panel); }
.cmp-steppers { display: flex; flex-wrap: wrap; gap: 14px; }
.stepper-field { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--ink-2); }
.stepper-field .stepper output { min-width: 56px; font-size: 14px; }
.stepper-field .stepper button { width: 40px; height: 38px; }
.cmp-tip { margin: 0; color: var(--warn); }
@media (max-width: 820px) { .m-tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

/* Shortcuts. */
.keys-list { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; font-size: 13.5px; }
.keys-list dt { text-align: right; } .keys-list dd { margin: 0; color: var(--ink-2); }
.keys kbd:last-of-type { pointer-events: none; }

/* ---------- embed mode ---------- */
body.embed { grid-template-columns: minmax(0, 1fr); grid-template-rows: 52px minmax(0, 1fr); grid-template-areas: "top" "stage"; }
body.embed .ribbon, body.embed .sidebar, body.embed #layouts, body.embed .side-toggle, body.embed #design-btn, body.embed #share,
body.embed .keys, body.embed #issues, body.embed #compare-cards, body.embed .stage-max-btn { display: none !important; }
body.embed .top { padding-right: 56px; } /* room for the host's close button */
.embed-panel { position: absolute; top: 14px; right: 14px; width: 330px; max-height: calc(100% - 28px); overflow: auto; z-index: 4;
  background: var(--panel); border-radius: 16px; box-shadow: var(--shadow); padding: 14px; display: flex; flex-direction: column; gap: 10px; animation: panel-in .25s; }
.ep-product { display: grid; grid-template-columns: 84px 1fr; gap: 10px; align-items: center; }
.ep-product img { width: 84px; aspect-ratio: 1376/864; object-fit: contain; background: #fff; border: 1px solid var(--line); border-radius: 8px; }
.ep-product b { display: block; line-height: 1.25; }
.ep-product span { font-size: 12.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.ep-verdict { display: grid; grid-template-columns: 40px 1fr; gap: 10px; align-items: center; padding: 12px; border-radius: 12px; }
.ep-verdict b { display: block; font-size: 16px; }
.ep-verdict span { font-size: 13px; }
.ep-icon { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 19px; color: #fff; }
.ep-verdict.fits { background: var(--ok-soft); color: var(--ok); } .ep-verdict.fits .ep-icon { background: var(--ok); }
.ep-verdict.check { background: var(--warn-soft); color: var(--warn); } .ep-verdict.check .ep-icon { background: #f5a524; }
.ep-verdict.blocked, .ep-verdict.no-door { background: var(--err-soft); color: var(--err); } .ep-verdict.blocked .ep-icon, .ep-verdict.no-door .ep-icon { background: var(--err); }
.ep-verdict.no-room { background: var(--bg); color: var(--ink-2); } .ep-verdict.no-room .ep-icon { background: var(--ink-3); }
.ep-room { font-size: 12.5px; color: var(--ink-2); display: flex; gap: 6px; flex-wrap: wrap; align-items: baseline; }
.ep-actions { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.ep-actions .primary { padding: 8px 18px; }
.ep-actions button.on { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.ep-h { margin: 4px 0 0; font-size: 15px; }
.ep-field { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--ink-2); }
.ep-wait, .ep-error { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 18px 8px; text-align: center; color: var(--ink-2); }
.embed-panel .variants { margin: 0; }
.embed-panel .insp-issues { margin-top: 0; }

/* ---------- layering ---------- */
/* CSS2D labels set their own z-index; keep them all below the app's panels. */
.labels { z-index: 1; }
.layouts, .issues, #compare-cards { z-index: 2; }
.drawbar, .photobar { z-index: 3; }
.inspector { z-index: 4; }
.stage-max-btn { display: none; }

/* Bigger targets for fingers. */
@media (pointer: coarse) {
  .wall-handle.corner { width: 26px; height: 26px; }
  .wall-handle.mid { width: 20px; height: 20px; }
  .draw-dot { width: 14px; height: 14px; }
  .chip { padding: 6px 12px; }
  .insp-actions button { padding: 7px 12px; }
}


/* ---------- small screens ---------- */
@media (max-width: 820px) {
  html, body { height: 100%; }
  body {
    height: 100dvh;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr) minmax(0, var(--sheet-h, 45dvh));
    grid-template-areas: "top" "ribbon" "stage" "side";
  }
  body.stage-max { grid-template-rows: auto auto minmax(0, 1fr) 0; }
  /* The ribbon is a row of tabs; a tab's tools drop down over the room. */
  .rb-tabs { overflow-x: auto; scrollbar-width: none; height: 36px; }
  .rb-tab { padding: 8px 12px 7px; }
  .rb-collapse { display: none; }
  .rb-panel { position: absolute; left: 0; right: 0; top: 100%; box-shadow: 0 10px 24px rgba(0,0,0,.14); border-bottom: 1px solid var(--line); }
  .ribbon.collapsed .rb-panel { box-shadow: none; border-bottom: 0; }
  .rb-inner { overflow-x: auto; scrollbar-width: none; }
  .ribbon:not(.collapsed) .rb-inner { overflow-x: auto; }
  .rb-btn { min-width: 60px; padding: 7px 6px 5px; }
  .room-switch { max-width: 120px; padding: 5px 4px; }
  .nr-body.with-preview { grid-template-columns: 1fr; }
  .nr-preview { position: static; order: -1; }
  .nr-preview img { max-height: 30dvh; object-fit: contain; }
  .nr-types { grid-template-columns: repeat(3, 1fr); }
  .nr-shapes { grid-template-columns: 1fr 1fr; }
  .nr-op { grid-template-columns: 1fr 1fr; }
  body.embed { grid-template-rows: auto minmax(0, 1fr); }
  .embed-panel { top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 46dvh; border-radius: 16px 16px 0 0; padding: 16px 14px calc(14px + env(safe-area-inset-bottom)); }
  body.embed .tool-btns { bottom: calc(46dvh + 10px); }
  .logo { display: inline-flex; }
  .logo-word { display: none; }
  .logo-mark { width: 30px; height: 30px; }
  .room-switch { max-width: 104px; padding: 5px 2px; }
  .top { gap: 4px; padding: 8px; }
  .brand, .seg, .actions { min-width: 0; flex-shrink: 1; }
  .top { overflow: hidden; }
  .ribbon { max-width: 100vw; }
  .rb-panel, .rb-inner { max-width: 100vw; }
  #redo { display: none; }
  .seg button { padding: 5px 9px; }
  .nr-body, .nr-form, .nr-preview { min-width: 0; max-width: 100%; }
  dialog.designer { overflow-x: hidden; }
  .ds-body { overflow-x: hidden; }
  .presets { flex-wrap: wrap; }
  .nr-preview img { max-height: 24dvh; }
  .toast { left: 12px; right: 12px; transform: none; max-width: none; }
  @keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
  body.stage-max .sidebar { display: none; }
  .top { gap: 6px; padding: 8px 10px; min-height: 52px; }
  .brand { flex: 0 0 auto; gap: 0; }
  .logo { font-size: 16px; }
  .seg button { padding: 5px 11px; }
  .seg .lbl { display: none; }
  .actions { flex: 0 0 auto; gap: 5px; margin-left: auto; }
  .actions button { padding: 5px 10px; }
  #room-name, #snapshot, #print, .keys, .side-toggle, #design-btn .lbl { display: none; }
  #design-btn { padding: 5px 11px; }
  .start-paths { grid-template-columns: 1fr; gap: 6px; }
  .start { padding: 9px 12px; flex-direction: row; align-items: center; }
  .start small { display: none; }
  /* The welcome card stays inside the room view however far the panel is pulled up. */
  .issues:has(.empty-stage) { top: 10px; justify-content: flex-end; pointer-events: none; }
  .issues:has(.empty-stage) > * { pointer-events: auto; }
  .empty-stage { max-height: 100%; overflow: auto; padding: 14px 16px; gap: 6px; width: calc(100vw - 24px); }
  .empty-stage strong { font-size: 15px; }
  .empty-stage > span { font-size: 12.5px; }
  .actions { gap: 4px; }
  .actions button { padding: 5px 9px; }
  .card .thumb::after { display: none; }
  dialog.designer { width: 100%; max-width: 100%; height: 100dvh; max-height: 100dvh; border-radius: 0; margin: 0; }
  .ds-head { padding: 12px 14px 4px; } .ds-head .hint { display: none; }
  .ds-steps { padding: 6px 14px 10px; overflow-x: auto; white-space: nowrap; }
  .ds-body { padding: 14px; }
  .ds-types { grid-template-columns: 1fr 1fr; gap: 8px; }
  .ds-type { min-height: 0; padding: 14px 12px; }
  .ds-field { grid-template-columns: 1fr; gap: 6px; }
  .ds-results { grid-template-columns: 1fr; }
  .ds-foot { padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); flex-wrap: wrap; }
  .sidebar, .stage-wrap { min-width: 0; }
  .sidebar { border-right: 0; border-top: 1px solid var(--line); }
  .tabs { overflow-x: auto; }
  .tabs button { white-space: nowrap; padding: 11px 9px 9px; }
  .tool-btns { bottom: 56px; right: 10px; }
  .stage-max-btn { display: block; position: absolute; right: 10px; top: 10px; z-index: 3; padding: 5px 9px; font-size: 15px; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
  .stage-wrap.compare .stage-max-btn { top: auto; bottom: 10px; }

  /* The item panel slides up over the lower half, leaving the room in view. */
  .inspector, .stage-wrap.compare .inspector {
    position: fixed; top: auto; left: 0; right: 0; bottom: 0; width: auto;
    max-height: 48dvh; border-radius: 16px 16px 0 0; padding: 18px 14px calc(14px + env(safe-area-inset-bottom));
  }
  /* Both sheets have a grip: drag or flick it, or tap it to step sizes. */
  .sheet-grip { display: block; position: relative; height: 18px; flex: none; touch-action: none; cursor: grab; }
  .sheet-grip::before { content: ""; position: absolute; top: 7px; left: 50%; width: 40px; height: 5px; margin-left: -20px; border-radius: 3px; background: color-mix(in srgb, var(--ink-3) 45%, transparent); transition: background-color .15s, width .15s; }
  .sheet-grip:active::before, .sheet-drag .sheet-grip::before, body.sheet-drag .side-grip::before { background: var(--ink-3); width: 52px; margin-left: -26px; }
  .sheet-grip:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 8px; }
  .sidebar { border-radius: 16px 16px 0 0; box-shadow: 0 -4px 16px rgba(0,0,0,.06); position: relative; z-index: 2; }
  .sidebar .tabs { touch-action: pan-x; }
  body.sheet-drag { transition: none; }
  body.sheet-drag .sidebar { user-select: none; }
  body.sheet-peek .side-body { visibility: hidden; }
  .inspector .sheet-grip { position: absolute; top: 0; left: 0; right: 0; height: 22px; z-index: 1; }
  .inspector { transform: translateY(var(--drag-y, 0px)); max-height: var(--drag-h, 48dvh); transition: transform .24s cubic-bezier(.2,.7,.2,1), max-height .28s cubic-bezier(.2,.7,.2,1); }
  .inspector.tall { max-height: var(--drag-h, 86dvh); }
  .inspector.sheet-drag { transition: none; }
  .issues { bottom: 10px; }
  .issue-list { max-height: 30dvh; }
  .layouts { top: 8px; left: 8px; max-width: calc(100% - 64px); gap: 4px; }
  .stage-wrap.compare .layouts { max-width: calc(100% - 16px); }
  .layout-tab { padding: 4px 9px; font-size: 12px; }
  .layout-tab .lbl { display: none; }
  .tool-btns .lbl { display: none; }

  /* Compare stacks the two layouts top and bottom. */
  .stage-wrap.compare #stage { right: 0; bottom: 50%; }
  #stage2 { left: 0; top: 50%; border-left: 0; border-top: 2px solid var(--line); }
  .stage-wrap.compare .issues { left: 50%; bottom: calc(50% + 8px); }
  .cmp-card { max-width: calc(100% - 16px); padding: 5px 10px; gap: 2px 10px; }
  .cmp-card.left { left: 8px; top: 44px; }
  .cmp-card.right { left: 8px; top: calc(50% + 8px); }
  .cmp-stats { font-size: 11.5px; gap: 0 10px; }
  .cmp-card { flex-wrap: nowrap; }
  .cmp-card .hint-inline, .cmp-stats span:nth-child(4) { display: none; }
  .cmp-title select { padding: 2px 4px; font-size: 12px; }
  #cmp-edit { font-size: 12px; white-space: nowrap; }
  .stage-wrap.compare .issues { display: none; }

  .drawbar, .photobar { top: 8px; left: 8px; right: 8px; transform: none; max-width: none; padding: 8px; gap: 6px; }
  .drawbar .tips { flex-basis: 100%; font-size: 12.5px; }
  .toast { bottom: calc(50dvh + 12px); }
  body.stage-max .toast { bottom: 70px; }

  .builder-view { position: fixed; inset: 0; z-index: 30; }
  .bv-head { padding: 8px 10px calc(8px); }
  .bv-title { display: none; }
  .bv-actions { width: 100%; }
  .bv-actions .check { margin-right: auto; }
  .bv-actions .check { font-size: 12px; }
  .bv-body { display: flex; flex-direction: column; overflow: auto; }
  .bv-body .b-templates { display: flex; flex-wrap: nowrap; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 6px; flex: none; }
  .bv-body .b-templates .b-group { display: none; }
  .bv-body .b-templates .b-sec, .bv-body .b-templates .cg-b, .bv-body .b-templates .cg-in { display: contents; }
  .bv-body .b-templates .cg.shut .cg-in { visibility: visible; opacity: 1; }
  .bv-body .b-templates .b-tpl { width: auto; white-space: nowrap; flex: none; }
  .bv-stage { flex: none; height: 52dvh; }
  .bv-toolbar { padding: 8px 10px; gap: 6px; }
  .bv-toolbar .seg-pick button { padding: 5px 10px; }
  .bv-top, .bv-stage .b-preview { margin: 0 10px; }
  .bv-body > .b-form { border-left: 0; border-top: 1px solid var(--line); overflow: visible; padding: 12px 12px calc(20px + env(safe-area-inset-bottom)); }
  dialog.photo-match { width: 100%; max-width: 100%; height: 100dvh; max-height: 100dvh; border-radius: 0; margin: 0; }
  .pm-foot { flex-wrap: wrap; }
  .pm-status { flex-basis: 100%; }
}

/* ---------- accounts ---------- */
.save-state { display: inline-flex; align-items: center; gap: 6px; padding: 4px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: transparent; border: 1px solid transparent; color: var(--ink-3); white-space: nowrap; }
.save-state .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.save-state:hover { background: var(--bg); border-color: var(--line); }
.save-state.unsaved, .save-state.guest { color: var(--warn); }
.save-state.unsaved { background: var(--warn-soft); }
.save-state.saved { color: var(--ok); }
.save-state.saving { color: var(--ink-3); }
.save-state.saving .dot { animation: save-pulse 1s ease-in-out infinite; }
.save-state.offline { color: var(--ink-3); }
.save-state.offline .dot { background: transparent; border: 1.5px solid currentColor; }
.save-state.error { color: var(--err); background: var(--err-soft); }
@keyframes save-pulse { 50% { opacity: .25; } }
button.account { display: inline-flex; align-items: center; gap: 6px; }
button.account svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
button.account.signed-in { padding: 2px; border-radius: 50%; border-color: transparent; background: none; }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: inline-grid; place-items: center; background: var(--brand); color: var(--brand-ink); font-weight: 700; font-size: 14px; flex: none; }
.acct-menu { min-width: 260px; max-width: calc(100vw - 16px); }
.acct-menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 9px 10px; border-radius: 8px; }
.acct-menu button:hover, .acct-menu button:focus-visible { background: var(--bg); }
.acct-who { display: flex; gap: 10px; align-items: center; padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.acct-who b { display: block; font-size: 13px; word-break: break-all; }
.acct-who small { display: block; color: var(--ink-3); font-size: 12px; margin-top: 2px; }

/* Sign-in dialog: a brand panel beside the form on wide screens, a bottom sheet on phones. */
dialog.auth-dlg { width: min(820px, calc(100% - 32px)); max-width: none; padding: 0; border-radius: 20px; overflow: hidden; background: var(--panel); box-shadow: 0 24px 64px rgba(10, 14, 20, .28); }
dialog.auth-dlg[open] { animation: auth-in .26s cubic-bezier(.2, .8, .2, 1); }
dialog.auth-dlg::backdrop { background: rgba(10, 14, 20, .45); backdrop-filter: blur(3px); animation: auth-fade .2s; }
@keyframes auth-in { from { opacity: 0; transform: translateY(10px) scale(.98); } }
@keyframes auth-fade { from { opacity: 0; } }
.auth-shell { display: grid; grid-template-columns: 320px minmax(0, 1fr); min-height: 580px; }
/* Pinned from the top (not re-centred), so a taller form grows downward
   instead of moving the whole dialog. */
dialog.auth-dlg { margin-top: max(24px, calc(50vh - 300px)); margin-bottom: auto; max-height: calc(100vh - 48px); }
.auth-shell.solo { grid-template-columns: 1fr; min-height: 0; }
dialog.auth-dlg:has(.auth-shell.solo) { width: min(440px, calc(100% - 32px)); }

.auth-side { position: relative; display: flex; flex-direction: column; gap: 18px; padding: 30px 28px 24px; background: var(--brand); color: var(--brand-ink); overflow: hidden; }
.auth-side::after { content: ""; position: absolute; inset: auto -40% -45% -10%; height: 70%; background: radial-gradient(closest-side, rgba(255,255,255,.16), transparent); pointer-events: none; }
.auth-brand { font-weight: 800; font-size: 18px; letter-spacing: -.01em; opacity: .95; }
.auth-side h2 { margin: 6px 0 0; font-size: 28px; line-height: 1.15; letter-spacing: -.02em; font-family: var(--font-head, var(--font)); font-weight: var(--head-weight, 700); color: inherit; }
.auth-perks { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.auth-perks li { display: flex; gap: 11px; align-items: flex-start; font-size: 14px; line-height: 1.35; }
.auth-perks svg, .auth-private svg { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; opacity: .9; margin-top: -1px; }
.auth-art { width: 100%; margin-top: auto; }
.auth-art * { fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; }
.auth-art .wall { stroke-width: 3.5; opacity: .9; }
.auth-art .door, .auth-art .dim { stroke-width: 1.2; opacity: .55; stroke-dasharray: 3 3; }
.auth-art .win { stroke-width: 1.5; opacity: .8; }
.auth-art .rug { stroke-width: 1.2; opacity: .45; }
.auth-art .piece { stroke-width: 1.8; fill: rgba(255,255,255,.16); }
.auth-art .piece.soft { fill: rgba(255,255,255,.08); opacity: .8; }
.auth-private { display: flex; gap: 8px; align-items: center; margin: 0; font-size: 12.5px; opacity: .85; }
.auth-private svg { width: 16px; height: 16px; }

.auth-main { position: relative; display: flex; flex-direction: column; justify-content: flex-start; padding: 40px 38px 28px; min-width: 0; }
.auth-x { position: absolute; top: 14px; right: 14px; width: 34px; height: 34px; padding: 0; display: grid; place-items: center; border-radius: 50%; border: 0; background: transparent; color: var(--ink-3); font-size: 15px; z-index: 2; }
.auth-x:hover { background: var(--bg); color: var(--ink); }
.auth-view { display: grid; gap: 14px; }
.auth-view.enter { animation: auth-view .18s ease; }
@keyframes auth-view { from { opacity: 0; } }
.auth-view h3 { margin: 0; padding-right: 36px; font-size: 24px; letter-spacing: -.015em; text-transform: none; color: var(--ink); font-family: var(--font-head, var(--font)); font-weight: var(--head-weight, 700); }
.auth-sub { margin: -8px 0 2px; color: var(--ink-2); font-size: 14.5px; line-height: 1.45; min-height: 2.9em; }
.auth-sent .auth-sub { min-height: 0; }
.auth-note { margin: 0; color: var(--ink-3); font-size: 13px; line-height: 1.5; }
.auth-note code, .auth-view code { font-size: 12px; background: var(--bg); padding: 1px 5px; border-radius: 4px; }

.auth-switch { position: relative; display: grid; grid-template-columns: 1fr 1fr; padding: 4px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); }
.auth-switch button { position: relative; z-index: 1; border: 0; background: none; height: 40px; min-height: 40px; padding: 0 8px; border-radius: 9px; font-weight: 600; font-size: 14px; color: var(--ink-3); transition: color .2s; display: flex; align-items: center; justify-content: center; }
.auth-switch button:hover { color: var(--ink); }
.auth-switch button[aria-selected=true] { color: var(--ink); }
.auth-switch .auth-pill { position: absolute; top: 4px; height: 40px; left: 4px; width: calc(50% - 4px); border-radius: 9px; background: var(--panel); box-shadow: 0 1px 3px rgba(0,0,0,.12); transition: transform .26s cubic-bezier(.2, .8, .2, 1); }
.auth-switch:has([data-v=signup][aria-selected=true]) .auth-pill { transform: translateX(100%); }

.auth-providers { display: grid; gap: 8px; }
.auth-provider { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 11px; font-weight: 600; font-size: 14.5px; border-radius: 12px; background: var(--panel); }
.auth-provider svg { width: 18px; height: 18px; }
.auth-provider:hover { background: var(--bg); }
.auth-provider.busy { opacity: .6; }
.auth-or { display: flex; align-items: center; gap: 12px; color: var(--ink-3); font-size: 12px; }
.auth-or::before, .auth-or::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.auth-field { display: grid; gap: 6px; }
.auth-field label, .auth-label-row label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.auth-label-row { display: flex; justify-content: space-between; align-items: baseline; }
.auth-forgot { font-size: 13px; font-weight: 500; }
.auth-input { position: relative; display: flex; align-items: center; }
.auth-input > svg { position: absolute; left: 13px; width: 18px; height: 18px; fill: none; stroke: var(--ink-3); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; transition: stroke .15s; }
.auth-input input { width: 100%; height: 48px; padding: 0 14px 0 42px; font-size: 16px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--panel); color: var(--ink); transition: border-color .15s, box-shadow .15s; }
.auth-input input::placeholder { color: var(--ink-3); opacity: .8; }
.auth-input input:hover { border-color: color-mix(in srgb, var(--ink-3) 60%, var(--line)); }
.auth-input input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 16%, transparent); }
.auth-input:focus-within > svg { stroke: var(--accent); }
.auth-input input[name=password] { padding-right: 48px; }
.auth-eye { position: absolute; right: 6px; width: 36px; height: 36px; padding: 0; display: grid; place-items: center; border: 0; border-radius: 9px; background: none; color: var(--ink-3); }
.auth-eye:hover { color: var(--ink); background: var(--bg); }
.auth-eye svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.auth-field.bad .auth-input input { border-color: var(--err); }
.auth-field.bad .auth-input input:focus { box-shadow: 0 0 0 4px color-mix(in srgb, var(--err) 14%, transparent); }
.auth-field.bad .auth-input > svg { stroke: var(--err); }
.auth-ferr { display: flex; gap: 6px; align-items: center; margin: 0; color: var(--err); font-size: 13px; }
.auth-ferr svg, .auth-alert > svg { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.auth-caps { margin: 0; font-size: 12.5px; color: var(--warn); font-weight: 600; }
.auth-meter { display: grid; grid-template-columns: auto 1fr; grid-template-areas: "bars lbl" "hint hint"; align-items: center; gap: 4px 10px; }
.auth-meter .bars { grid-area: bars; display: grid; grid-template-columns: repeat(4, 28px); gap: 4px; }
.auth-meter .bars i { height: 4px; border-radius: 2px; background: var(--line); transition: background-color .2s; }
.auth-meter .bars[data-score="1"] i:nth-child(-n+1) { background: var(--err); }
.auth-meter .bars[data-score="2"] i:nth-child(-n+2) { background: var(--warn); }
.auth-meter .bars[data-score="3"] i:nth-child(-n+3) { background: color-mix(in srgb, var(--ok) 75%, var(--warn)); }
.auth-meter .bars[data-score="4"] i { background: var(--ok); }
.auth-meter .lbl { grid-area: lbl; font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.auth-meter .hint { grid-area: hint; font-size: 12.5px; color: var(--ink-3); }

.auth-alert { display: flex; gap: 9px; align-items: flex-start; padding: 11px 13px; border-radius: 12px; background: var(--err-soft); color: var(--err); font-size: 13.5px; line-height: 1.4; animation: auth-shake .3s; }
.auth-alert > div { display: grid; gap: 3px; }
.auth-alert span { color: var(--ink); }
.auth-alert .link { justify-self: start; font-weight: 600; font-size: 13.5px; }
@keyframes auth-shake { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }
.auth-go { position: relative; display: flex; align-items: center; justify-content: center; gap: 10px; height: 50px; margin-top: 2px; font-size: 15.5px; font-weight: 700; border-radius: var(--btn-radius, 12px); box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 28%, transparent); }
.auth-go:hover:not(:disabled) { filter: brightness(1.06); }
.auth-go .spin { display: none; width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: auth-spin .7s linear infinite; }
.auth-go.busy { cursor: progress; opacity: .85; }
.auth-go.busy .spin { display: inline-block; }
@keyframes auth-spin { to { transform: rotate(360deg); } }
.auth-alt { display: flex; justify-content: center; align-items: center; gap: 8px; flex-wrap: wrap; color: var(--ink-3); }
.auth-alt:empty { display: none; }
.auth-alt .link { font-size: 14px; font-weight: 500; }
.auth-fine { margin: 0; text-align: center; font-size: 12px; color: var(--ink-3); }
.auth-fine a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }

.auth-sent { justify-items: center; text-align: center; }
.auth-sent h3 { padding: 0; }
.auth-sent .auth-sub { margin: -6px 0 0; }
.auth-inbox { width: 76px; height: 76px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.auth-inbox svg { width: 42px; height: 42px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.auth-inbox .dot { fill: var(--accent); stroke: var(--panel); stroke-width: 2.5; animation: auth-ping 1.6s ease-in-out infinite; transform-origin: 38px 12px; }
@keyframes auth-ping { 50% { transform: scale(.75); } }
.auth-resend { padding: 10px 18px; border-radius: 999px; font-weight: 600; }
.auth-success { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 12px; background: var(--panel); animation: auth-fade .2s; z-index: 3; font-size: 17px; }
.auth-success span { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; background: var(--ok); color: #fff; animation: auth-pop .35s cubic-bezier(.2, 1.4, .4, 1); }
.auth-success svg { width: 34px; height: 34px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
@keyframes auth-pop { from { transform: scale(.4); opacity: 0; } }
.auth-success small { color: var(--ink-2); font-size: 14px; max-width: 280px; text-align: center; }
.auth-inbox.ok { background: color-mix(in srgb, var(--ok) 14%, var(--panel)); color: var(--ok); }
.auth-inbox.ok svg { width: 38px; height: 38px; stroke-width: 2; }
.auth-change { font-size: inherit; padding: 0 2px; }
.auth-steps { margin: 0; padding: 12px 16px 12px 36px; width: 100%; box-sizing: border-box; text-align: left; background: var(--bg); border-radius: 12px; display: grid; gap: 6px; font-size: 14px; color: var(--ink-2); }
.auth-steps b { color: var(--ink); }
.auth-mailbtn { display: inline-flex; align-items: center; gap: 8px; padding: 10px 18px; border-radius: 999px; background: var(--accent); color: var(--accent-ink, #fff); font-weight: 700; text-decoration: none; box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 28%, transparent); }
.auth-mailbtn:hover { filter: brightness(1.06); }
.auth-mailbtn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.auth-code { width: 100%; display: grid; gap: 6px; text-align: left; }
.auth-code label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.auth-code-row { display: flex; gap: 8px; }
.auth-code input { flex: 1; min-width: 0; height: 48px; font-size: 22px; letter-spacing: .3em; text-align: center; font-variant-numeric: tabular-nums; border-radius: 12px; }
.auth-code input[aria-invalid] { border-color: var(--err); }
.auth-code button { display: inline-flex; align-items: center; gap: 8px; height: 48px; padding: 0 18px; border-radius: 12px; font-weight: 700; }
.auth-code button .spin, .auth-wait .spin { display: none; width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: auth-spin .7s linear infinite; flex: none; }
.auth-code button.busy .spin, .auth-wait .spin { display: inline-block; }
.auth-wait { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--ink-2); text-align: left; }
.auth-wait .spin { color: var(--accent); }
.auth-sent-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
@media (prefers-reduced-motion: reduce) { dialog.auth-dlg[open], .auth-view, .auth-alert, .auth-success span, .auth-inbox .dot { animation: none; } }
@media (max-width: 720px) {
  .auth-shell { grid-template-columns: 1fr; min-height: 0; }
  .auth-side { display: none; }
  .auth-main { padding: 26px 20px calc(22px + env(safe-area-inset-bottom)); }
}
.rooms-signin { display: flex; gap: 14px; align-items: center; justify-content: space-between; margin: 0 22px; padding: 12px 14px; border-radius: 12px; background: var(--accent-soft); }
.rooms-signin b { display: block; }
.rooms-signin span { display: block; font-size: 13px; color: var(--ink-2); margin-top: 2px; }
.rooms-signin button { flex: none; }
.b-save .link { font-weight: 600; }
@media (max-width: 820px) {
  .save-state { padding: 4px; }
  .save-state .lbl { display: none; }
  .save-state .lbl { display: none; }
  button.account .lbl { display: none; }
  button.account { padding: 5px 7px; }
  .avatar { width: 28px; height: 28px; font-size: 13px; }
  .rooms-signin { flex-direction: column; align-items: stretch; margin: 0 14px; }
  dialog.auth-dlg, dialog.auth-dlg:has(.auth-shell.solo) { width: 100%; max-width: 100%; margin: auto 0 0; border-radius: 22px 22px 0 0; max-height: 94dvh; overflow: auto; }
  dialog.auth-dlg[open] { animation: auth-up .3s cubic-bezier(.2, .8, .2, 1); }
  @keyframes auth-up { from { transform: translateY(40px); opacity: 0; } }
  .auth-main::before { content: ""; position: absolute; top: 8px; left: 50%; width: 40px; height: 5px; margin-left: -20px; border-radius: 3px; background: color-mix(in srgb, var(--ink-3) 40%, transparent); }
}

/* ---------- builder: 3D view tools, drag and drop, motion ---------- */
.b-canvas { position: relative; flex: 1; min-width: 0; }
.b-canvas > canvas { display: block; }
.b-labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
/* The 3D layer moves labels with `transform` every frame, so nothing may animate it
   (that's what made them trail the camera); hover and drop effects use `scale`. */
.l3, .l3:active { transition: none; translate: none; }
.l3 { pointer-events: auto; font: 600 12px/1.2 var(--font); white-space: nowrap; border-radius: 6px; padding: 2px 7px; background: var(--panel); border: 1.5px solid var(--accent); color: var(--accent); box-shadow: 0 1px 4px rgba(0,0,0,.12); cursor: pointer; }
button.l3 { min-height: 0; }
.l3.dim:hover, .l3.in:hover { text-decoration: line-through; }
.l3.in { border-color: var(--in-color, #0f8a7e); color: var(--in-color, #0f8a7e); border-style: dashed; }
.l3.in.front { border-style: dotted; }
.l3.total { pointer-events: none; border-color: var(--ink-3); color: var(--ink); font-weight: 700; background: color-mix(in srgb, var(--panel) 88%, transparent); }
.l3.num { pointer-events: none; opacity: .8; width: 20px; height: 20px; padding: 0; display: grid; place-items: center; border-radius: 50%; border: 0; background: color-mix(in srgb, var(--ink) 55%, transparent); color: #fff; font-size: 11.5px; box-shadow: none; }
/* These sit on 3D labels positioned by a transform: never scale or translate
   them (that multiplies their position and they jump away from the pointer).
   Hover grows a ring instead. */
.l3.joint { width: 26px; height: 26px; padding: 0; display: grid; place-items: center; border-radius: 50%; border: 2px dashed var(--accent); color: var(--accent); font-size: 18px; font-weight: 700; background: var(--panel); transition: background-color .15s, box-shadow .15s; }
.l3.joint:hover { background: var(--accent-soft); border-style: solid; box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent), 0 1px 4px rgba(0,0,0,.12); }
.l3.del { width: 30px; height: 30px; padding: 0; display: grid; place-items: center; border-radius: 50%; border: 2px solid #fff; background: var(--err); color: #fff; font-size: 14px; box-shadow: 0 2px 8px rgba(0,0,0,.25); }
.b-foot { user-select: none; }

/* Pieces glide to their new places in the top view, and new ones pop in. */
.cmp-svg .mod { transition: transform .32s cubic-bezier(.2, .8, .2, 1); transform-box: view-box; }
.cmp-svg .mod.new { animation: mod-pop .42s cubic-bezier(.3, 1.5, .5, 1); transform-box: fill-box; transform-origin: center; }
@keyframes mod-pop { from { transform: scale(.55); opacity: 0; } }
.cmp-svg .m-deg { fill: var(--ink-2); font-weight: 700; }
.cmp-svg .in.front .dim-l { stroke-dasharray: 1.2 2.4; }
.cmp-svg .mod { cursor: grab; }
.builder-view.dragging, .builder-view.dragging * { cursor: grabbing !important; }

/* Drag and drop: a chip follows the pointer; joints that can take it pulse,
   and the nearest one lights up. */
.drag-ghost { position: fixed; left: 0; top: 0; z-index: 100; pointer-events: none; display: flex; align-items: center; gap: 8px; margin: -22px 0 0 -30px; padding: 7px 12px 7px 8px; border-radius: 12px; background: var(--panel); color: var(--ink); border: 1.5px solid var(--accent); box-shadow: 0 10px 28px rgba(0,0,0,.22); font-size: 13px; transition: border-color .15s, background-color .15s, scale .15s; scale: 1.02; }
.drag-ghost svg { width: 30px; height: 30px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.drag-ghost.snap { background: var(--accent); color: var(--accent-ink); scale: .92; }
.cmp-svg .joint.drop-ok circle, .l3.joint.drop-ok { animation: joint-pulse 1s ease-in-out infinite; }
.cmp-svg .joint.drop-hot circle { fill: var(--accent); stroke-dasharray: none; }
.cmp-svg .joint.drop-hot .joint-t { fill: var(--accent-ink); }
.l3.joint.drop-hot { background: var(--accent); color: var(--accent-ink); border-style: solid; box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 30%, transparent); }
@keyframes joint-pulse { 50% { opacity: .55; } }
.m-tile { touch-action: pan-y; }
.kbd-help { font-size: 12.5px; color: var(--ink-2); }
.kbd-help summary { cursor: pointer; color: var(--ink-3); font-weight: 600; }
.kbd-help dl { display: grid; grid-template-columns: auto 1fr; gap: 5px 12px; margin: 8px 0 0; align-items: center; }
.kbd-help dt { white-space: nowrap; }
.kbd-help dd { margin: 0; }
kbd { display: inline-block; min-width: 18px; padding: 1px 5px; margin-right: 2px; border-radius: 5px; border: 1px solid var(--line); border-bottom-width: 2px; background: var(--bg); font: 600 11px/1.4 var(--font); text-align: center; color: var(--ink); }
.undo-redo button { min-width: 36px; font-size: 16px; }
.cmp-curve { flex-wrap: wrap; gap: 6px; }
.cmp-curve .chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
@media (prefers-reduced-motion: reduce) { .cmp-svg .mod, .cmp-svg .mod.new { transition: none; animation: none; } }

/* Like a desktop app: controls don't highlight as text when clicked or dragged. */
body { -webkit-tap-highlight-color: transparent; }
button, .ribbon, .tabs, .bv-toolbar, .bv-head, .b-templates, .m-tiles, .cmp-svg, .chip, .seg, .seg-pick, .layouts, .tool-btns,
.stepper, .menu, .rb-tabs, label, .side-toggle, .pill, .l3, .cg-h, .auth-switch, .drag-ghost, .b-labels { -webkit-user-select: none; user-select: none; }
.builder-view { -webkit-user-select: none; user-select: none; }
.builder-view input, .builder-view textarea, .builder-view select { -webkit-user-select: text; user-select: text; }
img, svg { -webkit-user-drag: none; }

/* Fabric and finish swatches (CC0 textures). */
.mat-pick { display: grid; gap: 8px; }
.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); gap: 6px; }
.swatches.small { grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); }
.sw { display: grid; justify-items: center; gap: 4px; padding: 4px 2px 5px; border-radius: 10px; border: 1.5px solid transparent; background: none; min-width: 0; }
.sw span { width: 42px; height: 42px; border-radius: 50%; background-size: 220%; background-position: center; box-shadow: inset 0 0 0 1px rgba(0,0,0,.12), 0 1px 3px rgba(0,0,0,.12); transition: transform .15s; }
.swatches.small .sw span { width: 32px; height: 32px; }
.sw small { font-size: 11px; color: var(--ink-2); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sw:hover span { transform: scale(1.06); }
.sw.on { border-color: var(--accent); background: var(--accent-soft); }
.sw.on small { color: var(--ink); font-weight: 600; }
.mat-tint { display: flex; align-items: end; gap: 12px; }
.mat-tint label { display: grid; gap: 4px; font-size: 12.5px; }
.mat-credit { margin: 0; font-size: 11px; }
.mat-credit a { color: inherit; }

/* Builder full view: the drawing or 3D view fills the window. */
.builder-view.full { position: fixed; inset: 0; z-index: 60; }
.builder-view.full .b-templates, .builder-view.full .b-form { display: none; }
.builder-view.full .bv-body { grid-template-columns: minmax(0, 1fr); }
.builder-view.full .bv-stage { height: auto; flex: 1; min-height: 0; }
.builder-view.full .bv-body { flex: 1; min-height: 0; }

/* ---------- tablets and small screens ---------- */
/* A tucked-away ribbon drops its tools down over the room. */
.ribbon.drop .rb-panel { position: absolute; left: 0; right: 0; top: 100%; box-shadow: 0 10px 24px rgba(0,0,0,.14); border-bottom: 1px solid var(--line); }
.ribbon.drop.collapsed .rb-panel { box-shadow: none; border-bottom: 0; }
.ribbon.drop .rb-collapse .ri { transform: none; }
.ribbon.drop:not(.collapsed) .rb-collapse { color: var(--accent); }

@media (max-width: 1180px) and (min-width: 821px) {
  :root { --side: 300px; }
  .bv-title .hint { display: none; }
  .inspector { width: 292px; }
  .bv-body { grid-template-columns: 64px minmax(0, 1fr) 316px; }
  /* Templates become an icon rail; names show as tooltips. */
  .bv-body .b-templates { padding: 6px 4px; }
  .bv-body .b-templates .b-tpl { flex-direction: column; justify-content: center; gap: 2px; padding: 8px 2px; font-size: 10px; text-align: center; }
  .bv-body .b-templates .b-tpl span { white-space: normal; line-height: 1.1; }
  .bv-body .b-templates .cg-h.b-group { font-size: 9.5px; padding: 6px 2px 2px; letter-spacing: .02em; }
  .bv-body .b-templates .cg-chev { display: none; }
}


/* ---------- one size scale for mouse and touch (everything but phones) ----------
   Desktop and tablet share this layout, so every control is a comfortable
   finger target and nothing depends on hovering, double-clicking or a keyboard. */
@media (min-width: 821px) {
  :root { --ctl: 40px; --ctl-sm: 36px; --ctl-lg: 48px; }
  body { font-size: 14.5px; grid-template-rows: 60px auto minmax(0, 1fr); }
  button { min-height: var(--ctl); padding: 8px 14px; border-radius: 10px; }
  button.icon { min-width: var(--ctl); padding: 0 10px; font-size: 17px; }
  button.link { min-height: 0; padding: 6px 2px; }
  /* :where() keeps this a default, so a component's own field styling (like an icon gap) wins. */
  input:where(:not([type=checkbox]):not([type=radio]):not([type=color]):not([type=range])), select, textarea { min-height: var(--ctl); padding: 8px 11px; font-size: 16px; border-radius: 10px; }
  input[type=checkbox], input[type=radio] { width: 20px; height: 20px; accent-color: var(--accent); }
  input[type=color] { min-height: var(--ctl); min-width: 56px; padding: 3px; border-radius: 10px; }
  label.check { min-height: var(--ctl-sm); display: inline-flex; align-items: center; gap: 9px; }
  /* Builder: always the whole window. */
  .builder-view { position: fixed; inset: 0; z-index: 30; }

  /* Header */
  .top { gap: 14px; padding: 0 18px; }
  .logo { font-size: 19px; }
  .room-switch { min-height: var(--ctl); padding: 6px 10px; font-size: 15px; }
  .save-state { min-height: 34px; padding: 4px 12px; font-size: 12.5px; }
  .seg { padding: 3px; border-radius: 12px; }
  .seg button { min-height: 38px; padding: 6px 18px; border-radius: 9px; }
  .seg button.seg-icon { padding: 6px 14px; }
  .actions { gap: 8px; }
  .actions button { min-height: 42px; }
  #undo, #redo { min-width: 42px; }
  button.account.signed-in { min-height: 0; }

  /* Ribbon */
  .rb-tabs { height: 44px; }
  .rb-tab { min-height: 42px; padding: 8px 16px; font-size: 14.5px; }
  .rb-collapse { min-width: 42px; min-height: 42px; }
  .rb-btn { min-width: 72px; min-height: 66px; padding: 8px 8px 6px; gap: 5px; font-size: 12.5px; border-radius: 10px; }
  .rb-btn .ri { width: 24px; height: 24px; }
  .rb-btn:hover:not(:disabled) { background: var(--bg); border-color: var(--line); }
  .rb-glabel { font-size: 11px; }

  /* Side panel */
  .tabs { padding: 0 10px; }
  .tabs button { min-height: 50px; padding: 12px 14px 10px; font-size: 15px; }
  .chip { min-height: var(--ctl-sm); padding: 6px 15px; font-size: 14px; }
  .chips { gap: 8px; }
  .filters summary { padding: 10px 0; min-height: var(--ctl); display: flex; align-items: center; gap: 6px; cursor: pointer; }
  .card { border-radius: 14px; }
  .cg-h { min-height: 44px; font-size: 13.5px; }
  .room-form section { padding: 16px 16px 12px; }
  .row3 { gap: 10px; margin-bottom: 10px; }
  .row3 label, .room-form label { font-size: 13px; }

  /* Room view overlays */
  .layout-tab { min-height: var(--ctl); padding: 6px 14px; font-size: 14px; gap: 8px; }
  .layout-tab .more { display: inline-grid; place-items: center; width: 28px; height: 28px; margin: -4px -8px -4px 0; border-radius: 8px; font-weight: 700; letter-spacing: 1px; color: var(--ink-2); }
  .layout-tab .more:hover { background: var(--bg); color: var(--ink); }
  .tool-btns { gap: 8px; right: 14px; bottom: 14px; flex-direction: row; align-items: end; }
  .tool-btns button { min-height: 44px; font-size: 14px; }
  #help-btn { min-width: 44px; font-weight: 700; }
  .pill { min-height: 44px; padding: 10px 20px; font-size: 14.5px; }
  .side-toggle { width: 26px; height: 72px; margin-top: -36px; }
  .menu { min-width: 260px; padding: 8px; border-radius: 14px; }
  .menu button { min-height: 44px; padding: 9px 12px; font-size: 14.5px; gap: 10px; border-radius: 10px; }
  .menu .menu-title { font-size: 12.5px; padding: 6px 12px 4px; }

  /* Item panel */
  .inspector { padding: 16px; border-radius: 16px; width: 340px; }
  .insp-btns { gap: 6px; }
  .insp-head .icon, #insp-min, #insp-close { min-width: var(--ctl); min-height: var(--ctl); }
  .inspector .chip { min-height: 36px; }
  .insp-actions { gap: 8px; }
  .insp-actions button { min-height: var(--ctl); padding: 8px 14px; font-size: 14px; }
  .inspector .row3 input { text-align: left; }

  /* Builder */
  .bv-head { padding: 10px 18px; min-height: 64px; }
  .bv-head #b-submit { min-height: var(--ctl-lg); padding: 10px 22px; font-size: 15.5px; }
  .bv-head [data-close] { min-height: var(--ctl-lg); padding: 10px 18px; }
  .bv-toolbar { gap: 8px; padding: 12px 16px 10px; }
  .bv-toolbar button { min-height: var(--ctl); }
  .seg-pick button { min-height: 36px; padding: 6px 16px; }
  .b-tpl { min-height: 44px; padding: 9px 10px; font-size: 14px; border-radius: 10px; }
  .b-tpl svg { width: 22px; height: 22px; }
  .m-tile { min-height: 78px; font-size: 12.5px; }
  .stepper button, .stepper-field .stepper button { width: 46px; height: var(--ctl); }
  .stepper-field { font-size: 13px; }
  .b-form { gap: 14px; }
  .l3.joint { width: 32px; height: 32px; }
  .l3.del { width: 34px; height: 34px; }
  .cmp-sel-row button { min-width: var(--ctl); }
  .kbd-help summary { padding: 8px 0; }
  .bv-pop { width: 340px; padding: 12px; border-radius: 16px; }

  /* Dialogs */
  dialog { border-radius: 18px; }
  .dlg-actions button { min-height: 44px; padding: 10px 18px; }
}
@media (min-width: 821px) and (max-width: 1180px) {
  .inspector { width: 300px; }
}

/* Catalog: search with Build beside it; Category and Filters dropdowns; pills for what's applied. */
.search { display: flex; gap: 8px; align-items: stretch; }
.search input { flex: 1; min-width: 0; }
.build-cta { flex: none; display: inline-flex; align-items: center; gap: 4px; background: var(--accent-soft); color: var(--accent); border-color: transparent; font-weight: 600; white-space: nowrap; }
.build-cta:hover:not(:disabled) { border-color: var(--accent); }
.filter-bar { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 8px; padding: 0 12px 8px; }
.dd { display: flex; align-items: center; gap: 6px; min-width: 0; text-align: left; background: var(--panel); }
.dd .dd-l { color: var(--ink-3); font-size: 12.5px; }
.dd .dd-v { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.dd .dd-c { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; color: var(--ink-3); transition: transform .2s; }
.dd[aria-expanded=true] { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.dd[aria-expanded=true] .dd-c { transform: rotate(180deg); }
.dd.set { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.dd-n { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 700; display: inline-grid; place-items: center; }
.active-filters { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px; align-items: center; }
.active-filters:not(:empty) { padding-bottom: 8px; }
.fpill { display: inline-flex; align-items: center; gap: 6px; min-height: 32px !important; padding: 4px 8px 4px 12px !important; border-radius: 999px; background: var(--accent-soft); color: var(--accent); border-color: transparent; font-size: 13px; font-weight: 600; }
.fpill span { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; font-size: 10px; background: color-mix(in srgb, var(--accent) 18%, transparent); }
.fpill:hover span { background: var(--accent); color: var(--accent-ink); }
.dd-pop { position: fixed; z-index: 60; }
.cat-pop { width: 260px; max-height: min(70vh, 520px); overflow: auto; }
.cat-pop button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.cat-pop button small { margin-left: auto; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.filt-pop { width: 300px; display: grid; gap: 8px; padding: 12px; }
.filt-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.filt-grid label { display: grid; gap: 4px; font-size: 12.5px; color: var(--ink-2); }
.filt-door { font-size: 13.5px; }
.filt-sort { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.filt-pop .filt-sort button { justify-content: center; text-align: center; border: 1px solid var(--line); background: var(--panel); font-size: 13.5px; }
.filt-pop .filt-sort button.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.filt-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 4px; }
.filt-pop .filt-foot .primary { width: auto; justify-content: center; background: var(--accent); color: var(--accent-ink); }
.filt-pop .filt-foot .link { width: auto; }
.filt-pop .menu-title { padding: 2px 0; }
.tabs button { white-space: nowrap; }
.tabs .count:empty { display: none; }
@media (min-width: 821px) and (max-width: 1180px) { .tabs button { padding-left: 10px; padding-right: 10px; font-size: 14.5px; } }
.filter-bar { grid-template-columns: minmax(0, 1fr) auto; }
.filter-bar .dd-l { display: none; }
#filt-dd .dd-v { flex: none; }

/* Builder steppers: two to a row, each filling its half. */
.cmp-steppers { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.cmp-steppers .stepper { width: 100%; }
.cmp-steppers .stepper output { flex: 1; }
/* A door or window row: its type and remove button, then which wall, full width. */
.op-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.op-head > span { display: none; }
.op-head select[data-f=wall] { grid-column: 1 / -1; grid-row: 2; }
.op-head select[data-f=corner] { grid-column: 1 / -1; grid-row: 2; }
.op-head .icon[data-del] { grid-column: 2; grid-row: 1; }
.opening { padding: 10px; }

/* Drawing bar: a compact toolbar along the bottom of the plan. */
.drawbar:has(.db-row) { top: auto; bottom: 14px; flex-direction: column; align-items: stretch; gap: 6px; padding: 8px 10px; width: min(760px, calc(100% - 24px)); flex-wrap: nowrap; }
.drawbar .db-tip { font-size: 12.5px; color: var(--ink-2); padding: 0 4px; }
.drawbar .db-tip b { color: var(--ink); }
.drawbar .db-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.drawbar .db-row .grow { flex: 1; }
.drawbar .draw-len { display: inline-flex; align-items: center; gap: 6px; }
.drawbar #draw-len { width: 170px; }
.draw-dirs button { min-width: 38px; padding: 4px 0; font-size: 16px; }
.stage-wrap.drawing .tool-btns, .stage-wrap.drawing .layouts { display: none; }
@media (max-width: 980px) { .drawbar .lbl { display: none; } .drawbar #draw-len { width: 130px; } }
@media (max-width: 820px) {
  /* Phone header: the view switch keeps its size; the room name gives way.
     "Design it for me" lives in the Home tab and on the welcome card. */
  #design-btn { display: none; }
  .top .seg { flex-shrink: 0; }
  .brand { flex: 1 1 auto; min-width: 0; }
  .room-switch { min-width: 0; }
  .room-switch .rs-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
/* The logo on the sign-in panel's brand colour: a light tile, white wordmark. */
.auth-brand { display: flex; align-items: center; gap: 9px; }
.auth-brand .logo-mark.on-brand { background: rgba(255,255,255,.18); box-shadow: inset 0 0 0 1px rgba(255,255,255,.3); }
.auth-brand .logo-word { height: 22px; }
.auth-brand .logo-word .w-sofa, .auth-brand .logo-word .w-plot { fill: currentColor; }

/* Prices are estimates: a small "est." tag on each price, and a note where totals add up. */
.est { margin-left: 3px; font-size: .78em; font-weight: 500; color: var(--ink-3); cursor: help; text-transform: none; letter-spacing: 0; }
.price-note { margin: 8px 0 0; padding: 10px 12px; border-radius: 10px; background: var(--bg); color: var(--ink-2); font-size: 12.5px; line-height: 1.45; }
.price-note b { color: var(--ink); }
.price-note.small { margin: -2px 12px 8px; padding: 0; background: none; font-size: 12px; color: var(--ink-3); }

/* ---------- plans and Sofa Tokens ---------- */
.tok-ico { width: 18px; height: 18px; flex: none; vertical-align: -4px; }
.tok-chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px 3px 4px; border-radius: 999px; background: color-mix(in srgb, #6a5cf6 12%, var(--panel)); color: var(--ink); font-size: 13px; }
.tok-chip b { font-variant-numeric: tabular-nums; }
button.account.signed-in { gap: 8px; border-radius: 999px; padding: 2px 2px 2px 4px; }
.acct-plan { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 12px; font-size: 13.5px; color: var(--ink-2); }
.acct-plan b { color: var(--ink); }
.acct-menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 6px; }

dialog.plans-dlg { width: min(880px, calc(100% - 32px)); max-width: none; padding: 0; border-radius: 20px; overflow: auto; max-height: calc(100vh - 40px); }
dialog.plans-dlg::backdrop { background: rgba(10, 14, 20, .45); backdrop-filter: blur(3px); }
.pl-head { display: flex; justify-content: space-between; gap: 16px; align-items: start; padding: 24px 26px 8px; }
.pl-head h3 { margin: 0; font-size: 22px; text-transform: none; letter-spacing: -.01em; color: var(--ink); }
.pl-head .hint { margin: 4px 0 0; font-size: 14px; }
.pl-body { padding: 12px 26px 26px; display: grid; gap: 18px; }
.pl-plans { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.pl-plan { border: 1.5px solid var(--line); border-radius: 16px; padding: 18px; display: flex; flex-direction: column; gap: 6px; }
.pl-plan.pro { border-color: var(--accent); background: linear-gradient(180deg, var(--accent-soft), var(--panel) 60%); }
.pl-plan.current { box-shadow: inset 0 0 0 1px var(--accent); }
.pl-name { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.pl-badge { font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); }
.pl-price b { font-size: 32px; letter-spacing: -.02em; }
.pl-price span { color: var(--ink-3); margin-left: 3px; }
.pl-alt { font-size: 13px; color: var(--ink-3); }
.pl-plan ul { list-style: none; margin: 8px 0; padding: 0; display: grid; gap: 7px; flex: 1; }
.pl-plan li { display: flex; gap: 8px; font-size: 14px; align-items: flex-start; }
.pl-plan li svg { width: 18px; height: 18px; flex: none; fill: none; stroke: var(--ok); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; margin-top: 1px; }
.pl-cta { display: flex; flex-direction: column; align-items: stretch; gap: 6px; }
.pl-cta .primary { min-height: 46px; font-size: 15px; }
.pl-note { margin: 0; color: var(--ok); font-weight: 600; }
.pl-tokens { border: 1.5px solid var(--line); border-radius: 16px; padding: 18px; display: grid; gap: 14px; }
.pl-tok-head { display: flex; justify-content: space-between; gap: 14px; align-items: start; }
.pl-tok-head h4 { margin: 0; font-size: 16px; display: flex; align-items: center; gap: 6px; }
.pl-tok-head h4 .tok-ico { width: 22px; height: 22px; }
.pl-tok-head .hint { margin: 4px 0 0; }
.pl-balance { text-align: right; } .pl-balance span { display: block; font-size: 12px; color: var(--ink-3); } .pl-balance b { font-size: 26px; }
.pl-packs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.pl-pack { position: relative; display: grid; justify-items: center; gap: 4px; padding: 16px 10px 12px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--panel); }
.pl-pack:hover:not(:disabled) { border-color: var(--accent); }
.pl-pack.best { border-color: #6a5cf6; background: color-mix(in srgb, #6a5cf6 7%, var(--panel)); }
.pl-best { position: absolute; top: -10px; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: #6a5cf6; color: #fff; }
.pl-n { display: inline-flex; align-items: center; gap: 6px; } .pl-n .tok-ico { width: 24px; height: 24px; } .pl-n b { font-size: 24px; }
.pl-p { color: var(--ink-2); font-weight: 600; }
.pl-costs { display: grid; gap: 6px; font-size: 13.5px; }
.pl-costs > div { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 6px 0; border-top: 1px solid var(--line); }
.pl-costs > div span:last-child { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; white-space: nowrap; }
.pl-costs .hint { margin: 2px 0 0; }
.pl-msg { margin: 0; padding: 10px 12px; border-radius: 10px; background: var(--accent-soft); color: var(--ink); font-size: 13.5px; }
@media (max-width: 720px) {
  .pl-plans, .pl-packs { grid-template-columns: 1fr; }
  dialog.plans-dlg { width: 100%; margin: auto 0 0; border-radius: 22px 22px 0 0; max-height: 94dvh; }
}

/* ---------- photo view tools ---------- */
#stage canvas.photo-front { position: absolute; z-index: 1; pointer-events: none; touch-action: none; }
.photo-front.painting { cursor: none; }
.brush-ring { position: absolute; z-index: 3; pointer-events: none; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1.5px var(--accent), 0 0 8px rgba(0,0,0,.35); }
.brush-ring.erase { border-style: dashed; }
.photobar { display: flex; flex-direction: column; gap: 8px; }
.photobar .pb-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.photobar .pb-tool { padding-top: 8px; border-top: 1px solid var(--line); }
.photobar .pb-tip { font-size: 12.5px; color: var(--ink-2); flex-basis: 100%; }
.photobar .tb-toggle svg, #pb-save svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#pb-save { display: inline-flex; align-items: center; gap: 6px; }
.pb-slider { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); }
.pb-slider input { width: 120px; accent-color: var(--accent); }
#save-menu button small { margin-left: auto; color: var(--ink-3); }
.photobar { width: max-content; max-width: calc(100% - 24px); }

/* ---------- AI tools ---------- */
.photobar #pb-empty svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.real-btn { position: absolute; top: 12px; right: 12px; z-index: 2; display: inline-flex; align-items: center; gap: 8px; height: 44px; padding: 0 14px 0 12px; border-radius: 999px; border: 0; font-size: 15px; font-weight: 600; color: #fff;
  background: linear-gradient(135deg, #7c4dff, #3f6df2); box-shadow: 0 4px 14px rgba(76, 70, 220, .35); animation: panel-in .2s; }
.real-btn:hover { filter: brightness(1.06); box-shadow: 0 6px 18px rgba(76, 70, 220, .45); }
.real-btn .rb-spark { font-size: 17px; }
.real-btn .ai-cost { padding: 2px 7px 2px 3px; border-radius: 999px; background: rgba(255, 255, 255, .2); font-size: 13px; }
@media (max-width: 820px) { .real-btn { top: 58px; right: 10px; height: 38px; padding: 0 10px; font-size: 14px; gap: 6px; } }
.ai-cost { display: inline-flex; align-items: center; gap: 3px; margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ai-cost .tok-ico { width: 16px; height: 16px; vertical-align: -3px; }

dialog.ai-dlg { width: min(980px, calc(100% - 32px)); max-width: none; padding: 0; border-radius: 18px; overflow: hidden; display: none; flex-direction: column; max-height: calc(100vh - 40px); }
dialog.ai-dlg[open] { display: flex; }
dialog.ai-dlg::backdrop { background: rgba(10, 14, 20, .55); backdrop-filter: blur(3px); }
.ai-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; }
.ai-head h3 { margin: 0; font-size: 18px; text-transform: none; letter-spacing: -.01em; color: var(--ink); }
.ai-stage { position: relative; background: #111; min-height: 240px; display: grid; place-items: center; overflow: hidden; user-select: none; -webkit-user-select: none; }
.ai-stage img { display: block; max-width: 100%; max-height: calc(100vh - 220px); width: auto; height: auto; }
.ai-stage.working img, .ai-stage.error img { filter: saturate(.6) brightness(.55); }
.ai-shimmer { position: absolute; inset: 0; background: linear-gradient(110deg, transparent 30%, rgba(255, 255, 255, .14) 50%, transparent 70%); background-size: 250% 100%; animation: ai-shimmer 1.8s linear infinite; }
@keyframes ai-shimmer { from { background-position: 120% 0; } to { background-position: -120% 0; } }
.ai-progress { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; color: #fff; text-align: center; padding: 20px; text-shadow: 0 1px 8px rgba(0, 0, 0, .5); }
.ai-progress b { font-size: 17px; }
.ai-progress span { font-size: 13.5px; opacity: .85; }
.ai-spin { width: 34px; height: 34px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, .25); border-top-color: #fff; animation: spin .9s linear infinite; }
.ai-stage.compare { display: block; width: fit-content; max-width: 100%; margin: 0 auto; background: none; }
.ai-stage.compare .ai-after { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; clip-path: inset(0 0 0 var(--cut)); max-height: none; }
.ai-handle { position: absolute; top: 0; bottom: 0; left: var(--cut); width: 2px; margin-left: -1px; background: #fff; box-shadow: 0 0 6px rgba(0, 0, 0, .4); pointer-events: none; }
.ai-handle span { position: absolute; top: 50%; left: 50%; width: 34px; height: 34px; margin: -17px 0 0 -17px; border-radius: 50%; background: #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, .35); }
.ai-handle span::before, .ai-handle span::after { content: ''; position: absolute; top: 12px; border: 5px solid transparent; }
.ai-handle span::before { left: 5px; border-right-color: #444; }
.ai-handle span::after { right: 5px; border-left-color: #444; }
.ai-cut { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: ew-resize; touch-action: pan-y; }
.ai-tag { position: absolute; top: 10px; padding: 3px 9px; border-radius: 999px; background: rgba(0, 0, 0, .55); color: #fff; font-size: 12px; font-weight: 600; pointer-events: none; }
.ai-tag.l { left: 10px; } .ai-tag.r { right: 10px; }
.ai-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 18px 16px; flex-wrap: wrap; }
.ai-foot .hint { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-size: 12.5px; max-width: 520px; }
.ai-btns { display: flex; gap: 8px; margin-left: auto; flex-wrap: wrap; }
.ai-btns button { display: inline-flex; align-items: center; gap: 6px; }
.ai-btns .ai-cost { margin-left: 2px; font-weight: 600; }
@media (max-width: 720px) {
  dialog.ai-dlg { width: 100%; margin: auto 0 0; border-radius: 22px 22px 0 0; max-height: 94dvh; }
  .ai-stage img { max-height: 60dvh; }
  .ai-btns { width: 100%; } .ai-btns button { flex: 1; justify-content: center; }
}
.ai-foot .hint > span { display: inline; }
.ai-foot .hint .link { padding: 0; font-size: inherit; }

/* ---------- My pictures ---------- */
dialog.pics-dlg { width: min(1040px, calc(100% - 32px)); max-width: none; height: min(760px, calc(100% - 40px)); padding: 0; border-radius: 18px; overflow: hidden; display: none; flex-direction: column; }
dialog.pics-dlg[open] { display: flex; }
dialog.pics-dlg::backdrop { background: rgba(10, 14, 20, .5); backdrop-filter: blur(3px); }
.pics-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 20px 10px; }
.pics-head h3 { margin: 0; font-size: 20px; text-transform: none; letter-spacing: -.01em; color: var(--ink); }
.pics-head .hint { margin: 2px 0 0; }
.pics-back { font-size: 15px; font-weight: 600; padding: 6px 0; }
.pics-filters { display: flex; gap: 6px; padding: 0 20px 10px; flex-wrap: wrap; }
.pics-filters .chip { padding: 6px 14px; font-size: 14px; }
.pics-body { flex: 1; overflow: auto; padding: 4px 20px 20px; }
.pics-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.pic-card { display: flex; flex-direction: column; padding: 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--panel); text-align: left; cursor: pointer; transition: border-color .12s, transform .12s, box-shadow .12s; }
.pic-card:hover { border-color: var(--accent); transform: translateY(-1px); box-shadow: var(--shadow); }
.pic-card img, .pic-card .pic-missing { width: 100%; aspect-ratio: 3 / 2; object-fit: cover; display: block; background: var(--bg); }
.pic-card.skeleton { aspect-ratio: 3 / 2.5; background: linear-gradient(110deg, var(--bg) 30%, var(--line) 50%, var(--bg) 70%); background-size: 250% 100%; animation: ai-shimmer 1.6s linear infinite; cursor: default; }
.pic-missing { display: grid; place-items: center; color: var(--ink-3); font-size: 13px; }
.pic-meta { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px 10px; min-width: 0; }
.pic-kind { font-size: 13px; font-weight: 600; color: var(--ink); }
.pic-kind.k-real::before { content: '✨ '; }
.pic-sub { font-size: 12.5px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pics-empty { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; color: var(--ink-2); padding: 60px 20px; max-width: 420px; margin: 0 auto; font-size: 14px; }
.pics-empty b { color: var(--ink); font-size: 16px; }
.pics-view { flex: 1; min-height: 0; display: grid; place-items: center; background: #111; }
.pics-view img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.pics-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 20px 16px; flex-wrap: wrap; }
.pics-foot .hint { margin: 0; }
.pics-confirm { align-self: center; font-size: 14px; color: var(--ink-2); }
@media (max-width: 720px) {
  dialog.pics-dlg { width: 100%; height: 94dvh; margin: auto 0 0; border-radius: 22px 22px 0 0; }
  .pics-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .pics-foot .ai-btns { width: 100%; } .pics-foot .ai-btns button { flex: 1; }
}

/* ---------- AI measuring tools (Add from a photo, Read a plan) ---------- */
dialog.aim-dlg, dialog.real-dlg { width: min(760px, calc(100% - 32px)); max-width: none; padding: 0; border-radius: 18px; overflow: hidden; display: none; flex-direction: column; max-height: calc(100vh - 40px); }
dialog.real-dlg { width: min(620px, calc(100% - 32px)); }
dialog.aim-dlg[open], dialog.real-dlg[open] { display: flex; }
dialog.aim-dlg::backdrop, dialog.real-dlg::backdrop { background: rgba(10, 14, 20, .5); backdrop-filter: blur(3px); }
.aim-body, .real-body { padding: 0 20px 4px; overflow: auto; display: grid; gap: 12px; }
.aim-intro { margin: 0; color: var(--ink-2); font-size: 14.5px; line-height: 1.5; }
.aim-drop { display: grid; place-items: center; gap: 6px; min-height: 220px; border: 2px dashed var(--line); border-radius: 14px; background: var(--bg); color: var(--ink-2); text-align: center; padding: 18px; cursor: pointer; transition: border-color .15s, background-color .15s; }
.aim-drop:hover, .aim-drop:focus-visible, .aim-drop.over { border-color: var(--accent); background: var(--accent-soft); }
.aim-drop svg { width: 40px; height: 40px; fill: none; stroke: var(--accent); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.aim-drop b { color: var(--ink); font-size: 16px; }
.aim-drop span { font-size: 13px; }
.aim-drop.has { padding: 8px; min-height: 0; border-style: solid; }
.aim-drop img { max-width: 100%; max-height: 340px; border-radius: 8px; display: block; }
.aim-tips { margin: 0; padding-left: 18px; color: var(--ink-3); font-size: 13px; display: grid; gap: 3px; }
.aim-work { border-radius: 14px; min-height: 260px; }
.aim-work img { max-height: 420px; }
.aim-result { gap: 14px; }
.aim-piece-grid { display: grid; grid-template-columns: 220px 1fr; gap: 18px; align-items: start; }
.aim-thumb { width: 100%; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); object-fit: contain; max-height: 280px; }
.aim-form { display: grid; gap: 10px; min-width: 0; }
.aim-badge { font-size: 13px; line-height: 1.45; padding: 8px 10px; border-radius: 10px; }
.aim-badge.ok { background: color-mix(in srgb, var(--ok) 13%, var(--panel)); color: var(--ink); }
.aim-badge.ok::before { content: '✓ '; color: var(--ok); font-weight: 700; }
.aim-badge.est { background: var(--warn-soft, #fff4d6); color: var(--ink); }

.aim-field { display: grid; gap: 4px; font-size: 12.5px; font-weight: 600; color: var(--ink-2); min-width: 0; }
.aim-field input, .aim-field select { font-weight: 400; }
.aim-row { display: flex; gap: 10px; }
.aim-row > * { flex: 1; }
.aim-color { flex: 0 0 90px; }
.aim-color input { height: 40px; padding: 2px; width: 100%; }
.aim-row.dims .aim-dim { display: grid; gap: 4px; font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.aim-dim input { font-variant-numeric: tabular-nums; }
.aim-fit { margin: 0; font-size: 13px; padding-left: 22px; position: relative; color: var(--ink-2); }
.aim-fit::before { position: absolute; left: 0; font-weight: 700; }
.aim-fit.ok::before { content: '✓'; color: var(--ok); }
.aim-fit.tight::before, .aim-fit.tilt::before { content: '!'; color: var(--warn, #b7791f); }
.aim-fit.no::before, .aim-fit.bad::before { content: '✕'; color: var(--err); }
.aim-fit.na::before { content: 'ⓘ'; color: var(--ink-3); }
.aim-rooms { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.aim-room { display: grid; justify-items: center; gap: 3px; padding: 10px; border: 1.5px solid var(--line); border-radius: 12px; background: var(--panel); text-align: center; font-size: 13px; }
.aim-room.on { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent); }
.aim-room svg { width: 110px; height: 110px; }
.aim-room svg .room { fill: color-mix(in srgb, var(--accent) 12%, var(--panel)); stroke: var(--ink); stroke-width: 2; stroke-linejoin: round; }
.aim-room svg .door { fill: #c2793b; } .aim-room svg .window { fill: #3f8fd6; }
.aim-room b { font-size: 14px; color: var(--ink); }
.aim-room small, .aim-room-meta { color: var(--ink-3); font-size: 12px; }
.aim-room .aim-badge { padding: 3px 8px; font-size: 12px; }
.real-label { font-size: 12.5px; font-weight: 700; color: var(--ink-2); text-transform: uppercase; letter-spacing: .04em; }
.real-styles { display: grid; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 8px; }
.real-style { display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: 10px; border: 1.5px solid var(--line); background: var(--panel); font-size: 13.5px; text-align: left; }
.real-style .sw { width: 18px; height: 18px; border-radius: 50%; flex: none; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12); }
.real-style.on { border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.real-light { justify-self: start; }
dialog .real-decor { display: flex; flex-direction: row; gap: 10px; align-items: flex-start; font-size: 14px; color: var(--ink); cursor: pointer; }
.real-decor input { flex: none; margin-top: 2px; accent-color: var(--accent); width: 18px; height: 18px; }
.real-decor small { display: block; color: var(--ink-3); font-size: 12.5px; }
@media (max-width: 720px) {
  dialog.aim-dlg, dialog.real-dlg { width: 100%; margin: auto 0 0; border-radius: 22px 22px 0 0; max-height: 94dvh; }
  .aim-piece-grid { grid-template-columns: 1fr; }
  .aim-thumb { max-height: 180px; }
  .aim-rooms { grid-template-columns: 1fr 1fr; }
}

/* ---------- Builder: AI set button and "Your modules" ---------- */
.b-ai { display: flex; align-items: center; gap: 8px; width: 100%; margin: 0 0 8px; padding: 10px 10px; border-radius: 10px; border: 0; font-size: 13px; font-weight: 700; color: #fff; text-align: left; background: linear-gradient(135deg, #7c4dff, #3f6df2); box-shadow: 0 3px 10px rgba(76, 70, 220, .28); }
.b-ai:hover { filter: brightness(1.06); }
.m-tile.yours { border-color: color-mix(in srgb, #7c4dff 40%, var(--line)); background: color-mix(in srgb, #7c4dff 6%, var(--panel)); }
.m-tile.yours img { width: 40px; height: 36px; object-fit: contain; border-radius: 6px; background: #fff; }
.m-tile.yours small { display: block; color: var(--ink-3); font-weight: 600; }
.yours-row { margin-bottom: 4px; }
@media (max-width: 820px) { .b-ai { width: auto; flex: none; margin: 0 6px 0 0; white-space: nowrap; } }

/* ---------- Pieces from a photo ---------- */
dialog.aim-set { width: min(1040px, calc(100% - 32px)); }
.set-top { display: grid; grid-template-columns: minmax(0, 1fr) 240px; gap: 16px; align-items: start; }
.set-photo { position: relative; justify-self: start; max-width: 100%; }
.set-photo img { display: block; max-width: 100%; max-height: 300px; border-radius: 10px; }
.set-box { position: absolute; border: 2px solid #7c4dff; border-radius: 6px; background: color-mix(in srgb, #7c4dff 10%, transparent); pointer-events: none; }
.set-box.off { opacity: .25; }
.set-box b { position: absolute; top: -10px; left: -10px; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: #7c4dff; color: #fff; font-size: 12px; }
.set-sum { display: grid; gap: 4px; font-size: 13.5px; color: var(--ink-2); }
.set-sum b { font-size: 17px; color: var(--ink); }
.set-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 10px; }
.set-card { display: grid; grid-template-columns: 28px 72px minmax(0, 1fr); gap: 10px; align-items: start; padding: 10px; border: 1.5px solid var(--line); border-radius: 12px; background: var(--panel); min-width: 0; }
.set-card input, .set-card select { min-width: 0; width: 100%; box-sizing: border-box; }
.set-card .aim-row { min-width: 0; }
.set-card .aim-row > * { min-width: 0; }
.set-card .aim-row.dims { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.set-card.off { opacity: .55; }
dialog .set-pick { display: grid; justify-items: center; gap: 4px; flex-direction: row; cursor: pointer; }
.set-pick input { width: 20px; height: 20px; accent-color: #7c4dff; margin: 0; }
.set-pick b { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: #7c4dff; color: #fff; font-size: 12px; }
.set-thumb { width: 72px; height: 72px; object-fit: contain; border-radius: 8px; background: var(--bg); border: 1px solid var(--line); display: block; }
.set-fields { display: grid; gap: 6px; min-width: 0; }
.set-fields > input { font-weight: 600; }
dialog .set-count { display: flex; flex-direction: row; align-items: center; gap: 4px; flex: 0 0 64px; font-size: 14px; color: var(--ink-2); }
.set-card .set-count input { width: 48px; flex: none; }
.set-card .aim-badge { padding: 4px 8px; font-size: 12px; justify-self: start; }
@media (max-width: 720px) {
  .set-top { grid-template-columns: 1fr; }
  .set-list { grid-template-columns: 1fr; }
}
.aim-link { display: flex; gap: 8px; }
.aim-link input { flex: 1; min-width: 0; height: 42px; }
.aim-link button { flex: none; height: 42px; padding: 0 16px; font-weight: 600; }
.b-ai .short { display: none; }
@media (max-width: 1180px) and (min-width: 821px) {
  .b-ai { flex-direction: column; justify-content: center; gap: 3px; padding: 8px 2px; font-size: 10px; text-align: center; line-height: 1.1; }
  .b-ai .long { display: none; }
  .b-ai .short { display: inline; }
}

/* ---------- confirm dialog (askConfirm) ---------- */
dialog.confirm-dlg { width: min(420px, calc(100% - 32px)); padding: 26px 24px 20px; border-radius: 18px; text-align: center; display: none; }
dialog.confirm-dlg[open] { display: grid; justify-items: center; gap: 10px; animation: cf-in .16s ease-out; }
dialog.confirm-dlg::backdrop { background: rgba(10, 14, 20, .45); backdrop-filter: blur(3px); }
@keyframes cf-in { from { opacity: 0; transform: translateY(6px) scale(.98); } }
.cf-icon { width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.confirm-dlg.danger .cf-icon { background: color-mix(in srgb, var(--err) 12%, var(--panel)); color: var(--err); }
.cf-icon svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.confirm-dlg h3 { margin: 4px 0 0; font-size: 18px; text-transform: none; letter-spacing: -.01em; color: var(--ink); line-height: 1.3; }
.confirm-dlg p { margin: 0; color: var(--ink-2); font-size: 14.5px; line-height: 1.5; max-width: 340px; }
.cf-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; margin-top: 10px; }
.cf-actions button { height: 46px; font-size: 15px; font-weight: 600; border-radius: 12px; }
button.danger-solid { background: var(--err); border-color: var(--err); color: #fff; }
button.danger-solid:hover { filter: brightness(1.06); }
@media (prefers-reduced-motion: reduce) { dialog.confirm-dlg[open] { animation: none; } }

/* ---------- icons (js/icons.js) ---------- */
.spark { width: 1.15em; height: 1.15em; flex: none; fill: currentColor; vertical-align: -0.2em; }
.ai-head h3 .spark, .ds-head h3 .spark { color: #7c4dff; }
.ai-head h3 { display: flex; align-items: center; gap: 8px; }
.design .spark, .real-btn .spark, .b-ai .spark { width: 1.35em; height: 1.35em; }
.tok-ico { filter: drop-shadow(0 1px 1px rgba(40, 30, 120, .18)); }

/* ---------- builder: leg style ---------- */
.leg-pick { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin-bottom: 6px; }
.leg-opt { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 4px; border-radius: 10px; font-size: 12px; min-height: 0; }
.leg-opt svg { width: 40px; height: 30px; fill: var(--accent-soft); stroke: var(--ink-3); stroke-width: 1.2; }
.leg-opt svg .f { fill: var(--ink-2); stroke: none; }
.leg-opt.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.leg-opt.on svg { stroke: var(--accent); }
.leg-opt.on svg .f { fill: var(--accent); }
.ds-label.sub { font-size: 11.5px; margin-top: 2px; }
