/* 只用一套字：山海圖集明體（一點明體子集，fonts/shanhai-ming.css 載入）；只有常規字重，層次靠字號 */

:root {
  --paper: #efe6cc;
  --ink: #2c2418;
  --wood: #3a2814;
  --gold: #e9cf8b;
  --j1: #9b3b2c;
  --j2: #3f6b4a;
  --j3: #5a4a86;
  --j4: #a5662a;
  --j5: #2f6f78;
  --j6: #8a3a62;
  --j7: #4d5560;
  font-family: "Shanhai Atlas Ming", serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--paper); color: var(--ink); }

.atlas-page { position: fixed; inset: 0; overflow: hidden; }
.atlas-map { position: absolute; inset: 0; }
.atlas-labels { position: absolute; inset: 0; }

/* 左上一條細長的搜尋列：小字圖名＋搜尋框；其餘功能收在右下的「圖層」 */
.atlas-head {
  position: absolute; left: 16px; top: 14px; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: 4px 4px 4px 16px; border-radius: 999px;
  background: rgba(247, 240, 220, .92); box-shadow: 0 2px 12px rgba(40, 30, 10, .2);
  max-width: calc(100% - 32px);
}
.atlas-head h1 { margin: 0; font-size: 1.05rem; font-weight: 400; letter-spacing: .25em; white-space: nowrap; }
.atlas-filters { display: flex; flex-wrap: wrap; gap: 6px; }
.atlas-chip {
  font: inherit; font-size: .78rem; font-weight: 400; letter-spacing: .08em;
  padding: 3px 9px; border-radius: 999px; cursor: pointer;
  border: 1px solid currentColor; background: transparent; opacity: .45;
}
.atlas-chip.on { opacity: 1; background: rgba(255, 255, 255, .55); }
.atlas-chip.j1 { color: var(--j1); }
.atlas-chip.j2 { color: var(--j2); }
.atlas-chip.j3 { color: var(--j3); }
.atlas-chip.j4 { color: var(--j4); }
.atlas-chip.j5 { color: var(--j5); }
.atlas-chip.j6 { color: var(--j6); }
.atlas-chip.j7 { color: var(--j7); }

/*
 * 山名題簽：拉遠時只有墨字配紙色光暈，不蓋山形；放大（.atlas-near）成米白簽條——
 * 像線裝書封面貼的題簽：細墨框裡再一道細線，墨字，不搶山形。選中的：朱紅字、朱紅框。
 */
.atlas-slip {
  --slip-ink: #2a2118;
  --slip-line: rgba(70, 52, 30, .55);
  position: absolute; transform: translate(-50%, -12%);
  appearance: none; font: inherit; cursor: pointer;
  padding: 2px 1px; border: 0; border-radius: 1px;
  background: transparent; color: var(--slip-ink);
  transition: color .15s, border-color .15s, box-shadow .15s;
}
.atlas-slip-text {
  display: block; writing-mode: vertical-rl; text-orientation: upright;
  font-size: .82rem; letter-spacing: .14em; line-height: 1.05;
  color: var(--slip-ink);
  text-shadow: 0 0 2px #f6efd9, 0 0 4px #f6efd9, 0 0 6px rgba(246, 239, 217, .9);
}
.atlas-near .atlas-slip {
  padding: 7px 4px 6px;
  background: #f7f0dc;
  border: 1px solid var(--slip-line);
  box-shadow: inset 0 0 0 2px #f7f0dc, inset 0 0 0 2.6px rgba(70, 52, 30, .28), 0 1px 3px rgba(40, 30, 10, .28);
}
.atlas-near .atlas-slip-text { font-size: .86rem; letter-spacing: .2em; text-shadow: none; }
.atlas-slip:hover { --slip-ink: #7a3b22; }
.atlas-slip.on { --slip-ink: #a3301f; --slip-line: #a3301f; z-index: 3; }
.atlas-slip.on .atlas-slip-text { text-shadow: 0 0 2px #fbf4e2, 0 0 5px #fbf4e2, 0 0 8px rgba(251, 244, 226, .95); }
.atlas-near .atlas-slip.on {
  background: #fbf5e4;
  box-shadow: inset 0 0 0 2px #fbf5e4, inset 0 0 0 2.6px rgba(163, 48, 31, .45), 0 0 0 3px rgba(163, 48, 31, .14), 0 2px 8px rgba(60, 20, 10, .3);
}
.atlas-near .atlas-slip.on .atlas-slip-text { text-shadow: none; }

.atlas-card {
  position: absolute; right: 16px; top: 16px; z-index: 6;
  width: min(380px, calc(100% - 32px)); max-height: calc(100% - 300px); min-height: 0; overflow: auto;
  padding: 16px 18px; border-radius: 8px;
  background: rgba(248, 242, 224, .97); box-shadow: 0 8px 28px rgba(40, 30, 10, .25);
}
.atlas-card h2 { margin: 2px 0 6px; font-size: 1.5rem; font-weight: 400; letter-spacing: .12em; }
.atlas-card-jing { margin: 0; font-size: .8rem; letter-spacing: .1em; opacity: .7; }
.atlas-card-route { margin: 0 0 10px; font-size: .9rem; color: #7a3b22; letter-spacing: .08em; }
.atlas-card-text { margin: 0; font-size: .95rem; line-height: 1.9; text-align: justify; }
.atlas-card-close {
  position: absolute; right: 8px; top: 6px; border: 0; background: none;
  font-size: 1.4rem; line-height: 1; cursor: pointer; color: inherit; opacity: .6;
}

.atlas-status { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); letter-spacing: .3em; }

@media (max-width: 600px) {
  .atlas-head { left: 10px; right: 10px; top: 10px; padding-left: 12px; }
  .atlas-head h1 { font-size: .95rem; letter-spacing: .15em; }
  .atlas-search { flex: 1; }
  .atlas-search input, .atlas-search input:focus { width: 100%; }
  .atlas-slip-text { font-size: .68rem; }
  .atlas-card { left: 10px; right: 10px; top: auto; bottom: 10px; width: auto; max-height: 45%; }
  /* 手機上原文卡打開時，右下的小地圖與按鈕先讓開 */
  .atlas-page:has(.atlas-card:not([hidden])) .atlas-minimap,
  .atlas-page:has(.atlas-card:not([hidden])) .atlas-controls { display: none; }
}

/* 搜尋 */
.atlas-search { position: relative; }
.atlas-search input {
  width: 15em; box-sizing: border-box; font: inherit; font-size: .88rem;
  padding: 6px 12px; border: 0; border-radius: 999px;
  background: rgba(255, 252, 242, .9); color: var(--ink); outline: none;
  transition: width .2s, box-shadow .2s;
}
.atlas-search input:focus { width: 20em; box-shadow: 0 0 0 1px rgba(122, 59, 34, .45); }
.atlas-results { min-width: 18em; }
.atlas-results {
  position: absolute; left: 0; right: 0; top: 100%; margin: 2px 0 0; padding: 4px 0; list-style: none; z-index: 10;
  max-height: 50vh; overflow: auto; background: rgba(250, 245, 230, .98); border-radius: 4px;
  box-shadow: 0 6px 20px rgba(40, 30, 10, .25);
}
.atlas-results li { display: flex; justify-content: space-between; gap: 12px; padding: 5px 10px; cursor: pointer; }
.atlas-results li.on, .atlas-results li:hover { background: rgba(122, 59, 34, .1); }
.atlas-result-name { font-size: .95rem; }
.atlas-result-sub { font-size: .75rem; opacity: .6; white-space: nowrap; }

/* 圖層開關 */
.atlas-layers { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.atlas-layer {
  font: inherit; font-size: .72rem; padding: 2px 7px; border-radius: 3px; cursor: pointer;
  border: 1px solid rgba(90, 70, 40, .3); background: transparent; color: var(--ink); opacity: .45;
}
.atlas-layer.on { opacity: 1; background: rgba(255, 255, 255, .6); }

/* 原文卡：地名連結、圖注、白話 */
.atlas-card-note { margin: .3em 0 0; font-size: .82em; line-height: 1.6; color: #7a6650; }
.atlas-card-inline { margin-left: .4em; padding: 0; border: 0; background: none; font: inherit; color: #7a3b22; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.atlas-card-text p { margin: 0 0 .5em; }
.atlas-card-more { padding-left: .6em; border-left: 2px solid rgba(122, 59, 34, .18); }
.atlas-link { color: #7a3b22; text-decoration: none; border-bottom: 1px dotted rgba(122, 59, 34, .6); }
.atlas-link:hover { background: rgba(122, 59, 34, .08); }
/* 物產：按類一列，點了在原文裡標出那一句 */
.atlas-wuchan { margin-top: 12px; padding-top: 10px; border-top: 1px dashed rgba(90, 70, 40, .3); }
.atlas-wuchan h3 { margin: 0 0 6px; font-size: .85rem; font-weight: 400; letter-spacing: .2em; color: #7a6650; }
.atlas-wuchan-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0 0 6px; }
.atlas-wuchan-kind { width: 2.4em; font-size: .78rem; color: #7a6650; letter-spacing: .05em; }
.atlas-wuchan-item {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; cursor: pointer;
  font: inherit; font-size: .88rem; border: 1px solid rgba(122, 59, 34, .3); background: rgba(255, 252, 242, .9); color: #3a3024;
}
.atlas-wuchan-item:hover { border-color: rgba(122, 59, 34, .7); }
.atlas-wuchan-item img { width: 28px; height: 28px; margin-left: -6px; object-fit: contain; }
.atlas-guji { display: flex; gap: 8px; overflow-x: auto; margin: 0 0 8px; padding-bottom: 4px; }
.atlas-guji-plate {
  flex: none; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 0; border: 0; background: none;
  font: inherit; font-size: .78rem; color: #3a3024; cursor: pointer;
}
.atlas-guji-plate img { height: 96px; width: auto; border: 1px solid rgba(90, 70, 40, .25); }
.atlas-plate { max-width: min(560px, 94vw); max-height: 94vh; padding: 16px 18px 12px; border: 0; border-radius: 8px; background: #f8f2e0; color: #3a3024; }
.atlas-plate::backdrop { background: rgba(20, 15, 5, .55); }
.atlas-plate.wide { max-width: min(1100px, 96vw); }
.atlas-plate h2 { margin: 0 0 6px; font-size: 1.3rem; font-weight: 400; letter-spacing: .12em; }
.atlas-plate figure { margin: 0; }
.atlas-plate img { display: block; max-width: 100%; margin: 0 auto 6px; }
.atlas-plate-one img { max-height: 70vh; }
/* 並排：寬螢幕一列排開，手機左右滑 */
.atlas-plate-side { display: flex; gap: 12px; overflow-x: auto; scroll-snap-type: x mandatory; }
.atlas-plate-side figure { flex: 0 0 min(300px, 78vw); scroll-snap-align: start; }
.atlas-plate-side img { max-height: 62vh; }
.atlas-plate figcaption { font-size: .82rem; line-height: 1.6; color: #7a6650; text-align: center; }
.atlas-plate-got { margin: 8px 0 0; text-align: center; font-size: .82rem; color: #7a3b22; }
.atlas-plate-tools { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; justify-content: center; }
.atlas-guji-plate { position: relative; }
.atlas-guji-count { position: absolute; top: 2px; right: 2px; padding: 0 4px; border-radius: 3px; font-size: .68rem; background: rgba(122, 59, 34, .85); color: #fff; }
::highlight(wuchan) { background: rgba(201, 88, 63, .22); color: inherit; }
.atlas-card-tools { display: flex; gap: 8px; margin-top: 12px; }
.atlas-card-btn {
  font: inherit; font-size: .82rem; padding: 4px 12px; border-radius: 3px; cursor: pointer;
  border: 1px solid rgba(122, 59, 34, .45); background: rgba(255, 252, 242, .9); color: #7a3b22;
}
.atlas-card-btn:disabled { opacity: .6; cursor: default; }
.atlas-baihua:not(:empty) {
  margin-top: 10px; padding-top: 10px; border-top: 1px dashed rgba(90, 70, 40, .3);
  font-size: .9rem; line-height: 1.85; color: #3a3024;
}
/* 篇目、圖層：右下「圖層」按鈕彈出的小面板 */
.atlas-panel {
  position: absolute; right: calc(100% + 8px); bottom: 0; width: max-content; max-width: min(320px, calc(100vw - 80px));
  padding: 10px 12px 12px; border-radius: 6px;
  background: rgba(247, 240, 220, .97); box-shadow: 0 4px 18px rgba(40, 30, 10, .25);
}
.atlas-panel-title { margin: 0 0 6px; font-size: .75rem; letter-spacing: .2em; opacity: .6; }
.atlas-panel .atlas-filters { margin-bottom: 10px; }
.atlas-panel .atlas-layers { margin-top: 0; }
#layers-btn[aria-expanded="true"] { color: #7a3b22; background: rgba(122, 59, 34, .08); }

/* 地圖按鈕：兩組上下相連的圓角按鈕（放大縮小一組、全圖與圖層一組），細墨線圖示；滑鼠停上去有文字說明 */
.atlas-controls {
  position: absolute; right: 12px; z-index: 4; display: flex; flex-direction: column; gap: 8px;
  bottom: var(--controls-bottom, 210px);
}
.atlas-ctl-group {
  display: flex; flex-direction: column; overflow: hidden; border-radius: 8px;
  background: rgba(247, 240, 220, .95); box-shadow: 0 0 0 1px rgba(70, 52, 30, .22), 0 2px 8px rgba(40, 30, 10, .2);
}
.atlas-ctl {
  width: 36px; height: 36px; display: grid; place-items: center; padding: 0;
  cursor: pointer; color: #3a2c1c; background: transparent; border: 0;
}
.atlas-ctl + .atlas-ctl { border-top: 1px solid rgba(70, 52, 30, .16); }
.atlas-ctl svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.atlas-ctl:hover { color: #7a3b22; background: rgba(255, 252, 242, .9); }
.atlas-ctl:active { background: rgba(122, 59, 34, .08); }

/* 凡例：搜尋列右端的小字入口；彈出一頁像短卷的說明 */
.atlas-fanli-link {
  font-size: .82rem; letter-spacing: .15em; color: #7a3b22; text-decoration: none; white-space: nowrap; padding: 0 10px 0 2px;
}
.atlas-fanli-link:hover { text-decoration: underline; text-underline-offset: 3px; }
.atlas-fanli {
  width: min(560px, calc(100vw - 32px)); max-height: min(80vh, 720px); overflow: auto;
  padding: 22px 26px 18px; border: 0; border-radius: 8px; color: var(--ink);
  background: #f8f2e0; box-shadow: 0 0 0 1px rgba(70, 52, 30, .25), 0 12px 40px rgba(20, 14, 6, .4);
  font-family: inherit; line-height: 1.75;
}
.atlas-fanli::backdrop { background: rgba(20, 16, 10, .35); }
.atlas-fanli h2 { margin: 0 0 10px; font-size: 1.35rem; font-weight: 400; letter-spacing: .4em; text-align: center; }
.atlas-fanli ol { margin: 0; padding-left: 1.6em; font-size: .9rem; }
.atlas-fanli li { margin: .3em 0; }
.atlas-fanli b { font-weight: 400; color: #7a3b22; letter-spacing: .08em; }
.atlas-fanli details { margin-top: 10px; font-size: .84rem; }
.atlas-fanli summary { cursor: pointer; color: #7a3b22; letter-spacing: .12em; }
.atlas-fanli details ul { margin: 6px 0 0; padding-left: 1.3em; color: #4a3c2a; }
.atlas-fanli-thanks { margin: 14px 0 0; font-size: .8rem; color: #4a3c2a; }
.atlas-fanli-thanks a { color: #7a3b22; }
.atlas-fanli-foot { margin: 14px 0 0; font-size: .78rem; opacity: .65; text-align: center; letter-spacing: .1em; }
.atlas-fanli-close {
  position: absolute; right: 10px; top: 8px; border: 0; background: none; font-size: 1.4rem; line-height: 1; cursor: pointer; color: inherit; opacity: .6;
}
@media (max-width: 600px) {
  .atlas-fanli { padding: 18px 16px 14px; }
  .atlas-fanli-link { padding-right: 8px; letter-spacing: .05em; }
}
