/* ==========================================================================
   How to Dhamma — ธีมโทนสงบ (ครีม/น้ำตาล/ทอง) + dark mode
   ========================================================================== */
:root {
    --bg: #f7f3ea;
    --bg-soft: #fffdf8;
    --surface: #ffffff;
    --surface-2: #f3ecdd;
    --border: #e4d9c3;
    --text: #2e2a24;
    --text-soft: #6b6357;
    --muted: #8a8175;
    --primary: #8a5a2b;       /* น้ำตาลทอง */
    --primary-dark: #6d4520;
    --accent: #c79a3e;        /* ทอง */
    --accent-soft: #f0e2bf;
    --saffron: #d98a2b;
    --danger: #b3402f;
    --success: #4b7a4a;
    --info: #3d6a8a;
    --radius: 14px;
    --radius-sm: 9px;
    --shadow: 0 6px 24px rgba(80, 60, 30, 0.08);
    --shadow-lg: 0 14px 44px rgba(80, 60, 30, 0.14);
    --serif: 'Noto Serif Thai', serif;
    --sans: 'Sarabun', system-ui, sans-serif;
    --maxw: 1160px;
    --cover-text: #fff6e2;    /* ตัวหนังสือบนปกหนังสือ (เล่มพระไตรปิฎก) — สว่างจัดเพื่อคอนทราสต์กับปกน้ำตาล */
}
[data-theme="dark"] {
    --bg: #1b1813;
    --bg-soft: #221e18;
    --surface: #262019;
    --surface-2: #2f281f;
    --border: #3d3428;
    --text: #ece4d6;
    --text-soft: #b9ad9a;
    --muted: #948a79;
    --primary: #d09a5a;
    --primary-dark: #b98443;
    --accent: #dcb45f;
    --accent-soft: #3a3020;
    --cover-text: #2a1d0e;    /* ปกโหมดมืดพื้นสว่างกว่า (--primary อ่อนลง) จึงต้องใช้ตัวหนังสือเข้ม */
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 14px 44px rgba(0, 0, 0, 0.45);
}

/* ---------- โทนสีธีมทางเลือก (data-palette) — ปรับเฉพาะสีเน้น ไม่แตะพื้นหลัง ---------- */
[data-palette="green"] {
    --primary: #3f6b42; --primary-dark: #2f5033; --accent: #7a9d5c; --accent-soft: #e3ecd9;
}
[data-theme="dark"][data-palette="green"] {
    --primary: #8fc17e; --primary-dark: #6fa05f; --accent: #a8d194; --accent-soft: #263a24;
}
[data-palette="blue"] {
    --primary: #2f5a72; --primary-dark: #234459; --accent: #5b8fa8; --accent-soft: #dbe8ee;
}
[data-theme="dark"][data-palette="blue"] {
    --primary: #6fa8c9; --primary-dark: #4f89ac; --accent: #8cc0dc; --accent-soft: #1f333d;
}
[data-palette="rose"] {
    --primary: #8a3b2b; --primary-dark: #6d2e21; --accent: #c77b52; --accent-soft: #f0dccb;
}
[data-theme="dark"][data-palette="rose"] {
    --primary: #d98f6a; --primary-dark: #b96f4d; --accent: #e0a37e; --accent-soft: #3a2620;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
    margin: 0;
    font-family: var(--sans);
    background: var(--bg);
    color: var(--text);
    line-height: 1.7;
    font-size: 16.5px;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

/* ---------- ไอคอน (Flaticon UIcons, self-hosted) ---------- */
.fi { display: inline-block; vertical-align: -0.125em; line-height: 1; }
.icon-inline { display: inline-flex; align-items: center; gap: .45em; }
h1, h2, h3, h4 { font-family: var(--serif); font-weight: 600; line-height: 1.35; color: var(--text); }
p { margin: 0 0 1rem; }
.container { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 0 20px; }
.muted { color: var(--muted); }
.small { font-size: 0.86rem; }
.accent { color: var(--accent); }
.site-main { min-height: 62vh; }

/* ---------- ปุ่ม ---------- */
.btn {
    display: inline-flex; align-items: center; gap: .5rem; justify-content: center;
    background: var(--primary); color: #fff; border: none;
    padding: .7rem 1.4rem; border-radius: var(--radius-sm);
    font-family: var(--sans); font-size: 1rem; font-weight: 600; cursor: pointer;
    transition: transform .12s, background .18s, box-shadow .18s;
}
.btn:hover { background: var(--primary-dark); color: #fff; transform: translateY(-1px); box-shadow: var(--shadow); }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; color: var(--primary); border: 1.5px solid var(--border); }
.btn-ghost:hover { background: var(--surface-2); color: var(--primary); }
.btn-sm { padding: .42rem .85rem; font-size: .9rem; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #922f21; }
.btn-success { background: var(--success); }
.btn-success:hover { background: #3c6339; }
.linklike { background: none; border: none; color: var(--primary); cursor: pointer; font: inherit; padding: 0; }

/* ---------- Header / Nav ---------- */
.site-header {
    position: sticky; top: 0; z-index: 50;
    background: color-mix(in srgb, var(--bg-soft) 88%, transparent);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}
.nav-wrap { display: flex; align-items: center; justify-content: space-between; height: 66px; gap: 1rem; }
.brand { display: flex; align-items: center; gap: .6rem; font-family: var(--serif); font-weight: 600; color: var(--text); font-size: 1.15rem; }
.brand-mark { color: var(--accent); font-size: 1.5rem; }
.brand-mark.big { font-size: 2.6rem; }
img.brand-logo { height: 2rem; width: auto; object-fit: contain; display: block; }
img.brand-logo.big { height: 3.4rem; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text small { font-size: .62rem; color: var(--muted); font-family: var(--sans); font-weight: 400; letter-spacing: .04em; }

/* โลโก้ที่อัปโหลดเองมักมีชื่อเว็บวาดอยู่ในภาพแล้ว — เมื่อมีโลโก้ ไม่ต้องซ้ำด้วยตัวหนังสือ ให้ปล่อยโลโก้ยาวเต็มพื้นที่แทน */
.brand-logo-only { gap: 0; }
.brand-logo-wrap { display: inline-flex; align-items: center; }
img.brand-logo-solo { height: 2.75rem; max-width: 260px; transition: filter .2s ease; }
.footer-brand img.brand-logo-solo { height: 2.9rem; max-width: 280px; }

/* ธีมมืด (ไม่มีโลโก้เฉพาะธีมมืด): โลโก้ปกติมักเป็นสีเข้ม กลืนกับพื้นหลังมืด จึงเรืองแสงสว่างรอบตัวภาพเอง (ไม่ใช้กล่องพื้นหลัง) ให้เห็นชัดขึ้น */
[data-theme="dark"] img.brand-logo-solo.brand-logo-fallback-glow,
[data-theme="dark"] img.brand-logo.big.brand-logo-fallback-glow {
    filter: drop-shadow(0 0 5px rgba(255, 240, 205, .65)) drop-shadow(0 0 14px rgba(255, 240, 205, .45)) brightness(1.15);
}

/* หน้า auth (login/register): โลโก้ต้องอยู่กึ่งกลาง — .brand-logo-wrap เป็น inline-flex จึงถูกจัดกึ่งกลางได้ด้วย text-align:center ของ .auth-head ในขณะที่ img.brand-logo เดิมเป็น display:block ซึ่ง text-align จัดกึ่งกลางให้ไม่ได้ */
.auth-head .brand-logo-wrap { margin-bottom: .3rem; }

/* ธีมมืด (มีโลโก้เฉพาะธีมมืด): สลับไปแสดงโลโก้เฉพาะธีมมืดแทน โดยไม่ใส่ filter ใดๆ เพราะเป็นไฟล์ที่ออกแบบมาให้เหมาะกับพื้นมืดอยู่แล้ว */
/* ระบุ specificity เท่ากับ img.brand-logo (element+class) ไม่งั้น display:block ของกฎด้านบนจะชนะ */
img.brand-logo-for-dark { display: none; }
[data-theme="dark"] img.brand-logo-for-light { display: none; }
[data-theme="dark"] img.brand-logo-for-dark { display: inline-block; }
.site-nav { display: flex; align-items: center; gap: 1.15rem; }
.site-nav > a { color: var(--text-soft); font-weight: 500; font-size: .97rem; padding: .3rem 0; border-bottom: 2px solid transparent; }
.site-nav > a:hover { color: var(--primary); }
.site-nav > a.active { color: var(--primary); border-bottom-color: var(--accent); }
.site-nav > a.btn-nav {
    background: linear-gradient(135deg, var(--primary), var(--saffron));
    color: #fff !important; padding: .5rem 1.3rem; border-radius: 999px;
    border-bottom: none !important; font-weight: 600; letter-spacing: .01em;
    box-shadow: 0 4px 14px rgba(138, 90, 43, .28);
    transition: transform .14s, box-shadow .2s, filter .2s;
}
.site-nav > a.btn-nav:hover { color: #fff; transform: translateY(-1px); filter: brightness(1.06); box-shadow: 0 7px 20px rgba(138, 90, 43, .4); }
.nav-toggle { display: none; background: none; border: none; font-size: 1.5rem; color: var(--text); cursor: pointer; }
.theme-toggle {
    display: grid; place-items: center; background: var(--surface-2);
    border: 1px solid var(--border); border-radius: 50%; width: 38px; height: 38px;
    cursor: pointer; color: var(--text-soft); transition: color .18s, border-color .18s, background .18s;
}
.theme-toggle:hover { color: var(--primary); border-color: var(--accent); background: var(--accent-soft); }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .icon-sun, .theme-toggle .icon-auto { display: none; }
[data-theme-mode="dark"] .theme-toggle .icon-moon { display: none; }
[data-theme-mode="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme-mode="auto"] .theme-toggle .icon-moon { display: none; }
[data-theme-mode="auto"] .theme-toggle .icon-auto { display: block; }

/* dropdown เมนูผู้ใช้ (mega menu) */
.nav-menu { position: relative; }
.nav-menu-btn {
    display: inline-flex; align-items: center; gap: .5rem;
    background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: .3rem .9rem .3rem .3rem;
    cursor: pointer; font: inherit; color: var(--text); font-weight: 500;
}
.nav-menu-caret { font-size: .8rem; color: var(--muted); transition: transform .15s; }
.nav-menu.is-open .nav-menu-caret { transform: rotate(180deg); }
.nav-avatar {
    width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0; overflow: hidden;
    background: linear-gradient(150deg, var(--primary), var(--accent)); color: #fff;
    display: grid; place-items: center; font-family: var(--serif); font-size: .95rem;
}
.nav-avatar img { width: 100%; height: 100%; object-fit: cover; }
/* เปิด/ปิดด้วยคลิก (JS toggles .is-open) แทน :hover เดิม — กันปัญหาหายตอนเลื่อนจอ และใช้งานได้บนมือถือ */
.nav-menu-list {
    position: absolute; right: 0; top: calc(100% + 10px); background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-lg);
    display: none; flex-direction: column; z-index: 60;
}
.nav-menu.is-open .nav-menu-list { display: flex; }

/* ---------- Mega menu ---------- */
.nav-mega { width: 340px; padding: 1rem; gap: .9rem; }
.nav-mega-header { display: flex; align-items: center; gap: .8rem; padding-bottom: .8rem; border-bottom: 1px solid var(--border); }
.nav-mega-avatar {
    width: 48px; height: 48px; border-radius: 50%; flex-shrink: 0; overflow: hidden;
    background: linear-gradient(150deg, var(--primary), var(--accent)); color: #fff;
    display: grid; place-items: center; font-family: var(--serif); font-size: 1.3rem; box-shadow: var(--shadow);
}
.nav-mega-avatar img { width: 100%; height: 100%; object-fit: cover; }
.nav-mega-who { display: flex; flex-direction: column; min-width: 0; }
.nav-mega-who strong { font-size: .98rem; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-mega-who small { color: var(--muted); font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-mega-badges { display: flex; flex-wrap: wrap; gap: .4rem; padding-bottom: .8rem; border-bottom: 1px solid var(--border); }
.nav-mega-badges .achv-ico-sm { transition: transform .15s; }
.nav-mega-badges:hover .achv-ico-sm { opacity: .6; }
.nav-mega-badges .achv-ico-sm:hover { opacity: 1; transform: translateY(-2px); }
.nav-mega-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; }
.nav-mega-item {
    display: flex; align-items: center; gap: .6rem; padding: .55rem .6rem; border-radius: var(--radius-sm);
    color: var(--text-soft); font-size: .87rem; text-align: left; background: none; border: none; font: inherit;
    cursor: pointer; width: 100%;
}
.nav-mega-item i {
    width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center;
    background: var(--accent-soft); color: var(--primary-dark); font-size: .95rem;
}
.nav-mega-item:hover { background: var(--surface-2); color: var(--primary); }
.nav-mega-item-admin i { color: var(--saffron); }
.nav-mega-footer { margin: 0; border-top: 1px solid var(--border); padding-top: .6rem; }
.nav-mega-logout i { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }
.nav-mega-logout:hover { background: color-mix(in srgb, var(--danger) 10%, transparent); color: var(--danger); }

/* ---------- Flash (toast ลอยมุมขวาบน ไม่ดันเนื้อหาหน้าลง) ---------- */
.flash-area {
    position: fixed; top: 1.1rem; right: 1.1rem; z-index: 1000;
    display: flex; flex-direction: column; gap: .6rem;
    width: min(360px, calc(100vw - 2.2rem));
}
.flash {
    display: flex; align-items: flex-start; gap: .65rem; padding: .8rem .95rem; border-radius: var(--radius-sm);
    border: 1px solid; font-weight: 500; font-size: .92rem; line-height: 1.45;
    background: var(--surface); box-shadow: 0 10px 30px -6px rgba(0, 0, 0, .18);
    animation: flash-in .25s ease;
}
@keyframes flash-in { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
.flash i { flex-shrink: 0; font-size: 1.1rem; padding-top: .1rem; }
.flash span { flex: 1; min-width: 0; }
.flash-success { border-color: #bcdcb9; color: #2f5e2e; }
.flash-success i { color: #3f8a3d; }
.flash-error { border-color: #eecbc4; color: #8f3324; }
.flash-error i { color: #c85b3f; }
.flash-info { border-color: #c4d6e6; color: #305a78; }
.flash-info i { color: #4f83a8; }
[data-theme="dark"] .flash-success { color: #a8d6a2; }
[data-theme="dark"] .flash-error { color: #e0a99e; }
[data-theme="dark"] .flash-info { color: #a5c4dd; }
.flash-close { flex-shrink: 0; background: none; border: none; font-size: 1.2rem; line-height: 1; cursor: pointer; color: inherit; opacity: .5; }
.flash-close:hover { opacity: 1; }
@media (max-width: 600px) {
    .flash-area { left: 1.1rem; right: 1.1rem; width: auto; }
}

/* ---------- แถบยอมรับคุกกี้ (แสดงครั้งแรกที่เข้าเว็บ จำค่าไว้ใน localStorage) ---------- */
.cookie-consent {
    position: fixed; left: 1.1rem; right: 1.1rem; bottom: 1.1rem; z-index: 1500;
    max-width: 640px; margin: 0 auto; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 1rem 1.2rem; box-shadow: 0 10px 30px -6px rgba(0, 0, 0, .25);
    animation: cookie-in .25s ease;
}
.cookie-consent[hidden] { display: none; }
.cookie-consent p { flex: 1; min-width: 200px; margin: 0; font-size: .88rem; color: var(--text-soft); line-height: 1.55; }
@keyframes cookie-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Hero ---------- */
.hero {
    position: relative; overflow: hidden;
    border-bottom: 1px solid var(--border); padding: 4rem 0 3.4rem;
}
.hero-inner { position: relative; z-index: 1; text-align: center; max-width: 780px; }
.hero-kicker { color: var(--saffron); font-weight: 600; letter-spacing: .05em; margin-bottom: .4rem; transition: color 2s ease; }
.hero-title { font-size: clamp(2.2rem, 5vw, 3.6rem); margin: 0 0 1rem; transition: color 2s ease; }
.hero-sub { font-size: 1.12rem; color: var(--text-soft); margin-bottom: 2rem; transition: color 2s ease; }
.hero-search { display: flex; gap: .5rem; max-width: 620px; margin: 0 auto 2.2rem; background: var(--surface); padding: .5rem; border-radius: 999px; border: 1px solid var(--border); box-shadow: var(--shadow-lg, var(--shadow)); }
.hero-search input { flex: 1; border: none; background: transparent; padding: .6rem 1.1rem; font: inherit; color: var(--text); outline: none; }
.hero-search .btn { border-radius: 999px; padding-inline: 1.6rem; }
.hero-search-inline { margin: 0 0 2rem; max-width: 100%; }
.hero-stats { display: flex; justify-content: center; gap: 2.6rem; }
.hero-stats strong { display: block; font-family: var(--serif); font-size: 1.9rem; color: var(--primary); transition: color 2s ease; }
.hero-stats span { font-size: .85rem; color: var(--muted); transition: color 2s ease; }

/* เบื้องหลังฟ้า/คืนของ hero — ไล่สีตามเวลาจริงของผู้ใช้ (พระอาทิตย์/พระจันทร์+ดาวไหลตามเวลา), ควบคุมด้วย JS ใน app.js (initHeroSky) */
.hero-sky {
    position: absolute; inset: 0; z-index: 0; overflow: hidden; pointer-events: none;
    background: linear-gradient(180deg, #bfe0ff 0%, #eaf4ff 45%, var(--bg-soft) 100%);
    transition: background 2.5s ease;
}
.hero.is-night .hero-sky { background: linear-gradient(180deg, #080c1c 0%, #141c38 55%, var(--bg-soft) 100%); }
.hero.is-night .hero-kicker { color: #f0c869; }
.hero.is-night .hero-title { color: #f7f2e6; }
.hero.is-night .hero-sub { color: #cdc6b4; }
.hero.is-night .hero-stats strong { color: #f0c869; }
.hero.is-night .hero-stats span { color: #a9a292; }

.hero-sun, .hero-moon {
    position: absolute; left: 0; top: 0; border-radius: 50%; opacity: 0;
    transition: left 17s linear, top 17s linear, opacity 2.2s ease;
    will-change: left, top;
}
.hero-sun {
    width: 64px; height: 64px; margin: -32px 0 0 -32px;
    background: radial-gradient(circle at 35% 35%, #fff9e3, #ffd977 45%, #ff9d43 85%);
    box-shadow: 0 0 70px 20px rgba(255, 178, 70, .5);
}
.hero-moon {
    width: 44px; height: 44px; margin: -22px 0 0 -22px;
    background: #eef1fb; overflow: hidden;
    box-shadow: 0 0 34px 10px rgba(200, 212, 255, .4);
}
/* จุด "หลุมอุกกาบาต" นิ่งอยู่กับผิวดวงจันทร์ (ไม่หมุนตามเงา) ให้ดูเป็นดวงจันทร์จริงมากขึ้น */
.hero-moon-crater { position: absolute; border-radius: 50%; background: rgba(150, 160, 195, .4); }
.hero-moon-crater:nth-child(1) { width: 7px; height: 7px; top: 28%; left: 58%; }
.hero-moon-crater:nth-child(2) { width: 5px; height: 5px; top: 54%; left: 32%; }
.hero-moon-crater:nth-child(3) { width: 4px; height: 4px; top: 62%; left: 60%; }
/*
 * เสี้ยวจันทร์ไม่สมมาตรแบบจริง: ครึ่งวงกลมทึบด้าน "มืดค้าง" (fixed) + วงรีตรงกลางความกว้างแปรผัน
 * ที่ "เติม" เงาให้กว้างขึ้น (ข้างแรม/เสี้ยวจันทร์ดับ) หรือ "ลบ" เงาออก (ข้างขึ้น/เสี้ยวจันทร์เพ็ญ) —
 * ความกว้างวงรี = |cos(2π×เฟส)| × เส้นผ่านศูนย์กลาง ตรงกับเส้นแบ่งสว่าง-มืด (terminator) จริงของดวงจันทร์
 * จุด 4 เฟสหลักตรวจสอบแล้ว: จันทร์ดับ=วงกลมมืดเต็ม, กึ่งจันทร์=ครึ่งวงตรงเป๊ะ, จันทร์เพ็ญ=สว่างเต็มดวง
 */
.hero-moon-shadow-half {
    position: absolute; top: 0; left: 0; width: 50%; height: 100%;
    background: #12122a;
    border-radius: 50% 0 0 50% / 50% 0 0 50%;
    transition: left 2.5s ease, border-radius 2.5s ease;
}
.hero-moon-shadow-half.is-right {
    left: 50%;
    border-radius: 0 50% 50% 0 / 0 50% 50% 0;
}
.hero-moon-shadow-ellipse {
    position: absolute; top: 0; left: 50%; height: 100%;
    border-radius: 50%;
    transform: translateX(-50%);
    transition: width 2.5s ease, background-color 2.5s ease;
}
.hero-sun.is-visible, .hero-moon.is-visible { opacity: 1; }

.hero-stars { position: absolute; inset: 0; opacity: 0; transition: opacity 2.5s ease; }
.hero.is-night .hero-stars { opacity: 1; }
.hero-star { position: absolute; width: 2px; height: 2px; border-radius: 50%; background: #fff; animation: hero-star-twinkle 3.6s ease-in-out infinite; }
@keyframes hero-star-twinkle { 0%, 100% { opacity: .18; } 50% { opacity: .95; } }

/* ---------- การ์ดแนะนำหัวข้ออ่านประจำวัน (หน้าแรก, เฉพาะสมาชิก) ---------- */
.daily-topic-card {
    display: flex; align-items: center; gap: 1.2rem; margin-top: 1.6rem; padding: 1.3rem 1.6rem;
    background: linear-gradient(135deg, var(--accent-soft), var(--surface));
    border: 1px solid var(--accent); border-radius: var(--radius);
    text-decoration: none; color: var(--text); transition: box-shadow .18s, transform .18s;
}
.daily-topic-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.daily-topic-ico { flex-shrink: 0; font-size: 2.2rem; color: var(--primary); }
.daily-topic-thumb { flex-shrink: 0; width: 110px; height: 78px; border-radius: var(--radius-sm); object-fit: cover; }
@media (max-width: 560px) { .daily-topic-card { flex-wrap: wrap; } .daily-topic-thumb { width: 100%; height: auto; aspect-ratio: 16 / 9; } }
.daily-topic-body { flex: 1; min-width: 0; }
.daily-topic-kicker { margin: 0 0 .2rem; font-size: .8rem; font-weight: 600; color: var(--primary-dark); letter-spacing: .02em; }
.daily-topic-body h3 { margin: 0 0 .3rem; font-family: var(--serif); color: var(--primary-dark); }
.daily-topic-cta { flex-shrink: 0; font-weight: 700; color: var(--primary); white-space: nowrap; }

/* ---------- Section ---------- */
/* padding-top/bottom เท่านั้น (ไม่ใช้ shorthand padding) เพราะ .section มักอยู่ร่วมกับ .container บนอิลิเมนต์
   เดียวกัน — shorthand จะทับ padding ซ้าย/ขวาของ .container ทั้งหมดจนกรอบเนื้อหาชิดขอบจอบนมือถือ */
.section { padding-top: 3rem; padding-bottom: 3rem; }
.section-title { font-size: 1.7rem; text-align: center; margin-bottom: 2rem; position: relative; }
.section-title::after {
    content: "\e673"; font-family: "uicons-regular-rounded" !important; font-style: normal;
    display: block; color: var(--accent); font-size: 1rem; margin-top: .3rem;
}

.pitaka-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.3rem; }
.pitaka-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 2rem 1.6rem; text-align: center; transition: transform .16s, box-shadow .16s; position: relative; overflow: hidden; }
.pitaka-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }
.pitaka-icon { font-size: 2.6rem; margin-bottom: .6rem; }
.pitaka-card h3 { margin: 0 0 .5rem; color: var(--primary); }

/* การ์ดที่มีภาพพื้นหลัง (admin อัปโหลดที่ /admin/settings) — ซ้อนไล่สีเข้มเพื่อให้ตัวหนังสือขาวอ่านชัดเสมอ ไม่ว่าธีมไหน */
.pitaka-card.has-bg, .feature-item.has-bg { background-size: cover; background-position: center; border: none; }
.pitaka-card.has-bg::before, .feature-item.has-bg::before {
    content: ''; position: absolute; inset: 0;
    background: linear-gradient(180deg, rgba(20, 14, 8, .35), rgba(20, 14, 8, .8));
}
.pitaka-card.has-bg > *, .feature-item.has-bg > * { position: relative; z-index: 1; }
.pitaka-card.has-bg .pitaka-icon, .pitaka-card.has-bg h3, .feature-item.has-bg .feature-ico, .feature-item.has-bg h3 { color: #fff; }
.pitaka-card.has-bg p, .feature-item.has-bg p { color: rgba(255, 255, 255, .85); }
.feature-item.has-bg a { color: #fff; text-decoration: underline; }

.edition-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.1rem; }
.edition-card { display: flex; align-items: center; gap: 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.2rem 1.3rem; transition: transform .16s, box-shadow .16s, border-color .16s; }
.edition-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: var(--ed-color, var(--accent)); }
.edition-card-cover {
    position: relative; flex-shrink: 0; width: 44px; height: 60px; border-radius: 3px 7px 7px 3px;
    background: linear-gradient(155deg, var(--ed-color, var(--primary)) 0%, var(--ed-color-dark, var(--primary-dark)) 100%);
    box-shadow: 0 1px 0 rgba(255, 255, 255, .12) inset, 0 3px 8px rgba(30, 20, 5, .25);
    display: grid; place-items: center; color: var(--cover-text); font-size: 1.2rem; opacity: .85;
}
.edition-card-cover::before {
    content: ''; position: absolute; inset: 0 auto 0 0; width: 5px; border-radius: 3px 0 0 3px;
    background: linear-gradient(180deg, rgba(0, 0, 0, .4), rgba(255, 255, 255, .1) 45%, rgba(0, 0, 0, .4));
}
.edition-card-body { min-width: 0; flex: 1; }
.edition-card h3 { margin: 0 0 .2rem; font-size: 1.15rem; color: var(--ed-color, var(--text)); }
.edition-meta { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .7rem; font-size: .82rem; color: var(--text-soft); }
.edition-meta span { background: var(--surface-2); padding: .2rem .55rem; border-radius: 6px; }

/* ---------- สีประจำแต่ละฉบับ (edition) — ช่วยให้รู้ทันทีว่ากำลังดู/เลือกฉบับไหนอยู่ ----------
   กำหนด --ed-color/--ed-color-dark ตาม data-edition ที่ติดไว้บน .edition-card (หน้ารวมฉบับ)
   และบน .container ของหน้าเล่ม/หน้าอ่าน แล้วนำไปย้อมปกหนังสือ + หัวข้อกลุ่มปิฎก + breadcrumb ที่เกี่ยวข้อง
   ฉบับหลวงใช้โทนน้ำตาลทองเดิม (ไม่ต้องเปลี่ยนพฤติกรรม) ส่วนอีก 3 ฉบับได้โทนสีใหม่ที่แยกจากกันชัดเจน */
[data-edition="thai_royal"] { --ed-color: #8a5a2b; --ed-color-dark: #6d4520; }
[data-edition="thai_mcu"]   { --ed-color: #3f6b42; --ed-color-dark: #2f5033; }
[data-edition="thai_mbu"]   { --ed-color: #2f5a72; --ed-color-dark: #234459; }
[data-edition="pali_siam"]  { --ed-color: #5c3a6b; --ed-color-dark: #46294f; }
[data-theme="dark"] [data-edition="thai_royal"] { --ed-color: #d09a5a; --ed-color-dark: #b98443; }
[data-theme="dark"] [data-edition="thai_mcu"]   { --ed-color: #8fc17e; --ed-color-dark: #6fa05f; }
[data-theme="dark"] [data-edition="thai_mbu"]   { --ed-color: #6fa8c9; --ed-color-dark: #4f89ac; }
[data-theme="dark"] [data-edition="pali_siam"]  { --ed-color: #b18ec9; --ed-color-dark: #9470ab; }
/* html เองก็มี data-theme แต่ไม่มี data-edition — เผื่อกรณี container ชนกับ html ให้ตรงพอดี (เช่นทดสอบ) */
html[data-theme="dark"][data-edition="thai_royal"] { --ed-color: #d09a5a; --ed-color-dark: #b98443; }
html[data-theme="dark"][data-edition="thai_mcu"]   { --ed-color: #8fc17e; --ed-color-dark: #6fa05f; }
html[data-theme="dark"][data-edition="thai_mbu"]   { --ed-color: #6fa8c9; --ed-color-dark: #4f89ac; }
html[data-theme="dark"][data-edition="pali_siam"]  { --ed-color: #b18ec9; --ed-color-dark: #9470ab; }

[data-edition] .pitaka-section h2 { color: var(--ed-color); border-left-color: var(--ed-color); }
[data-edition] .reader-locator strong { color: var(--ed-color); }

.feature-band { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.3rem; }
.feature-item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.8rem; position: relative; overflow: hidden; }
.feature-ico { font-size: 2rem; }
.feature-item h3 { margin: .6rem 0 .4rem; }
.upcoming-chip { margin-top: .9rem; background: var(--accent-soft); color: var(--primary-dark); padding: .4rem .8rem; border-radius: 8px; font-size: .82rem; font-weight: 600; }

/* ---------- แถบ "ชมรมของฉัน" ในหน้าแรก — โชว์เฉพาะสมาชิกที่ล็อกอินและเข้าร่วมชมรมเลิกอบายมุขอย่างน้อย 1 ชมรม ---------- */
.my-programs-strip {
    display: flex; align-items: center; gap: 1.4rem; flex-wrap: wrap;
    background: linear-gradient(120deg, var(--primary), var(--primary-dark));
    color: #fff; border-radius: var(--radius); padding: 1rem 1.4rem; margin-bottom: 0;
    text-decoration: none; transition: transform .15s, box-shadow .15s;
}
/* ต้องประกาศ color ซ้ำตรงนี้ — a:hover ของทั้งเว็บ (color: var(--primary-dark)) specificity สูงกว่า .my-programs-strip
   เฉย ๆ (pseudo-class นับเป็น class เพิ่ม) เลยชนะทับตัวหนังสือขาวตอน hover จนกลืนไปกับพื้นหลังไล่สีเดียวกัน */
.my-programs-strip:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); color: #fff; }
.my-programs-item { display: flex; align-items: center; gap: .5rem; font-size: .92rem; }
.my-programs-item i { font-size: 1.1rem; }
.my-programs-item strong {
    background: #fff; color: var(--primary-dark); font-family: var(--serif);
    font-size: 1rem; line-height: 1; padding: .3rem .6rem; border-radius: 999px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .18);
}
.my-programs-cta { margin-left: auto; font-size: .85rem; font-weight: 600; opacity: .9; }

/* ---------- ฟอร์ม / การ์ด auth ---------- */
.auth-container { display: flex; justify-content: center; padding: 3.5rem 0; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 2.4rem; width: 100%; max-width: 430px; }
.auth-head { text-align: center; margin-bottom: 1.6rem; }
.auth-head h1 { font-size: 1.7rem; margin: .4rem 0 .2rem; }
.form label { display: block; margin-bottom: 1rem; }
.form label > span { display: block; font-weight: 500; margin-bottom: .35rem; font-size: .92rem; color: var(--text-soft); }
.form input, .form select, .form textarea {
    width: 100%; padding: .7rem .9rem; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
    font: inherit; background: var(--bg-soft); color: var(--text); outline: none; transition: border .15s;
}
.form input:focus, .form select:focus, .form textarea:focus { border-color: var(--accent); }
.auth-alt { text-align: center; margin-top: 1.3rem; color: var(--text-soft); }
.auth-divider { display: flex; align-items: center; gap: .8rem; margin: 1.1rem 0; color: var(--muted); font-size: .85rem; }
.auth-divider::before, .auth-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.btn-google {
    display: flex; align-items: center; justify-content: center; gap: .6rem;
    background: var(--surface); color: var(--text); border: 1.5px solid var(--border);
}
.btn-google:hover { background: var(--bg-soft); }

/* ---------- Breadcrumb ---------- */
.breadcrumb { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; font-size: .9rem; color: var(--muted); padding: 1.2rem 0; }
.breadcrumb a { color: var(--text-soft); }
.breadcrumb span.sep { opacity: .5; }

/* ---------- แถบเมนูในหน้าบัญชีผู้ใช้ (/account/*, /practice, /recovery) ---------- */
.account-nav { display: flex; gap: .5rem; overflow-x: auto; padding: 1.4rem 0 1.6rem; scrollbar-width: thin; }
.account-nav-item {
    display: flex; align-items: center; gap: .45rem; flex-shrink: 0;
    padding: .55rem 1.05rem; border-radius: 999px; border: 1px solid var(--border);
    background: var(--surface); color: var(--text-soft); font-size: .9rem; font-weight: 500;
    transition: background .15s, color .15s, border-color .15s;
}
.account-nav-item i { font-size: 1rem; color: var(--muted); transition: color .15s; }
.account-nav-item:hover { border-color: var(--accent); color: var(--primary); }
.account-nav-item.is-active { background: var(--primary); border-color: var(--primary); color: #fff; }
.account-nav-item.is-active i { color: #fff; }

.account-hero { display: flex; align-items: center; gap: 1.2rem; margin-bottom: 1.6rem; }
.account-hero-avatar {
    width: 64px; height: 64px; border-radius: 50%; flex-shrink: 0; overflow: hidden;
    background: linear-gradient(150deg, var(--primary), var(--accent));
    color: #fff; display: grid; place-items: center;
    font-family: var(--serif); font-size: 1.7rem; box-shadow: var(--shadow);
}
.account-hero-avatar img { width: 100%; height: 100%; object-fit: cover; }
.account-hero h1 { margin: 0 0 .2rem; }
.account-hero p { margin: 0; }

/* ---------- Tipitaka browse ---------- */
.page-head { padding: 2rem 0 1rem; }
.page-head h1 { font-size: 1.9rem; margin: 0; }
.pitaka-section { margin-bottom: 2.2rem; }
.pitaka-section h2 { font-size: 1.3rem; color: var(--primary); border-left: 4px solid var(--accent); padding-left: .7rem; margin-bottom: 1rem; }
.volume-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); gap: 1.4rem 1.1rem; }
.volume-card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    aspect-ratio: 3 / 4.3;
    padding: 1.1rem .8rem .75rem;
    border-radius: 3px 10px 10px 3px;
    background:
        linear-gradient(155deg, var(--ed-color, var(--primary)) 0%, var(--ed-color-dark, var(--primary-dark)) 100%);
    background-clip: padding-box;
    color: var(--accent-soft);
    text-decoration: none;
    box-shadow:
        0 1px 0 rgba(255, 255, 255, .12) inset,
        0 3px 10px rgba(30, 20, 5, .22);
    margin-top: 0;
    /* หมายเหตุ: ห้ามใส่ box-shadow ใน transition — การ animate box-shadow ทำให้ Chrome
       ยก card ขึ้นเป็น GPU layer แล้ว raster ตัวหนังสือเบลอตอน hover (โดยเฉพาะจอ Retina) */
    transition: margin-top .18s ease, background .18s ease;
}
/* สันหนังสือ (ซ้าย) */
.volume-card::before {
    content: '';
    position: absolute; inset: 0 auto 0 0; width: 10px;
    border-radius: 3px 0 0 3px;
    background: linear-gradient(180deg, rgba(0, 0, 0, .4), rgba(255, 255, 255, .1) 45%, rgba(0, 0, 0, .4));
}
/* ขอบหน้ากระดาษ (ขวา) */
.volume-card::after {
    content: '';
    position: absolute; right: 2px; top: 4px; bottom: 4px; width: 5px;
    border-radius: 0 3px 3px 0;
    background: repeating-linear-gradient(180deg, rgba(255, 250, 235, .8) 0 2px, rgba(210, 195, 165, .5) 2px 4px);
    opacity: .6;
}
.volume-card:hover {
    margin-top: -6px;
    /* ห้ามทำให้ปกสว่างขึ้นตอน hover — จะทำให้สีพื้นใกล้เคียงสีตัวหนังสือจนอ่านยาก */
    box-shadow: 0 1px 0 rgba(255, 255, 255, .14) inset, 0 18px 30px rgba(30, 20, 5, .32);
}
.volume-emblem {
    position: absolute; bottom: 16%; left: 0; right: 0; text-align: center;
    font-size: 3.6rem; opacity: .16; color: var(--cover-text); line-height: 1; pointer-events: none;
    z-index: 0;
}
.volume-no {
    position: relative; z-index: 1;
    font-family: var(--serif); font-weight: 700; font-size: 1.25rem;
    color: var(--cover-text); text-shadow: 0 1px 2px rgba(0, 0, 0, .8);
    margin-bottom: .3rem;
}
.volume-title {
    position: relative; z-index: 1;
    font-family: var(--serif); line-height: 1.25;
    text-align: center; flex: 1;
    display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
    padding-top: .45rem; gap: .12rem;
    color: var(--cover-text); text-shadow: 0 1px 2px rgba(0, 0, 0, .8);
}
.vt-main { font-size: 1.12rem; font-weight: 700; }
.vt-sub { font-size: .86rem; font-weight: 500; opacity: .95; }
.volume-pages {
    position: relative; z-index: 1;
    font-size: .72rem; color: var(--cover-text); opacity: .9;
    border-top: 1px solid rgba(255, 255, 255, .3); padding-top: .35rem; width: 100%; text-align: center;
}

/* ---------- แท็บหน้าเล่ม (สรุปเนื้อหา / หน้าในเล่มนี้) ---------- */
.volume-tabs { display: flex; gap: .4rem; border-bottom: 2px solid var(--border); margin-bottom: 1.4rem; }
.vtab-btn {
    background: none; border: none; padding: .75rem 1.1rem; font: inherit; font-weight: 600;
    color: var(--text-soft); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px;
    transition: color .15s, border-color .15s;
}
.vtab-btn:hover { color: var(--primary); }
.vtab-btn.is-active { color: var(--primary); border-bottom-color: var(--accent); }
.vtab-panel[hidden] { display: none; }

/* สถานะสรุปเนื้อหาด้วย AI */
.ai-summary-status { text-align: center; padding: 3rem 1.5rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.ai-summary-status .ico { font-size: 2.4rem; color: var(--accent); margin-bottom: .8rem; }
.ai-summary-status h4 { margin: 0 0 .5rem; }
.ai-summary-progress { max-width: 320px; margin: 1.2rem auto 0; }
.ai-summary-progress .bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.ai-summary-progress .bar-fill { height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent)); border-radius: 99px; }
.ai-summary-progress .label { font-size: .82rem; color: var(--muted); margin-top: .5rem; }

/* รายการหน้าในเล่ม */
/* ---------- ควบคุมการนำทางหน้าในเล่ม (jump / filter) ---------- */
.page-nav-tools { display: flex; flex-wrap: wrap; gap: .8rem; align-items: flex-end; margin-bottom: 1.4rem; padding: 1rem 1.2rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.page-nav-field { display: flex; flex-direction: column; gap: .3rem; }
.page-nav-field label { font-size: .78rem; color: var(--muted); font-weight: 600; }
.page-nav-field .row { display: flex; gap: .4rem; }
.page-nav-field input {
    padding: .5rem .8rem; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
    background: var(--bg-soft); color: var(--text); font: inherit; width: 140px; transition: border-color .15s;
}
.page-nav-field input:focus { border-color: var(--accent); outline: none; }
.page-nav-field input.input-error { border-color: var(--danger); animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

.page-group { margin-bottom: 1.1rem; }
.page-group-label { font-size: .8rem; color: var(--muted); font-weight: 600; margin-bottom: .5rem; padding-left: .1rem; }

.page-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); gap: .5rem; }
.page-chip { text-align: center; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .5rem; font-size: .9rem; transition: .15s; }
.page-chip:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
/* หน้าที่ AI ประเมินว่าน่าสนใจ — เข้มขึ้นตามระดับคะแนน */
.page-chip.is-warm { background: var(--accent-soft); border-color: var(--accent); color: var(--primary-dark); font-weight: 600; }
.page-chip.is-hot { background: var(--accent); border-color: var(--primary); color: #fff; font-weight: 700; }
.page-chip.is-hot:hover, .page-chip.is-warm:hover { background: var(--primary); color: #fff; }
.page-chip.has-bookmark { position: relative; }
.page-chip-bm { position: absolute; top: -6px; right: -4px; font-size: .72rem; color: var(--bm-color, var(--accent)); background: var(--surface); border-radius: 50%; padding: 1px; }
.side-pages a.has-bookmark { position: relative; }
.side-pages a .page-chip-bm { top: -5px; right: -6px; }

/* ---------- แท็บสรุปเนื้อหา: รายการหัวข้อ ---------- */
.topic-list { list-style: none; margin: 0; padding: 0; counter-reset: topic; }
.topic-list li { counter-increment: topic; }
.topic-list a {
    display: flex; gap: 1rem; align-items: flex-start; padding: .85rem 1rem; border-radius: var(--radius-sm);
    border-bottom: 1px solid var(--border); color: var(--text); transition: background .15s;
}
.topic-list li:first-child a { border-top-left-radius: var(--radius); border-top-right-radius: var(--radius); }
.topic-list li:last-child a { border-bottom: none; border-bottom-left-radius: var(--radius); border-bottom-right-radius: var(--radius); }
.topic-list a::before { content: counter(topic) "."; color: var(--accent); font-weight: 700; font-family: var(--serif); flex-shrink: 0; width: 1.6rem; padding-top: .1rem; }
.topic-list a:hover { background: var(--surface-2); }
.topic-range { flex-shrink: 0; color: var(--muted); font-size: .85rem; width: 130px; padding-top: .1rem; }
.topic-body { display: flex; flex-direction: column; gap: .25rem; min-width: 0; }
.topic-title { font-weight: 500; }
.topic-summary { color: var(--muted); font-size: .85rem; line-height: 1.5; }
.topic-list a.is-topic-done { background: color-mix(in srgb, var(--success) 8%, transparent); }
.topic-done-badge { color: var(--success); margin-right: .3rem; }
.topic-thumb { flex-shrink: 0; width: 128px; height: 72px; border-radius: var(--radius-sm); object-fit: cover; cursor: zoom-in; transition: opacity .15s; }
.topic-thumb:hover { opacity: .85; }

/* มือถือ: เรียงเลข+หน้าไว้แถวบน แล้วให้รูปกว้างเต็มการ์ด ตามด้วยข้อความ แทนการยัดทุกอย่างไว้แถวเดียวจนข้อความถูกบีบแคบ */
@media (max-width: 600px) {
    .topic-list a { flex-wrap: wrap; gap: .3rem .6rem; padding: .8rem .9rem; }
    .topic-list a::before { order: 1; }
    .topic-range { order: 2; width: auto; }
    .topic-thumb { order: 3; flex-basis: 100%; width: 100%; height: auto; aspect-ratio: 16 / 9; margin-top: .2rem; }
    .topic-body { order: 4; flex-basis: 100%; }
}

/* ---------- Dropzone อัปโหลดรูป (ลากวาง/คลิกเลือกไฟล์ อัปโหลดทันทีไม่ต้องกดปุ่มแยก) ---------- */
.dropzone {
    display: flex; align-items: center; justify-content: center; text-align: center;
    border: 2px dashed var(--border); border-radius: var(--radius-sm); cursor: pointer;
    color: var(--muted); font-size: .8rem; line-height: 1.4; transition: border-color .15s, background .15s, color .15s;
    overflow: hidden; padding: .6rem;
}
.dropzone:hover, .dropzone.is-dragover { border-color: var(--accent); background: var(--surface-2); color: var(--text); }
.dropzone.is-uploading { opacity: .55; pointer-events: none; }
.dropzone input[type="file"] { display: none; }
.dropzone img { width: 100%; height: 100%; object-fit: cover; }
.dropzone-text i { display: block; font-size: 1.3rem; margin-bottom: .3rem; }

/* ---------- หน้าแอดมินจัดการรูปหัวข้อ (/admin/topics/...) — การ์ดกริดกะทัดรัด ---------- */
.topics-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 1rem; }
.topic-edit-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .8rem; display: flex; flex-direction: column; gap: .6rem; }
.topic-edit-card .dropzone { aspect-ratio: 4 / 3; }
.topic-edit-card .dropzone.has-image { border-style: solid; }
.topic-edit-body { display: flex; flex-direction: column; gap: .25rem; }
.topic-edit-body .summary { color: var(--muted); font-size: .85rem; line-height: 1.5; }
.topic-edit-body form { margin-top: .2rem; }

/* ---------- กล่องคำสั่งที่พับซ่อนได้ (details/summary) — ใช้กับข้อมูลที่ไม่ต้องเห็นตลอดเวลา ---------- */
.details-toggle > summary {
    cursor: pointer; list-style: none; display: inline-flex; align-items: center; gap: .4rem;
    font-size: .85rem; color: var(--primary); font-weight: 500;
    padding: .45rem .9rem; border: 1.5px solid var(--border); border-radius: 999px; width: fit-content;
}
.details-toggle > summary::-webkit-details-marker { display: none; }
.details-toggle[open] > summary { margin-bottom: 1rem; }

/* ---------- แอดมิน: ระบบอัปเดตเว็บไซต์ ---------- */
.sysupdate-item {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    padding: .8rem 1rem; border: 1px solid var(--border); border-radius: 10px; margin-bottom: .6rem;
    background: var(--surface-2);
}
.sysupdate-log {
    margin-top: 1rem; border: 1px solid var(--border); border-radius: 10px; padding: .8rem 1rem;
    background: var(--surface-2); display: flex; flex-direction: column; gap: .5rem;
}
.sysupdate-log-line { font-size: .88rem; display: flex; align-items: center; gap: .6rem; }
.sysmigrate-version {
    padding: .8rem 1rem; border: 1px solid var(--border); border-radius: 10px; margin-bottom: .6rem;
}
.sysmigrate-version ul { margin: .5rem 0 0; padding-left: 1.2rem; color: var(--muted); font-size: .85rem; }
.changelog-entry { margin-bottom: .8rem; }
.changelog-entry ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
.changelog-entry li { display: flex; align-items: baseline; gap: .6rem; font-size: .92rem; }

/* ---------- Reader ---------- */
.reader-layout { display: grid; grid-template-columns: 260px 1fr; gap: 1.6rem; padding: 1.4rem 0 3rem; }
.reader-side { position: sticky; top: 82px; align-self: start; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem; max-height: 80vh; overflow: auto; }
.reader-side h4 { margin: 0 0 .6rem; font-size: .95rem; }
.reader-main { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 2.2rem clamp(1.2rem, 4vw, 3rem); }
.reader-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .8rem; padding-bottom: 1rem; margin-bottom: 1.4rem; border-bottom: 1px solid var(--border); }
.reader-locator { font-size: .92rem; color: var(--muted); }
.reader-locator strong { color: var(--text); font-family: var(--serif); }
.reader-tools { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.font-btn { width: 34px; height: 34px; border: 1px solid var(--border); background: var(--surface-2); border-radius: 8px; cursor: pointer; color: var(--text); }
.read-aloud-btn {
    border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
    border-radius: 8px; padding: .45rem .85rem; font: inherit; font-size: .85rem; cursor: pointer;
    transition: background .15s, color .15s, border-color .15s;
}
.read-aloud-btn:hover { border-color: var(--accent); color: var(--primary); }
.read-aloud-btn.is-speaking { background: var(--primary); color: #fff; border-color: var(--primary); }
.read-aloud-btn .ra-playing { display: none; }
.read-aloud-btn.is-speaking .ra-idle { display: none; }
.read-aloud-btn.is-speaking .ra-playing { display: inline-flex; }

.reader-content { font-family: var(--serif); font-size: 1.22rem; line-height: 2.05; word-break: break-word; color: var(--text); }
.reader-content mark { background: var(--accent-soft); color: var(--primary-dark); padding: 0 .15em; border-radius: 3px; }
.reader-content p { margin: 0 0 1.1em; text-indent: 1.7em; }
.reader-content .item-no { font-weight: 700; color: var(--primary); text-indent: 0; }
.reader-content p.dhamma-item { margin: 0 0 .35em; text-indent: 0; }
.reader-content .content-heading { text-align: center; font-weight: 700; color: var(--primary-dark); text-indent: 0; }
.reader-content h3.content-heading { font-size: 1.5rem; margin: 1.8rem 0 .9rem; }
.reader-content h4.content-heading { font-size: 1.15rem; margin: 1.3rem 0 .7rem; }
.reader-content h3.content-heading:first-child, .reader-content h4.content-heading:first-child { margin-top: 0; }

/* เนื้อหาส่วนที่ยังตกค้างจากหัวข้อก่อนหน้า/ถัดไป (อยู่ปนหน้าเดียวกับหัวข้อที่กำลังอ่าน) — แสดงจางลง */
.topic-boundary-fade {
    opacity: .45; border-left: 3px solid var(--border); padding-left: 1rem;
    margin-bottom: 1.4rem; position: relative;
}
.topic-boundary-fade::after {
    content: attr(data-caption);
    display: block; font-family: var(--sans); font-size: .8rem; font-style: normal;
    color: var(--muted); text-indent: 0; margin-top: -.6rem; margin-bottom: 1.2rem;
}
/* เส้นคั่น "จบหัวข้อนี้" ก่อนเนื้อหาของหัวข้อถัดไปที่เผลอเริ่มปนอยู่ท้ายหน้าเดียวกัน */
.topic-boundary-end-divider {
    display: flex; align-items: center; gap: .8rem; margin: 1.6rem 0; color: var(--muted);
    font-family: var(--sans); font-size: .82rem; font-weight: 500;
}
.topic-boundary-end-divider::before, .topic-boundary-end-divider::after {
    content: ""; flex: 1; height: 1px; background: var(--border);
}
.reader-nav { display: flex; justify-content: space-between; margin-top: 2rem; padding-top: 1.2rem; border-top: 1px solid var(--border); gap: .6rem; }

/* ---------- แถบสถานะหัวข้อ (ทำเครื่องหมายอ่านจบ) + แผงแนะนำอ่านต่อ ---------- */
.topic-progress-bar {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .8rem;
    margin-top: 1.6rem; padding: .9rem 1.1rem; background: var(--surface-2); border-radius: var(--radius-sm);
}
.topic-progress-main { display: flex; align-items: center; gap: .9rem; min-width: 0; }
.topic-progress-info { display: flex; flex-direction: column; gap: .1rem; min-width: 0; }
.topic-progress-thumb { flex-shrink: 0; width: 96px; height: 60px; border-radius: var(--radius-sm); object-fit: cover; cursor: zoom-in; transition: opacity .15s; }
.topic-progress-thumb:hover { opacity: .85; }

/* ---------- Lightbox ซูมรูปหัวข้อเป็นรูปใหญ่ ---------- */
.lightbox-overlay {
    position: fixed; inset: 0; z-index: 2000; background: rgba(0, 0, 0, .8);
    display: flex; align-items: center; justify-content: center; padding: 2rem;
    opacity: 0; animation: lightbox-fade .18s ease forwards;
}
@keyframes lightbox-fade { to { opacity: 1; } }
.lightbox-overlay img { max-width: 100%; max-height: 100%; border-radius: var(--radius-sm); box-shadow: 0 20px 60px rgba(0, 0, 0, .5); cursor: zoom-out; }
.lightbox-close {
    position: absolute; top: 1.2rem; right: 1.4rem; background: none; border: none; color: #fff;
    font-size: 2rem; line-height: 1; cursor: pointer; opacity: .8;
}
.lightbox-close:hover { opacity: 1; }

/* ---------- แกลเลอรีภาพประกอบพระไตรปิฎก (หน้าแรก) ---------- */
.illustration-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.1rem; }
@media (max-width: 900px) { .illustration-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 480px) { .illustration-grid { grid-template-columns: 1fr; } }
.illustration-card {
    border: none; padding: 0; border-radius: var(--radius); overflow: hidden; cursor: pointer; text-align: left;
    background: var(--surface); box-shadow: var(--shadow); transition: transform .15s, box-shadow .15s; font: inherit; color: inherit;
}
.illustration-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.illustration-card img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; }
.illustration-card-title {
    display: block; padding: .65rem .85rem; font-weight: 500; font-size: .9rem; color: var(--text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---------- Modal รูปหัวข้อ + ลิงก์ไปอ่านเนื้อหาที่เกี่ยวข้อง (ใช้ overlay เดียวกับ lightbox) ---------- */
.topic-modal-card {
    display: flex; flex-direction: column; max-width: min(880px, 94vw); max-height: 92vh;
    background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}
.topic-modal-media { position: relative; }
.topic-modal-media img { width: 100%; max-height: 68vh; object-fit: cover; cursor: default; border-radius: 0; box-shadow: none; max-width: none; display: block; }
.topic-modal-nav-btn {
    position: absolute; top: 50%; transform: translateY(-50%); z-index: 1;
    width: 40px; height: 40px; border-radius: 50%; border: none; cursor: pointer;
    background: rgba(0, 0, 0, .45); color: #fff; display: grid; place-items: center; font-size: 1.1rem;
    transition: background .15s, transform .15s;
}
.topic-modal-nav-btn:hover { background: rgba(0, 0, 0, .7); }
.topic-modal-prev { left: .8rem; }
.topic-modal-next { right: .8rem; }
.topic-modal-counter { font-size: .78rem; color: var(--muted); }
.topic-modal-body { padding: 1.3rem 1.5rem; display: flex; flex-direction: column; align-items: flex-start; gap: .6rem; overflow-y: auto; }
.topic-modal-body h3 { margin: 0; font-family: var(--serif); color: var(--primary-dark); }
.topic-modal-summary { margin: 0; color: var(--text-soft); font-size: .9rem; line-height: 1.5; }

/* แถวล่างของโมดัล — ปุ่มอ่านเนื้อหาชิดซ้าย ปุ่มแชร์ Social ชิดขวา */
.topic-modal-actions { display: flex; align-items: center; justify-content: space-between; width: 100%; gap: 1rem; flex-wrap: wrap; }
.topic-share-bar { display: flex; gap: .5rem; margin-left: auto; }
.topic-share-btn {
    width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
    background: var(--bg-soft); color: var(--text-soft); box-shadow: none; border: 1px solid var(--border);
    transition: transform .15s, background .15s, color .15s, border-color .15s; cursor: pointer; padding: 0;
}
.topic-share-btn svg { width: 16px; height: 16px; }
.topic-share-btn i { font-size: 15px; }
.topic-share-btn:hover { transform: translateY(-2px); }
.topic-share-fb:hover { background: #1877f2; color: #fff; border-color: #1877f2; }
.topic-share-line:hover { background: #06c755; color: #fff; border-color: #06c755; }
.topic-share-x:hover { background: #000; color: #fff; border-color: #000; }
.topic-share-copy.is-copied { background: var(--primary); color: #fff; border-color: var(--primary); }
.read-next-panel { margin-top: 1.4rem; padding: 1.2rem; background: var(--bg-soft); border: 1px solid var(--border); border-radius: var(--radius); }
.read-next-panel h4 { margin: 0 0 .9rem; color: var(--primary); }
.read-next-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .9rem; }
.read-next-card {
    display: flex; flex-direction: column; gap: .35rem; padding: .9rem 1rem;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
    text-decoration: none; color: var(--text); transition: box-shadow .15s, border-color .15s;
}
.read-next-card:hover { box-shadow: var(--shadow); border-color: var(--accent); }
.read-next-card strong { color: var(--primary-dark); font-family: var(--serif); }
.read-next-card .tag { align-self: flex-start; }
.edition-switch { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .4rem; }
.edition-switch a { font-size: .82rem; padding: .3rem .7rem; border: 1px solid var(--border); border-radius: 20px; color: var(--text-soft); }
.edition-switch a.current { background: var(--primary); color: #fff; border-color: var(--primary); }
.side-pages { display: grid; grid-template-columns: repeat(auto-fill, minmax(34px, 38px)); gap: .3rem; }
.side-pages a { text-align: center; font-size: .8rem; padding: .3rem 0; border-radius: 6px; color: var(--text-soft); }
.side-pages a:hover { background: var(--surface-2); }
.side-pages a.current { background: var(--accent); color: #fff; }

/* ---------- Search ---------- */
.search-header { background: var(--bg-soft); border-bottom: 1px solid var(--border); padding: 1.8rem 0; }
.search-form { display: flex; flex-direction: column; gap: 1.1rem; max-width: 900px; }

.search-main {
    display: flex; gap: .5rem; background: var(--surface); padding: .4rem;
    border-radius: 999px; border: 1.5px solid var(--border); box-shadow: var(--shadow);
}
.search-main input { flex: 1; border: none; background: transparent; padding: .6rem 1.1rem; font: inherit; color: var(--text); outline: none; }
.search-main .btn { border-radius: 999px; padding-inline: 1.6rem; flex-shrink: 0; }

.search-filters { display: flex; flex-wrap: wrap; gap: 1.1rem; align-items: flex-end; }
.filter-field { display: flex; flex-direction: column; gap: .35rem; }
.filter-field label { font-size: .78rem; font-weight: 600; color: var(--muted); padding-left: .1rem; }
.filter-field .ts-wrapper { min-width: 170px; }
.filter-field-sm .volume-input { width: 110px; }
.volume-input { padding: .45rem .7rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit; height: 38px; box-sizing: border-box; }
.filter-clear { align-self: center; font-size: .85rem; color: var(--text-soft); padding: .5rem .3rem; white-space: nowrap; }
.filter-clear:hover { color: var(--danger); }

.thai-date-picker { display: flex; gap: .5rem; flex-wrap: wrap; }
.thai-date-picker .ts-wrapper { min-width: 0; }
.thai-date-picker .thai-date-day + .ts-wrapper { flex: 0 0 80px; }
.thai-date-picker .thai-date-month + .ts-wrapper { flex: 1 1 150px; }
.thai-date-picker .thai-date-year + .ts-wrapper { flex: 0 0 100px; }
.thai-date-picker .thai-date-time { flex: 0 0 110px; }

/* ---------- Tom Select — ปรับให้เข้าธีมโทนสงบของเว็บ ---------- */
/* หมายเหตุ: Tom Select เองจะซ่อน <select> เดิมให้อัตโนมัติหลัง init สำเร็จ
   จึงไม่ล็อก display:none ไว้ล่วงหน้า — ถ้า JS โหลดไม่สำเร็จ select ปกติจะยังใช้งานได้ */
.ts-wrapper { min-width: 170px; font-family: var(--sans); font-size: .9rem; }
.ts-wrapper.single .ts-control {
    background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
    color: var(--text); padding: .45rem .7rem; box-shadow: none; min-height: unset;
    height: 38px; box-sizing: border-box; display: flex; align-items: center;
}
.ts-wrapper.single.focus .ts-control { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.ts-control input { color: var(--text); }
.ts-dropdown {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg); font-family: var(--sans); margin-top: 4px;
}
.ts-dropdown .option, .ts-dropdown .no-results { color: var(--text-soft); padding: .5rem .8rem; }
.ts-dropdown .option.active { background: var(--surface-2); color: var(--primary); }
.ts-dropdown .option.selected { background: var(--accent-soft); color: var(--primary-dark); }
[data-theme="dark"] .ts-wrapper.single .ts-control { background: var(--bg-soft); }
.search-summary { color: var(--muted); padding: 1.2rem 0 .4rem; }
.result-list { display: flex; flex-direction: column; gap: 1rem; padding-bottom: 2rem; }
.result-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.2rem 1.4rem; transition: box-shadow .15s; }
.result-card:hover { box-shadow: var(--shadow); }
.result-meta { display: flex; flex-wrap: wrap; gap: .5rem; font-size: .82rem; margin-bottom: .5rem; }
.tag { background: var(--surface-2); color: var(--text-soft); padding: .18rem .6rem; border-radius: 20px; }
.tag-edition { background: var(--accent-soft); color: var(--primary-dark); font-weight: 600; }
.result-snippet { font-family: var(--serif); font-size: 1.05rem; line-height: 1.9; color: var(--text-soft); }
.result-snippet mark { background: var(--accent-soft); color: var(--primary-dark); font-weight: 600; }
.result-title { font-family: var(--serif); color: var(--primary); font-weight: 600; margin-bottom: .3rem; display: inline-block; }

/* ---------- ผลค้นหา: หัวข้อที่ AI สรุปไว้ ---------- */
.result-topics { margin: 1rem 0 1.6rem; }
.result-topics-head { display: flex; align-items: center; gap: .5rem; font-size: 1rem; color: var(--primary-dark); margin-bottom: .7rem; }
.result-topics-head i { color: var(--accent); }
.result-topic-list { display: flex; flex-direction: column; gap: .7rem; }
.result-topic-card {
    display: block; background: var(--accent-soft); border: 1px solid var(--border); border-radius: var(--radius);
    padding: .9rem 1.2rem; color: var(--text); transition: box-shadow .15s;
}
.result-topic-card:hover { box-shadow: var(--shadow); }
.result-topic-title { font-weight: 600; color: var(--primary-dark); margin-bottom: .25rem; }
.result-topic-summary { font-size: .9rem; color: var(--text-soft); line-height: 1.6; }
.result-topic-card mark, .result-topic-title mark { background: var(--accent); color: #fff; font-weight: 700; border-radius: 3px; padding: 0 .1rem; }

/* ---------- หน้าตั้งค่าบัญชี ---------- */
.settings-row {
    display: flex; align-items: center; justify-content: space-between; gap: 1.2rem;
    padding: 1rem 0; border-bottom: 1px solid var(--border);
}
.settings-row:last-of-type { border-bottom: none; }
.theme-options { display: flex; gap: .5rem; flex-shrink: 0; }
.theme-option {
    padding: .5rem 1rem; border: 1px solid var(--border); background: var(--surface-2);
    border-radius: 8px; cursor: pointer; color: var(--text); font-size: .92rem;
}
.theme-option.is-active { background: var(--primary); border-color: var(--primary); color: #fff; }
.palette-options { display: flex; gap: .6rem; flex-shrink: 0; }
.palette-option {
    width: 34px; height: 34px; border-radius: 50%; cursor: pointer;
    border: 2px solid var(--border); background: var(--swatch, var(--primary));
    position: relative; padding: 0;
}
.palette-option.is-active { border-color: var(--text); box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--swatch, var(--primary)); }
.palette-options-sm { display: flex; gap: .4rem; margin-top: .5rem; }
.palette-option-sm { width: 18px; height: 18px; border-width: 1.5px; }
.palette-option-sm.is-active { box-shadow: 0 0 0 1.5px var(--surface), 0 0 0 3px var(--swatch, var(--primary)); }
.font-family-options { display: flex; gap: .5rem; flex-shrink: 0; }
.font-family-option {
    padding: .5rem 1rem; border: 1px solid var(--border); background: var(--surface-2);
    border-radius: 8px; cursor: pointer; color: var(--text); font-size: .92rem;
}
.font-family-option.is-active { background: var(--primary); border-color: var(--primary); color: #fff; }
.font-size-controls { display: flex; align-items: center; gap: .6rem; flex-shrink: 0; }
.font-size-pct { min-width: 3.2em; text-align: center; color: var(--muted); font-size: .88rem; }
.font-preview {
    margin: 1rem 0 0; padding: 1rem; border: 1px dashed var(--border); border-radius: 8px;
    font-family: var(--serif); line-height: 1.9; color: var(--text-soft); background: var(--surface-2);
}

/* ---------- Slider ปรับเสียงอ่านออกเสียง (ความเร็ว/ระดับเสียง) ---------- */
.tts-field { margin-bottom: 1.6rem; }
.tts-field-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .7rem; }
.tts-field-head > span:first-child { display: flex; align-items: center; gap: .5rem; font-weight: 500; color: var(--text); font-size: .95rem; }
.tts-field-head i { color: var(--primary); font-size: 1rem; }
.tts-value-pill {
    background: var(--accent-soft); color: var(--primary-dark); font-weight: 700; font-size: .85rem;
    padding: .25rem .8rem; border-radius: 999px; min-width: 3.6rem; text-align: center;
}
.tts-field input[type="range"] {
    -webkit-appearance: none; appearance: none; width: 100%; height: 6px; border-radius: 999px;
    background: var(--border); accent-color: var(--primary); padding: 0; border: none; margin: 0; cursor: pointer;
}
.tts-field-ticks { display: flex; justify-content: space-between; margin-top: .4rem; font-size: .78rem; color: var(--muted); }

/* ---------- ปฏิทินเลือกวันที่ไทย (Flatpickr) — ปรับให้เข้าธีมเว็บ + รองรับปี พ.ศ. ---------- */
.flatpickr-calendar { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); font-family: inherit; }
.flatpickr-calendar.arrowTop:before, .flatpickr-calendar.arrowTop:after { border-bottom-color: var(--surface); }
.flatpickr-months, .flatpickr-weekdays { background: var(--surface); }
.flatpickr-current-month { font-size: .95rem; color: var(--text); }
.flatpickr-current-month .flatpickr-monthDropdown-months { background: var(--surface); color: var(--text); }
.flatpickr-current-month .fp-year-be {
    border: none; background: transparent; font: inherit; font-weight: 600; color: var(--text);
    cursor: pointer; padding: 0 2px; outline: none; margin-left: .3rem;
}
.flatpickr-weekday { background: var(--surface); color: var(--muted); }
.flatpickr-day { color: var(--text); }
.flatpickr-day.today { border-color: var(--accent); }
.flatpickr-day.selected, .flatpickr-day.selected:hover { background: var(--primary); border-color: var(--primary); color: #fff; }
.flatpickr-day:hover { background: var(--surface-2); }
.flatpickr-day.flatpickr-disabled, .flatpickr-day.prevMonthDay, .flatpickr-day.nextMonthDay { color: var(--muted); opacity: .5; }
.flatpickr-time input, .flatpickr-time .flatpickr-time-separator, .flatpickr-time .flatpickr-am-pm { color: var(--text); }
span.flatpickr-prev-month, span.flatpickr-next-month { fill: var(--muted); color: var(--muted); }
span.flatpickr-prev-month:hover, span.flatpickr-next-month:hover { fill: var(--primary); color: var(--primary); }
[data-theme="dark"] .flatpickr-day.prevMonthDay, [data-theme="dark"] .flatpickr-day.nextMonthDay { opacity: .35; }

/* ---------- ตาราง/แดชบอร์ด ---------- */
.section-lead { padding: 2rem 0 1rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; box-shadow: var(--shadow); }
/* min-width:0 บนลูกกริดทุกตัว กัน "grid blowout" — ปกติ grid item จะไม่ยอมหดเกิน content
   ที่กว้างที่สุดของมัน (min-width:auto โดยดีฟอลต์) ถ้าเนื้อหาข้างในกว้างกว่าที่ 1fr แบ่งให้
   ทั้งแทร็กจะดันกว้างเกิน container จนล้นขวาจอ (อาการ: การ์ดคอลัมน์ขวาถูกตัดขอบ) */
.grid-2, .grid-3, .grid-4, .grid-5 { min-width: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.3rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3,1fr); gap: 1.1rem; }
.grid-4 { display: grid; grid-template-columns: repeat(4,1fr); gap: 1.1rem; }
.grid-5 { display: grid; grid-template-columns: repeat(5,1fr); gap: 1.1rem; }
.grid-2 > *, .grid-3 > *, .grid-4 > *, .grid-5 > * { min-width: 0; }
.stat-card {
    background: var(--surface); border: 1px solid var(--border); border-top: 3px solid var(--accent);
    border-radius: var(--radius); padding: 1.3rem; text-align: center;
    transition: transform .15s, box-shadow .15s;
    min-width: 0;
}

/* ---------- หน้าฝึกจิต — ตัวจับเวลานั่งสมาธิ + เช็กลิสต์ศีลรายข้อ ---------- */
.meditation-timer { text-align: center; padding: 1.2rem; margin-bottom: 1.2rem; background: var(--surface-2); border-radius: var(--radius-sm); border: 1px solid var(--border); transition: background .2s, border-color .2s; }
.meditation-timer.mt-done { border-color: var(--accent); background: var(--accent-soft); }
.mt-display { font-family: var(--serif); font-size: 2.8rem; color: var(--primary); letter-spacing: .04em; line-height: 1.2; }
.mt-actions { display: flex; gap: .5rem; justify-content: center; margin: .6rem 0 .3rem; flex-wrap: wrap; }
.meditation-timer.mt-done .mt-display { color: var(--accent); animation: mt-pulse 1s infinite; }
@keyframes mt-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }
.mt-note { margin: .3rem 0 0; }
/* ล็อกช่องประเภท/ระยะเวลาตอนจับเวลาอยู่ — ป้องกันการแก้ระหว่างนับถอยหลัง (ไม่ใช้ disabled เพราะจะไม่ถูกส่งไปกับฟอร์ม) */
#mtLockGroup.is-locked { pointer-events: none; opacity: .6; }

.precept-items { margin: .2rem 0 1rem; }
.precept-items-label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .5rem; }
/* :not([hidden]) กันไม่ให้ display:flex ของคลาสนี้ชนะทับ [hidden] ของ user-agent stylesheet
   (ทั้งคู่มี specificity เท่ากัน — ใครมาทีหลังใน cascade ชนะ) ไม่งั้นกลุ่มศีล ๕/๘ จะโชว์ซ้อนกันทั้งคู่ */
.precept-item-group:not([hidden]) { display: flex; flex-direction: column; gap: .6rem; }

.precept-item {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    font-size: .92rem; background: var(--surface-2); border: 1px solid var(--border);
    border-radius: 12px; padding: .8rem 1rem; cursor: pointer;
    transition: border-color .15s, background .15s, box-shadow .15s;
}
.precept-item:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.precept-item-text { flex: 1; line-height: 1.4; }
.precept-item-text strong { color: var(--primary); margin-right: .3rem; }
.precept-item-input { position: absolute; width: 0; height: 0; opacity: 0; pointer-events: none; }

/* ตัวสวิตช์ toggle วาดด้วย CSS ล้วน (ไม่พึ่ง JS) — ใช้ :has() อ่านสถานะ checkbox ที่ซ่อนไว้ */
.precept-toggle {
    position: relative; flex-shrink: 0; width: 46px; height: 27px; border-radius: 999px;
    background: var(--border); transition: background .2s;
}
.precept-toggle::after {
    content: ''; position: absolute; top: 3px; left: 3px; width: 21px; height: 21px;
    border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .35);
    transition: transform .2s;
}
/* .is-checked มาจาก JS ล้วน ๆ (ดู initPreceptToggleClass ใน app.js) — ทดสอบแล้วพบว่า :has(input:checked)
   ไม่รีเพนต์ทันทีตอนคลิกในบางเบราว์เซอร์ (สวิตช์ค้างไม่ขยับทั้งที่ค่าจริงเปลี่ยนแล้ว) จึงตัดออกไม่ใช้เลย */
.precept-item.is-checked { background: var(--accent-soft); border-color: var(--accent); }
.precept-item.is-checked .precept-toggle { background: var(--primary); }
.precept-item.is-checked .precept-toggle::after { transform: translateX(19px); }
.precept-item-input:focus-visible ~ .precept-toggle { outline: 2px solid var(--accent); outline-offset: 2px; }
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat-card .num { font-family: var(--serif); font-size: 2rem; color: var(--primary); }
.stat-card .lbl { color: var(--muted); font-size: .88rem; }
.edition-filter-card { cursor: pointer; }
.edition-filter-card.is-active { border-color: var(--primary); background: var(--accent-soft); box-shadow: var(--shadow); }
.edition-filter-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- แถบสีสถานะข้อมูล AI ต่อฉบับ (บนการ์ดฉบับใน admin/data) ---------- */
.edition-progress {
    width: 100%; height: 8px; border-radius: 999px; background: var(--surface-2);
    overflow: hidden; margin: .8rem 0 .45rem; border: 1px solid var(--border);
}
.edition-progress-fill { height: 100%; border-radius: 999px; background: var(--muted); transition: width .3s ease; }
.edition-progress.is-partial .edition-progress-fill { background: var(--accent); }
.edition-progress.is-complete .edition-progress-fill { background: #4a8f5c; }
[data-theme="dark"] .edition-progress.is-complete .edition-progress-fill { background: #5fb374; }
.edition-progress-lbl { font-size: .78rem; color: var(--muted); }

/* ---------- infinite scroll (ประวัติการอ่าน/ที่คั่นหน้า) ---------- */
.infinite-sentinel { display: flex; justify-content: center; padding: 1.5rem 0; }
.infinite-sentinel .spinner {
    width: 26px; height: 26px; border-radius: 50%;
    border: 3px solid var(--border); border-top-color: var(--accent);
    animation: infinite-spin .7s linear infinite;
}
.infinite-sentinel.is-done { display: none; }
@keyframes infinite-spin { to { transform: rotate(360deg); } }
/* ---------- กราฟแท่งเข้าชมรายวัน (admin/visits) ---------- */
.visit-trend { display: flex; align-items: flex-end; gap: .5rem; height: 140px; }
.visit-trend-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; }
.visit-trend-bar-wrap { flex: 1; width: 100%; display: flex; align-items: flex-end; }
.visit-trend-bar { width: 100%; min-height: 3px; background: linear-gradient(180deg, var(--accent), var(--primary)); border-radius: 4px 4px 0 0; transition: height .2s; }
.visit-trend-label { margin-top: .4rem; font-size: .72rem; color: var(--muted); white-space: nowrap; }
table.data { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); }
table.data th, table.data td { padding: .75rem 1rem; text-align: left; border-bottom: 1px solid var(--border); font-size: .93rem; }
table.data th { background: var(--surface-2); font-weight: 600; color: var(--text-soft); }
table.data tbody tr { transition: background .12s; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tr:last-child td { border-bottom: none; }
.table-scroll { overflow-x: auto; }

/* เลย์เอาต์ 2 คอลัมน์ในหน้าแอดมิน (เนื้อหาหลัก + ฟอร์ม/แผงด้านข้างแคบ) — ใช้แทนการ inline style
   grid-template-columns เพราะ inline style จะชนะ media query ของ .admin-shell ทำให้มือถือพังคอลัมน์ไม่ยุบ */
.admin-split { display: grid; grid-template-columns: 1fr 320px; gap: 1.6rem; }
@media (max-width: 800px) {
    .admin-split { grid-template-columns: 1fr; }
}

/* ตารางสถานะสรุปเนื้อหาด้วย AI — บังคับแต่ละแถวให้อยู่บรรทัดเดียว ยกเว้นคอลัมน์หมายเหตุที่ตัดด้วย … */
.ai-summary-table { table-layout: auto; }
.ai-summary-table th, .ai-summary-table td { white-space: nowrap; }
.ai-summary-table td.col-notes {
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    max-width: 320px; cursor: help;
}
.badge { padding: .2rem .6rem; border-radius: 20px; font-size: .78rem; font-weight: 600; }
.badge-admin { background: var(--accent-soft); color: var(--primary-dark); }
.badge-user { background: var(--surface-2); color: var(--text-soft); }
.badge-active { background: #e7f2e6; color: #396e37; }
.badge-suspended { background: #fbe6e2; color: #9a3626; }

.list-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 1rem 1.2rem; margin-bottom: .7rem; display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }

/* ---------- Calendar ---------- */
.calendar { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.cal-head { display: flex; justify-content: space-between; align-items: center; padding: 1rem 1.3rem; background: var(--surface-2); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-grid .dow { text-align: center; padding: .6rem; font-weight: 600; color: var(--muted); font-size: .85rem; border-bottom: 1px solid var(--border); }
.cal-cell { min-height: 92px; border: 1px solid var(--border); padding: .4rem; position: relative; }
.cal-cell .d { font-size: .85rem; color: var(--text-soft); }
.cal-cell.today { background: var(--accent-soft); }
.cal-cell.empty { background: var(--bg); }
.cal-cell { display: flex; flex-direction: column; }
.cal-obs { display: block; margin-top: .25rem; font-size: .72rem; line-height: 1.5; background: var(--saffron); color: #fff; border-radius: 5px; padding: .15rem .35rem; white-space: normal; overflow-wrap: break-word; }
.cal-obs.holiday { background: var(--primary); }
.cal-precept { position: absolute; bottom: 4px; right: 5px; font-size: .8rem; }

/* ---------- Error ---------- */
.error-page { text-align: center; padding: 5rem 0; }
.error-mark { font-size: 3rem; color: var(--accent); }
.error-page h1 { font-size: 3.5rem; margin: .3rem 0; color: var(--primary); }

/* ---------- Footer ---------- */
.site-footer { background: var(--bg-soft); border-top: 1px solid var(--border); margin-top: 3rem; padding: 2.6rem 0 1.4rem; }
.footer-grid { display: grid; grid-template-columns: 1.6fr 1fr 1fr 1fr; gap: 1.6rem; }
.footer-grid h4 { font-size: 1rem; margin: 0 0 .7rem; }
.footer-grid a { display: block; color: var(--text-soft); font-size: .92rem; padding: .2rem 0; }
.footer-grid a:hover { color: var(--primary); }
.footer-brand { font-size: 1.2rem; margin-bottom: .6rem; }
.footer-bottom { border-top: 1px solid var(--border); margin-top: 1.6rem; padding-top: 1.2rem; text-align: center; }

/* ---------- Utilities ---------- */
.mt-1 { margin-top: 1rem; } .mt-2 { margin-top: 2rem; } .mb-1 { margin-bottom: 1rem; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.row-gap { display: flex; gap: .6rem; flex-wrap: wrap; }
.text-center { text-align: center; }
.pagination { display: flex; justify-content: center; gap: .4rem; padding: 1.5rem 0; }
.pagination a, .pagination span { padding: .45rem .8rem; border: 1px solid var(--border); border-radius: 8px; color: var(--text-soft); }
.pagination .cur { background: var(--primary); color: #fff; border-color: var(--primary); }
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty-state .ico { font-size: 2.6rem; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
    .pitaka-grid, .edition-grid, .feature-band, .footer-grid, .grid-2, .grid-3, .grid-4, .grid-5 { grid-template-columns: 1fr 1fr; }
    .reader-layout { grid-template-columns: 1fr; }
    .reader-main { order: -1; }
    .reader-side { position: static; max-height: 260px; padding: .85rem; }
    .side-pages { grid-template-columns: repeat(auto-fill, minmax(30px, 34px)); }
}
@media (max-width: 680px) {
    .nav-toggle { display: block; }
    .site-nav { position: fixed; inset: 66px 0 auto 0; background: var(--bg-soft); border-bottom: 1px solid var(--border); flex-direction: column; align-items: stretch; padding: 1rem; gap: .3rem; display: none; box-shadow: var(--shadow-lg); }
    body.nav-open .site-nav { display: flex; }
    .site-nav > a { padding: .6rem .4rem; }
    .site-nav > a.btn-nav { align-self: center; width: auto; text-align: center; margin-top: .4rem; }
    .nav-menu-list { position: static; box-shadow: none; border: none; display: flex; }
    .nav-mega { width: auto; }
    .nav-mega-grid { grid-template-columns: 1fr; }
    .pitaka-grid, .edition-grid, .feature-band, .footer-grid, .grid-2, .grid-3, .grid-4, .grid-5 { grid-template-columns: 1fr; }
    .hero-stats { flex-wrap: wrap; row-gap: 1.1rem; column-gap: 1.7rem; }
    .hero-stats > div { flex: 0 1 auto; }
    .hero-stats strong { font-size: 1.5rem; }
    .hero { padding: 2.6rem 0; }
}

/* ---------- ตราสัญลักษณ์เว็บไซต์ (admin/settings) ---------- */
.branding-row { display: flex; gap: 2rem; flex-wrap: wrap; }
.branding-item { display: flex; flex-direction: column; gap: .5rem; align-items: flex-start; }
.branding-empty { font-size: 1.6rem; color: var(--muted); }
.branding-form { display: flex; flex-direction: column; align-items: flex-start; gap: .6rem; }

.branding-file-input {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

.branding-dropzone {
    width: 220px; min-height: 90px; border: 2px dashed var(--border); border-radius: 12px;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .4rem;
    background: var(--surface-2); overflow: hidden; cursor: pointer; padding: .6rem;
    text-align: center; transition: border-color .15s ease, background-color .15s ease;
}
.branding-dropzone:hover { border-color: var(--accent, #b08d57); }
.branding-dropzone.is-dragover { border-color: var(--accent, #b08d57); background: var(--surface-3, #efe6d4); }
.branding-dropzone-sq { width: 90px; height: 90px; padding: .4rem; }
.branding-dropzone-img { max-width: 100%; max-height: 60px; object-fit: contain; }
.branding-dropzone-sq .branding-dropzone-img { max-height: 100%; }
.branding-dropzone-hint { font-size: .72rem; color: var(--muted); line-height: 1.3; }
.branding-dropzone-sq .branding-dropzone-hint { display: none; }

/* กล่องโลโก้ธีมมืด: พื้นหลังเป็นสีเข้มเสมอ (ไม่ตามธีมของหน้าตั้งค่า) เพราะโลโก้ธีมมืดมักเป็นสีอ่อน ต้องดูบนพื้นเข้มถึงจะเห็นจริง */
.branding-dropzone-dark { background: #221e18; border-color: #4a4030; }
.branding-dropzone-dark .branding-dropzone-hint { color: #b8ac95; }
.branding-dropzone-dark:hover { border-color: var(--accent, #dcb45f); }
.branding-dropzone-dark.is-dragover { background: #2f281f; border-color: var(--accent, #dcb45f); }

.checkbox-label { display: flex; align-items: center; gap: .55rem; margin-bottom: 1rem; cursor: pointer; }
.checkbox-label input[type="checkbox"] { width: 1.05rem; height: 1.05rem; accent-color: var(--primary); }
.checkbox-label span { font-weight: 500; font-size: .92rem; color: var(--text-soft); }

/* ---------- ตราสัญลักษณ์/ความสำเร็จ (เกมมิฟิเคชัน — /account/badges, admin/badges) ----------
   ตั้งใจใช้คำนำหน้า .achv-* แยกจาก .badge/.badge-admin/.badge-user/.badge-active/.badge-suspended
   ที่มีอยู่แล้ว (ป้ายบทบาท/สถานะผู้ใช้เล็กๆ ใน admin/users.php) เพื่อไม่ให้ชนกัน — คนละความหมายกัน */
.achv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 1.4rem; }
.achv-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 1.8rem 1.3rem 1.5rem; text-align: center; display: flex; flex-direction: column; align-items: center; gap: .35rem;
    transition: transform .15s, box-shadow .15s; box-shadow: 0 1px 3px rgba(0, 0, 0, .05);
}
.achv-card.is-earned { border-top: 4px solid var(--accent); }
.achv-card.is-earned:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.achv-card.is-locked { opacity: .55; filter: grayscale(.6); }
.achv-ico {
    width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center;
    background: var(--accent-soft); color: var(--primary-dark); font-size: 1.4rem; margin-bottom: .3rem;
}
/* ขยายใหญ่ขึ้นเฉพาะในกริดตราสัญลักษณ์ (/account/badges) — .achv-ico เดี่ยวๆ (เช่นใน recovery/index.php) ยังคงขนาดฐาน 54px */
.achv-card .achv-ico {
    width: 88px; height: 88px; font-size: 2.2rem; margin-bottom: .7rem;
}
.achv-card.is-earned .achv-ico { box-shadow: 0 0 0 4px var(--surface), 0 0 0 6px var(--accent-soft); }
.achv-card.is-locked .achv-ico { background: var(--surface-2); color: var(--muted); }
.achv-card strong { font-family: var(--serif); font-size: 1.1rem; color: var(--text); line-height: 1.3; }
.badge-share-bar { display: flex; gap: .4rem; justify-content: center; margin-top: .5rem; }
.badge-share-bar .topic-share-btn { width: 30px; height: 30px; }
/* รุ่นเล็กสำหรับแถวรายการ (admin/badges) แทนที่จะใช้ .achv-ico ขนาดเต็มที่ออกแบบไว้สำหรับกริดกว้าง */
.achv-ico-sm { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--primary-dark); font-size: 1rem; flex-shrink: 0; }
/* รูปที่ admin อัปโหลดเอง (แทน icon ตัวอักษร) — ครอปเป็นวงกลมให้เข้าชุดกับ .achv-ico/.achv-ico-sm */
.achv-ico img, .achv-ico-sm img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }

/* กล่องลากรูปวางขนาดเล็กในแถวรายการ admin/badges — สืบท็อดสไตล์จาก .dropzone ฐาน (border/hover/uploading) */
.achv-dropzone {
    width: 46px; height: 46px; border-radius: 50%; flex-shrink: 0; padding: 0;
    font-size: 1.1rem; color: var(--primary-dark); background: var(--accent-soft); border-style: solid;
}
.achv-dropzone:not(.has-image) { border-style: dashed; background: var(--surface-2); color: var(--muted); font-size: .85rem; }
.achv-dropzone.has-image img { border-radius: 50%; }

/* ---------- ภาพพื้นหลังการ์ดหน้าแรก (admin/settings) — สี่เหลี่ยม 16:9 แทนวงกลม ---------- */
.bg-dropzone { width: 160px; height: 90px; border-radius: var(--radius-sm); }
.bg-dropzone.has-image img { border-radius: var(--radius-sm); object-fit: cover; width: 100%; height: 100%; }

/* ---------- รูปประกอบขั้นตอน How to (admin/how_to_steps) — สี่เหลี่ยมขนาดใหญ่กว่า .achv-dropzone วงกลม ---------- */
.step-dropzone { width: 120px; height: 120px; border-radius: var(--radius-sm); flex-shrink: 0; font-size: 1.3rem; }
.step-dropzone:not(.has-image) { border-style: dashed; background: var(--surface-2); color: var(--muted); }
.step-dropzone.has-image img { border-radius: var(--radius-sm); object-fit: cover; width: 100%; height: 100%; }

/* ---------- รูปโปรไฟล์ผู้ใช้ (account/profile) — วงกลมขนาดใหญ่ สืบท็อดสไตล์จาก .dropzone ฐาน ---------- */
.profile-avatar-row { display: flex; align-items: center; gap: 1.2rem; margin-bottom: 1.4rem; }
.profile-avatar-dropzone {
    width: 108px; height: 108px; border-radius: 50%; flex-shrink: 0;
    font-size: 1rem; color: var(--primary-dark); background: var(--accent-soft);
}
.profile-avatar-dropzone:not(.has-image) { border-style: dashed; background: var(--surface-2); color: var(--muted); }
.profile-avatar-dropzone .dropzone-text { display: flex; flex-direction: column; align-items: center; gap: .2rem; font-size: .78rem; }
.profile-avatar-info { display: flex; flex-direction: column; gap: .55rem; }
.profile-avatar-info form { margin: 0; }

/* ---------- Modal ฟอร์มทั่วไป (เช่น "เพิ่มตราสัญลักษณ์") — เปิด/ปิดด้วย classList.toggle('is-open') จาก inline onclick ---------- */
.modal-overlay {
    display: none; position: fixed; inset: 0; z-index: 2000; background: rgba(0, 0, 0, .55);
    align-items: center; justify-content: center; padding: 2rem;
}
.modal-overlay.is-open { display: flex; animation: lightbox-fade .18s ease forwards; }
.modal-card {
    background: var(--surface); border-radius: var(--radius); box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
    width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto; padding: 1.6rem;
    position: relative;
}
.modal-card h3 { margin: 0 0 1rem; font-family: var(--serif); color: var(--primary-dark); }
.modal-close {
    position: absolute; top: .9rem; right: 1rem; background: none; border: none; color: var(--muted);
    font-size: 1.6rem; line-height: 1; cursor: pointer; padding: 0;
}
.modal-close:hover { color: var(--text); }

/* ---------- Confirm/Alert modal (แทน native confirm()/alert()) — เปิดปิดผ่าน JS showConfirmModal()/showAlertModal() ---------- */
.confirm-overlay {
    display: flex; position: fixed; inset: 0; z-index: 3000; background: rgba(0, 0, 0, 0);
    align-items: center; justify-content: center; padding: 1.4rem;
    opacity: 0; pointer-events: none; transition: opacity .18s ease, background .18s ease;
}
.confirm-overlay.is-open { opacity: 1; pointer-events: auto; background: rgba(0, 0, 0, .55); }
.confirm-card {
    background: var(--surface); border-radius: var(--radius); box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
    width: 100%; max-width: 380px; padding: 1.7rem 1.6rem; text-align: center;
    transform: translateY(10px) scale(.97); transition: transform .18s ease;
}
.confirm-overlay.is-open .confirm-card { transform: translateY(0) scale(1); }
.confirm-icon {
    width: 52px; height: 52px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
    margin: 0 auto .9rem; font-size: 1.35rem; background: var(--accent-soft); color: var(--primary-dark);
}
.confirm-overlay.is-danger .confirm-icon { background: #f6e0da; color: var(--danger); }
[data-theme="dark"] .confirm-overlay.is-danger .confirm-icon { background: rgba(179, 64, 47, .22); }
.confirm-title { margin: 0 0 .5rem; font-family: var(--serif); font-size: 1.15rem; color: var(--primary-dark); }
.confirm-message { margin: 0 0 1.3rem; color: var(--text-soft); font-size: .95rem; line-height: 1.55; white-space: pre-line; }
.confirm-actions { display: flex; gap: .7rem; }
.confirm-actions .btn { flex: 1; }

/* ---------- ชมรมเลิกอบายมุข (/recovery) — sobriety counter การ์ด ---------- */
.recovery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1.2rem; }
.recovery-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.4rem; display: flex; flex-direction: column; gap: .8rem; overflow: hidden; }
.recovery-card-cover { width: calc(100% + 2.8rem); margin: -1.4rem -1.4rem 0; aspect-ratio: 16 / 7; object-fit: cover; display: block; }
.recovery-card-head { display: flex; align-items: flex-start; gap: .8rem; }
.recovery-member-count { margin-top: .4rem; }
.recovery-card-head strong { font-family: var(--serif); font-size: 1.05rem; color: var(--text); }
.streak-counter { text-align: center; padding: 1rem 0; }
.streak-num { font-family: var(--serif); font-size: 3rem; color: var(--primary); line-height: 1; }
.streak-lbl { color: var(--muted); font-size: .85rem; margin-top: .3rem; }
.recovery-encourage { text-align: center; margin: -.4rem 0 0; }
.milestone-row { display: flex; flex-wrap: wrap; gap: .4rem; justify-content: center; }
.milestone-chip {
    font-size: .78rem; padding: .25rem .65rem; border-radius: 20px; border: 1px solid var(--border);
    color: var(--muted); background: var(--surface-2); display: inline-flex; align-items: center; gap: .3rem;
}
.milestone-chip.is-reached { color: var(--primary-dark); background: var(--accent-soft); border-color: transparent; font-weight: 600; }
.recovery-actions { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; margin-top: .3rem; }

/* ---------- คู่มือ How to (/how-to) — การ์ดกริด + ลำดับขั้นตอนแนวตั้ง ---------- */
.howto-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.2rem; }
@media (max-width: 900px) { .howto-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px) { .howto-grid { grid-template-columns: 1fr; } }
.howto-card {
    display: block; border-radius: var(--radius); overflow: hidden; background: var(--surface);
    box-shadow: var(--shadow); transition: transform .15s, box-shadow .15s; text-decoration: none; color: inherit;
}
.howto-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.howto-card-cover { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; display: block; background: var(--surface-2); }
.howto-card-cover-fallback { display: grid; place-items: center; font-size: 2rem; color: var(--muted); }
.howto-card-body { padding: 1rem 1.1rem 1.2rem; }
.howto-card-body h3 { margin: .5rem 0 .3rem; font-family: var(--serif); font-size: 1.1rem; }

.howto-hero { display: flex; align-items: center; gap: 2rem; padding: 2rem 0 2rem; }
.howto-hero-text { flex: 1; min-width: 0; }
.howto-hero-text .tag { margin-bottom: .7rem; }
.howto-hero-text h1 { font-size: 1.9rem; margin: 0 0 .6rem; }
.howto-hero-text p.muted { margin: 0; }
.howto-cover {
    width: 300px; height: 210px; flex-shrink: 0; object-fit: cover;
    border-radius: var(--radius); box-shadow: var(--shadow);
}
@media (max-width: 720px) {
    .howto-hero { flex-direction: column-reverse; padding: 1.4rem 0; gap: 1.2rem; }
    .howto-cover { width: 100%; height: 200px; }
}
.howto-steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 1.3rem; }
.howto-step { display: flex; gap: 1.1rem; padding-bottom: 1.3rem; position: relative; }
.howto-step::before {
    content: ''; position: absolute; left: 21px; top: 44px; bottom: 0; width: 2px; background: var(--border);
}
.howto-step:last-child::before { display: none; }
.howto-step:last-child { padding-bottom: 0; }
.howto-step-num {
    flex-shrink: 0; width: 44px; height: 44px; border-radius: 50%; background: var(--primary); color: #fff;
    display: grid; place-items: center; font-family: var(--serif); font-size: 1.2rem; z-index: 1;
}
.howto-step-body {
    flex: 1; min-width: 0; display: flex; flex-wrap: wrap; gap: 1.2rem; align-items: flex-start;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 1.1rem 1.3rem; box-shadow: var(--shadow);
}
.howto-step-body img {
    flex-shrink: 0; width: 220px; max-width: 100%; aspect-ratio: 3 / 2; object-fit: cover;
    border-radius: var(--radius-sm); cursor: zoom-in; display: block;
}
.howto-step-text { flex: 1; min-width: 200px; }
.howto-step-body h3 { margin: 0 0 .5rem; font-family: var(--serif); }
.howto-step-body p { color: var(--text-soft); line-height: 1.7; margin: 0; }
