/* 阿威奇譚 —— 閱讀版面
   設計目標:長篇中文小說,桌機與手機都要能久讀不累。
   紙書感:襯線體、米白紙色、寬行距、窄版心。 */

:root {
  --paper:      #f7f4ed;
  --paper-2:    #efeadf;
  --ink:        #23201b;
  --ink-soft:   #5c564c;
  --ink-faint:  #756e62;   /* 4.5:1 於 --paper,日期與字數等小字要讀得到 */
  --rule:       #ddd5c6;
  --accent:     #8a6d3b;
  --bubble:     #e6efd8;
  --bubble-ink: #2c3a1c;

  --measure: 34em;
  --fs: 18.5px;
  --lh: 1.95;

  --serif: "Noto Serif TC", "Source Han Serif TC", "Songti TC", "Songti SC",
           "SimSun", "PMingLiU", "AR PL UMing TW", Georgia, "Times New Roman", serif;
  --sans: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", "Hiragino Sans TC",
          system-ui, -apple-system, "Segoe UI", sans-serif;
}

:root[data-fontsize="s"]  { --fs: 17px;   --measure: 33em; }
:root[data-fontsize="l"]  { --fs: 20.5px; --measure: 32em; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper:      #16161a;
    --paper-2:    #1e1e23;
    --ink:        #ddd8cf;
    --ink-soft:   #a49d92;
    --ink-faint:  #8b8478;
    --rule:       #33323a;
    --accent:     #c4a86a;
    --bubble:     #26301f;
    --bubble-ink: #cfdcbb;
  }
}
:root[data-theme="dark"] {
  --paper:      #16161a;
  --paper-2:    #1e1e23;
  --ink:        #ddd8cf;
  --ink-soft:   #a49d92;
  --ink-faint:  #8b8478;
  --rule:       #33323a;
  --accent:     #c4a86a;
  --bubble:     #26301f;
  --bubble-ink: #cfdcbb;
}

* { box-sizing: border-box; }

html {
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: var(--fs);
  line-height: var(--lh);
  transition: background .25s, color .25s;
}

.wrap {
  max-width: var(--measure);
  margin-inline: auto;
  padding-inline: 1.4rem;
}

a { color: inherit; text-decoration-color: var(--rule); text-underline-offset: .25em; }
a:hover { text-decoration-color: var(--accent); }

/* ---------- 頁首 ---------- */

.site-head {
  position: relative;
  padding: clamp(3rem, 10vw, 6rem) 0 clamp(2rem, 6vw, 3.5rem);
  text-align: center;
}
.site-title {
  font-size: clamp(2rem, 8vw, 2.9rem);
  letter-spacing: .22em;
  text-indent: .22em;
  margin: 0 0 .6rem;
  font-weight: 600;
}
.site-tagline {
  margin: 0;
  color: var(--ink-soft);
  font-size: .92em;
  letter-spacing: .06em;
}

/* ---------- 目錄列表 ---------- */

.story-list { list-style: none; margin: 0 0 4rem; padding: 0; }

.card { border-top: 1px solid var(--rule); }
.card:last-child { border-bottom: 1px solid var(--rule); }
.card a {
  display: block;
  padding: 2rem .25rem;
  text-decoration: none;
  position: relative;
  transition: background .18s;
}
.card a:hover { background: var(--paper-2); }
.card .num {
  display: block;
  font-family: var(--sans);
  font-size: .72rem;
  letter-spacing: .3em;
  color: var(--ink-faint);
  margin-bottom: .5rem;
}
.card h2 {
  margin: 0 0 .55rem;
  font-size: 1.42em;
  font-weight: 600;
  letter-spacing: .04em;
}
.card .summary {
  margin: 0 0 .8rem;
  color: var(--ink-soft);
  font-size: .95em;
  line-height: 1.75;
}
.card .meta {
  margin: 0;
  font-family: var(--sans);
  font-size: .76rem;
  color: var(--ink-faint);
  letter-spacing: .04em;
}
.dot { margin: 0 .55em; }
.empty { color: var(--ink-faint); padding: 3rem 0; text-align: center; }

/* ---------- 內文 ---------- */

.article { padding-bottom: 4rem; }

article h1 {
  font-size: clamp(1.75rem, 6.5vw, 2.4rem);
  line-height: 1.4;
  letter-spacing: .06em;
  margin: 1rem 0 3rem;
  font-weight: 600;
  text-align: center;
}
article h2 {
  font-size: 1.05em;
  font-weight: 600;
  letter-spacing: .35em;
  text-indent: .35em;
  text-align: center;
  color: var(--ink-soft);
  margin: 4rem 0 2.2rem;
}
article h3 {
  font-size: 1.05em;
  margin: 2.6rem 0 1rem;
  letter-spacing: .06em;
}

article p { margin: 0 0 1.35em; }

/* 敘述者的括號旁白 */
article p.aside {
  color: var(--ink-soft);
  font-size: .94em;
  line-height: 1.85;
  border-left: 2px solid var(--rule);
  padding: .15em 0 .15em 1.1em;
  margin-left: .1em;
}

article hr {
  border: 0;
  margin: 3rem auto;
  width: 100%;
  text-align: center;
}
article hr::before {
  content: "· · ·";
  color: var(--ink-faint);
  letter-spacing: .7em;
  font-size: .9em;
}

article strong { font-weight: 700; }
article em { font-style: normal; border-bottom: 1px solid var(--accent); }

article blockquote {
  margin: 1.8em 0;
  padding-left: 1.2em;
  border-left: 3px solid var(--rule);
  color: var(--ink-soft);
}
article blockquote p:last-child { margin-bottom: 0; }

pre {
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 1rem 1.1rem;
  overflow-x: auto;
  font-size: .86em;
  line-height: 1.7;
}
code { font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; }

/* ---------- LINE 訊息 ---------- */

.chat { margin: 1.9em 0; }
.msg {
  display: flex;
  align-items: baseline;
  gap: .7em;
  margin-bottom: .55em;
  font-family: var(--sans);
}
.msg .who {
  flex: 0 0 auto;
  font-size: .78em;
  color: var(--ink-faint);
  letter-spacing: .05em;
  padding-top: .15em;
}
.msg .bubble {
  background: var(--bubble);
  color: var(--bubble-ink);
  border-radius: 4px 14px 14px 14px;
  padding: .5em .95em;
  font-size: .95em;
  line-height: 1.65;
  max-width: 24em;
}
.msg .bubble strong { font-weight: 600; }

/* ---------- 工具列 ---------- */

.story-head {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .75rem 0;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid transparent;
  transition: border-color .2s;
}
.story-head.scrolled { border-bottom-color: var(--rule); }
.story-head .wrap { margin: 0; padding-inline: 1.4rem; max-width: none; }
.back {
  font-family: var(--sans);
  font-size: .82rem;
  color: var(--ink-soft);
  text-decoration: none;
  letter-spacing: .05em;
}
.back:hover { color: var(--ink); }

.tools { display: flex; align-items: center; gap: .3rem; padding-right: 1.1rem; }

.theme-toggle, .font-toggle, .toc-btn {
  appearance: none;
  border: 1px solid transparent;
  background: none;
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: .8rem;
  cursor: pointer;
  border-radius: 6px;
  padding: .4rem .6rem;
  line-height: 1;
  transition: background .15s, color .15s;
}
.theme-toggle:hover, .font-toggle:hover, .toc-btn:hover {
  background: var(--paper-2);
  color: var(--ink);
}
.theme-toggle::after { content: "☾"; font-size: 1rem; }
:root[data-theme="dark"] .theme-toggle::after { content: "☀"; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle::after { content: "☀"; }
}

.site-head .theme-toggle {
  position: absolute;
  top: 1.1rem;
  right: 1.2rem;
}

/* 目錄 */
.toc { position: relative; }
.toc ol {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + .5rem);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 8px;
  box-shadow: 0 8px 30px rgba(0,0,0,.13);
  list-style: none;
  margin: 0;
  padding: .5rem;
  min-width: 9rem;
  max-height: 60vh;
  overflow-y: auto;
}
.toc.open ol { display: block; }
.toc li a {
  display: block;
  padding: .45rem .8rem;
  font-family: var(--sans);
  font-size: .84rem;
  color: var(--ink-soft);
  text-decoration: none;
  border-radius: 5px;
  letter-spacing: .1em;
}
.toc li a:hover { background: var(--paper-2); color: var(--ink); }

/* 閱讀進度 */
.progress {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 2px;
  z-index: 30;
  pointer-events: none;
}
.progress i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width .1s linear;
}

/* ---------- 前後篇 ---------- */

.story-nav {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--rule);
  font-family: var(--sans);
  font-size: .85rem;
}
.story-nav a { color: var(--ink-soft); text-decoration: none; }
.story-nav a:hover { color: var(--ink); }

/* ---------- 頁尾 ---------- */

.site-foot {
  padding: 2.5rem 1.4rem 4rem;
  color: var(--ink-faint);
  font-family: var(--sans);
  font-size: .76rem;
  text-align: center;
  letter-spacing: .04em;
}
.site-foot p { margin: 0; }

/* ---------- 手機 ---------- */

@media (max-width: 640px) {
  :root { --fs: 17.5px; --lh: 1.9; }
  :root[data-fontsize="l"] { --fs: 19.5px; }
  .wrap { padding-inline: 1.15rem; }
  .card a { padding: 1.6rem .1rem; }
  .card h2 { font-size: 1.3em; }
  article h2 { margin: 3rem 0 1.8rem; }
  article p.aside { padding-left: .9em; }
  .msg { flex-direction: column; gap: .2em; }
  .msg .bubble { max-width: 100%; }
  .story-nav { flex-direction: column; gap: .8rem; }
  .story-nav .next { text-align: right; }
}

@media print {
  .story-head, .progress, .story-nav, .site-foot, .theme-toggle { display: none; }
  body { font-size: 11pt; background: #fff; color: #000; }
}
