/* ═══════════════════════════════════════════════════════════════
   MD.Piece — 衛教文章「醫典 / Medical Codex」閱讀體驗（education-scoped）

   只作用於衛教頁的開書閱讀器（.notebook / .nb-page / .edu-article-body），
   把文章變成古醫典手稿：羊皮紙質感、襯線字、暗紅墨點綴、章節分隔、
   首字下沉、重點概念墨痕、文獻＝研究註記、章節書籤、閱讀進度。

   搭配 js/edu-codex.js（漸進增強：書籤/進度/首字下沉/詞彙彈窗）。
   還原：移除 index.html 的這支 <link> 與 <script> 即可；不動 app.js。
   ═══════════════════════════════════════════════════════════════ */

:root {
  --codex-ink:      #3a2a1e;
  --codex-ink-soft: #6a5640;
  --codex-burgundy: #7a2230;
  --codex-burg-2:   #8c2f3a;
  --codex-gold:     #9c7b3f;
  --codex-parch:    #efe3c4;
  --codex-parch-2:  #e7d6ac;
  --codex-edge:     #cdb988;
  /* 手寫字型堆疊：優先用系統／開源楷書手寫字（多數裝置已內建），無大檔 webfont；
     缺字時優雅退回現有襯線，仍可讀（長者模式 readability 不致崩）。 */
  --codex-hand: "LXGW WenKai TC", "LXGW WenKai", "Jason Handwriting", "KaiTi TC",
                "KaiTi", "DFKai-SB", "BiauKai", "標楷體", "Noto Serif TC", serif;
}

/* ── 書桌底（書本外的木質暗底，襯托羊皮紙）── */
body[data-page="education"] .edu-stage .notebook-wrap {
  background:
    radial-gradient(ellipse at 50% 0%, rgba(60,40,20,.10), transparent 60%),
    linear-gradient(180deg, #4a3525, #3a2918) !important;
  padding: 14px !important;
  border-radius: 8px !important;
  box-shadow: inset 0 0 40px rgba(0,0,0,.35) !important;
}

/* ── 羊皮紙頁面 ── */
body[data-page="education"] .notebook .nb-page {
  font-family: "Cormorant Garamond", "Noto Serif TC", "Songti TC", "STSong", serif;
  color: var(--codex-ink) !important;
  background:
    /* 邊角焦化暈染 */
    radial-gradient(ellipse at 0% 0%,   rgba(120,80,30,.16), transparent 26%),
    radial-gradient(ellipse at 100% 0%, rgba(120,80,30,.16), transparent 26%),
    radial-gradient(ellipse at 0% 100%, rgba(120,80,30,.18), transparent 28%),
    radial-gradient(ellipse at 100% 100%, rgba(120,80,30,.18), transparent 28%),
    /* 紙纖維顆粒 */
    radial-gradient(rgba(120,90,50,.06) .6px, transparent .9px),
    /* 主羊皮色 */
    linear-gradient(160deg, var(--codex-parch) 0%, var(--codex-parch-2) 100%) !important;
  background-size: auto, auto, auto, auto, 7px 7px, 100% 100% !important;
  border: 2px solid var(--codex-edge) !important;
  box-shadow:
    inset 0 0 0 1px rgba(255,250,235,.5),
    inset 0 0 26px rgba(120,85,40,.20) !important;
  border-radius: 4px !important;
}
/* 內側裝飾雙線框 */
body[data-page="education"] .notebook .nb-page::before {
  content: "" !important;
  position: absolute !important; inset: 10px !important;
  border: 1px solid rgba(122,34,48,.30) !important;
  box-shadow: inset 0 0 0 3px rgba(122,34,48,.06) !important;
  border-radius: 3px !important;
  pointer-events: none !important;
  background: none !important;
}

/* ── 左頁＝醫者前言 / 書籤 ── */
body[data-page="education"] .nb-heading {
  font-family: "Cormorant Garamond", "Noto Serif TC", serif !important;
  color: var(--codex-burgundy) !important;
  letter-spacing: .5px;
  border-bottom: 1.5px solid rgba(122,34,48,.3) !important;
  padding-bottom: 8px;
}
body[data-page="education"] .nb-heading::after { background: none !important; }
body[data-page="education"] .nb-subtle {
  font-style: italic;
  color: var(--codex-ink-soft) !important;
  font-size: 1.02rem !important;
}

/* ── 正文：襯線、墨色、寬鬆行距 ── */
body[data-page="education"] .edu-article-body {
  /* 衛教內文用手寫體更生動（章名仍維持襯線紅字，對齊圖 2 印刷標題） */
  font-family: var(--codex-hand) !important;
  color: var(--codex-ink) !important;
  font-size: 1.12rem !important;
  line-height: 2.0 !important;
  text-align: justify;
  letter-spacing: .2px;
}

/* 章節標題（# → h2，## → h3，### → h4）→ 章首樣式 + 飾紋 */
body[data-page="education"] .edu-article-body h2,
body[data-page="education"] .edu-article-body h3,
body[data-page="education"] .edu-article-body h4 {
  font-family: "Cormorant Garamond", "Noto Serif TC", serif !important;
  color: var(--codex-burgundy) !important;
  text-align: center !important;
  letter-spacing: 1px;
  margin: 26px 0 14px !important;
  position: relative;
}
body[data-page="education"] .edu-article-body h2 { font-size: 1.55rem !important; }
body[data-page="education"] .edu-article-body h3 { font-size: 1.3rem !important; }
body[data-page="education"] .edu-article-body h4 { font-size: 1.12rem !important; color: var(--codex-burg-2) !important; }
/* 章首飾紋 ❦ */
body[data-page="education"] .edu-article-body h2::before,
body[data-page="education"] .edu-article-body h3::before {
  content: "❦";
  display: block;
  color: var(--codex-gold);
  font-size: .9rem;
  margin-bottom: 4px;
  opacity: .8;
}
/* 章節下細分隔線 */
body[data-page="education"] .edu-article-body h2::after {
  content: "";
  display: block; width: 120px; height: 0;
  margin: 8px auto 0;
  border-bottom: 1.5px solid rgba(122,34,48,.4);
}

/* 重點概念：strong → 墨痕底線高亮 */
body[data-page="education"] .edu-article-body strong {
  color: var(--codex-burgundy) !important;
  font-weight: 700;
  background: linear-gradient(180deg, transparent 62%, rgba(156,123,63,.28) 62%);
  padding: 0 1px;
}
body[data-page="education"] .edu-article-body em {
  color: var(--codex-ink-soft) !important;
  font-style: italic;
}
body[data-page="education"] .edu-article-body li { list-style: none !important; position: relative; padding-left: 22px; margin-left: 0 !important; }
body[data-page="education"] .edu-article-body li::before {
  content: "❧"; position: absolute; left: 2px; color: var(--codex-gold); font-size: .85em;
}

/* 首字下沉（JS 包 .codex-dropcap）— 蝕刻「初模框」：boxed engraving initial，
   對齊古版書章首大寫字母被細墨線框 + 米紙底襯的傳統（畫風支柱 1/6）。 */
body[data-page="education"] .codex-dropcap {
  float: left;
  font-family: "Cormorant Garamond", serif;
  font-size: 3rem;
  line-height: 1;
  margin: 4px 12px 2px 0;
  padding: 8px 12px;
  color: var(--codex-burgundy);
  font-weight: 700;
  border: 1.4px solid var(--codex-ink);
  background: linear-gradient(160deg, #f4ead0, #ecdcb4);
  box-shadow: 2px 2px 0 rgba(58,42,30,.16);
}

/* 文章內插圖 → 仿古銅版蝕刻（去彩、加墨框） */
body[data-page="education"] .edu-article-body img {
  filter: sepia(.55) contrast(1.05) brightness(.98) grayscale(.35);
  border: 1.5px solid var(--codex-ink);
  border-radius: 2px;
  box-shadow: 3px 3px 0 rgba(58,42,30,.18);
  background: #f3ead2;
  padding: 6px;
}

/* ── 章節書籤（JS 注入左頁 .codex-toc）── */
body[data-page="education"] .codex-toc {
  margin-top: 16px;
  border-top: 1.5px solid rgba(122,34,48,.25);
  padding-top: 10px;
}
body[data-page="education"] .codex-toc-title {
  font-family: "Cormorant Garamond", "Noto Serif TC", serif;
  color: var(--codex-gold);
  font-size: .9rem; letter-spacing: 2px; margin-bottom: 8px;
}
body[data-page="education"] .codex-bm {
  display: block; width: 100%; text-align: left;
  font-family: "Cormorant Garamond", "Noto Serif TC", serif;
  background: linear-gradient(90deg, rgba(122,34,48,.10), transparent);
  border: none; border-left: 3px solid var(--codex-burgundy);
  color: var(--codex-ink); cursor: pointer;
  padding: 7px 10px; margin-bottom: 5px; border-radius: 0 6px 6px 0;
  font-size: 1rem; line-height: 1.35;
  transition: background .15s, transform .15s;
}
body[data-page="education"] .codex-bm:hover { background: linear-gradient(90deg, rgba(122,34,48,.2), transparent); transform: translateX(2px); }
body[data-page="education"] .codex-bm-h3 { padding-left: 20px; font-size: .94rem; color: var(--codex-ink-soft); border-left-color: var(--codex-gold); }
body[data-page="education"] .codex-bm-h4 { padding-left: 30px; font-size: .9rem; color: var(--codex-ink-soft); border-left-color: rgba(156,123,63,.5); }

/* ── 文獻出處 → 研究註記（依賴既有 inline 結構，這裡只柔化容器）── */
body[data-page="education"] .edu-article-body ol li {
  font-family: "Noto Sans TC", sans-serif !important;  /* 註記用無襯線保可讀 */
}

/* ════ 全域元件（JS 動態建立；以 body.codex-reading 控制顯示）════ */
/* 閱讀進度條 */
#codex-progress {
  position: fixed; top: 0; left: 0; right: 0; height: 4px;
  background: rgba(122,34,48,.12); z-index: 1200;
  opacity: 0; transition: opacity .25s; pointer-events: none;
}
#codex-progress.show { opacity: 1; }
#codex-progress i {
  display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, var(--codex-burgundy), var(--codex-gold));
}
body:not(.codex-reading) #codex-progress { opacity: 0 !important; }

/* 詞彙彈窗（glossary） */
body[data-page="education"] .codex-term {
  border-bottom: 1.5px dotted var(--codex-burgundy);
  cursor: help;
  color: inherit;
}
.codex-gloss-pop {
  position: absolute; z-index: 1300; max-width: 260px;
  font-family: "Noto Sans TC", sans-serif;
  background:
    radial-gradient(rgba(120,90,50,.06) .6px, transparent .9px),
    linear-gradient(160deg, #f6ecd2, #ecdcb6);
  background-size: 7px 7px, 100% 100%;
  border: 1.5px solid var(--codex-edge);
  border-radius: 8px;
  box-shadow: 0 8px 22px -8px rgba(40,28,14,.5);
  padding: 10px 12px;
  animation: codexPop .18s ease both;
}
@keyframes codexPop { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.codex-gloss-term { font-weight: 700; color: var(--codex-burgundy); font-size: .9rem; margin-bottom: 4px; }
.codex-gloss-def { color: var(--codex-ink); font-size: .82rem; line-height: 1.6; }

/* 開書時的翻頁感（淡入 + 輕微立體） */
body[data-page="education"] #edu-stage-notebook.active .notebook { animation: codexOpen .4s ease both; }
@keyframes codexOpen { from { opacity: 0; transform: perspective(1400px) rotateY(-4deg); } to { opacity: 1; transform: none; } }

/* 無障礙：減少動態 */
@media (prefers-reduced-motion: reduce) {
  body[data-page="education"] #edu-stage-notebook.active .notebook,
  .codex-gloss-pop { animation: none !important; }
}

/* ════════════════════════════════════════════════════════════
   翻頁書本閱讀器（古董書，點開書本彈出）
   ════════════════════════════════════════════════════════════ */
body.codex-reader-open { overflow: hidden; }

.codex-reader {
  position: fixed; inset: 0; z-index: 1400;
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) 6px env(safe-area-inset-bottom);
  /* 暗色木桌 */
  background:
    radial-gradient(ellipse at 50% -8%, rgba(70,48,24,.30), transparent 60%),
    repeating-linear-gradient(90deg, rgba(0,0,0,.10) 0 2px, transparent 2px 26px),
    linear-gradient(180deg, #2c1f15 0%, #20160e 100%);
  animation: codexBookIn .42s cubic-bezier(.2,.9,.3,1.1) both;
}
@keyframes codexBookIn {
  from { opacity: 0; transform: scale(.86) translateY(12px); }
  to   { opacity: 1; transform: none; }
}

.codex-reader-bar {
  display: flex; align-items: center; gap: 10px; padding: 8px 8px 6px;
  color: #efe0bd; font-family: "Cormorant Garamond","Noto Serif TC",serif;
}
.codex-reader-title { flex: 1; text-align: center; font-size: 1.05rem; letter-spacing: .5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.codex-rbtn { background: rgba(255,255,255,.07); border: 1px solid rgba(239,224,189,.28);
  color: #efe0bd; width: 38px; height: 38px; border-radius: 10px; font-size: 1.05rem; cursor: pointer; }
.codex-rbtn:active { transform: scale(.94); }

.codex-book { flex: 1; min-height: 0; display: flex; padding: 4px 2px; }

/* 一頁書葉（古紙 + 破墨邊框 + 書脊陰影） */
.codex-reader-stage {
  position: relative; flex: 1; min-height: 0; border-radius: 5px 7px 6px 5px;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 0% 0%, rgba(120,80,30,.16), transparent 24%),
    radial-gradient(ellipse at 100% 100%, rgba(120,80,30,.20), transparent 26%),
    radial-gradient(rgba(120,90,50,.06) .6px, transparent .9px),
    linear-gradient(165deg, #f0e4c6 0%, #e6d3a8 100%);
  background-size: auto, auto, 7px 7px, 100% 100%;
  /* 紙張堆疊感：右／下緣疊出多層紙邊，像一疊厚筆記本（對齊參考圖的仿真筆記本）。 */
  box-shadow:
    3px 4px 0 -1px #ece0bf, 6px 8px 0 -1px #e4d5ac,
    10px 13px 0 -1px #d9c89a, 14px 19px 0 -1px #cdba86,
    0 22px 52px -12px rgba(0,0,0,.7),
    inset 0 0 0 1px rgba(255,250,235,.5);
}
/* 破墨邊框（SVG turbulence 手繪感：外黑內暗紅） */
.codex-reader-stage::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 4;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 300 440' preserveAspectRatio='none'%3E%3Cdefs%3E%3Cfilter id='r'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.012 0.02' numOctaves='3' seed='6' result='n'/%3E%3CfeDisplacementMap in='SourceGraphic' in2='n' scale='10'/%3E%3C/filter%3E%3C/defs%3E%3Cg filter='url(%23r)' fill='none'%3E%3Crect x='9' y='9' width='282' height='422' stroke='%231a1310' stroke-width='8'/%3E%3Crect x='17' y='17' width='266' height='406' stroke='%237a2230' stroke-width='3'/%3E%3C/g%3E%3C/svg%3E");
  background-size: 100% 100%; background-repeat: no-repeat;
}
/* 書脊（左緣內陰影，暗示是攤開的書） */
.codex-spine {
  position: absolute; top: 0; bottom: 0; left: 0; width: 26px; z-index: 3; pointer-events: none;
  background: linear-gradient(90deg, rgba(60,40,20,.34), rgba(60,40,20,0));
}

/* 內容流（多欄分頁） */
.codex-reader-flow {
  position: relative; z-index: 2;
  box-sizing: border-box; padding: 26px 26px 30px 34px;
  will-change: transform;
}
/* 章節標題仿古書「第X章」紅字（沿用 .edu-article-body 既有 codex 樣式，再加強） */
body[data-page="education"] .codex-reader-flow h2 { font-size: 1.7rem !important; margin-top: 6px !important; }
.codex-reader-flow .codex-dropcap { font-size: 3.6rem; }

/* 頁碼（書葉底部置中，像古書的頁碼） */
.codex-folio {
  position: absolute; left: 0; right: 0; bottom: 8px; z-index: 5; text-align: center;
  font-family: "Cormorant Garamond","Noto Serif TC",serif; color: #6a4a2a; font-size: .95rem; letter-spacing: 1px;
}

/* 左右翻頁感應區 */
.codex-edge { position: absolute; top: 0; bottom: 0; width: 30%; background: transparent; border: none; cursor: pointer; z-index: 5; }
.codex-edge.prev { left: 0; } .codex-edge.next { right: 0; }

/* 翻頁時書葉輕微立體 */
.codex-reader.turning .codex-reader-stage { animation: codexTurn .45s ease; }
@keyframes codexTurn { 0% { transform: perspective(1600px) rotateY(-2.5deg); } 100% { transform: none; } }

/* 進度 + 控制列 */
.codex-pagebar { height: 4px; margin: 6px 12px 0; background: rgba(239,224,189,.16); border-radius: 3px; overflow: hidden; }
.codex-pagebar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--codex-burgundy), var(--codex-gold)); transition: width .3s; }
.codex-reader-foot { display: flex; align-items: center; gap: 10px; padding: 8px 12px 4px;
  color: #e9dcbb; font-family: "Cormorant Garamond","Noto Serif TC",serif; }
.codex-fbtn { background: rgba(255,255,255,.06); border: 1px solid rgba(239,224,189,.26);
  color: #efe0bd; padding: 9px 14px; border-radius: 11px; font-size: .95rem; cursor: pointer; }
.codex-fbtn:active { transform: scale(.96); }
.codex-pageno { flex: 1; text-align: center; letter-spacing: 1px; font-size: 1rem; }

/* 章節抽屜 */
.codex-toc-drawer {
  position: absolute; top: 52px; left: 12px; right: 12px; max-height: 62%; overflow: auto; z-index: 8;
  background: linear-gradient(160deg, #f6ecd2, #ecdcb6); border: 1.5px solid var(--codex-edge);
  border-radius: 10px; padding: 12px; box-shadow: 0 18px 44px -10px rgba(0,0,0,.6);
}

/* 浮動「翻頁閱讀」按鈕 */
#codex-open-btn {
  position: fixed; right: 16px; bottom: 86px; z-index: 1150; display: none;
  background: linear-gradient(180deg, var(--codex-burg-2), var(--codex-burgundy));
  color: #f7ecd0; border: 1.5px solid rgba(40,20,16,.55);
  padding: 11px 16px; border-radius: 24px;
  font-family: "Noto Serif TC", serif; font-size: .92rem;
  box-shadow: 0 8px 20px -6px rgba(0,0,0,.5); cursor: pointer;
}
#codex-open-btn.show { display: inline-flex; }
body.codex-reader-open #codex-open-btn { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  .codex-reader, .codex-reader.turning .codex-reader-stage { animation: none !important; }
}

/* ── 整頁古典插圖（扉頁 + 各章插圖頁）──────────────────────── */
.codex-frontis, .codex-plate {
  margin: 0; text-align: center;
  break-inside: avoid; -webkit-column-break-inside: avoid;
  break-after: column; -webkit-column-break-after: always; page-break-after: always;
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  min-height: 86%;
}
/* 每章插圖自成一頁（整頁插圖頁，對齊圖 2「左頁插圖／右頁文字」） */
.codex-plate {
  break-before: column; -webkit-column-break-before: always;
}
/* 左頁對齊用的空白欄（JS 在對開模式視需要插入，把插圖推到左頁） */
.codex-col-spacer {
  height: 100%; min-height: 86%;
  break-after: column; -webkit-column-break-after: always;
  break-inside: avoid; -webkit-column-break-inside: avoid;
}
.codex-plate-art {
  position: relative;
  display: inline-block; padding: 16px;
  border: none; border-radius: 1px;
  box-shadow: 3px 3px 0 rgba(58,42,30,.20);
  max-width: 92%;
  /* 加強排線材質：暖米底 + 斜向細排線（45° hatching）做出蝕刻紙的手感 */
  background:
    repeating-linear-gradient(45deg, rgba(58,42,30,.06) 0 1px, transparent 1px 5px),
    #f1e7cd;
}
/* 破墨雙線蝕刻框（feTurbulence 手繪抖動：外粗內細）— 取代乾淨的向量直線框，
   對齊銅版書插圖的破墨手繪邊框（畫風支柱 5）。 */
.codex-plate-art::before {
  content: ""; position: absolute; inset: 5px; pointer-events: none; z-index: 1;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 300 380' preserveAspectRatio='none'%3E%3Cdefs%3E%3Cfilter id='e'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.014 0.03' numOctaves='3' seed='4' result='n'/%3E%3CfeDisplacementMap in='SourceGraphic' in2='n' scale='6'/%3E%3C/filter%3E%3C/defs%3E%3Cg filter='url(%23e)' fill='none' stroke='%232a1d12'%3E%3Crect x='6' y='6' width='288' height='368' stroke-width='3'/%3E%3Crect x='12' y='12' width='276' height='356' stroke-width='1'/%3E%3C/g%3E%3C/svg%3E");
  background-size: 100% 100%; background-repeat: no-repeat;
}
.codex-plate-art svg {
  position: relative; z-index: 2;
  display: block; width: 100%; height: auto; max-height: 46vh;
  /* 桌機＝古董書：維持銅版雕刻單色（sepia 去彩 + 紅 spot color）。
     手機＝筆記本：在下方 media query 改高飽和（暖色插畫）。 */
  filter: sepia(.42) contrast(1.06) brightness(.99);
}
.codex-plate figcaption {
  margin-top: 10px; color: var(--codex-ink-soft);
  font-family: "Cormorant Garamond","Noto Serif TC",serif;
  font-size: .9rem; letter-spacing: 3px;
}
.codex-frontis-eyebrow {
  margin-top: 16px; color: var(--codex-gold);
  font-family: "Cormorant Garamond","Noto Serif TC",serif;
  letter-spacing: 7px; font-size: .82rem;
}
.codex-frontis-rule { width: 64px; height: 0; border-top: 1.5px solid rgba(122,34,48,.5); margin: 8px auto; }
.codex-frontis-title {
  font-family: "Cormorant Garamond","Noto Serif TC",serif;
  color: var(--codex-burgundy); font-size: 1.9rem; line-height: 1.25;
  letter-spacing: 1px; padding: 0 10px;
}

/* ════════════════════════════════════════════════════════════
   手機版「活頁筆記本」（≤ 767px）
   — 桌機端維持古董書原樣，僅手機切換為活頁筆記本 UI；
     貼紙與圓點 indicator 在桌機由 CSS 隱藏。
   ════════════════════════════════════════════════════════════ */

/* 書籤貼紙與底部圓點 indicator：桌機完全不顯示 */
@media (min-width: 768px) {
  .codex-bookmark-sticker,
  .codex-dots { display: none !important; }

  /* 書本實體感：四周留出桌面、書葉外加皮革封面／裝訂邊（圖 2 的書本物件感） */
  .codex-book { padding: 14px 46px 6px; }
  .codex-reader-stage {
    box-shadow:
      0 0 0 9px #2a1d12, 0 0 0 12px #1a120c,                 /* 皮革封面邊 + 暗裝訂 */
      3px 4px 0 9px #ece0bf, 7px 9px 0 9px #e0d0a4,          /* 露出的書頁厚度 */
      0 26px 60px -14px rgba(0,0,0,.78),
      inset 0 0 0 1px rgba(255,250,235,.5);
  }
  /* 對開兩頁的中央書脊（左右兩頁交界的內凹陰影） */
  .codex-spine {
    left: 50%; right: auto; transform: translateX(-50%); width: 48px;
    background: linear-gradient(90deg,
      rgba(60,40,20,0) 0%, rgba(60,40,20,.06) 32%,
      rgba(60,40,20,.34) 50%, rgba(60,40,20,.06) 68%, rgba(60,40,20,0) 100%);
  }
  /* 桌機插圖更純的單色雕刻（圖 2 的銅版黑白線畫） */
  .codex-plate-art svg { filter: grayscale(.55) sepia(.3) contrast(1.1) brightness(.98); }

  /* 翻頁葉（3D）：next 從書脊往左翻、prev 從書脊往右翻 */
  .codex-leaf {
    position: absolute; top: 0; bottom: 0; width: 50%; z-index: 6; pointer-events: none;
    background: linear-gradient(90deg, #e7d9b4 0%, #f1e5c7 60%, #f3e8ca 100%);
    box-shadow: 0 0 34px rgba(60,40,20,.28);
    backface-visibility: hidden;
  }
  .codex-leaf.turn-next { right: 0; transform-origin: left center;
    animation: codexLeafNext .6s cubic-bezier(.36,.1,.2,1) forwards; }
  .codex-leaf.turn-prev { left: 0; transform-origin: right center;
    animation: codexLeafPrev .6s cubic-bezier(.36,.1,.2,1) forwards; }
  @keyframes codexLeafNext {
    0%   { transform: perspective(1700px) rotateY(0deg); }
    100% { transform: perspective(1700px) rotateY(-172deg); }
  }
  @keyframes codexLeafPrev {
    0%   { transform: perspective(1700px) rotateY(0deg); }
    100% { transform: perspective(1700px) rotateY(172deg); }
  }
}
@media (prefers-reduced-motion: reduce) { .codex-leaf { display: none !important; } }

@media (max-width: 767px) {
  /* 書葉外觀：左留位給打孔釘環、角更柔、不需要破墨 SVG 邊框（手機螢幕太小、易雜訊） */
  .codex-reader-stage {
    margin: 22px 14px 0 22px;
    border-radius: 8px 12px 12px 6px;
    /* 右／下緣疊紙（紙張堆疊感）+ 左緣釘環內陰影 */
    box-shadow:
      3px 4px 0 -1px #ece0bf, 6px 8px 0 -1px #e3d4ab, 9px 12px 0 -1px #d6c597,
      0 18px 50px -12px rgba(0,0,0,.7),
      inset 14px 0 22px -14px rgba(60,40,20,.32),
      inset 0 0 0 1px rgba(255,250,235,.5);
  }
  .codex-reader-stage::after { display: none; }     /* 關掉破墨邊框，讓筆記本感更乾淨 */
  .codex-spine { display: none; }                   /* 書脊在手機不適合 */

  /* 左側 5 個打孔釘環（pure CSS：黑色金屬釘 + 內凹高光） */
  .codex-reader-stage::before {
    content: "";
    position: absolute;
    left: -12px; top: 8%; bottom: 8%;
    width: 14px;
    pointer-events: none;
    z-index: 5;
    background-image:
      radial-gradient(circle at 50% 10%,  #0e0a06 0 4.5px, rgba(60,40,20,.35) 5px 6.5px, transparent 7px),
      radial-gradient(circle at 50% 32.5%, #0e0a06 0 4.5px, rgba(60,40,20,.35) 5px 6.5px, transparent 7px),
      radial-gradient(circle at 50% 55%,   #0e0a06 0 4.5px, rgba(60,40,20,.35) 5px 6.5px, transparent 7px),
      radial-gradient(circle at 50% 77.5%, #0e0a06 0 4.5px, rgba(60,40,20,.35) 5px 6.5px, transparent 7px),
      radial-gradient(circle at 50% 100%,  #0e0a06 0 4.5px, rgba(60,40,20,.35) 5px 6.5px, transparent 7px);
    background-repeat: no-repeat;
    filter: drop-shadow(1px 1px 0 rgba(255,250,235,.45)) drop-shadow(0 1px 2px rgba(0,0,0,.4));
  }

  /* 上方書籤貼紙 — 米黃紙條 + 醫療圖示，輕微旋轉、貼紙撕角陰影 */
  .codex-bookmark-sticker {
    position: absolute;
    top: -10px; right: 28px;
    width: 50px; height: 62px;
    z-index: 7;
    background:
      linear-gradient(180deg, #f6e9c2 0%, #ecdba6 100%);
    border: 1px solid rgba(120,90,40,.32);
    border-radius: 2px 2px 3px 3px;
    box-shadow:
      2px 5px 9px rgba(0,0,0,.28),
      inset 0 -6px 10px rgba(120,90,40,.16);
    transform: rotate(-3.5deg);
    display: flex; align-items: center; justify-content: center;
  }
  .codex-bookmark-sticker .lucide,
  .codex-bookmark-sticker svg {
    width: 24px; height: 24px;
    color: var(--codex-burgundy);
    stroke-width: 2.2;
    filter: drop-shadow(0 1px 1px rgba(0,0,0,.18));
  }
  /* 貼紙底部撕痕（兩條斜陰影模擬撕開的紙邊） */
  .codex-bookmark-sticker::after {
    content: ""; position: absolute;
    left: -1px; right: -1px; bottom: -3px; height: 4px;
    background:
      linear-gradient(transparent 40%, rgba(120,90,40,.28) 41% 55%, transparent 56%),
      linear-gradient(135deg, transparent 0 40%, rgba(0,0,0,.12) 41% 45%, transparent 46%);
    background-size: 100% 100%, 6px 4px;
    background-repeat: no-repeat, repeat-x;
  }

  /* 進度條改為圓點 indicator（既有 pagebar 還是保留為底層輔助） */
  .codex-pagebar {
    height: 2px;                                    /* 變細，幾乎不搶戲 */
    margin: 4px 36px 0;
    opacity: .55;
  }
  .codex-dots {
    display: flex; gap: 7px; justify-content: center;
    padding: 8px 0 2px;
    min-height: 16px;
  }
  .codex-dot {
    width: 6px; height: 6px; border-radius: 50%;
    background: rgba(239,224,189,.32);
    transition: transform .25s ease, background-color .25s ease;
  }
  .codex-dot.active {
    background: var(--codex-gold);
    transform: scale(1.55);
    box-shadow: 0 0 0 2px rgba(156,123,63,.25);
  }

  /* 控制列在手機略小一點，騰出空間給圓點 */
  .codex-fbtn { padding: 7px 12px; font-size: .9rem; }

  /* 手機＝暖色筆記本：插圖改高飽和（拿掉桌機的 sepia 去彩），讓彩色插畫跳出來 */
  .codex-plate-art svg { filter: contrast(1.08) saturate(1.18); }
}
