/* 山海經現實映射 Web App — 紙本風格 */
:root {
  --paper: #f7f3e8;
  --paper-2: #efe9d8;
  --ink: #2b2620;
  --ink-soft: #5d564a;
  --line: #d8cfba;
  --west: #6c3483;
  --center: #c0392b;
  --north: #a07d1e;
  --east: #1e8449;
  --south: #2e86c1;
  --accent: #7d6608;
  --serif: "Songti TC", "Songti SC", "Noto Serif CJK TC", "PMingLiU", serif;
  --sans: -apple-system, "PingFang TC", "PingFang SC", "Hiragino Sans GB", "Microsoft JhengHei", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.75;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
a { color: #1a5276; text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }

/* ── 頁首 / 頁腳 ─────────────────────────── */
.site-header {
  display: flex; align-items: center; flex-wrap: wrap; gap: 4px 18px;
  padding: 10px 22px;
  background: var(--paper-2);
  border-bottom: 1px solid var(--line);
}
.site-title { font-family: var(--serif); font-size: 20px; font-weight: 700; letter-spacing: 2px; }
.site-title a { color: var(--ink); }
.site-title .sub { font-size: 12px; color: var(--ink-soft); font-family: var(--sans); letter-spacing: 0; margin-left: 8px; }
.site-nav { display: flex; gap: 14px; flex-wrap: wrap; margin-left: auto; }
.site-nav a { color: var(--ink-soft); padding: 2px 6px; border-radius: 4px; }
.site-nav a.active { color: var(--paper); background: var(--accent); text-decoration: none; }
.site-nav a:hover { color: var(--ink); text-decoration: none; }
.site-nav a.active:hover { color: var(--paper); }

.site-footer {
  margin-top: auto;
  padding: 12px 22px;
  border-top: 1px solid var(--line);
  background: var(--paper-2);
  font-size: 13px;
  color: var(--ink-soft);
  text-align: center;
}
.site-footer .honesty { font-weight: 600; color: #6e2c00; }

main { flex: 1; padding: 18px 22px; max-width: 1180px; width: 100%; margin: 0 auto; }
main.full { max-width: none; padding: 0; }

/* ── 首頁地圖 ────────────────────────────── */
.map-wrap { position: relative; width: 100%; height: calc(100vh - 120px); min-height: 420px; background: #eef4f6; overflow: hidden; }
.map-wrap svg { display: block; width: 100%; height: 100%; cursor: grab; user-select: none; touch-action: none; }
.map-wrap svg.dragging { cursor: grabbing; }
.map-loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--ink-soft); }

.layer-panel {
  position: absolute; top: 12px; left: 12px; z-index: 5;
  background: rgba(247, 243, 232, 0.94);
  border: 1px solid var(--line); border-radius: 6px;
  padding: 8px 12px; font-size: 13px; line-height: 1.6;
  box-shadow: 0 1px 4px rgba(0,0,0,0.12);
}
.layer-panel .lp-title { font-weight: 700; margin-bottom: 2px; }
.layer-panel label { display: block; white-space: nowrap; cursor: pointer; }

.map-legend {
  position: absolute; left: 12px; bottom: 12px; z-index: 5;
  background: rgba(247, 243, 232, 0.94);
  border: 1px solid var(--line); border-radius: 6px;
  padding: 8px 12px; font-size: 12px; line-height: 1.7;
  max-width: 300px;
}
.map-legend .swatch { display: inline-block; width: 18px; height: 4px; vertical-align: middle; margin-right: 6px; border-radius: 2px; }
.map-legend .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; vertical-align: middle; margin-right: 6px; }
.map-legend .sq { display: inline-block; width: 9px; height: 9px; border: 1.5px dashed #c0392b; vertical-align: middle; margin-right: 6px; }

.map-tooltip {
  position: absolute; z-index: 8; pointer-events: none;
  background: rgba(43, 38, 32, 0.92); color: #f7f3e8;
  font-size: 12px; padding: 4px 8px; border-radius: 4px;
  max-width: 320px; display: none;
}

/* 首次訪客引導條 */
.map-hint {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 6;
  background: rgba(43, 38, 32, 0.88); color: #f7f3e8;
  font-size: 13px; padding: 7px 14px; border-radius: 6px;
  max-width: min(560px, 82vw); text-align: center; cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

/* 地圖 SVG 元素 */
.shj-label { font-family: var(--sans); fill: var(--ink-soft); pointer-events: none; }
.shj-chain-label { font-weight: 700; paint-order: stroke; stroke: #f7f3e8; stroke-width: 3px; vector-effect: non-scaling-stroke; }
.shj-station { cursor: pointer; }
.shj-station:hover { stroke: #000; stroke-width: 1.2; vector-effect: non-scaling-stroke; }
.shj-point { cursor: pointer; }
.shj-point:hover { stroke: #000; stroke-width: 1.2; vector-effect: non-scaling-stroke; }

/* ── 詳情卡（右側欄 / 移動端底部抽屜）────────── */
.detail-card {
  position: fixed; top: 0; right: 0; z-index: 40;
  width: 460px; max-width: 92vw; height: 100vh;
  background: var(--paper);
  border-left: 1px solid var(--line);
  box-shadow: -4px 0 18px rgba(0,0,0,0.18);
  overflow-y: auto; padding: 16px 20px 60px;
  transform: translateX(105%);
  transition: transform 0.25s ease;
}
.detail-card.open { transform: translateX(0); }
.detail-close {
  position: sticky; top: 0; float: right;
  background: var(--paper-2); border: 1px solid var(--line); border-radius: 4px;
  font-size: 14px; padding: 2px 10px; cursor: pointer; z-index: 2;
}
.detail-card h3 { font-family: var(--serif); margin: 6px 0 4px; line-height: 1.4; }
.detail-meta { font-size: 12px; color: var(--ink-soft); margin-bottom: 10px; }

/* ── 徽章與標記 ─────────────────────────── */
.badge {
  display: inline-block; font-size: 12px; line-height: 1.5;
  padding: 1px 8px; border-radius: 10px; border: 1px solid;
  margin: 1px 3px 1px 0; white-space: nowrap;
}
.badge.good  { background: #e8f6ee; border-color: #1e8449; color: #145a32; }
.badge.ok    { background: #fef9e7; border-color: #b7950b; color: #7d6608; }
.badge.dir   { background: #fdf2e9; border-color: #ca6f1e; color: #873600; }
.badge.na    { background: #f2f3f4; border-color: #909497; color: #515a5a; }
.badge.myth  { background: #eaf2f8; border-color: #5d6d7e; color: #33475b; font-style: italic; }
.badge.review { background: #f5eef8; border-color: #6c3483; color: #4a235a; }
.badge.anchor { background: #eaf2f8; border-color: #2e86c1; color: #1a5276; }
.badge.region { background: #fef9e7; border-color: #b7950b; color: #7d6608; }
.badge.pending { background: #fdedec; border-color: #c0392b; color: #922b21; }
.badge.warn  { background: #f5eef8; border-color: #6c3483; color: #4a235a; }

/* 借名警示：紫斜紋框 */
.borrowed-warning {
  border: 2px solid #6c3483;
  background: repeating-linear-gradient(-45deg, #f5eef8, #f5eef8 10px, #ead8f0 10px, #ead8f0 20px);
  border-radius: 6px; padding: 8px 14px; margin: 10px 0; font-size: 13px;
  color: #4a235a;
}
/* 神話層：灰藍斜體標籤 */
.myth-note {
  border-left: 4px solid #5d6d7e; background: #eaf2f8;
  padding: 6px 12px; margin: 10px 0; font-size: 13px; font-style: italic; color: #33475b;
}

/* ── 條目正文（markdown 渲染）────────────── */
.entry-body h1, .entry-body h2, .entry-body h3, .entry-body h4 { font-family: var(--serif); line-height: 1.45; }
.entry-body h3 { font-size: 18px; }
.entry-body h4 { font-size: 15px; margin: 14px 0 4px; }
.entry-body blockquote {
  margin: 10px 0; padding: 8px 14px;
  border-left: 4px solid var(--accent);
  background: var(--paper-2);
  font-family: var(--serif); font-size: 15px; line-height: 1.9;
}
.entry-body code { background: var(--paper-2); border: 1px solid var(--line); border-radius: 3px; padding: 0 4px; font-size: 12px; }
.entry-body img { border: 1px solid var(--line); border-radius: 4px; margin: 6px 0; cursor: zoom-in; }
.entry-body hr { border: none; border-top: 1px dashed var(--line); margin: 14px 0; }
.entry-body table { border-collapse: collapse; font-size: 13px; }
.entry-body th, .entry-body td { border: 1px solid var(--line); padding: 3px 8px; }
.entry-body .img-src { font-size: 12px; color: var(--ink-soft); }

details.unresolved { margin: 10px 0; border: 1px dashed #ca6f1e; border-radius: 6px; padding: 6px 12px; background: #fdf6ec; }
details.unresolved summary { cursor: pointer; font-weight: 600; color: #873600; font-size: 13px; }

/* ── 卷頁 ───────────────────────────────── */
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.book-tile {
  border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px;
  background: #fffdf6; border-top: 4px solid var(--accent);
}
.book-tile h3 { margin: 2px 0; font-family: var(--serif); font-size: 17px; }
.book-tile .cnt { font-size: 12px; color: var(--ink-soft); }
.book-maps img { width: 100%; border: 1px solid var(--line); border-radius: 6px; background: #fff; margin: 6px 0; cursor: zoom-in; }
.entry-list { list-style: none; margin: 0; padding: 0; }
.entry-list > li { border-bottom: 1px solid var(--line); }
.entry-row {
  display: flex; gap: 10px; align-items: baseline; padding: 7px 4px; cursor: pointer;
}
.entry-row:hover { background: var(--paper-2); }
.entry-row .eid { font-family: ui-monospace, monospace; font-size: 12px; color: var(--ink-soft); flex-shrink: 0; }
.entry-row .cnt-badge { margin-left: auto; font-size: 12px; color: #873600; flex-shrink: 0; }
.entry-detail { padding: 6px 10px 18px; border-top: 1px dashed var(--line); background: #fffdf6; }
.sub-head {
  font-family: var(--serif); font-size: 17px; font-weight: 700;
  margin: 22px 0 6px; padding-bottom: 4px; border-bottom: 2px solid var(--accent);
}

/* ── 實體庫 ─────────────────────────────── */
.entities-layout { display: grid; grid-template-columns: 210px 1fr; gap: 18px; }
.type-tree { font-size: 14px; }
.type-tree ul { list-style: none; padding-left: 14px; margin: 4px 0; }
.type-tree a { cursor: pointer; color: var(--ink-soft); }
.type-tree a.active { color: var(--accent); font-weight: 700; }
.search-box { width: 100%; padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fffdf6; font-size: 14px; margin-bottom: 10px; }
.entity-row { border-bottom: 1px solid var(--line); padding: 6px 4px; display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.entity-row:hover { background: var(--paper-2); }
.entity-row .nm { font-family: var(--serif); font-weight: 600; }
.entity-row .rd { font-size: 12px; color: var(--ink-soft); flex: 1; min-width: 200px; }
.agg-block { border: 1px solid var(--line); border-radius: 8px; margin: 10px 0; padding: 8px 14px; background: #fffdf6; }
.agg-block h3 { margin: 2px 0 6px; font-family: var(--serif); }

/* 實體詳情 */
table.attr-table { border-collapse: collapse; width: 100%; font-size: 13px; }
table.attr-table th, table.attr-table td { border: 1px solid var(--line); padding: 5px 8px; vertical-align: top; text-align: left; }
table.attr-table th { background: var(--paper-2); white-space: nowrap; }
.kv { margin: 2px 0; }
.kv b { color: var(--ink-soft); font-weight: 600; }

/* ── 裁決頁 ─────────────────────────────── */
.adj-list { list-style: none; padding: 0; }
.adj-list li { border-bottom: 1px solid var(--line); padding: 10px 4px; }
.adj-list .file { font-family: ui-monospace, monospace; font-size: 12px; color: var(--ink-soft); }

/* ── lightbox ───────────────────────────── */
.lightbox {
  position: fixed; inset: 0; z-index: 90; background: rgba(30,25,18,0.85);
  display: flex; align-items: center; justify-content: center; cursor: zoom-out;
}
.lightbox img { max-width: 94vw; max-height: 92vh; background: #fff; }
.lightbox .cap { position: absolute; bottom: 14px; color: #f7f3e8; font-size: 13px; max-width: 80vw; text-align: center; }

.notice { border: 1px solid var(--line); background: #fffdf6; border-radius: 6px; padding: 8px 14px; font-size: 13px; color: var(--ink-soft); margin: 10px 0; }
.muted { color: var(--ink-soft); font-size: 13px; }
.mono { font-family: ui-monospace, monospace; font-size: 12px; }

/* ── 響應式：移動端詳情卡改底部抽屜 ─────────── */
@media (max-width: 820px) {
  main { padding: 12px 14px; }
  .detail-card {
    top: auto; bottom: 0; left: 0; right: 0;
    width: 100%; max-width: none; height: 62vh;
    border-left: none; border-top: 1px solid var(--line);
    transform: translateY(105%);
  }
  .detail-card.open { transform: translateY(0); }
  .entities-layout { grid-template-columns: 1fr; }
  .map-wrap { height: auto; }
  .map-wrap svg { height: auto; }
  .layer-panel { font-size: 12px; padding: 6px 9px; max-width: 62vw; }
  .map-legend { display: none; }
}

/* 裁決與發現：內嵌全文 */
details.adj-item { margin: 10px 0; border: 1px solid #cbb; border-radius: 6px; padding: 8px 14px; background: #fffdf5; }
details.adj-item summary { cursor: pointer; font-size: 14px; }
details.adj-item summary .file { color: #999; font-size: 11px; margin-left: 8px; }
details.adj-item .adj-body { margin-top: 10px; font-size: 13px; line-height: 1.7; }
details.adj-item .adj-body table { border-collapse: collapse; }
details.adj-item .adj-body th, details.adj-item .adj-body td { border: 1px solid #d9d2c0; padding: 3px 8px; font-size: 12px; }

/* 比例尺（屏幕固定，右下角） */
.map-scalebar { position: absolute; right: 14px; bottom: 12px; z-index: 5; background: rgba(255,253,245,0.92); border: 1px solid #cbb; border-radius: 4px; padding: 4px 8px; font-size: 11px; color: #444; display: flex; align-items: center; gap: 8px; }
.map-scalebar .bar { height: 6px; border: 1.5px solid #333; border-top: none; box-sizing: border-box; }
.map-scalebar span { white-space: nowrap; }

/* 覆核按鈕 */
.rev-btn { font-size: 11px; padding: 1px 8px; margin-right: 4px; border: 1px solid #cbb; border-radius: 4px; background: #fffdf5; cursor: pointer; color: #666; }
.rev-btn:hover { border-color: #873600; color: #873600; }
.rev-btn.on { background: #873600; color: #fffdf5; border-color: #873600; }
.rev-btn[disabled] { opacity: 0.45; cursor: default; }
.rev-cell { white-space: nowrap; }

/* ── 關係圖譜 ─────────────────────────────── */
.kg-controls { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.kg-controls .search-box { flex: 1; min-width: 220px; margin-bottom: 0; }
.kg-controls select {
  padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px;
  background: #fffdf6; font-size: 14px; color: var(--ink);
}
.kg-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.kg-stat {
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px;
  background: #fffdf6; cursor: pointer;
}
.kg-stat:hover { border-color: var(--accent); }
.kg-stat .num { font-family: var(--serif); font-size: 22px; font-weight: 700; }
.kg-stat .lbl { font-size: 13px; color: var(--ink-soft); }
.kg-rel-group { border: 1px solid var(--line); border-radius: 8px; background: #fffdf6; margin: 10px 0; padding: 8px 14px; }
.kg-rel-group h4 { margin: 2px 0 6px; font-family: var(--serif); }
.kg-rel-group ul { margin: 0; padding-left: 20px; }
.kg-attr { border-top: 1px dashed var(--line); padding: 6px 0; }
.kg-attr:first-of-type { border-top: none; }
.kg-attr-meta { margin-bottom: 2px; }
.kg-role-head { margin: 8px 0 2px; font-size: 13px; color: var(--ink-soft); font-weight: 700; }
.kv-list { margin: 2px 0; padding-left: 20px; }

/* ── 時光地圖（timelapse.html）── */
.tl-intro { padding: 10px 18px; font-size: 14px; line-height: 1.7; background: var(--paper, #fdfaf2); border-bottom: 1px solid var(--line, #d8cfbc); }
.tl-bar { position: absolute; left: 50%; transform: translateX(-50%); bottom: 12px; z-index: 6; width: min(620px, 72%); background: rgba(255,253,245,0.95); border: 1px solid #cbb; border-radius: 8px; padding: 8px 14px 6px; }
.tl-bar input[type=range] { width: 100%; accent-color: #7d6608; }
.tl-ticks { display: flex; justify-content: space-between; font-size: 12px; color: #555; margin-top: -2px; }
.tl-tick { cursor: pointer; padding: 2px 6px; border-radius: 4px; }
.tl-tick:hover { background: #efe7d2; }
.tl-desc { font-size: 12.5px; line-height: 1.55; color: #444; margin-top: 6px; border-top: 1px dashed #d8cfbc; padding-top: 6px; }
@media (max-width: 720px) {
  .tl-bar { width: 92%; bottom: 8px; }
  .tl-intro { font-size: 13px; }
}
.tl-tick.on { background: #efe3c0; font-weight: 700; color: #7d6608; }
