/* =============================================================
   鳥類圖鑑 — 共用樣式表 (unified design system)
   每個鳥種頁面只需在自己的 <style> 內定義 :root 配色，再連結本檔。

   各頁 :root 變數契約（必填）:
     --bg          頁面背景
     --text        內文文字色
     --heading     標題／品牌色 (h2、卡片標題、表頭)
     --accent      主強調色 (邊框、時間軸圓點)
     --header-grad 頁首漸層 (linear-gradient(...))
   選填（下方有合理預設，未填時自動沿用）:
     --accent2     次強調色 (時間軸漸層尾端)  預設 = --accent
     --card-bg     卡片背景                預設 #fafafd
     --shadow      陰影                    預設見下
     --ink         深色條 (nav / footer 底)  預設近黑
   其餘色調 (muted 文字、表格斑馬色、nav/footer 細節) 由上列變數
   透過 color-mix() 自動衍生，確保各鳥種視覺一致。

   衍生變數皆採「先寫靜態後備值、再寫 color-mix()」的漸進增強寫法：
   不支援 color-mix() 的舊瀏覽器會忽略第二條宣告並沿用後備值。
   ============================================================= */

:root {
  /* 後備值；各頁 :root 會覆寫 --accent / --heading / --bg 等 */
  --accent:      #5a6890;
  --accent2:     var(--accent);
  /* 連結與徽章使用較深的衍生色，避免淺色主題中的文字對比不足 */
  --link-color:  #3f465a;
  --link-color:  color-mix(in srgb, var(--accent) 55%, #000);
  --accent-strong:  #3f465a;
  --accent-strong:  color-mix(in srgb, var(--accent) 55%, #000);
  --accent2-strong: #3f465a;
  --accent2-strong: color-mix(in srgb, var(--accent2) 55%, #000);
  --heading:     #1a1a2a;
  --text:        #18181e;
  --bg:          #f2f4f8;
  --card-bg:     #fafafd;
  --ink:         #0b0b14;
  --shadow:      0 4px 18px rgba(20, 20, 30, .14);
  --header-grad: linear-gradient(135deg, #080810 0%, #1a1a2a 50%, #2a2a40 100%);

  --font-serif: 'Noto Serif TC', 'Source Han Serif TC', 'Source Han Serif TW',
                'Songti TC', 'Songti SC', 'PMingLiU', 'MingLiU',
                Georgia, 'Times New Roman', serif;

  /* 衍生色調 (依上列核心變數自動推導；每組先後備、後 color-mix) */
  --muted:       #6e6e6e;
  --muted:       color-mix(in srgb, var(--heading) 68%, #6e6e6e);
  --row-even:    #f0f0f4;
  --row-even:    color-mix(in srgb, var(--heading) 10%, #ffffff);
  --row-hover:   #e4e4ec;
  --row-hover:   color-mix(in srgb, var(--heading) 18%, #ffffff);
  --nav-bg:      rgba(11, 11, 20, .94);
  --nav-bg:      color-mix(in srgb, var(--ink) 94%, transparent);
  --nav-link:    #b8c4dc;
  --nav-link:    color-mix(in srgb, var(--accent) 52%, #ffffff);
  --footer-text: #c8d0e0;
  --footer-text: color-mix(in srgb, var(--accent) 42%, #ffffff);

  /* 表頭：淺色模式為深底白字 */
  --thead-bg:    var(--heading);
  --thead-fg:    #ffffff;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font-serif);
  background: var(--bg);
  color: var(--text);
  line-height: 1.8;
}

/* ── Header ── */
header {
  background: var(--header-grad);
  color: #fff;
  padding: 3.5rem 2rem 4rem;
  text-align: center;
  position: relative;
  overflow: hidden;
}
header::before {
  content: '';
  position: absolute; inset: 0;
  background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle cx='5' cy='5' r='1.5' fill='%23ffffff12'/%3E%3C/svg%3E") repeat;
}
header h1 { font-size: 3.2rem; letter-spacing: .2em; text-shadow: 2px 3px 8px rgba(0,0,0,.5); position: relative; }
header .subtitle { font-size: 1.15rem; opacity: .85; margin-top: .6rem; letter-spacing: .08em; position: relative; }
header .latin { font-size: .95rem; font-style: italic; opacity: .7; margin-top: .35rem; letter-spacing: .04em; position: relative; }
.endemic-badge {
  display: inline-block; background: #c81e4a; color: #fff;
  font-size: .82rem; font-weight: bold; padding: .25rem .9rem;
  border-radius: 20px; margin-top: .7rem; letter-spacing: .06em; position: relative;
  border: 1px solid rgba(255,255,255,.5); box-shadow: 0 2px 8px rgba(0,0,0,.35);
}
.hero-birds {
  margin-top: 2rem; display: flex; justify-content: center;
  align-items: flex-end; gap: 1.8rem; position: relative; flex-wrap: wrap;
}

/* ── Nav ── */
nav {
  position: sticky; top: 0; z-index: 100;
  background: var(--nav-bg); backdrop-filter: blur(8px);
  display: flex; justify-content: center; flex-wrap: nowrap;
  padding: 0; box-shadow: 0 2px 12px rgba(0,0,0,.4); overflow-x: auto;
}
nav a {
  color: var(--nav-link); text-decoration: none; font-size: .84rem;
  letter-spacing: .04em; padding: .75rem .75rem; white-space: nowrap;
  transition: background .2s, color .2s; border-bottom: 2px solid transparent;
}
nav a:hover { background: rgba(255,255,255,.12); color: #fff; border-bottom-color: var(--accent); }
nav a:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ── Layout ── */
main { max-width: 960px; margin: 0 auto; padding: 2.5rem 1.5rem 4rem; }
section { margin-bottom: 3rem; scroll-margin-top: 56px; }
.related-birds { margin-top: 1.2rem; }
h2 { font-size: 1.6rem; color: var(--heading); border-left: 5px solid var(--accent); padding-left: .75rem; margin-bottom: 1.2rem; }
h3 { color: var(--heading); font-size: 1.1rem; margin: 1.2rem 0 .5rem; }
p { margin-bottom: .9rem; }
a { color: var(--link-color); }
a:focus-visible { outline: 2px solid var(--link-color); outline-offset: 2px; border-radius: 2px; }

/* ── Cards ── */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 1.4rem; }
.card { background: var(--card-bg); border-radius: 14px; box-shadow: var(--shadow); padding: 1.4rem 1.2rem; text-align: center; transition: transform .2s; }
.card:hover { transform: translateY(-4px); }
.card .icon { font-size: 2.8rem; margin-bottom: .6rem; }
.card h3 { color: var(--heading); font-size: 1.05rem; margin: 0 0 .4rem; }
.card p { font-size: .93rem; color: var(--muted); margin: 0; }

/* ── Info row ── */
.info-row { display: flex; gap: 2rem; align-items: flex-start; flex-wrap: wrap; }
.info-row .text { flex: 1 1 300px; }
.info-row .visual { flex: 0 0 auto; background: var(--card-bg); border-radius: 16px; box-shadow: var(--shadow); padding: 1rem; text-align: center; }
.info-row .visual figcaption { font-size: .82rem; color: var(--muted); margin-top: .5rem; }
.info-row .visual svg { max-width: 100%; height: auto; }

/* ── Fact table ── */
.fact-table { width: 100%; border-collapse: collapse; background: var(--card-bg); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
.fact-table th, .fact-table td { padding: .75rem 1.1rem; text-align: left; font-size: .96rem; }
.fact-table caption { padding: .75rem 1.1rem .45rem; text-align: left; font-weight: bold; color: var(--heading); background: var(--card-bg); }
.fact-table thead tr { background: var(--thead-bg); color: var(--thead-fg); }
.fact-table tbody tr:nth-child(even) { background: var(--row-even); }
.fact-table tbody tr:hover { background: var(--row-hover); }
.fact-table :is(th, td):first-child { white-space: nowrap; }

/* ── Timeline ── */
.timeline { position: relative; padding-left: 2rem; }
.timeline::before { content: ''; position: absolute; left: .6rem; top: 0; bottom: 0; width: 3px; background: linear-gradient(to bottom, var(--accent), var(--accent2)); border-radius: 3px; }
.tl-item { position: relative; margin-bottom: 1.4rem; }
.tl-item::before { content: ''; position: absolute; left: -1.65rem; top: .45rem; width: 13px; height: 13px; background: var(--accent); border: 2px solid var(--card-bg); border-radius: 50%; box-shadow: 0 0 0 2px var(--accent); }
.tl-item h3 { color: var(--heading); font-size: 1rem; margin: 0; }
.tl-item p { font-size: .93rem; margin: .2rem 0 0; color: var(--muted); }

/* ── Quote ── */
blockquote { border-left: 4px solid var(--accent); background: var(--card-bg); border-radius: 0 12px 12px 0; padding: 1rem 1.4rem; font-style: italic; color: var(--muted); box-shadow: var(--shadow); margin: 1.2rem 0; }

/* ── Compare ── */
.compare-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem; }
.compare-box { background: var(--card-bg); border-radius: 14px; box-shadow: var(--shadow); padding: 1.2rem; }
.compare-box h3 { font-size: 1rem; margin: 0 0 .5rem; color: var(--heading); display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.compare-box ul { padding-left: 1.2rem; font-size: .93rem; color: var(--muted); line-height: 2; }

/* ── Highlight box + tag ── */
.highlight-box { background: linear-gradient(135deg, var(--accent-strong), var(--accent2-strong)); color: #fff; border-radius: 12px; padding: 1.5rem; margin: 1rem 0; }
.highlight-box h3 { color: #fff; }
.highlight-box a { color: #fff; }
.tag { display: inline-block; background: var(--accent-strong); color: #fff; border-radius: 20px; padding: .2rem .8rem; font-size: .8rem; margin: .2rem; }

/* ── References ── */
.source-list { font-size: .95rem; }

/* ── Footer ── */
footer { text-align: center; padding: 1.5rem; background: var(--ink); color: var(--footer-text); font-size: .87rem; letter-spacing: .04em; }
footer a { color: inherit; }

/* ── Responsive ── */
@media (max-width: 600px) {
  header { padding: 2.5rem 1.2rem 3rem; }
  header h1 { font-size: 2.2rem; }
  .info-row { flex-direction: column; }
  nav { justify-content: flex-start; }
  main { padding: 1.8rem 1.1rem 3rem; }
  .fact-table th, .fact-table td { padding: .6rem .7rem; font-size: .9rem; }
}
@media (max-width: 560px) { .compare-grid { grid-template-columns: 1fr; } }

/* ── 深色模式 ──
   各頁 :root 在本檔之後載入，故此處用 :root:root 提高權重以確保覆寫。
   保留各鳥種自訂的 --accent 作為識別色，僅重算底色與衍生色。 */
@media (prefers-color-scheme: dark) {
  :root:root {
    --bg:       #12141a;
    --card-bg:  #1c1f27;
    --text:     #e6e8ee;
    --ink:      #08090d;
    --shadow:   0 4px 18px rgba(0, 0, 0, .55);

    --heading:  #cfd6e4;
    --heading:  color-mix(in srgb, var(--accent) 55%, #ffffff);
    --link-color: #d6e2f2;
    --link-color: color-mix(in srgb, var(--accent) 55%, #ffffff);
    --muted:    #a8aebc;
    --muted:    color-mix(in srgb, var(--text) 70%, #8d94a4);
    --row-even: #22262f;
    --row-even: color-mix(in srgb, var(--accent) 12%, #1c1f27);
    --row-hover:#2b3039;
    --row-hover:color-mix(in srgb, var(--accent) 24%, #1c1f27);
    --nav-bg:   rgba(8, 9, 13, .94);
    --nav-link: #c4cee0;
    --nav-link: color-mix(in srgb, var(--accent) 58%, #ffffff);
    --footer-text: #b8c2d6;
    --footer-text: color-mix(in srgb, var(--accent) 46%, #ffffff);

    /* 深色模式表頭改為深底淺字，避免淺色 --heading 配白字讀不到 */
    --thead-bg: #2a2f3a;
    --thead-bg: color-mix(in srgb, var(--accent) 30%, #1a1d24);
    --thead-fg: #eef1f6;
  }
  .card, .compare-box, .info-row .visual, blockquote, .fact-table {
    border: 1px solid rgba(255, 255, 255, .07);
  }
}

/* ── 減少動態效果 ── */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
  .card:hover { transform: none; }
}

/* ── 列印 ── */
@media print {
  nav { display: none; }
  body { background: #fff; color: #000; line-height: 1.6; }
  header { background: none; color: #000; padding: 0 0 1rem; }
  header h1 { font-size: 2rem; text-shadow: none; }
  header::before, .hero-birds { display: none; }
  .endemic-badge { border: 1px solid #000; color: #000; background: none; box-shadow: none; }
  main { max-width: none; padding: 0; }
  section { margin-bottom: 1.2rem; page-break-inside: avoid; }
  h2 { font-size: 1.2rem; color: #000; border-left: 3px solid #000; }
  h3, .card h3, .tl-item h3 { color: #000; }
  .card, .compare-box, blockquote, .info-row .visual, .fact-table {
    box-shadow: none; border: 1px solid #bbb; background: #fff;
  }
  .card:hover { transform: none; }
  .card p, .compare-box ul, .tl-item p, blockquote { color: #222; }
  .highlight-box { background: none; color: #000; border: 1px solid #666; }
  .highlight-box h3 { color: #000; }
  .tag { background: none; color: #000; border: 1px solid #666; }
  .fact-table thead tr { background: #eee; color: #000; }
  .fact-table tbody tr:nth-child(even) { background: #f7f7f7; }
  .card-grid { grid-template-columns: 1fr 1fr; }
  footer { background: none; color: #000; border-top: 1px solid #bbb; }
  a { color: #000; text-decoration: underline; }
  .source-list a::after { content: ' (' attr(href) ')'; font-size: .8em; color: #555; }
}
