:root {
  --bg: #FBF5E9; --card: #FFFDF8; --ink: #3B2A1A; --muted: #6E5A45;
  --line: #E6D9C2; --accent: #9A4E12; --accent-ink: #FFFDF8;
  --bar: linear-gradient(100deg, #16302A, #21463B 60%, #2B5547); --bar-ink: #FFF8EC;
  --gold: #E8B04A; --tint: #F6E7CC;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1C1712; --card: #26201A; --ink: #EDE3D1; --muted: #BBA98F;
    --line: #3A3128; --accent: #E0A15E; --accent-ink: #1C1712; color-scheme: dark;
    --bar: linear-gradient(100deg, #0F201C, #17332B 60%, #1F3E35); --bar-ink: #FBE9CF; --tint: #33261A; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { font-size: 20px; -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink);
  font-family: 'Noto Sans Thai', sans-serif; line-height: 1.7; }
h1, h2, h3 { font-family: 'Prompt', sans-serif; font-weight: 600; line-height: 1.35; margin: 0 0 .5em; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.3rem; } h3 { font-size: 1.05rem; }
a { color: var(--accent); }
.wrap { max-width: 900px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }

/* ป้องกันคัดลอก (docs/adr/0001) */
body.protect { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
body.protect img { -webkit-user-drag: none; pointer-events: none; }
/* QR ต้องกดค้างบันทึกได้ เพื่อไปสแกนในแอปธนาคาร */
body.protect img.qr { pointer-events: auto; -webkit-touch-callout: default; }
@media print { body { display: none !important; } }

.top { position: sticky; top: 0; z-index: 5; background: var(--bar); color: var(--bar-ink);
  border-bottom: 3px solid var(--gold); box-shadow: 0 2px 10px rgb(0 0 0 / .15); }
.top .btn.ghost { color: var(--bar-ink); border-color: var(--bar-ink); }
.top .wrap { display: flex; align-items: center; gap: 12px; min-height: 60px; }
.top .title { flex: 1; font-family: 'Prompt', sans-serif; font-weight: 600; font-size: .95rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 8px 20px; border-radius: 12px; border: 2px solid var(--accent);
  background: var(--accent); color: var(--accent-ink); font: inherit; font-weight: 600;
  text-decoration: none; cursor: pointer; }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.small { min-height: 44px; padding: 4px 14px; font-size: .85rem; }

/* หน้าแรก */
.intro { padding: 28px 0 8px; }
.intro h1 { color: var(--accent); }
.intro h1::after { content: ''; display: block; width: 72px; height: 5px; border-radius: 3px; margin-top: 10px;
  background: linear-gradient(90deg, var(--gold), #D9731F, #2F6B4F); }
.intro .lead { font-size: 1.15rem; font-weight: 600; margin: 14px 0 10px; }
.intro .purpose { border-left: 5px solid var(--gold); background: var(--tint); border-radius: 0 12px 12px 0;
  padding: 10px 14px; margin: 0 0 10px; }
/* ยอดนิยม และรายชื่อหนังสือ */
.popular, #toc { margin: 22px 0; }
.popular h2, #toc h2 { color: var(--accent); margin-bottom: 10px; }
.popular ol, .toc { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.popular a { position: relative; display: flex; align-items: center; gap: 14px; padding: 10px 14px 10px 10px; text-decoration: none; color: var(--ink);
  background: linear-gradient(110deg, color-mix(in srgb, var(--sc) 16%, var(--card)), var(--card) 70%);
  border: 2px solid color-mix(in srgb, var(--sc) 45%, transparent); border-radius: 16px; box-shadow: 0 6px 16px rgb(60 30 0 / .14);
  transition: transform .25s, box-shadow .25s; }
.popular a:hover, .popular a:focus-visible { transform: translateY(-3px); box-shadow: 0 12px 24px rgb(60 30 0 / .22); }
.popular .cover { width: 64px; height: 96px; object-fit: cover; border-radius: 3px 8px 8px 3px; flex: none; background: var(--line);
  box-shadow: inset 6px 0 6px -4px rgb(0 0 0 / .4), 3px 3px 0 #EDE3D0, 6px 8px 12px rgb(60 30 0 / .3); }
.popular .info { display: grid; gap: 2px; min-width: 0; }
.popular .info small { color: var(--muted); font-size: .8rem; }
.popular .info .views { color: var(--sc); font-weight: 700; }
.medal { position: absolute; top: -8px; left: -8px; z-index: 1; display: grid; place-items: center; width: 34px; height: 34px;
  border-radius: 50%; color: #fff; font-weight: 700; box-shadow: 0 3px 8px rgb(0 0 0 / .3); border: 2px solid #fff; }
.m1 { background: linear-gradient(135deg, #FFD54A, #E0A100); }
.m2 { background: linear-gradient(135deg, #D9DEE4, #8E99A6); }
.m3 { background: linear-gradient(135deg, #E9A56A, #A8612A); }
.medal.new { width: auto; height: 26px; padding: 0 9px; border-radius: 13px; font-size: .78rem; background: linear-gradient(135deg, #FF7A8E, #D93A5A); }
.toc { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
@media (prefers-color-scheme: dark) { .popular .info .views { color: color-mix(in srgb, var(--sc) 50%, white); } }
.toc a { display: flex; align-items: center; gap: 10px; height: 100%; padding: 10px 12px; line-height: 1.4; text-decoration: none; color: var(--ink);
  background: var(--card); border: 1px solid var(--line); border-left: 6px solid var(--sc); border-radius: 12px;
  box-shadow: 0 3px 8px rgb(60 30 0 / .08); transition: transform .2s, background .2s; }
.toc a:hover, .toc a:focus-visible { transform: translateX(4px); background: color-mix(in srgb, var(--sc) 10%, var(--card)); }
.toc .n { display: grid; place-items: center; flex: none; width: 30px; height: 30px; border-radius: 50%; background: var(--sc); color: #fff; font-weight: 700; }
.toc .w { display: inline-block; }  /* ตัดบรรทัดเฉพาะที่ช่องว่าง ไม่ตัดกลางชื่อ */
.toc small { display: block; color: var(--muted); font-size: .8rem; }
.series { scroll-margin-top: 60px; }
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
.resume { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; justify-content: space-between;
  background: linear-gradient(120deg, var(--tint), var(--card)); border: 2px solid var(--gold);
  border-radius: 16px; padding: 16px; margin: 16px 0; }
.series { --sc: #2F6B4F; margin: 36px 0; padding: 18px 14px 22px; border-radius: 20px;
  background: color-mix(in srgb, var(--sc) 9%, var(--bg)); border: 1px solid color-mix(in srgb, var(--sc) 25%, transparent); }
.series h2 { color: var(--sc); border-left: 6px solid var(--sc); padding-left: 12px; }
@media (prefers-color-scheme: dark) { .series h2 { color: color-mix(in srgb, var(--sc) 55%, white); } }
.shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 18px; }
.ep { display: block; text-decoration: none; color: var(--ink); background: var(--card);
  border: 1px solid var(--line); border-top: 5px solid var(--sc, var(--accent)); border-radius: 14px; overflow: hidden;
  box-shadow: 0 3px 10px rgb(0 0 0 / .08); }
.ep .no { display: inline-block; background: var(--sc, var(--accent)); color: #fff; font-size: .75rem;
  font-weight: 600; border-radius: 999px; padding: 0 10px; margin-bottom: 4px; }
.ep .cover { display: block; width: 100%; height: auto; aspect-ratio: 2 / 3; object-fit: cover; background: var(--line); }
.ep .soon { display: flex; align-items: center; justify-content: center; aspect-ratio: 2 / 3;
  background: repeating-linear-gradient(135deg, color-mix(in srgb, var(--sc, var(--accent)) 14%, var(--card)) 0 14px, var(--card) 14px 28px);
  color: var(--sc, var(--muted)); font-weight: 600; }
.ep .meta { padding: 10px 12px 14px; }
.ep strong { display: block; line-height: 1.4; }
.ep small { color: var(--muted); font-size: .8rem; }

/* เล่มหนังสือ 3 มิติ: เอียง สันปก ขอบกระดาษ แสงวาบ */
.shelf { perspective: 1200px; padding: 4px 6px 10px 2px; }
.ep { position: relative; border-radius: 4px 14px 14px 4px; transform-origin: left center;
  transform: rotateY(-9deg); transition: transform .45s cubic-bezier(.2,.8,.2,1), box-shadow .45s;
  box-shadow: 1px 1px 0 #fff, 3px 3px 0 #EDE3D0, 4px 4px 0 #fff, 6px 6px 0 #E3D6BD,
    10px 16px 22px rgb(60 30 0 / .28), 2px 4px 6px rgb(60 30 0 / .18); }
.ep::before { content: ''; position: absolute; inset: 0 auto 0 0; width: 14px; z-index: 2; pointer-events: none;
  background: linear-gradient(90deg, rgb(0 0 0 / .38), rgb(255 255 255 / .35) 40%, rgb(0 0 0 / .12) 70%, transparent); }
.ep::after { content: ''; position: absolute; inset: 0; z-index: 3; pointer-events: none;
  background: linear-gradient(115deg, transparent 35%, rgb(255 255 255 / .55) 48%, transparent 60%);
  transform: translateX(-120%); transition: transform .8s ease; }
a.ep:hover, a.ep:focus-visible, a.ep:active { transform: rotateY(0) translateY(-8px) scale(1.04);
  box-shadow: 1px 1px 0 #fff, 3px 3px 0 #EDE3D0, 4px 4px 0 #fff, 6px 6px 0 #E3D6BD,
    0 26px 40px rgb(60 30 0 / .35), 0 0 0 3px color-mix(in srgb, var(--sc, var(--accent)) 45%, transparent); }
a.ep:hover::after, a.ep:focus-visible::after, a.ep:active::after { transform: translateX(120%); }
.ep .cover { filter: saturate(1.1) contrast(1.04); }
.ep .no { box-shadow: 0 2px 6px color-mix(in srgb, var(--sc, var(--accent)) 50%, transparent); }
@media (prefers-color-scheme: dark) { .ep { box-shadow: 1px 1px 0 #4a3f33, 3px 3px 0 #2e2620, 4px 4px 0 #4a3f33, 6px 6px 0 #2e2620, 10px 16px 22px rgb(0 0 0 / .55); } }
@media (prefers-reduced-motion: reduce) { .ep, .ep::after { transition: none; } }

/* หน้าอ่าน */
.strip { max-width: 900px; margin: 0 auto; }
.pg { margin: 0 0 6px; scroll-margin-top: 64px; }
.pg img { display: block; width: 100%; height: auto; aspect-ratio: 2 / 3; background: var(--line); }
.end { padding-top: 32px; padding-bottom: 32px; display: grid; gap: 22px; }
.box { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 18px; }
#donate { background: linear-gradient(160deg, var(--tint), var(--card) 45%); border: 2px solid var(--gold); }
#donate h2, #donors h2 { color: var(--accent); }
.row { display: flex; flex-wrap: wrap; gap: 10px; }
.qr { display: block; width: 100%; max-width: 320px; height: auto; margin: 12px auto; border-radius: 8px; }
.acct { font-family: 'IBM Plex Sans Thai', sans-serif; font-size: 1.2rem; font-weight: 600; }
.epbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; background: var(--bar);
  border-top: 3px solid var(--gold); display: flex; justify-content: space-between; gap: 8px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); }
.epbar .btn { flex: 1; font-size: .85rem; padding: 4px 8px; color: var(--bar-ink); border-color: var(--bar-ink); }
.epbar .btn[aria-disabled="true"] { opacity: .35; pointer-events: none; }
.dtable { overflow-x: auto; margin: 0 0 12px; }
.donors { width: 100%; border-collapse: separate; border-spacing: 5px; margin: 0 -5px; font-size: .95rem; }
.donors th, .donors td { padding: 10px 12px; border-radius: 10px; border: 2px solid var(--c, #FF8A00); vertical-align: middle; }
.donors thead th { background: linear-gradient(120deg, #FF8A00, #E52E71); border-color: transparent; color: #fff; font-weight: 700; }
.donors tbody tr:nth-child(4n+1) { --c: #FFB300; }
.donors tbody tr:nth-child(4n+2) { --c: #00C2A8; }
.donors tbody tr:nth-child(4n+3) { --c: #3B82F6; }
.donors tbody tr:nth-child(4n+4) { --c: #EC4899; }
.donors tbody td { background: color-mix(in srgb, var(--c) 13%, var(--card)); }
.donors td:first-child { text-align: center; width: 1%; }
.donors td:last-child { text-align: right; white-space: nowrap; font-weight: 700; width: 1%; }
@media (max-width: 600px) { .donors { border-spacing: 3px; margin: 0 -3px; font-size: .88rem; } .donors th, .donors td { padding: 8px 7px; } }
.donors .no { display: inline-grid; place-items: center; min-width: 2em; height: 2em; padding: 0 6px; border-radius: 999px;
  background: var(--c); color: #fff; font-weight: 700; }
.donors p { margin: 4px 0 0; color: var(--muted); }
.donors tfoot th, .donors tfoot td { background: linear-gradient(120deg, #10B981, #0EA5E9); border-color: transparent; color: #fff;
  font-weight: 700; font-size: 1.05rem; }
.donors tfoot th { text-align: right; }
.site-foot { text-align: center; padding: 24px 16px 32px; margin-top: 24px; border-top: 1px solid var(--line); color: var(--muted); font-size: .95rem; line-height: 1.9; }
.site-foot a { color: inherit; font-weight: 600; }
/* หน้าอ่าน: เว้นท้ายเว็บไม่ให้แถบเลื่อนตอนบัง */
body:has(.epbar) .site-foot { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }

/* มือถือ: แถบบน/ล่างเตี้ยลง ให้เหลือพื้นที่อ่านมากขึ้น */
@media (max-width: 600px) {
  .top { border-bottom-width: 2px; }
  .top .wrap { min-height: 42px; gap: 8px; padding: 0 10px; }
  .top .btn.small { min-height: 32px; padding: 0 10px; font-size: .75rem; border-width: 1.5px; border-radius: 8px; }
  .top .title { font-size: .8rem; }
  .pg { scroll-margin-top: 46px; }
  .epbar { gap: 6px; border-top-width: 2px; padding: 4px 8px calc(4px + env(safe-area-inset-bottom)); }
  .epbar .btn { min-height: 36px; padding: 0 6px; font-size: .75rem; border-width: 1.5px; border-radius: 8px; }
  body:has(.epbar) .site-foot { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
}
.ep .views { color: var(--sc, var(--accent)); font-weight: 600; }

/* หน้าแรกแบบใหม่ (ต.ค. 2569): แบนเนอร์ตอนแนะนำ วงกลมเรื่อง การ์ดตอน เมนูล่าง — โทนเดียวกับเว็บธรรมบท */
body.home { --forest: #16302A; --saffron: #D98A1F; --chip: #FFFDF8; }
@media (prefers-color-scheme: dark) { body.home { --chip: #26201A; } }
body.home svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.home .eyebrow { display: block; color: var(--accent); font-size: .8rem; font-weight: 600; }
.home .intro { padding: 22px 0 6px; }
.home .intro h1 { color: var(--ink); margin-top: 2px; }
.home .intro h1::after { display: none; }
.home .intro .lead { font-weight: 400; color: var(--muted); font-size: 1rem; margin: 6px 0 14px; }
.home .purpose { border-left: 5px solid var(--gold); background: var(--tint); border-radius: 0 12px 12px 0; padding: 10px 14px; margin: 18px 0 8px; }

.hero-slides { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; border-radius: 24px; box-shadow: 0 16px 36px rgb(22 48 42 / .3); }
.hero-slides::-webkit-scrollbar { display: none; }
.slide { flex: 0 0 100%; scroll-snap-align: start; position: relative; overflow: hidden; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 20px;
  padding: 28px 32px; min-height: 300px; text-decoration: none; color: #F7EFDC;
  background: radial-gradient(circle at 80% 50%, rgb(217 138 31 / .35), transparent 45%), linear-gradient(135deg, #16302A, #21463B 60%, #2B5547); }
.slide::before { content: ''; position: absolute; right: -70px; bottom: -110px; width: 300px; height: 300px; border-radius: 50%;
  border: 1px solid rgb(240 196 106 / .25); box-shadow: 0 0 0 28px rgb(240 196 106 / .05), 0 0 0 56px rgb(240 196 106 / .03); }
.slide-copy { position: relative; display: grid; justify-items: start; gap: 4px; }
.slide-tag { background: rgb(240 196 106 / .18); color: #F0C46A; border: 1px solid rgb(240 196 106 / .5); border-radius: 999px; padding: 0 12px; font-size: .75rem; font-weight: 600; }
.slide-title { font-family: 'Prompt', sans-serif; font-size: 1.6rem; line-height: 1.3; color: #fff; margin-top: 6px; }
.slide-ep { font-size: 1rem; color: #E6DCC5; }
.slide-btn { display: inline-flex; align-items: center; gap: 10px; margin-top: 12px; min-height: 52px; padding: 0 24px; border-radius: 999px;
  background: var(--saffron); color: #1D1407; font-weight: 700; box-shadow: 0 6px 16px rgb(217 138 31 / .4); }
.slide:hover .slide-btn, .slide:focus-visible .slide-btn { background: #F0C46A; }
.slide small { color: #CFC4AB; font-size: .8rem; margin-top: 6px; }
.slide-art { position: relative; width: 170px; }
.slide-art::before { content: ''; position: absolute; inset: -24px -30px; border-radius: 50%; background: radial-gradient(circle, rgb(240 196 106 / .3), transparent 68%); }
.slide-art .cover { position: relative; display: block; width: 100%; height: auto; aspect-ratio: 2 / 3; object-fit: cover; border-radius: 10px;
  transform: rotate(4deg); border: 3px solid #FFF8E6; box-shadow: 0 16px 30px rgb(0 0 0 / .45); background: #2B5547; }
.hero-dots { display: flex; margin-top: 4px; }
.hero-dots button { width: 44px; height: 44px; display: grid; place-items: center; background: none; border: 0; padding: 0; cursor: pointer; }
.hero-dots button::after { content: ''; width: 10px; height: 10px; border-radius: 6px; background: var(--line); transition: width .2s; }
.hero-dots button[aria-pressed="true"]::after { width: 28px; background: var(--saffron); }

.quick { display: flex; gap: 10px; overflow-x: auto; scrollbar-width: none; margin: 10px -16px 0; padding: 2px 16px 4px; }
.quick::-webkit-scrollbar { display: none; }
.quick a { flex: none; display: inline-flex; align-items: center; min-height: 48px; padding: 0 20px; border-radius: 999px; text-decoration: none;
  background: var(--card); border: 1px solid var(--line); color: var(--ink); font-weight: 600; font-size: .9rem; }
.quick a:first-child { background: var(--saffron); border-color: var(--saffron); color: #1D1407; }

/* เรื่องทั้งหมด: วงกลมสีประจำเรื่อง */
.home .toc { display: flex; flex-wrap: wrap; gap: 14px 8px; }
.home .toc li { width: 120px; }
.home .toc a { flex-direction: column; text-align: center; gap: 6px; padding: 4px 2px; background: none; border: 0; box-shadow: none; font-size: .85rem; }
.home .toc a:hover, .home .toc a:focus-visible { transform: translateY(-3px); background: none; }
.home .toc .n { width: 64px; height: 64px; font-size: 1.4rem; font-family: 'Prompt', sans-serif; border: 3px solid var(--chip);
  box-shadow: 0 0 0 2px var(--sc), 0 6px 14px rgb(60 30 0 / .2); }
.home .toc a:hover .n { box-shadow: 0 0 0 3px var(--saffron), 0 8px 18px rgb(60 30 0 / .25); }

/* ยอดนิยม / มาใหม่: การ์ดเรียงข้างกัน */
@media (min-width: 700px) { .home .popular ol { grid-template-columns: repeat(3, 1fr); } }

/* ชั้นตอน: การ์ดแบน มุมโค้ง แทนเล่ม 3 มิติ */
.home .series { background: var(--card); border: 1px solid var(--line); border-top: 6px solid var(--sc); box-shadow: 0 6px 18px rgb(60 30 0 / .06); }
.home .shelf { perspective: none; padding: 0; }
.home .ep { transform: none; border: 1px solid var(--line); border-radius: 18px; padding: 8px; background: var(--bg);
  box-shadow: 0 6px 16px rgb(60 30 0 / .1); transition: transform .2s, box-shadow .2s; }
.home .ep::before { display: none; }
.home .ep::after { border-radius: 18px; }
.home .ep .cover { border-radius: 12px; }
.home .ep .soon { border-radius: 12px; }
.home a.ep:hover, .home a.ep:focus-visible, .home a.ep:active { transform: translateY(-4px); box-shadow: 0 14px 26px rgb(60 30 0 / .2), 0 0 0 3px color-mix(in srgb, var(--sc) 45%, transparent); }
.home .ep .meta { padding: 10px 4px 4px; }
@media (prefers-color-scheme: dark) { .home .ep { box-shadow: 0 6px 16px rgb(0 0 0 / .4); } }

/* เมนูล่าง (มือถือ) */
.tabbar { display: none; }
@media (max-width: 700px) {
  .slide { grid-template-columns: 1fr 110px; gap: 12px; padding: 20px 18px; min-height: 250px; }
  .slide-title { font-size: 1.25rem; }
  .slide-ep { font-size: .9rem; }
  .slide-btn { min-height: 48px; padding: 0 18px; }
  .slide-art { width: 110px; }
  .home .toc { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 4px 16px 8px; }
  .home .toc::-webkit-scrollbar { display: none; }
  .home .toc li { flex: none; width: 108px; }
  .tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; justify-content: space-around;
    background: color-mix(in srgb, var(--card) 94%, transparent); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
    border-top: 1px solid var(--line); padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); box-shadow: 0 -6px 20px rgb(60 30 0 / .1); }
  .tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-width: 72px; min-height: 56px;
    text-decoration: none; color: var(--muted); font-size: .75rem; font-weight: 600; }
  .tabbar a:active { color: var(--accent); }
  body.home .site-foot { padding-bottom: calc(90px + env(safe-area-inset-bottom)); }
}
