/* 版面：左邊整片 3D 微縮城市，右邊固定的城堡索引；手機改成上城市、下清單
   刻意只做一種亮色外觀（玩具模型白天的桌面），所有顏色都寫在這裡 */
:root {
  --paper: #fffaf3;
  --card: rgba(255, 250, 243, 0.95);
  --ink: #2b2730;
  --muted: #6c6570;
  --line: #ebdfcd;
  --accent: #e0703a;
  --accent-soft: #fdeadf;
  --teal: #2f7d74;
  --display: "Huninn", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  --body: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  --shadow: 0 6px 22px rgba(70, 50, 30, 0.14);
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--paper); color: var(--ink); font-family: var(--body); font-size: 15px; line-height: 1.65; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; }
a { color: var(--teal); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.eyebrow { font-size: 12px; letter-spacing: 0.12em; color: var(--accent); font-weight: 700; }
h1, h2, h3 { font-family: var(--display); font-weight: 400; margin: 0; line-height: 1.25; text-wrap: balance; }

.app { display: grid; grid-template-columns: minmax(0, 1fr) 400px; height: 100dvh; }
.map { position: relative; overflow: hidden; background: #cfe6ee; container-type: inline-size; }
.map canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.card { background: var(--card); border-radius: 18px; box-shadow: var(--shadow); backdrop-filter: blur(6px); }

/* 左上品牌 */
.topleft { position: absolute; top: max(14px, env(safe-area-inset-top)); left: max(14px, env(safe-area-inset-left)); right: 120px; display: flex; flex-direction: column; align-items: flex-start; gap: 10px; z-index: 5; pointer-events: none; }
.topleft > * { pointer-events: auto; }
.brand { padding: 12px 18px 12px; display: flex; flex-direction: column; gap: 2px; }
.brand h1 { font-size: 26px; color: var(--ink); }
.brand p { margin: 0; font-size: 13px; color: var(--muted); }

/* 工具列 */
.toolbar { display: flex; align-items: center; gap: 2px; padding: 6px; flex-wrap: wrap; max-width: 100%; }
.seg { display: flex; gap: 2px; }
.seg button { border: 0; background: transparent; border-radius: 12px; padding: 6px 9px; font-size: 13px; cursor: pointer; }
.seg button.on { background: var(--ink); color: var(--paper); }
.sep { width: 1px; height: 28px; background: var(--line); margin: 0 4px; }
.tool { border: 0; background: transparent; border-radius: 12px; padding: 4px 8px; display: flex; flex-direction: column; align-items: center; gap: 1px; font-size: 11.5px; cursor: pointer; color: var(--muted); min-width: 48px; }
.tool svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tool.on { color: var(--ink); background: var(--accent-soft); }
.tool:hover, .seg button:hover:not(.on) { background: #f3e9db; }

.viewbar { position: absolute; top: max(14px, env(safe-area-inset-top)); right: 14px; display: flex; gap: 6px; z-index: 5; }
.chipbtn { border: 0; background: var(--card); box-shadow: var(--shadow); border-radius: 12px; padding: 7px 13px; font-size: 13.5px; cursor: pointer; }
.chipbtn.round { width: 36px; padding: 7px 0; }
#vList { display: none; }

.filterbar { position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); padding: 9px 16px; display: flex; gap: 14px; align-items: center; z-index: 5; white-space: nowrap; font-size: 14px; }
.filterbar b { color: var(--accent); font-weight: 700; }
.link { border: 0; background: none; color: var(--teal); text-decoration: underline; cursor: pointer; padding: 0; }

.loading { position: absolute; right: 16px; bottom: 16px; font-size: 12.5px; color: var(--muted); background: var(--card); padding: 5px 12px; border-radius: 99px; z-index: 4; }
.nogl { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; text-align: center; color: var(--muted); }
.nogl p { max-width: 30ch; }

/* 名牌 */
.labels { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.tag { position: absolute; left: 0; top: 0; pointer-events: auto; border: 0; background: rgba(255, 250, 243, 0.92); color: var(--ink); border-radius: 99px; padding: 2px 10px; font-family: var(--display); font-size: 13px; line-height: 1.5; box-shadow: 0 2px 6px rgba(60, 40, 20, 0.18); cursor: pointer; white-space: nowrap; transition: opacity 0.2s, background 0.2s; }
.tag.dim { opacity: 0.28; }
.tag.on { background: var(--ink); color: var(--paper); z-index: 3; }
.tag.cluster { pointer-events: none; display: flex; flex-direction: column; align-items: center; border-radius: 14px; padding: 4px 14px 5px; line-height: 1.3; }
.tag.cluster b { font-weight: 400; font-size: 16px; }
.tag.cluster small { font-family: var(--body); font-size: 11.5px; color: var(--muted); }

/* 詳細卡 */
.detail { position: absolute; left: 14px; top: max(14px, env(safe-area-inset-top)); bottom: 14px; width: min(360px, calc(100% - 28px)); overflow-y: auto; padding: 18px 18px 20px; z-index: 6; display: flex; flex-direction: column; gap: 14px; overscroll-behavior: contain; }
.detail .close { position: sticky; top: 0; align-self: flex-end; margin: -6px -6px -34px 0; border: 0; background: var(--paper); width: 32px; height: 32px; border-radius: 50%; font-size: 20px; line-height: 1; cursor: pointer; z-index: 1; }
.detail h3 { font-size: 26px; }
.detail .titles { color: var(--muted); font-size: 14px; margin-top: 2px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 2px 10px; font-size: 13px; }
button.chip { cursor: pointer; }
button.chip:hover { border-color: var(--accent); }
.chip.hi { background: var(--accent-soft); border-color: transparent; color: #8a3d17; }
.note { background: #fff4d6; border-radius: 12px; padding: 9px 12px; font-size: 14px; }
.sec { display: flex; flex-direction: column; gap: 7px; }
.sec > b { font-size: 12.5px; color: var(--muted); letter-spacing: 0.06em; font-weight: 500; }
.props { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0; list-style: none; }
.props li { display: grid; grid-template-columns: 30px 1fr; gap: 10px; align-items: start; }
.props .ico { width: 30px; height: 30px; border-radius: 9px; background: var(--accent-soft); display: grid; place-items: center; font-family: var(--display); color: #8a3d17; font-size: 15px; }
.props p { margin: 0; font-size: 14px; }
.props p b { font-weight: 700; }
.details { white-space: pre-line; font-size: 14px; margin: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.btn { border: 0; background: var(--ink); color: var(--paper); border-radius: 12px; padding: 9px 16px; font-size: 14px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.btn.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.btn.teal { background: var(--teal); }

/* 日誌 */
.log { position: absolute; right: 14px; bottom: 56px; width: min(300px, calc(100% - 28px)); max-height: 46%; overflow-y: auto; padding: 14px 16px; z-index: 5; font-size: 13.5px; }
.log ol { margin: 8px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }
.log li { display: grid; grid-template-columns: 52px 1fr; gap: 8px; }
.log time { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; padding-top: 2px; }

.settings { position: absolute; right: 14px; bottom: 56px; width: min(280px, calc(100% - 28px)); padding: 14px 16px; z-index: 6; display: flex; flex-direction: column; gap: 10px; font-size: 14px; }
.settings fieldset { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.settings legend { font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.settings label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.settings label small { color: var(--muted); font-size: 12px; margin-left: auto; }
.settings .vol { flex-direction: column; align-items: stretch; gap: 4px; font-size: 12.5px; color: var(--muted); }
.settings input[type=range] { width: 100%; accent-color: var(--accent); }

/* 右側索引 */
.panel { background: var(--paper); border-left: 1px solid var(--line); overflow-y: auto; padding: 22px max(20px, env(safe-area-inset-right)) 28px 20px; display: flex; flex-direction: column; gap: 16px; }
.panel-head h2 { font-size: 28px; margin-top: 4px; }
.stats { margin: 6px 0 0; color: var(--muted); font-size: 13.5px; font-variant-numeric: tabular-nums; }
.quizcard { text-align: left; border: 1px solid #f3cdb5; background: var(--accent-soft); border-radius: 16px; padding: 12px 40px 12px 14px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; position: relative; }
.quizcard::after { content: "›"; position: absolute; right: 16px; top: 50%; transform: translateY(-50%); font-size: 22px; color: var(--accent); }
.quizcard b { font-family: var(--display); font-weight: 400; font-size: 17px; }
.quizcard span { font-size: 13px; color: var(--muted); }
.search input { width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 14px; padding: 10px 14px; font: inherit; color: var(--ink); }
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; background: #f4ebde; border-radius: 14px; padding: 4px; }
.tab { border: 0; background: transparent; border-radius: 10px; padding: 7px 0; font-size: 13.5px; cursor: pointer; }
.tab.on { background: var(--ink); color: var(--paper); }
.list { display: flex; flex-direction: column; }
.group { border-bottom: 1px solid var(--line); }
.group > button { width: 100%; border: 0; background: none; display: flex; align-items: baseline; gap: 10px; padding: 11px 2px; cursor: pointer; text-align: left; }
.group > button .n { font-family: var(--display); color: var(--accent); font-size: 20px; min-width: 1.6em; font-variant-numeric: tabular-nums; }
.group > button .t { flex: 1; font-size: 15px; }
.group > button .c { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.group.on > button { color: var(--accent); }
.group .body { padding: 0 0 12px 2px; display: flex; flex-direction: column; gap: 6px; }
.group .sub { display: flex; flex-wrap: wrap; gap: 6px; }
.sub button.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.people { display: flex; flex-direction: column; gap: 2px; margin-top: 4px; }
.person { border: 0; background: none; text-align: left; padding: 7px 8px; border-radius: 10px; cursor: pointer; display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; align-items: baseline; }
.person:hover, .person.on { background: #f4ebde; }
.person b { font-family: var(--display); font-weight: 400; font-size: 16px; }
.person span { color: var(--muted); font-size: 12.5px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 4px; vertical-align: -1px; }
.legend-item { display: grid; grid-template-columns: 30px 1fr; gap: 10px; padding: 10px 2px; border-bottom: 1px solid var(--line); font-size: 14px; }
.legend-item p { margin: 0; }
.legend-item .who { color: var(--muted); font-size: 12.5px; }
.empty { color: var(--muted); padding: 12px 2px; }
.panel-foot { margin-top: auto; font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; border-top: 1px solid var(--line); padding-top: 14px; }
.panel-foot p { margin: 0; }
.credits { font-size: 12px; }

/* 導覽 */
.tour { position: fixed; inset: 0; background: rgba(43, 39, 48, 0.28); display: grid; place-items: center; z-index: 50; padding: 16px; }
.tour-card { max-width: 380px; padding: 20px 22px; display: flex; flex-direction: column; gap: 8px; background: var(--paper); }
.tour-card h3 { font-size: 24px; }
.tour-card p { margin: 0; color: var(--muted); }
.tour-actions { display: flex; justify-content: space-between; margin-top: 8px; }

/* 小測驗 */
.quiz { border: 0; border-radius: 20px; padding: 0; width: min(520px, calc(100% - 24px)); max-height: calc(100dvh - 24px); background: var(--paper); color: var(--ink); box-shadow: var(--shadow); }
.quiz::backdrop { background: rgba(43, 39, 48, 0.35); }
.quiz-inner { padding: 20px 22px; display: flex; flex-direction: column; gap: 14px; }
.quiz header { position: relative; padding-right: 36px; }
.quiz h3 { font-size: 24px; margin-top: 4px; }
.quiz .x { position: absolute; right: -6px; top: -6px; border: 0; background: none; font-size: 26px; cursor: pointer; width: 36px; height: 36px; }
.quiz-options { display: flex; flex-direction: column; gap: 8px; }
.quiz-options button { text-align: left; border: 1px solid var(--line); background: #fff; border-radius: 14px; padding: 11px 14px; cursor: pointer; font-size: 15px; }
.quiz-options button:hover { border-color: var(--accent); background: var(--accent-soft); }
.quiz footer { display: flex; align-items: center; gap: 12px; }
.fine { font-size: 12.5px; color: var(--muted); margin: 0; }
.quiz-result { display: flex; flex-direction: column; gap: 10px; }
.quiz-result .person { background: #fff; border: 1px solid var(--line); }

@media (max-width: 860px) {
  .app { display: block; height: auto; }
  .map { height: 64svh; min-height: 420px; position: sticky; top: 0; z-index: 1; }
  /* 詳細卡是 .map 裡的固定定位元素，要讓 .map 整層蓋過下面的清單 */
  .map:has(.detail:not([hidden])), .map:has(.settings:not([hidden])), .map:has(.log:not([hidden])) { z-index: 3; }
  .panel { border-left: 0; border-top: 1px solid var(--line); position: relative; z-index: 2; padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  .topleft { display: contents; }
  .brand { position: absolute; top: max(10px, env(safe-area-inset-top)); left: max(10px, env(safe-area-inset-left)); z-index: 5; padding: 8px 12px; }
  .brand h1 { font-size: 19px; }
  .brand h1 br { display: none; }
  .brand p { display: none; }
  .toolbar { position: absolute; bottom: 10px; left: 10px; right: 10px; z-index: 5; justify-content: center; padding: 4px; }
  .tool { min-width: 40px; padding: 3px 4px; font-size: 10.5px; }
  .seg button { padding: 5px 6px; font-size: 12px; }
  .viewbar { top: auto; bottom: 74px; right: 10px; }
  #vList { display: inline-block; }
  .filterbar { top: 64px; bottom: auto; font-size: 13px; }
  .detail { position: fixed; left: 0; right: 0; top: auto; bottom: 0; width: auto; max-height: 55svh; border-radius: 20px 20px 0 0; box-shadow: 0 -6px 24px rgba(70, 50, 30, 0.18); padding-bottom: max(20px, env(safe-area-inset-bottom)); padding-left: max(18px, env(safe-area-inset-left)); padding-right: max(18px, env(safe-area-inset-right)); z-index: 30; }
  .log, .settings { bottom: 120px; }
  .loading { bottom: 74px; left: 10px; right: auto; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@container (max-width: 680px) {
  .tool span { display: none; }
  .tool { min-width: 34px; padding: 6px; }
  .toolbar { flex-wrap: nowrap; overflow-x: auto; justify-content: flex-start; scrollbar-width: none; }
  .toolbar::-webkit-scrollbar { display: none; }
  .toolbar > * { flex: none; }
  .seg button { white-space: nowrap; }
  .tag.cluster { padding: 2px 10px; }
  .tag.cluster b { font-size: 13px; }
  .tag.cluster small { display: none; }
}

/* 收起鍵：品牌卡、工具列、城堡索引都可以收起來，狀態記在這台裝置 */
.fold { border: 0; background: transparent; color: var(--muted); width: 30px; height: 30px; border-radius: 10px; display: inline-grid; place-items: center; cursor: pointer; flex: none; }
.fold:hover { background: #f3e9db; color: var(--ink); }
.fold svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: transform 0.2s; }
.brand { padding-right: 40px; }
@media (min-width: 861px) { .brand { position: relative; } }
.brand .fold { position: absolute; top: 6px; right: 6px; }
.brand.min { padding: 6px 40px 6px 14px; }
.brand.min .eyebrow, .brand.min > p { display: none; }
.brand.min h1 { font-size: 15px; }
.brand.min h1 br { display: none; }
.brand.min .fold svg { transform: rotate(180deg); }
.tool-fold { height: auto; width: auto; min-width: 30px; padding: 6px 4px; gap: 2px; }
.fold-label { display: none; font-size: 12px; }
.toolbar.min > :not(.tool-fold) { display: none; }
.toolbar.min .tool-fold { padding: 6px 10px; display: inline-flex; align-items: center; gap: 4px; color: var(--ink); }
.toolbar.min .fold-label { display: inline; }
.toolbar.min .tool-fold svg { transform: rotate(180deg); }
.panel-head { position: relative; padding-right: 36px; }
.panel-head .fold { position: absolute; top: -4px; right: 0; }
.app.panel-min { grid-template-columns: minmax(0, 1fr) 0; }
.app.panel-min .panel { display: none; }
@media (max-width: 860px) {
  /* 手機：索引在地圖下方，收起時只留搜尋、分頁和清單 */
  .app.panel-min .panel { display: flex; }
  .app.panel-min .panel-head h2, .app.panel-min .panel-head .stats, .app.panel-min .quizcard { display: none; }
  .app.panel-min .panel-head { min-height: 26px; }
  .panel-head .fold svg { transform: rotate(-90deg); }
  .app.panel-min .panel-head .fold svg { transform: rotate(90deg); }
  .toolbar.min { right: auto; }
}
