/* =====================================================================
 * Bestoolab 共用樣式
 * 1. 設計變數（顏色、字體、圓角）— 所有頁面與工具都只用這些變數
 * 2. 基礎排版
 * 3. 網站框架：header / footer / 麵包屑 / 頁首
 * 4. 共用元件：卡片、按鈕、分段切換、表單、提示、工具卡、FAQ、廣告位
 * 工具頁自己的樣式寫在頁面的 <!--#head--> 區塊，並盡量引用這裡的變數。
 * 想讓某個工具換主色：在頁面 front matter 加 accent: #色碼（見 build.py）。
 * ===================================================================== */

/* ---------- 1. 設計變數 ---------- */
:root {
  /* 中性底色；實際使用的 --bg / --surface-2 / --line 會混入一點主題色，換主題色整頁跟著變 */
  --base-bg: #f6f7f9;
  --base-surface-2: #f1f3f6;
  --base-line: #e2e6ec;
  --tint-bg: 5%;
  --tint-2: 7%;
  --tint-line: 10%;
  --bg: color-mix(in srgb, var(--accent) var(--tint-bg), var(--base-bg));
  --surface: #ffffff;
  --surface-2: color-mix(in srgb, var(--accent) var(--tint-2), var(--base-surface-2));
  --fg: #16191f;
  --muted: #5b6472;
  --faint: #8a93a1;
  --line: color-mix(in srgb, var(--accent) var(--tint-line), var(--base-line));
  --line-strong: #cfd5de;

  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --on-accent: #ffffff;
  --accent-soft: color-mix(in srgb, var(--accent) 12%, var(--surface));
  --accent-line: color-mix(in srgb, var(--accent) 40%, transparent);

  --danger: #dc2626;
  --success: #16a34a;
  --warn: #d97706;

  --sans: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Noto Serif TC", "Songti TC", "PMingLiU", serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;

  --r-sm: 8px;
  --r: 12px;
  --r-lg: 16px;
  --shadow: 0 1px 2px rgb(16 24 40 / .05), 0 4px 16px rgb(16 24 40 / .05);
  --wrap: 1200px;   /* 全站唯一內容寬度：header、內容、footer 對齊 */
  --gutter: 16px;
  color-scheme: light;
}
/* 預設淺色；使用者按切換鈕才進深色（不跟隨系統設定） */
:root[data-theme="dark"] {
  --base-bg: #111418; --base-surface-2: #222730; --base-line: #2b313b; --tint-bg: 6%; --tint-2: 9%; --tint-line: 14%;
  --surface: #1a1e24; --fg: #e8ebf0; --muted: #a2abb8;
  --faint: #6f7886; --line-strong: #3a414d; --accent: #5b8def; --accent-strong: #7aa5f5;
  --on-accent: #0b1220; --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 6px 20px rgb(0 0 0 / .25); color-scheme: dark;
}

/* ---------- 2. 基礎排版 ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scrollbar-gutter: stable; }   /* 長頁短頁都預留捲軸位置，換頁時版面不跳動 */
body {
  margin: 0; min-height: 100vh; display: flex; flex-direction: column;
  background: var(--bg); color: var(--fg); font-family: var(--sans);
  font-size: 16px; line-height: 1.65;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-strong); }
img, svg { max-width: 100%; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden], .hidden { display: none !important; }
p, li, .lead, .hint, .tool-card__body span, .menu__tool small, .faq summary { text-wrap: pretty; }   /* 避免最後一行只剩一兩個字 */
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.wrap { width: 100%; max-width: var(--wrap); margin-inline: auto; padding-inline: var(--gutter); }
.site-main { flex: 1; padding-bottom: 48px; }

/* ---------- 3. 網站框架 ---------- */
.skip-link { position: absolute; left: -999px; top: 8px; z-index: 100; background: var(--surface); padding: 8px 12px; border-radius: var(--r-sm); }
.skip-link:focus { left: 8px; }

.site-header { position: sticky; top: 0; z-index: 50; background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px); border-bottom: 1px solid var(--line); }
.site-header__inner { display: flex; align-items: center; gap: 16px; min-height: 56px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--fg); text-decoration: none; font-weight: 700; }
.brand__logo { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: var(--fg); color: var(--bg); font-size: 15px; font-weight: 800; }
.brand__name { font-size: 1.05rem; letter-spacing: -.01em; }
.site-nav { display: flex; align-items: center; gap: 2px; margin-left: auto; }
.nav-link { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); text-decoration: none; font-size: .92rem; padding: 7px 10px; border: 0; background: none; border-radius: var(--r-sm); white-space: nowrap; cursor: pointer; }
.nav-link:hover, .nav-item:hover > .nav-link, .nav-item.is-open > .nav-link { color: var(--fg); background: var(--surface-2); }
.nav-link[aria-current="page"] { color: var(--fg); font-weight: 600; }
.chev { transition: transform .15s; }
.nav-item:hover .chev, .nav-item.is-open .chev { transform: rotate(180deg); }
.site-header__actions { display: flex; gap: 6px; align-items: center; }

/* 下拉選單：滑鼠移上去打開（桌面）、點一下打開（觸控 / 鍵盤） */
.nav-item { position: relative; }
.menu { display: none; position: absolute; top: 100%; left: 0; z-index: 60; min-width: 220px; margin-top: 6px; padding: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: 0 10px 30px rgb(16 24 40 / .14); }
.menu::before { content: ""; position: absolute; left: 0; right: 0; top: -8px; height: 8px; } /* 補滑鼠移動的空隙 */
.menu--right { left: auto; right: 0; }
.nav-item.is-open > .menu { display: block; }
@media (hover: hover) { .nav-item:hover > .menu { display: block; } }
.menu--tools { width: 340px; }
.menu--cols { width: auto; display: none; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 4px 12px; min-width: 560px; }
.nav-item.is-open > .menu--cols { display: grid; }
@media (hover: hover) { .nav-item:hover > .menu--cols { display: grid; } }
.menu__col { display: grid; gap: 2px; align-content: start; }
.menu__h { font-size: .75rem; font-weight: 600; color: var(--faint); padding: 4px 8px; letter-spacing: .04em; }
.menu__tool { display: flex; gap: 10px; align-items: center; padding: 8px; border-radius: var(--r-sm); color: var(--fg); text-decoration: none; }
.menu__tool:hover, .menu__tool[aria-current="page"] { background: var(--surface-2); }
.menu__tool strong { display: block; font-size: .92rem; font-weight: 600; }
.menu__tool small { display: block; font-size: .78rem; color: var(--muted); line-height: 1.45; }
.menu__icon { flex: none; width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; font-weight: 700; line-height: 1; background: var(--accent-soft); color: var(--accent-strong); }
.menu__all { grid-column: 1 / -1; display: block; margin-top: 4px; padding: 8px; border-top: 1px solid var(--line); font-size: .85rem; text-decoration: none; color: var(--accent-strong); }
.menu--lang { min-width: 170px; }
.menu__lang { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 10px; border-radius: var(--r-sm); color: var(--fg); text-decoration: none; font-size: .92rem; }
a.menu__lang:hover { background: var(--surface-2); }
.menu__lang[aria-current] { font-weight: 600; color: var(--accent-strong); }
.menu__lang[aria-current]::after { content: "✓"; }
.menu__lang.is-disabled { color: var(--faint); cursor: default; }
.menu__lang small { font-size: .72rem; }

/* 主題色面板 */
.menu--accent { min-width: 0; width: 200px; }
.swatches { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 4px 8px 8px; }
.swatch { width: 32px; height: 32px; border-radius: 50%; border: 2px solid var(--surface); background: var(--sw); box-shadow: 0 0 0 1px var(--line-strong); cursor: pointer; padding: 0; }
.swatch:hover { transform: scale(1.08); }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--fg); }
.swatch--auto { background: conic-gradient(#2563eb, #7c3aed, #be185d, #b45309, #eab308, #0e7490, #2563eb); }
.icon-btn { width: 36px; height: 36px; display: grid; place-items: center; border: 1px solid var(--line); background: var(--surface); border-radius: var(--r-sm); cursor: pointer; color: var(--muted); }
.icon-btn:hover { color: var(--fg); border-color: var(--line-strong); }
.i-moon { display: none; }
:root[data-theme="dark"] .i-sun { display: none; }
:root[data-theme="dark"] .i-moon { display: block; }
.nav-toggle, .lang-icon { display: none; }
.nav-toggle .i-close, .nav-toggle[aria-expanded="true"] .i-menu { display: none; }
.nav-toggle[aria-expanded="true"] .i-close { display: block; }
@media (max-width: 760px) {
  .nav-toggle { display: grid; }
  .lang-icon { display: block; }
  .site-nav .nav-lang { display: none; }   /* 手機的語言切換改用頂欄地球圖標 */
  .site-header__actions { margin-left: auto; }
  /* 手機：選單收進漢堡鈕，打開後下拉內容直接展開 */
  .site-nav { display: none; position: absolute; left: 0; right: 0; top: 100%; flex-direction: column; align-items: stretch; gap: 0; max-height: calc(100vh - 56px); overflow-y: auto; padding: 8px var(--gutter) 12px; background: var(--surface); border-bottom: 1px solid var(--line); box-shadow: var(--shadow); }
  .site-nav.is-open { display: flex; }
  .site-nav .nav-link { padding: 10px 8px; font-size: 1rem; width: 100%; justify-content: flex-start; }
  .site-nav .nav-link:hover, .site-nav .nav-item:hover > .nav-link { background: none; }
  .site-nav .chev { display: none; }
  .site-nav .menu, .site-nav .menu--cols { display: block; position: static; width: auto; min-width: 0; margin: 0 0 8px; padding: 0 0 0 4px; border: 0; box-shadow: none; background: none; }
  .site-nav .menu::before { display: none; }
  .site-nav .menu--lang { display: flex; flex-wrap: wrap; gap: 4px; }
  .site-nav .menu__lang { padding: 6px 10px; background: var(--surface-2); }
}

.breadcrumb ol { list-style: none; display: flex; flex-wrap: wrap; gap: 4px; margin: 16px 0 0; padding: 0; font-size: .82rem; color: var(--faint); }
.breadcrumb li + li::before { content: "/"; margin-right: 4px; }
.breadcrumb a { color: var(--muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--fg); }

.page-head { margin: 12px 0 20px; }
.page-head h1, .hero h1 { margin: 0; font-size: clamp(1.5rem, 3.2vw, 2.1rem); line-height: 1.25; letter-spacing: -.01em; text-wrap: balance; }
.lead { margin: 6px 0 0; color: var(--muted); max-width: 65ch; }
.lead > span:not([data-words]) { display: inline-block; }   /* 導言可用 <span> 手動分段，換行只發生在段與段之間 */
.w { white-space: nowrap !important; }   /* site.js 分詞後的每個詞：詞內不換行（text-wrap: pretty 也會重設換行模式，所以要 !important） */
.lead:empty { display: none; }
@media (max-width: 760px) {
  .page-head { margin: 8px 0 14px; }
  .page-head .lead { font-size: .92rem; }
}

.hero { margin-top: 24px; padding: 36px 28px 32px; border-radius: var(--r-lg); border: 1px solid var(--line); background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 16%, var(--surface)), color-mix(in srgb, var(--accent) 4%, var(--surface)) 70%); }
@media (max-width: 760px) { .hero { margin-top: 16px; padding: 24px 18px; } }
.hero .lead { font-size: 1.08rem; max-width: none; }

.site-footer { border-top: 1px solid var(--line); background: var(--surface); font-size: .9rem; }
.site-footer__grid { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 24px; padding-block: 32px 16px; }
.site-footer__h { font-size: .85rem; color: var(--muted); margin: 4px 0 8px; font-weight: 600; }
.site-footer ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.site-footer a:not(.brand) { color: var(--fg); text-decoration: none; }
.site-footer a:not(.brand):hover { color: var(--accent-strong); }
.site-footer__copy { padding-block: 12px 24px; color: var(--faint); font-size: .82rem; }
@media (max-width: 760px) { .site-footer__grid { grid-template-columns: 1fr 1fr; } .site-footer__grid > :first-child { grid-column: 1 / -1; } }

/* ---------- 4. 共用元件 ---------- */
/* 卡片：工具裡的每個區塊 */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px; box-shadow: var(--shadow); }
.card--accent { border-color: var(--accent-line); }
.card__label { display: block; font-size: .8rem; font-weight: 600; color: var(--muted); margin: 0 0 10px; letter-spacing: .02em; }
@media (min-width: 1024px) { .card { padding: 20px; } }

/* 按鈕 */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px; padding: 6px 14px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--fg); border-radius: var(--r-sm); font-size: .9rem; font-weight: 500; cursor: pointer; text-decoration: none; transition: border-color .15s, background .15s, transform .1s; -webkit-tap-highlight-color: transparent; }
.btn:hover { border-color: var(--accent); color: var(--accent-strong); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn--primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); color: var(--on-accent); }
.btn--ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn--danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.btn--danger:hover { color: var(--danger); border-color: var(--danger); background: color-mix(in srgb, var(--danger) 6%, var(--surface)); }
.btn--sm { min-height: 30px; padding: 3px 10px; font-size: .8rem; }
.btn--block { width: 100%; }
.btn.is-active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }

/* 分段切換（作息範本、性別等） */
.seg { display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 3px; padding: 3px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-sm); }
.seg > button, .seg > a { border: 0; background: transparent; border-radius: 6px; padding: 6px 12px; font-size: .88rem; color: var(--muted); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.seg > button:hover { color: var(--fg); }
.seg > .is-active, .seg > .on { background: var(--surface); color: var(--fg); font-weight: 600; box-shadow: 0 1px 2px rgb(16 24 40 / .12); }

/* 表單 */
.field { display: grid; gap: 6px; }
.field > label, .field__label { font-size: .82rem; color: var(--muted); }
.input, .select { width: 100%; min-height: 38px; padding: 6px 10px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-sm); }
.input:hover, .select:hover { border-color: var(--line-strong); }

/* 標籤與提示 */
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 99px; font-size: .75rem; font-weight: 500; background: var(--accent-soft); color: var(--accent-strong); white-space: nowrap; }
.chip-btn { flex: 0 1 auto; max-width: 100%; padding: 5px 10px; border-radius: var(--r-sm); border: 1px solid transparent; background: var(--surface-2); color: var(--muted); font-size: .8rem; cursor: pointer; }
.chip-btn:hover { border-color: var(--accent-line); background: var(--accent-soft); color: var(--accent-strong); }
.hint { margin: 0; font-size: .8rem; color: var(--muted); line-height: 1.55; }
.notice { font-size: .85rem; padding: 8px 12px; border-radius: var(--r-sm); background: color-mix(in srgb, var(--warn) 10%, var(--surface)); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent); }
.result-big { font-family: var(--serif); font-weight: 900; font-size: clamp(1.9rem, 5vw, 2.6rem); line-height: 1.2; color: var(--accent-strong); word-break: break-word; }

/* 工具卡片（首頁、相關工具） */
.tool-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.tool-card { display: flex; gap: 14px; align-items: flex-start; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); text-decoration: none; color: var(--fg); transition: border-color .15s, transform .15s, box-shadow .15s; }
.tool-card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow); }
.tool-card__icon { flex: none; width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; font-size: 1.3rem; font-weight: 700; background: var(--accent-soft); color: var(--accent-strong); line-height: 1; }
.tool-card__body { display: grid; gap: 2px; }
.tool-card__body span { font-size: .86rem; color: var(--muted); line-height: 1.5; }
.home-tools h2, .related h2 { font-size: 1.15rem; margin: 32px 0 12px; }
.tool-cat { font-size: .9rem; font-weight: 600; color: var(--muted); margin: 20px 0 8px; }

/* 文章內容（工具說明，SEO 與 AdSense 審核都需要） */
.prose { margin-top: 40px; }
.prose:empty { display: none; }
.prose h2 { font-size: 1.3rem; margin: 2em 0 .6em; line-height: 1.35; }
.prose h3 { font-size: 1.08rem; margin: 1.6em 0 .5em; }
.prose p, .prose ul, .prose ol { margin: 0 0 1em; }
.prose li { margin: .25em 0; }
.prose table { border-collapse: collapse; width: 100%; margin: 0 0 1em; font-size: .92rem; display: block; overflow-x: auto; }
.prose th, .prose td { border: 1px solid var(--line); padding: 8px 10px; text-align: left; }
.prose th { background: var(--surface-2); }
.prose code { font-family: var(--mono); font-size: .88em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

.faq { margin-top: 32px; }
.faq h2 { font-size: 1.3rem; }
.faq details { border: 1px solid var(--line); background: var(--surface); border-radius: var(--r); margin-bottom: 8px; }
.faq summary { cursor: pointer; padding: 12px 16px; font-weight: 600; list-style: none; display: flex; justify-content: space-between; gap: 12px; }
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: "+"; color: var(--faint); font-weight: 400; }
.faq details[open] summary::after { content: "−"; }
.faq details > div { padding: 0 16px 14px; color: var(--muted); }

/* 廣告位：先保留高度，避免廣告載入時版面跳動（CLS） */
.ad-slot { margin: 32px auto; min-height: 120px; text-align: center; }
.ad-slot--dev { display: grid; place-items: center; border: 2px dashed var(--line-strong); border-radius: var(--r); color: var(--faint); font-size: .85rem; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
