/* =========================================================================
   นิมิตร — สวดมนต์
   Design tokens: โทน "วัดยามค่ำ" — ไม้เข้มอมทอง แสงเทียน หมึกทอง
   Signature: สัญลักษณ์คั่นบทแบบใบลานไทย (๏ ฟองมัน / ๛ โคมูตร)
   ========================================================================= */

:root {
  /* --- สี --- */
  --bg: #15110c;
  --panel: #221a12;
  --panel-2: #2a2117;
  --border: #3b2e1d;
  --gold: #c9992f;
  --gold-bright: #efc868;
  --ink: #f3e9d8;
  --ink-muted: #b2a68f;
  --lacquer: #9a3f3f;

  /* --- โหมด (มือถือ / แท็บเล็ต+พีซี) จะสลับตัวแปรนี้ผ่าน body class --- */
  --content-max: 640px;
  --font-size-content: 32px;
  --space-page: 20px;

  /* --- ตัวอักษร --- */
  --font-display: "Noto Serif Thai", "Sarabun", serif;
  --font-body: "Sarabun", "Noto Sans Thai", sans-serif;

  --radius: 14px;
  --radius-sm: 8px;
}

body.mode-desktop {
  --content-max: 760px;
  --space-page: 32px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.7;
  min-height: 100vh;
  background-image:
    radial-gradient(ellipse 900px 500px at 50% -10%, rgba(201, 153, 47, 0.14), transparent 60%);
  background-repeat: no-repeat;
}

body.theme-light {
  --bg: #f6f0e2;
  --panel: #fffdf8;
  --panel-2: #f1e8d4;
  --border: #e2d3ab;
  --ink: #2c2114;
  --ink-muted: #6b5d45;
}

h1,
h2,
h3,
.font-display {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--ink);
  margin: 0;
}

a {
  color: inherit;
}

button {
  font-family: inherit;
}

.wrap {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--space-page);
}
/* กันเนื้อหาโดนบังจากแถบล่างแบบ fixed (reader-bottombar / home-bottombar) */
.wrap.page-body,
#content-wrap {
  padding-bottom: 84px;
}

/* --- แถบบนสุด --- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px var(--space-page);
  background: rgba(21, 17, 12, 0.86);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
body.theme-light .topbar {
  background: rgba(246, 240, 226, 0.9);
}

.topbar .title {
  font-family: var(--font-display);
  font-size: 1.05rem;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ปุ่มกลมทองมาตรฐาน — ใช้ร่วมกันทุกหน้า (index.php: gear-btn / prayer.php: icon-btn) */
/* v18: บังคับ border-radius ที่ตัว img ตรงๆ ด้วย (ไม่พึ่ง overflow:hidden ของปุ่มแม่อย่างเดียว กันหลุดวงกลม) */
.icon-btn img,
.gear-btn img,
.lotus-fab img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 999px;
  display: block;
  pointer-events: none;
}
.nav-drawer-fab img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 0 14px 14px 0;
  display: block;
  pointer-events: none;
}
.icon-btn,
.gear-btn,
.nav-drawer-fab,
.lotus-fab {
  overflow: hidden;
  padding: 0;
}
.icon-btn,
.gear-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  border: 1px solid var(--gold-bright);
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  color: #ffffff;
  cursor: pointer;
  flex-shrink: 0;
  text-decoration: none;
  font-size: 1.2rem;
  box-shadow: 0 4px 12px rgba(201, 153, 47, 0.35);
  transition: filter 0.15s ease, transform 0.15s ease;
}
.icon-btn:hover,
.gear-btn:hover {
  filter: brightness(1.05);
}
.icon-btn:active,
.gear-btn:active {
  transform: scale(0.94);
}
.icon-btn:focus-visible,
button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 2px solid var(--gold-bright);
  outline-offset: 2px;
}

/* --- สัญลักษณ์คั่นบทแบบใบลาน (signature element) --- */
.thai-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin: 28px 0;
  color: var(--gold);
  user-select: none;
}
.thai-divider::before,
.thai-divider::after {
  content: "";
  height: 1px;
  flex: 1;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
}
.thai-divider span {
  font-size: 1.4rem;
  animation: flicker 4.5s ease-in-out infinite;
}
@media (prefers-reduced-motion: reduce) {
  .thai-divider span {
    animation: none;
  }
}
@keyframes flicker {
  0%, 100% { opacity: 0.85; text-shadow: 0 0 6px rgba(239, 200, 104, 0.25); }
  45% { opacity: 1; text-shadow: 0 0 12px rgba(239, 200, 104, 0.5); }
  60% { opacity: 0.8; text-shadow: 0 0 4px rgba(239, 200, 104, 0.2); }
}

/* --- การ์ด / รายการ --- */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.list-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 6px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s ease;
  text-decoration: none;
  color: inherit;
}
.list-item:hover {
  background: var(--panel);
}
.list-item .num {
  font-family: var(--font-display);
  color: var(--gold);
  min-width: 28px;
  text-align: center;
  font-size: 1.05rem;
}
.list-item .meta {
  flex: 1;
  min-width: 0;
}
.list-item .meta .t {
  font-size: 1rem;
  color: var(--ink);
}
.list-item .meta .n {
  font-size: 0.82rem;
  color: var(--ink-muted);
  margin-top: 2px;
}
.list-item .chev {
  color: var(--ink-muted);
  flex-shrink: 0;
}

/* --- ปุ่ม --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 999px;
  border: 1px solid var(--gold-bright);
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  color: #ffffff;
  font-size: 0.95rem;
  font-weight: 700;
  padding: 12px 20px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(201, 153, 47, 0.35);
  transition: transform 0.12s ease, filter 0.15s ease, box-shadow 0.15s ease;
}
.btn:hover {
  filter: brightness(1.05);
}
.btn:active {
  transform: scale(0.97);
}
.btn-gold {
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  border-color: var(--gold-bright);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(201, 153, 47, 0.35);
}
.btn-gold:hover {
  filter: brightness(1.05);
}
.btn-block {
  width: 100%;
}
.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

/* --- input --- */
.field {
  display: block;
  width: 100%;
}
.field label {
  display: block;
  font-size: 0.85rem;
  color: var(--ink-muted);
  margin-bottom: 6px;
}
.field input[type="text"],
.field input[type="search"] {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--ink);
  padding: 12px 14px;
  font-size: 1rem;
  font-family: inherit;
}
.field input:focus {
  border-color: var(--gold);
}

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 4px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.checkbox-row input {
  margin-top: 3px;
  width: 20px;
  height: 20px;
  accent-color: var(--gold);
  flex-shrink: 0;
}
.checkbox-row .meta {
  flex: 1;
}
.checkbox-row .order-badge {
  font-size: 0.8rem;
  color: var(--gold);
  margin-top: 2px;
}

/* --- toolbar ล่างในหน้าอ่าน --- */
.reader-toolbar {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px var(--space-page);
  background: rgba(21, 17, 12, 0.9);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
}
body.theme-light .reader-toolbar {
  background: rgba(246, 240, 226, 0.92);
}

.round-counter {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 auto;
}
.round-counter .count {
  min-width: 64px;
  text-align: center;
  font-family: var(--font-display);
}
.round-counter .count .n {
  font-size: 1.6rem;
  color: var(--gold-bright);
  display: block;
  line-height: 1;
}
.round-counter .count .lbl {
  font-size: 0.7rem;
  color: var(--ink-muted);
}
.round-btn {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 1px solid var(--gold-bright);
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  color: #ffffff;
  font-size: 1.3rem;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(201, 153, 47, 0.35);
  transition: filter 0.15s ease, transform 0.15s ease;
}
.round-btn:hover {
  filter: brightness(1.05);
}
.round-btn:active {
  transform: scale(0.92);
}

/* --- ปรับขนาดตัวอักษร / สลับธีม (เมนูลอย) --- */
.settings-panel {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 76px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  border-left: none;
  border-right: none;
  border-bottom: none;
  border-radius: 16px 16px 0 0;
  padding: 16px var(--space-page) 18px;
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.35);
  display: none;
  z-index: 20;
  max-height: 60vh;
  overflow-y: auto;
}
.settings-panel::before {
  content: "";
  display: block;
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: var(--border);
  margin: 0 auto 14px;
}
.settings-panel.open {
  display: block;
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
}
.settings-row .lbl {
  font-size: 0.9rem;
  color: var(--ink-muted);
}
.stepper {
  display: flex;
  align-items: center;
  gap: 10px;
}
.stepper button {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: 1px solid var(--gold-bright);
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  color: #ffffff;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(201, 153, 47, 0.35);
}
.theme-toggle {
  display: flex;
  gap: 8px;
}
.theme-toggle button {
  border: 1px solid var(--gold);
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  color: #ffffff;
  border-radius: 999px;
  padding: 9px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  opacity: 0.6;
}
.theme-toggle button.active {
  opacity: 1;
  border-color: var(--gold-bright);
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(201, 153, 47, 0.35);
}

.autoscroll-toggle {
  width: 46px;
  height: 26px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
}
.autoscroll-toggle::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--ink-muted);
  transition: transform 0.18s ease, background 0.18s ease;
}
.autoscroll-toggle.on {
  border-color: var(--gold);
}
.autoscroll-toggle.on::after {
  transform: translateX(20px);
  background: var(--gold-bright);
}

.speed-slider {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 130px;
}
.speed-slider input[type="range"] {
  flex: 1;
  accent-color: var(--gold);
}
.speed-slider .speed-icon {
  font-size: 0.9rem;
  color: var(--ink-muted);
}

/* --- เนื้อหาบทสวด --- */
.prayer-title {
  font-size: calc(var(--font-size-content) * 1.25);
  color: var(--gold-bright);
  text-align: center;
  margin-bottom: 4px;
}
.prayer-note {
  text-align: center;
  color: var(--ink-muted);
  font-size: calc(var(--font-size-content) * 0.75);
  margin-bottom: 8px;
}
.section-subtitle {
  color: var(--gold);
  font-family: var(--font-display);
  font-size: var(--font-size-content);
  margin: 22px 0 10px;
}
.paragraph {
  margin: 0 0 14px;
  font-size: var(--font-size-content);
  line-height: 1.85;
}
.prayer-rich-content {
  font-size: var(--font-size-content);
  line-height: 1.85;
}
.prayer-rich-content p {
  margin: 0 0 14px;
}
.prayer-rich-content p:last-child {
  margin-bottom: 0;
}
.prayer-rich-content strong { color: var(--gold-bright); }
.prayer-rich-content .ql-align-center { text-align: center; }
.prayer-rich-content .ql-align-right { text-align: right; }

/* --- empty state --- */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--ink-muted);
}
.empty-state .glyph {
  font-size: 2.2rem;
  color: var(--gold);
  display: block;
  margin-bottom: 12px;
}

.center-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  text-align: center;
  gap: 22px;
  padding: 24px;
}

.hidden {
  display: none !important;
}

/* --- แถบเมนูล่าง --- */
.bottom-nav {
  position: relative;
  display: flex;
  border-radius: 16px 16px 0 0;
  background: rgba(21, 17, 12, 0.92);
  backdrop-filter: blur(8px);
  box-shadow: 0 -4px 14px rgba(43, 30, 10, 0.1);
  padding-top: 6px;
  transition: border-radius 0.2s ease, box-shadow 0.2s ease;
}
/* v3: row1/bottom-nav อยู่บนสุดของ sheet เสมอ (radius+shadow คงไว้ตลอด ไม่ต้องสลับตาม .drawer-open) */
.bottom-nav::before {
  content: "";
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.5);
}
body.theme-light .bottom-nav {
  background: linear-gradient(180deg, #e6bf6c, #c08c2e);
}
.bottom-nav a {
  flex: 1;
  text-align: center;
  padding: 12px 8px 14px;
  text-decoration: none;
  color: rgba(255, 255, 255, 0.75);
  font-size: 0.78rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.bottom-nav a .ic {
  font-size: 1.3rem;
}
.bottom-nav a.active {
  color: #ffffff;
  font-weight: 700;
}

.page-body {
  min-height: calc(100vh - 130px);
  padding-bottom: 8px;
}

.search-box {
  margin: 4px 0 10px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--ink);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.88rem;
  box-shadow: 0 8px 20px rgba(0,0,0,0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 40;
  white-space: nowrap;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(-4px);
}

/* --- พื้นที่โฆษณา --- */
.ad-slot {
  margin: 24px 0 8px;
  padding: 10px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  text-align: center;
  overflow: hidden;
}
.ad-slot .ad-label {
  font-size: 0.68rem;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
}

/* --- ตั้งค่าจำนวนจบก่อนเริ่มสวด --- */
.rounds-setup {
  text-align: center;
  padding: 10px 0 6px;
}
.rounds-setup .lbl {
  color: var(--ink-muted);
  font-size: 0.9rem;
  margin-bottom: 10px;
}
.rounds-setup .stepper-big {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  margin-bottom: 18px;
}
.rounds-setup .stepper-big .n {
  font-family: var(--font-display);
  font-size: 2.2rem;
  color: var(--gold-bright);
  min-width: 60px;
}
.rounds-progress {
  text-align: center;
  color: var(--ink-muted);
  font-size: 0.85rem;
  margin-top: 4px;
}
.rounds-done {
  text-align: center;
  padding: 30px 16px;
}
.rounds-done .glyph {
  font-size: 2.4rem;
  color: var(--gold);
  display: block;
  margin-bottom: 10px;
}

/* =========================================================================
   สุขใจ Sukjai — ส่วนต่อขยาย UI ใหม่
   ========================================================================= */

/* --- หน้า Splash เลือกโหมด --- */
.splash-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  text-align: center;
  gap: 20px;
  padding: 32px 24px;
}
.splash-logo {
  width: 160px;
  height: 160px;
  object-fit: contain;
}
.splash-title {
  font-size: 2rem;
  color: var(--gold);
  line-height: 1.25;
}
.splash-title .en {
  display: block;
  font-size: 1.3rem;
  color: var(--gold-bright);
}
.splash-sub {
  color: var(--ink-muted);
  font-size: 0.9rem;
}
.mode-choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  width: 100%;
  max-width: 520px;
}
@media (max-width: 480px) {
  .mode-choices { grid-template-columns: 1fr; }
}
.mode-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 18px;
  cursor: pointer;
  text-align: center;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.mode-card:hover {
  border-color: var(--gold);
  transform: translateY(-2px);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.12);
}
.mode-card .glyph {
  font-size: 2.4rem;
  color: var(--gold);
  display: block;
  margin-bottom: 14px;
}
.mode-card .glyph img {
  width: 56px;
  height: 56px;
  object-fit: contain;
  margin: 0 auto;
}
.mode-card h2 {
  font-size: 1.05rem;
  margin-bottom: 6px;
}
.mode-card p {
  color: var(--ink-muted);
  font-size: 0.85rem;
  margin: 0;
}
.splash-footnote {
  color: var(--ink-muted);
  font-size: 0.8rem;
}

/* --- แถบบนหน้ารายการ (index) --- */
.home-topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px var(--space-page);
  background: rgba(246, 240, 226, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
body:not(.theme-light) .home-topbar {
  background: rgba(21, 17, 12, 0.88);
}
.home-topbar .back-link {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--gold);
  text-decoration: none;
  font-size: 0.95rem;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
}
.home-brand {
  text-align: center;
  padding: 22px 20px 6px;
}
.home-brand .splash-logo {
  width: 160px;
  height: 160px;
  margin-bottom: 6px;
}
.home-brand .splash-title {
  font-size: 1.5rem;
}
.home-brand .splash-title .en {
  font-size: 1rem;
}

/* --- ลิ้นชักรายการบทสวดทั้งหมด (nav drawer) --- */
.nav-drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 45;
  display: none;
}
.nav-drawer-overlay.open {
  display: block;
}
.nav-drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(86vw, 340px);
  background: var(--panel);
  z-index: 46;
  transform: translateX(-100%);
  transition: transform 0.22s ease;
  display: flex;
  flex-direction: column;
  box-shadow: 8px 0 24px rgba(0, 0, 0, 0.25);
}
.nav-drawer.open {
  transform: translateX(0);
}
.nav-drawer-tabs {
  display: flex;
  gap: 8px;
  padding: 14px 14px 10px;
}
.nav-drawer-tabs button {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--ink-muted);
  border-radius: 999px;
  padding: 10px 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.nav-drawer-tabs button.active {
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  color: #221708;
  border-color: var(--gold);
}
.nav-drawer-search {
  padding: 0 14px 10px;
  display: flex;
  gap: 8px;
}
.nav-drawer-search input {
  flex: 1;
  min-width: 0;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--ink);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 0.9rem;
}
.nav-drawer-search select {
  flex-shrink: 0;
  width: 110px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--ink);
  padding: 10px 8px;
  font-family: inherit;
  font-size: 0.85rem;
}
.nav-drawer-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 6px 20px;
}
.nav-drawer-category {
  color: var(--gold);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 14px 12px 6px;
}
.nav-drawer-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--ink);
  font-size: 0.92rem;
  cursor: pointer;
}
.nav-drawer-item:hover {
  background: var(--panel-2);
}
.nav-drawer-item .del {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--lacquer);
  cursor: pointer;
  font-size: 1rem;
  padding: 4px;
}
.nav-drawer-empty {
  text-align: center;
  color: var(--ink-muted);
  font-size: 0.85rem;
  padding: 30px 20px;
}
.nav-drawer-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--ink);
  cursor: pointer;
}

.home-bottombar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  flex-direction: column; /* v3: bottom-nav บนสุดของ sheet เสมอ, bb-row2 ขยายด้านล่าง */
}
.home-bottombar .bottom-nav {
  position: static;
}
.category-pills {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 4px 0 16px;
}
.category-pills::-webkit-scrollbar { display: none; }
.cat-pill {
  flex-shrink: 0;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--gold);
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  color: #ffffff;
  font-size: 0.85rem;
  text-decoration: none;
  white-space: nowrap;
  opacity: 0.6;
}
.cat-pill.active {
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  color: #ffffff;
  border-color: var(--gold-bright);
  font-weight: 700;
  opacity: 1;
  box-shadow: 0 4px 12px rgba(201, 153, 47, 0.35);
}

/* --- แถบล่างหน้าอ่าน (bottom bar v2) --- */
.reader-bottombar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  flex-direction: column; /* v3: bb-row1 บนสุดของ sheet เสมอ, bb-row2 ขยายด้านล่าง */
}
.bb-row1 {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px var(--space-page) 10px;
  background: linear-gradient(180deg, #e6bf6c, #c08c2e);
  box-shadow: 0 -4px 14px rgba(43, 30, 10, 0.25);
  border-radius: 16px 16px 0 0;
  overflow-x: auto;
  scrollbar-width: none;
  position: relative;
}
.bb-row1::before {
  content: "";
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.5);
}
/* v3: bb-row1 อยู่บนสุดของ sheet เสมอ (radius+shadow คงไว้ตลอด) */
body:not(.theme-light) .bb-row1 {
  background: rgba(21, 17, 12, 0.94);
}
.bb-row1::-webkit-scrollbar { display: none; }
.bb-round {
  flex-shrink: 0;
  text-align: center;
  font-family: var(--font-display);
  padding-right: 8px;
  border-right: 1px solid rgba(255, 255, 255, 0.35);
}
.bb-round .n {
  display: block;
  font-size: 1rem;
  color: #ffffff;
  line-height: 1.1;
}
.bb-round .lbl {
  font-size: 0.65rem;
  color: rgba(255, 255, 255, 0.85);
}
.bb-finish {
  flex-shrink: 0;
  white-space: nowrap;
  padding: 10px 16px;
  font-size: 0.88rem;
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  border: 1px solid var(--gold-bright);
  color: #ffffff;
  font-weight: 700;
}
.speed-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.speed-controls button {
  flex-shrink: 0;
  border: 1px solid var(--gold);
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  color: #ffffff;
  border-radius: 999px;
  padding: 9px 14px;
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  opacity: 0.6;
}
.speed-controls button.active {
  border-color: var(--gold-bright);
  font-weight: 700;
  opacity: 1;
  box-shadow: 0 4px 12px rgba(201, 153, 47, 0.35);
}
.speed-controls button.restart-btn {
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  color: #ffffff;
  opacity: 0.7;
}
.speed-cycle-btn {
  min-width: 88px;
  text-align: center;
}

.nav-drawer-fab {
  position: fixed;
  left: 0;
  top: 76px;
  transform: none;
  width: 50px;
  height: 50px;
  border-radius: 0 14px 14px 0;
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  color: #ffffff;
  border: none;
  border-left: none;
  display: grid;
  place-items: center;
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: 2px 4px 12px rgba(201, 153, 47, 0.35);
  z-index: 48;
  transition: transform 0.22s ease; /* v2: เลื่อนตามลิ้นชักตอนเปิด */
}

.lotus-fab {
  position: fixed;
  right: 14px;
  bottom: 50px;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  color: #221708;
  border: 3px solid var(--bg);
  display: grid;
  place-items: center;
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(201, 153, 47, 0.35);
  z-index: 22;
  transition: bottom 0.25s ease;
}

/* v3: bb-row2 อยู่ใน flow ปกติ ใต้ bb-row1/bottom-nav เสมอ (column ปกติ) ไม่ใช่ขอบบนของ sheet
   จึงไม่มี radius/shadow ด้านบน (พื้นหลัง gradient เดียวกับ row1 เลยดูต่อเนื่อง ไม่มีรอยต่อ) */
.bb-row2 {
  background: linear-gradient(180deg, #e6bf6c, #c08c2e);
  border-radius: 0;
  padding: 0 var(--space-page) 0;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.25s ease;
}
body:not(.theme-light) .bb-row2 {
  background: rgba(21, 17, 12, 0.96);
}
.bb-row2.open {
  max-height: 70vh;
  overflow-y: auto;
  padding: 14px var(--space-page) 14px;
}
.bb-settings-row {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  padding-bottom: 12px;
}
.font-stepper {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 999px;
  padding: 4px 6px;
}
.font-stepper button {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid var(--gold-bright);
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  color: #ffffff;
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 4px 12px rgba(201, 153, 47, 0.35);
}
.font-stepper .n {
  min-width: 28px;
  text-align: center;
  font-family: var(--font-display);
  color: #ffffff;
}
.theme-pill-toggle {
  display: flex;
  gap: 8px;
}
.theme-pill-toggle button {
  border: 1px solid var(--gold);
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  color: #ffffff;
  border-radius: 999px;
  padding: 9px 16px;
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  opacity: 0.6;
}
.theme-pill-toggle button.active {
  border-color: var(--gold-bright);
  opacity: 1;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(201, 153, 47, 0.35);
}
.choose-font-btn {
  border: 1px solid var(--gold-bright);
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  color: #ffffff;
  border-radius: 999px;
  padding: 9px 16px;
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
}

/* --- ตัวเลือกฟอนต์ (font picker overlay) --- */
.font-picker-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 60;
  display: none;
  align-items: flex-end;
  justify-content: center;
}
.font-picker-overlay.open {
  display: flex;
}
.font-picker-sheet {
  background: var(--panel);
  width: 100%;
  max-width: 520px;
  max-height: 74vh;
  border-radius: 18px 18px 0 0;
  padding: 16px;
  display: flex;
  flex-direction: column;
}
.font-picker-sheet h3 {
  text-align: center;
  margin-bottom: 12px;
}
.font-picker-sheet input[type="search"] {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--ink);
  padding: 10px 12px;
  font-family: inherit;
  margin-bottom: 10px;
}
.font-picker-list {
  overflow-y: auto;
  flex: 1;
}
.font-picker-item {
  padding: 13px 10px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.font-picker-item.active {
  color: var(--gold-bright);
}

/* --- ADS ในแถบตั้งค่า --- */
.settings-ad-slot {
  margin-top: 4px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  text-align: center;
}
.settings-ad-slot .ad-label {
  font-size: 0.65rem;
  color: rgba(255, 255, 255, 0.75);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 4px 0;
}
/* v2: บังคับให้โค้ดโฆษณา (iframe/div ของ AdSense) อยู่กึ่งกลางจริง */
.settings-ad-slot > *:not(.ad-label) {
  display: inline-block !important;
}

/* --- Footer ทุกหน้า (affiliate carousel + brand line) --- */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 18px var(--space-page) 90px;
  text-align: center;
}
/* v9: กล่อง Ads ที่ footer (แสดงตลอด ไม่ต้องเปิดลิ้นชักตั้งค่า) */
.footer-ads {
  padding: 16px var(--space-page) 4px;
  text-align: center;
}
.footer-ads .settings-ad-slot .ad-label {
  color: var(--ink-muted); /* พื้นหลังหน้าเว็บปกติสว่าง ใช้สีเข้มแทนสีขาวของในลิ้นชัก */
}
.footer-ads .affiliate-carousel { margin-bottom: 14px; }
/* v11: caption กลับไปอยู่ใต้ภาพแบบเดิม (ไม่ overlay ทับภาพแล้ว) ยังคง fade ทีละใบเหมือนเดิม */
.affiliate-carousel {
  position: relative;
  width: min(88vw, 420px);
  min-height: calc(min(88vw, 420px) / 3 + 34px); /* ความสูงภาพ (3:1) + พื้นที่ caption 1 บรรทัด */
  margin: 0 auto;
}
.affiliate-slide {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 0.9s ease;
  pointer-events: none;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  overflow: hidden;
  text-decoration: none;
  display: block;
  background: var(--panel);
}
.affiliate-slide.is-active {
  opacity: 1;
  pointer-events: auto;
}
.affiliate-slide img {
  width: 100%;
  aspect-ratio: 3 / 1;
  object-fit: cover;
  display: block;
}
.affiliate-slide .cap {
  font-size: 0.78rem;
  color: var(--ink-muted);
  padding: 6px 10px;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bb-row2 .affiliate-carousel {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.25);
}
.bb-row2 .affiliate-slide {
  border-color: rgba(255, 255, 255, 0.4);
  background: rgba(255, 255, 255, 0.92);
}
.site-footer .brand-line {
  color: var(--ink-muted);
  font-size: 0.78rem;
  margin-top: 10px;
}
.site-footer .app-version {
  opacity: 0.7;
}

/* Admin: preview + slides list */
.img-preview {
  max-width: 120px;
  max-height: 120px;
  border-radius: 8px;
  border: 1px solid var(--a-border, var(--border));
  display: block;
  margin-top: 8px;
}
.slide-row {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--a-border, var(--border));
}
.slide-row img {
  width: 72px;
  height: 48px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
}
.slide-row .meta { flex: 1; min-width: 0; font-size: 0.85rem; }
.slide-row .meta .cap-t { color: var(--a-ink, var(--ink)); }
.slide-row .meta .cap-l { color: var(--a-ink-muted, var(--ink-muted)); font-size: 0.78rem; word-break: break-all; }

