/* ==========================================================
   雲林探秘・.Site Style
   設計目標：國中學生閱讀友善（字大、對比高、卡片化）
   ========================================================== */

:root {
  --ink: #1f2630;
  --ink-2: #45525f;
  --ink-3: #6c7a87;
  --bg: #fbf7ef;
  --surface: #ffffff;
  --surface-2: #f4efe6;
  --line: #e4dbc9;
  --rice: #e8a33d;
  --rice-soft: #fdf1dc;
  --sea: #2f7ea1;
  --sea-soft: #e3eff5;
  --mountain: #3f8f5e;
  --mountain-soft: #e5f2ea;
  --clay: #c0563c;
  --clay-soft: #fbe8e2;
  --grape: #7a6ea6;
  --focus: #1a6fbf;
  --shadow: 0 2px 3px rgba(31, 38, 48, .06), 0 10px 24px -12px rgba(31, 38, 48, .18);
  --radius: 16px;
  --radius-s: 10px;
  --maxw: 1080px;
  font-size: 17px;
}

@media (min-width: 1200px) { :root { font-size: 18px; } }

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background:
    radial-gradient(1100px 460px at 92% -12%, #eef6fa 0%, transparent 60%),
    radial-gradient(900px 420px at -12% 4%, #fdf3e2 0%, transparent 62%),
    var(--bg);
  color: var(--ink);
  font-family: "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", "Apple LiGothic", -apple-system, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.8;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--sea); text-underline-offset: 3px; }
a:hover { color: #1f5f7d; }

h1, h2, h3, h4 { line-height: 1.35; margin: 0 0 .5em; font-weight: 800; letter-spacing: .01em; }
h1 { font-size: 1.9rem; }
h2 { font-size: 1.45rem; margin-top: 1.6em; }
h3 { font-size: 1.12rem; margin-top: 1.4em; }
p { margin: 0 0 1em; }
ul, ol { padding-left: 1.4em; margin: 0 0 1em; }
li { margin-bottom: .35em; }

code, .mono { font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace; font-size: .9em; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }

.skip {
  position: absolute; left: -9999px; top: 0;
  background: #fff; padding: .6em 1em; z-index: 99;
}
.skip:focus { left: .5rem; top: .5rem; }

/* ---------- 導覽 ---------- */
header.site {
  position: sticky; top: 0; z-index: 40;
  background: rgba(255, 251, 244, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.nav-inner {
  max-width: var(--maxw); margin: 0 auto; padding: .5rem 1rem;
  display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
}
.brand {
  display: flex; align-items: center; gap: .5rem;
  font-weight: 900; text-decoration: none; color: var(--ink); font-size: 1.02rem;
  white-space: nowrap;
}
.brand .mark {
  width: 30px; height: 30px; border-radius: 9px; flex: none;
  background: linear-gradient(135deg, var(--rice), var(--clay));
  display: grid; place-items: center; color: #fff; font-size: 15px;
}
.brand small { display: block; font-weight: 600; font-size: .6rem; color: var(--ink-3); letter-spacing: .08em; }
nav.main { display: flex; gap: .2rem; flex-wrap: wrap; margin-left: auto; }
nav.main a {
  text-decoration: none; color: var(--ink-2); font-weight: 700; font-size: .82rem;
  padding: .35rem .55rem; border-radius: 999px; white-space: nowrap;
}
nav.main a:hover { background: var(--surface-2); color: var(--ink); }
nav.main a[aria-current="page"] { background: var(--ink); color: #fff; }
.progress-chip {
  display: inline-flex; align-items: center; gap: .4rem;
  font-size: .74rem; font-weight: 700; color: var(--ink-2);
  background: var(--surface); border: 1px solid var(--line);
  padding: .22rem .6rem; border-radius: 999px;
}
.menu-btn { display: none; }

@media (max-width: 900px) {
  .menu-btn {
    display: inline-block; margin-left: auto; font: inherit; font-weight: 800; font-size: .85rem;
    background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .35rem .7rem; cursor: pointer;
  }
  nav.main {
    display: none; width: 100%; margin-left: 0; flex-direction: column; gap: .1rem;
  }
  nav.main.open { display: flex; }
  nav.main a { font-size: .95rem; padding: .55rem .6rem; }
  .progress-chip { order: 3; }
}

/* ---------- 版面 ---------- */
main { max-width: var(--maxw); margin: 0 auto; padding: 1.2rem 1rem 4rem; }
main > section { margin-bottom: 2.6rem; }

.lede { font-size: 1.05rem; color: var(--ink-2); max-width: 62ch; }
.kicker {
  display: inline-block; font-size: .74rem; font-weight: 800; letter-spacing: .12em;
  color: var(--clay); background: var(--clay-soft); border-radius: 999px; padding: .2rem .7rem; margin-bottom: .6rem;
}
h1 .sub { display: block; font-size: .95rem; font-weight: 600; color: var(--ink-3); margin-top: .4em; }

.grid { display: grid; gap: 1rem; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.g4 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.05rem 1.1rem; box-shadow: var(--shadow);
}
.card h3 { margin-top: 0; }
.card.flat { box-shadow: none; background: var(--surface-2); }
.card.pad-0 { padding: 0; overflow: hidden; }

.card:hover .chip-cta { color: var(--clay); }
.chip-cta { font-weight: 800; font-size: .84rem; }

a.card { display: block; text-decoration: none; color: inherit; transition: transform .12s ease, border-color .12s ease; }
a.card:hover { transform: translateY(-2px); border-color: var(--rice); }

.tile-emoji { font-size: 1.6rem; line-height: 1; }
.tile-num { font-size: 1.9rem; font-weight: 900; letter-spacing: -.02em; }
.tile-num small { font-size: .8rem; font-weight: 700; color: var(--ink-3); margin-left: .25em; }
.muted { color: var(--ink-3); }
.small { font-size: .85rem; }
.tiny { font-size: .76rem; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }

/* 學習卡片（首頁地圖） */
.lesson { display: flex; flex-direction: column; gap: .45rem; }
.lesson .top { display: flex; align-items: center; gap: .55rem; }
.lesson .no {
  font-size: .7rem; font-weight: 900; color: #fff; background: var(--ink-3);
  border-radius: 6px; padding: .1rem .4rem;
}
.lesson .no.done { background: var(--mountain); }
.lesson p { margin: 0; font-size: .9rem; color: var(--ink-2); }

/* 徽章／標籤 */
.pill {
  display: inline-block; font-size: .76rem; font-weight: 700;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 999px; padding: .1rem .6rem; margin: 0 .25rem .3rem 0;
}
.pill.sea { background: var(--sea-soft); border-color: #c7e0ea; color: #1f5f7d; }
.pill.rice { background: var(--rice-soft); border-color: #f0dcb8; color: #8a5c11; }
.pill.green { background: var(--mountain-soft); border-color: #c5e2d1; color: #24603c; }
.pill.clay { background: var(--clay-soft); border-color: #f0cec3; color: #8f3a25; }

/* 提示框 */
.callout {
  border-left: 6px solid var(--sea); background: var(--sea-soft);
  border-radius: 0 var(--radius-s) var(--radius-s) 0;
  padding: .9rem 1.05rem; margin: 1.1rem 0;
}
.callout.warn { border-color: var(--clay); background: var(--clay-soft); }
.callout.tip { border-color: var(--mountain); background: var(--mountain-soft); }
.callout.data { border-color: var(--rice); background: var(--rice-soft); }
.callout h4 { margin: 0 0 .35em; font-size: .98rem; }
.callout p:last-child { margin-bottom: 0; }

/* 按鈕 */
.btn {
  display: inline-block; font: inherit; font-weight: 800; font-size: .95rem;
  background: var(--ink); color: #fff; text-decoration: none;
  border: 0; border-radius: 999px; padding: .6rem 1.15rem; cursor: pointer;
}
.btn:hover { background: #000; color: #fff; }
.btn.ghost { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn.rice { background: var(--clay); }
.btn.rice:hover { background: #9c422a; }
.btn.row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }

/* 控制器 */
.controls { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin: .8rem 0 1rem; }
.controls label { font-size: .82rem; font-weight: 700; color: var(--ink-2); }
select, input[type="search"], input[type="text"] {
  font: inherit; font-size: .9rem; padding: .38rem .6rem;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink);
}
.chip-btn {
  font: inherit; font-size: .8rem; font-weight: 800; cursor: pointer;
  border: 1.5px solid var(--line); background: #fff; color: var(--ink-2);
  border-radius: 999px; padding: .25rem .7rem;
}
.chip-btn[aria-pressed="true"], .chip-btn.on { background: var(--ink); color: #fff; border-color: var(--ink); }

/* ---------- 長條圖 ---------- */
.bars { display: grid; gap: .42rem; }
.bar-row { display: grid; grid-template-columns: 5.6em 1fr auto; align-items: center; gap: .6rem; font-size: .88rem; }
.bar-row .name { font-weight: 700; text-align: right; color: var(--ink-2); }
.bar-track { background: var(--surface-2); border-radius: 999px; height: 1.05em; overflow: hidden; position: relative; }
.bar-fill { height: 100%; border-radius: 999px; background: var(--sea); min-width: 2px; transition: width .5s ease; }
.bar-val { font-variant-numeric: tabular-nums; font-weight: 800; min-width: 4.4em; }
.bar-row.hi .bar-fill { background: var(--clay); }
.bar-row.lo .bar-fill { background: var(--sea); }
.bar-note { font-size: .78rem; color: var(--ink-3); margin-top: .2rem; }
.bar-row.zero .bar-track::after {
  content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 2px; background: var(--ink-3); opacity: .5;
}


@media (max-width: 560px) {
  .bar-row { grid-template-columns: 4.2em 1fr 3.9em; gap: .4rem; font-size: .8rem; }
  .bar-val { min-width: 0; font-weight: 800; }
  h1 { font-size: 1.55rem; }
  .kv { font-size: .85rem; }
  .map-shell { gap: .8rem; }
}

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-s); background: #fff; }
table { border-collapse: collapse; width: 100%; font-size: .88rem; }
th, td { padding: .5rem .7rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
thead th { background: var(--surface-2); font-size: .8rem; white-space: nowrap; position: sticky; top: 0; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:nth-child(even) { background: #fdfbf7; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.hl { background: var(--rice-soft) !important; }

/* ---------- 示意地圖 ---------- */
.map-shell { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1.15fr) minmax(260px, .85fr); }
@media (max-width: 860px) { .map-shell { grid-template-columns: 1fr; } }
.map-box { background: linear-gradient(180deg, #eaf4f9 0%, #f7f2e8 78%); border: 1px solid var(--line); border-radius: var(--radius); padding: .4rem; }
svg.map { width: 100%; height: auto; display: block; touch-action: manipulation; }
.sea-label { fill: #6b9cb5; font-size: 3.6px; font-weight: 800; letter-spacing: .12em; }
.mountain-band { fill: #dfeadd; opacity: .8; }
.grid-line { stroke: #cfe0e8; stroke-width: .3; stroke-dasharray: 1.6 1.6; }
.town-g { cursor: pointer; }
.town-g circle.halo { fill: #fff; opacity: .55; }
.town-g circle.dot { stroke: #fff; stroke-width: 1; }
.town-g text { font-size: 3.5px; font-weight: 800; fill: var(--ink); pointer-events: none; }
.town-g.dim { opacity: .22; }
.town-g.sel circle.dot { stroke: var(--ink); stroke-width: .9; }
.town-g:focus-visible circle.dot { stroke: var(--focus); stroke-width: 1.2; }
.compass { fill: var(--ink-3); font-size: 3.2px; font-weight: 700; }

.legend { display: flex; flex-wrap: wrap; gap: .35rem .8rem; font-size: .78rem; margin-top: .5rem; }
.legend span { display: inline-flex; align-items: center; gap: .3rem; }
.legend i { width: .8em; height: .8em; border-radius: 3px; display: inline-block; }

/* 細節面板 */
.panel { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.05rem; box-shadow: var(--shadow); }
.panel h3 { margin: 0 0 .2em; font-size: 1.2rem; }
.panel .zone-line { font-size: .82rem; font-weight: 700; margin-bottom: .6rem; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: .25rem .7rem; font-size: .88rem; margin: .7rem 0; }
.kv dt { color: var(--ink-3); font-weight: 700; }
.kv dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }

/* 時間軸 */
.timeline { position: relative; margin-left: .6rem; padding-left: 1.4rem; border-left: 3px solid var(--line); }
.tl-item { position: relative; margin-bottom: 1.2rem; }
.tl-item::before {
  content: ""; position: absolute; left: -1.85rem; top: .55rem;
  width: .85rem; height: .85rem; border-radius: 50%; background: var(--rice); border: 3px solid #fff; box-shadow: 0 0 0 2px var(--rice);
}
.tl-item .era { font-size: .76rem; font-weight: 900; letter-spacing: .04em; color: var(--clay); }
.tl-item h3 { margin: .1em 0 .3em; }
.tl-item p { margin: 0; font-size: .93rem; color: var(--ink-2); }

/* 流程（經濟五層） */
.flow { display: grid; gap: .7rem; }
.flow .step { display: grid; grid-template-columns: 8.4em 1fr; gap: 1rem; align-items: start; }
@media (max-width: 700px) { .flow .step { grid-template-columns: 1fr; gap: .3rem; } }
.flow .badge {
  background: var(--ink); color: #fff; border-radius: 12px; padding: .5rem .7rem;
  font-weight: 800; font-size: .9rem; text-align: center; height: fit-content;
}
.flow .badge small { display: block; font-weight: 600; font-size: .72rem; opacity: .8; }

/* 對對樂 */
.match-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.match-item {
  font: inherit; font-weight: 700; font-size: .88rem; text-align: left; cursor: pointer;
  background: #fff; border: 2px solid var(--line); border-radius: 12px; padding: .55rem .7rem; color: var(--ink);
}
.match-item:hover { border-color: var(--rice); }
.match-item.sel { border-color: var(--sea); background: var(--sea-soft); }
.match-item.ok { border-color: var(--mountain); background: var(--mountain-soft); cursor: default; opacity: .75; }
.match-item.bad { border-color: var(--clay); background: var(--clay-soft); animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

/* 測驗 */
.quiz-q { font-size: 1.08rem; font-weight: 800; margin: 0 0 .8rem; }
.opts { display: grid; gap: .5rem; }
.opt {
  font: inherit; text-align: left; cursor: pointer; background: #fff; color: var(--ink);
  border: 2px solid var(--line); border-radius: 12px; padding: .6rem .8rem; line-height: 1.6;
}
.opt:hover { border-color: var(--rice); }
.opt.right { border-color: var(--mountain); background: var(--mountain-soft); }
.opt.wrong { border-color: var(--clay); background: var(--clay-soft); }
.opt[disabled] { cursor: default; }
.explain { margin-top: .9rem; }
.progressbar { height: .5rem; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-bottom: 1rem; }
.progressbar > div { height: 100%; background: var(--mountain); }
.score-ring { font-size: 2.4rem; font-weight: 900; }

/* 辭典 */
dl.gloss dt { font-weight: 900; margin-top: .9rem; }
dl.gloss dd { margin: .1rem 0 0; color: var(--ink-2); }

/* 頁腳 */
footer.site {
  border-top: 1px solid var(--line); background: var(--surface-2);
  padding: 1.6rem 1rem 2.4rem; margin-top: 2rem;
}
footer.site .inner { max-width: var(--maxw); margin: 0 auto; font-size: .84rem; color: var(--ink-2); }
footer.site h4 { font-size: .88rem; margin: 0 0 .4rem; }
footer.site ul { list-style: none; padding: 0; margin: 0; }
.pager { display: flex; justify-content: space-between; gap: .6rem; flex-wrap: wrap; margin: 2rem 0 0; }
.pager a { text-decoration: none; }

/* 列印（學習單） */
@media print {
  header.site, footer.site, .controls, .pager, .btn, .menu-btn, .noscript-hide { display: none !important; }
  body { background: #fff; font-size: 11pt; line-height: 1.6; }
  .card, .panel { box-shadow: none; border: 1px solid #bbb; break-inside: avoid; }
  main { padding: 0; max-width: none; }
  a { color: #000; text-decoration: none; }
  .print-block { break-inside: avoid; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
  html { scroll-behavior: auto; }
}
