/* 書窩 — 響應式樣式（手機優先，防破框）
   配色：單一暖棕色系的不同深淺 + 中性，共三調 */
:root {
  --bg: #faf6ef;        /* 頁面底：米 */
  --surface: #fffdf9;   /* 卡片/表面：近白 */
  --ink: #2c2620;       /* 文字：深棕黑 */
  --muted: #7a6b57;     /* 次要文字：淺棕（同色系） */
  --accent: #9c5a2b;    /* 主色：棕 */
  --accent-soft: #f0e2d0;/* 主色極淺（背景用） */
  --line: #e7ddcd;      /* 分隔線 */
  --radius: 14px;
  --maxw: 720px;
  --shadow: 0 10px 30px rgba(74, 46, 20, .12);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16130f;
    --surface: #1f1b16;
    --ink: #ece4d7;
    --muted: #a89e8f;
    --accent: #d99a5b;
    --accent-soft: #2a2119;
    --line: #322b23;
    --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

/* 頁面切換淡入淡出（支援的瀏覽器自動生效，其餘無害略過） */
@view-transition { navigation: auto; }
@keyframes pageIn { from { opacity: 0; } to { opacity: 1; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  line-height: 1.85;
  overflow-wrap: break-word;
  word-break: break-word;
  animation: pageIn .45s ease both;
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  body { animation: none; }
}

img { max-width: 100%; height: auto; display: block; }
a { color: var(--accent); }

/* 頁首 / 頁尾 */
.site-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.brand { font-weight: 800; font-size: 1.15rem; text-decoration: none; color: var(--ink); }

.content { max-width: var(--maxw); margin: 0 auto; padding: 28px 20px 56px; }

.site-footer {
  border-top: 1px solid var(--line);
  padding: 24px 20px 40px;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}
.site-footer p { margin: 6px 0; }

/* ---- 文章頁 ---- */
.post-title { font-size: clamp(1.5rem, 5vw, 2.1rem); line-height: 1.25; margin: 0 0 12px; }
.post-meta {
  display: flex; flex-wrap: wrap; gap: 8px 16px;
  color: var(--muted); font-size: 0.9rem; margin: 0 0 24px;
}
.post-meta .upd { margin-left: 6px; }

/* HERO：等比縮放、寬度不超過內文容器 */
.hero { margin: 0 0 28px; }
.hero img {
  width: 100%; max-width: 100%; height: auto;
  border-radius: var(--radius);
  border: 1px solid var(--line);
}

/* 內文：行距寬鬆、段落間距明顯 */
.post-body { font-size: 1.05rem; line-height: 1.9; }
.post-body h2 { font-size: 1.35rem; margin: 40px 0 14px; }
.post-body h3 { font-size: 1.15rem; margin: 30px 0 10px; }
.post-body p { margin: 22px 0; }
.post-body ul, .post-body ol { margin: 22px 0; padding-left: 1.4em; }
.post-body li { margin: 8px 0; }
.post-body blockquote {
  margin: 28px 0; padding: 10px 20px;
  border-left: 4px solid var(--accent);
  color: var(--muted); background: var(--surface); border-radius: 0 8px 8px 0;
}
.post-body img { border-radius: 10px; margin: 24px auto; }
.post-body pre {
  background: var(--surface); border: 1px solid var(--line);
  padding: 14px; border-radius: 10px; overflow-x: auto;
}
.post-body code { font-size: 0.92em; }
.post-body :not(pre) > code {
  background: var(--surface); border: 1px solid var(--line);
  padding: 1px 5px; border-radius: 5px;
}
.back { margin-top: 48px; }

/* ---- 首頁 ---- */
.intro { text-align: center; margin-bottom: 36px; }
.intro h1 { font-size: clamp(1.8rem, 6vw, 2.6rem); margin: 0 0 8px; }
.tagline { color: var(--muted); margin: 0 0 6px; }
.site-stat { color: var(--muted); font-size: 0.9rem; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr));
  gap: 22px;
}
.card {
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  text-decoration: none; color: inherit;
  transition: transform .22s ease, box-shadow .22s ease, border-color .22s ease;
  min-width: 0;
}
/* 卡片 hover：輕微上浮 + 陰影加深 */
.card:hover {
  transform: translateY(-6px);
  box-shadow: var(--shadow);
  border-color: var(--accent);
}
.card-thumb { aspect-ratio: 16 / 9; background: var(--bg); overflow: hidden; }
.card-thumb img { width: 100%; height: 100%; object-fit: cover; transition: transform .3s ease; }
.card:hover .card-thumb img { transform: scale(1.04); }
.card-body { padding: 16px 18px 18px; min-width: 0; }
.card-title { font-size: 1.15rem; margin: 0 0 8px; line-height: 1.35; }
.card-summary {
  color: var(--muted); font-size: 0.92rem; margin: 0 0 14px; line-height: 1.7;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.card-meta {
  display: flex; flex-wrap: wrap; gap: 4px 12px;
  color: var(--muted); font-size: 0.8rem; margin: 0;
}
.empty { color: var(--muted); }

/* ---- 捲動進場動畫（滑到才觸發） ---- */
.reveal { opacity: 0; transform: translateY(18px); transition: opacity .6s ease, transform .6s ease; }
.reveal.in { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) {
  .reveal { opacity: 1; transform: none; transition: none; }
}

/* ---- 數據區塊：數字跑動 ---- */
.stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 14px; margin: 28px 0;
}
.stat {
  background: var(--accent-soft); border: 1px solid var(--line);
  border-radius: 12px; padding: 18px 14px; text-align: center;
}
.stat b { display: block; font-size: 2rem; font-weight: 800; color: var(--accent); line-height: 1.1; }
.stat small { display: block; margin-top: 6px; color: var(--muted); font-size: 0.82rem; }

/* ---- 長條圖：滑到才展開 ---- */
.chart { margin: 28px 0; display: flex; flex-direction: column; gap: 14px; }
.chart .row { display: grid; grid-template-columns: 4.5em 1fr auto; align-items: center; gap: 10px; }
.chart .label { color: var(--muted); font-size: 0.9rem; }
.chart .track { background: var(--accent-soft); border-radius: 999px; height: 14px; overflow: hidden; }
.chart .bar {
  display: block; height: 100%; width: 0; border-radius: 999px;
  background: var(--accent); transition: width 1.1s cubic-bezier(.2,.7,.2,1);
}
.chart .bar.in { width: var(--barw, 0%); }
.chart .val { color: var(--accent); font-size: 0.85rem; font-weight: 700; min-width: 2.5em; text-align: right; }

/* ---- 回到頂部按鈕 ---- */
.to-top {
  position: fixed; right: 20px; bottom: 20px;
  width: 46px; height: 46px; border-radius: 50%;
  background: var(--accent); color: #fff; border: none;
  display: grid; place-items: center; cursor: pointer;
  box-shadow: var(--shadow);
  opacity: 0; visibility: hidden; transform: translateY(12px);
  transition: opacity .3s ease, transform .3s ease, visibility .3s;
}
.to-top.show { opacity: 1; visibility: visible; transform: none; }
.to-top:hover { filter: brightness(1.07); }
.to-top svg { width: 22px; height: 22px; }
