/* ------------------------------------------------------------------ *
 * Part Guide — "See your build in action".
 * Chrome uses the Part Guide "industrial hardware journal" design
 * (tokens mirrored from sites/parts/theme.css): paper, burnt-red
 * accent, Geist + Geist Mono, hairline rules, 3px radius, flat panels.
 * Only the diorama (rooms + sprites) stays cosy.
 * ------------------------------------------------------------------ */
:root {
  --bg: #f3f3ef; --surface: #fafaf7; --surface-high: #fff; --surface-hover: #e9e9e3;
  --border: #dcdcd5; --border-strong: #bdbfb5; --text: #20231f; --muted: #63685f; --faint: #75796f;
  --black: #161915;
  --accent: rgb(189, 59, 28); --accent-hover: #a63518;
  --up: #39724d; --down: #ad4934;
  --radius: 3px;
  --sans: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Geist Mono", ui-monospace, monospace;
  --stage-w: 1600; --stage-h: 1200;
  font-family: var(--sans);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; overflow: hidden; }
.app { position: fixed; inset: 0; display: flex; flex-direction: column; }
.loading { margin: auto; color: var(--muted); font: 10px var(--mono); letter-spacing: .08em; text-transform: uppercase; }
/* Static hero shown before the viewer boots — crawlable landing content, then scene.js replaces it. */
.splash { margin: auto; max-width: 600px; max-height: 100%; overflow-y: auto; padding: 44px 28px; text-align: center; font-family: var(--sans); }
.splash-logo { display: inline-block; font-weight: 800; font-size: 22px; letter-spacing: -.02em; color: var(--text); text-decoration: none; margin-bottom: 24px; }
.splash h1 { margin: 0 0 14px; font-size: 30px; line-height: 1.15; letter-spacing: -.02em; font-weight: 700; color: var(--text); }
.splash-lede { margin: 0 auto 22px; max-width: 520px; font-size: 15px; line-height: 1.6; color: var(--muted); }
.splash-lede a { color: var(--accent); }
.splash-feat { list-style: none; margin: 0 auto 24px; padding: 0; font: 10px/2 var(--mono); letter-spacing: .04em; text-transform: uppercase; color: var(--faint); }
.splash-load { margin: 0; font: 9px var(--mono); letter-spacing: .14em; text-transform: uppercase; color: var(--faint); }
a { color: inherit; }

.pg-logo { display: inline-flex; color: var(--black); text-decoration: none; }
.pg-logo .pg-logo-svg { height: 30px; width: auto; display: block; }
.pg-logo.sm .pg-logo-svg { height: 20px; }

/* ---------------- Start screen (arcade stage-select) ---------------- */
.start { position: absolute; inset: 0; display: flex; flex-direction: column; overflow: hidden; }

.start-bar { display: flex; align-items: center; gap: 12px; flex: 0 0 auto; padding: 13px 22px; background: var(--bg); border-bottom: 1px solid var(--border-strong); position: sticky; top: 0; z-index: 5; }
.start-bar .pg-logo { color: var(--black); }
.start-tag { font: 9px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding-left: 12px; border-left: 1px solid var(--border-strong); }
.start-beta { font: 700 8px var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--accent); border: 1px solid var(--accent); border-radius: 2px; padding: 3px 6px; }
.start-bar-sp { flex: 1 1 auto; }
.start-bar .toolbar-icon { width: 34px; height: 34px; padding: 8px; display: inline-grid; place-items: center; }

.start-stage { flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; }
.start-inner { max-width: 1060px; width: 92%; margin: 0 auto; padding: 22px 0 28px; }
/* Enter CTA always visible: pinned footer below the scrolling room picker. */
.start-foot { flex: 0 0 auto; background: var(--bg); border-top: 1px solid var(--border-strong); box-shadow: 0 -8px 26px rgb(16 13 23 / 8%); z-index: 6; }
.start-foot-inner { max-width: 1060px; width: 92%; margin: 0 auto; padding: 12px 0 calc(12px + env(safe-area-inset-bottom, 0px)); }
.start-head { grid-column: 1; grid-row: 1; margin-bottom: 22px; }
.start-kicker { display: flex; align-items: center; gap: 9px; font: 9px var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 14px; }
.start-kicker > span { width: 7px; height: 7px; background: var(--accent); }
.start-head h1 { font: 600 clamp(26px, 3vw, 38px)/1.02 var(--sans); letter-spacing: -.045em; margin: 0; }

/* Headline sits top-left in the grid so the preview rises to the top-right — no gap above it. */
.select { display: grid; grid-template-columns: minmax(320px, 380px) 1fr; grid-template-rows: auto 1fr; gap: 0 22px; align-items: start; }
.col-loadout { grid-column: 1; grid-row: 2; }
.col-world { grid-column: 2; grid-row: 1 / 3; min-width: 0; }
.col-label { display: flex; align-items: center; gap: 10px; margin: 0 0 12px; font: 9px var(--mono); letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.col-label .step { display: grid; place-items: center; width: 20px; height: 20px; border-radius: 2px; background: var(--accent); color: #fff; font: 700 11px var(--mono); flex: 0 0 auto; }

/* Loadout — save slots */
.slots { display: grid; gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.slot { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; background: var(--surface-high); border: 0; padding: 13px 14px; cursor: pointer; color: inherit; font: inherit; transition: background .12s; }
.slot:hover { background: var(--surface-hover); }
.slot:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.slot-no { font: 700 11px var(--mono); color: var(--faint); letter-spacing: .04em; flex: 0 0 auto; }
.slot-ico { width: 34px; height: 38px; border-radius: 2px; display: grid; place-items: center; background: #e7e8e1; color: var(--accent); flex: 0 0 auto; }
.slot-body { min-width: 0; flex: 1; }
.slot-name { display: block; font: 500 15px var(--sans); letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot-stat { display: block; color: var(--muted); font: 9px var(--mono); letter-spacing: .03em; text-transform: uppercase; margin-top: 4px; }
.slot-src { font: 8px var(--mono); color: var(--muted); text-transform: uppercase; letter-spacing: .08em; flex: 0 0 auto; }
.slot-go { font: 13px var(--mono); color: transparent; flex: 0 0 auto; transition: color .12s, transform .12s; }
.slot:hover .slot-go { color: var(--border-strong); }
.slot[aria-pressed="true"] { background: color-mix(in srgb, var(--accent) 9%, var(--surface-high)); box-shadow: inset 4px 0 0 var(--accent); }
.slot[aria-pressed="true"] .slot-no { color: var(--accent); }
.slot[aria-pressed="true"] .slot-ico { background: var(--accent); color: #fff; }
.slot[aria-pressed="true"] .slot-go { color: var(--accent); transform: translateX(2px); }

.hint { color: var(--muted); font: 10px/1.7 var(--mono); }
.hint a { color: var(--accent); }
.hint.small { margin: 13px 2px 0; font-size: 9px; }

/* Live world preview */
.preview { position: relative; aspect-ratio: 16/9; border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; background: #1b1922; margin-bottom: 22px; }
.preview-room { width: 100%; height: 100%; object-fit: cover; display: block; }
.pv-corner { position: absolute; width: 15px; height: 15px; border: 2px solid rgba(255,255,255,.82); z-index: 2; pointer-events: none; }
.pv-corner.tl { top: 11px; left: 11px; border-right: 0; border-bottom: 0; }
.pv-corner.tr { top: 11px; right: 11px; border-left: 0; border-bottom: 0; }
.pv-corner.bl { bottom: 11px; left: 11px; border-right: 0; border-top: 0; }
.pv-corner.br { bottom: 11px; right: 11px; border-left: 0; border-top: 0; }
.pv-status { position: absolute; top: 13px; right: 15px; z-index: 3; display: inline-flex; align-items: center; gap: 6px; font: 700 8px var(--mono); letter-spacing: .14em; text-transform: uppercase; color: #fff; background: var(--accent); padding: 4px 8px; border-radius: 2px; }
.pv-status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: #fff; animation: pv-blink 1.4s steps(1, end) infinite; }
.preview.empty .pv-status { background: rgba(255,255,255,.22); color: #fff; }
.preview.empty .pv-status::before { animation: none; opacity: .5; }
.pv-hud { position: absolute; left: 0; right: 0; bottom: 0; z-index: 3; padding: 30px 16px 15px; background: linear-gradient(transparent, rgba(12,9,18,.84)); color: #fff; }
.pv-name { display: block; font: 600 clamp(18px, 2.4vw, 25px)/1.08 var(--sans); letter-spacing: -.02em; }
.pv-meta { display: block; margin-top: 6px; font: 9px var(--mono); letter-spacing: .07em; text-transform: uppercase; color: rgba(255,255,255,.78); }
@keyframes pv-blink { 50% { opacity: .2; } }
@media (prefers-reduced-motion: reduce) { .pv-status::before, .bs-caret { animation: none; } }

/* World picker */
.worlds { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.world { position: relative; border: 2px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; cursor: pointer; background: #e7e8e1; aspect-ratio: 4/3; padding: 0; transition: border-color .12s, box-shadow .12s, transform .12s; }
.world img { width: 100%; height: 100%; object-fit: cover; display: block; }
.world:hover { border-color: var(--muted); transform: translateY(-2px); }
.world:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.world[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); transform: translateY(-2px); }
.world-name { position: absolute; left: 0; right: 0; bottom: 0; padding: 9px 10px; font: 8px var(--mono); letter-spacing: .06em; text-transform: uppercase; color: #fff; background: linear-gradient(transparent, rgba(0,0,0,.66)); text-align: left; }
.world-pick { position: absolute; top: 6px; right: 6px; width: 20px; height: 20px; border-radius: 2px; background: var(--accent); color: #fff; display: grid; place-items: center; font: 700 11px var(--mono); opacity: 0; transform: scale(.6); transition: opacity .12s, transform .12s; }
.world[aria-pressed="true"] .world-pick { opacity: 1; transform: none; }
.world.locked { cursor: pointer; }
.world.locked img { filter: grayscale(.72) brightness(.5); }
.world.locked:hover { border-color: var(--accent); }
.world-lock { position: absolute; inset: 0; display: grid; place-items: center; font-size: 22px; z-index: 2; filter: drop-shadow(0 2px 5px rgba(0,0,0,.6)); pointer-events: none; }

/* Share-to-unlock panel for the bonus rooms */
.unlock { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; margin-top: 14px; padding: 11px 14px; border: 1px solid var(--accent); border-radius: var(--radius); background: color-mix(in srgb, var(--accent) 7%, var(--surface-high)); }
.unlock-ico { font-size: 16px; flex: 0 0 auto; }
.unlock-txt { flex: 1; min-width: 160px; font: 10px/1.55 var(--mono); letter-spacing: .01em; color: var(--text); }
.unlock-txt b { font-weight: 700; }
.unlock-btn { flex: 0 0 auto; font: 9px var(--mono); letter-spacing: .06em; text-transform: uppercase; border: 1px solid var(--accent); background: var(--accent); color: #fff; border-radius: 2px; padding: 9px 13px; cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s; }
.unlock-btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.unlock-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.unlock.nudge { animation: unlock-nudge .42s ease; }
@keyframes unlock-nudge { 0%, 100% { transform: none; } 20% { transform: translateX(-5px); } 40% { transform: translateX(5px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(3px); } }

/* Opt-in play-stats consent (deskMetrics.label) */
.col-world > label { display: flex; align-items: center; gap: 8px; margin: 16px 2px 0; font: 9px var(--mono); letter-spacing: .03em; text-transform: uppercase; color: var(--muted); cursor: pointer; }
.col-world > label input { width: 14px; height: 14px; margin: 0; accent-color: var(--accent); cursor: pointer; flex: 0 0 auto; }

/* PRESS START */
.start-actions { margin-top: 0; }
.btn-start { display: inline-flex; align-items: center; gap: 14px; width: 100%; text-align: left; border: 1px solid var(--accent); background: var(--accent); color: #fff; border-radius: var(--radius); padding: 16px 20px; cursor: pointer; font: inherit; transition: background .12s, border-color .12s; }
.btn-start:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-start:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.btn-start:disabled { opacity: .42; cursor: not-allowed; }
.bs-icon { display: grid; place-items: center; width: 26px; height: 26px; border: 1px solid rgba(255,255,255,.55); border-radius: 2px; font-size: 9px; flex: 0 0 auto; }
.bs-text { font: 600 15px var(--sans); letter-spacing: -.01em; }
.bs-hint { margin-left: auto; display: inline-flex; align-items: center; font: 9px var(--mono); letter-spacing: .06em; text-transform: uppercase; color: rgba(255,255,255,.82); }
.bs-hint b { font-weight: 700; }
.bs-caret { width: 7px; height: 13px; margin-left: 5px; background: #fff; animation: pv-blink 1.1s steps(1, end) infinite; }
.btn-start:disabled .bs-caret { animation: none; opacity: .4; }

/* ---------------- Scene ---------------- */
.scene { position: fixed; inset: 0; display: flex; flex-direction: column; }
.scene-top {
  display: flex; align-items: center; gap: 8px 14px; padding: 10px 16px; flex: 0 0 auto; flex-wrap: wrap;
  position: relative; background: var(--bg); border-bottom: 1px solid var(--border-strong); z-index: 20;
}
.scene-top .pg-logo { flex: 0 0 auto; }
.scene-top .title { font: 500 15px var(--sans); letter-spacing: -.02em; padding-left: 14px; border-left: 1px solid var(--border-strong); }
.scene-top .title small { display: block; font: 8px var(--mono); color: var(--muted); letter-spacing: .04em; margin-top: 3px; text-transform: uppercase; }
.scene-top .chip { white-space: nowrap; }
.scene-menu summary { list-style: none; }
.scene-menu summary::-webkit-details-marker { display: none; }
.scene-menu summary::after { content: " ▾"; }
.scene-menu-panel { position: absolute; z-index: 2; top: calc(100% + 6px); right: 12px; display: grid; gap: 6px; width: min(230px, calc(100vw - 24px)); padding: 10px; background: var(--surface-high); border: 1px solid var(--border-strong); box-shadow: 0 8px 24px rgb(0 0 0 / 12%); }
.scene-menu-panel > .chip { text-align: left; }
.scene-menu-panel .size-ctrl input { flex: 1; min-width: 45px; }
.chip { font: 9px var(--mono); letter-spacing: .04em; text-transform: uppercase; border: 1px solid var(--border-strong); background: transparent; color: var(--text); border-radius: 2px; padding: 8px 12px; cursor: pointer; transition: background .12s, border-color .12s, color .12s; }
.chip:hover { background: var(--surface-hover); }
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip.icon { display: inline-flex; align-items: center; gap: 7px; }
.size-ctrl { display: inline-flex; flex: 0 0 auto; align-items: center; gap: 8px; font: 9px var(--mono); white-space: nowrap; }
.size-ctrl[hidden] { display: none; }
.size-ctrl input { width: 76px; margin: 0; accent-color: var(--text); cursor: pointer; }
.size-ctrl .sc-val { min-width: 5ch; font-variant-numeric: tabular-nums; }

/* ---------------- HUD: in-scene game menu (symbols, not text) ---------------- */
.hud {
  position: absolute; right: 16px; top: 50%; transform: translateY(-50%); z-index: 18;
  display: flex; flex-direction: column; gap: 7px; padding: 8px; border-radius: 18px;
  background: color-mix(in srgb, var(--surface-high) 85%, transparent);
  border: 1px solid var(--border-strong); box-shadow: 0 12px 30px rgb(16 13 23 / 20%);
  -webkit-backdrop-filter: blur(9px); backdrop-filter: blur(9px);
}
.hud-btn {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  width: 60px; height: 58px; padding: 0; cursor: pointer; color: var(--text);
  background: transparent; border: 1px solid transparent; border-radius: 13px;
  font: 600 8.5px var(--mono); text-transform: uppercase; letter-spacing: .03em;
  transition: background .14s, border-color .14s, transform .07s, color .14s;
}
.hud-btn:hover { background: var(--surface-hover); border-color: var(--border-strong); }
.hud-btn:active { transform: translateY(1px); }
.hud-btn[hidden] { display: none; }
.hud-btn .hud-ico { width: 23px; height: 23px; display: block; }
.hud-label { display: block; line-height: 1; }
.hud-btn[aria-expanded="true"] { background: var(--surface-hover); border-color: var(--border-strong); }
/* Prominent primary action */
.hud-add { background: var(--accent); border-color: var(--accent); color: #fff; margin-bottom: 3px; }
.hud-add:hover { background: color-mix(in srgb, var(--accent) 86%, #000); border-color: color-mix(in srgb, var(--accent) 86%, #000); color: #fff; }
.hud-add .hud-ico { width: 26px; height: 26px; }
/* Options popover opens beside the rail, not under it */
.hud .scene-menu { position: static; display: block; }
.hud-more > summary::after { content: none; }
.hud .scene-menu-panel { top: auto; bottom: 0; right: calc(100% + 12px); left: auto; width: min(220px, 60vw); }
.hud .scene-menu-panel .game-theme, .hud .scene-menu-panel #shotChip { justify-content: flex-start; width: 100%; gap: 8px; }
.hud .scene-menu-panel .game-theme::after { content: "Dark mode"; }
.hud .scene-menu-panel .game-theme[aria-pressed="true"]::after { content: "Light mode"; }

.stage-wrap { position: relative; flex: 1 1 auto; overflow: hidden; display: flex; min-height: 0; background: repeating-linear-gradient(45deg, #ecece7, #ecece7 2px, #f3f3ef 2px, #f3f3ef 10px); }
.stage-area { position: relative; flex: 1 1 auto; min-width: 0; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; padding-right: 102px; }
.stage {
  position: relative; flex: 0 0 auto; overflow: hidden; border: 1px solid var(--border-strong);
  background-size: cover; background-position: center;
}
.stage .room-bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }

.sprite {
  position: absolute; transform-origin: bottom center; cursor: pointer;
  transform: translate(-50%, -100%) scale(var(--s, 1));
  transition: transform .55s cubic-bezier(.2,.9,.25,1.25), opacity .4s ease, filter .15s;
  filter: drop-shadow(0 10px 14px rgba(40,25,70,.28));
}
.sprite img { width: 100%; height: 100%; display: block; object-fit: contain; object-position: bottom center; transform-origin: bottom center; pointer-events: none; -webkit-user-drag: none; }
.sprite.shaped { pointer-events: none; }
.sprite-hit-area { position: absolute; inset: 0; width: 100%; height: 100%; transform-origin: bottom center; pointer-events: none; }
.sprite-hit-area path { fill: none; pointer-events: fill; }
.sprite.enter { transform: translate(-50%, -165%) scale(calc(var(--s, 1) * .5)); opacity: 0; }
.sprite:hover, .sprite.active { filter: drop-shadow(0 14px 18px rgba(40,25,70,.35)); }
.sprite .badge { position: absolute; top: -6px; right: -6px; background: var(--accent); color: #fff; font: 700 11px var(--mono); border-radius: 2px; padding: 1px 6px; pointer-events: auto; }
.sprite.box { cursor: pointer; }
.sprite.box:hover, .sprite.box:focus-visible { filter: drop-shadow(0 16px 20px rgba(40,25,70,.4)); outline: none; }
.sprite.box .box-tag { position: absolute; top: -6px; left: 50%; transform: translateX(-50%); background: var(--accent); color: #fff; font: 700 10px var(--mono); letter-spacing: .06em; text-transform: uppercase; border-radius: 2px; padding: 2px 7px; white-space: nowrap; opacity: 0; transition: opacity .15s; pointer-events: none; }
.sprite.box:hover .box-tag, .sprite.box:focus-visible .box-tag { opacity: 1; }
.sprite.draggable { cursor: grab; touch-action: none; }
.sprite.draggable.locked { cursor: default; touch-action: auto; }
.sprite.dragging { cursor: grabbing; transition: none; filter: drop-shadow(0 20px 24px rgba(40,25,70,.42)); }
.stage[data-room="streamer"] .sprite.draggable { filter: drop-shadow(0 3px 5px rgb(14 10 22 / 22%)); }
.stage[data-room="streamer"] .sprite.dragging { filter: drop-shadow(0 7px 10px rgb(14 10 22 / 30%)); }
.stage.case-view .room-bg { object-fit: contain; }
.stage.angled-case .room-bg { filter: brightness(.48) blur(3px); }
.case-shell { position: absolute; transform-origin: bottom center; pointer-events: none; }

.drag-hint { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); background: color-mix(in srgb, var(--text) 86%, transparent); color: var(--bg); font: 500 10px var(--mono); letter-spacing: .05em; text-transform: uppercase; padding: 7px 13px; border-radius: 2px; pointer-events: none; opacity: 1; transition: opacity .5s; z-index: 16; }
.drag-hint.hide { opacity: 0; }

/* ---------------- Spec card ---------------- */
.spec { position: absolute; z-index: 30; width: 250px; background: var(--surface-high); border: 1px solid var(--border-strong); border-radius: var(--radius); box-shadow: 0 12px 30px color-mix(in srgb, var(--text) 10%, transparent); padding: 14px; pointer-events: none; opacity: 0; transform: translateY(6px); transition: opacity .12s, transform .12s; }
.spec.show { opacity: 1; transform: none; pointer-events: auto; }
.spec .sp-cat { font: 8px var(--mono); text-transform: uppercase; letter-spacing: .06em; color: var(--accent); }
.spec .sp-photo { width: 100%; height: 120px; object-fit: contain; background: #e7e8e1; border-radius: 2px; margin: 10px 0; mix-blend-mode: multiply; }
.spec .sp-photo.icon { display: grid; place-items: center; mix-blend-mode: normal; color: var(--muted); }
.spec .sp-name { font: 500 15px var(--sans); letter-spacing: -.02em; line-height: 1.25; }
.spec .sp-brand { color: var(--muted); font: 9px var(--mono); margin-top: 4px; }
.spec .sp-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); }
.spec .sp-price { font: 500 14px var(--mono); }
.spec .sp-link { font: 9px var(--mono); color: var(--accent); text-decoration: none; }
.spec .sp-link:hover { text-decoration: underline; text-underline-offset: 3px; }
.spec .sp-extra { color: var(--muted); font: 9px var(--mono); margin-top: 8px; }
/* Per-item controls, inside the overlay */
.spec .sp-controls { display: flex; gap: 6px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.spec .sp-ctrl { flex: 1 1 0; display: inline-flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; padding: 7px 3px; background: transparent; border: 1px solid var(--border-strong); border-radius: 8px; color: var(--text); cursor: pointer; font: 600 7.5px var(--mono); letter-spacing: .03em; text-transform: uppercase; transition: background .12s, border-color .12s, color .12s; }
.spec .sp-ctrl:hover { background: var(--surface-hover); }
.spec .sp-ctrl.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.spec .sp-ctrl.sp-del:hover { background: #e5484d; border-color: #e5484d; color: #fff; }
.spec .sp-ctrl .sp-ctrl-l { line-height: 1; }
.spec .sp-ctrl svg { display: block; }
.spec .sp-size { display: flex; align-items: center; gap: 10px; margin-top: 10px; font: 9px var(--mono); text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.spec .sp-size input[type="range"] { flex: 1; min-width: 0; accent-color: var(--accent); }
/* Touch: the info panel is docked at the bottom as a compact bar, outside the play area. */
.spec.docked { position: fixed; left: 8px; right: 8px; bottom: 8px; top: auto; width: auto; max-width: 540px; margin-inline: auto; padding: 10px 12px; display: grid; grid-template-columns: 54px minmax(0, 1fr) auto 26px; align-items: center; column-gap: 12px; row-gap: 9px; transform: translateY(10px); z-index: 60; }
.spec.docked.show { transform: none; }
.spec.docked .sp-photo { grid-column: 1; grid-row: 1; width: 54px; height: 46px; margin: 0; }
.spec.docked .sp-name { grid-column: 2; grid-row: 1; font-size: 14px; }
.spec.docked .sp-foot { grid-column: 3; grid-row: 1; margin: 0; padding: 0; border: 0; flex-direction: column; align-items: flex-end; gap: 3px; white-space: nowrap; }
.spec.docked .sp-cat, .spec.docked .sp-brand, .spec.docked .sp-extra { display: none; }
.spec.docked .sp-close { grid-column: 4; grid-row: 1; display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; padding: 0; background: none; border: 0; color: var(--muted); line-height: 1; cursor: pointer; }
.spec.docked .sp-controls { grid-column: 1 / -1; grid-row: 2; margin: 0; padding: 0; border: 0; }
.spec.docked .sp-size { grid-column: 1 / -1; grid-row: 3; display: flex; align-items: center; gap: 10px; margin: 0; font: 9px var(--mono); text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.spec.docked .sp-size input[type="range"] { flex: 1; min-width: 0; accent-color: var(--accent); }

/* ---------------- Legend ---------------- */
.legend { flex: 0 0 clamp(264px, 25vw, 344px); min-width: 0; align-self: stretch; overflow: auto; background: var(--surface); border-right: 1px solid var(--border-strong); padding: 14px; }
.legend h3 { margin: 2px 2px 10px; font: 9px var(--mono); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.legend .lg-row { display: flex; gap: 8px; align-items: center; padding: 8px 6px; border-radius: 4px; cursor: pointer; }
.legend .lg-row:hover, .legend .lg-row.active { background: var(--surface-hover); }
.legend .lg-ico { width: 28px; height: 30px; border-radius: 3px; background: #e7e8e1; color: var(--accent); display: grid; place-items: center; flex: 0 0 auto; }
.legend .lg-main { min-width: 0; flex: 1; margin-right: 2px; }
.legend .lg-name { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font: 500 13px/1.3 var(--sans); letter-spacing: -.01em; overflow-wrap: break-word; }
.legend .lg-cat { display: block; font: 8px/1.5 var(--mono); color: var(--muted); letter-spacing: .03em; text-transform: uppercase; margin-top: 3px; }
.legend .lg-eye { flex: 0 0 auto; align-self: center; background: none; border: 0; color: var(--muted); cursor: pointer; padding: 3px; border-radius: 3px; display: grid; place-items: center; }
.legend .lg-eye:hover { color: var(--text); background: var(--surface-hover); }
.legend .lg-row.hidden { opacity: .55; }
.legend .lg-row.hidden .lg-name { text-decoration: line-through; }
.legend .lg-row.hidden .lg-eye { color: var(--accent); }
.legend .lg-row.locked .lg-name { color: var(--muted); }
.legend .lg-row.locked .lg-eye[data-action="lock"] { color: var(--accent); }
.legend .lg-select { flex: 0 0 auto; align-self: center; margin: 1px 0 0; accent-color: var(--accent); cursor: pointer; }
.legend .lg-group { display: inline-block; width: 8px; height: 8px; border-radius: 50%; vertical-align: middle; }
.legend .lg-grouptools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 0 2px 10px; font: 9px var(--mono); text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.chip.sm { padding: 5px 9px; font-size: 8px; }
.legend .lg-total { margin: 10px 4px 2px; padding-top: 10px; border-top: 1px solid var(--border); font: 9px var(--mono); color: var(--muted); display: flex; justify-content: space-between; text-transform: uppercase; letter-spacing: .04em; }
.legend .lg-total b { color: var(--text); font-weight: 500; }

/* ---------------- Toast ---------------- */
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: var(--radius); font: 500 11px var(--sans); opacity: 0; transition: opacity .2s, transform .2s; z-index: 50; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------------- Calibration overlay (dev, ?cal=1) ---------------- */
.calib { position: absolute; inset: 0; z-index: 40; pointer-events: none; }
.calib .cal-dot { position: absolute; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; background: #ff3b6b; box-shadow: 0 0 0 2px #fff; }
.calib .cal-label { position: absolute; transform: translate(8px, -6px); font: 11px/1 var(--mono); color: #fff; background: #ff3b6b; padding: 2px 4px; border-radius: 2px; white-space: nowrap; }
.calib .cal-read { position: absolute; left: 8px; bottom: 8px; font: 12px/1.3 var(--mono); color: #fff; background: rgba(0,0,0,.72); padding: 6px 8px; border-radius: 2px; }
.calib .cal-cross-x, .calib .cal-cross-y { position: absolute; background: rgba(255,59,107,.6); }
.calib .cal-cross-x { height: 1px; left: 0; right: 0; }
.calib .cal-cross-y { width: 1px; top: 0; bottom: 0; }

.legend-toggle { display: none; }

@media (max-width: 760px) {
  .select { grid-template-columns: 1fr; grid-template-rows: none; gap: 22px; }
  .start-head, .col-loadout, .col-world { grid-column: 1; grid-row: auto; }
  .start-head { margin-bottom: 0; }
}
@media (max-width: 640px) {
  .start-head h1 { font-size: 30px; }
  .stage-wrap { flex-direction: column; }

  /* Items list as a thumb-reachable bottom-sheet drawer (slides up over the scene). */
  .legend {
    display: block; position: fixed; left: 0; right: 0; bottom: 0; top: auto; z-index: 55;
    flex: none; width: auto; max-height: 68dvh; margin: 0;
    padding: 6px 14px calc(20px + env(safe-area-inset-bottom, 0px));
    background: var(--surface); border: 0; border-top: 1px solid var(--border-strong);
    border-radius: 16px 16px 0 0; box-shadow: 0 -14px 34px rgb(16 13 23 / 20%);
    transform: translateY(101%); visibility: hidden;
    transition: transform .24s cubic-bezier(.2,.8,.3,1), visibility 0s linear .24s;
    overscroll-behavior: contain;
  }
  .legend.expanded { transform: none; visibility: visible; transition: transform .24s cubic-bezier(.2,.8,.3,1), visibility 0s; }
  .legend::before { content: ""; display: block; width: 42px; height: 4px; margin: 4px auto 10px; border-radius: 3px; background: var(--border-strong); }
  .legend h3 { position: sticky; top: 0; z-index: 1; margin: 0 2px 8px; padding: 4px 0 6px; background: var(--surface); }
  .legend-toggle { display: inline-flex; }
  .legend .lg-name { -webkit-line-clamp: 3; }

  /* Just logo + title in the top bar — all controls live in the HUD rail. */
  .scene-top { gap: 6px 10px; padding: 8px 12px; align-items: center; }
  .scene-top .title { flex: 1 1 0; min-width: 0; font-size: 13px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .scene-top .title small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  /* Compact the HUD rail and keep it clear of the bottom sheet / docked panel. */
  .hud { right: 8px; gap: 6px; padding: 6px; }
  .hud-btn { width: 52px; height: 50px; }
  .hud .scene-menu-panel { right: calc(100% + 10px); bottom: 0; }
  .stage-area { padding-right: 70px; }   /* smaller HUD gutter on phones */

  /* Bigger touch targets in the parts sheet. */
  .legend .lg-row { padding: 12px 8px; }
  .legend .lg-eye { padding: 8px; }
  .legend .lg-select { width: 20px; height: 20px; }
}

.desk-gallery { width: min(520px, calc(100vw - 32px)); max-height: 80dvh; overflow: hidden; padding: 20px; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius); }
.desk-gallery[open] { display: flex; flex-direction: column; gap: 12px; }
.desk-gallery::backdrop { background: rgb(16 13 23 / 55%); }
.desk-gallery form { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.desk-gallery h2, .desk-gallery p { margin: 0; }
.desk-gallery label { display: grid; gap: 6px; }
.desk-gallery input { width: 100%; padding: 8px; color: inherit; background: var(--surface-high); border: 1px solid var(--border-strong); font: inherit; }
.gallery-status { color: var(--muted); font-size: 13px; }
.desk-gallery ul { min-height: 0; overflow: auto; padding: 0; margin: 0; list-style: none; }
.desk-gallery li { display: grid; grid-template-columns: 48px minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 8px 0; border-top: 1px solid var(--border); }
.desk-gallery li img { width: 48px; height: 40px; object-fit: contain; }
.desk-gallery li small { display: block; color: var(--muted); }

.mount-picker { display: block; width: 100%; min-width: 0; margin-top: 5px; color: inherit; background: var(--surface-high); border: 1px solid var(--border-strong); font: 11px var(--sans); }

.power-controls { display: inline-flex; align-items: center; flex: 0 0 auto; gap: 6px; }
.power-controls[hidden] { display: none; }
.power-controls label { font: 9px var(--mono); white-space: nowrap; }
.power-controls select { padding: 6px 2px; color: inherit; background: var(--surface); border: 1px solid var(--border-strong); font: inherit; }
.system-screen { position: absolute; inset: 0; width: 100%; height: 100%; transform-origin: bottom center; pointer-events: none; }
.system-screen.booting { animation: boot-screen .85s ease-out both; }
@keyframes boot-screen { 0%, 22% { opacity: 0; } 65% { opacity: .5; } 100% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .system-screen.booting { animation: none; } }

.music-controls { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.music-controls label { display: inline-flex; align-items: center; gap: 4px; font: 9px var(--mono); white-space: nowrap; }
.music-controls select { max-width: 135px; padding: 6px 2px; color: inherit; background: var(--surface); border: 1px solid var(--border-strong); font: inherit; }
.music-controls input { width: 56px; margin: 0; accent-color: var(--text); }

.music-controls[hidden] { display: none; }
.room-music-frame { position: absolute; width: 1px; height: 1px; padding: 0; border: 0; clip-path: inset(50%); pointer-events: none; }

:root[data-game-theme="dark"] {
  color-scheme: dark;
  --bg: #1a1c1a; --surface: #232522; --surface-high: #2c2f2b; --surface-hover: #363a34;
  --border: #383d36; --border-strong: #575e54; --text: #f0f2eb; --muted: #b0b8a9; --faint: #a0a99a;
  --accent: #f09878; --accent-hover: #ffb398;
  --black: #f0f2eb;
}
:root[data-game-theme="dark"] .stage-wrap { background: repeating-linear-gradient(45deg, #232522, #232522 2px, #1d201d 2px, #1d201d 10px); }
:root[data-game-theme="dark"] .btn-start { color: #211815; }
:root[data-game-theme="dark"] .bs-icon { border-color: rgba(33,24,21,.5); }
:root[data-game-theme="dark"] .bs-hint { color: rgba(33,24,21,.82); }
:root[data-game-theme="dark"] .bs-caret { background: #211815; }
:root[data-game-theme="dark"] .pv-status { color: #211815; }
:root[data-game-theme="dark"] .pv-status::before { background: #211815; }
.gallery-tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.gallery-categories { display: flex; flex: 0 0 auto; gap: 6px; overflow-x: auto; padding: 2px 2px 6px; }
.gallery-categories[hidden] { display: none; }
.gallery-categories .chip { flex: 0 0 auto; white-space: nowrap; }
.desk-gallery label[hidden] { display: none; }
.music-player-sprite:focus-visible, .music-player-sprite.playing { filter: drop-shadow(0 0 5px #f4c477); }
.music-player-sprite[aria-busy="true"] { opacity: .65; }
.legend-decor, .legend-mounts, .legend-interior { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.legend-interior ul { margin: 0; padding: 0; list-style: none; }
.legend-interior li { display: flex; justify-content: space-between; gap: 8px; padding: 9px 7px; }
.legend-interior .lg-price { font: 11px var(--mono); }
.stage[data-room] .sprite.desk-mat { filter: drop-shadow(0 1px 1px rgb(24 16 20 / 25%)); }
.stage[data-room] .sprite.flat-on-desk { filter: drop-shadow(0 2px 2px rgb(24 16 20 / 26%)); }
.room-music-credit { text-decoration: none; overflow: hidden; text-overflow: ellipsis; }

.wallpaper-controls { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.wallpaper-controls .chip { padding: 3px 5px; font-size: 8px; }

.start-actions button, .start-bar button { user-select: none; }
.toolbar-icon svg { display: block; width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.share-desk { width: min(360px, calc(100vw - 24px)); padding: 16px; background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); border-radius: var(--radius); }
.share-desk::backdrop { background: rgb(16 13 23 / 55%); }
.share-desk form, .share-link { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.share-desk h2 { margin: 0; font: 600 18px var(--sans); }
.share-desk figure { display: grid; justify-items: center; gap: 8px; margin: 14px 0; }
.share-desk canvas { max-width: 100%; image-rendering: pixelated; }
.share-desk figcaption { color: var(--muted); font-size: 12px; text-align: center; }
.share-link label { flex: 1; min-width: 0; font-size: 11px; }
.share-link input { display: block; width: 100%; margin-top: 3px; padding: 6px; background: var(--surface-high); color: var(--text); border: 1px solid var(--border); font: 11px var(--mono); }
.share-link button { flex-shrink: 0; }
.share-desk > .chip { margin-top: 10px; }

.furniture-layer { position: absolute; pointer-events: none; }
.furniture-layer > img { display: block; width: 100%; height: 100%; }
.sprite.riser-front, .sprite.mount-clamp { pointer-events: none; filter: none; }
.sprite-layer { isolation: isolate; }
.stage[data-room] .sprite.grounded-decor { filter: none; }
.riser-front, .mount-clamp { touch-action: none; }
