/* 版面概念：繪圖桌——灰泥色桌面上的描圖紙面板，尺寸讀數用等寬字，像施工圖上的標註 */
:root {
  --plaster: #e9e6e0;
  --sheet: #f8f7f4;
  --sheet-2: #f0eee9;
  --ink: #23262b;
  --ink-2: #5d6168;
  --rule: #d8d4cc;
  --accent: #2c5d8f;
  --accent-soft: #dce6f0;
  --accent-ink: #ffffff;
  --danger: #b8432f;
  --danger-soft: #f5dfda;
  --ok: #3f7a52;
  --scene: #e4e1db;
  --shadow: 0 1px 2px rgba(35, 38, 43, .06), 0 8px 24px rgba(35, 38, 43, .08);
  --font-display: "Noto Serif TC", "Songti TC", serif;
  --font-body: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --left-w: 288px;
  --right-w: 300px;
  --top-h: 54px;
  --r: 8px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --plaster: #16181b; --sheet: #1e2125; --sheet-2: #262a2f; --ink: #e8e6e1; --ink-2: #a2a6ad;
    --rule: #33383e; --accent: #7aaee0; --accent-soft: #24384d; --accent-ink: #0f1a26; --danger: #e7826d;
    --danger-soft: #3b2420; --ok: #7cc493; --scene: #24272b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --plaster: #16181b; --sheet: #1e2125; --sheet-2: #262a2f; --ink: #e8e6e1; --ink-2: #a2a6ad;
  --rule: #33383e; --accent: #7aaee0; --accent-soft: #24384d; --accent-ink: #0f1a26; --danger: #e7826d;
  --danger-soft: #3b2420; --ok: #7cc493; --scene: #24272b;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--plaster);
  color: var(--ink);
  font: 14px/1.5 var(--font-body);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app {
  height: 100%;
  display: grid;
  grid-template-columns: var(--left-w) minmax(0, 1fr) var(--right-w);
  grid-template-rows: var(--top-h) minmax(0, 1fr);
  grid-template-areas: "top top top" "left stage right";
}

/* ---------- 上方工具列 ---------- */
.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 12px;
  padding-block: 0;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: var(--sheet);
  border-bottom: 1px solid var(--rule);
  min-width: 0;
}
.brand { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.brand-mark {
  width: 22px; height: 22px; border: 2px solid var(--ink); border-radius: 2px; position: relative;
}
.brand-mark::before, .brand-mark::after { content: ""; position: absolute; background: var(--accent); }
.brand-mark::before { left: 3px; bottom: 3px; width: 8px; height: 5px; }
.brand-mark::after { right: 3px; top: 3px; width: 5px; height: 9px; }
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 17px; letter-spacing: .04em; }

.room-chip {
  display: inline-flex; align-items: baseline; gap: 4px;
  font-family: var(--font-mono); font-size: 13px; font-variant-numeric: tabular-nums;
  background: var(--sheet-2); border: 1px dashed var(--rule); border-radius: 999px; padding: 4px 12px;
}
.room-chip:hover { border-color: var(--accent); color: var(--accent); }
.room-chip .unit { color: var(--ink-2); font-size: 11px; }

.human-chip {
  display: inline-flex; align-items: baseline; gap: 4px;
  font-family: var(--font-mono); font-size: 13px; font-variant-numeric: tabular-nums;
  background: var(--sheet-2); border: 1px solid var(--rule); border-radius: 999px; padding: 4px 10px;
  cursor: pointer; user-select: none; transition: border-color .15s, color .15s, background .15s;
  color: var(--ink); margin-left: 6px;
}
.human-chip:hover { border-color: var(--accent); color: var(--accent); }
.human-chip em { font-style: normal; color: var(--ink-2); font-size: 11px; }
.human-chip .icon { font-size: 12px; }

.views { display: flex; background: var(--sheet-2); border: 1px solid var(--rule); border-radius: 8px; padding: 2px; margin-left: auto; }
.seg { border: 0; background: none; padding: 5px 12px; border-radius: 6px; font-size: 13px; color: var(--ink-2); white-space: nowrap; }
.seg:hover { color: var(--ink); }
.seg.is-on { background: var(--sheet); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); font-weight: 500; }

.tools { display: flex; align-items: center; gap: 4px; margin-left: 8px; }
.divider { width: 1px; height: 22px; background: var(--rule); margin: 0 6px; }
.icon-btn {
  width: 34px; height: 34px; display: grid; place-items: center; border: 0; border-radius: 8px; background: none; color: var(--ink-2);
}
.icon-btn:hover:not(:disabled) { background: var(--sheet-2); color: var(--ink); }
.icon-btn:disabled { opacity: .35; cursor: default; }

.btn {
  border: 1px solid var(--rule); background: var(--sheet); border-radius: 8px; padding: 6px 14px; font-size: 13px; font-weight: 500; white-space: nowrap;
}
.btn:hover { border-color: var(--ink-2); }
.btn.ghost { border-color: transparent; background: none; color: var(--ink-2); }
.btn.ghost:hover { background: var(--sheet-2); color: var(--ink); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn:disabled { opacity: .5; cursor: progress; }

.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 190px;
  background: var(--sheet); border: 1px solid var(--rule); border-radius: 10px; box-shadow: var(--shadow); padding: 6px;
  display: flex; flex-direction: column;
}
.menu button { text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 6px; font-size: 13px; }
.menu button:hover { background: var(--sheet-2); }
.menu button.danger { color: var(--danger); }
.menu button { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.menu kbd { font-size: 10px; }

/* ---------- 面板 ---------- */
.panel { background: var(--sheet); overflow-y: auto; overscroll-behavior: contain; min-width: 0; }
.panel.left { grid-area: left; border-right: 1px solid var(--rule); display: flex; flex-direction: column; }
.panel.right { grid-area: right; border-left: 1px solid var(--rule); }

.tabs { display: flex; border-bottom: 1px solid var(--rule); position: sticky; top: 0; background: var(--sheet); z-index: 2; }
.tab { flex: 1; border: 0; background: none; padding: 12px 8px; font-size: 13px; color: var(--ink-2); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab.is-on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 500; }

.tab-body { padding: 14px 16px 24px; display: flex; flex-direction: column; gap: 12px; }

.search { display: flex; align-items: center; gap: 8px; background: var(--sheet-2); border: 1px solid var(--rule); border-radius: 8px; padding: 0 10px; color: var(--ink-2); }
.search input { border: 0; background: none; outline: none; padding: 8px 0; width: 100%; color: var(--ink); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--rule); background: none; border-radius: 999px; padding: 3px 11px; font-size: 12px; color: var(--ink-2); }
.chip.is-on { background: var(--ink); border-color: var(--ink); color: var(--sheet); }
.chip .n { font-family: var(--font-mono); font-size: 11px; opacity: .7; margin-left: 3px; }
.hint { margin: 0; font-size: 12px; color: var(--ink-2); }

.lib-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.lib-card {
  display: flex; flex-direction: column; text-align: left; gap: 2px; padding: 6px 6px 8px;
  border: 1px solid var(--rule); background: var(--sheet); border-radius: var(--r); cursor: grab; position: relative; min-width: 0;
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
.lib-card:hover { border-color: var(--accent); }
.lib-card:active { cursor: grabbing; }
.lib-card .thumb { aspect-ratio: 4 / 3; max-width: 100%; border-radius: 5px; background: var(--sheet-2); display: grid; place-items: center; overflow: hidden; }
.lib-card .thumb img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.lib-card .thumb.photo img { object-fit: cover; }
.lib-card .name { font-size: 12.5px; font-weight: 500; padding: 4px 2px 0; line-height: 1.35; min-height: calc(2 * 1.35em + 4px); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.lib-card .size { font-family: var(--font-mono); font-size: 10.5px; color: var(--ink-2); padding: 0 2px; font-variant-numeric: tabular-nums; }
.lib-card .del {
  position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 6px; border: 0;
  background: var(--sheet); color: var(--ink-2); display: none; place-items: center; font-size: 14px; line-height: 1;
}
.lib-card:hover .del { display: grid; }
.lib-card .badge { position: absolute; top: 10px; left: 10px; font-size: 10px; font-weight: 600; background: var(--accent); color: var(--accent-ink); border-radius: 4px; padding: 1px 6px; z-index: 1; letter-spacing: 0.02em; box-shadow: 0 1px 2px rgba(0,0,0,.15); }
.lib-card .badge.brand-badge[data-brand="IKEA"] { background: #0058a3; color: #ffdb00; }
.lib-card .badge.brand-badge[data-brand="宜得利"] { background: #009e96; color: #ffffff; }
.lib-card .badge.brand-badge[data-brand="HOLA"] { background: #6b5344; color: #f7f3eb; }
.lib-card .badge.brand-badge[data-brand="hoi!"] { background: #d47a42; color: #ffffff; }
.lib-card .badge.brand-badge[data-brand="特力屋"] { background: #e65525; color: #ffffff; }
.lib-card .badge.brand-badge[data-brand="全國電子"] { background: #c8102e; color: #ffffff; }
.brand-chips { padding-bottom: 4px; border-bottom: 1px dashed var(--rule); }
.brand-chips .chip.is-on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.empty { font-size: 12.5px; color: var(--ink-2); border: 1px dashed var(--rule); border-radius: var(--r); padding: 14px; grid-column: 1 / -1; }

.block { display: flex; flex-direction: column; gap: 8px; border: 1px solid var(--rule); border-radius: var(--r); padding: 12px; }
.block h3, .block summary { margin: 0; font-size: 13.5px; font-weight: 700; }
.block summary { cursor: pointer; }
details.block[open] summary { margin-bottom: 4px; }
.sub { margin: 0; font-size: 12px; color: var(--ink-2); line-height: 1.55; }
.row { display: flex; gap: 6px; }
.row > input { flex: 1; min-width: 0; }
input[type="url"], input[type="text"], input[type="number"], select, textarea {
  background: var(--sheet); border: 1px solid var(--rule); border-radius: 7px; padding: 7px 9px; width: 100%; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; font-size: 13px; }
.notice { font-size: 12px; line-height: 1.55; background: var(--accent-soft); border-radius: var(--r); padding: 10px 12px; }
.notice.warn { background: var(--danger-soft); }
.bookmarklet {
  align-self: flex-start; text-decoration: none; color: var(--accent-ink); background: var(--accent);
  border-radius: 7px; padding: 6px 12px; font-size: 12.5px; font-weight: 500; cursor: grab;
}
.file-drop { border: 1.5px dashed var(--rule); border-radius: var(--r); padding: 14px; text-align: center; font-size: 12.5px; color: var(--ink-2); cursor: pointer; }
.file-drop:hover, .file-drop.over { border-color: var(--accent); color: var(--accent); }
.file-drop input { display: none; }
.brand-links { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.brand-links a { display: block; text-align: center; text-decoration: none; color: var(--ink); border: 1px solid var(--rule); border-radius: 7px; padding: 6px 4px; font-size: 12.5px; }
.brand-links a:hover { border-color: var(--accent); color: var(--accent); }

.result-head { display: flex; gap: 10px; align-items: flex-start; }
.result-head img { width: 72px; height: 72px; object-fit: cover; border-radius: 6px; background: var(--sheet-2); flex-shrink: 0; }
.result-head .meta { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.result-head .src { font-size: 11px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-head .price { font-family: var(--font-mono); font-size: 12px; }
.tag { display: inline-block; font-size: 10.5px; border-radius: 4px; padding: 0 6px; background: var(--sheet-2); color: var(--ink-2); }
.tag.ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.tag.warn { background: var(--danger-soft); color: var(--danger); }

/* ---------- 屬性面板 ---------- */
.props { padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.props h2 { margin: 0; font-family: var(--font-display); font-size: 18px; font-weight: 700; text-wrap: balance; }
.eyebrow { margin: 0; font-size: 11px; letter-spacing: .12em; color: var(--ink-2); text-transform: uppercase; }
.group { display: flex; flex-direction: column; gap: 8px; }
.group > .label { font-size: 11.5px; letter-spacing: .08em; color: var(--ink-2); }
.dims3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.dims3 label { display: flex; flex-direction: column; gap: 3px; position: relative; min-width: 0; }
.dims3 label span { font-size: 11.5px; color: var(--ink-2); padding-right: 22px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* 單位放在標籤右上角，輸入框整格留給數字，窄面板也不會被截斷 */
.dims3 input { font-family: var(--font-mono); font-variant-numeric: tabular-nums; padding-inline: 8px; font-size: 13.5px; -moz-appearance: textfield; appearance: textfield; }
.dims3 input::-webkit-outer-spin-button, .dims3 input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.dims3 em { position: absolute; right: 2px; top: 1px; font-style: normal; font-size: 10.5px; color: var(--ink-2); pointer-events: none; font-family: var(--font-mono); }
.photo-prev {
  display: grid; place-items: center; border-radius: 6px; padding: 8px; max-height: 170px;
  background: repeating-conic-gradient(var(--sheet-2) 0% 25%, var(--sheet) 0% 50%) 50% / 14px 14px;
  border: 1px solid var(--rule);
}
.photo-prev img { max-width: 100%; max-height: 150px; object-fit: contain; }
.ratio-line { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 11.5px; color: var(--ink-2); }
.ratio-line button { border: 0; background: none; color: var(--accent); font-size: 11.5px; padding: 0; text-decoration: underline; }
.field { display: flex; flex-direction: column; gap: 3px; }
.field > span { font-size: 11.5px; color: var(--ink-2); }
.inline { display: flex; align-items: center; gap: 8px; }
.inline input[type="range"] { flex: 1; accent-color: var(--accent); min-width: 0; }
.readout { font-family: var(--font-mono); font-size: 12.5px; font-variant-numeric: tabular-nums; min-width: 44px; text-align: right; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.sw { width: 26px; height: 26px; border-radius: 50%; border: 1px solid rgba(0,0,0,.12); padding: 0; }
.sw.is-on { outline: 2px solid var(--accent); outline-offset: 2px; }
.sw-custom { width: 30px; height: 30px; border: 0; padding: 0; background: none; }
.skin-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 6px; }
.skin-btn { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 7px 3px; background: var(--sheet-2); border: 1px solid var(--rule); border-radius: 6px; cursor: pointer; font-size: 11px; color: var(--ink); transition: all .15s; }
.skin-btn:hover { background: var(--sheet); border-color: var(--accent); }
.skin-btn.is-on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; box-shadow: 0 0 0 1px var(--accent); }
.skin-btn .skin-icon { font-size: 18px; line-height: 1; }
.skin-upload-row { display: flex; gap: 6px; margin-top: 6px; }
.skin-upload-btn { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 6px 8px; font-size: 12px; border: 1px dashed var(--rule); border-radius: 6px; background: var(--sheet-2); cursor: pointer; color: var(--ink-2); }
.skin-upload-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--sheet); }
.btn-row { display: flex; flex-wrap: wrap; gap: 6px; }
.btn-row .btn { flex: 1; }
.rot-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.rot-row .btn { padding-inline: 4px; }
.toggles { display: flex; flex-direction: column; gap: 2px; }
.toggle { display: flex; align-items: center; justify-content: space-between; padding: 6px 0; font-size: 13px; cursor: pointer; }
.toggle input { appearance: none; width: 34px; height: 20px; border-radius: 999px; background: var(--rule); position: relative; transition: background .15s; cursor: pointer; flex-shrink: 0; }
.toggle input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--sheet); transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.toggle input:checked { background: var(--accent); }
.toggle input:checked::after { transform: translateX(14px); }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px; background: var(--rule); border: 1px solid var(--rule); border-radius: var(--r); overflow: hidden; }
.stats div { background: var(--sheet); padding: 8px 10px; display: flex; flex-direction: column; }
.stats b { font-family: var(--font-mono); font-weight: 500; font-size: 15px; font-variant-numeric: tabular-nums; }
.stats small { font-size: 11px; color: var(--ink-2); }
.warn-line { font-size: 12px; color: var(--danger); background: var(--danger-soft); border-radius: 6px; padding: 6px 10px; }
.item-head { display: flex; gap: 10px; align-items: center; }
.item-head img { width: 54px; height: 44px; object-fit: contain; border-radius: 6px; background: var(--sheet-2); flex-shrink: 0; }
.item-head .name-input { font-family: var(--font-display); font-weight: 700; font-size: 16px; border-color: transparent; padding: 4px 6px; background: none; }
.item-head .name-input:hover { border-color: var(--rule); }
.link { color: var(--accent); font-size: 12px; text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link:hover { text-decoration: underline; }
.list-items { display: flex; flex-direction: column; border: 1px solid var(--rule); border-radius: var(--r); max-height: 220px; overflow-y: auto; }
.list-items button { display: flex; justify-content: space-between; gap: 8px; border: 0; border-bottom: 1px solid var(--rule); background: none; padding: 7px 10px; font-size: 12.5px; text-align: left; }
.list-items button:last-child { border-bottom: 0; }
.list-items button:hover { background: var(--sheet-2); }
.list-items .sz { font-family: var(--font-mono); font-size: 11px; color: var(--ink-2); white-space: nowrap; }
.list-items .bad { color: var(--danger); }

/* ---------- 3D 舞台 ---------- */
.stage { grid-area: stage; position: relative; min-width: 0; overflow: hidden; background: var(--scene); }
.viewport { position: absolute; inset: 0; touch-action: none; }
.viewport canvas { display: block; }
.viewport.grab { cursor: grab; }
.viewport.dragging { cursor: grabbing; }
.hud-tl {
  position: absolute; top: 12px; left: 12px; display: flex; gap: 6px; flex-wrap: wrap; pointer-events: none;
  font-family: var(--font-mono); font-size: 11.5px; font-variant-numeric: tabular-nums;
}
.hud-tl span { background: color-mix(in srgb, var(--sheet) 88%, transparent); border: 1px solid var(--rule); border-radius: 6px; padding: 3px 8px; }
.hud-tl span.bad { color: var(--danger); border-color: var(--danger); }
.eye-hint {
  position: absolute; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: color-mix(in srgb, var(--sheet) 92%, transparent);
  border: 1px solid var(--accent); border-radius: 999px;
  padding: 6px 16px; font-size: 12px; color: var(--ink);
  display: flex; align-items: center; gap: 8px; z-index: 10;
  pointer-events: none; box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}
.eye-hint strong { color: var(--accent); font-weight: 600; }
.eye-hint .icon { font-size: 14px; }
.hud-bl {
  position: absolute; left: 12px; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 11.5px; color: var(--ink-2);
  background: color-mix(in srgb, var(--sheet) 85%, transparent); border-radius: 8px; padding: 6px 10px; pointer-events: none; max-width: calc(100% - 24px);
}
kbd { font-family: var(--font-mono); font-size: 10.5px; border: 1px solid var(--rule); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; margin-right: 3px; background: var(--sheet); color: var(--ink); }
.drop-hint { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--sheet); padding: 5px 12px; border-radius: 999px; font-size: 12px; pointer-events: none; }

/* 3D 尺寸標註 */
.dim-label {
  font-family: var(--font-mono); font-size: 11px; font-variant-numeric: tabular-nums; color: var(--accent);
  background: var(--sheet); border: 1px solid var(--accent); border-radius: 4px; padding: 0 5px; white-space: nowrap; pointer-events: none;
}
.dim-label.room { color: var(--ink-2); border-color: var(--rule); background: color-mix(in srgb, var(--sheet) 85%, transparent); }
.dim-label.bad { color: var(--danger); border-color: var(--danger); }

/* ---------- 對話框與提示 ---------- */
.modal-back {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: color-mix(in srgb, var(--plaster) 55%, transparent); backdrop-filter: blur(3px);
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); padding-block: 16px;
}
.modal { width: min(480px, 100%); background: var(--sheet); border: 1px solid var(--rule); border-radius: 14px; box-shadow: var(--shadow); padding: 24px; display: flex; flex-direction: column; gap: 14px; max-height: 100%; overflow-y: auto; }
.modal.small { width: min(380px, 100%); }
.modal h2 { margin: 0; font-family: var(--font-display); font-size: 22px; text-wrap: balance; }
.modal .dims3 input { font-size: 18px; padding-block: 9px; padding-right: 34px; }
.modal .dims3 em { top: auto; bottom: 12px; right: 10px; font-size: 12px; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; }
.presets button { border: 1px solid var(--rule); background: none; border-radius: 999px; padding: 4px 11px; font-size: 12px; color: var(--ink-2); }
.presets button:hover { border-color: var(--accent); color: var(--accent); }
.area { margin: 0; font-family: var(--font-mono); font-size: 12.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.modal-actions .spacer { flex: 1; }

.toasts { position: fixed; z-index: 60; left: 50%; transform: translateX(-50%); bottom: calc(20px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
.toast { background: var(--ink); color: var(--sheet); border-radius: 8px; padding: 8px 14px; font-size: 13px; box-shadow: var(--shadow); animation: toast-in .2s ease-out; max-width: 90vw; }
.toast.err { background: var(--danger); color: #fff; }
@keyframes toast-in { from { transform: translateY(6px); opacity: .4; } to { transform: none; opacity: 1; } }

.scrim { position: fixed; inset: var(--top-h) 0 0 0; background: rgba(0,0,0,.25); z-index: 19; }
.only-mobile, .only-narrow { display: none !important; }

/* ---------- 響應式 ---------- */
@media (max-width: 1180px) {
  :root { --left-w: 256px; --right-w: 268px; }
  .hide-narrow { display: none !important; }
  .only-narrow { display: block !important; }
  .brand-name { display: none; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "stage"; }
  .only-mobile { display: grid !important; }
  .panel {
    position: fixed; top: var(--top-h); bottom: 0; z-index: 20; width: min(330px, 88vw); box-shadow: var(--shadow);
    transition: transform .22s ease; padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .panel.left { left: 0; transform: translateX(-102%); padding-left: env(safe-area-inset-left, 0px); }
  .panel.right { right: 0; transform: translateX(102%); padding-right: env(safe-area-inset-right, 0px); }
  .panel.open { transform: none; }
  .topbar { gap: 6px; }
  .views { margin-left: auto; }
  .seg { padding: 5px 8px; }
  .tools { margin-left: 0; }
  .tools .divider, #btnUndo, #btnRedo { display: none; }
}
@media (max-width: 520px) {
  .room-chip { display: none; }
  .seg[data-view="front"] { display: none; }
  .brand { display: none; }
  .views { margin-left: 0; flex: 1; }
  .seg { flex: 1; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------- 平面圖匯入精靈 ---------- */
.pw-back {
  position: fixed; inset: 0; z-index: 55; display: grid; place-items: center;
  background: color-mix(in srgb, var(--plaster) 60%, transparent); backdrop-filter: blur(3px);
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-bottom, 0px));
}
.pw {
  width: min(1240px, 100%); height: min(860px, 100%); display: grid; grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--sheet); border: 1px solid var(--rule); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden;
}
.pw-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--rule); }
.pw-head h2 { margin: 0; font-family: var(--font-display); font-size: 19px; }
.pw-body { display: grid; grid-template-columns: minmax(0, 1fr) 340px; min-height: 0; }
.pw-body.empty { grid-template-columns: minmax(0, 1fr); }
.pw-stage { position: relative; min-width: 0; min-height: 0; background: var(--sheet-2); overflow: hidden; }
.pw-stage.over { outline: 2px dashed var(--accent); outline-offset: -8px; }
.pw-stage canvas { position: absolute; inset: 0; display: block; cursor: pointer; }
.pw-stage canvas.measuring { cursor: crosshair; }
.pw-drop {
  position: absolute; inset: 20px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; text-align: center;
  border: 2px dashed var(--rule); border-radius: 12px; cursor: pointer; padding: 24px; color: var(--ink-2);
}
.pw-drop:hover { border-color: var(--accent); color: var(--accent); }
.pw-drop strong { font-size: 16px; color: var(--ink); }
.pw-drop span { max-width: 44ch; font-size: 12.5px; line-height: 1.6; }
.pw-drop input { display: none; }
.pw-tools { position: absolute; top: 8px; left: 8px; right: 8px; display: flex; gap: 8px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.pw-tools .views { margin: 0; }
.pw-tools .btn.is-on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.views.small .seg { padding: 4px 10px; font-size: 12.5px; }
.pw-measure {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); display: flex; flex-wrap: wrap; align-items: center; gap: 8px; justify-content: center;
  background: var(--sheet); border: 1px solid var(--rule); border-radius: 10px; box-shadow: var(--shadow); padding: 8px 12px; font-size: 13px; max-width: calc(100% - 24px);
}
.pw-measure input { width: 110px; }
.pw-busy { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); background: var(--ink); color: var(--sheet); padding: 6px 14px; border-radius: 999px; font-size: 12.5px; }
.pw-side { border-left: 1px solid var(--rule); overflow-y: auto; padding: 14px 16px 18px; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.pw-sec { display: flex; flex-direction: column; gap: 8px; }
.pw-sec h3, .pw-sec summary { margin: 0; font-size: 13.5px; font-weight: 700; }
.pw-sec summary { cursor: pointer; }
details.pw-sec[open] summary { margin-bottom: 4px; }
.pw-sec h3 .n { font-family: var(--font-mono); font-weight: 500; color: var(--ink-2); font-size: 12px; }
.pw-row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.pw-rooms { display: flex; flex-direction: column; border: 1px solid var(--rule); border-radius: var(--r); max-height: 300px; overflow-y: auto; }
.pw-room { display: grid; grid-template-columns: auto auto minmax(0, 1fr) auto auto; align-items: center; gap: 6px; padding: 5px 8px; border-bottom: 1px solid var(--rule); cursor: pointer; }
.pw-room:last-child { border-bottom: 0; }
.pw-room.is-sel { background: var(--accent-soft); }
.pw-room.is-ex { opacity: .55; }
.pw-room .pw-chk { accent-color: var(--accent); width: 15px; height: 15px; }
.pw-dot { width: 22px; height: 22px; border-radius: 6px; display: grid; place-items: center; font-family: var(--font-mono); font-size: 11px; color: #1d2b4a; font-weight: 600; }
.pw-name { padding: 4px 7px !important; font-size: 13px; }
.pw-area { font-family: var(--font-mono); font-size: 11.5px; color: var(--ink-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.pw-ex { border: 0; background: none; color: var(--ink-2); font-size: 12px; padding: 2px 4px; text-decoration: underline; }
.pw-ex:hover { color: var(--danger); }
.pw-foot { display: flex; align-items: center; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--rule); }
.pw-foot #pwStatus { margin-right: auto; }
.dims3.two { grid-template-columns: minmax(0, 160px); }
.field .readout { font-weight: 500; margin-left: 4px; font-size: 11.5px; }
.field input[type="range"] { accent-color: var(--accent); width: 100%; }

/* 3D 房間標籤 */
.room-tag {
  display: flex; flex-direction: column; align-items: center; gap: 0; padding: 3px 9px; border-radius: 8px; cursor: pointer; pointer-events: auto;
  background: color-mix(in srgb, var(--sheet) 90%, transparent); border: 1px solid var(--rule); color: var(--ink); white-space: nowrap;
  font-size: 12.5px; font-weight: 500; line-height: 1.3; box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.room-tag small { font-family: var(--font-mono); font-size: 10.5px; color: var(--ink-2); font-weight: 400; }
.room-tag:hover, .room-tag.is-on { border-color: var(--accent); color: var(--accent); }
.room-row { display: grid !important; grid-template-columns: 12px minmax(0, 1fr) auto; align-items: center; }
.room-row i { width: 10px; height: 10px; border-radius: 3px; display: block; }
.room-row.is-on { background: var(--accent-soft) !important; }
.seg-wide { display: flex; background: var(--sheet-2); border: 1px solid var(--rule); border-radius: 8px; padding: 2px; }
.seg-wide .seg { flex: 1; }

@media (max-width: 860px) {
  .pw-back { padding: 0; }
  .pw { width: 100%; height: 100%; border-radius: 0; border: 0; }
  .pw-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(260px, 46vh) minmax(0, 1fr); }
  .pw-body.empty { grid-template-rows: minmax(0, 1fr); }
  .pw-side { border-left: 0; border-top: 1px solid var(--rule); }
  .pw-foot { flex-wrap: wrap; }
  .pw-foot #pwStatus { flex-basis: 100%; }
}

/* ---------- 我的設計 ---------- */
.modal.wide { width: min(880px, 100%); max-height: calc(100% - 8px); }
.design-badge {
  display: inline-flex; align-items: center; gap: 6px; max-width: 220px; border: 0; background: none; padding: 4px 6px; border-radius: 6px;
  font-size: 13px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.design-badge:hover { background: var(--sheet-2); color: var(--ink); }
.design-badge b { font-weight: 500; color: var(--ink); overflow: hidden; text-overflow: ellipsis; }
.design-badge .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex-shrink: 0; }
.design-badge .dot.saved { background: var(--ok); }
.design-save { display: flex; gap: 8px; flex-wrap: wrap; }
.design-save input { flex: 1 1 200px; min-width: 0; }
.design-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; overflow-y: auto; min-height: 0; padding: 2px; }
.design-card { display: flex; flex-direction: column; border: 1px solid var(--rule); border-radius: var(--r); overflow: hidden; background: var(--sheet); min-width: 0; }
.design-card.is-cur { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.design-card .shot { aspect-ratio: 16 / 10; max-width: 100%; background: var(--sheet-2); display: grid; place-items: center; cursor: pointer; border: 0; padding: 0; position: relative; }
.design-card .shot img { width: 100%; height: 100%; object-fit: cover; display: block; }
.design-card .shot .cur { position: absolute; top: 6px; left: 6px; font-size: 10.5px; background: var(--accent); color: var(--accent-ink); border-radius: 4px; padding: 1px 6px; }
.design-card .body { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 2px; }
.design-card .name { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.design-card .meta { font-size: 11.5px; color: var(--ink-2); }
.design-card .time { font-family: var(--font-mono); font-size: 10.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.design-card .acts { display: flex; gap: 4px; margin-top: 6px; }
.design-card .acts .btn { flex: 1; padding: 4px 6px; font-size: 12px; }
.design-card .acts .btn.danger-text { color: var(--danger); }
.design-empty { grid-column: 1 / -1; border: 1px dashed var(--rule); border-radius: var(--r); padding: 22px; text-align: center; color: var(--ink-2); font-size: 13px; }
.design-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; border-top: 1px solid var(--rule); padding-top: 12px; }
.design-foot .sub { max-width: 52ch; }

/* ---------- 上下移動 ---------- */
.height-tip { position: absolute; pointer-events: none; background: var(--ink); color: var(--sheet); font-family: var(--font-mono); font-size: 11.5px; padding: 2px 8px; border-radius: 6px; z-index: 5; }
.float-btn {
  position: absolute; right: calc(12px + env(safe-area-inset-right, 0px)); bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--rule); background: var(--sheet); color: var(--ink);
  border-radius: 999px; padding: 7px 14px; font-size: 13px; box-shadow: var(--shadow);
}
.float-btn.is-on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.height-row { display: grid; grid-template-columns: 1fr 1fr 1.6fr; }
.height-row .btn { padding-inline: 6px; }

/* ---------- 圖層列：整棟 › 樓層 › 房間 ---------- */
.layer-bar {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 4;
  display: flex; align-items: center; gap: 2px; padding: 3px; border-radius: 10px; max-width: calc(100% - 24px); overflow-x: auto;
  background: color-mix(in srgb, var(--sheet) 92%, transparent); border: 1px solid var(--rule); box-shadow: var(--shadow);
}
.layer-bar .layer { border: 0; background: none; padding: 5px 12px; border-radius: 7px; font-size: 13px; color: var(--ink-2); white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.layer-bar button.layer:hover { background: var(--sheet-2); color: var(--ink); }
.layer-bar .layer.is-on { background: var(--accent); color: var(--accent-ink); font-weight: 500; }
.layer-bar .layer.room { background: var(--accent-soft); color: var(--ink); }
.layer-bar .layer .x { border: 0; background: none; color: inherit; font-size: 15px; line-height: 1; padding: 0 2px; cursor: pointer; }
.layer-bar .sep { color: var(--ink-2); font-size: 12px; padding: 0 2px; }
.floor-tag { font-size: 14px; font-weight: 700; }
@media (max-width: 860px) { .layer-bar { top: 44px; } }

/* 匯入精靈：樓層 */
.pw-tool-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.pw-floors { display: flex; flex-direction: column; border: 1px solid var(--rule); border-radius: var(--r); }
.pw-floor { display: grid; grid-template-columns: 6px minmax(0, 1fr) 92px auto auto; align-items: center; gap: 8px; padding: 6px 8px; border-bottom: 1px solid var(--rule); }
.pw-floor:last-child { border-bottom: 0; }
.pw-floor.is-ex { opacity: .55; }
.pw-fbar { width: 6px; height: 26px; border-radius: 3px; }
.pw-fname { padding: 4px 7px !important; font-size: 13px; font-weight: 600; }
.pw-fh { position: relative; display: block; }
.pw-fh input { width: 100%; padding: 4px 30px 4px 7px !important; font-family: var(--font-mono); font-size: 12.5px; }
.pw-fh em { position: absolute; right: 7px; top: 50%; transform: translateY(-50%); font-style: normal; font-size: 10.5px; color: var(--ink-2); }
.pw-group { padding: 5px 10px; font-size: 11.5px; font-weight: 700; letter-spacing: .06em; color: var(--ink-2); background: var(--sheet-2); border-bottom: 1px solid var(--rule); }
.pw-group.is-ex { text-decoration: line-through; }

/* ---------- 匯入變更設計圖（客變） ---------- */
.rm-sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.rm-nudge { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.rm-nudge .btn { padding: 6px 0; justify-content: center; font-family: var(--font-mono); }
.rm-nudge .btn.ghost { grid-column: span 2; font-family: inherit; }
.rm-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--ink-2); }
.rm-legend i { display: inline-block; width: 16px; height: 8px; border-radius: 2px; margin-right: 6px; vertical-align: 1px; }
.rm-legend i.dash { background: repeating-linear-gradient(135deg, #2f9e4f 0 2px, transparent 2px 5px); border: 1px solid #2f9e4f; }
.pw-sec.is-dim { opacity: .6; }
.rm-note { padding: 8px 10px; border-radius: var(--r); background: var(--accent-soft); color: var(--ink); }
.remodel-box { padding: 10px 12px; border: 1px solid var(--rule); border-radius: var(--r); background: var(--sheet-2); }
.remodel-box .btn.ghost { align-self: flex-start; padding-left: 0; }
#rmSheets:empty { display: none; }
.layer .lv-tag { margin-left: 4px; padding: 0 4px; border-radius: 4px; font-size: 10.5px; font-weight: 700; background: #c8412f; color: #fff; vertical-align: 1px; }
.layer.is-on .lv-tag { background: #fff; color: #c8412f; }

/* 拖曳方向切換：目前的方向反白 */
.float-btn.move-mode { padding: 3px; gap: 2px; }
.float-btn.move-mode .mm { display: inline-flex; align-items: center; gap: 5px; padding: 5px 11px; border-radius: 999px; color: var(--ink-2); }
.float-btn.move-mode .mm.is-on { background: var(--accent); color: var(--accent-ink); }
.float-btn.move-mode.is-on { background: var(--sheet); border-color: var(--rule); color: var(--ink); }
