/* ========================================
   ธรรมบทอ่านง่าย — ธีมห้องฉาย (๑๐ ต.ค. ๒๕๖๙ หลวงพี่สั่ง "ปรับ design ให้เข้ากับหน้าอื่นๆ")
   หน้ารวมเล่ม + รายชื่อเรื่อง = ป้ายใหญ่เต็มจอ + การ์ดโปสเตอร์ (แบบ /videos · /vocab-bank)
   หน้าอ่าน = กระดาษวางบนโต๊ะเข้ม (แบบธรรมบท ๒ ภาษา)
   ไม่ใช้แถบสีขอบซ้าย — การ์ด/แถวใช้กรอบรอบทั้งใบ หรือพื้นเต็มแถว
   ======================================== */

.ds-wrap { width: 100%; max-width: 80rem; margin: 0 auto; padding: 0 16px; }
@media (min-width: 640px) { .ds-wrap { padding: 0 24px; } }

/* ════ แถบหัวของหน้า (ใต้เมนูบน) ════ */
.ds-bar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(var(--ui-lpanel-rgb, 15, 23, 48), .92); border-bottom: 1px solid var(--ds-line);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.ds-bar-inner { display: flex; align-items: center; gap: 12px; min-height: var(--ds-bar-h); }
.ds-bar-brand { display: flex; flex-direction: column; justify-content: center; min-height: 44px; min-width: 0; color: var(--ui-strong); text-decoration: none; line-height: 1.25; }
.ds-bar-name { font-size: 16px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: color .15s ease; }
.ds-bar-sub { font-size: 12px; font-weight: 700; color: var(--ds-muted); }
.ds-bar-brand:hover .ds-bar-name { color: var(--ds-gold); }
.ds-bar-back {
  display: inline-flex; align-items: center; gap: 10px; min-height: 44px; min-width: 0; padding: 0 14px 0 12px;
  border-radius: 12px; border: 1px solid var(--ds-line2); background: rgba(var(--ui-tint), .07); color: var(--ui-ink2);
  font-family: inherit; font-size: 15px; font-weight: 800; cursor: pointer; transition: background-color .15s ease;
}
.ds-bar-back i { color: var(--ds-gold); }
.ds-bar-back span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ds-bar-back:hover { background: rgba(var(--ui-tint), .14); color: var(--ui-strong); }

/* ════ ป้ายใหญ่ (billboard) ════ */
.ds-bill { position: relative; isolation: isolate; overflow: hidden; background: var(--ds-bg); }
.ds-bill::before {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background:
    linear-gradient(90deg, rgba(10, 15, 30, .97) 0%, rgba(10, 15, 30, .86) 34%, rgba(10, 15, 30, .25) 64%, rgba(10, 15, 30, .05) 100%),
    linear-gradient(0deg, var(--ds-bg) 0%, rgba(10, 15, 30, .72) 16%, rgba(10, 15, 30, 0) 42%),
    linear-gradient(180deg, rgba(10, 15, 30, .55) 0%, rgba(10, 15, 30, 0) 18%);
}
.ds-bill-inner { min-height: clamp(470px, 64vh, 600px); display: flex; flex-direction: column; justify-content: flex-end; padding-top: 48px; padding-bottom: 36px; }
.ds-bill-copy { max-width: 620px; display: flex; flex-direction: column; gap: 12px; }
.ds-eyebrow { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 800; color: var(--ds-muted); }
.ds-eyebrow i { color: var(--ds-gold); }
.ds-title { font-size: clamp(2.2rem, 4.8vw, 3.6rem); font-weight: 800; line-height: 1.25; letter-spacing: -.01em; color: var(--ui-strong); text-shadow: 0 2px 24px rgba(0, 0, 0, .45); }
.ds-title span { display: block; color: var(--ds-gold); }
.ds-desc { max-width: 560px; font-size: 17px; line-height: 1.7; color: var(--ui-ink2); }
.ds-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; font-size: 14px; }
.ds-meta-chip { display: inline-flex; align-items: center; gap: 8px; min-height: 32px; padding: 0 12px; border-radius: 999px; background: rgba(var(--ui-tint), .1); border: 1px solid var(--ds-line2); color: var(--ui-ink2); font-weight: 800; backdrop-filter: blur(6px); }
.ds-meta-chip i { color: var(--ds-gold); }
.ds-meta-note { color: var(--ds-muted); font-weight: 600; }

/* กำแพงปก ๘ ภาค (หน้ารวมเล่ม) */
.ds-wall {
  position: absolute; z-index: -2; top: -36px; right: -48px;
  display: grid; grid-template-columns: repeat(4, var(--tile)); grid-auto-rows: var(--tile); gap: 16px;
  --tile: calc((clamp(470px, 64vh, 600px) + 72px) / 2 - 8px);
  transform: rotate(-4deg); transform-origin: 100% 0;
}
.ds-wall img { width: 100%; height: 100%; object-fit: cover; border-radius: 16px; box-shadow: 0 0 0 1px rgba(var(--ui-tint), .08); }
.ds-wall img:nth-child(even) { transform: translateY(26px); }

/* ปกภาคนั้น (หน้ารายชื่อเรื่อง) */
.ds-bill-vol { background: radial-gradient(ellipse 60% 80% at 78% 30%, rgba(245, 191, 69, .1), transparent 70%), var(--ds-bg); }
.ds-bill-cover {
  position: absolute; z-index: -2; top: 0; right: 0; height: 100%; aspect-ratio: 1; max-width: 62%; object-fit: cover;
  -webkit-mask-image: linear-gradient(90deg, transparent 0%, #000 38%); mask-image: linear-gradient(90deg, transparent 0%, #000 38%);
}
.ds-bill-vol .ds-bill-inner { min-height: clamp(420px, 56vh, 540px); }
/* กำแพงปกเรื่องของภาค: แผ่นเล็กลงตามความสูงป้ายของหน้าภาค */
.ds-bill-vol.has-wall .ds-wall { --tile: calc((clamp(420px, 56vh, 540px) + 72px) / 2 - 8px); }

/* ปุ่ม */
.ds-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 6px; }
.ds-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px; min-height: 52px; padding: 8px 22px;
  border-radius: 12px; border: 0; font-family: inherit; font-size: 16px; font-weight: 800; text-decoration: none; cursor: pointer;
  transition: transform .15s ease, background-color .15s ease, color .15s ease;
}
.ds-btn:active { transform: scale(.97); }
.ds-btn-play { background: #fff; color: var(--ds-bg); }
.ds-btn-play:hover { background: var(--ds-gold-fill, var(--ds-gold)); }
.ds-btn-ghost { background: rgba(var(--ui-tint), .16); color: var(--ui-strong); backdrop-filter: blur(6px); }
.ds-btn-ghost:hover { background: rgba(var(--ui-tint), .26); }
.ds-btn-ghost i { color: var(--ds-gold); }
.ds-btn-stack { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; line-height: 1.25; text-align: left; }
.ds-btn-stack small { font-size: 12px; font-weight: 700; color: #4b5576; }
.ds-btn-stack > span { max-width: 17rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* ปุ่มโหลดแอป PuriNotes (ปุ่มกระจก) — ตัวเล็กบนพื้นเข้มต้องสว่าง · ไอคอนร้านค้าขาว */
.ds-btn-app .ds-btn-stack small { color: var(--ui-indigo); font-size: 14px; white-space: nowrap; }
.ds-btn-app > i { color: var(--ui-strong) !important; font-size: 1.25em; }
.ds-app-pair { display: contents; }

/* ช่องค้นหา */
.ds-search { position: relative; max-width: 520px; margin-top: 4px; }
.ds-search i { position: absolute; z-index: 1; left: 18px; top: 50%; transform: translateY(-50%); color: var(--ds-gold); pointer-events: none; }
.ds-search input {
  width: 100%; min-height: 52px; padding: 0 18px 0 48px; border-radius: 12px;
  background: rgba(var(--ui-lpanel-rgb, 15, 23, 48), .78); border: 1px solid var(--ds-line2); color: var(--ui-strong);
  font-family: 'Sarabun', sans-serif; font-size: 16px; font-weight: 600; outline: none;
  backdrop-filter: blur(8px); transition: border-color .15s ease, box-shadow .15s ease;
}
.ds-search input::placeholder { color: #8f9abb; }
.ds-search input:focus { border-color: var(--ds-gold); box-shadow: 0 0 0 3px rgba(245, 191, 69, .2); }
.ds-search input::-webkit-search-cancel-button { filter: invert(1); opacity: .6; cursor: pointer; }
.ds-search-sm { margin: 0; flex: 1 1 260px; max-width: 340px; }
.ds-search-sm input { min-height: 46px; background: rgba(var(--ui-tint), .06); }

/* ════ เนื้อหา ════ */
.ds-body { padding-top: 32px; padding-bottom: 64px; scroll-margin-top: calc(var(--ds-bar-h) + 12px); }
.ds-sec + .ds-sec { margin-top: 44px; }
.ds-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; margin-bottom: 18px; }
.ds-head > div { flex: 1 1 260px; min-width: 0; }
.ds-head h2 { font-size: clamp(1.3rem, 2vw, 1.6rem); font-weight: 800; line-height: 1.3; color: var(--ui-strong); }
.ds-head p { margin-top: 2px; font-size: 15px; line-height: 1.55; color: var(--ds-muted); }
.ds-no { width: 48px; height: 48px; flex: none; display: grid; place-items: center; border-radius: 14px; background: linear-gradient(135deg, #4338ca, #312e81); color: #fff; font-size: 22px; font-weight: 800; box-shadow: inset 0 0 0 1px rgba(var(--ui-tint), .15); }
.ds-no i { font-size: 18px; color: var(--ds-gold); }
.ds-list-tools { display: flex; align-items: center; gap: 8px; flex: 1 1 360px; justify-content: flex-end; }
.ds-icon-btn {
  width: 46px; height: 46px; flex: none; display: grid; place-items: center; border-radius: 12px; cursor: pointer;
  background: rgba(var(--ui-tint), .06); border: 1px solid var(--ds-line2); color: var(--ui-ink2); font-size: 17px;
  transition: background-color .15s ease, color .15s ease, border-color .15s ease;
}
.ds-icon-btn:hover { background: rgba(var(--ui-tint), .14); color: var(--ui-strong); }
.ds-icon-btn.on { background: var(--ds-gold-fill, var(--ds-gold)); border-color: var(--ds-gold); color: var(--ds-gold-ink); }

/* ── ปกภาค ── */
.ds-vol-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; }
.ds-vol {
  display: flex; flex-direction: column; padding: 0; overflow: hidden; text-align: left; cursor: pointer; font-family: inherit;
  border-radius: 18px; background: var(--ds-card); border: 1.5px solid var(--ds-card-line); color: var(--ui-strong);
  box-shadow: 0 14px 30px -20px rgba(0, 0, 0, .85);
  transition: transform .3s cubic-bezier(.25, 1, .5, 1), border-color .2s ease, box-shadow .25s ease;
}
.ds-vol:hover { transform: translateY(-4px); border-color: var(--ds-gold); box-shadow: 0 0 0 3px rgba(245, 191, 69, .18), 0 22px 44px -18px rgba(0, 0, 0, .95); }
.ds-vol-art { position: relative; display: block; aspect-ratio: 1; overflow: hidden; background: var(--ds-panel); }
.ds-vol-art img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .6s ease; }
.ds-vol:hover .ds-vol-art img { transform: scale(1.05); }
.ds-vol-art::after { content: ""; position: absolute; inset: 0; background: linear-gradient(0deg, rgba(24, 34, 63, 1) 0%, rgba(24, 34, 63, 0) 34%); pointer-events: none; }
.ds-vol-no { position: absolute; z-index: 1; top: 12px; left: 12px; display: inline-flex; align-items: center; height: 30px; padding: 0 12px; border-radius: 999px; background: rgba(255, 255, 255, .95); color: #3730a3; font-size: 15px; font-weight: 800; }
.ds-vol-info { display: flex; flex-direction: column; gap: 4px; padding: 4px 16px 16px; }
.ds-vol-title { font-size: 19px; font-weight: 800; line-height: 1.35; color: var(--ui-strong); }
.ds-vol-count { display: inline-flex; align-items: center; gap: 7px; font-size: 14px; font-weight: 700; color: var(--ds-muted); }
.ds-vol-count i { color: var(--ds-gold); font-size: 12px; }

/* ── การ์ดเรื่อง ── */
.ds-story-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.ds-story {
  position: relative; display: flex; flex-direction: column; overflow: hidden; cursor: pointer;
  border-radius: 16px; background: var(--ds-bg2); border: 1px solid var(--ds-line); color: var(--ui-strong);
  transition: transform .3s cubic-bezier(.25, 1, .5, 1), border-color .2s ease, box-shadow .25s ease;
}
.ds-story:hover { transform: translateY(-4px); border-color: rgba(var(--ui-tint), .28); box-shadow: 0 18px 40px -18px rgba(0, 0, 0, .9); }
.ds-story-art { position: relative; display: block; aspect-ratio: 4 / 3; overflow: hidden; background: var(--ds-panel); }
.ds-story-art img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .5s ease; }
.ds-story:hover .ds-story-art img { transform: scale(1.05); }
.ds-story-art::after { content: ""; position: absolute; inset: 0; background: linear-gradient(0deg, rgba(15, 23, 48, 1) 0%, rgba(15, 23, 48, .3) 26%, rgba(15, 23, 48, 0) 50%); pointer-events: none; }
.ds-story-no { position: absolute; z-index: 1; top: 10px; left: 10px; display: inline-flex; align-items: center; height: 26px; padding: 0 10px; border-radius: 999px; background: rgba(255, 255, 255, .95); color: #3730a3; font-size: 13px; font-weight: 800; }
.ds-story-info { display: flex; flex: 1; flex-direction: column; gap: 4px; padding: 4px 16px 16px; }
.ds-story-title { font-size: 17px; font-weight: 800; line-height: 1.4; color: var(--ui-strong); }
.ds-story-vagga { font-size: 13px; font-weight: 700; color: var(--ds-gold); }
.ds-story-desc { font-size: 14px; line-height: 1.55; color: var(--ds-muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ds-mark {
  position: absolute; z-index: 2; top: 6px; right: 6px; width: 44px; height: 44px; display: grid; place-items: center;
  border: 0; border-radius: 999px; cursor: pointer; background: rgba(10, 15, 30, .62); color: #fff; font-size: 16px;
  backdrop-filter: blur(4px); transition: background-color .15s ease, color .15s ease, transform .15s ease;
}
.ds-mark:hover { background: rgba(var(--ui-lpanel-rgb, 10, 15, 30), .85); transform: scale(1.06); }
.ds-mark.on { background: var(--ds-gold-fill, var(--ds-gold)); color: var(--ds-gold-ink); }

/* มุมมองรายการ: แถวเต็ม ภาพเล็กซ้าย */
.ds-story-grid.is-list { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.is-list .ds-story { flex-direction: row; align-items: center; gap: 14px; min-height: 84px; padding: 8px 60px 8px 8px; border-radius: 14px; }
.is-list .ds-story:hover { transform: none; background: var(--ds-panel); }
.is-list .ds-story-art { width: 68px; height: 68px; flex: none; aspect-ratio: 1; border-radius: 12px; }
.is-list .ds-story-art::after { display: none; }
.is-list .ds-story-no { top: auto; bottom: 4px; left: 4px; height: 20px; padding: 0 7px; font-size: 11px; }
.is-list .ds-story-info { padding: 0; justify-content: center; }
.is-list .ds-story-title { font-size: 16px; }
.is-list .ds-mark { top: 50%; right: 8px; transform: translateY(-50%); background: rgba(var(--ui-tint), .06); }
.is-list .ds-mark:hover { transform: translateY(-50%) scale(1.06); background: rgba(var(--ui-tint), .14); }
.is-list .ds-mark.on { background: var(--ds-gold-fill, var(--ds-gold)); }

/* โครงรอโหลด */
.ds-skel { display: block; height: 300px; border-radius: 16px; background: var(--ds-panel); animation: dspulse 1.4s ease-in-out infinite; }
@keyframes dspulse { 50% { opacity: .55; } }

/* ── ผลค้นหาในเนื้อเรื่อง ── */
.ds-hits { display: flex; flex-direction: column; gap: 14px; }
.ds-hit { overflow: hidden; border-radius: 16px; background: var(--ds-bg2); border: 1px solid var(--ds-line); }
.ds-hit-head {
  display: flex; align-items: center; gap: 14px; width: 100%; padding: 12px 16px 12px 12px; border: 0; cursor: pointer;
  background: none; color: var(--ui-strong); font-family: inherit; text-align: left; transition: background-color .15s ease;
}
.ds-hit-head:hover { background: rgba(var(--ui-tint), .05); }
.ds-hit-head img { width: 56px; height: 56px; flex: none; object-fit: cover; border-radius: 12px; }
.ds-hit-head > i { color: var(--ds-dim); }
.ds-hit-info { display: flex; flex: 1; min-width: 0; flex-direction: column; gap: 2px; }
.ds-hit-title { font-size: 17px; font-weight: 800; line-height: 1.35; }
.ds-hit-meta { font-size: 13px; font-weight: 700; color: var(--ds-muted); }
.ds-hit-list { display: flex; flex-direction: column; gap: 2px; padding: 6px 8px 10px; border-top: 1px solid var(--ds-line); }
.ds-hit-row { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 6px 10px; border-radius: 10px; color: var(--ui-ink2); font-size: 15px; line-height: 1.5; text-decoration: none; transition: background-color .15s ease; }
.ds-hit-row:hover { background: rgba(var(--ui-tint), .07); color: var(--ui-strong); }
.ds-hit-page { flex: none; padding: 2px 9px; border-radius: 999px; background: rgba(245, 191, 69, .16); color: var(--ds-gold); font-size: 12px; font-weight: 800; white-space: nowrap; }
.ds-hit-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ds-hit-text mark { padding: 0 3px; border-radius: 4px; background: var(--ds-gold-fill, var(--ds-gold)); color: var(--ds-gold-ink); font-weight: 700; }

.ds-empty { display: flex; flex-direction: column; align-items: center; gap: 12px; max-width: 520px; margin: 0 auto; padding: 56px 16px; text-align: center; font-size: 16px; font-weight: 700; line-height: 1.6; color: var(--ds-muted); }
.ds-empty i { font-size: 28px; color: var(--ds-dim); }

/* ── ส่วนท้าย ── */
.ds-foot { padding: 32px 0 48px; border-top: 1px solid var(--ds-line); text-align: center; }
.ds-foot p { margin-bottom: 16px; font-size: 14px; color: var(--ds-muted); }
.ds-foot .ds-btn { min-height: 46px; font-size: 15px; background: rgba(var(--ui-tint), .08); border: 1px solid var(--ds-line2); }

/* ════ หน้าอ่าน: กระดาษบนโต๊ะเข้ม ════ */
.reader-view { display: flex; height: calc(100vh - var(--ds-nav-h)); height: calc(100dvh - var(--ds-nav-h)); overflow: hidden; background: var(--ds-bg); }

/* สารบัญ */
.toc-sidebar {
  position: relative; z-index: 100; width: 290px; flex: none; display: flex; flex-direction: column; overflow: hidden;
  background: var(--ds-bg2); border-right: 1px solid var(--ds-line);
}
.toc-header { position: relative; flex: none; padding: 14px 14px 16px; border-bottom: 1px solid var(--ds-line); }
.toc-back {
  display: flex; align-items: center; gap: 8px; width: 100%; min-height: 44px; padding: 0 14px; border-radius: 12px; cursor: pointer;
  background: rgba(var(--ui-tint), .07); border: 1px solid var(--ds-line2); color: var(--ui-ink2);
  font-family: inherit; font-size: .92em; font-weight: 800; text-align: left; transition: background-color .15s ease;
}
.toc-back:hover { background: rgba(var(--ui-tint), .14); color: var(--ui-strong); }
.toc-close { display: none; }
.toc-story-title { margin-top: 12px; padding: 0 4px; font-size: 1.05em; font-weight: 800; line-height: 1.4; color: var(--ui-strong); }
.toc-list { flex: 1; overflow-y: auto; padding: 10px 10px 28px; }
.toc-list::-webkit-scrollbar { width: 6px; }
.toc-list::-webkit-scrollbar-thumb { background: rgba(var(--ui-tint), .16); border-radius: 4px; }
.toc-ch { margin: 14px 0 4px; padding: 8px 10px; border-radius: 10px; color: var(--ds-gold); line-height: 1.3; transition: background-color .15s ease; }
.toc-ch-clickable { cursor: pointer; }
.toc-ch-clickable:hover { background: rgba(var(--ui-tint), .05); }
.toc-ch-num { display: block; font-size: .82em; font-weight: 800; letter-spacing: .04em; }
.toc-ch-sub { display: block; margin-top: 2px; font-size: .86em; font-weight: 600; color: var(--ui-ink2); }
.toc-sec {
  display: block; width: 100%; min-height: 40px; padding: 8px 12px; border: 1px solid transparent; border-radius: 10px; cursor: pointer;
  background: none; color: var(--ui-ink2); font-family: 'Sarabun', sans-serif; font-size: .9em; line-height: 1.45; text-align: left;
  transition: background-color .15s ease, color .15s ease;
}
.toc-sec:hover { background: rgba(var(--ui-tint), .06); color: var(--ui-strong); }
.toc-sec.active { background: rgba(245, 191, 69, .14); border-color: rgba(245, 191, 69, .4); color: var(--ui-gold-ink); font-weight: 700; }
.toc-cover { font-weight: 800; color: var(--ui-strong); }
.toc-overlay { display: none; }

/* แถบบน + พื้นโต๊ะ */
.reader-wrap { position: relative; flex: 1; min-width: 0; display: flex; flex-direction: column; overflow: hidden; }
.reader-topbar {
  flex: none; display: flex; align-items: center; gap: 12px; min-height: var(--ds-bar-h); padding: 8px 16px 8px 24px;
  background: rgba(var(--ui-lpanel-rgb, 15, 23, 48), .94); border-bottom: 1px solid var(--ds-line);
}
.toc-toggle {
  display: none; width: 44px; height: 44px; flex: none; place-items: center; border-radius: 12px; cursor: pointer;
  background: rgba(var(--ui-tint), .07); border: 1px solid var(--ds-line2); color: var(--ds-gold); font-size: 17px;
}
.toc-toggle:hover { background: rgba(var(--ui-tint), .14); }
.topbar-title { flex: 1; min-width: 0; font-size: 16px; font-weight: 800; color: var(--ui-strong); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-indicator { flex: none; padding: 4px 10px; border-radius: 999px; background: rgba(var(--ui-tint), .07); color: var(--ds-muted); font-size: 13px; font-weight: 800; white-space: nowrap; }
.reader-topbar .ds-tools { margin-left: 4px; }

.page-container { flex: 1; overflow-y: auto; padding: 28px 24px 40px; scroll-behavior: smooth; }
.page-container::-webkit-scrollbar { width: 8px; }
.page-container::-webkit-scrollbar-thumb { background: var(--reader-scrollbar); border-radius: 4px; }

/* กระดาษ */
.page {
  max-width: 820px; margin: 0 auto; padding: 40px 48px 48px; border-radius: 20px;
  background: var(--paper); color: var(--reader-text);
  box-shadow: 0 1px 0 var(--paper-edge) inset, 0 30px 60px -28px rgba(0, 0, 0, .95), 0 0 0 1px rgba(var(--ui-tint), .06);
}
.page-wrap { animation: pageIn .35s ease; }
.page-wrap.anim-back { animation: pageInBack .35s ease; }
.page-wrap.anim-forward { animation: pageIn .35s ease; }
@keyframes pageIn { from { opacity: 0; transform: translateX(30px); } to { opacity: 1; transform: none; } }
@keyframes pageInBack { from { opacity: 0; transform: translateX(-30px); } to { opacity: 1; transform: none; } }

/* หน้าปกเรื่อง */
.cover-hero { position: relative; overflow: hidden; margin-bottom: 28px; padding: 26px 16px 18px; border: 1px solid var(--reader-rule); border-radius: 18px; background: var(--reader-cover-bg); text-align: center; }
.cover-title { margin-bottom: 8px; font-size: clamp(1.6rem, 4vw, 2.3rem); font-weight: 800; line-height: 1.3; color: var(--reader-heading); }
.cover-sub { margin-bottom: 6px; font-size: 1.12rem; font-style: italic; color: var(--reader-accent); }
.cover-src { margin-bottom: 16px; font-size: .88rem; color: var(--reader-text-secondary); }
.cover-rule { width: 64px; height: 2px; margin: 0 auto 6px; background: linear-gradient(90deg, transparent, var(--ds-gold), transparent); }
.cover-img-wrap { margin: 0 0 24px; overflow: hidden; border-radius: 14px; }
.cover-img { display: block; width: 100%; object-fit: cover; object-position: center; }
.cover-desc { max-width: 600px; margin: 0 auto 24px; padding: 0 16px; font-size: 1em; font-style: italic; line-height: 1.75; text-align: center; color: var(--reader-text-secondary); }
.intro-h2 { margin: 0 0 14px; padding-bottom: 8px; font-size: 1.3rem; font-weight: 700; color: var(--reader-intro-h2); border-bottom: 2px solid var(--reader-intro-h2-border); }

/* หัวภาค / หัวตอน / คาถา — กรอบรอบทั้งกล่อง ไม่มีแถบขอบซ้าย */
.ch-banner { margin-bottom: 24px; padding: 20px 24px; border: 1px solid var(--reader-rule); border-radius: 16px; background: var(--reader-tint); text-align: center; }
.ch-num { display: block; font-size: 1.05rem; font-weight: 700; letter-spacing: .08em; color: var(--reader-accent); }
.ch-sub { display: block; margin-top: 4px; font-size: 1.5rem; font-weight: 700; line-height: 1.35; color: var(--reader-heading); }
.sec-title { margin: 0 0 20px; padding: 12px 18px; border: 1px solid var(--reader-sec-title-border); border-radius: 14px; background: var(--reader-sec-title-bg); font-size: 1.25em; font-weight: 700; line-height: 1.5; color: var(--reader-sec-title-color); }
.story-img { display: block; width: 100%; height: auto; margin: 20px 0 0; border-radius: 14px; box-shadow: 0 10px 30px -14px rgba(0, 0, 0, .45); }
.img-cap { margin: 8px 0 24px; padding: 0 16px; font-size: .84em; font-style: italic; text-align: center; color: var(--reader-img-cap); }
.story-p { margin: 0 0 14px; font-size: 1.05em; line-height: 1.85; text-indent: 2em; text-align: justify; color: var(--reader-text); }
.verse {
  position: relative; margin: 24px 0; padding: 26px 36px; border: 1px solid var(--reader-verse-border); border-radius: 16px;
  background: var(--reader-verse-bg); color: var(--reader-verse-color);
  font-size: 1.08em; font-weight: 600; font-style: italic; line-height: 1.85; text-align: center;
}
.verse::before, .verse::after { position: absolute; font-family: serif; font-size: 2.5em; line-height: 1; color: var(--ds-gold); opacity: .55; }
.verse::before { content: '\201C'; top: 8px; left: 12px; }
.verse::after { content: '\201D'; bottom: 2px; right: 14px; }

/* แถบล่าง */
.reader-navbar {
  flex: none; display: flex; align-items: center; gap: 12px; padding: 10px 16px 10px 24px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: rgba(var(--ui-lpanel-rgb, 15, 23, 48), .94); border-top: 1px solid var(--ds-line);
}
.nav-btn {
  min-height: 46px; padding: 0 20px; border-radius: 12px; cursor: pointer; white-space: nowrap;
  font-family: 'Sarabun', sans-serif; font-size: 15px; font-weight: 800; transition: background-color .15s ease, color .15s ease;
}
.nav-prev { background: rgba(var(--ui-tint), .07); border: 1px solid var(--ds-line2); color: var(--ui-ink2); }
.nav-prev:hover:not(:disabled) { background: rgba(var(--ui-tint), .14); color: var(--ui-strong); }
.nav-next { background: #fff; border: 1px solid #fff; color: var(--ds-bg); }
.nav-next:hover:not(:disabled) { background: var(--ds-gold-fill, var(--ds-gold)); border-color: var(--ds-gold); }
.nav-btn:disabled { background: rgba(var(--ui-tint), .04); border: 1px solid rgba(var(--ui-tint), .08); color: rgba(var(--ui-tint), .28); cursor: default; }
.page-indicator-bot { flex: 1; text-align: center; font-size: 14px; font-weight: 800; color: var(--ds-muted); }

/* กำลังโหลด */
.reader-loading { display: flex; align-items: center; justify-content: center; gap: 12px; height: 60vh; font-size: 1.05rem; font-weight: 700; color: var(--ds-muted); }
.reader-loading::before { content: ''; width: 24px; height: 24px; border: 3px solid var(--ds-gold); border-top-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ════ จอกลาง ════ */
@media (max-width: 1100px) {
  .ds-vol-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .ds-story-grid.is-list { grid-template-columns: minmax(0, 1fr); }
}

/* ════ แท็บเล็ต/มือถือ: สารบัญเป็นลิ้นชัก ════ */
@media (max-width: 860px) {
  .toc-sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 200; width: min(320px, 86vw);
    transform: translateX(-100%); visibility: hidden; box-shadow: 30px 0 60px -30px rgba(0, 0, 0, .9);
    transition: transform .3s cubic-bezier(.25, 1, .5, 1), visibility .3s;
  }
  .toc-sidebar.open { transform: none; visibility: visible; }
  .toc-header { padding-right: 68px; }
  .toc-close {
    display: grid; place-items: center; position: absolute; top: 14px; right: 14px; width: 44px; height: 44px; border-radius: 12px; cursor: pointer;
    background: rgba(var(--ui-tint), .07); border: 1px solid var(--ds-line2); color: var(--ui-strong); font-size: 18px;
  }
  .toc-sec { min-height: 44px; }
  .toc-overlay { display: block; position: fixed; inset: 0; z-index: 199; background: rgba(var(--ui-lpanel-rgb, 4, 7, 16), .6); opacity: 0; visibility: hidden; transition: opacity .25s ease, visibility .25s; }
  .toc-overlay.show { opacity: 1; visibility: visible; }
  .toc-toggle { display: grid; }
  .reader-topbar { padding-left: 12px; padding-right: 12px; gap: 10px; }
}

@media (max-width: 640px) {
  /* แถบหัว */
  .ds-bar-sub { display: none; }
  .ds-tools { gap: 6px; }

  /* ป้ายใหญ่: ภาพเป็นแถบบนสุด แล้วไล่สีลงพื้นเข้มก่อนถึงข้อความ */
  .ds-bill::before { background: linear-gradient(0deg, var(--ds-bg) 0%, var(--ds-bg) calc(100% - 270px), rgba(var(--ui-lpanel-rgb, 10, 15, 30), .5) calc(100% - 150px), rgba(var(--ui-lpanel-rgb, 10, 15, 30), .1) calc(100% - 40px)); }
  .ds-bill-inner, .ds-bill-vol .ds-bill-inner { min-height: 0; padding-top: 210px; padding-bottom: 24px; }
  .ds-wall { --tile: 120px; gap: 10px; top: -20px; right: -70px; }
  .ds-bill-vol.has-wall .ds-wall { --tile: 120px; }
  .ds-wall img { border-radius: 12px; }
  .ds-wall img:nth-child(even) { transform: translateY(16px); }
  .ds-bill-cover { left: 0; right: 0; width: 100%; max-width: none; height: 290px; aspect-ratio: auto; object-position: 50% 30%; -webkit-mask-image: none; mask-image: none; }
  .ds-title { font-size: 2.1rem; }
  .ds-desc { font-size: 16px; }
  .ds-meta-note { flex-basis: 100%; }
  .ds-actions { flex-direction: column; }
  .ds-btn { width: 100%; }
  /* มือถือ: ปุ่มแอป ๒ ร้านเคียงกันครึ่งต่อครึ่ง */
  .ds-app-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; }
  .ds-app-pair .ds-btn { width: auto; padding-left: 10px; padding-right: 10px; gap: 8px; }
  .ds-btn-play { justify-content: flex-start; }
  .ds-btn-stack > span { max-width: none; }

  /* หัวหมวด + เครื่องมือรายชื่อ */
  .ds-body { padding-top: 24px; }
  .ds-list-tools { flex-basis: 100%; }
  .ds-search-sm { max-width: none; }

  /* ปกภาค ๒ คอลัมน์ */
  .ds-vol-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .ds-vol { border-radius: 16px; }
  .ds-vol-no { top: 8px; left: 8px; height: 26px; padding: 0 10px; font-size: 13px; }
  .ds-vol-info { padding: 2px 12px 12px; }
  .ds-vol-title { font-size: 16px; }
  .ds-vol-count { font-size: 13px; }

  /* การ์ดเรื่อง: นอน ภาพซ้าย ข้อความขวา — เห็นหลายเรื่องในจอเดียว */
  .ds-story-grid { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .ds-story-grid:not(.is-list) .ds-story { flex-direction: row; min-height: 128px; }
  .ds-story-grid:not(.is-list) .ds-story-art { flex: none; width: 40%; aspect-ratio: auto; }
  .ds-story-grid:not(.is-list) .ds-story-art::after { display: none; }
  .ds-story-grid:not(.is-list) .ds-story-info { justify-content: center; padding: 12px 52px 12px 14px; }
  .ds-story-grid:not(.is-list) .ds-mark { top: 50%; right: 4px; transform: translateY(-50%); background: rgba(var(--ui-tint), .06); }
  .ds-story-grid:not(.is-list) .ds-mark.on { background: var(--ds-gold-fill, var(--ds-gold)); }
  .ds-story-grid:not(.is-list) .ds-mark:hover { transform: translateY(-50%); }
  .ds-story-title { font-size: 16px; }
  .ds-story-desc { font-size: 13.5px; }
  .ds-story:hover { transform: none; }
  .is-list .ds-story { padding-right: 56px; }
  .is-list .ds-mark { right: 4px; }

  .ds-hit-text { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

  /* หน้าอ่าน */
  .topbar-indicator { display: none; }
  .topbar-title { font-size: 15px; }
  .page-container { padding: 12px 10px 24px; }
  .page { padding: 22px 18px 28px; border-radius: 16px; }
  .cover-hero { padding: 20px 10px 14px; }
  .ch-banner { padding: 16px 14px; }
  .ch-sub { font-size: 1.3rem; }
  .story-p { font-size: 1em; }
  .sec-title { font-size: 1.1em; padding: 10px 14px; }
  .verse { padding: 24px 22px; }
  .reader-navbar { padding-left: 10px; padding-right: 10px; gap: 8px; }
  .nav-btn { padding: 0 14px; }
}

/* เลื่อนล้อเมาส์ต่อเมื่อสุดหน้า → พลิกหน้า: ป้ายบอกพร้อมวงแหวนความคืบหน้า (StoryReader.onWheel) */
.pull-hint {
  position: absolute; left: 50%; z-index: 5; transform: translateX(-50%);
  display: inline-flex; align-items: center; gap: 10px; padding: 8px 16px 8px 8px;
  border-radius: 999px; background: rgba(15, 23, 48, .94); border: 1px solid var(--ds-line);
  color: var(--ds-ink); font: 700 14px/1.3 'Sarabun', sans-serif; white-space: nowrap;
  box-shadow: 0 12px 28px -14px rgba(0, 0, 0, .9); pointer-events: none; animation: pullIn .18s ease both;
}
.pull-hint.pull-down { bottom: calc(var(--ds-bar-h, 60px) + 14px); }
.pull-hint.pull-up { top: calc(var(--ds-bar-h, 60px) + 14px); }
.pull-ring {
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: 999px; color: var(--ds-gold-ink); font-size: 13px;
  background: radial-gradient(closest-side, var(--ds-gold) 72%, transparent 74% 100%), conic-gradient(var(--ds-gold) var(--p), rgba(var(--ui-tint), .15) 0);
}
@keyframes pullIn { from { opacity: 0; transform: translate(-50%, 6px); } to { opacity: 1; transform: translateX(-50%); } }
@media (prefers-reduced-motion: reduce) { .pull-hint { animation: none; } }

/* โหมดสว่าง: ป้ายเลขภาคพื้นสีอ่อน ไม่ทึบ */
html[data-ui="light"] .ds-no { background: #eef2ff; color: #3730a3; box-shadow: inset 0 0 0 1.5px rgba(79, 70, 229, .32); }
html[data-ui="light"] .ds-no i { color: #b45309; }

/* ════ โหมดสว่าง (กรอบหน้า · หลวงพี่สั่ง ๑๐ ต.ค. ๒๕๖๙) — สีพื้นฐานสลับใน theme.css · ที่นี่เฉพาะไล่สี/ปุ่มทึบ ════ */
html[data-ui="light"] .ds-bill::before {
  background:
    linear-gradient(90deg, rgba(245, 247, 252, .97) 0%, rgba(245, 247, 252, .9) 34%, rgba(245, 247, 252, .3) 64%, rgba(245, 247, 252, .05) 100%),
    linear-gradient(0deg, var(--ds-bg) 0%, rgba(245, 247, 252, .72) 16%, rgba(245, 247, 252, 0) 42%);
}
html[data-ui="light"] .ds-btn-play, html[data-ui="light"] .nav-next { background: #1e1b4b; border-color: #1e1b4b; color: #fff; }
html[data-ui="light"] .ds-btn-play:hover { background: #312e81; color: #fff; }
html[data-ui="light"] .nav-next:hover:not(:disabled) { background: #312e81; border-color: #312e81; color: #fff; }
html[data-ui="light"] .ds-story-art::after { background: linear-gradient(0deg, #fff 0%, rgba(255, 255, 255, .3) 26%, rgba(255, 255, 255, 0) 50%); }
html[data-ui="light"] .pull-hint { background: rgba(255, 255, 255, .96); box-shadow: 0 10px 24px -14px rgba(20, 26, 51, .4); }
html[data-ui="light"] .ds-no { background: #eef2ff; color: #3730a3; box-shadow: inset 0 0 0 1.5px rgba(79, 70, 229, .32); }
@media (max-width: 640px) {
  html[data-ui="light"] .ds-bill::before { background: linear-gradient(0deg, var(--ds-bg) 0%, var(--ds-bg) calc(100% - 270px), rgba(245, 247, 252, .5) calc(100% - 150px), rgba(245, 247, 252, .1) calc(100% - 40px)); }
}
