/* 勇博講古：宣紙底、墨色字、朱紅印章 */
:root {
  --bg: #f5efe3;          /* 宣紙 */
  --surface: #fbf7ef;
  --text: #2b2520;        /* 墨 */
  --muted: #776b5d;
  --line: #e2d7c3;
  --accent: #b23a26;      /* 朱紅 */
  --accent-soft: #f3dfd6;
  --share: #3f6b5c;       /* 好文分享用的青綠 */
  --share-soft: #dfe9e2;
  --seal-text: #fbf3e8;
  --shadow: 0 1px 0 rgba(80, 60, 30, .06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1815; --surface: #24201c; --text: #ece3d4; --muted: #a69888;
    --line: #3a332c; --accent: #e0775f; --accent-soft: #3a2520;
    --share: #8cc0aa; --share-soft: #22322b; --seal-text: #1b1815;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #1b1815; --surface: #24201c; --text: #ece3d4; --muted: #a69888;
  --line: #3a332c; --accent: #e0775f; --accent-soft: #3a2520;
  --share: #8cc0aa; --share-soft: #22322b; --seal-text: #1b1815;
  --shadow: none;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 80px; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.8 "Noto Sans TC", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
h1, h2, h3 { font-family: "Noto Serif TC", serif; line-height: 1.35; font-weight: 600; }
[hidden] { display: none !important; }

/* 印章：四個字由右上往下、再換左行，跟傳統印章讀法一樣 */
.seal {
  display: inline-grid; place-items: center;
  width: 2.6em; height: 2.6em; padding: .15em;
  writing-mode: vertical-rl; text-orientation: upright;
  background: var(--accent); color: var(--seal-text);
  font: 900 15px/1.05 "Noto Serif TC", serif; letter-spacing: 0;
  border-radius: 4px;
  box-shadow: inset 0 0 0 2px var(--accent), inset 0 0 0 3.5px var(--seal-text);
}
.seal-lg { font-size: 54px; border-radius: 10px; transform: rotate(-4deg);
  box-shadow: inset 0 0 0 6px var(--accent), inset 0 0 0 9px var(--seal-text); }

/* 導覽列 */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 20px;
  padding: 10px max(16px, calc((100% - 1080px) / 2));
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand .seal { font-size: 13px; }
.brand-name { font: 700 20px "Noto Serif TC", serif; letter-spacing: .08em; }
.topbar nav { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.topbar nav a { color: var(--muted); font-size: 15px; padding: 4px 10px; border-radius: 6px; }
.topbar nav a:hover { color: var(--text); text-decoration: none; background: var(--surface); }
.topbar nav a[aria-current="page"] { color: var(--accent); font-weight: 500; }
.theme-toggle {
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 999px; width: 34px; height: 34px; cursor: pointer; font-size: 16px; flex: none;
}

main { max-width: 1080px; margin: 0 auto; padding: 0 16px; }
section { padding: 48px 0; }
h2 { font-size: 24px; margin: 0; }
.section-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin-bottom: 20px; padding-bottom: 10px; border-bottom: 2px solid var(--text);
}
.section-head a { font-size: 14px; color: var(--muted); }
.section-head a:hover { color: var(--accent); }

.btn { display: inline-block; padding: 8px 20px; border-radius: 999px; background: var(--accent); color: var(--seal-text);
  font-size: 15px; border: 1px solid var(--accent); }
.btn:hover { text-decoration: none; opacity: .9; }
.btn.ghost { background: transparent; color: var(--accent); }

/* 首頁主視覺 */
.hero {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 32px;
  padding: 72px 0 56px; border-bottom: 1px solid var(--line);
}
.eyebrow { color: var(--accent); font-size: 15px; letter-spacing: .2em; margin: 0; }
.hero h1 { font: 900 clamp(52px, 10vw, 96px)/1.1 "Noto Serif TC", serif; margin: 12px 0 16px; letter-spacing: .06em; }
.hero h1 span { color: var(--accent); }
.tagline { font: 400 clamp(18px, 2.4vw, 22px)/1.7 "Noto Serif TC", serif; color: var(--muted); margin: 0 0 28px; max-width: 32em; }
.hero-links { display: flex; gap: 12px; flex-wrap: wrap; margin: 0; }
.hero-seal { padding-right: 24px; }

/* 首頁：文章（主）＋側欄 */
.home-main { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 56px; border-bottom: 1px solid var(--line); }
.home-side { padding: 48px 0; display: flex; flex-direction: column; gap: 40px; }
.side-block { padding: 0; }
.about-card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 20px 22px; box-shadow: var(--shadow); }
.about-card h2 { font-size: 18px; margin-bottom: 6px; }
.about-card p { margin: 0 0 10px; color: var(--muted); font-size: 15px; }
.about-card a { font-size: 14px; }

/* 文章列表 */
.entries { list-style: none; margin: 0; padding: 0; }
.entry {
  display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 20px;
  padding: 20px 0; border-bottom: 1px dashed var(--line);
}
.entry:last-child { border-bottom: 0; }
.entry time { font: 400 15px "Noto Serif TC", serif; color: var(--muted); padding-top: 2px; font-variant-numeric: tabular-nums; }
.kind { margin: 0; font-size: 13px; color: var(--accent); letter-spacing: .08em; }
.kind.is-share { color: var(--share); }
.entry h3 { margin: 2px 0 6px; font-size: 21px; }
.entry h3 a { color: var(--text); }
.entry h3 a:hover { color: var(--accent); text-decoration: none; }
.summary { margin: 0; color: var(--muted); font-size: 15px; }
.list-page { max-width: 760px; padding-bottom: 64px; }

/* 教學列表 */
.lessons { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.lesson a {
  display: flex; flex-direction: column; gap: 2px; color: var(--text);
  padding: 14px 16px; border-left: 3px solid var(--accent); background: var(--surface);
  border-radius: 0 8px 8px 0; transition: transform .15s;
}
.lesson a:hover { text-decoration: none; transform: translateX(3px); }
.lesson-meta { font-size: 13px; color: var(--accent); }
.lesson-title { font: 600 17px/1.5 "Noto Serif TC", serif; }
.lesson-sum { font-size: 14px; color: var(--muted); }
.lessons.list-page { gap: 14px; }
.lessons.list-page .lesson a { padding: 18px 22px; }
.lessons.list-page .lesson-title { font-size: 20px; }

/* AI 作品、遊戲卡片 */
.lab + .lab { padding-top: 8px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 20px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column;
  color: var(--text); transition: transform .15s, border-color .15s;
}
a.card:hover { transform: translateY(-3px); border-color: var(--accent); text-decoration: none; }
.card .thumb { aspect-ratio: 16 / 10; width: 100%; object-fit: cover; display: grid; place-items: center;
  background: repeating-linear-gradient(135deg, var(--accent-soft) 0 10px, color-mix(in srgb, var(--accent-soft) 70%, var(--surface)) 10px 20px); }
.card .thumb span { font: 900 40px "Noto Serif TC", serif; color: var(--accent); }
.card .body { padding: 14px 18px 20px; }
.card h3 { margin: 8px 0 4px; font-size: 18px; }
.card p { margin: 0; color: var(--muted); font-size: 14px; }
.card .tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tag { background: var(--accent-soft); color: var(--accent); padding: 1px 10px; border-radius: 999px; font-size: 13px; }

/* 篩選按鈕 */
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.filters button {
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  padding: 4px 14px; border-radius: 999px; cursor: pointer; font: inherit; font-size: 14px;
}
.filters button[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: var(--bg); }

/* 列表頁標題 */
.page-head { padding: 56px 0 24px; max-width: 760px; }
.page-head h1 { font-size: clamp(34px, 6vw, 48px); margin: 0 0 6px; font-weight: 900; letter-spacing: .04em; }
.lead { color: var(--muted); font-size: 17px; margin: 0 0 18px; }
main > .grid, main > .papers { padding-bottom: 64px; }

/* 內頁：閱讀版面 */
.reading { max-width: 720px; margin: 0 auto; padding: 40px 0 72px; }
.detail.wide { max-width: 960px; margin: 0 auto; padding: 40px 0 72px; }
.crumb { margin: 0 0 28px; font-size: 14px; }
.crumb a { color: var(--muted); }
.reading-head { padding-bottom: 24px; margin-bottom: 28px; border-bottom: 1px solid var(--line); }
.reading h1, .detail h1 { font-size: clamp(30px, 5vw, 42px); font-weight: 900; margin: 8px 0 14px; }
.reading-head .lead { margin: 0; font-size: 18px; }
.source {
  display: flex; align-items: center; gap: 12px; margin: 0 0 28px; padding: 14px 18px;
  background: var(--share-soft); color: var(--text); border-radius: 10px;
}
.source:hover { text-decoration: none; filter: brightness(.98); }
.source-label { font-size: 13px; color: var(--share); white-space: nowrap; }
.source-name { font-weight: 500; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.downloads { list-style: none; padding: 0; margin: 0 0 28px; display: flex; gap: 10px; flex-wrap: wrap; }

.prose { font: 400 18px/2 "Noto Serif TC", serif; }
.prose h1 { font-size: clamp(30px, 5vw, 42px); font-weight: 900; margin: 0 0 20px; }
.prose h2 { font-size: 24px; margin: 44px 0 12px; }
.prose h3 { font-size: 20px; margin: 32px 0 8px; }
.prose p { margin: 0 0 1.2em; }
.prose img { max-width: 100%; border-radius: 8px; }
.prose blockquote { margin: 1.5em 0; padding: 4px 0 4px 20px; border-left: 3px solid var(--accent); color: var(--muted); }
.prose code { font-size: .88em; background: var(--surface); padding: 1px 6px; border-radius: 4px; }
.prose li { margin: 4px 0; }

/* 學術著作 */
.about-papers { margin-top: 32px; }
.papers { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; max-width: 860px; }
.paper {
  display: grid; grid-template-columns: 64px 1fr; gap: 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px 20px;
}
.paper .yr { font: 600 18px "Noto Serif TC", serif; color: var(--accent); }
.paper h3 { margin: 0 0 4px; font-size: 17px; line-height: 1.5; }
.paper h3 a { color: var(--text); }
.paper .meta { color: var(--muted); font-size: 14px; margin: 0; }
.paper .actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 8px; font-size: 14px; align-items: center; }
.detail .meta { color: var(--muted); }
.detail .actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 16px 0; }
.abstract { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px 20px; margin: 24px 0; }
.abstract h2 { font-size: 18px; margin-bottom: 4px; }
.abstract p { margin: 0; }
.cover { width: 100%; border-radius: 12px; margin: 8px 0 16px; }
.game-frame { aspect-ratio: 4 / 5; max-height: 80vh; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin: 16px 0 8px; }
.game-frame iframe { width: 100%; height: 100%; border: 0; display: block; }
.app-frame { height: min(78vh, 720px); min-height: 480px; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin: 8px 0; }
.app-frame iframe { width: 100%; height: 100%; border: 0; display: block; }

/* 頁尾 */
.footer { border-top: 1px solid var(--line); margin-top: 24px; padding: 40px 16px 24px; color: var(--muted); font-size: 14px; }
.footer-inner { max-width: 1080px; margin: 0 auto; display: flex; justify-content: space-between; gap: 24px; flex-wrap: wrap; }
.footer-inner p { margin: 0; }
.footer-name { font: 700 18px "Noto Serif TC", serif; color: var(--text); letter-spacing: .08em; }
.footer ul { list-style: none; padding: 0; margin: 0; display: flex; gap: 20px; flex-wrap: wrap; }
.footer a { color: var(--muted); }
.footer a:hover { color: var(--accent); }
.copy { text-align: center; margin: 32px 0 0; font-size: 12px; }

@media (max-width: 860px) {
  .home-main { grid-template-columns: 1fr; gap: 0; }
  .home-side { padding-top: 0; }
}
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; gap: 8px 12px; }
  .brand-name { font-size: 18px; }
  .topbar nav { order: 3; width: 100%; margin: 0 -10px; gap: 0; flex-wrap: nowrap; overflow-x: auto; }
  .topbar nav a { white-space: nowrap; }
  .theme-toggle { margin-left: auto; }
  .hero { grid-template-columns: 1fr; padding: 48px 0 40px; }
  .hero-seal { display: none; }
  .entry { grid-template-columns: 1fr; gap: 2px; }
  .entry h3 { font-size: 19px; }
  .paper { grid-template-columns: 1fr; gap: 4px; }
  .prose { font-size: 17px; }
}
.detail.reading h1 { font-size: clamp(24px, 3.6vw, 32px); font-weight: 600; }
.empty { color: var(--muted); font: 400 17px/1.8 "Noto Serif TC", serif; padding: 24px 0 48px; margin: 0; }
.card .thumb.icon span { font: 400 56px/1 system-ui, "Apple Color Emoji", "Segoe UI Emoji", sans-serif; }
.grid.games { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.grid.games .thumb { aspect-ratio: 16 / 9; }
.grid.games .card p { font-size: 13px; }

/* 晚安故事：書架與翻頁播放器（固定用夜晚配色，不管網站深淺色） */
.night-head h1 { color: var(--text); }
.shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 24px 18px; padding-bottom: 64px; }
.book { display: flex; flex-direction: column; gap: 6px; color: var(--text); }
.book:hover { text-decoration: none; }
.book img { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 4px 10px 10px 4px; box-shadow: -4px 0 0 #00000022 inset, 0 6px 18px rgba(30, 30, 60, .18); transition: transform .2s; background: #1d2235; }
.book:hover img { transform: translateY(-4px) rotate(-1deg); }
.book-title { font: 600 15px/1.45 "Noto Serif TC", serif; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book-meta { font-size: 12px; color: var(--muted); }
.night-band { margin: 24px calc(50% - 50vw) 0; padding: 48px max(16px, calc(50vw - 540px)); background: #1d2235; color: #f1e9da; }
.night-band .section-head { border-color: #f1e9da; }
.night-band .section-head a, .night-band .book-meta { color: #b8b3c9; }
.night-band .book { color: #f1e9da; }
.shelf-row { grid-template-columns: repeat(5, minmax(120px, 1fr)); padding-bottom: 0; }
@media (max-width: 760px) { .shelf-row { grid-auto-flow: column; grid-template-columns: none; grid-auto-columns: 34%; overflow-x: auto; scroll-snap-type: x mandatory; } .shelf-row .book { scroll-snap-align: start; } }

.story { max-width: 1000px; margin: 0 auto; padding: 32px 0 64px; }
.story-head h1 { font-size: clamp(24px, 4vw, 34px); font-weight: 900; margin: 0 0 4px; }
.story-meta { color: var(--muted); margin: 0 0 20px; font-size: 14px; }
.reader { display: grid; grid-template-columns: minmax(0, auto) minmax(280px, 1fr); gap: 28px; align-items: center;
  background: #1d2235; color: #f1e9da; border-radius: 18px; padding: 22px; }
.stage-img { position: relative; height: min(76vh, 760px); aspect-ratio: 9 / 16; max-width: 100%; cursor: pointer; touch-action: pan-y; user-select: none; }
.spread { position: absolute; inset: 0; margin: 0; opacity: 0; transition: opacity .45s; pointer-events: none; }
.spread.on { opacity: 1; }
.spread img { width: 100%; height: 100%; object-fit: contain; border-radius: 12px; background: #141828; }
.story-text { font: 400 clamp(20px, 2.4vw, 26px)/1.9 "Noto Serif TC", serif; min-height: 7.6em; margin: 0 0 18px; letter-spacing: .02em; }
.story-progress { font-size: 13px; color: #b8b3c9; margin-bottom: 14px; }
.story-progress .bar { height: 4px; background: #343a55; border-radius: 4px; margin-top: 6px; overflow: hidden; }
.story-progress .bar i { display: block; height: 100%; width: 0; background: #e2b44f; transition: width .3s; }
.story-controls { display: flex; gap: 10px; }
.story-controls button { border: 1px solid #4a5175; background: #262c45; color: #f1e9da; border-radius: 999px; height: 48px; min-width: 48px; font: inherit; font-size: 16px; cursor: pointer; padding: 0 16px; }
.story-controls button.primary { flex: 1; background: #e2b44f; border-color: #e2b44f; color: #1d2235; font-weight: 700; }
.auto { display: block; margin-top: 12px; font-size: 14px; color: #b8b3c9; }
.fulltext { margin-top: 24px; }
.fulltext summary { cursor: pointer; color: var(--muted); }
@media (max-width: 760px) {
  .story { padding-top: 20px; }
  .reader { grid-template-columns: 1fr; padding: 12px; gap: 12px; margin: 0 -8px; }
  .stage-img { height: 44vh; width: 100%; aspect-ratio: auto; }
  .story-text { min-height: 5.4em; font-size: 18px; line-height: 1.8; margin-bottom: 6px; }
  .story-head h1 { font-size: 22px; }
  .story .crumb { margin-bottom: 12px; }
}

/* 文獻筆記 */
.paper-box { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0 0 24px; padding: 16px 20px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; font-size: 15px; }
.paper-box dt { color: var(--muted); }
.paper-box dd { margin: 0; overflow-wrap: anywhere; }
.paper-box .tag { display: inline-block; margin: 0 4px 4px 0; }
.study-card { margin: 0 0 28px; text-align: center; }
.study-card img { max-width: min(100%, 520px); border-radius: 10px; border: 1px solid var(--line); }
.study-card figcaption { font-size: 13px; color: var(--muted); margin-top: 6px; }
.note-disclaimer { font-size: 13px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 14px; margin-top: 40px; }
.kind.sec-stories { color: var(--blue, #3a6ea5); }
.kind.sec-notes { color: var(--share); }
.kind.sec-finance { color: #a07514; }

/* 勇博開講 */
.video { aspect-ratio: 16 / 9; border-radius: 12px; overflow: hidden; margin: 0 0 28px; background: #000; }
.video iframe { width: 100%; height: 100%; border: 0; display: block; }
.grid.episodes { padding-bottom: 24px; }

/* 廣告位 */
.ad-slot { margin: 36px 0; min-height: 100px; }
.tag.draft { background: var(--text); color: var(--bg); }
.draft-banner { background: #fff3cd; color: #6b4e00; border: 1px solid #e6c766; border-radius: 8px; padding: 10px 14px; font-size: 14px; }
.video.vertical { aspect-ratio: 9 / 16; max-width: 360px; margin-left: auto; margin-right: auto; }
.paged .over { display: none; }
.more-wrap { text-align: center; padding-bottom: 48px; }
.reading h1.en-title { font-family: "Noto Serif TC", Georgia, serif; font-size: clamp(24px, 3.4vw, 32px); font-weight: 600; }

/* AI 小工具：文獻下載小幫手 */
.tool { max-width: 820px; margin: 0 auto; padding: 40px 0 72px; }
.tool h1 { font-size: clamp(30px, 5vw, 42px); font-weight: 900; margin: 8px 0 14px; }
.tools-grid { padding-bottom: 64px; }
.pf-form { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; margin-bottom: 24px; }
.pf-form label[for] { display: block; font-size: 14px; color: var(--muted); margin-bottom: 8px; }
.pf-form textarea { width: 100%; font: 15px/1.6 ui-monospace, Menlo, monospace; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; resize: vertical; }
.pf-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 12px; }
.pf-actions button[disabled] { opacity: .45; cursor: default; }
.pf-file { cursor: pointer; }
.pf-status { color: var(--muted); font-size: 14px; }
.pf-summary { background: var(--share-soft); border-radius: 10px; padding: 12px 16px; margin-bottom: 16px; }
.pf-results { list-style: none; padding: 0; margin: 0 0 40px; display: grid; gap: 12px; }
.pf-item { border: 1px solid var(--line); border-left: 4px solid var(--line); border-radius: 0 10px 10px 0; padding: 14px 18px; background: var(--surface); }
.pf-item.is-pdf { border-left-color: var(--share); }
.pf-item.is-landing { border-left-color: #c08a1e; }
.pf-item.is-closed, .pf-item.is-notfound, .pf-item.is-error { border-left-color: var(--accent); }
.pf-item.is-loading { opacity: .6; }
.pf-state { margin: 0; font-size: 14px; font-weight: 500; }
.pf-src { color: var(--muted); font-weight: 400; margin-left: 8px; }
.pf-item h3 { margin: 4px 0; font: 600 17px/1.5 Georgia, "Noto Serif TC", serif; }
.pf-meta, .pf-note { margin: 0; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.pf-note { color: #a07514; }
.pf-links { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; margin: 10px 0 0; font-size: 14px; }
.pf-links .btn { padding: 5px 16px; font-size: 14px; }
.pf-help { font-size: 16px; }
.pf-help h2 { font-size: 20px; }
