:root {
  --paper: #F3EEE6;
  --paper-2: #E7DED1;
  --surface: rgba(250, 247, 242, .86);
  --ink: #2A2320;
  --ink-2: #5C5048;
  --walnut: #5B4334;
  --bronze: #8A5A2E;
  --bronze-soft: #C49A6C;
  --sage: #66765F;
  --line: rgba(42, 35, 32, .14);
  --shadow: 0 10px 30px -12px rgba(60, 40, 25, .35);
  --night: #171310;
  --r: 14px;
  --ease: cubic-bezier(.2, .7, .2, 1);
  --serif: "Noto Serif TC", "Songti TC", serif;
  --sans: "Noto Sans TC", "PingFang TC", system-ui, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 400 16px/1.6 var(--sans);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.btn.primary svg { fill: currentColor; stroke: none; }
:focus-visible { outline: 2px solid var(--bronze); outline-offset: 3px; border-radius: 8px; }

.skip { position: absolute; left: -999px; top: 8px; z-index: 100; background: var(--ink); color: var(--paper); padding: 8px 14px; border-radius: 8px; }
.skip:focus { left: 16px; }

#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#labels { position: fixed; inset: 0; pointer-events: none; z-index: 5; }

/* ---------- 頂部 ---------- */
.top {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 20px 28px;
  pointer-events: none;
}
.top > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 12px; color: var(--walnut); }
.brand-en { margin: 0; font: 500 11px/1 var(--sans); letter-spacing: .32em; color: var(--bronze); }
.brand h1 { margin: 4px 0 0; font: 700 20px/1.2 var(--serif); letter-spacing: .08em; color: var(--ink); }
.actions { display: flex; gap: 10px; }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 999px;
  border: 1px solid var(--line); cursor: pointer;
  font-size: 15px; font-weight: 500; letter-spacing: .04em;
  transition: background .2s var(--ease), color .2s var(--ease), border-color .2s var(--ease), transform .15s var(--ease);
}
.btn:active { transform: scale(.97); }
.btn.ghost { background: var(--surface); backdrop-filter: blur(10px); }
.btn.ghost:hover { border-color: var(--bronze-soft); }
.btn.primary { background: var(--walnut); color: #FBF7F1; border-color: var(--walnut); }
.btn.primary:hover { background: #4A3629; }
.btn.primary[aria-pressed="true"] { background: var(--bronze); border-color: var(--bronze); }

/* ---------- 樓層選單 ---------- */
.floor-nav {
  position: fixed; left: 28px; top: 50%; transform: translateY(-50%); z-index: 10;
  padding: 14px 10px; border-radius: 20px;
  background: var(--surface); backdrop-filter: blur(12px);
  border: 1px solid var(--line); box-shadow: var(--shadow);
}
.nav-cap { margin: 0 0 6px; text-align: center; font-size: 12px; letter-spacing: .3em; color: var(--ink-2); }
.floor-nav ol { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.floor-btn {
  position: relative; display: grid; grid-template-columns: 44px 1fr; align-items: center; gap: 4px;
  width: 168px; min-height: 48px; padding: 4px 12px 4px 4px;
  border: 0; border-radius: 12px; background: transparent; cursor: pointer; text-align: left;
  transition: background .2s var(--ease);
}
.floor-btn:hover { background: rgba(138, 90, 46, .08); }
.floor-btn .fid { font: 700 18px/1 var(--serif); text-align: center; color: var(--walnut); }
.floor-btn .fname { font-size: 14px; line-height: 1.3; color: var(--ink); }
.floor-btn .fname small { display: block; font-size: 12px; color: var(--ink-2); }
.floor-btn[aria-current="true"] { background: var(--walnut); }
.floor-btn[aria-current="true"] .fid,
.floor-btn[aria-current="true"] .fname,
.floor-btn[aria-current="true"] .fname small { color: #FBF7F1; }

/* ---------- 側欄 ---------- */
.panel {
  position: fixed; right: 28px; top: 96px; bottom: 28px; z-index: 10;
  width: 340px; display: flex; flex-direction: column;
  background: var(--surface); backdrop-filter: blur(14px);
  border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow);
  overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; cursor: pointer;
  padding: 22px 18px 14px 22px; border: 0; border-bottom: 1px solid var(--line); background: none;
}
.panel-headtext { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.panel-kicker { font-size: 12px; letter-spacing: .28em; color: var(--bronze); }
.panel-title { margin: 6px 0 2px; font: 700 26px/1.25 var(--serif); }
.panel-sub { font-size: 14px; color: var(--ink-2); }
.panel-chev {
  display: grid; place-items: center; flex: 0 0 auto; width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid var(--line); color: var(--walnut); transition: transform .3s var(--ease), background .2s;
}
.panel-head:hover .panel-chev { background: rgba(138, 90, 46, .08); }
.panel:not(.is-collapsed) .panel-chev { transform: rotate(180deg); }
.panel.is-collapsed { bottom: auto; }
.panel.is-collapsed .panel-head { border-bottom: 0; padding-bottom: 18px; }
.panel.is-collapsed .space-list { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.space-list { list-style: none; margin: 0; padding: 10px; overflow-y: auto; flex: 1; }
.space-btn {
  display: grid; grid-template-columns: 96px 1fr; gap: 12px; align-items: center;
  width: 100%; padding: 8px; border: 0; border-radius: 12px; background: transparent; cursor: pointer; text-align: left;
  transition: background .2s var(--ease);
}
.space-btn:hover, .space-btn.is-hot { background: rgba(138, 90, 46, .09); }
.space-thumb { position: relative; display: block; }
.space-btn img { width: 96px; height: 60px; object-fit: cover; border-radius: 8px; background: var(--paper-2); display: block; }
.space-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.space-btn .st { font-weight: 500; font-size: 15px; line-height: 1.35; }
.space-btn .sc { font-size: 13px; color: var(--ink-2); }

/* 編號圓圈：清單、導覽卡、3D 熱點共用同一種樣式 */
.num, .pin .dot {
  display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%;
  background: var(--bronze); color: #fff; font: 700 14px/1 var(--sans); font-variant-numeric: tabular-nums;
  box-shadow: 0 0 0 3px rgba(250, 247, 242, .92), 0 4px 10px -4px rgba(60, 40, 25, .5);
}
.space-thumb .num, .tour-thumb .num { position: absolute; top: -6px; left: -6px; }
.space-btn.is-hot .num { background: var(--walnut); }
/* 從地圖點數字選取後的標示 */
.space-btn.is-selected { background: rgba(138, 90, 46, .12); }
.space-btn.is-selected img { outline: 2px solid var(--bronze); outline-offset: 2px; }
.space-btn.is-selected .num, .pin.is-selected .dot { background: var(--walnut); }
.space-thumb::after {
  content: "點照片看大圖"; position: absolute; right: 6px; bottom: 6px; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; color: #fff; background: rgba(42, 35, 32, .72); opacity: 0; transition: opacity .2s var(--ease);
}
.space-btn.is-selected .space-thumb::after { opacity: 1; }
.pin.is-selected .dot { transform: scale(1.18); }
.pin.is-selected .lbl { opacity: 1; transform: translate(-50%, 0); }
.pin.is-selected { z-index: 3; }

.hint {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 9; margin: 0;
  padding: 8px 16px; border-radius: 999px; font-size: 13px; letter-spacing: .06em; color: var(--ink-2);
  background: var(--surface); border: 1px solid var(--line);
}

/* ---------- 3D 標籤 ---------- */
.tag {
  position: absolute; left: 0; top: 0; pointer-events: auto; cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px; white-space: nowrap;
  min-height: 36px; padding: 0 14px 0 6px; border-radius: 999px;
  background: rgba(250, 247, 242, .92); border: 1px solid var(--line); box-shadow: var(--shadow);
  font-size: 14px; color: var(--ink); will-change: transform, opacity;
  transition: border-color .2s var(--ease), background .2s var(--ease);
}
.tag .tid { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--walnut); color: #FBF7F1; font: 700 12px/1 var(--serif); }
.tag:hover, .tag.is-hot { border-color: var(--bronze); background: #fff; }
.tag.floor-tag .tid { width: auto; padding: 0 8px; border-radius: 999px; }

.pin {
  position: absolute; left: 0; top: 0; pointer-events: auto; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: none; border: 0; padding: 0; will-change: transform, opacity;
}
.pin .dot { width: 30px; height: 30px; transition: transform .2s var(--ease); }
.pin .lbl {
  position: absolute; top: calc(100% + 8px); left: 50%; transform: translate(-50%, -4px);
  padding: 5px 12px; border-radius: 999px; font-size: 13px; font-weight: 500; white-space: nowrap;
  background: rgba(250, 247, 242, .97); border: 1px solid var(--line); box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity .2s var(--ease), transform .2s var(--ease);
}
/* 名稱只在滑過／選取時出現，避免標籤互相重疊；平時以圓圈數字對應右側清單 */
.pin:hover .lbl, .pin:focus-visible .lbl, .pin.is-hot .lbl { opacity: 1; transform: translate(-50%, 0); }
.pin:hover, .pin:focus-visible, .pin.is-hot { z-index: 2; }
.pin:hover .dot, .pin.is-hot .dot { transform: scale(1.15); }
.pin:hover .lbl, .pin.is-hot .lbl { border-color: var(--bronze); }

/* ---------- 導覽卡 ---------- */
.tour-card {
  position: fixed; left: 50%; bottom: 72px; transform: translateX(-50%); z-index: 12;
  display: grid; grid-template-columns: 180px 1fr; gap: 16px; align-items: center;
  width: min(520px, calc(100vw - 32px)); padding: 10px 18px 10px 10px; border-radius: 18px;
  background: var(--surface); backdrop-filter: blur(14px); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.tour-thumb { position: relative; display: block; }
.tour-card img { width: 180px; height: 104px; object-fit: cover; border-radius: 10px; display: block; }
.tour-step { margin: 0; font-size: 12px; letter-spacing: .2em; color: var(--bronze); }
.tour-title { margin: 2px 0 6px; font: 700 18px/1.35 var(--serif); }
.link { background: none; border: 0; padding: 6px 0; color: var(--walnut); font-size: 14px; font-weight: 500; cursor: pointer; text-decoration: underline; text-underline-offset: 4px; }

/* ---------- 模擬圖檢視器 ---------- */
.viewer { position: fixed; inset: 0; z-index: 50; background: var(--night); color: #F4EEE6; }
#viewer-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: pan-y; }
.viewer-top {
  position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 16px;
  padding: 18px 24px; background: linear-gradient(rgba(23, 19, 16, .85), rgba(23, 19, 16, 0));
}
.viewer-top > div { flex: 1; min-width: 0; }
.viewer-kicker { margin: 0; font-size: 12px; letter-spacing: .28em; color: var(--bronze-soft); }
.viewer-top h2 { margin: 4px 0 0; font: 700 22px/1.3 var(--serif); }
.viewer-count { margin: 0; font-variant-numeric: tabular-nums; letter-spacing: .1em; color: #CFC4B6; }
.icon-btn {
  display: grid; place-items: center; width: 48px; height: 48px; border-radius: 50%;
  background: rgba(244, 238, 230, .12); border: 1px solid rgba(244, 238, 230, .22); cursor: pointer; color: #F4EEE6;
  transition: background .2s var(--ease);
}
.icon-btn:hover { background: rgba(244, 238, 230, .24); }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn.nav { position: absolute; top: 50%; transform: translateY(-50%); }
.icon-btn.prev { left: 20px; }
.icon-btn.next { right: 20px; }
.thumbs {
  position: absolute; left: 0; right: 0; bottom: 0; display: flex; gap: 8px; overflow-x: auto;
  padding: 14px 24px 18px; background: linear-gradient(rgba(23, 19, 16, 0), rgba(23, 19, 16, .9));
  scrollbar-width: thin;
}
.thumbs button { flex: 0 0 auto; padding: 0; border: 2px solid transparent; border-radius: 8px; background: #2A231E; cursor: pointer; opacity: .6; transition: opacity .2s, border-color .2s; }
.thumbs button img { display: block; width: 112px; height: 63px; object-fit: cover; border-radius: 6px; }
.thumbs button:hover { opacity: .9; }
.thumbs button[aria-current="true"] { opacity: 1; border-color: var(--bronze-soft); }

/* ---------- 載入 ---------- */
.loader {
  position: fixed; inset: 0; z-index: 80; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  background: var(--paper);
}
.loader-en { margin: 0; letter-spacing: .5em; font-size: 12px; color: var(--bronze); }
.loader-zh { margin: 0 0 18px; font: 700 26px/1.3 var(--serif); letter-spacing: .12em; }
.bar { width: 220px; height: 2px; background: var(--line); overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; background: var(--walnut); transition: width .3s var(--ease); }
.loader-pct { margin: 6px 0 0; font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.noscript { position: fixed; inset: 0; display: grid; place-items: center; background: var(--paper); margin: 0; }

[hidden] { display: none !important; }

/* ---------- 小螢幕 ----------
   版面由上而下：頂部列 → 樓層列 → 3D 可視區 → 空間卡片列 → 底部保留區
   底部保留 76px：Netlify 自動插入的徽章（右下角 iframe）會蓋在這裡 */
@media (max-width: 860px) {
  :root { --safe-b: calc(76px + env(safe-area-inset-bottom, 0px)); }
  .top { padding: 12px 16px; }
  .brand h1 { font-size: 17px; }
  .btn { width: 44px; padding: 0; justify-content: center; }
  .btn span { display: none; }

  .floor-nav { left: 16px; right: 16px; top: 68px; bottom: auto; transform: none; padding: 4px; border-radius: 14px; }
  .nav-cap { display: none; }
  .floor-nav ol { flex-direction: row; gap: 2px; }
  .floor-nav li { flex: 1; }
  .floor-btn { width: 100%; grid-template-columns: 1fr; justify-items: center; padding: 0; min-height: 44px; }
  .floor-btn .fid { font-size: 16px; }
  .floor-btn .fname { display: none; }

  .panel { left: 12px; right: 12px; top: auto; bottom: var(--safe-b); width: auto; max-height: none; border-radius: 18px; }
  .panel.is-collapsed { bottom: var(--safe-b); }
  .panel-head { padding: 8px 10px 8px 16px; border-bottom: 0; min-height: 52px; }
  .panel.is-collapsed .panel-head { padding-bottom: 8px; }
  .panel-headtext { flex-direction: row; flex-wrap: wrap; align-items: baseline; column-gap: 8px; }
  .panel-kicker { font-size: 11px; letter-spacing: .2em; }
  .panel-title { margin: 0; font-size: 16px; order: -1; }
  .panel-sub { width: 100%; font-size: 12px; }
  .panel-chev { width: 36px; height: 36px; }
  .space-list {
    display: flex; gap: 12px; overflow-x: auto; overflow-y: hidden; padding: 10px 16px 14px;
    scroll-snap-type: x mandatory; scroll-padding-left: 16px; overscroll-behavior-x: contain; scrollbar-width: none;
  }
  .space-list::-webkit-scrollbar { display: none; }
  .space-list li { flex: 0 0 136px; scroll-snap-align: start; }
  .space-btn { grid-template-columns: 1fr; gap: 6px; padding: 0; background: none; }
  .space-btn:hover, .space-btn.is-hot, .space-btn.is-selected { background: none; }
  .space-btn.is-hot img { outline: 2px solid var(--bronze); outline-offset: 2px; }
  .space-btn img { width: 136px; height: 78px; }
  .space-thumb .num { top: 6px; left: 6px; }
  .space-btn .st { font-size: 13px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .space-btn .sc { font-size: 12px; }

  .hint { display: none; }
  .pin .dot { width: 34px; height: 34px; font-size: 15px; }

  .tour-card { top: 124px; bottom: auto; grid-template-columns: 112px 1fr; gap: 12px; }
  .tour-card img { width: 112px; height: 64px; }
  .tour-title { font-size: 16px; }

  .viewer-top { padding: 14px 16px; }
  .viewer-top h2 { font-size: 18px; }
  .thumbs { padding: 12px 16px var(--safe-b); }
  .thumbs button img { width: 96px; height: 54px; }
  .icon-btn.nav { top: auto; bottom: calc(var(--safe-b) + 80px); transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0s !important; }
}

/* ---------- v2：版本標籤、區域色彩圖例 ---------- */
.brand h1 .ver { display: inline-block; margin-left: 6px; padding: 2px 8px; border-radius: 999px; vertical-align: 3px;
  font: 500 11px/1.4 var(--sans); letter-spacing: .08em; color: var(--bronze); border: 1px solid var(--bronze-soft); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 10px; padding: 12px 18px 16px; border-top: 1px solid var(--line); }
.legend-cap { width: 100%; margin: 0 0 2px; font-size: 12px; letter-spacing: .2em; color: var(--ink-2); }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink); }
.chip i { width: 14px; height: 14px; border-radius: 4px; border: 1px solid rgba(58, 46, 39, .3); }
.panel.is-collapsed .legend { display: none; }
@media (max-width: 860px) {
  .brand h1 .ver { display: none; }
  .legend { padding: 4px 16px 12px; gap: 4px 8px; }
  .legend-cap { display: none; }
  .chip { font-size: 11px; }
}

/* 右下角 Netlify 徽章（自動插入、無法移除）會蓋住縮圖列尾端：桌機版右側預留空間 */
@media (min-width: 861px) { .thumbs { padding-right: 210px; } }
