/* ═══════════════════════════════════════════
   EndoPedia 牙髓知識庫 — 紙白 × 赭紅
   設計 token 見 DESIGN.md
   全站最小字 0.9rem（老花眼鐵則）
   ═══════════════════════════════════════════ */

:root {
  /* 品牌 */
  --brand-primary: #a8483d;
  --brand-primary-strong: #86362d;
  --brand-primary-soft: #f2dfd8;
  --brand-accent: #b98a3e;
  --brand-accent-soft: #f2e8d8;

  /* 頁面 */
  --bg-page: #f7f3ec;
  --bg-surface: #fbf8f2;
  --bg-surface-hover: #f0eae0;
  --bg-inset: #eae3d6;

  /* 側欄 */
  --sidebar-bg: #efe9df;
  --sidebar-bg-hover: #e6dfd2;
  --sidebar-text: #3a352e;
  --sidebar-text-active: #86362d;
  --sidebar-border: #ddd5c6;

  /* 文字 */
  --text-primary: #2b2824;
  --text-secondary: #5a544b;
  --text-tertiary: #6b6459;
  --text-muted: #a8a295;

  /* 佈局（比照核醫母站：masthead 全寬容器，閱讀欄獨立） */
  --container-max: 1120px;
  --content-max: 820px;
  --font-size: 17.5px;

  --radius: 8px;
  --shadow-soft: 0 1px 3px rgba(43, 40, 36, 0.08);
  --line-dark: #e2d9cc;
  --muted: #6b6459;
  --ink-soft: #5a544b;
}

/* ── Base ── */
* { box-sizing: border-box; }
html { font-size: var(--font-size); scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: 'Noto Sans TC', 'PingFang TC', 'Microsoft JhengHei', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  background: var(--bg-page);
  color: var(--text-primary);
  line-height: 1.82;
  letter-spacing: 0.022em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a { color: var(--brand-primary); text-decoration: none; }
a:hover { color: var(--brand-primary-strong); text-decoration: underline; }

.skip-link {
  position: absolute; left: -999px; top: 0;
  background: var(--brand-primary-strong); color: #fff;
  padding: 0.6rem 1rem; z-index: 300;
}
.skip-link:focus { left: 0; }

/* ── 閱讀進度條 ── */
.reading-progress {
  position: fixed; top: 0; left: 0; height: 3px; width: 0;
  background: var(--brand-primary); z-index: 100;
  transition: width 0.1s linear;
}

/* ══ Masthead（比照核醫母站設計語言）══ */
.masthead { border-bottom: 1px solid var(--line-dark); background: var(--bg-page); }
.masthead-top, .masthead-nav, .main-content, .site-footer {
  width: min(var(--container-max), calc(100% - 56px));
  margin-inline: auto;
}
.masthead-top {
  display: grid; grid-template-columns: auto 1fr auto; gap: 34px;
  align-items: center; min-height: 92px;
}
.brand {
  display: flex; align-items: center; gap: 14px;
  border: 0; background: transparent; padding: 0;
  cursor: pointer; font-family: inherit; text-align: left;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  display: grid; width: 48px; height: 48px; place-content: center;
  border: 2px solid var(--text-primary);
  color: var(--brand-primary); font-size: 0.95rem; font-weight: 900;
  line-height: 1.05; text-align: center; transform: rotate(-3deg);
}
.brand-copy { display: grid; gap: 0; }
.brand-copy strong { font-size: 1.15rem; line-height: 1.25; color: var(--text-primary); }
.brand-copy small { color: var(--muted); font-size: 0.95rem; line-height: 1.4; }
.masthead-line { justify-self: center; margin: 0; color: var(--ink-soft); font-size: 1.02rem; }
.menu-toggle {
  display: none; min-height: 42px; padding: 6px 14px;
  border: 1px solid var(--line-dark); background: transparent;
  color: var(--text-primary); font-size: 1rem; cursor: pointer;
  border-radius: var(--radius);
}

/* 導覽列 + 搜尋 */
.masthead-nav {
  display: flex; align-items: center;
  gap: 24px; min-height: 54px;
}
.main-nav { display: flex; gap: 22px; align-items: end; min-height: 52px; flex-wrap: wrap; }
.nav-button {
  position: relative; min-height: 45px; padding: 4px 0 9px;
  border: 0; background: transparent; cursor: pointer;
  color: var(--muted); font-family: inherit;
  font-size: 1.02rem; font-weight: 700; white-space: nowrap;
}
.nav-button::after {
  position: absolute; right: 0; bottom: -1px; left: 0; height: 3px;
  background: var(--brand-primary); content: "";
  opacity: 0; transform: scaleX(0.3);
  transition: opacity 160ms ease, transform 160ms ease;
}
.nav-button:hover, .nav-button.is-active { color: var(--text-primary); }
.nav-button.is-active::after { opacity: 1; transform: scaleX(1); }

/* ── 主內容 ── */
.main-content {
  padding: 2.4rem 0 4.5rem;
  outline: none;
}

/* ── 頁尾（含版權宣告）── */
.site-footer {
  display: flex; gap: 20px; align-items: center; justify-content: space-between;
  flex-wrap: wrap;
  padding: 24px 0 42px;
  border-top: 1px solid var(--line-dark);
  color: var(--muted);
  font-size: 1rem;
}
.site-footer .footer-brand { display: flex; gap: 12px; flex-wrap: wrap; align-items: baseline; }
.site-footer .footer-brand strong { color: var(--text-primary); font-size: 1.05rem; }
.site-footer .footer-brand span { color: var(--muted); }
.site-footer .footer-links { display: flex; gap: 16px; flex-wrap: wrap; }
.site-footer .footer-links button {
  border: 0; background: transparent; padding: 0;
  color: var(--brand-primary); font-family: inherit;
  font-size: 1rem; cursor: pointer;
}
.site-footer .footer-links button:hover { color: var(--brand-primary-strong); text-decoration: underline; }
.site-footer small { color: var(--muted); font-size: 1rem; }

/* ── 分類識別圖 ── */
.category-cover {
  margin: 1.1rem 0 1.9rem;
  max-width: var(--content-max);
}
.category-cover img {
  display: block; width: 100%; height: auto;
  border-radius: 12px;
  border: 1px solid var(--line-dark);
  box-shadow: var(--shadow-soft);
}

/* ── 首頁分類選單（純入口，單欄垂直）── */
.home-menu { display: block; }
.home-intro {
  max-width: 68ch; margin: 0 0 2.2rem; padding: 0 0 1.3rem;
  border-bottom: 3px solid var(--brand-primary);
}
.home-intro h1 {
  margin: 0 0 0.55rem; color: var(--brand-primary-strong);
  font-family: "Noto Serif TC", "Songti TC", Georgia, serif;
  font-size: clamp(2rem, 4vw, 3.1rem); line-height: 1.25; letter-spacing: 0.03em;
}
.home-intro p { margin: 0; max-width: 62ch; color: var(--text-secondary); font-size: 1.05rem; line-height: 1.85; }
.home-section-heading { margin: 0 0 1.1rem; }
.home-section-heading h2 { display: inline; margin: 0 0.65rem 0 0; color: var(--text-primary); font-size: 1.45rem; }
.home-section-heading p { display: inline; color: var(--text-tertiary); font-size: 0.95rem; }
.cat-entry {
  display: block;
  margin: 0 0 2.4rem;
  color: inherit;
}
.cat-entry:hover { text-decoration: none; }
.cat-entry .category-cover { margin: 0 0 0.7rem; }
.cat-entry .category-cover img { transition: transform 0.2s ease, box-shadow 0.2s ease; }
.cat-entry:hover .category-cover img { transform: translateY(-2px); box-shadow: 0 4px 14px rgba(43, 40, 36, 0.14); }
.cat-entry-info {
  display: flex; align-items: baseline; gap: 0.8rem; flex-wrap: wrap;
  padding: 0 0.15rem;
}
.cat-entry-name { font-size: 1.25rem; font-weight: 700; color: var(--brand-primary-strong); }
.cat-entry-desc { font-size: 1rem; color: var(--text-secondary); }
.cat-entry-count {
  font-size: 0.95rem; color: var(--brand-primary);
  background: var(--brand-primary-soft);
  border-radius: 4px; padding: 0.1rem 0.55rem;
}

/* ── 研究入口：沿用法老入口的讀本結構，但使用真正的研究圖像 ── */
.dental-entry {
  display: block;
  margin: 0 0 2.7rem;
  border-bottom: 2px solid var(--brand-primary);
  color: inherit;
}
.dental-entry:hover { text-decoration: none; }
.dental-entry-media {
  height: 11rem;
  overflow: hidden;
  background: var(--bg-surface);
  border-top: 1px solid var(--line-dark);
  border-bottom: 1px solid var(--line-dark);
}
.dental-entry-media img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 54%;
  transition: transform 0.2s ease;
}
.dental-entry:hover .dental-entry-media img { transform: scale(1.015); }
.dental-entry-body {
  padding: 1rem 0 1.2rem;
}
.dental-entry-body .dental-kicker {
  color: var(--brand-accent);
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.12em;
}
.dental-entry-body h3 {
  margin: 0.3rem 0 0.35rem;
  color: var(--text-primary);
  font-size: 1.5rem;
}
.dental-entry-body p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 1rem;
  line-height: 1.7;
}
.nav-dental-link { color: var(--brand-primary-strong); }
.nav-dental-link:hover { color: var(--brand-primary); }

/* ── 首頁橫幅 ── */
.home-banner {
  padding: 2.6rem 0 2.2rem;
  border-bottom: 3px solid var(--brand-primary);
  margin-bottom: 2.6rem;
}
.banner-kicker {
  margin: 0 0 0.5rem;
  font-size: 1rem; font-weight: 600;
  color: var(--brand-accent);
  letter-spacing: 0.18em;
}
.banner-title {
  margin: 0 0 1rem;
  font-size: clamp(2.6rem, 6vw, 4rem);
  line-height: 1.15; font-weight: 700;
  color: var(--brand-primary-strong);
}
.banner-sub {
  margin: 0 0 1.6rem;
  font-size: 1.1rem; line-height: 1.85;
  color: var(--text-secondary);
  max-width: 60ch;
}
.banner-cta {
  display: inline-block;
  padding: 0.7rem 1.6rem;
  font-size: 1.05rem; font-weight: 600;
  color: #fff;
  background: var(--brand-primary);
  border-radius: var(--radius);
}
.banner-cta:hover { background: var(--brand-primary-strong); color: #fff; text-decoration: none; }

/* ── 首頁區塊 ── */
.home-section { margin-bottom: 2.6rem; }
.section-heading-big {
  font-size: 1.65rem; font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 0.4rem;
  padding-bottom: 0.35rem;
  border-bottom: 3px solid var(--brand-accent);
  display: inline-block;
}
.section-desc {
  margin: 0 0 1rem;
  font-size: 1rem; color: var(--text-tertiary);
}

/* ── 專題列（單欄，禁止並排卡片） ── */
.topic-row {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem;
  padding: 1rem 0.25rem;
  border-bottom: 1px solid var(--bg-inset);
  color: var(--text-primary);
}
.topic-row:hover { background: var(--bg-surface-hover); text-decoration: none; }
.topic-row-main { flex: 1; }
.topic-row-id {
  display: inline-block;
  font-size: 0.92rem; font-weight: 700;
  color: var(--brand-primary);
  background: var(--brand-primary-soft);
  border-radius: 4px;
  padding: 0.05rem 0.5rem;
  margin-bottom: 0.3rem;
}
.topic-row-title {
  margin: 0 0 0.25rem;
  font-size: 1.2rem; font-weight: 600; line-height: 1.5;
  color: var(--text-primary);
}
.topic-row:hover .topic-row-title { color: var(--brand-primary-strong); }
.topic-row-sub {
  margin: 0;
  font-size: 0.95rem; line-height: 1.7;
  color: var(--text-tertiary);
}
.topic-row-meta { flex-shrink: 0; text-align: right; }
.topic-row-date { display: block; font-size: 0.9rem; color: var(--text-muted); }
.topic-row-count { display: block; font-size: 0.92rem; color: var(--text-muted); margin-top: 0.2rem; }

/* ── 通用頁頭 ── */
.breadcrumb {
  font-size: 0.95rem; color: var(--text-tertiary);
  margin-bottom: 1.4rem;
}
.breadcrumb a { color: var(--brand-primary); }
.breadcrumb a:hover { color: var(--brand-accent); }
.crumb-sep { margin: 0 0.45rem; color: var(--text-muted); }

.page-title {
  margin: 0 0 0.8rem;
  font-size: clamp(2.1rem, 4vw, 2.9rem);
  line-height: 1.25; font-weight: 700;
  color: var(--text-primary);
}
.page-desc {
  margin: 0 0 2rem;
  font-size: 1.05rem; color: var(--text-secondary);
}
.text-link { font-weight: 600; }

/* ── 專題詳細頁 ── */
.article-header {
  margin-bottom: 1.8rem;
  padding-bottom: 1.2rem;
  border-bottom: 3px solid var(--brand-primary);
}
.article-kicker {
  margin: 0 0 0.4rem;
  font-size: 1rem; font-weight: 600;
  color: #8f6a1f;
  letter-spacing: 0.1em;
}
.article-subtitle {
  margin: 0 0 0.8rem;
  font-size: 1.15rem; line-height: 1.8;
  color: var(--text-secondary);
}
.article-meta {
  font-size: 0.92rem; color: var(--text-tertiary);
}

/* prose 內文（閱讀欄獨立限寬，容器 1120px） */
.prose { font-size: 1rem; line-height: 1.85; overflow-wrap: anywhere; max-width: var(--content-max); }
.prose a { overflow-wrap: anywhere; }
.prose img { max-width: 100%; }
.prose h2 {
  font-size: 1.6rem; font-weight: 600;
  margin: 2.4rem 0 0.9rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--bg-inset);
  scroll-margin-top: 20px;
}
.prose h3 {
  font-size: 1.25rem; font-weight: 600;
  margin: 1.8rem 0 0.7rem;
}
.prose h4 {
  font-size: 1.08rem; font-weight: 600;
  margin: 1.4rem 0 0.5rem;
}
.prose p { margin: 0 0 1rem; }
.prose ul, .prose ol { margin: 0 0 1.1rem; padding-left: 1.4rem; }
.prose li { margin-bottom: 0.4rem; }
.prose strong { color: var(--text-primary); }
.prose em { color: var(--text-primary); }

.section-anchor-link {
  opacity: 0;
  margin-left: 0.5rem;
  font-size: 0.95rem;
  color: var(--brand-accent);
  text-decoration: none;
}
.prose h2:hover .section-anchor-link,
.section-anchor-link:focus-visible { opacity: 1; }

/* 提示框 */
.prose .note-box {
  background: var(--brand-primary-soft);
  border-left: 4px solid var(--brand-primary);
  padding: 0.9rem 1.1rem;
  border-radius: 0 var(--radius) var(--radius) 0;
  margin: 0 0 1.2rem;
}
.prose .note-box p { margin: 0; }

/* 表格（可橫向捲動） */
.data-table-wrapper {
  overflow-x: auto;
  max-width: 100%;
  margin: 0 0 1.3rem;
  border: 1px solid var(--bg-inset);
  border-radius: var(--radius);
  background: var(--bg-surface);
  -webkit-overflow-scrolling: touch;
}
.data-table-wrapper table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
  min-width: 560px;
}
.data-table-wrapper th, .data-table-wrapper td {
  padding: 0.6rem 0.8rem;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--bg-inset);
}
.data-table-wrapper th {
  background: var(--brand-primary-soft);
  font-weight: 600;
  color: var(--brand-primary-strong);
  white-space: nowrap;
}
.data-table-wrapper tr:last-child td { border-bottom: none; }

/* 詞彙表 */
.glossary { margin: 0; }
.glossary dt {
  font-weight: 600; color: var(--brand-primary-strong);
  margin-top: 0.9rem;
}
.glossary dd { margin: 0.15rem 0 0; font-size: 0.98rem; }

/* 文獻連結 */
.sources { margin: 0; padding-left: 1.5rem; }
.sources li { margin-bottom: 1.1rem; }
.source-title { display: block; font-weight: 600; }
.source-meta { display: block; font-size: 0.92rem; color: var(--text-tertiary); }
.source-links { display: block; font-size: 0.9rem; margin-top: 0.15rem; }
.source-links a { color: var(--brand-primary); }

/* 來源清單樣式 */
.congress-list { margin: 0; padding-left: 0; list-style: none; }
.congress-list li {
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--bg-inset);
  font-size: 0.98rem;
}
.congress-id {
  display: inline-block;
  font-weight: 700; color: var(--brand-accent);
  margin-right: 0.6rem;
}

/* 文章頁尾 */
.article-footer { margin-top: 2.6rem; padding-top: 1.2rem; border-top: 1px solid var(--bg-inset); }
.back-btn {
  display: inline-block;
  padding: 0.55rem 1.3rem;
  font-size: 1rem;
  color: var(--brand-primary);
  border: 1px solid var(--brand-primary);
  border-radius: var(--radius);
}
.back-btn:hover { background: var(--brand-primary-soft); text-decoration: none; }

/* ── 載入指示 ── */
.loading-indicator {
  display: flex; gap: 0.4rem;
  padding: 3rem 0;
  justify-content: center;
}
.loading-dot {
  width: 9px; height: 9px;
  background: var(--brand-primary);
  border-radius: 50%;
  animation: loading-bounce 0.6s ease-in-out infinite alternate;
}
.loading-dot:nth-child(2) { animation-delay: 0.2s; }
.loading-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes loading-bounce {
  from { transform: translateY(0); opacity: 0.4; }
  to { transform: translateY(-6px); opacity: 1; }
}

/* ── 回到頂部 ── */
.scroll-top {
  position: fixed; right: 1.4rem; bottom: 1.4rem;
  width: 2.9rem; height: 2.9rem;
  font-size: 1.3rem;
  color: #fff; background: var(--brand-primary);
  border: none; border-radius: 50%;
  cursor: pointer;
  display: none;
  box-shadow: var(--shadow-soft);
  z-index: 60;
}
.scroll-top.visible { display: inline-flex; align-items: center; justify-content: center; }
.scroll-top:hover { background: var(--brand-primary-strong); }

/* ── 圖解 figure ── */
.prose figure {
  margin: 1.6rem 0;
  padding: 1rem;
  max-width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--bg-inset);
  border-radius: var(--radius);
}
.prose figure img {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 70vh;
  margin: 0 auto;
  border-radius: 4px;
  cursor: zoom-in;
}
.prose figcaption {
  margin-top: 0.6rem;
  font-size: 0.92rem; line-height: 1.6;
  color: var(--text-tertiary);
}
.prose figcaption .fig-src {
  display: block;
  font-size: 0.92rem;
  color: var(--text-muted);
}

/* ── 病例區塊 ── */
.case-box {
  margin: 1.6rem 0;
  background: var(--bg-surface);
  border: 1px solid var(--brand-accent);
  border-left: 5px solid var(--brand-accent);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
}
.case-box .case-head {
  display: flex; align-items: baseline; gap: 0.6rem; flex-wrap: wrap;
  margin-bottom: 0.5rem;
}
.case-box .case-tag {
  font-size: 0.92rem; font-weight: 700;
  color: var(--brand-accent);
  background: var(--brand-accent-soft);
  border-radius: 4px;
  padding: 0.05rem 0.5rem;
  white-space: nowrap;
}
.case-box .case-title {
  font-size: 1.1rem; font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}
.case-box p { margin: 0 0 0.6rem; }
.case-box p:last-child { margin-bottom: 0; }
.case-box .case-points {
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px dashed var(--bg-inset);
}
.case-box .case-points strong { color: var(--brand-primary-strong); }

/* ── Lightbox ── */
.lightbox-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(30, 26, 22, 0.9);
  display: flex; align-items: center; justify-content: center;
  padding: 2rem;
  overscroll-behavior: contain;
}
.lightbox-overlay[hidden] { display: none; }
.lightbox-figure { margin: 0; max-width: min(1100px, 94vw); text-align: center; }
.lightbox-figure img {
  max-width: 100%; max-height: 82vh;
  border-radius: 6px;
  touch-action: manipulation;
}
.lightbox-figure figcaption {
  margin-top: 0.8rem;
  color: #e8e2d8;
  font-size: 1rem; line-height: 1.6;
}
.lightbox-close {
  position: absolute; top: 1rem; right: 1.4rem;
  width: 2.8rem; height: 2.8rem;
  font-size: 1.6rem; line-height: 1;
  color: #f7f3ec; background: transparent;
  border: 1px solid rgba(247, 243, 236, 0.4);
  border-radius: 50%;
  cursor: pointer;
}
.lightbox-close:hover { background: rgba(247, 243, 236, 0.15); }

/* ── 手機選單（masthead menu-toggle 取代舊 drawer，此段已無用）── */

/* ── 響應式 ── */
@media (max-width: 900px) {
  .masthead-top, .masthead-nav, .main-content, .site-footer {
    width: min(100% - 36px, 760px);
  }
  .masthead-top { grid-template-columns: auto 1fr auto; gap: 15px; min-height: 78px; }
  .masthead-line { display: none; }
  .menu-toggle { display: block; }
  .masthead-nav { flex-direction: column; align-items: stretch; gap: 4px; min-height: 0; }
  .main-nav {
    display: none; min-height: 0; padding: 7px 0 13px;
    flex-wrap: wrap; gap: 5px 21px;
  }
  .main-nav.is-open { display: flex; }
  .search-box { width: 100%; }
  .main-content { padding: 2rem 0 4rem; }
  .category-cover { margin: 0.8rem 0 1.4rem; max-width: none; }
  .category-cover img { border-radius: 10px; }
  .home-banner { padding: 1.8rem 0 1.6rem; }
  .topic-row { flex-direction: column; gap: 0.3rem; }
  .topic-row-meta { text-align: left; }
  /* 多媒體響應：圖與表格限寬 */
  .prose { max-width: none; }
  .prose figure { padding: 0.6rem; }
  .lightbox-overlay { padding: 0.6rem; align-items: flex-start; overflow-y: auto; }
  .lightbox-figure { max-width: 98vw; }
  .lightbox-figure img { max-height: 76vh; }
  .lightbox-close { top: 0.6rem; right: 0.6rem; }
}

/* ── 減少動畫 ── */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
