/* StudForge — 3D LEGO Idea Maker Stylesheet
 *
 * Layout: header (brand, ← LIBRARY, model summary, Save/Share, ⋯) → create bar (Make) → canvas + workbench (4 tabs).
 *   The home screen (.sf-home, body.home-open) is the kit library, full screen under the header; the create bar,
 *   the canvas and the phone tab bar stay out of sight while it shows.
 *   The canvas has a control dock at the bottom: the step scrubber and the explode slider (plus, on phones, a
 *   labelled row of views, parts layout and spin).
 *   ≥1101px  canvas and a fixed workbench column side by side
 *   768–1100 the workbench is a drawer over the canvas, opened from a rail of tab icons
 *   ≤767px   the canvas fills the screen; the workbench is a bottom sheet (peek / half / full) driven by a
 *            tab bar (Make, Build, Parts, Style, Learn); the create bar becomes the full-height Make sheet
 */

:root {
    --bg-main: #0c0f17;
    --bg-card: #131822;
    --bg-card-hover: #19202e;
    --bg-deep: #090c13;
    --border-main: rgba(255, 255, 255, 0.08);
    --border-active: rgba(242, 205, 55, 0.45);

    --lego-red: #c91a09;
    --lego-yellow: #f2cd37;
    --lego-blue: #0055bf;
    --lego-green: #184e32;
    --lego-orange: #fe8a18;

    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --font-heading: 'Orbitron', -apple-system, sans-serif;
    --font-body: 'Rajdhani', -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    --head-h: 52px;
    --tabbar-h: 58px;
    --bench-w: 340px;
    --safe-b: env(safe-area-inset-bottom, 0px);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
}
input, textarea { user-select: text; -webkit-user-select: text; }

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-family: var(--font-body);
}
body { display: flex; flex-direction: column; }
button { font-family: inherit; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 2px solid var(--lego-yellow); outline-offset: 2px; }
[hidden] { display: none !important; }
.car { font-size: 9px; color: var(--text-muted); margin-left: 2px; }

/* ── header ─────────────────────────────────────────────── */
.top-nav {
    height: var(--head-h);
    flex: none;
    background: var(--bg-deep);
    border-bottom: 1px solid var(--border-main);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    position: relative;
    z-index: 30;
}
.nav-brand { display: flex; align-items: center; gap: 10px; flex: none; }
.brick-logo {
    width: 26px; height: 26px;
    background: var(--lego-red);
    border-radius: 4px;
    display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr;
    gap: 3px; padding: 4px;
    box-shadow: 0 2px 8px rgba(201, 26, 9, 0.5);
    flex: none;
}
.brick-logo .stud { background: #e62310; border-radius: 50%; box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.6), 0 1px 2px rgba(0, 0, 0, 0.4); }
.brand-title { font-family: var(--font-heading); font-size: 15px; font-weight: 900; letter-spacing: 1.5px; color: #fff; line-height: 1; }
.brand-sub { font-size: 9px; font-family: var(--font-heading); letter-spacing: 1px; color: var(--lego-yellow); font-weight: 600; }

.model-summary {
    display: flex; align-items: baseline; gap: 10px;
    min-width: 0;
    background: none; border: none; border-left: 1px solid var(--border-main);
    padding: 4px 4px 4px 14px;
    color: var(--text-primary); cursor: pointer; text-align: left;
}
.summary-name { font-family: var(--font-body); font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.summary-meta { font-family: var(--font-mono); font-size: 11px; color: var(--text-secondary); white-space: nowrap; display: inline-flex; align-items: baseline; gap: 6px; }
.summary-meta .dot { color: var(--text-muted); }
#summary-slot:empty { display: none; }
#summary-slot { display: inline-flex; gap: 6px; align-items: baseline; }
#summary-slot::before { content: '·'; color: var(--text-muted); }
.model-summary:hover .summary-name { color: var(--lego-yellow); }
.nav-spacer { flex: 1; }
.nav-actions { display: flex; align-items: center; gap: 8px; }
.nav-actions:empty { display: none; }

.nav-btn, .nav-actions > button {
    height: 32px; padding: 0 12px;
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--bg-card); border: 1px solid var(--border-main); border-radius: 7px;
    color: var(--text-primary); font-family: var(--font-heading); font-size: 10px; font-weight: 800; letter-spacing: 1px;
    cursor: pointer; white-space: nowrap;
}
.nav-btn:hover, .nav-actions > button:hover { border-color: var(--lego-yellow); }
.nav-btn.primary { background: var(--lego-yellow); color: #0c0f17; border-color: var(--lego-yellow); }
.nav-btn.primary .car { color: rgba(0, 0, 0, 0.55); }
.nav-btn.primary:hover { filter: brightness(1.08); }
.nb-ico { font-size: 13px; }
.lib-back { background: transparent; border-color: rgba(242, 205, 55, 0.6); color: var(--lego-yellow); flex: none; }
.lib-back:hover { background: rgba(242, 205, 55, 0.1); }
.lib-back .nb-ico { font-size: 14px; line-height: 1; }
.to-kit-phone { display: none; }
#btn-to-kit .nb-ico { font-size: 14px; line-height: 1; }
.nav-icon-btn {
    background: var(--bg-card); border: 1px solid var(--border-main); color: var(--text-primary);
    width: 32px; height: 32px; border-radius: 7px; cursor: pointer;
    display: flex; align-items: center; justify-content: center; font-size: 15px; flex: none;
}
.nav-icon-btn:hover { border-color: var(--lego-yellow); background: var(--bg-card-hover); }

.back-to-home {
    display: none;
    height: 32px; padding: 0 12px; align-items: center;
    border: 1px solid var(--lego-yellow); border-radius: 7px;
    color: var(--lego-yellow); text-decoration: none;
    font-family: var(--font-heading); font-size: 10px; font-weight: 700; letter-spacing: 1px; white-space: nowrap;
}
.back-to-home:hover { background: var(--lego-yellow); color: #000; }
body:not(.in-iframe) .back-to-home { display: inline-flex; }
body.in-iframe #btn-back-home { display: none; }
@media (max-width: 1240px) { body:not(.in-iframe) .back-to-home { display: none; } }

/* ── home screen: the kit library ───────────────────────── */
body.home-open #model-summary, body.home-open #btn-library, body.home-open #head-actions, body.home-open #share-menu { display: none; }
body.home-open .create-bar, body.home-open .tabbar, body.home-open .bom-card { display: none !important; }
.sf-home {
    position: fixed; left: 0; right: 0; top: var(--head-h); bottom: 0; z-index: 28;
    display: flex; flex-direction: column;
    background: var(--bg-main);
}
.home-scroll { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.home-wrap { max-width: 1280px; margin: 0 auto; padding: 30px 24px 44px; }
.home-hero {
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 430px); gap: 32px; align-items: end;
    padding-bottom: 6px;
}
.home-kicker { display: inline-flex; align-items: center; gap: 8px; font-family: var(--font-heading); font-size: 10px; font-weight: 800; letter-spacing: 2px; color: var(--lego-yellow); }
.hk-dot { width: 8px; height: 8px; border-radius: 2px; background: var(--lego-red); box-shadow: 0 0 10px rgba(201, 26, 9, 0.7); }
.home-title { font-family: var(--font-heading); font-size: 32px; font-weight: 900; letter-spacing: 0.5px; color: #fff; line-height: 1.1; margin: 10px 0 8px; }
.home-sub { font-size: 16px; font-weight: 500; line-height: 1.45; color: var(--text-secondary); max-width: 600px; }
.home-make {
    display: flex; flex-direction: column; gap: 9px;
    background: linear-gradient(180deg, rgba(25, 32, 46, 0.9), rgba(19, 24, 34, 0.9)); border: 1px solid var(--border-main); border-radius: 14px; padding: 13px 14px 12px;
}
.home-make-h { font-family: var(--font-heading); font-size: 9px; font-weight: 700; letter-spacing: 1.4px; color: var(--text-secondary); display: flex; gap: 6px; align-items: center; }
.home-make-row { display: flex; gap: 8px; }
.home-make-row input {
    flex: 1; min-width: 0; height: 42px; padding: 0 12px;
    background: var(--bg-main); border: 1px solid var(--border-main); border-radius: 9px; outline: none;
    color: #fff; font-family: var(--font-body); font-size: 16px; font-weight: 600;
}
.home-make-row input::placeholder { color: var(--text-muted); font-weight: 500; }
.home-make-row input:focus { border-color: var(--lego-yellow); box-shadow: 0 0 0 3px rgba(242, 205, 55, 0.12); }
.home-make .forge-btn { height: 42px; padding: 0 16px; }
.home-make .forge-btn.surprise { width: 42px; padding: 0; }
.home-make-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.home-more { background: none; border: none; padding: 0; cursor: pointer; color: var(--text-secondary); font-family: var(--font-body); font-size: 13px; font-weight: 600; white-space: nowrap; }
.home-more:hover { color: var(--lego-yellow); }
.home-library { margin-top: 8px; }

/* No model yet (Make opened from home, or a share link still loading): hide the kit-only controls. */
body.no-model .summary-meta, body.no-model #head-actions, body.no-model #share-menu,
body.no-model .ctl-dock, body.no-model .view-cluster, body.no-model .viewport-hint, body.no-model .side-panels, body.no-model .sheet-peek { visibility: hidden; }

/* ── menus and popovers ─────────────────────────────────── */
.sf-menu { position: relative; flex: none; }
.sf-menu-list {
    display: none;
    position: absolute; top: calc(100% + 6px); left: 0; z-index: 60;
    min-width: 230px; max-width: min(340px, calc(100vw - 24px));
    background: #161c28; border: 1px solid rgba(255, 255, 255, 0.12); border-radius: 10px;
    padding: 6px; box-shadow: 0 18px 44px rgba(0, 0, 0, 0.55);
    flex-direction: column; gap: 2px;
}
.sf-menu-list.right { left: auto; right: 0; }
.sf-menu.open > .sf-menu-list { display: flex; }
.sf-menu-item {
    display: flex; align-items: flex-start; gap: 10px; width: 100%;
    padding: 8px 10px; border-radius: 7px; border: none; background: none;
    color: var(--text-primary); font-family: var(--font-body); font-size: 15px; font-weight: 700; text-align: left; text-decoration: none;
    cursor: pointer;
}
.sf-menu-item:hover { background: rgba(255, 255, 255, 0.06); }
.sf-menu-item.on { background: rgba(242, 205, 55, 0.1); box-shadow: inset 0 0 0 1px rgba(242, 205, 55, 0.45); }
.sf-menu-item small { display: block; font-size: 12px; font-weight: 500; color: var(--text-secondary); line-height: 1.3; }
.mi-ico { width: 20px; flex: none; text-align: center; font-size: 15px; line-height: 1.35; }
.mi-text { min-width: 0; }
.sf-menu-list.compact { min-width: 150px; }
.sf-menu-list.compact .sf-menu-item { font-family: var(--font-heading); font-size: 11px; letter-spacing: 1px; padding: 8px 10px; flex-direction: column; gap: 0; }
.sf-menu-list.compact .sf-menu-item small { font-family: var(--font-body); letter-spacing: 0; }
#more-extra:empty { display: none; }
#more-extra { border-top: 1px solid var(--border-main); margin-top: 4px; padding-top: 6px; display: flex; flex-wrap: wrap; gap: 6px; }
.lock { display: none; margin-left: 6px; font-size: 11px; }
.engine-item .en-name, .engine-item .en-tiny { display: none; }
.engine-item .en-long { display: block; }
.engine-item.locked .lock, .create-sel .lock { display: inline; }

/* ── create bar (Make) ──────────────────────────────────── */
.create-bar {
    flex: none; position: relative; z-index: 25;
    padding: 10px 16px;
    background: #0e121b; border-bottom: 1px solid var(--border-main);
}
.make-head { display: none; }
.create-row { display: flex; align-items: center; gap: 8px; }
.create-sel {
    height: 40px; padding: 0 12px;
    display: inline-flex; align-items: center; gap: 7px;
    background: var(--bg-card-hover); border: 1px solid var(--border-main); border-radius: 9px;
    color: var(--text-primary); font-family: var(--font-body); font-size: 15px; font-weight: 700; white-space: nowrap; cursor: pointer;
}
.create-sel:hover, .sf-menu.open > .create-sel { border-color: var(--lego-yellow); }
.input-bar-wrap {
    flex: 1; min-width: 0; height: 40px;
    display: flex; align-items: center;
    background: var(--bg-card); border: 1px solid var(--border-main); border-radius: 9px; padding: 0 12px;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.input-bar-wrap:focus-within { border-color: var(--lego-yellow); box-shadow: 0 0 0 3px rgba(242, 205, 55, 0.12); }
.input-bar-wrap input { flex: 1; min-width: 0; background: transparent; border: none; outline: none; color: #fff; font-family: var(--font-body); font-size: 17px; font-weight: 600; }
.input-bar-wrap input::placeholder { color: var(--text-muted); font-weight: 500; }
.engine-list { min-width: 300px; }
.create-bar[data-engine="plan"] #btn-engine, .create-bar[data-engine="design"] #btn-engine { border-color: rgba(242, 205, 55, 0.5); }

.forge-btn {
    height: 40px;
    background: linear-gradient(135deg, var(--lego-yellow) 0%, #d4a017 100%);
    color: #0c0f17; border: none; border-radius: 9px; padding: 0 20px;
    font-family: var(--font-heading); font-size: 12px; font-weight: 800; letter-spacing: 1px;
    cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; flex: none;
    transition: transform 0.1s ease, filter 0.2s ease;
}
.forge-btn:hover { filter: brightness(1.1); }
.forge-btn:active { transform: translateY(1px); }
.forge-btn[disabled] { opacity: 0.75; cursor: wait; }
.forge-btn.surprise { width: 40px; padding: 0; font-size: 16px; background: var(--bg-card); color: #fff; border: 1px solid var(--border-main); }
.forge-btn.surprise:hover { border-color: var(--lego-yellow); }
.spin-icon { display: inline-block; animation: sf-spin 1s linear infinite; }
@keyframes sf-spin { to { transform: rotate(360deg); } }

.create-pop {
    display: none;
    position: absolute; top: calc(100% - 4px); left: 16px; z-index: 40;
    width: min(640px, calc(100% - 32px));
    max-height: calc(100vh - var(--head-h) - 90px); overflow-y: auto;
    background: #161c28; border: 1px solid rgba(255, 255, 255, 0.12); border-radius: 12px;
    padding: 14px; box-shadow: 0 22px 54px rgba(0, 0, 0, 0.6);
}
.create-bar.pop-open .create-pop { display: block; }
.create-bar.has-source .create-pop { width: min(820px, calc(100% - 32px)); }
.cp-h { font-family: var(--font-heading); font-size: 9px; letter-spacing: 1.3px; color: var(--text-muted); margin: 0 0 8px; }
.cp-home .inspo-pills + .cp-h { margin-top: 14px; }
.inspo-pills { display: flex; flex-wrap: wrap; gap: 6px; }
.inspo-pill {
    background: var(--bg-card); border: 1px solid var(--border-main); color: var(--text-secondary);
    padding: 5px 12px; border-radius: 999px; font-family: var(--font-body); font-size: 14px; font-weight: 600;
    cursor: pointer; white-space: nowrap; display: inline-flex; gap: 5px; align-items: center;
}
.inspo-pill:hover { border-color: var(--lego-yellow); color: #fff; }
.inspo-pill.active { border-color: var(--lego-yellow); color: var(--lego-yellow); background: rgba(242, 205, 55, 0.08); }
.start-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; }
.start-tiles:empty::after { content: 'Loading…'; color: var(--text-muted); font-size: 13px; }
.start-tile {
    display: grid; grid-template-columns: auto 1fr; column-gap: 9px; align-items: center; text-align: left;
    padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border-main); background: var(--bg-main);
    color: var(--text-primary); cursor: pointer;
}
.start-tile:hover { border-color: var(--lego-yellow); }
.st-ico { grid-row: span 2; font-size: 20px; }
.st-label { font-weight: 700; font-size: 15px; }
.start-tile small { font-size: 12px; color: var(--text-secondary); line-height: 1.25; }
.cp-source-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.cp-back { background: none; border: 1px solid var(--border-main); color: var(--text-secondary); border-radius: 7px; padding: 4px 10px; font-family: var(--font-heading); font-size: 9px; letter-spacing: 1px; cursor: pointer; }
.cp-back:hover { color: #fff; border-color: var(--lego-yellow); }
.cp-source-title { font-family: var(--font-heading); font-size: 12px; letter-spacing: 1px; color: #fff; }
.cp-close { margin-left: auto; min-width: 32px; min-height: 32px; }
.source-body { font-size: 13px; color: var(--text-secondary); }
.source-body h4 { font-family: var(--font-heading); font-size: 11px; letter-spacing: 1px; color: #fff; margin: 0 0 8px; }

/* ── main layout ────────────────────────────────────────── */
.app-layout { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 12px 16px 14px; }
.studio-grid { flex: 1; display: grid; grid-template-columns: 1fr var(--bench-w); gap: 14px; min-height: 0; position: relative; }

/* ── canvas ─────────────────────────────────────────────── */
.viewport-card { position: relative; background: var(--bg-card); border: 1px solid var(--border-main); border-radius: 12px; overflow: hidden; min-height: 0; }
.canvas-3d-box { width: 100%; height: 100%; cursor: grab; touch-action: none; }
.canvas-3d-box:active { cursor: grabbing; }

.view-cluster { position: absolute; top: 12px; right: 12px; z-index: 6; display: flex; gap: 6px; align-items: flex-start; }
.cam-btn {
    height: 30px; padding: 0 10px; display: inline-flex; align-items: center; gap: 5px;
    background: rgba(9, 12, 19, 0.82); border: 1px solid var(--border-main); color: var(--text-secondary);
    font-family: var(--font-heading); font-size: 9px; font-weight: 700; letter-spacing: 0.8px;
    border-radius: 7px; cursor: pointer; white-space: nowrap; backdrop-filter: blur(6px);
}
.cam-btn:hover, .sf-menu.open > .cam-btn { color: #fff; border-color: var(--lego-yellow); }
.cam-btn.on { color: var(--lego-yellow); border-color: rgba(242, 205, 55, 0.6); }
.vc-ico { font-size: 12px; }
.viewport-widgets { display: flex; gap: 6px; }
.viewport-widgets:empty { display: none; }
/* Feature widgets sit in the cluster and take its look. */
.viewport-widgets > button { height: 30px; }
.explode-pop { min-width: 240px; padding: 12px; gap: 8px; }
.tool-label-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.tool-name { font-family: var(--font-heading); font-size: 9px; font-weight: 700; color: var(--text-secondary); letter-spacing: 0.8px; }
.tool-val { font-family: var(--font-mono); font-size: 11px; font-weight: 700; color: var(--lego-yellow); white-space: nowrap; }
.tool-hint { font-family: var(--font-mono); font-size: 11px; font-weight: 500; color: var(--text-muted); white-space: nowrap; }

.tech-slider {
    --fill: 0%;
    -webkit-appearance: none; appearance: none;
    width: 100%; height: 22px; background: transparent; cursor: pointer;
}
.tech-slider::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: linear-gradient(90deg, var(--lego-yellow) var(--fill), rgba(255, 255, 255, 0.16) var(--fill)); }
.tech-slider::-moz-range-track { height: 4px; border-radius: 4px; background: linear-gradient(90deg, var(--lego-yellow) var(--fill), rgba(255, 255, 255, 0.16) var(--fill)); }
.tech-slider::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; margin-top: -6px; border-radius: 50%; background: var(--lego-yellow); border: 2px solid #0c0f17; box-shadow: 0 0 0 1px var(--lego-yellow); }
.tech-slider::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--lego-yellow); border: 2px solid #0c0f17; }

/* the control dock: steps and explode, always in view */
.ctl-dock {
    position: absolute; left: 12px; right: 12px; bottom: 12px; z-index: 6;
    display: flex; align-items: center; gap: 12px;
    background: rgba(19, 24, 34, 0.9); border: 1px solid var(--border-main); border-radius: 11px;
    padding: 6px 8px; backdrop-filter: blur(8px);
}
.step-scrub { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.step-scrub .tech-slider { flex: 1; min-width: 60px; }
.dock-explode { display: flex; align-items: center; gap: 8px; flex: 0 1 300px; min-width: 190px; padding-left: 12px; border-left: 1px solid var(--border-main); }
.dk-label { display: inline-flex; align-items: center; gap: 5px; font-family: var(--font-heading); font-size: 9px; font-weight: 700; letter-spacing: 0.8px; color: var(--text-secondary); white-space: nowrap; cursor: pointer; }
.dock-explode.on .dk-label { color: var(--lego-yellow); }
.dock-explode .tech-slider { flex: 1; min-width: 60px; }
#val-explode { min-width: 34px; text-align: right; }
/* While the parts layout is out the explode slider sleeps (studio.js); reset beside it on phones stays awake. */
.dock-explode.sfs-explode-off { opacity: 1; }
.dock-explode.sfs-explode-off > :not(#btn-cam-reset) { opacity: 0.45; }
.dock-tools { display: none; }
.view-seg { display: flex; flex: none; border: 1px solid var(--border-main); border-radius: 8px; overflow: hidden; background: rgba(9, 12, 19, 0.82); }
.view-seg button { height: 32px; padding: 0 9px; background: none; border: none; color: var(--text-secondary); font-family: var(--font-heading); font-size: 9px; font-weight: 700; letter-spacing: 0.6px; cursor: pointer; }
.view-seg button + button { border-left: 1px solid var(--border-main); }
.view-seg button:active, .view-seg button.on { color: var(--lego-yellow); background: rgba(242, 205, 55, 0.12); }
.viewport-card .sfpose-axis { bottom: calc(var(--dock-cover, 56px) + 8px); }
.step-btn {
    width: 32px; height: 30px; flex: none;
    display: inline-flex; align-items: center; justify-content: center;
    background: rgba(255, 255, 255, 0.07); border: 1px solid var(--border-main); color: var(--text-primary);
    font-size: 11px; border-radius: 7px; cursor: pointer;
}
.step-btn:hover { border-color: var(--lego-yellow); }
.step-btn.play.on { color: var(--lego-yellow); border-color: var(--lego-yellow); }
#val-step { min-width: 92px; }
.viewport-hint {
    position: absolute; left: 50%; bottom: calc(var(--dock-cover, 56px) + 6px); transform: translateX(-50%);
    font-size: 11px; color: var(--text-muted); white-space: nowrap; pointer-events: none;
    background: rgba(9, 12, 19, 0.5); padding: 2px 10px; border-radius: 999px;
}

/* ── workbench ──────────────────────────────────────────── */
.bom-card {
    background: var(--bg-card); border: 1px solid var(--border-main); border-radius: 12px;
    display: flex; flex-direction: column; overflow: hidden; min-height: 0;
}
.sheet-handle, .sheet-peek, .bench-close { display: none; }
.side-tabs { display: grid; grid-template-columns: repeat(4, 1fr); border-bottom: 1px solid var(--border-main); background: rgba(9, 12, 19, 0.45); flex: none; position: relative; }
.side-tab {
    background: none; border: none; color: var(--text-muted); cursor: pointer;
    padding: 9px 0 8px; font-family: var(--font-heading); font-size: 9px; font-weight: 700; letter-spacing: 1px;
    display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.side-tab i { font-style: normal; font-size: 15px; filter: grayscale(0.6); }
.side-tab:hover { color: #fff; }
.side-tab.on { color: var(--lego-yellow); box-shadow: inset 0 -2px 0 var(--lego-yellow); }
.side-tab.on i { filter: none; }
.side-panels { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.side-panel { display: none; flex: 1; flex-direction: column; min-height: 0; }
.side-panel.on { display: flex; }
.tab-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.bench-sec { border-bottom: 1px solid var(--border-main); }
.bench-sec:last-child { border-bottom: none; }
.bench-sec.flash { animation: sf-flash 1.1s ease-out; }
@keyframes sf-flash { 0% { background: rgba(242, 205, 55, 0.14); } 100% { background: transparent; } }
.bench-h { font-family: var(--font-heading); font-size: 10px; letter-spacing: 1.2px; color: var(--text-muted); padding: 12px 14px 0; font-weight: 700; }
.bench-sec .panel-body { padding: 10px 14px 14px; font-size: 13px; color: var(--text-secondary); }
.bench-sec h4 { font-family: var(--font-heading); font-size: 11px; letter-spacing: 1px; color: #fff; margin: 0 0 8px; }
/* Legacy class some feature panels test for: a section counts as showing when its tab does. */
.side-panel.on .bench-sec { }

.model-head { padding: 14px 14px 12px; border-bottom: 1px solid var(--border-main); }
.model-badge-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.badge-pill {
    background: rgba(9, 12, 19, 0.85); border: 1px solid var(--border-main); color: var(--text-secondary);
    padding: 3px 9px; border-radius: 12px; font-family: var(--font-heading); font-size: 9px; font-weight: 700; letter-spacing: 0.5px;
}
.badge-pill.highlight { color: var(--lego-yellow); border-color: rgba(242, 205, 55, 0.4); }
.badge-pill.dims { color: var(--text-muted); }
.badge-pill:empty { display: none; }
.active-model-desc { font-size: 14px; line-height: 1.4; color: var(--text-secondary); font-weight: 500; }
.active-model-title { font-family: var(--font-heading); font-size: 16px; font-weight: 800; color: #fff; }

/* the core parts list */
.bom-header { padding: 14px; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.bom-title { font-family: var(--font-heading); font-size: 12px; font-weight: 800; letter-spacing: 1px; color: #fff; }
.bom-sub { font-size: 10px; color: var(--text-muted); display: block; letter-spacing: 0.5px; }
.bom-counts { text-align: right; flex: none; }
.main-count { font-family: var(--font-mono); font-size: 14px; font-weight: 700; color: var(--lego-yellow); display: block; }
.sub-count { font-size: 10px; color: var(--text-muted); display: block; }
.bom-table-wrap { padding: 0 8px; }
.bom-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.bom-table th { text-align: left; padding: 8px 6px; font-family: var(--font-heading); font-size: 9px; font-weight: 700; color: var(--text-muted); letter-spacing: 0.5px; border-bottom: 1px solid var(--border-main); }
.bom-table td { padding: 8px 6px; border-bottom: 1px solid rgba(255, 255, 255, 0.04); }
.part-preview-cell { display: flex; align-items: center; gap: 8px; }
.color-dot { width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgba(255, 255, 255, 0.25); flex-shrink: 0; }
.part-info { display: flex; flex-direction: column; min-width: 0; }
.part-name { font-weight: 600; color: #e2e8f0; line-height: 1.2; }
.part-meta { font-family: var(--font-mono); font-size: 10px; color: var(--text-muted); }
.qty-badge { font-family: var(--font-mono); font-weight: 700; color: #fff; background: rgba(255, 255, 255, 0.08); padding: 2px 6px; border-radius: 4px; }
.text-right { text-align: right; }
.bom-actions { padding: 12px 14px 14px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.bom-actions .action-btn.primary { grid-column: 1 / -1; order: -1; }
.action-btn {
    width: 100%; padding: 9px 6px; border-radius: 7px;
    font-family: var(--font-heading); font-size: 10px; font-weight: 800; letter-spacing: 0.8px;
    cursor: pointer; border: none; display: flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
}
.action-btn.primary { background: linear-gradient(135deg, var(--lego-yellow) 0%, #d4a017 100%); color: #0c0f17; }
.action-btn.primary:hover { filter: brightness(1.1); }
.action-btn.secondary { background: rgba(255, 255, 255, 0.08); color: #fff; border: 1px solid var(--border-main); }
.action-btn.secondary:hover { background: rgba(255, 255, 255, 0.14); }
.action-btn.tertiary { background: transparent; color: var(--text-secondary); border: 1px solid var(--border-main); }
.action-btn.tertiary:hover { color: #fff; border-color: rgba(255, 255, 255, 0.25); }

/* shared chip style features use */
.tool-chip { background: var(--bg-card); border: 1px solid var(--border-main); color: var(--text-secondary); padding: 4px 10px; border-radius: 14px; font-size: 12px; font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; font-family: var(--font-body); }
.tool-chip.on, .tool-chip:hover { border-color: var(--lego-yellow); color: #fff; }

.tabbar { display: none; }
.sf-toast {
    position: fixed; left: 50%; bottom: 24px; z-index: 10060; transform: translate(-50%, 20px);
    background: #1b2231; border: 1px solid var(--border-active); color: #fff; font-size: 14px; font-weight: 600;
    padding: 8px 16px; border-radius: 999px; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
    max-width: calc(100vw - 32px); text-align: center;
}
.sf-toast.on { opacity: 1; transform: translate(-50%, 0); }

body.sfi-booklet-open .create-bar, body.sfi-booklet-open .tabbar { display: none !important; }

/* ── short windows (the app inside a small desktop window) ── */
@media (max-height: 640px) and (min-width: 768px) {
    :root { --head-h: 44px; }
    .brand-sub { display: none; }
    .create-bar { padding: 6px 12px; }
    .create-sel, .input-bar-wrap, .forge-btn { height: 34px; }
    .forge-btn.surprise { width: 34px; }
    .app-layout { padding: 8px 12px 10px; }
    .viewport-hint { display: none; }
}

/* ── tablets / narrow windows: the workbench is a drawer ── */
@media (min-width: 768px) and (max-width: 1100px) {
    .studio-grid { grid-template-columns: 1fr; }
    .brand-text { display: none; }
    .source-menu .cs-label { display: none; }
    #btn-source .cs-label { display: none; }
    .bom-card {
        position: absolute; top: 0; right: 0; bottom: 0; z-index: 20;
        width: 58px; border-radius: 12px;
        background: rgba(19, 24, 34, 0.92); backdrop-filter: blur(8px);
        transition: width 0.22s ease;
    }
    .bom-card .side-tabs { grid-template-columns: 1fr; border-bottom: none; background: none; }
    .bom-card .side-tab { padding: 10px 0; font-size: 7.5px; }
    .bom-card .side-tab.on { box-shadow: inset -2px 0 0 var(--lego-yellow); }
    .bom-card .side-panels { display: none; }
    body:not(.bench-open) .bom-card .side-tab.on { color: var(--text-muted); box-shadow: none; }
    body:not(.bench-open) .bom-card .side-tab.on i { filter: grayscale(0.6); }
    body.bench-open .bom-card { width: min(380px, 70vw); box-shadow: -16px 0 44px rgba(0, 0, 0, 0.5); }
    body.bench-open .bom-card .side-tabs { grid-template-columns: repeat(4, 1fr) 44px; border-bottom: 1px solid var(--border-main); }
    body.bench-open .bom-card .side-tab { padding: 9px 0 8px; font-size: 9px; }
    body.bench-open .bom-card .side-tab.on { box-shadow: inset 0 -2px 0 var(--lego-yellow); }
    body.bench-open .bom-card .side-panels { display: flex; }
    body.bench-open .bench-close { display: flex; align-items: center; justify-content: center; background: none; border: none; color: var(--text-secondary); font-size: 15px; cursor: pointer; }
    .viewport-card .view-cluster { right: 70px; }
    .viewport-card .ctl-dock { right: 70px; }
    .viewport-hint { display: none; }
    #view-menu .vc-label, #btn-cam-reset .vc-label, #btn-spin .vc-label { display: none; }
    .dock-explode { flex-basis: 220px; min-width: 170px; }
    body.home-open .brand-text { display: block; }
    .home-hero { grid-template-columns: minmax(0, 1fr); gap: 18px; }
    .home-make { max-width: 620px; }
    #model-step-count, .summary-meta > .dot { display: none; }
}

/* ── phones ─────────────────────────────────────────────── */
@media (max-width: 767px) {
    :root { --head-h: 48px; }
    .top-nav { padding: 0 8px; gap: 6px; }
    .brand-text { display: none; }
    .brick-logo { width: 22px; height: 22px; padding: 3px; gap: 2px; }
    .model-summary { flex-direction: column; align-items: flex-start; gap: 0; border-left: none; padding: 0 2px; flex: 1; }
    .summary-name { font-size: 15px; max-width: 100%; }
    .summary-meta { font-size: 10px; }
    .nav-spacer { display: none; }
    .nav-btn, .nav-actions > button { height: 32px; padding: 0 9px; }
    .nav-btn .nb-label, .nav-btn .car, .nav-actions .nb-label { display: none; }
    .lib-back { padding: 0 9px 0 7px; gap: 4px; }
    .lib-back .lib-label { font-size: 9px; }
    body:not(.home-open) .nav-brand { display: none; }
    body.home-open .brand-text { display: block; }
    body.home-open .nav-spacer { display: block; }
    .to-kit-wide { display: none; }
    .to-kit-phone { display: inline; }
    .back-to-home, body:not(.in-iframe) .back-to-home { display: none; }
    #btn-keys { display: none; }

    /* Make: hidden until the Make tab opens it full height. */
    .create-bar {
        display: none;
        position: fixed; left: 0; right: 0; top: 0; bottom: calc(var(--tabbar-h) + var(--safe-b)); z-index: 45;
        padding: env(safe-area-inset-top, 0px) 0 0; border-bottom: none;
        background: var(--bg-main); flex-direction: column;
    }
    body.make-open .create-bar { display: flex; }
    .make-head { display: flex; align-items: center; justify-content: space-between; height: var(--head-h); padding: 0 12px; border-bottom: 1px solid var(--border-main); flex: none; }
    .make-title { font-family: var(--font-heading); font-size: 12px; letter-spacing: 1.4px; color: #fff; }
    .create-row { flex-wrap: wrap; padding: 12px 12px 0; gap: 8px; }
    #source-menu { display: none; }
    .input-bar-wrap { flex: 1 1 100%; order: 1; height: 46px; border-color: rgba(242, 205, 55, 0.5); }
    .input-bar-wrap input { font-size: 17px; }
    /* The engine picker is a three-way switch on phones. */
    .engine-menu { order: 2; flex: 1 1 100%; }
    .engine-menu > .create-sel { display: none; }
    .engine-menu .sf-menu-list { display: grid; position: static; grid-auto-flow: column; grid-auto-columns: 1fr; min-width: 0; max-width: none; padding: 0; gap: 0; background: none; border: 1px solid var(--border-main); border-radius: 10px; box-shadow: none; overflow: hidden; }
    .engine-menu .engine-item { flex-direction: column; align-items: center; gap: 0; text-align: center; padding: 7px 4px; border-radius: 0; font-size: 13px; }
    .engine-menu .engine-item + .engine-item { border-left: 1px solid var(--border-main); }
    .engine-menu .engine-item .mi-ico { width: auto; font-size: 14px; }
    .engine-menu .engine-item .en-long, .engine-menu .engine-item .en-hint { display: none; }
    .engine-menu .engine-item .en-name, .engine-menu .engine-item .en-tiny { display: block; }
    .engine-menu .engine-item small { font-size: 11px; }
    .engine-menu .engine-item.on { background: rgba(242, 205, 55, 0.1); box-shadow: inset 0 0 0 1px var(--lego-yellow); }
    .engine-menu .engine-item.on .en-name { color: var(--lego-yellow); }
    #btn-generate { order: 3; flex: 1; height: 46px; font-size: 13px; }
    #btn-surprise { order: 4; height: 46px; width: 46px; }
    .create-pop { display: block; position: static; width: auto; max-height: none; flex: 1; min-height: 0; overflow-y: auto; background: none; border: none; box-shadow: none; padding: 14px 12px 20px; border-radius: 0; }
    .create-bar.has-source .create-pop { width: auto; }
    .create-bar.has-source .create-row { display: none; }
    .start-tiles { grid-template-columns: repeat(3, 1fr); }
    .start-tile { grid-template-columns: 1fr; text-align: center; justify-items: center; padding: 10px 6px; }
    .st-ico { grid-row: auto; }
    .start-tile small { display: none; }
    .inspo-pill { font-size: 14px; padding: 6px 12px; }

    /* Canvas: full bleed between the header and the tab bar. */
    .app-layout { padding: 0 0 calc(var(--tabbar-h) + var(--safe-b)); }
    .studio-grid { display: block; height: 100%; }
    .viewport-card { position: absolute; inset: 0; border-radius: 0; border: none; }
    body[data-sheet="half"] .viewport-card { bottom: calc(46vh - var(--tabbar-h) - var(--safe-b) - 2px); }
    body[data-sheet="full"] .viewport-card { bottom: 0; }
    /* The control dock: steps; explode + reset; then a labelled row of views, parts layout and spin. */
    .ctl-dock {
        left: 8px; right: 8px; bottom: calc(64px + 8px);
        flex-direction: column; align-items: stretch; gap: 0;
        padding: 5px 6px 6px; border-radius: 14px; background: rgba(15, 19, 28, 0.92);
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    }
    body[data-sheet="half"] .ctl-dock, body[data-sheet="full"] .ctl-dock { bottom: 8px; }
    body[data-sheet="half"] .dock-tools { display: none; }
    .step-scrub { gap: 6px; padding-bottom: 5px; }
    .step-btn { width: 36px; height: 34px; font-size: 12px; }
    #val-step { min-width: 0; font-size: 10px; }
    .dock-explode { flex: none; min-width: 0; gap: 8px; padding: 5px 0 5px 4px; border-left: none; border-top: 1px solid var(--border-main); }
    .dock-explode .tech-slider { height: 30px; }
    .dock-explode .tech-slider::-webkit-slider-thumb { width: 20px; height: 20px; margin-top: -8px; }
    .dock-explode #btn-cam-reset { flex: none; }
    .dock-tools {
        display: flex; gap: 6px; padding-top: 6px; border-top: 1px solid var(--border-main);
        overflow-x: auto; scrollbar-width: none; -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 18px), transparent); mask-image: linear-gradient(90deg, #000 calc(100% - 18px), transparent);
    }
    .dock-tools::-webkit-scrollbar { display: none; }
    .dock-tools .view-cluster, .dock-tools .viewport-widgets { display: contents; }
    .dock-tools #view-menu { display: none; }
    .ctl-dock .cam-btn { height: 34px; flex: none; padding: 0 10px; background: rgba(255, 255, 255, 0.05); color: var(--text-primary); font-size: 9px; }
    .ctl-dock .cam-btn.on { color: var(--lego-yellow); border-color: var(--lego-yellow); background: rgba(242, 205, 55, 0.12); }
    .dock-tools #btn-parts-layout { order: 1; }
    .dock-tools .view-seg { order: 2; }
    .dock-tools #btn-spin { order: 3; }
    .dock-tools #btn-pose { order: 4; }
    .dock-tools .view-seg button { height: 34px; padding: 0 9px; }
    .tool-hint { display: none; }
    .viewport-hint { display: none; }

    /* Workbench: a bottom sheet above the tab bar. */
    .bom-card {
        position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + var(--safe-b)); z-index: 35;
        height: 64px; border-radius: 16px 16px 0 0; border: none; border-top: 1px solid rgba(255, 255, 255, 0.1);
        box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.45);
        transition: height 0.25s ease;
    }
    body[data-sheet="half"] .bom-card { height: calc(46vh - var(--tabbar-h) - var(--safe-b)); }
    body[data-sheet="full"] .bom-card { height: calc(100% - var(--head-h) - var(--tabbar-h) - var(--safe-b) - 8px); }
    body.make-open .bom-card { display: none; }
    .sheet-handle { display: flex; justify-content: center; padding: 7px 0 5px; flex: none; touch-action: none; cursor: grab; }
    .sheet-handle span { width: 38px; height: 4px; border-radius: 4px; background: #3a4458; }
    .sheet-peek { display: flex; align-items: center; gap: 8px; padding: 0 14px 10px; font-size: 13px; color: var(--text-secondary); flex: none; touch-action: none; white-space: nowrap; overflow: hidden; }
    .sheet-peek .pk-main { font-weight: 700; color: #fff; }
    .sheet-peek .pk-sub { overflow: hidden; text-overflow: ellipsis; }
    body:not([data-sheet="peek"]) .sheet-peek { display: none; }
    .side-tabs { display: none; }
    body[data-sheet="peek"] .side-panels { display: none; }

    .tabbar {
        display: grid; grid-template-columns: repeat(6, 1fr);
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
        height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
        background: #0b0e16; border-top: 1px solid var(--border-main);
    }
    .tb { background: none; border: none; color: var(--text-muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-family: var(--font-heading); font-size: 8px; font-weight: 700; letter-spacing: 0.8px; cursor: pointer; }
    .tb i { font-style: normal; font-size: 17px; filter: grayscale(0.6); line-height: 1; }
    .tb.on { color: var(--lego-yellow); }
    .tb.on i { filter: none; }
    .tb.make i { display: inline-flex; width: 34px; height: 24px; align-items: center; justify-content: center; border-radius: 9px; background: var(--lego-yellow); color: #111; filter: none; font-size: 16px; font-weight: 700; }
    .tb.make { color: var(--lego-yellow); }
    .tb.make.on i { box-shadow: 0 0 0 2px rgba(242, 205, 55, 0.35); }
    .tb.lib { color: var(--text-secondary); }
    .tb.lib i { font-size: 19px; filter: none; color: var(--lego-yellow); }

    .bom-actions { grid-template-columns: 1fr 1fr; }
    .sf-toast { top: calc(var(--head-h) + 10px); bottom: auto; transform: translate(-50%, -12px); }
    .sf-toast.on { transform: translate(-50%, 0); }

    /* Home: one column, the kits close to the top. */
    .home-wrap { padding: 16px 16px 28px; }
    .home-hero { grid-template-columns: minmax(0, 1fr); gap: 12px; padding-bottom: 2px; }
    .home-kicker { font-size: 9px; letter-spacing: 1.6px; }
    .home-title { font-size: 22px; margin: 6px 0 4px; }
    .home-sub { font-size: 14px; line-height: 1.35; }
    .hs-more, .hm-wide { display: none; }
    .home-make { padding: 9px 10px 10px; gap: 7px; border-radius: 12px; }
    .home-make .forge-btn { padding: 0 13px; }
    .home-more { font-size: 13px; color: var(--lego-yellow); }
    .home-library { margin-top: 4px; }
}

/* Print: the parts list */
@media print {
    body { background: #fff !important; color: #000 !important; display: block; }
    .top-nav, .sf-home, .create-bar, .viewport-card, .side-tabs, .bom-actions, .tabbar, .sheet-handle, .sheet-peek, .side-panel:not(#tab-parts) { display: none !important; }
    html, body, .app-layout, .studio-grid, .bom-card, .side-panels, #tab-parts, .tab-scroll { display: block !important; height: auto !important; overflow: visible !important; position: static !important; }
    .bom-card { border: 1px solid #ccc !important; background: #fff !important; color: #000 !important; }
    .bom-table th, .bom-table td { color: #000 !important; border-bottom: 1px solid #eee !important; }
    .part-name, .qty-badge, .bom-title { color: #000 !important; }
}

@media (prefers-reduced-motion: reduce) {
    .bom-card, .sf-toast { transition: none; }
    .spin-icon { animation: none; }
}
