/* ============================================================
   base.css — 版型與元件（全部 var() 驅動，零硬色碼）
   對齊 v6a（11_line-style-sample）：2 欄版型 + 內容卡片 + 文章頂端 TOC。
   顏色一律來自 tokens.css。
   ============================================================ */

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC",
    "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  background: var(--page);
  color: var(--fg);
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--link); }

/* ---------- 頂部品牌列 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 18px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.topbar .brand { text-decoration: none; font-size: 1.15rem; font-weight: 800; color: var(--green); letter-spacing: -0.01em; }
.topbar .brand #brandS { color: var(--fg); font-weight: 700; margin-left: 2px; }
.topbar .brand:hover { text-decoration: none; }
.tb-spacer { flex: 1; }
.hdr-icon-btn, .theme-toggle { display: inline-flex; align-items: center; justify-content: center; border: none; background: none; cursor: pointer; color: var(--fg); padding: 6px 9px; border-radius: 8px; }
.hdr-icon-btn:hover, .theme-toggle:hover { background: var(--green-bg); color: var(--green-d); }
.hdr-icon-btn .mag-ico { width: 21px; height: 21px; }
.theme-toggle .tt-ic { width: 19px; height: 19px; }
.theme-toggle .ic-sun { display: none; }
html[data-theme="dark"] .theme-toggle .ic-moon { display: none; }
html[data-theme="dark"] .theme-toggle .ic-sun { display: inline; }
.hamburger { display: none; background: none; border: none; font-size: 20px; cursor: pointer; color: var(--fg); padding: 4px 8px; }

/* ---------- 2 欄版型：側欄 + 主內容卡片 ---------- */
.layout {
  max-width: 1180px; margin: 0 auto;
  display: grid; grid-template-columns: 248px minmax(0, 1fr);
  gap: 36px; padding: 28px 20px 90px; align-items: start;
}
.side {
  position: sticky; top: 80px; align-self: start;
  max-height: calc(100vh - 100px); overflow-y: auto;
  padding-right: 6px; font-size: 0.92rem;
}
.side-title { font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted-light); font-weight: 700; margin: 0 0 0.8em 0.4em; }
.side-group:first-of-type .side-cat { margin-top: 0; }
.side-cat { font-weight: 700; color: var(--fg); margin: 1.4em 0 0.4em; padding: 0 0.4em; font-size: 0.86rem; }
.side ul { list-style: none; margin: 0; padding: 0; }
.side li a { display: block; padding: 0.45em 0.8em; border-radius: 8px; color: var(--fg-soft); border-left: 3px solid transparent; text-decoration: none; transition: background 0.12s, color 0.12s; }
.side li a:hover { background: var(--green-bg); text-decoration: none; color: var(--fg); }
.side li a.active { background: var(--green-bg); color: var(--green-d); font-weight: 700; border-left-color: var(--green); }

.main { min-width: 0; }
.content {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 36px 44px;
}

/* 麵包屑（content 之外，對齊 v6a） */
.crumb { font-size: 0.82rem; color: var(--muted); margin: 0 0 1.4em; }
.crumb a { color: var(--link); font-weight: 600; text-decoration: none; }
.crumb a:hover { color: var(--green-d); text-decoration: underline; }
.crumb .sep { margin: 0 0.5em; color: var(--muted-light); }
.crumb .cur { color: var(--fg); }

/* h1 下方分享工具 */
.art-hr { border: none; border-top: 1px solid var(--border); margin: 0.6em 0 0; }
.art-tools { display: flex; justify-content: flex-end; margin: 0.7em 0 1.6em; }
.art-copy { display: inline-flex; align-items: center; gap: 5px; font: inherit; font-size: 0.85rem; cursor: pointer; color: var(--muted); background: var(--card); border: 1px solid var(--border-d); border-radius: 999px; padding: 5px 14px; transition: all 0.15s; }
.art-copy:hover, .art-copy.copied { color: var(--green-d); border-color: var(--green); background: var(--green-bg); }
.art-copy .ac-ico { width: 15px; height: 15px; }

/* 底部搜尋鈕 */
.bottom-search { display: flex; align-items: center; gap: 10px; width: 100%; max-width: 100%; margin-top: 1.6em; padding: 14px 18px; background: var(--card); border: 1.5px solid var(--border-d); border-radius: 999px; cursor: pointer; color: var(--muted); font: inherit; text-align: left; transition: all 0.15s; }
.bottom-search:hover { border-color: var(--green); box-shadow: 0 0 0 3px rgba(143, 128, 107, 0.14); }
.bottom-search .bs-ico { display: inline-flex; color: var(--muted-light); }
.bottom-search .bs-ico svg { width: 19px; height: 19px; }
.bottom-search .bs-txt { color: var(--muted); }

/* ---------- 內文排版（對齊 v6a） ---------- */
.content h1 { font-size: 1.85rem; font-weight: 800; color: var(--fg); margin: 0 0 0.5em; line-height: 1.3; letter-spacing: -0.01em; }
.content h1 + p { color: var(--muted); font-size: 1.05rem; margin: 0 0 1.4em; }
.content h2 { font-size: 1.32rem; font-weight: 700; color: var(--fg); margin: 2.4em 0 0.7em; padding-bottom: 0.4em; border-bottom: 2px solid var(--h2-rule); line-height: 1.4; }
.content h3 { font-size: 1.08rem; font-weight: 700; color: var(--fg); margin: 1.8em 0 0.7em; padding-left: 0.6em; border-left: 4px solid var(--green); line-height: 1.45; }
.content p { margin: 0.9em 0; color: var(--ink); }
.content strong { color: var(--fg); font-weight: 700; }
.content a { color: var(--link); font-weight: 700; text-decoration: underline; text-underline-offset: 2px; text-decoration-color: rgba(116, 110, 103, 0.45); }
.content a:hover { color: var(--green-d); text-decoration-color: var(--green-d); }
.content ul, .content ol { padding-left: 1.4em; margin: 0.9em 0; color: var(--ink); }
.content li { margin: 0.4em 0; }
.content code { background: var(--code-bg); color: var(--code-fg); padding: 2px 6px; border-radius: 4px; font-size: 0.9em; font-family: "SF Mono", Menlo, Consolas, monospace; }
.content pre { background: var(--pre-bg); color: var(--pre-fg); padding: 1rem 1.2rem; border-radius: 10px; overflow-x: auto; line-height: 1.6; font-size: 0.88em; margin: 1.3em 0; }
.content pre code { background: transparent; color: inherit; padding: 0; }
.content blockquote { border-left: 4px solid var(--green); background: var(--green-bg); padding: 0.9em 1.3em; color: var(--fg-soft); margin: 1.4em 0; border-radius: 0 10px 10px 0; }
.content blockquote p:first-child { margin-top: 0; }
.content blockquote p:last-child { margin-bottom: 0; }
.content hr { border: none; border-top: 1px solid var(--border); margin: 2.4em 0; }

/* ---------- 文章頂端 TOC（盒子，h2-only，scroll-spy） ---------- */
.toc { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 1.1em 1.4em; margin: 0 0 2em; }
.toc-title { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 700; margin-bottom: 0.5em; }
.toc ul { list-style: none; padding: 0; margin: 0; }
.toc a { display: block; padding: 0.35em 0.6em; border-radius: 6px; color: var(--link); font-weight: 700; font-size: 0.94rem; border-left: 2px solid transparent; text-decoration: underline; text-underline-offset: 2px; text-decoration-color: rgba(116, 110, 103, 0.4); }
.toc a:hover { color: var(--green-d); background: var(--green-bg); }
.toc a.active { color: var(--green-d); border-left-color: var(--green); background: var(--green-bg); }

/* ---------- 首頁：hero + 大搜尋 + 分類區塊（對齊 v6a） ---------- */
.home-hero { background: linear-gradient(180deg, var(--hero-top) 0%, var(--page) 100%); border-bottom: 1px solid var(--border); padding: 3.2em 20px 2.6em; text-align: center; }
.home-hero h1 { margin: 0 0 0.3em; font-size: 2.1rem; font-weight: 800; color: var(--fg); }
.home-hero p { margin: 0 auto 1.6em; color: var(--muted); font-size: 1.05rem; max-width: 540px; }

.search-box { position: relative; max-width: 600px; margin: 0 auto; }
.search-box input { width: 100%; padding: 15px 18px 15px 50px; font-size: 16px; border: 1.5px solid var(--border-d); border-radius: 999px; background: var(--card); box-shadow: var(--shadow-sm); color: var(--fg); font-family: inherit; transition: all 0.15s; }
.search-box input:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 4px rgba(143, 128, 107, 0.18); }
.search-box input::placeholder { color: var(--muted-light); }
.search-box input::-webkit-search-cancel-button { -webkit-appearance: none; }
.search-box .search-icon { position: absolute; left: 18px; top: 50%; transform: translateY(-50%); color: var(--muted-light); display: flex; align-items: center; pointer-events: none; }
.search-box .search-icon svg { width: 18px; height: 18px; display: block; }
.search-box .clear-btn { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); background: none; border: none; cursor: pointer; color: var(--muted-light); font-size: 18px; padding: 4px 8px; border-radius: 6px; display: none; }
.search-box .clear-btn.visible { display: block; }

.home-main { max-width: 800px; margin: 2.4em auto; padding: 0 20px 80px; }
#results.hidden, #categories.hidden { display: none; }

.cat-block { margin-bottom: 2em; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.cat-head { display: flex; align-items: center; gap: 0.6em; padding: 1em 1.4em; border-bottom: 1px solid var(--border); background: var(--card); }
.cat-head .cat-name { font-weight: 700; color: var(--fg); font-size: 1.05rem; }
.cat-head .cat-count { color: var(--muted-light); font-size: 0.85rem; margin-left: auto; }
.cat-list { list-style: none; margin: 0; padding: 0.5em 0; }
.cat-list li a { display: flex; align-items: center; gap: 0.6em; padding: 0.7em 1.4em; color: var(--fg-soft); text-decoration: none; }
.cat-list li a:hover { background: var(--green-bg); color: var(--green-d); }
.cat-list .a-num { flex-shrink: 0; width: 22px; height: 22px; border-radius: 50%; background: var(--green-bg); color: var(--green-d); font-size: 0.72rem; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.cat-list .a-title { font-weight: 600; color: var(--fg); }
.cat-list .a-sum { color: var(--muted); font-size: 0.86rem; margin-left: auto; max-width: 50%; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.res-card { display: block; background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 1.1em 1.3em; margin-bottom: 0.8em; color: inherit; text-decoration: none; }
.res-card:hover { border-color: var(--green); }
.res-card h3 { margin: 0 0 0.3em; font-size: 1.02rem; color: var(--fg); }
.res-card p { margin: 0; color: var(--muted); font-size: 0.9em; }
.res-card .res-cat { display: inline-block; margin-top: 0.5em; font-size: 0.75em; color: var(--green-d); background: var(--green-bg); padding: 0.15em 0.7em; border-radius: 999px; }

@media (max-width: 900px) {
  .cat-list .a-sum { display: none; }
  .home-hero h1 { font-size: 1.6rem; }
}

/* ---------- 語意化 callout（含 SVG 徽章） ---------- */
.callout { border: 1px solid; border-left-width: 4px; border-radius: 10px; padding: 14px 18px; margin: 1.5em 0; }
.callout-head { font-weight: 700; display: flex; align-items: center; gap: 8px; margin-bottom: 0.4em; font-size: 0.96rem; }
.callout-ico { width: 19px; height: 19px; flex-shrink: 0; }
.callout-body { color: var(--ink); }
.callout-body > :first-child { margin-top: 0; }
.callout-body > :last-child { margin-bottom: 0; }
.callout-note { background: var(--note-bg); border-color: var(--note-bd); border-left-color: var(--note-bar); }
.callout-note .callout-head { color: var(--note-head); }
.callout-warn { background: var(--warn-bg); border-color: var(--warn-bd); border-left-color: var(--warn-bar); }
.callout-warn .callout-head { color: var(--warn-head); }
.callout-important { background: var(--important-bg); border-color: var(--important-bd); border-left-color: var(--important-bar); }
.callout-important .callout-head { color: var(--important-head); }

/* ---------- 摺疊區塊（常見問題/進階 → details） ---------- */
details.collapse { border: 1px solid var(--border); border-radius: 10px; margin: 1.5em 0; background: var(--card); padding: 0 1.4em; }
details.collapse[open] { background: var(--collapse-open-bg); }
details.collapse > summary { cursor: pointer; list-style: none; padding: 1em 0; font-weight: 700; color: var(--fg); display: flex; align-items: center; gap: 0.5em; }
details.collapse > summary::-webkit-details-marker { display: none; }
details.collapse > summary::before { content: "+"; color: var(--green); font-size: 1.2em; font-weight: 700; width: 1em; display: inline-block; }
details.collapse[open] > summary::before { content: "–"; }
details.collapse[open] > summary { border-bottom: 1px solid var(--border); }
details.collapse > summary + * { margin-top: 1em; }
details.collapse > :last-child { margin-bottom: 1.2em; }

/* ---------- 截圖占位 [[SHOT:]] ---------- */
figure.shot { margin: 1.6em 0; }
figure.shot .shot-box { border: 2px dashed var(--border-d); border-radius: 10px; background: var(--card); min-height: 140px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.5em; color: var(--muted-light); }
figure.shot .shot-cam { font-size: 1.8rem; opacity: 0.7; }
figure.shot .shot-tag { font-size: 0.76rem; letter-spacing: 0.05em; background: var(--page); border: 1px solid var(--border); border-radius: 999px; padding: 0.2em 0.8em; color: var(--muted); }
figure.shot figcaption { text-align: center; color: var(--muted); font-size: 0.9rem; margin-top: 0.6em; }
figure.shot img { max-width: 100%; border: 1px solid var(--border); border-radius: 10px; }

/* ---------- 路徑膠囊 [[PATH: a > b > c]]（對齊 v6a navpath） ---------- */
.navpath { display: inline; }
.navpath .np { display: inline-block; vertical-align: baseline; background: var(--np-bg); border: 1px solid var(--border-d); border-radius: 6px; padding: 2px 9px; margin: 0 1px; font-size: 0.92em; font-weight: 600; color: var(--fg); line-height: 1.4; }
.navpath .np-sep { display: inline-block; vertical-align: baseline; margin: 0 5px; color: var(--ink); font-weight: 400; }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; margin: 1.2em 0; }
.content table { border-collapse: collapse; width: 100%; font-size: 0.92rem; }
.content th, .content td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; }
.content th { background: var(--green-bg); }

/* ---------- 接下來 / 相關文章 ---------- */
.next-steps, .related { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 18px; margin: 1.6em 0; }
.next-steps h3, .related h3 { margin-top: 0.2em; border-left: none; padding-left: 0; }

/* ---------- 回饋（content 外的卡片，對齊 v6a） ---------- */
.feedback { margin-top: 2.2em; padding: 1.8em 1.5em; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); text-align: center; }
.feedback .fb-q { display: inline-block; position: relative; background: var(--green); color: #fff; font-weight: 700; font-size: 1.05rem; padding: 0.55em 1.6em; border-radius: 999px; margin: 0 0 1em; }
.feedback .fb-q::after { content: ""; position: absolute; left: 50%; bottom: -7px; transform: translateX(-50%); border: 7px solid transparent; border-top-color: var(--green); border-bottom: 0; }
.feedback .fb-sub { margin: 0 0 1.2em; color: var(--muted); font-size: 0.92rem; }
.feedback .fb-btns { display: flex; gap: 0.8em; justify-content: center; }
.feedback .fb-btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; font: inherit; font-weight: 700; cursor: pointer; min-width: 150px; padding: 0.7em 1.5em; border-radius: 10px; border: 1.5px solid var(--border-d); background: var(--card); color: var(--fg-soft); transition: all 0.15s; }
.feedback .fb-btn:hover { border-color: var(--green); color: var(--green-d); }
.feedback .fb-btn[data-v="yes"].chosen { background: var(--green); color: #fff; border-color: var(--green); box-shadow: 0 0 0 3px rgba(143, 128, 107, 0.34); }
.feedback .fb-btn[data-v="no"].chosen { background: #B4564C; color: #fff; border-color: #B4564C; box-shadow: 0 0 0 3px rgba(180, 86, 76, 0.32); }
.feedback .fb-thanks { max-width: 540px; margin: 1.3em auto 0; }
.feedback .fb-note { margin: 0 0 0.5em; color: var(--fg); font-size: 0.98rem; font-weight: 600; }
.feedback .fb-tips { list-style: none; padding: 0; margin: 0 0 1em; text-align: left; color: var(--muted-light); font-size: 0.82rem; line-height: 1.7; }
.feedback .fb-tips li { position: relative; padding-left: 1.3em; }
.feedback .fb-tips li::before { content: "※"; position: absolute; left: 0; }
.feedback textarea { width: 100%; font: inherit; font-size: 0.95em; padding: 0.7em 0.9em; border: 1px solid var(--border-d); border-radius: 10px; background: var(--page); color: var(--fg); resize: vertical; margin-bottom: 1em; }
.feedback .fb-send { display: block; margin: 0 auto; min-width: 240px; font: inherit; cursor: pointer; padding: 0.7em 1.6em; border-radius: 10px; border: none; background: var(--fg); color: var(--page); font-weight: 700; transition: background 0.15s; }
.feedback .fb-send:hover:not(:disabled) { opacity: 0.9; }
.feedback .fb-send:disabled { opacity: 0.6; cursor: default; }
.feedback .fb-btn:disabled { opacity: 0.55; cursor: default; }

/* ---------- 搜尋浮層 ---------- */
.search-ov { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.42); z-index: 300; display: flex; align-items: flex-start; justify-content: center; padding: 9vh 16px 16px; }
.search-ov[hidden] { display: none; }
.ov-box { width: 100%; max-width: 560px; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow-md); overflow: hidden; }
.ov-box input { width: 100%; border: none; outline: none; padding: 16px 18px; font: inherit; font-size: 1.05rem; background: var(--card); color: var(--fg); border-bottom: 1px solid var(--border); }
.search-res { max-height: 62vh; overflow-y: auto; }
.search-res a { display: block; padding: 12px 18px; text-decoration: none; color: var(--fg); border-bottom: 1px solid var(--border); }
.search-res a:hover { background: var(--green-bg); }
.search-res .r-cat { font-size: 0.76rem; color: var(--muted); }
.search-res .r-t { font-weight: 700; }
.search-res .empty { padding: 18px; color: var(--muted); text-align: center; }

/* ---------- 載入 / 錯誤態 ---------- */
.app-note { max-width: 640px; margin: 60px auto; padding: 20px 24px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); color: var(--fg-soft); }

/* ---------- 手機：單欄、漢堡抽屜（一致式設計） ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .content { padding: 24px 20px; }
  details.collapse > summary::before { display: none; }
  .side { position: fixed; top: 0; left: 0; bottom: 0; width: 260px; max-height: none; background: var(--card); border-right: 1px solid var(--border); padding: 60px 18px 20px; transform: translateX(-100%); transition: transform 0.2s; z-index: 200; overflow-y: auto; }
  .side.open { transform: translateX(0); }
  .hamburger { display: inline-flex; }
}
