/* Demo shell styles.
 *
 * Lives here rather than in an inline <style> so the deployed CSP can say
 * `style-src-elem 'self'` — an inline <style> element would force
 * 'unsafe-inline', which also re-opens injected <style> as an attack surface.
 * (Inline style ATTRIBUTES are a separate directive and are still allowed:
 * the viewer library builds its DOM with `Object.assign(el.style, ...)`, so
 * `style-src-attr 'unsafe-inline'` is load-bearing and deliberate.)
 *
 * Not processed by Vite/Tailwind — plain CSS, copied verbatim from public/.
 */

/* ---------- self-hosted fonts ----------
   Geist + Geist Mono, SIL OFL 1.1 (see ./fonts/LICENSE.txt). Served from this
   origin so the page needs no `font-src`/`style-src` exception for a CDN and
   no DNS round-trip to a third party before it can paint text.

   Both families ship as VARIABLE fonts: Google Fonts serves the same file for
   every weight and only varies the `font-weight` descriptor, so four files
   cover 400/500/600/700 instead of twelve identical ones. `font-weight: 100
   900` is what tells the browser it may interpolate.

   Split latin / latin-ext because the UI ships English and Turkish: ğ, ş and
   İ live in latin-ext, so an English-only visitor never downloads it and a
   Turkish one does.
*/
@font-face {
  font-family: "Geist";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("/fonts/geist-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Geist";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("/fonts/geist-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Geist Mono";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("/fonts/geist-mono-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Geist Mono";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("/fonts/geist-mono-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/*
 * Phase 11 brand palette — "Graphite & Signal". Values come from
 * brand/README.md, which is the single reference; the library's own token
 * layer (src/globals.css) carries the same values under semantic names. The
 * demo keeps the shorter `--bg`/`--fg` names because they are the demo's, not
 * the package's, public surface — but they must not disagree with the sheet.
 *
 * :root defines LIGHT defaults; [data-theme="dark"] overrides for dark mode.
 * The bootstrap script in <head> sets data-theme before paint to avoid FOUC.
 */
:root {
  --bg: #f9fafb;            /* surface-chrome */
  --bg-elevated: #f3f4f6;   /* surface-panel */
  --bg-panel: #f3f4f6;
  --bg-overlay: #e5e7eb;    /* surface-overlay */
  --bg-canvas: #edeae4;     /* viewport-bg — warm paper, not slate */
  --border: #e5e7eb;
  --border-strong: #6b7280;
  --fg: #111827;
  --fg-muted: #4b5563;
  --fg-dim: #6b7280;
  --primary: #2563eb;       /* blue-600 — the UI accent (see brand sheet) */
  --primary-hover: #1d4ed8; /* blue-700 */
  --primary-subtle: #eff6ff;
  --primary-fg: #ffffff;
  --success: #15803d;
  --warning: #b45309;
  --error: #b91c1c;

  /* Warm-tinted, never neutral black: a slate shadow under a warm surface
     reads as dirt. */
  --shadow-sm: 0 1px 2px rgba(28, 25, 23, 0.06);
  --shadow-md: 0 4px 12px rgba(28, 25, 23, 0.10);
  --shadow-lg: 0 12px 32px rgba(28, 25, 23, 0.14);

  --radius-sm: 6px;   /* rounded-md — buttons, inputs */
  --radius-md: 8px;
  --radius-lg: 12px;  /* rounded-xl — cards, panels */

  --font-sans: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

[data-theme="dark"] {
  --bg: #0f172a;            /* surface-chrome */
  --bg-elevated: #1e293b;   /* surface-panel */
  --bg-panel: #1e293b;
  --bg-overlay: #334155;    /* surface-overlay */
  --bg-canvas: #191715;     /* viewport-bg — warm ink */
  --border: #334155;
  --border-strong: #94a3b8;
  --fg: #f1f5f9;
  --fg-muted: #cbd5e1;
  --fg-dim: #64748b;
  --primary: #60a5fa;       /* blue-400 */
  --primary-hover: #93c5fd; /* blue-300 */
  --primary-subtle: #1e3a5f;
  --primary-fg: #111827;
  --success: #4ade80;
  --warning: #fbbf24;
  --error: #f87171;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.30);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.40);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.50);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ---------- shell ---------- */
.shell {
  --left-w: 280px;
  --right-w: 340px;
  --rail-w: 40px;
  display: grid;
  grid-template-rows: 48px 1fr 28px;
  grid-template-columns: var(--left-w) 1fr;
  grid-template-areas:
    "topbar topbar"
    "left   stage"
    "bottombar bottombar";
  height: 100vh;
  height: 100dvh; /* dvh excludes mobile browser chrome so the bottombar/toolbar never fall off-screen */
  width: 100vw;
  transition: grid-template-columns 0.22s ease;
}
.shell.left-collapsed { grid-template-columns: var(--rail-w) 1fr; }
/* shell-with-right: toggled by JS in response to modal:sidebar-shown.
   Adds the dockable sidebar column on the right; canvas resizes to fit. */
.shell.shell-with-right {
  grid-template-columns: var(--left-w) 1fr var(--right-w);
  grid-template-areas:
    "topbar topbar topbar"
    "left   stage  dock"
    "bottombar bottombar bottombar";
}
.shell.left-collapsed.shell-with-right {
  grid-template-columns: var(--rail-w) 1fr var(--right-w);
}
.panel-dock {
  grid-area: dock;
  display: none;
  flex-direction: column;
  background: var(--bg-elevated);
  border-left: 1px solid var(--border);
  min-height: 0;
}
.shell.shell-with-right .panel-dock { display: flex; }

/* ---------- topbar — glass header (h-14, surface-raised/90 + backdrop-blur) ---------- */
.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 0 20px;
  background: color-mix(in srgb, var(--bg-elevated) 88%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  -webkit-backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--border);
  z-index: 5;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -0.01em;
  /* Never let the brand steal width from the actions cluster. */
  flex-shrink: 0;
  min-width: 0;
}
/* The real mark (brand/mark.svg, shipped as public/favicon.svg), not a
   letter in a gradient chip. It carries its own graphite tile, so it reads on
   both themes without a per-theme variant. */
.brand .logo {
  width: 26px;
  height: 26px;
  flex-shrink: 0; /* never let a crowded topbar squash it into an oval */
  border-radius: 8px;
  display: block;
  box-shadow: var(--shadow-sm);
}
.brand .version {
  font-size: 10.5px;
  color: var(--fg-muted);
  background: var(--bg-overlay);
  padding: 2px 8px;
  border-radius: 999px;
  font-family: var(--font-mono);
  margin-left: 4px;
  font-weight: 500;
}
.topbar-spacer { flex: 1 1 0; min-width: 0; }
.topbar-actions { display: flex; gap: 6px; align-items: center; min-width: 0; }
/* WHY: `.btn` sets `white-space: nowrap`, but as a flex item it still
   shrinks below its content width — which clipped "Open IFC" into
   "+ Op..." in the 640-900px band where no media query applied. A button
   must never shrink; when there isn't room, the breakpoints below drop
   its label or move it into a menu instead. */
.topbar-actions > * { flex: 0 0 auto; }

/* ---------- buttons ---------- */
.btn {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--fg);
  padding: 0 12px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
  line-height: 1;
  height: 32px;
  white-space: nowrap;
  text-decoration: none;
}
.btn:hover { background: var(--bg-overlay); }
.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--bg-elevated), 0 0 0 4px var(--primary);
}
.btn.primary {
  background: var(--primary);
  color: var(--primary-fg);
  border-color: var(--primary);
}
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.ghost { color: var(--fg-muted); }
.btn.ghost:hover { color: var(--fg); background: var(--bg-overlay); }
.btn.outline { border-color: var(--border-strong); color: var(--fg); }
.btn.outline:hover { border-color: var(--primary); background: var(--bg-overlay); }
.btn .icon { width: 14px; height: 14px; }
/* Icon-only collapse. Replaces the old `font-size: 0` trick, which was
   fragile (it zeroed any text child and made intrinsic width depend on
   padding alone). `display: none` DOES strip the label from the
   accessibility tree, so every control that can reach this state carries
   an explicit aria-label in the markup. */
.btn.icon-only { padding: 0 8px; gap: 0; }
.btn.icon-only .btn-label { display: none; }
.btn.icon-only .icon { width: 15px; height: 15px; }
.btn.icon-only i { font-size: 14px; }

/* The links overflow menu only exists on narrow screens. */
.links-switcher { display: none; }
.links-switcher .theme-item { text-decoration: none; }

/* ---------- side panels — surface-raised, no shadows, separated by 1px border ---------- */
.panel {
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.panel.right { border-right: none; border-left: 1px solid var(--border); }

/* Mobile drawer backdrop — created by src/main.sidebar.ts, hidden until the
   mobile media query turns it on while the left panel is expanded. */
#sidebar-backdrop { display: none; }
.panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--fg);
  border-bottom: 1px solid var(--border);
  min-height: 44px;
}
.panel-header .count {
  font-size: 10.5px;
  font-weight: 500;
  background: var(--bg-overlay);
  padding: 1px 8px;
  border-radius: 999px;
  color: var(--fg-muted);
}
.panel-header .spacer { flex: 1; }
.panel-header .collapse-btn {
  appearance: none;
  background: transparent;
  border: none;
  color: var(--fg-muted);
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.panel-header .collapse-btn:hover { background: var(--bg-overlay); color: var(--fg); }
.panel-header .collapse-btn svg { width: 14px; height: 14px; }

/* collapsed state — panel becomes a thin vertical rail with just the expand button */
.panel.collapsed .panel-header {
  padding: 8px 0;
  justify-content: center;
  border-bottom: 1px solid var(--border);
}
.panel.collapsed .panel-header .title-text,
.panel.collapsed .panel-header .count,
.panel.collapsed .panel-header .spacer { display: none; }
.panel.collapsed .panel-body { display: none; }

/* fade panel contents while shell animates so we don't see broken layouts mid-transition */
.panel-header, .panel-body { transition: opacity 0.18s ease; }
.shell.left-collapsed .left .panel-body { opacity: 0; }
.panel-body {
  flex: 1;
  overflow: auto;
  padding: 12px;
}
.panel-body::-webkit-scrollbar { width: 10px; }
.panel-body::-webkit-scrollbar-track { background: transparent; }
.panel-body::-webkit-scrollbar-thumb { background: var(--bg-overlay); border-radius: 5px; border: 2px solid var(--bg-elevated); }
.panel-body::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* ---------- left panel: demo switcher (BIM / Geo) ---------- */
.demo-switcher-label {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--fg-dim);
  margin: 2px 4px 6px;
}
.demo-switcher {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.demo-switcher-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-lg);
  border: 1px solid transparent;
  color: var(--fg-muted);
  font-size: 12.5px;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.demo-switcher-item .icon { width: 15px; height: 15px; flex-shrink: 0; }
.demo-switcher-item:hover {
  background: var(--bg-overlay);
  border-color: var(--border);
  color: var(--fg);
}
.demo-switcher-item.active {
  background: var(--primary-subtle);
  border-color: color-mix(in srgb, var(--primary) 40%, transparent);
  color: var(--fg);
}

/* ---------- left panel: model list (rounded-xl cards, hover lift) ---------- */
.left { grid-area: left; }
.model-card {
  display: flex;
  gap: 6px;
  padding: 8px 8px 8px 12px;
  border-radius: var(--radius-lg);
  border: 1px solid transparent;
  align-items: center;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.model-card:hover {
  background: var(--bg-overlay);
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}
.model-card.active {
  background: var(--primary-subtle);
  border-color: color-mix(in srgb, var(--primary) 40%, transparent);
}
.model-card.active .name { color: var(--primary-hover); }
/* a hidden model stays listed, just visibly switched off */
.model-card.hidden-model .model-card-body { opacity: 0.45; }
.model-card.hidden-model .name { text-decoration: line-through; }

/* card body = the zoom-to-model click target */
.model-card-body {
  display: flex;
  gap: 12px;
  align-items: center;
  flex: 1;
  min-width: 0;
  padding: 4px 0;
  background: none;
  border: 0;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.model-card-body:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: var(--radius-sm); }

.model-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}
.model-actions .icon-btn {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: none;
  color: var(--fg-muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.model-actions .icon-btn:hover {
  background: var(--bg-elevated);
  border-color: var(--border);
  color: var(--fg);
}
.model-actions .icon-btn.off { color: var(--fg-muted); opacity: 0.75; }
.model-actions .icon-btn.danger:hover { color: var(--danger, #ef4444); }
.model-actions .icon-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.model-card .thumb {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: var(--bg-canvas);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  font-size: 16px;
  color: var(--fg-muted);
}
.model-card .meta { min-width: 0; flex: 1; }
.model-card .name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.model-card .info {
  font-size: 11.5px;
  color: var(--fg-muted);
  margin-top: 3px;
  font-family: var(--font-mono);
}

.empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--fg-muted);
  font-size: 12px;
}
.empty .ico {
  width: 44px;
  height: 44px;
  margin: 0 auto 10px;
  border-radius: 999px;
  background: var(--bg-overlay);
  display: grid;
  place-items: center;
  font-size: 18px;
  opacity: 0.7;
}

.upload-card {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 22px 14px;
  text-align: center;
  cursor: pointer;
  margin-bottom: 12px;
  background: var(--bg-panel);
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}
.upload-card:hover {
  border-color: var(--primary);
  background: var(--primary-subtle);
}
.upload-card .ico {
  width: 36px;
  height: 36px;
  margin: 0 auto 8px;
  border-radius: var(--radius-sm);
  background: var(--bg-overlay);
  display: grid;
  place-items: center;
  font-size: 18px;
  color: var(--primary);
}
.upload-card .title { font-size: 13px; font-weight: 500; }
.upload-card .hint { font-size: 11.5px; color: var(--fg-muted); margin-top: 4px; }

/* ---------- stage (3D viewport) ---------- */
.stage {
  grid-area: stage;
  position: relative;
  background: var(--bg-canvas);
  overflow: hidden;
}
#app {
  position: absolute;
  inset: 0;
}
#app canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.stage-overlay {
  position: absolute;
  z-index: 4;
  pointer-events: none;
}
.stage-overlay > * { pointer-events: auto; }

/* navcube — top-right CSS-3D widget; NavCube fills this container.
   No background/border so only the 3D cube itself is visible. */
.navcube {
  top: 22px;
  right: 14px;
  width: 96px;
  height: 96px;
  color: var(--fg-muted);
}

/* zoom-slider — sleek horizontal pill that lives directly under the
   NavCube. Width matches the cube so the two read as a vertical
   navigation cluster pinned to the top-right corner. */
.zoom-slider {
  top: 140px; /* navcube top (22) + navcube height (96) + 22 gap */
  right: 14px;
  width: 96px;
  height: 28px;
}

/* ---------- bottombar ---------- */
.bottombar {
  grid-area: bottombar;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--fg-muted);
}
.bottombar .dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--fg-dim);
  box-shadow: 0 0 0 0 transparent;
}
.bottombar.idle .dot { background: var(--fg-dim); }
.bottombar.loading .dot {
  background: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 25%, transparent);
  animation: pulse 1.2s ease-in-out infinite;
}
.bottombar.ready .dot {
  background: var(--success);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 22%, transparent);
}
.bottombar.error .dot {
  background: var(--error);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--error) 22%, transparent);
}
.bottombar .sep { width: 1px; height: 14px; background: var(--border); }
.bottombar .right-info { margin-left: auto; display: flex; gap: 12px; align-items: center; }
.bottombar #info-fps { font-family: var(--font-mono); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ---------- dropzone overlay ---------- */
.dropzone {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  border: 2px dashed var(--primary);
  pointer-events: none;
}
.dropzone.active { display: flex; }
.dropzone .hint {
  font-size: 14px;
  font-weight: 600;
  color: var(--fg);
  background: var(--bg-elevated);
  padding: 14px 22px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

/* loader bar */
.progress {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: transparent;
  z-index: 30;
  overflow: hidden;
}
.progress::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, var(--primary) 0%, #a78bfa 100%);
  transform-origin: left;
  transform: scaleX(var(--progress, 0));
  transition: transform 0.2s ease;
}
.progress.hidden { display: none; }

/* hidden file input — kept in DOM and clickable, just visually hidden */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

kbd {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 2px 6px;
  background: var(--bg-overlay);
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  color: var(--fg);
  line-height: 1;
}

/* ---------- theme switcher (light/dark/system dropdown) ---------- */
.theme-switcher { position: relative; }
.theme-trigger {
  appearance: none;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-muted);
  height: 32px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.theme-trigger:hover { background: var(--bg-overlay); color: var(--fg); border-color: var(--border-strong); }
.theme-trigger:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--bg-elevated), 0 0 0 4px var(--primary);
}
.theme-trigger .icon { width: 15px; height: 15px; }
.theme-trigger .chev { width: 12px; height: 12px; opacity: 0.7; }
.theme-trigger .label { font-size: 12px; }

.theme-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 160px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 4px;
  display: none;
  flex-direction: column;
  z-index: 100;
}
.theme-menu[data-open="true"] { display: flex; }
.theme-item {
  appearance: none;
  background: transparent;
  border: none;
  color: var(--fg);
  font-family: inherit;
  font-size: 12.5px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s ease;
}
.theme-item:hover { background: var(--bg-overlay); }
.theme-item .icon { width: 15px; height: 15px; color: var(--fg-muted); flex-shrink: 0; }
.theme-item .check { width: 14px; height: 14px; margin-left: auto; color: var(--primary); opacity: 0; }
.theme-item[aria-checked="true"] { color: var(--primary); }
.theme-item[aria-checked="true"] .icon { color: var(--primary); }
.theme-item[aria-checked="true"] .check { opacity: 1; }

/* ---------- responsive ladder ----------
   Three tiers. The 640px tier used to be the only one, which left the
   640-900px band unhandled — that is where "Open IFC" clipped into
   "+ Op...". Buttons never shrink (see `.topbar-actions > *` above);
   instead each tier removes something. */

/* Tier 1 — reclaim the label text of the secondary actions. */
@media (max-width: 900px) {
  /* 280px left + 340px right of chrome cannot coexist with a phone-width
     stage, so force the rail regardless of the JS-toggled
     `left-collapsed` class, and float the dock over the stage instead of
     holding a grid column. Taking the dock out of the grid *widens* the
     stage; Viewer's ResizeObserver fixes the camera aspect for free. */
  .shell,
  .shell.left-collapsed,
  .shell.shell-with-right,
  .shell.left-collapsed.shell-with-right {
    grid-template-columns: var(--rail-w) 1fr;
    grid-template-areas:
      "topbar topbar"
      "left stage"
      "bottombar bottombar";
  }
  .panel-dock {
    position: fixed;
    inset: 48px 0 28px 0;
    z-index: 20;
    border-left: none;
  }

  /* The corner widgets crowd each other once the stage narrows. */
  .navcube { top: 12px; right: 10px; width: 72px; height: 72px; }
  .zoom-slider { top: 96px; right: 10px; width: 72px; }

  .topbar { padding: 0 14px; gap: 10px; }
  .brand > span:not(.logo) { white-space: nowrap; } /* "KUI Viewer" on one line */
  .brand .version { display: none; }              /* version badge would overflow */
  .topbar-actions { gap: 4px; }
  .link-action { padding: 0 8px; gap: 0; }
  .link-action .btn-label { display: none; }
  .link-action .icon { width: 15px; height: 15px; }
  .link-action i { font-size: 14px; }
  .theme-trigger { padding: 0 8px; }
  .theme-trigger .label { display: none; }
  /* #btn-open keeps its label here — it is the demo's whole CTA. */

  /* Left panel as an overlay drawer. The grid column is pinned to the 40px
     rail above, so an *expanded* panel can't grow the column — it would just
     spill its contents out clipped. Lift it out of the grid and slide it in
     over the stage instead, with a tap-to-dismiss backdrop. Collapsed, it
     stays the in-grid rail (the chevron the user taps to open). */
  .panel.left { transition: transform 0.22s ease, box-shadow 0.22s ease; }
  .shell:not(.left-collapsed) .panel.left {
    position: fixed;
    top: 48px;
    bottom: 28px;
    left: 0;
    width: min(86vw, 320px);
    z-index: 30;
    border-right: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
  }
  .shell:not(.left-collapsed) .panel.left .panel-body { opacity: 1; }
  .shell:not(.left-collapsed) #sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 48px 0 28px 0;
    z-index: 25;
    background: color-mix(in srgb, var(--bg) 55%, transparent);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
  }
}

/* Tier 2 — external links move into the ⋯ menu; actions go icon-only. */
@media (max-width: 640px) {
  .topbar { padding: 0 10px; gap: 8px; }
  .topbar-actions { gap: 2px; }
  .link-action { display: none; }
  .links-switcher { display: block; }
  /* Declutter the phone topbar: the wordmark drops to just the logo, and the
     cross-demo link goes away entirely — the same navigation lives in the
     left drawer's demo switcher. Leaves: logo · Fit · Reset · ⋯ · theme ·
     Open IFC. */
  .brand > span:not(.logo) { display: none; }
  .demo-link { display: none; }
  /* .demo-link: the quick cross-link to the other demo page (index.html
     -> geo.html and back, etc.) — missed by every prior tier of this
     ladder, so it kept its full label ("Geo demo"/"BIM workflow demo") at
     every width down to a phone, a measured 105px vs its icon-only
     siblings' ~33px and the actual cause of `.topbar-actions` overflowing
     at 390px (02-adoptable.md). Collapses exactly like #btn-fit/
     #btn-reset/#btn-open — same kind of always-visible single action. */
  #btn-fit, #btn-reset, #btn-open, .demo-link { padding: 0 8px; gap: 0; }
  #btn-fit .btn-label, #btn-reset .btn-label, #btn-open .btn-label, .demo-link .btn-label { display: none; }
  #btn-fit .icon, #btn-reset .icon, #btn-open .icon, .demo-link .icon { width: 15px; height: 15px; }

  /* Dock becomes a bottom sheet rather than a full-height overlay — a
     phone-height panel that starts under the topbar reads as a takeover. */
  .panel-dock {
    inset: auto 0 28px 0;
    height: 60dvh;
    border-top: 1px solid var(--border);
    border-radius: 12px 12px 0 0;
  }
  /* Keep a wider right margin: the CSS-3D cube renders slightly outside its
     box as it rotates, and at right:8px it clipped past the viewport edge. */
  .navcube { top: 10px; right: 16px; width: 58px; height: 58px; }
  /* Pinch is the native zoom gesture here, and a 64px slider steals a
     drag region from the canvas while being the worse affordance. */
  .zoom-slider { display: none; }

  /* Footer status bar: too many segments for a 28px strip on a phone.
     Keep the live status text (truncated) + FPS; drop the file name,
     separators, and the redundant "KUI Viewer · demo" label. */
  .bottombar { padding: 0 12px; gap: 8px; }
  .bottombar .sep,
  .bottombar #status-file,
  .bottombar .right-info span:last-child { display: none; }
  .bottombar #status-text {
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
}

/* ---------- touch targets ----------
   A device-capability query, not a width breakpoint — same rule the
   library's own controls use (viewer-core/a11y/touch-targets.ts). A
   1024px tablet needs 44px targets; a 400px laptop window does not, and
   growing the chrome there would cost the user who least has the room.
   WCAG 2.5.5 (AAA) is 44×44 CSS px. */
@media (pointer: coarse) {
  .btn { height: 44px; padding: 0 16px; }
  .btn.icon-only, .link-action { padding: 0 12px; }
  .theme-trigger { height: 44px; }
  .theme-item { min-height: 44px; }
  /* The model card's show/hide/unload icons were 26px squares sitting
     2px apart — three adjacent mis-taps waiting to happen, and one of
     them unloads the model. */
  .model-actions { gap: 6px; }
  .model-actions .icon-btn { width: 44px; height: 44px; }
  .panel-header { min-height: 52px; }
  .panel-header .collapse-btn { width: 44px; height: 44px; }
  .model-card-body { padding: 8px 0; }
}

/* ---------- digital twin: room temperature legend (src/main.twinview.ts) ---------- */
.twin-legend {
  position: absolute;
  right: 16px;
  bottom: 16px;
  z-index: 4;
  width: 200px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(6px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  font-size: 11.5px;
  color: var(--fg);
  pointer-events: none;
}
.twin-legend-title { font-weight: 600; margin-bottom: 6px; }
.twin-legend-bar { height: 8px; border-radius: 4px; }
.twin-legend-scale {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
}
@media (max-width: 640px) {
  .twin-legend { right: 8px; bottom: 8px; width: 160px; }
}
