/* Layout: a cinematic still opens each chapter, then a narrow column of reading text;
   the 學理點睛 sits apart like a bronze tablet, the 考證 notes in smaller type below. */
:root {
  --paper: #eeede6;
  --paper-2: #e5e5dc;
  --ink: #1d1b17;
  --muted: #5d594f;
  --line: #d2cfc2;
  --patina: #2b675d;
  --patina-soft: #dbe6e0;
  --seal: #a3392a;
  --shade: rgba(20, 18, 14, .55);

  --f-display: "Noto Serif TC", "Songti TC", "PMingLiU", serif;
  --f-body: "Noto Serif TC", "Songti TC", "PMingLiU", serif;
  --f-brush: "LXGW WenKai TC", "Kaiti TC", "DFKai-SB", "BiauKai", serif;
  --f-ui: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;

  --fs: 1.125rem;
  --measure: 38em;
  --gutter: clamp(16px, 4vw, 40px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #14130f; --paper-2: #1c1b16; --ink: #e8e3d4; --muted: #a39d8d;
    --line: #36332b; --patina: #74b8a8; --patina-soft: #1f2c28; --seal: #d56a55;
    --shade: rgba(0, 0, 0, .6); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #14130f; --paper-2: #1c1b16; --ink: #e8e3d4; --muted: #a39d8d;
  --line: #36332b; --patina: #74b8a8; --patina-soft: #1f2c28; --seal: #d56a55;
  --shade: rgba(0, 0, 0, .6); color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } * { transition: none !important; animation: none !important; } }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--f-body); font-size: 16px; line-height: 1.8;
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; height: auto; display: block; }
a { color: var(--patina); text-underline-offset: .2em; }
a:focus-visible, button:focus-visible, summary:focus-visible { outline: 2px solid var(--patina); outline-offset: 3px; border-radius: 2px; }

/* ---------- top bar ---------- */
.progress { position: fixed; top: 0; left: 0; height: 3px; width: 0; background: var(--seal); z-index: 30; transition: width .1s linear; }
.bar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 10px var(--gutter);
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  font-family: var(--f-ui); font-size: .875rem;
}
.bar .home { font-family: var(--f-display); font-weight: 900; font-size: 1.05rem; color: var(--ink); text-decoration: none; letter-spacing: .08em; white-space: nowrap; }
.bar .here { flex: 1; min-width: 0; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: center; }
.bar .tools { display: flex; gap: 4px; margin-left: auto; }
.bar button {
  font: inherit; color: var(--ink); background: transparent; border: 1px solid var(--line);
  border-radius: 999px; padding: 4px 11px; cursor: pointer; min-height: 32px;
}
.bar button:hover { border-color: var(--patina); color: var(--patina); }
@media (max-width: 560px) { .bar .here { display: none; } .bar .tools { margin-left: auto; } }

/* ---------- chapter hero ---------- */
.still { max-width: 1280px; margin: 0 auto; padding: clamp(12px, 2.5vw, 28px) var(--gutter) 0; }
.still img { width: 100%; aspect-ratio: 1672 / 941; object-fit: cover; border-radius: 4px; background: var(--paper-2); }
.still figcaption { font-family: var(--f-brush); color: var(--muted); font-size: .95rem; margin-top: .6rem; text-align: right; }

.still-type {
  position: relative; aspect-ratio: 1672 / 941; max-width: 100%; border-radius: 4px; overflow: hidden;
  background:
    radial-gradient(120% 90% at 78% 30%, #6b4d2a 0%, #2a2016 45%, #0f0d0a 100%);
  color: #efe6d2; display: grid; align-content: center; padding: 0 clamp(20px, 7vw, 96px);
}
.still-type::after { content: ""; position: absolute; inset: 0; background: repeating-linear-gradient(90deg, rgba(255,255,255,.025) 0 2px, transparent 2px 38px); pointer-events: none; }
.still-type .no { font-family: var(--f-brush); font-size: clamp(1.1rem, 2.6vw, 2rem); letter-spacing: .3em; opacity: .85; }
.still-type .big { font-family: var(--f-brush); font-weight: 700; font-size: clamp(3.2rem, 13vw, 9rem); line-height: 1.05; letter-spacing: .08em; }
.still-type .tag { font-family: var(--f-body); font-size: clamp(.95rem, 1.9vw, 1.35rem); max-width: 26em; margin-top: 1rem; opacity: .9; }
.still-type .seal { position: absolute; right: clamp(20px, 6vw, 80px); bottom: clamp(20px, 6vw, 70px); width: clamp(44px, 6vw, 72px); aspect-ratio: 1; border: 3px solid #c0503b; color: #c0503b; display: grid; place-items: center; font-family: var(--f-brush); font-size: clamp(1.1rem, 2.2vw, 1.7rem); border-radius: 4px; transform: rotate(-4deg); }

/* ---------- reading column ---------- */
.read { max-width: calc(var(--measure) + 2 * var(--gutter)); margin: 0 auto; padding: 0 var(--gutter) 4rem; font-size: var(--fs); }
.chap-head { padding-block: clamp(1.8rem, 5vw, 3rem) 1rem; text-align: center; }
.chap-head .kicker { font-family: var(--f-ui); font-size: .8rem; letter-spacing: .3em; color: var(--muted); }
.chap-head h1 { font-family: var(--f-display); font-weight: 900; font-size: clamp(2.2rem, 7vw, 3.6rem); margin: .3rem 0 0; letter-spacing: .12em; line-height: 1.2; text-wrap: balance; }
.chap-head .tagline { font-family: var(--f-brush); color: var(--muted); margin-top: .6rem; font-size: 1.05em; }

.blk { margin-top: 2.6rem; }
.label {
  display: flex; align-items: center; gap: .8rem; margin: 0 0 1.1rem;
  font-family: var(--f-ui); font-size: .8rem; font-weight: 600; letter-spacing: .28em; color: var(--muted);
}
.label::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.label .mark { width: 1.6em; height: 1.6em; display: grid; place-items: center; border: 1.5px solid var(--seal); color: var(--seal); border-radius: 3px; font-family: var(--f-brush); letter-spacing: 0; font-size: .95rem; }

.read p { margin: 0 0 1.15em; text-align: justify; text-justify: inter-ideograph; }
.blk-bg p { color: var(--ink); }

/* volume prelude */
.volume { margin-top: 2rem; padding: 1.6rem clamp(1rem, 4vw, 2rem); background: var(--paper-2); border-radius: 4px; }
.volume .vol-title { font-family: var(--f-brush); font-size: 1.6em; margin: 0 0 .2rem; letter-spacing: .1em; }
.volume .vol-sub { font-family: var(--f-ui); font-size: .78rem; letter-spacing: .3em; color: var(--muted); margin-bottom: 1rem; }
.volume p { font-size: .95em; }

/* timeline table */
.table-wrap { overflow-x: auto; border-top: 2px solid var(--ink); border-bottom: 1px solid var(--line); }
table { border-collapse: collapse; width: 100%; font-family: var(--f-ui); font-size: .84em; line-height: 1.6; min-width: 520px; }
th, td { text-align: left; vertical-align: top; padding: .6rem .7rem; border-bottom: 1px solid var(--line); }
th { font-weight: 600; color: var(--muted); letter-spacing: .15em; font-size: .9em; }
td:first-child, th:first-child { white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--seal); font-weight: 600; width: 5.5em; }
tr:last-child td { border-bottom: 0; }

/* scenes */
.blk-text h3 {
  font-family: var(--f-display); font-weight: 900; color: var(--patina);
  font-size: 1.9em; line-height: 1; margin: 2.6rem 0 .5rem; text-align: center; letter-spacing: .1em;
}
.blk-text h3:first-of-type { margin-top: .5rem; }
.dateline { font-family: var(--f-brush); color: var(--muted); text-align: center !important; font-size: 1.02em; margin-bottom: 1.4em !important; }
.blk-text p:has(+ h3), .blk-text p:last-child { margin-bottom: 0; }
.poem { font-family: var(--f-brush); font-size: 1.1em; text-align: center !important; color: var(--ink); padding: .3em 0; }

/* the bronze tablet */
.blk-note {
  margin-top: 3.2rem; padding: clamp(1.2rem, 4vw, 2rem);
  background: var(--patina-soft); border: 1px solid color-mix(in srgb, var(--patina) 35%, transparent); border-radius: 6px;
}
.blk-note .label { color: var(--patina); }
.blk-note .label::after { background: color-mix(in srgb, var(--patina) 30%, transparent); }
.blk-note .label .mark { border-color: var(--patina); color: var(--patina); }
.blk-note .kw { font-family: var(--f-brush); font-size: 1.12em; color: var(--patina); margin-bottom: 1em; text-align: left !important; }
.blk-note .kw strong { font-weight: 700; }
.blk-note p { font-size: .95em; }
.blk-note p:last-child { margin-bottom: 0; }

/* notes */
.blk-src { font-size: .86em; color: var(--muted); }
.blk-src ul { padding-left: 1.2em; margin: 0; display: grid; gap: .7em; }
.blk-src li { line-height: 1.75; }
.blk-src strong { color: var(--ink); }
.blk-src p { text-align: left; }
.blk-extra h2 { font-family: var(--f-display); font-size: 1.3em; margin: 0 0 1rem; }

blockquote { margin: 1.2em 0; padding: 0 0 0 1em; border-left: 2px solid var(--line); color: var(--muted); }

/* prev / next */
.pager { max-width: 1100px; margin: 0 auto; padding: 0 var(--gutter) 3rem; display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.pager a { display: grid; grid-template-columns: 120px 1fr; gap: 14px; align-items: center; text-decoration: none; color: var(--ink); padding: 10px; border: 1px solid var(--line); border-radius: 6px; min-width: 0; }
.pager a:hover { border-color: var(--patina); }
.pager a.next { grid-template-columns: 1fr 120px; text-align: right; }
.pager a.next .thumb { order: 2; }
.pager .thumb { width: 120px; aspect-ratio: 16/9; object-fit: cover; border-radius: 3px; background: var(--paper-2); }
.pager .dir { font-family: var(--f-ui); font-size: .75rem; letter-spacing: .2em; color: var(--muted); }
.pager .t { font-family: var(--f-display); font-weight: 700; font-size: 1.05rem; }
.pager .empty { visibility: hidden; }
@media (max-width: 640px) { .pager { grid-template-columns: 1fr; } .pager a, .pager a.next { grid-template-columns: 96px 1fr; text-align: left; } .pager a.next .thumb { order: 0; } .pager .thumb { width: 96px; } }
.thumb-type { display: grid; place-items: center; font-family: var(--f-brush); color: #efe6d2; background: radial-gradient(120% 90% at 70% 30%, #6b4d2a, #1a140e); font-size: 1.3rem; }

footer { border-top: 1px solid var(--line); padding: 1.6rem var(--gutter) 2.4rem; text-align: center; font-family: var(--f-ui); font-size: .8rem; color: var(--muted); }

/* TOC dialog */
dialog.toc { border: 1px solid var(--line); border-radius: 8px; background: var(--paper); color: var(--ink); padding: 0; width: min(560px, calc(100vw - 32px)); max-height: min(80vh, 760px); }
dialog.toc::backdrop { background: var(--shade); }
.toc-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); font-family: var(--f-display); font-weight: 900; }
.toc-head button { font: inherit; font-family: var(--f-ui); font-weight: 400; background: none; border: 1px solid var(--line); border-radius: 999px; padding: 2px 12px; color: var(--ink); cursor: pointer; }
.toc-body { padding: 8px 18px 18px; overflow-y: auto; max-height: calc(min(80vh, 760px) - 60px); }
.toc-vol { font-family: var(--f-brush); color: var(--muted); margin: 14px 0 4px; letter-spacing: .15em; }
.toc-body a { display: flex; gap: 12px; padding: 6px 0; text-decoration: none; color: var(--ink); border-bottom: 1px dashed var(--line); }
.toc-body a span:first-child { width: 5.5em; color: var(--muted); font-family: var(--f-ui); font-size: .85rem; padding-top: .15em; flex: none; }
.toc-body a[aria-current="page"] { color: var(--seal); }

/* ---------- home ---------- */
.cover { max-width: 1280px; margin: 0 auto; padding: clamp(12px, 2.5vw, 28px) var(--gutter) 0; }
.cover img { width: 100%; aspect-ratio: 1672 / 941; object-fit: cover; border-radius: 4px; background: var(--paper-2); }
.intro { max-width: 1100px; margin: 0 auto; padding: clamp(2rem, 5vw, 3.5rem) var(--gutter) 0; display: grid; grid-template-columns: 1.1fr 1fr; gap: clamp(1.5rem, 5vw, 4rem); }
.intro > * { min-width: 0; }
@media (max-width: 820px) { .intro { grid-template-columns: 1fr; } }
.intro h1 { font-family: var(--f-display); font-weight: 900; font-size: clamp(2.4rem, 6.5vw, 4rem); margin: 0; letter-spacing: .1em; line-height: 1.15; text-wrap: balance; }
.intro .sub { font-family: var(--f-brush); font-size: clamp(1.15rem, 2.4vw, 1.5rem); margin: .4rem 0 0; }
.intro .by { font-family: var(--f-ui); color: var(--muted); letter-spacing: .3em; font-size: .85rem; margin-top: .8rem; }
.intro .lede { font-size: 1.05rem; margin-top: 1.4rem; text-align: justify; }
.cta { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 1.4rem; }
.btn { font-family: var(--f-ui); font-size: .95rem; text-decoration: none; padding: .65em 1.3em; border-radius: 999px; border: 1px solid var(--ink); color: var(--ink); }
.btn.primary { background: var(--ink); color: var(--paper); }
.btn:hover { border-color: var(--patina); }
.btn.primary:hover { background: var(--patina); border-color: var(--patina); }
.epi { display: grid; gap: 1.2rem; align-content: start; }
.epi figure { margin: 0; padding: 1.2rem 1.4rem; border-left: 3px solid var(--seal); background: var(--paper-2); border-radius: 0 4px 4px 0; }
.epi blockquote { border: 0; padding: 0; margin: 0; font-family: var(--f-brush); font-size: 1.25rem; color: var(--ink); line-height: 1.6; }
.epi figcaption { font-family: var(--f-ui); font-size: .8rem; color: var(--muted); margin-top: .5rem; }
.epi .howto { font-size: .95rem; color: var(--muted); text-align: justify; }

.contents { max-width: 1100px; margin: 0 auto; padding: clamp(2.5rem, 6vw, 4.5rem) var(--gutter) 3rem; }
.contents > h2 { font-family: var(--f-display); font-weight: 900; font-size: 1.6rem; letter-spacing: .3em; margin: 0 0 .4rem; }
.vol { margin-top: 2.2rem; }
.vol-h { display: flex; flex-wrap: wrap; align-items: baseline; gap: .4rem 1rem; border-bottom: 1px solid var(--ink); padding-bottom: .4rem; margin-bottom: 1rem; }
.vol-h h3 { font-family: var(--f-brush); font-size: 1.45rem; margin: 0; letter-spacing: .12em; }
.vol-h span { font-family: var(--f-ui); font-size: .82rem; color: var(--muted); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 20px; }
.card { text-decoration: none; color: var(--ink); display: grid; gap: .5rem; align-content: start; min-width: 0; }
.card .img { overflow: hidden; border-radius: 4px; aspect-ratio: 16/9; background: var(--paper-2); }
.card img { width: 100%; height: 100%; object-fit: cover; transition: transform .5s ease; }
.card:hover img { transform: scale(1.035); }
.card .no { font-family: var(--f-ui); font-size: .75rem; letter-spacing: .25em; color: var(--seal); }
.card .t { font-family: var(--f-display); font-weight: 900; font-size: 1.3rem; letter-spacing: .1em; line-height: 1.3; }
.card .d { font-size: .92rem; color: var(--muted); line-height: 1.65; }
.card .img.type { display: grid; place-items: center; background: radial-gradient(120% 90% at 70% 30%, #6b4d2a, #1a140e); color: #efe6d2; font-family: var(--f-brush); font-size: 2.6rem; letter-spacing: .1em; }
.resume[hidden] { display: none !important; }

@media (max-width: 600px) { .still-type .tag { display: none; } }
