:root {
  --bg: #f7f4ec;
  --paper: #fffdf8;
  --ink: #1d2420;
  --muted: #6b726c;
  --line: #e2ddd0;
  --accent: #2c5e8c;
  --accent-ink: #ffffff;
  --gold: #3d7a5f;
  --quote-bg: #f1ece0;
  --shadow: 0 10px 30px rgba(20, 30, 25, .10);
  --font: "Noto Sans Thai", "Noto Sans", system-ui, sans-serif;
  --size: 19px;
  --leading: 1.95;
  --measure: 40rem;
}
:root[data-theme="sepia"] {
  --bg: #efe4cc; --paper: #f6ecd6; --ink: #3b2f22; --muted: #7c6a52; --line: #dccbaa;
  --accent: #7a5520; --gold: #8b6420; --quote-bg: #eadbbd;
}
:root[data-theme="dark"] {
  --bg: #0c1714; --paper: #111f1b; --ink: #dfe6e1; --muted: #8fa198; --line: #22362f;
  --accent: #4fb68a; --accent-ink: #06130e; --gold: #d9b45a; --quote-bg: #172a24;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="sepia"]) {
    --bg: #0c1714; --paper: #111f1b; --ink: #dfe6e1; --muted: #8fa198; --line: #22362f;
    --accent: #4fb68a; --accent-ink: #06130e; --gold: #d9b45a; --quote-bg: #172a24;
    --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font); font-size: 16px; line-height: 1.6;
  transition: background .25s, color .25s;
}
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--accent); }
img { max-width: 100%; display: block; }

/* ---------- หน้าแรก ---------- */
.hero {
  position: relative; min-height: min(92vh, 760px); display: grid; align-items: end;
  color: #f4efe2; overflow: hidden; background: #0c1714;
}
.hero-bg { position: absolute; inset: 0; background: center 20% / cover no-repeat; opacity: .9; }
.hero::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(20,12,16,0) 0%, rgba(20,12,16,.25) 45%, rgba(20,12,16,.93) 100%);
}
.hero-girl {
  position: absolute; right: max(2vw, calc(50% - 560px)); bottom: 0; height: 96%; max-height: 740px;
  width: auto; z-index: 1; filter: drop-shadow(0 20px 40px rgba(0,0,0,.5));
}
.hero-inner { position: relative; z-index: 2; width: min(1120px, 100%); margin: 0 auto; padding: 48px 24px 56px; }
.hero-kicker { letter-spacing: .2em; font-size: 13px; color: #f4a6c0; font-weight: 600; }
.hero h1 { font-size: clamp(36px, 6.4vw, 72px); line-height: 1.15; margin: 10px 0 6px; font-weight: 700; letter-spacing: -.01em; }
.hero h1 .bolt { color: #f4a6c0; }
.hero-sub { font-size: clamp(16px, 2.4vw, 20px); color: #cfe0d6; margin: 0 0 22px; }
.hero-blurb { max-width: 36rem; color: #e3e9e4; font-size: 16px; line-height: 1.9; margin: 0 0 28px; }
.hero-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.btn {
  border: 0; border-radius: 999px; padding: 13px 24px; font-weight: 600; font-size: 16px;
  background: #d9b45a; color: #17130a; box-shadow: 0 6px 20px rgba(0,0,0,.3);
  transition: transform .15s, filter .15s;
}
.btn:hover { transform: translateY(-1px); filter: brightness(1.06); }
.btn.ghost { background: rgba(255,255,255,.1); color: #f4efe2; border: 1px solid rgba(255,255,255,.3); box-shadow: none; }
.btn.accent { background: var(--accent); color: var(--accent-ink); }
.hero-meta { margin-top: 18px; font-size: 13px; color: #9fb3a8; }

.toc-wrap { width: min(860px, 100%); margin: 0 auto; padding: 40px 16px 80px; }
.toc-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.toc-head h2 { margin: 0; font-size: 26px; }
.toc-head .small { color: var(--muted); font-size: 14px; }
.toc { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.toc button {
  width: 100%; text-align: left; display: grid; grid-template-columns: 74px 1fr auto; gap: 14px; align-items: center;
  background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 10px; transition: border-color .15s, transform .15s;
}
.toc button:hover { border-color: var(--accent); transform: translateY(-1px); }
.toc .thumb { width: 74px; height: 50px; border-radius: 9px; background: center / cover no-repeat var(--line); }
.toc .num { font-size: 12px; color: var(--gold); font-weight: 700; letter-spacing: .08em; }
.toc .t { font-weight: 600; font-size: 16px; line-height: 1.4; }
.toc .meta { font-size: 12px; color: var(--muted); white-space: nowrap; text-align: right; }
.toc .done .meta::before { content: "✓ "; color: var(--accent); font-weight: 700; }
.toc .current { border-color: var(--gold); }
.footnote { color: var(--muted); font-size: 13px; text-align: center; margin-top: 36px; line-height: 1.8; }

/* ---------- ตัวอ่าน ---------- */
.bar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
  transition: transform .25s;
}
.bar.hide { transform: translateY(-100%); }
.bar .title { flex: 1; min-width: 0; font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center; }
.icon-btn {
  border: 1px solid var(--line); background: var(--paper); border-radius: 10px; height: 38px; min-width: 38px; padding: 0 10px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-size: 14px;
}
.progress { position: fixed; left: 0; top: 0; height: 3px; background: var(--gold); z-index: 30; width: 0; transition: width .1s; }

.chapter { width: min(var(--measure), 100%); margin: 0 auto; padding: 28px 16px 40px; }
.ch-cover { width: min(960px, 100%); margin: 0 auto; padding: 16px 16px 0; }
.ch-cover .img { aspect-ratio: 16 / 7; border-radius: 18px; background: center 30% / cover no-repeat var(--line); box-shadow: var(--shadow); }
.ch-cover .img.portrait { background-position: center 18%; }
.ch-num { color: var(--gold); font-weight: 700; letter-spacing: .14em; font-size: 13px; margin-top: 28px; text-align: center; }
.ch-title { text-align: center; font-size: clamp(26px, 5vw, 36px); line-height: 1.35; margin: 8px 0 6px; }
.ch-time { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 30px; }
.prose { font-size: var(--size); line-height: var(--leading); }
.prose p { margin: 0 0 1.05em; text-indent: 2em; }
.prose p.dlg { text-indent: 0; }
.prose p.first { text-indent: 0; }
.prose p.first::first-letter { font-size: 1.5em; color: var(--gold); font-weight: 700; }
.prose .break { text-align: center; color: var(--gold); letter-spacing: 1em; margin: 1.8em 0; text-indent: 0; }
.prose blockquote {
  margin: 1.2em 0; padding: 14px 18px; background: var(--quote-bg); border-left: 3px solid var(--gold); border-radius: 0 10px 10px 0;
  font-style: italic; text-indent: 0;
}
.prose blockquote p { text-indent: 0; margin: 0 0 .5em; }
.prose blockquote p:last-child { margin: 0; }
.prose figure { margin: 2em -16px; }
.prose figure img { width: 100%; border-radius: 14px; box-shadow: var(--shadow); }
.prose figcaption { text-align: center; color: var(--muted); font-size: 13px; margin-top: 8px; font-style: italic; }
@media (min-width: 760px) { .prose figure { margin: 2.2em -60px; } }
.prose em { font-style: italic; }
.prose strong { font-weight: 700; }

.ch-end { width: min(var(--measure), 100%); margin: 0 auto; padding: 10px 16px 80px; display: grid; gap: 12px; }
.ch-end .fin { text-align: center; color: var(--gold); letter-spacing: .3em; margin-bottom: 10px; }
.ch-end .nav { display: flex; gap: 10px; justify-content: space-between; flex-wrap: wrap; }
.ch-end .nav .btn { flex: 1 1 200px; box-shadow: none; }
.ch-end .btn.ghost { background: var(--paper); color: var(--ink); border: 1px solid var(--line); }
.next-card {
  border: 1px solid var(--line); background: var(--paper); border-radius: 16px; padding: 18px; text-align: center;
}
.next-card .k { font-size: 12px; color: var(--muted); letter-spacing: .1em; }
.next-card .t { font-size: 20px; font-weight: 600; margin: 4px 0 14px; }

/* ---------- แผงตั้งค่า ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; opacity: 0; pointer-events: none; transition: opacity .2s; }
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 50%; bottom: 0; transform: translate(-50%, 105%); width: min(520px, 100%); z-index: 41;
  background: var(--paper); border: 1px solid var(--line); border-bottom: 0; border-radius: 20px 20px 0 0; padding: 18px 18px calc(22px + env(safe-area-inset-bottom));
  transition: transform .25s; box-shadow: var(--shadow);
}
.sheet.open { transform: translate(-50%, 0); }
.sheet h3 { margin: 0 0 14px; font-size: 17px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 12px 0; }
.row .lbl { font-size: 14px; color: var(--muted); }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 8px 12px; font-size: 14px; }
.seg button.on { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.swatch { width: 34px; height: 34px; border-radius: 50%; padding: 0; }
.swatch.light { background: #fffdf8; }
.swatch.sepia { background: #f6ecd6; }
.swatch.dark { background: #111f1b; }
.swatch.auto { background: linear-gradient(135deg, #fffdf8 50%, #111f1b 50%); }

.toc-sheet { max-height: 75vh; overflow: auto; }
.toc-sheet .toc button { grid-template-columns: 1fr auto; }
.toc-sheet .thumb { display: none; }

.loading { text-align: center; color: var(--muted); padding: 80px 16px; }

@media (max-width: 640px) {
  .hero { min-height: 100svh; }
  .hero-girl { right: -18vw; height: 72%; opacity: .9; }
  .hero-inner { padding-bottom: 36px; }
  .hero-blurb { font-size: 15px; }
  .toc button { grid-template-columns: 58px 1fr; }
  .toc .thumb { width: 58px; height: 42px; }
  .toc .meta { grid-column: 2; text-align: left; }
  .bar .label { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- ฉบับตัวอักษร: หน้าปก ตัวละคร สารบัญ ---------- */
.hero {
  display: grid; align-items: end; min-height: min(86vh, 720px); color: #eef2f6;
  background:
    radial-gradient(60% 70% at 78% 30%, rgba(77, 150, 120, .35), transparent 70%),
    radial-gradient(50% 60% at 15% 85%, rgba(60, 110, 170, .35), transparent 70%),
    linear-gradient(160deg, #0b1420 0%, #0d1d1a 55%, #081010 100%);
}
.hero::after { display: none; }
.hero-art { position: absolute; right: max(4vw, calc(50% - 520px)); top: 12%; width: min(420px, 70vw); aspect-ratio: 1; }
.hero-art .ring { position: absolute; inset: 0; border-radius: 50%; border: 1.5px solid rgba(200, 225, 215, .35); animation: ripple 5.5s ease-out infinite; }
.hero-art .r2 { animation-delay: 1.8s; }
.hero-art .r3 { animation-delay: 3.6s; }
.hero-art .spark { position: absolute; left: 50%; top: 50%; width: 14px; height: 14px; margin: -7px; border-radius: 50%; background: #d8efe6; box-shadow: 0 0 24px 8px rgba(160, 230, 200, .55), 0 0 80px 30px rgba(80, 160, 200, .25); }
@keyframes ripple { 0% { transform: scale(.05); opacity: .9; } 100% { transform: scale(1); opacity: 0; } }
.hero-kicker { color: #9fd8c0; }
.hero h1 { font-size: clamp(44px, 8vw, 88px); }
.hero h1 .bolt { color: #9fd8c0; }
.hero-sub { color: #c4d4e2; }
.hero-blurb { color: #dde6ee; }
.btn { background: #cfe3da; color: #0b1a14; }
.hero-meta { color: #8fa9b8; }

.cast { width: min(860px, 100%); margin: 0 auto; padding: 36px 16px 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.cast-card { margin: 0; background: var(--paper); border: 1px solid var(--line); border-radius: 18px; display: grid; grid-template-columns: 64px 1fr; gap: 14px; align-items: start; padding: 16px; box-shadow: var(--shadow); }
.cast-card .mono { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 22px; color: #fff; }
.cast-card.blue .mono { background: linear-gradient(135deg, #2c5e8c, #18324d); }
.cast-card.green .mono { background: linear-gradient(135deg, #2f7a5c, #123a2b); }
.cast-card.red .mono { background: linear-gradient(135deg, #9a3a30, #4d1712); }
.cast-card figcaption { color: var(--ink); font-size: 14px; line-height: 1.7; }
.cast-card strong { display: block; font-size: 17px; margin-bottom: 4px; }

.toc .thumb { display: grid; place-items: center; font-weight: 700; font-size: 20px; color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--paper)); letter-spacing: .04em; }
.toc-sheet .thumb { display: none; }

.ch-cover { padding-top: 40px; }
.ornament { display: flex; align-items: center; gap: 16px; justify-content: center; color: var(--gold); }
.ornament span { flex: 0 1 140px; height: 1px; background: linear-gradient(90deg, transparent, var(--gold)); }
.ornament span:last-child { background: linear-gradient(90deg, var(--gold), transparent); }
.ornament b { font-size: 30px; font-weight: 700; letter-spacing: .08em; }
.ch-num { margin-top: 10px; }

@media (max-width: 640px) {
  .hero { min-height: 92svh; }
  .hero-art { right: -12vw; top: 8%; width: 80vw; opacity: .7; }
}
@media (prefers-reduced-motion: reduce) { .hero-art .ring { animation: none; opacity: .3; } .r1 { transform: scale(.4); } .r2 { transform: scale(.7); } }
