/* ============================================================
   假作眞時眞亦假 — 設計系統
   章法轉寫自 SD Barrett 之畫：暖紙留白、近單色、稀而准的一味紅、軟邊。
   排版依《長篇繁體中文學術論文網頁呈現》研究報告。
   ============================================================ */

/* ---------- 字體（先用 fallback 鏈；部署時可換自托管子集 woff2） ---------- */
/* @font-face 預留：上線時把思源宋體 TC 子集放 fonts/ 下，解開下面註釋
@font-face {
  font-family: "Source Han Serif TC Subset";
  src: url("../fonts/SourceHanSerifTC-Regular.subset.woff2") format("woff2");
  font-weight: 400; font-display: swap;
  unicode-range: U+4E00-9FFF, U+3000-303F, U+FF00-FFEF;
}
*/

:root {
  /* —— 畫裏讀出的色（截圖鎖定） —— */
  --paper:        #F4ECD8;  /* 紙底 */
  --paper-card:   #F8F2E2;  /* 略亮的卡片/引文底 */
  --ink:          #33302A;  /* 炭墨·正文 */
  --ink-title:    #2A2722;  /* 深墨·標題 */
  --muted:        #756B5C;  /* 灰褐·次要文字 */
  --rule:         #9AA08F;  /* 灰綠·線/邊 */
  --rule-soft:    #cfd0bf;  /* 灰綠淡化（細分隔線） */
  --blue:         #2c557a;  /* 深靛藍——作者偏愛，作鏈接與結構之主色 */
  --link:         #2c557a;  /* 鏈接走深藍 */
  --link-hover:   #3a6c98;
  --berry:        #6e1519;  /* 暗猩紅·oxblood，再壓暗——稀用，只給最重的強調 */

  /* —— 排版 —— */
  /* 韓文 Noto CJK：漢字走正字/舊字形（眞·爲·値·裏），合古典口味。正文用 sans 讀着舒服 */
  --font-body: "Noto Sans CJK KR", "Noto Sans KR", "Apple SD Gothic Neo",
               -apple-system, "PingFang TC", sans-serif;
  --font-sans: "Noto Sans CJK KR", "Noto Sans KR", "Apple SD Gothic Neo",
               -apple-system, "PingFang TC", sans-serif;
  --font-display: "Noto Serif CJK KR", "Noto Serif KR",
                  "Apple LiSung", "Songti TC", serif;   /* 對聯·印章 留古典 */
  --font-size-base: clamp(1.02rem, 0.94rem + 0.42vw, 1.22rem);
  --lh-body: 1.78;
  --measure: 38em;            /* 正文欄寬 ≈ 38 漢字 */
  --measure-wide: 52em;       /* 含側欄目錄時的容器 */
  --space: clamp(1rem, 0.6rem + 2vw, 2rem);
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper:      #1d1913;
    --paper-card: #262017;
    --ink:        #e7ddc9;
    --ink-title:  #f1e8d6;
    --muted:      #a89b85;
    --rule:       #6f7563;
    --rule-soft:  #3a3a30;
    --blue:       #86b6da;
    --link:       #86b6da;   /* 深底上的淺靛藍 */
    --link-hover: #9fcaeb;
    --berry:      #c0524b;   /* 暗猩紅在深底上 */
  }
}

/* ---------- 基底 ---------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--font-size-base);
  line-height: var(--lh-body);
  font-feature-settings: "palt" 0;          /* 全角不擠壓，保留CJK節奏 */
  text-spacing-trim: space-first;           /* 漸進增強：標點擠壓（Chrome 123+） */
  line-break: strict;
  overflow-wrap: break-word;
  word-break: normal;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

/* ---------- 鏈接（赭紅 + 下劃線，淺色也分得出） ---------- */
a { color: var(--link); text-decoration: underline; text-underline-offset: 0.18em;
    text-decoration-thickness: 0.5px; text-decoration-color: color-mix(in srgb, var(--link) 50%, transparent); }
a:hover { color: var(--link-hover); text-decoration-color: currentColor; }
a:focus-visible { outline: 2px solid var(--link); outline-offset: 3px; border-radius: 2px; }

/* ---------- 容器與留白 ---------- */
.wrap { max-width: var(--measure); margin-inline: auto; padding: 0 var(--space); }
.prose { max-width: var(--measure); margin-inline: auto; }

main { padding-block: clamp(2rem, 1rem + 4vw, 4.5rem); }

/* ---------- 標題 ---------- */
h1, h2, h3, h4 { font-family: var(--font-display);   /* 標題用 serif，正文留 sans */
                 color: var(--ink-title); font-weight: 600; line-height: 1.3;
                 margin: 2.4em 0 0.8em; letter-spacing: 0.01em; }
h1 { font-size: clamp(1.7rem, 1.3rem + 2vw, 2.5rem); font-weight: 700;
     margin-top: 0; line-height: 1.25; letter-spacing: 0.03em; }
h2 { font-size: clamp(1.32rem, 1.1rem + 1.3vw, 1.8rem); padding-bottom: 0.25em;
     border-bottom: 1px solid var(--rule-soft); }
h3 { font-size: clamp(1.12rem, 1rem + 0.6vw, 1.34rem); font-weight: 600; color: var(--ink); }

/* 章標題上方多留呼吸 */
article > h1 + .meta { margin-top: 0.4em; }

/* ---------- 段落 ---------- */
p { margin: 0 0 1.05em; }
strong, b { font-weight: 700; color: var(--berry); }   /* 最重的強調用莓紅·稀用 */
em, i { font-style: normal; }                            /* 中文不用斜體；西文另設 */
em:lang(en), i:lang(en), cite { font-style: italic; }

/* ---------- 引文塊（脂批 / 直引）：灰綠左欄（截圖那樣） ---------- */
blockquote {
  margin: 1.6em 0; padding: 0.6em 1.2em;
  border-left: 3px solid var(--rule);
  background: color-mix(in srgb, var(--paper-card) 70%, transparent);
  border-radius: 0 6px 6px 0;
  color: color-mix(in srgb, var(--ink) 90%, var(--muted));
}
blockquote p:last-child { margin-bottom: 0; }

/* ---------- 對聯：定場的兩行 ---------- */
.couplet {
  font-family: var(--font-display);
  font-size: clamp(1.4rem, 1.1rem + 1.6vw, 2.1rem);
  line-height: 2; letter-spacing: 0.18em; text-indent: 0;
  color: var(--ink-title); text-align: center;
  margin: 1.4em 0; font-weight: 600;
}
.couplet .line { display: block; }

/* ---------- 待覆核 / 編者標記（小而靜，不搶眼） ---------- */
.pending {
  font-size: 0.82em; color: var(--muted);
  background: color-mix(in srgb, var(--rule) 18%, transparent);
  padding: 0.05em 0.4em; border-radius: 4px; white-space: normal;
}
.note-source {            /* 脂批本子歸屬標籤 */
  font-family: var(--font-sans); font-size: 0.8em; color: var(--muted);
  letter-spacing: 0.02em;
}

/* ---------- 表格（對照 / 對比）：無重框，灰綠細線 ---------- */
.table-wrap { overflow-x: auto; margin: 1.6em 0; }
table { border-collapse: collapse; width: 100%; font-size: 0.95em; }
th, td { padding: 0.55em 0.8em; text-align: left; vertical-align: top;
         border-bottom: 1px solid var(--rule-soft); }
thead th { color: var(--ink-title); font-weight: 600;
           border-bottom: 1.5px solid var(--rule); }
caption, figcaption { color: var(--muted); font-size: 0.88em; margin-top: 0.6em; text-align: center; }
td:lang(en) { font-family: Georgia, "Times New Roman", serif; }

/* ---------- 分隔（軟，不用硬線） ---------- */
hr { border: none; height: 1px; max-width: 8em; margin: 2.6em auto;
     background: var(--rule); opacity: 0.6; }

/* 三星分節（散文用） */
.asterism { text-align: center; color: var(--rule); letter-spacing: 0.6em;
            margin: 2.4em 0; border: none; }

/* ---------- 列表 ---------- */
ul, ol { padding-left: 1.4em; margin: 0 0 1.05em; }
li { margin: 0.3em 0; }

/* ---------- 頁眉（站點） ---------- */
.site-head { padding: 1.1em 0; border-bottom: 1px solid var(--rule-soft); }
.site-head .wrap { max-width: var(--measure-wide); display: flex;
                   justify-content: space-between; align-items: baseline; gap: 1em; flex-wrap: wrap; }
.site-head a.brand { font-family: var(--font-display); font-weight: 600;
                     color: var(--ink-title); text-decoration: none;
                     font-size: 1.85rem; letter-spacing: 0.04em; line-height: 1; }
.site-nav a { margin-left: 1.1em; color: var(--muted); text-decoration: none; font-size: 0.92rem; }
.site-nav a:hover, .site-nav a[aria-current="page"] { color: var(--link); }

/* ---------- 文章題首 ---------- */
.article-head { margin-bottom: 2.2em; }
.article-head .subtitle { color: var(--muted); font-size: 1.05em; margin-top: 0.2em; }
.article-head .meta { color: var(--muted); font-size: 0.9em; font-family: var(--font-sans);
                      margin-top: 0.8em; letter-spacing: 0.02em; }
.lead-cap::first-letter { /* 不做首字下沉，留素淨 */ }

/* ---------- 進度條（scroll-driven，Firefox 自動降級為不動） ---------- */
@keyframes grow-progress { from { transform: scaleX(0); } to { transform: scaleX(1); } }
.progress {
  position: fixed; top: 0; left: 0; right: 0; height: 2px; transform-origin: left;
  background: var(--blue); z-index: 50; transform: scaleX(0);
  animation: grow-progress linear; animation-timeline: scroll(root);
}
@media (prefers-reduced-motion: reduce) { .progress { animation: none; display: none; } }

/* ---------- 雙欄：側邊目錄 + 正文（論文用） ---------- */
.layout {
  max-width: var(--measure-wide); margin-inline: auto; padding: 0 var(--space);
  display: grid; grid-template-columns: 1fr; gap: 2.4em;
}
@media (min-width: 64rem) {
  .layout { grid-template-columns: 15.5rem minmax(0, var(--measure));
            justify-content: center; gap: 3em; align-items: start; }
  .toc { position: sticky; top: 1.6rem; max-height: calc(100vh - 3rem);
         overflow-y: auto; font-size: 0.9rem; }
  .toc > summary { display: none; }   /* 桌面：去掉折疊三角，固定展開 */
  /* 自動隱藏：鼠標移到左欄才浮現，移開即淡出；正文位置不動，不跳 */
  .toc { opacity: 0; transition: opacity .35s ease; }
  .toc:hover, .toc:focus-within { opacity: 1; }
}
@media (min-width: 64rem) and (prefers-reduced-motion: reduce) {
  .toc { transition: none; }
}
.toc { font-family: var(--font-sans); }
.toc h2 { font-size: 0.82rem; letter-spacing: 0.12em; color: var(--muted);
          border: none; margin: 0 0 0.8em; text-transform: none; font-weight: 600; }
.toc ol { list-style: none; padding: 0; margin: 0; }
.toc li { margin: 0.15em 0; }
.toc a { display: block; padding: 0.28em 0.6em; color: var(--muted);
         text-decoration: none; border-left: 2px solid transparent; border-radius: 0 4px 4px 0; }
.toc a:hover { color: var(--ink); background: color-mix(in srgb, var(--rule) 12%, transparent); }
.toc a.active { color: var(--link); border-left-color: var(--link);
                background: color-mix(in srgb, var(--rule) 14%, transparent); }
.toc .toc-sub { padding-left: 0.8em; font-size: 0.94em; }

/* 窄屏：目錄收進可摺疊 */
@media (max-width: 63.99rem) {
  .toc { background: var(--paper-card); border-radius: 8px; padding: 1em 1.2em; }
  .toc[open] summary { margin-bottom: 0.6em; }
  details.toc > summary { cursor: pointer; color: var(--ink-title); font-weight: 600;
                          font-family: var(--font-sans); list-style: none; }
  details.toc > summary::-webkit-details-marker { display: none; }
  .toc > h2 { display: none; }   /* 手機：summary 已當標籤，隱藏重複的「目錄」 */
}

/* ---------- 章節錨點：粘性頂欄不遮 ---------- */
section[id], h2[id], h3[id] { scroll-margin-top: 4.5rem; }
:target { background: color-mix(in srgb, var(--berry) 12%, transparent);
          border-radius: 4px; }

/* ---------- 頁腳 ---------- */
.site-foot { margin-top: 4rem; padding: 2rem 0 3rem;
             border-top: 1px solid var(--rule-soft); color: var(--muted);
             font-size: 0.86rem; font-family: var(--font-sans); }
.site-foot .wrap { max-width: var(--measure-wide); }
.site-foot p { margin: 0.3em 0; }
/* 作者署名：永遠突出——藍、加粗、可點郵箱 */
.author-link { color: var(--link); font-weight: 700; text-decoration: underline;
               text-underline-offset: 0.16em; text-decoration-thickness: 1px; }
.author-link:hover { color: var(--link-hover); }

/* ---------- 落地頁 ---------- */
.landing { min-height: 78vh; display: flex; flex-direction: column;
           justify-content: center; align-items: center; text-align: center;
           padding: 4rem var(--space); }
.landing .couplet { margin: 1.2em 0 0.4em; }
.landing .tagline { color: var(--muted); max-width: 28em; margin: 1.2em auto 2.4em; }
.cards { display: grid; gap: 1.2em; grid-template-columns: 1fr;
         max-width: 44em; width: 100%; margin-top: 1em; }
@media (min-width: 40rem) { .cards { grid-template-columns: 1fr 1fr; } }
.card { display: block; text-align: left; text-decoration: none; color: inherit;
        background: var(--paper-card); border: 1px solid var(--rule-soft);
        border-radius: 10px; padding: 1.3em 1.5em; transition: border-color .2s, transform .2s; }
.card:hover { border-color: var(--rule); transform: translateY(-2px); }
.card h3 { margin: 0 0 0.3em; color: var(--ink-title); }
.card p { margin: 0; color: var(--muted); font-size: 0.92em; }
.card .kind { font-family: var(--font-sans); font-size: 0.74em; letter-spacing: 0.14em;
              color: var(--link); text-transform: uppercase; }

/* 作者隱含的一句（五言聯，無標點）——是歌，不是公告：忽然飄起，又飄走 */
.seal { font-family: var(--font-display); text-align: center; color: var(--muted);
        font-size: 1.06rem; letter-spacing: 0.26em; margin: 0.4em 0 2em;
        opacity: 0; will-change: opacity, transform;
        animation: seal-in 1.8s ease 1.1s forwards, seal-float 9s ease-in-out 3.2s infinite; }
.seal span { display: inline-block; }
.seal span + span { margin-left: 1.4em; }
@keyframes seal-in   { from { opacity: 0; transform: translateY(12px); } to { opacity: 0.58; } }
@keyframes seal-float{ 0%,100% { transform: translateY(0); } 50% { transform: translateY(-7px); } }
@media (prefers-reduced-motion: reduce) { .seal { animation: none; opacity: 0.55; } }
@media (max-width: 30rem) { .seal span { display: block; } .seal span + span { margin: 0.2em 0 0; } }

/* ---------- 互文盒：散文 ↔ 論文 對讀 ---------- */
.intertext {
  margin: 0 0 2.4em; padding: 1em 1.3em;
  background: color-mix(in srgb, var(--link) 7%, var(--paper-card));
  border: 1px solid color-mix(in srgb, var(--link) 22%, transparent);
  border-radius: 10px; font-size: 0.94em;
}
.intertext p { margin: 0.2em 0; }
.intertext .xref { font-family: var(--font-sans); font-size: 0.86em; color: var(--muted);
                   margin-top: 0.5em; line-height: 1.9; }
.intertext .xref a { color: var(--link); }
.intertext::before { content: "互文"; display: inline-block; font-family: var(--font-sans);
                     font-size: 0.7em; letter-spacing: 0.18em; color: var(--link);
                     border: 1px solid color-mix(in srgb, var(--link) 35%, transparent);
                     border-radius: 4px; padding: 0.05em 0.5em; margin-right: 0.6em;
                     vertical-align: 0.12em; }

/* ---------- 致謝 / 體例 小字塊 ---------- */
.colophon { background: color-mix(in srgb, var(--paper-card) 60%, transparent);
            border-radius: 8px; padding: 1em 1.3em; margin: 1.6em 0;
            font-size: 0.92em; color: var(--muted); }
.colophon strong { color: var(--ink); }

/* ---------- 劃選浮出菜單（就此段聯繫作者） ---------- */
.sel-menu {
  position: absolute; z-index: 80; display: flex; gap: 2px;
  background: var(--ink-title); border-radius: 9px; padding: 4px;
  box-shadow: 0 8px 24px rgba(0,0,0,.24); font-family: var(--font-sans);
  animation: sel-in .12s ease-out;
}
.sel-menu[hidden] { display: none; }
.sel-menu button {
  background: none; border: none; color: var(--paper); font: inherit;
  font-size: 0.86rem; padding: 0.42em 0.8em; border-radius: 6px; cursor: pointer;
  white-space: nowrap; letter-spacing: 0.02em;
}
.sel-menu button:hover { background: rgba(255,255,255,.14); }
.sel-menu .sel-contact { color: #a9cce4; }   /* 菜單上也點一筆藍 */
.sel-menu button:focus-visible { outline: 2px solid var(--link-hover); outline-offset: 1px; }
@keyframes sel-in { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sel-menu { animation: none; } }

/* ---------- 打印 ---------- */
@media print {
  .site-head, .site-nav, .progress, .toc, .site-foot, details.toc { display: none !important; }
  body { background: #fff; color: #000; font-size: 11pt; line-height: 1.5; }
  .layout { display: block; max-width: none; }
  a { color: #000; }
  a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 0.8em; color: #555; }
  h2, h3, blockquote, tr, figure { break-inside: avoid; }
  h2, h3 { break-after: avoid; }
}
