/* ==========================================================================
   CSS ระบบเปิดอ่านหนังสือบุด: กลไก 3D Accordion Hinge เสมือนจริงทางกายภาพ
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Charm:wght@400;700&family=Sarabun:wght@300;400;500;600;700&family=Cinzel:wght@600&display=swap');

:root {
  --desk-bg: radial-gradient(ellipse at 50% 42%, #261f18 0%, #0d0b09 100%);
  --panel-bg: rgba(20, 17, 14, 0.96);
  --panel-border: #443727;
  --gold-accent: #dfc26a;
  --gold-glow: rgba(223, 194, 106, 0.25);
  --shadow-heavy: rgba(0, 0, 0, 0.85);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Sarabun', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: #080706;
  color: #e6dfd1;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
}

/* Custom Webkit Scrollbar */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-track {
  background: #14100c;
}
::-webkit-scrollbar-thumb {
  background: #54432c;
  border-radius: 5px;
  border: 2px solid #14100c;
}
::-webkit-scrollbar-thumb:hover {
  background: #dfc26a;
}

/* ==========================================================================
   Header & Toolbar
   ========================================================================== */
header.app-header {
  background: linear-gradient(180deg, rgba(14, 12, 10, 0.98) 0%, rgba(22, 18, 15, 0.94) 100%);
  border-bottom: 1px solid var(--panel-border);
  padding: 8px 20px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  z-index: 100;
  flex-shrink: 0;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.5);
}

.brand-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  background: #2b2216;
  border: 1px solid #7d6a45;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Charm', serif;
  font-weight: bold;
  font-size: 20px;
  color: var(--gold-accent);
}

.brand-text h1 {
  font-size: 1.05rem;
  font-weight: 700;
  color: #f0e6cf;
}

.brand-text p {
  font-size: 0.73rem;
  color: #a89c89;
}

.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.btn-group {
  display: inline-flex;
  align-items: center;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  overflow: hidden;
}

.btn-group .btn {
  border: none;
  border-radius: 0;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  background: transparent;
}

/* ==========================================================================
   Bookshelf Modal & Cards (MySQL Integration)
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  backdrop-filter: blur(5px);
}

.modal-card {
  background: #15110d;
  border: 1px solid #54432c;
  border-radius: 10px;
  width: 90%;
  max-width: 780px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 35px rgba(0,0,0,0.85);
  overflow: hidden;
  animation: fadeInModal 0.25s ease;
}

@keyframes fadeInModal {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.modal-header {
  padding: 16px 20px;
  background: #1f1812;
  border-bottom: 1px solid #3d2f1f;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  margin: 0;
  color: #dfc26a;
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.bookshelf-grid {
  padding: 22px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.book-card {
  background: #1c1611;
  border: 1px solid #4a3a25;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
}

.book-card:hover {
  border-color: #dfc26a;
  transform: translateY(-3px);
  box-shadow: 0 6px 16px rgba(223, 194, 106, 0.25);
}

.book-card-thumb {
  height: 120px;
  background: #080808;
  overflow: hidden;
}

.book-card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.book-card-body {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.book-card-title {
  font-weight: 600;
  color: #f5eedc;
  font-size: 0.95rem;
  line-height: 1.3;
}

.book-card-meta {
  font-size: 0.78rem;
  color: #a89c89;
}

/* ==========================================================================
   Upload Modal Popup Styles (เพิ่มเล่มใหม่แบบ Popup)
   ========================================================================== */
.upload-modal-card {
  max-width: 740px;
  width: 92%;
}

.modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  max-height: calc(85vh - 70px);
}

.upload-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.upload-form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.upload-form-group.full {
  grid-column: span 2;
}

.upload-form-group label {
  font-size: 0.85rem;
  color: #dfdbd3;
  font-weight: 500;
}

.upload-form-group label span.req {
  color: #e57373;
}

.upload-input, .upload-textarea {
  background: #1c1611;
  border: 1px solid #4a3a24;
  border-radius: 6px;
  padding: 8px 12px;
  color: #ffffff;
  font-size: 0.9rem;
  font-family: inherit;
  transition: all 0.2s;
}

.upload-input:focus, .upload-textarea:focus {
  outline: none;
  border-color: #dfc26a;
  box-shadow: 0 0 8px rgba(223, 194, 106, 0.35);
  background: #231b14;
}

.upload-dropzone {
  border: 2px dashed #6b5736;
  background: #19140f;
  border-radius: 8px;
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.upload-dropzone:hover, .upload-dropzone.dragover {
  border-color: #dfc26a;
  background: #251c14;
}

.dropzone-icon {
  color: #dfc26a;
  margin-bottom: 2px;
}

.dropzone-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: #f5eedc;
}

.dropzone-desc {
  font-size: 0.8rem;
  color: #9f9483;
}

.selected-file-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #2d2417;
  border: 1px solid #755b31;
  padding: 6px 14px;
  border-radius: 20px;
  color: #dfc26a;
  font-size: 0.86rem;
  margin-top: 6px;
}

.upload-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid #2d2317;
}

.btn-gold-submit {
  background: linear-gradient(135deg, #8a6c3e 0%, #5d4624 100%);
  color: #ffffff;
  border: 1px solid #b08d4b;
  padding: 10px 22px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
}

.btn-gold-submit:hover:not(:disabled) {
  background: linear-gradient(135deg, #a68551 0%, #745b34 100%);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(223, 194, 106, 0.3);
}

.btn-gold-submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.upload-spinner-state {
  text-align: center;
  padding: 40px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.pulse-spinner {
  width: 50px;
  height: 50px;
  border: 4px solid rgba(223, 194, 106, 0.2);
  border-top-color: #dfc26a;
  border-radius: 50%;
  animation: spinUpload 1s linear infinite;
}

@keyframes spinUpload {
  to { transform: rotate(360deg); }
}

.upload-result-state {
  padding: 30px 20px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.success-badge-icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: rgba(46, 125, 50, 0.25);
  border: 2px solid #4caf50;
  color: #81c784;
  display: flex;
  align-items: center;
  justify-content: center;
}

@media (max-width: 650px) {
  .upload-form-grid {
    grid-template-columns: 1fr;
  }
  .upload-form-group.full {
    grid-column: span 1;
  }
}

.btn {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--panel-border);
  color: #cfc5b0;
  padding: 5px 12px;
  font-size: 0.8rem;
  font-family: inherit;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.09);
  color: #ffffff;
}

.btn.active {
  background: #54442b;
  color: #fae7a5;
  border-color: #8f7447;
}

.btn-primary {
  background: linear-gradient(135deg, #745b34 0%, #4f3b1e 100%);
  border: 1px solid #9e814d;
  color: #fff2cb;
}
.btn-primary:hover {
  background: linear-gradient(135deg, #8a6c3e 0%, #5d4624 100%);
  color: #ffffff;
}

/* ==========================================================================
   Main Workspace
   ========================================================================== */
.main-container {
  display: flex;
  flex: 1;
  position: relative;
  overflow: hidden;
  height: calc(100vh - 58px);
}

.stage-area {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  background: var(--desk-bg);
  overflow: hidden;
  padding: 6px 16px 4px 16px;
}

/* ลายเสื่อและโต๊ะรองโบราณ */
.stage-area::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  opacity: 0.04;
  background-image: 
    repeating-linear-gradient(45deg, #ffffff 0, #ffffff 1px, transparent 0, transparent 24px),
    repeating-linear-gradient(-45deg, #ffffff 0, #ffffff 1px, transparent 0, transparent 24px);
  pointer-events: none;
}

/* ป้ายแสดงสถานะหน้า */
.status-pill {
  display: flex;
  gap: 12px;
  align-items: center;
  background: rgba(16, 13, 10, 0.94);
  backdrop-filter: blur(8px);
  padding: 4px 16px;
  border-radius: 20px;
  border: 1px solid #4a3e2e;
  z-index: 10;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}

/* ปุ่มลอยขยายเต็มจอ (Floating Fullscreen Button) */
.floating-fs-btn {
  position: absolute;
  top: 10px;
  right: 14px;
  background: rgba(22, 17, 13, 0.85);
  border: 1px solid #54432c;
  color: #dfc26a;
  border-radius: 8px;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 20;
  backdrop-filter: blur(6px);
  transition: all 0.2s ease;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}

.floating-fs-btn:hover {
  background: #34281c;
  border-color: #dfc26a;
  color: #ffffff;
  transform: scale(1.08);
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  color: #e5cf96;
}

.status-badge span.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #27ae60;
  box-shadow: 0 0 8px #27ae60;
}

/* ==========================================================================
   3D Stage: จำลองโต๊ะอ่านหนังสือบุด (Perspective Reading Desk)
   ========================================================================== */
.manuscript-3d-stage {
  perspective: 2000px;
  perspective-origin: 50% 46%;
  width: 100%;
  max-width: 860px;
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}

/* กรอบหนังสือบุด 3D (Accordion Book Container) */
.accordion-book-unit {
  position: relative;
  width: 100%;
  max-width: 820px;
  height: 416px;
  transform-style: preserve-3d;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

/* ==========================================================================
   1. เลเยอร์พื้นหลัง (Base Spread - รอรับการเปิดอยู่ด้านล่าง)
   ========================================================================== */
.base-spread-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  transform-style: preserve-3d;
  pointer-events: none;
  opacity: 0;
  z-index: 1;
}

.base-spread-layer.visible {
  opacity: 1;
}

/* ==========================================================================
   2. เลเยอร์ปัจจุบัน (Active Spread)
   ========================================================================== */
.active-spread-layer {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  transform-style: preserve-3d;
  z-index: 2;
}

/* แผ่นหน้าบน (Top Leaf) */
.leaf-top-surface {
  width: 100%;
  height: 202px;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  background-position: center;
  border-top-left-radius: 12px;
  border-top-right-radius: 12px;
  transform-origin: bottom center;
  transform: rotateX(12deg);
  box-shadow: 
    0 -6px 20px rgba(0, 0, 0, 0.6), 
    0 6px 25px rgba(0, 0, 0, 0.45),
    inset 0 1px 3px rgba(255, 255, 255, 0.12);
  position: relative;
  overflow: hidden;
}

/* สันรอยพับข่อยกึ่งกลาง (Center Accordion Crease Hinge) */
.center-crease-hinge {
  width: 100%;
  height: 12px;
  background: linear-gradient(180deg, 
    rgba(12,9,6,0.95) 0%, 
    rgba(42,32,20,0.95) 50%, 
    rgba(12,9,6,0.95) 100%
  );
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.85), inset 0 -2px 4px rgba(0,0,0,0.85);
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
}

.center-crease-hinge span {
  font-size: 0.65rem;
  color: #a89475;
  letter-spacing: 2px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.9);
}

/* แผ่นหน้าล่าง (Bottom Leaf) */
.leaf-bottom-surface {
  width: 100%;
  height: 202px;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  background-position: center;
  border-bottom-left-radius: 12px;
  border-bottom-right-radius: 12px;
  transform-origin: top center;
  transform: rotateX(-8deg);
  box-shadow: 
    0 16px 40px rgba(0, 0, 0, 0.85), 
    0 4px 12px rgba(0, 0, 0, 0.5),
    inset 0 -1px 3px rgba(0, 0, 0, 0.3);
  position: relative;
  overflow: hidden;
}

/* ป้ายระบุหน้าบน/หน้าล่าง */
.leaf-tag-badge {
  position: absolute;
  top: 8px;
  right: 12px;
  background: rgba(18, 14, 10, 0.85);
  border: 1px solid #6b5736;
  color: #fae4a2;
  font-size: 0.72rem;
  padding: 2px 10px;
  border-radius: 10px;
  backdrop-filter: blur(4px);
  z-index: 10;
  box-shadow: 0 2px 6px rgba(0,0,0,0.5);
}

/* ==========================================================================
   3. รูปแบบหน้าเดี่ยว: ปกหน้าต้น (DSCN8422) & หน้าสุดท้าย (DSCN8446)
   ========================================================================== */
.single-cover-book {
  width: 100%;
  max-width: 780px;
  height: 260px;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  background-position: center;
  border-radius: 12px;
  transform: rotateX(8deg);
  box-shadow: 
    0 1px 0 #3a3020,
    0 3px 0 #2c2417,
    0 5px 0 #211b11,
    0 7px 0 #18130c,
    0 22px 55px rgba(0, 0, 0, 0.95);
  position: relative;
  overflow: hidden;
}

/* ==========================================================================
   4. กลไกแผ่นพับ 3D ขณะกำลังเปิด (3D Flipping Flap Physics)
   ========================================================================== */
.flipping-flap-unit {
  position: absolute;
  left: 0;
  width: 100%;
  height: 202px;
  transform-style: preserve-3d;
  z-index: 20;
  pointer-events: none;
}

/* เมื่อเปิดไปข้างหน้า: แผ่นล่างยกพลิกขึ้นจากสันพับกลาง */
.flipping-flap-unit.flip-forward {
  top: 214px;
  transform-origin: top center;
  animation: flipForwardHinge 0.62s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

@keyframes flipForwardHinge {
  0% {
    transform: rotateX(-8deg);
  }
  50% {
    transform: rotateX(-90deg) scale(1.02);
  }
  100% {
    transform: rotateX(-172deg);
  }
}

/* เมื่อเปิดถอยหลัง: แผ่นบนพับกลับลงมาจากสันพับกลาง */
.flipping-flap-unit.flip-backward {
  top: 0;
  transform-origin: bottom center;
  animation: flipBackwardHinge 0.62s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

@keyframes flipBackwardHinge {
  0% {
    transform: rotateX(12deg);
  }
  50% {
    transform: rotateX(90deg) scale(1.02);
  }
  100% {
    transform: rotateX(172deg);
  }
}

/* ด้านหน้าของแผ่นที่กำลังพลิก (Front Face) */
.flap-side-front {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  background-position: center;
  backface-visibility: hidden;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.8);
}

/* ด้านหลังของแผ่นที่กำลังพลิก (Back Face - เนื้อกระดาษข่อยหลังสมุด) */
.flap-side-back {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: url('../images/khoi_back_texture.svg');
  background-size: 100% 100%;
  backface-visibility: hidden;
  transform: rotateX(180deg);
  border-radius: 12px;
  box-shadow: 0 -10px 30px rgba(0,0,0,0.8);
}

/* เงาทอดสมจริงขณะแผ่นกระดาษยกลอยตัว (Dynamic Drop Shadow) */
.flap-dynamic-shadow {
  position: absolute;
  top: 214px;
  left: 0;
  width: 100%;
  height: 202px;
  background: radial-gradient(ellipse at 50% 30%, rgba(0,0,0,0.8) 0%, transparent 70%);
  pointer-events: none;
  z-index: 15;
  animation: dynamicShadowFade 0.62s ease forwards;
}

@keyframes dynamicShadowFade {
  0% { opacity: 0; transform: scale(0.9); }
  50% { opacity: 0.9; transform: scale(1.05); }
  100% { opacity: 0; transform: scale(0.9); }
}

/* ==========================================================================
   Controls Bar & Filmstrip Carousel
   ========================================================================== */
.controls-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 20;
  flex-shrink: 0;
  margin-top: 4px;
}

.nav-btn {
  background: rgba(26, 22, 18, 0.94);
  border: 1px solid #6b5839;
  color: #fae4a2;
  padding: 7px 18px;
  border-radius: 24px;
  font-size: 0.86rem;
  font-family: inherit;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 14px rgba(0,0,0,0.5);
}

.nav-btn:hover:not(:disabled) {
  background: #473822;
  border-color: #d1b16c;
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(0,0,0,0.6);
}

.nav-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  transform: none;
}

.btn-cover-jump {
  background: linear-gradient(135deg, #443520 0%, #291f13 100%);
  border-color: #8c7247;
}

/* แถบภาพย่อทั้ง ๒๕ หน้า (Filmstrip) */
.thumbnail-filmstrip {
  width: 100%;
  max-width: 960px;
  height: 72px;
  background: rgba(14, 12, 10, 0.92);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 4px 8px;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  align-items: center;
  flex-shrink: 0;
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.6);
  scrollbar-width: thin;
  scrollbar-color: #5c4b31 #1c1915;
}

.thumb-card {
  height: 58px;
  width: 76px;
  flex-shrink: 0;
  border-radius: 4px;
  border: 1px solid #4a3e2e;
  overflow: hidden;
  position: relative;
  cursor: pointer;
  opacity: 0.6;
  transition: all 0.2s ease;
  background: #000;
}

.thumb-card:hover {
  opacity: 0.9;
  border-color: #b08d4b;
  transform: translateY(-2px);
}

.thumb-card.active {
  opacity: 1;
  border: 2px solid #dfc26a;
  box-shadow: 0 0 10px rgba(223, 194, 106, 0.5);
}

.thumb-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.thumb-card .thumb-badge {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.8);
  font-size: 0.62rem;
  color: #f5da82;
  text-align: center;
  padding: 1px 0;
}

/* ==========================================================================
   Side Drawer
   ========================================================================== */
.drawer-panel {
  width: 380px;
  background: var(--panel-bg);
  border-left: 1px solid var(--panel-border);
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.3, 1);
  z-index: 50;
  box-shadow: -4px 0 25px rgba(0,0,0,0.6);
}

.drawer-panel.closed {
  transform: translateX(100%);
  position: absolute;
  right: 0;
  height: 100%;
}

.drawer-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--panel-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.drawer-header h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: #f0e2c8;
  display: flex;
  align-items: center;
  gap: 8px;
}

.close-drawer-btn {
  background: transparent;
  border: none;
  color: #a69882;
  cursor: pointer;
  font-size: 1.2rem;
  padding: 4px;
}
.close-drawer-btn:hover {
  color: #ffffff;
}

.drawer-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.info-card {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 12px 14px;
}

.info-card h4 {
  font-size: 0.86rem;
  font-weight: 600;
  color: #dfc26a;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.meta-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.82rem;
  color: #bbb3a4;
}
.meta-list li {
  list-style: none;
  display: flex;
  justify-content: space-between;
}
.meta-list strong {
  color: #ecd79c;
}

/* ==========================================================================
   Responsive Adaptations
   ========================================================================== */
@media (max-width: 900px) {
  .drawer-panel {
    position: absolute;
    right: 0;
    height: 100%;
    transform: translateX(100%);
  }
  .drawer-panel.open-mobile {
    transform: translateX(0);
  }
  .accordion-book-unit {
    height: 350px;
  }
  .leaf-top-surface, .leaf-bottom-surface {
    height: 170px;
  }
  .flipping-flap-unit {
    height: 170px;
  }
  .flipping-flap-unit.flip-forward {
    top: 180px;
  }
  .single-cover-book {
    height: 220px;
  }
  .thumbnail-filmstrip {
    height: 60px;
  }
  .thumb-card {
    height: 48px;
    width: 64px;
  }
}

/* ==========================================================================
   Reading Modes (โหมดมืด, โหมดถนอมสายตา ซีเปีย, โหมดสว่าง)
   ========================================================================== */
.reading-theme-group {
  display: inline-flex;
  align-items: center;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  overflow: hidden;
  padding: 2px;
  gap: 2px;
}
.btn-theme-mode {
  background: transparent;
  border: none;
  color: #a89c89;
  padding: 5px 10px;
  font-size: 0.76rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.2s ease;
  user-select: none;
}
.btn-theme-mode:hover {
  color: #f2c94c;
  background: rgba(255, 255, 255, 0.06);
}
.btn-theme-mode.active {
  background: linear-gradient(135deg, #d4a017 0%, #8c650d 100%);
  color: #140d07;
  font-weight: 700;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}

/* --- โหมดกระดาษถนอมสายตา (Sepia / Warm Cream) --- */
body[data-reading-theme="sepia"] {
  background-color: #ede2cb !important;
  color: #3b2c1b !important;
}
body[data-reading-theme="sepia"] header.app-header {
  background: linear-gradient(180deg, #f4ecd8 0%, #e8dcbf 100%) !important;
  border-bottom: 1px solid #c9b491 !important;
  box-shadow: 0 3px 14px rgba(90, 70, 50, 0.15) !important;
}
body[data-reading-theme="sepia"] .brand-icon {
  background: #deb887 !important;
  border-color: #b89758 !important;
  color: #4a3417 !important;
}
body[data-reading-theme="sepia"] .brand-text h1 {
  color: #3b2c1b !important;
}
body[data-reading-theme="sepia"] .brand-text p {
  color: #6e583f !important;
}
body[data-reading-theme="sepia"] .reading-theme-group {
  background: #dfd1b5 !important;
  border-color: #c4b08f !important;
}
body[data-reading-theme="sepia"] .btn-theme-mode {
  color: #614c33 !important;
}
body[data-reading-theme="sepia"] .btn-theme-mode.active {
  background: #7a5015 !important;
  color: #fff9ea !important;
}
body[data-reading-theme="sepia"] .btn {
  background: #dfd1b5 !important;
  border-color: #c4b08f !important;
  color: #3b2c1b !important;
}
body[data-reading-theme="sepia"] .btn:hover {
  background: #d4c3a2 !important;
  color: #21160a !important;
}
body[data-reading-theme="sepia"] .status-pill {
  background: rgba(244, 236, 216, 0.95) !important;
  border-color: #c9b491 !important;
  box-shadow: 0 4px 16px rgba(90, 70, 50, 0.15) !important;
}
body[data-reading-theme="sepia"] .status-badge {
  color: #4a3722 !important;
}
body[data-reading-theme="sepia"] .status-badge .dot {
  background: #a36214 !important;
}
body[data-reading-theme="sepia"] .nav-btn {
  background: #f2e7d0 !important;
  border-color: #bfa884 !important;
  color: #4a3417 !important;
  box-shadow: 0 3px 10px rgba(90, 70, 50, 0.12) !important;
}
body[data-reading-theme="sepia"] .nav-btn.btn-accent {
  background: linear-gradient(135deg, #a36214 0%, #754407 100%) !important;
  color: #fff8eb !important;
  border-color: #bd7922 !important;
}
body[data-reading-theme="sepia"] .drawer-panel {
  background: rgba(247, 241, 227, 0.98) !important;
  border-left: 1px solid #c9b491 !important;
  color: #3b2c1b !important;
}
body[data-reading-theme="sepia"] .drawer-header {
  border-bottom: 1px solid #c9b491 !important;
  color: #3b2c1b !important;
}
body[data-reading-theme="sepia"] .info-card {
  background: rgba(255, 255, 255, 0.55) !important;
  border-color: #c9b491 !important;
}
body[data-reading-theme="sepia"] .info-card h4 {
  color: #7a4e10 !important;
}
body[data-reading-theme="sepia"] #currentDescription {
  color: #3b2c1b !important;
}
body[data-reading-theme="sepia"] .meta-list li span {
  color: #6e583f !important;
}
body[data-reading-theme="sepia"] .meta-list li strong,
body[data-reading-theme="sepia"] .meta-list li span:last-child {
  color: #21160a !important;
}

/* --- โหมดสว่าง (Light / Daylight Mode) --- */
body[data-reading-theme="light"] {
  background-color: #f3f5f8 !important;
  color: #212529 !important;
}
body[data-reading-theme="light"] header.app-header {
  background: linear-gradient(180deg, #ffffff 0%, #edf1f5 100%) !important;
  border-bottom: 1px solid #d0d7de !important;
  box-shadow: 0 3px 14px rgba(0, 0, 0, 0.08) !important;
}
body[data-reading-theme="light"] .brand-icon {
  background: #e9ecef !important;
  border-color: #ced4da !important;
  color: #9a6b0c !important;
}
body[data-reading-theme="light"] .brand-text h1 {
  color: #212529 !important;
}
body[data-reading-theme="light"] .brand-text p {
  color: #6c757d !important;
}
body[data-reading-theme="light"] .reading-theme-group {
  background: #e9ecef !important;
  border-color: #ced4da !important;
}
body[data-reading-theme="light"] .btn-theme-mode {
  color: #495057 !important;
}
body[data-reading-theme="light"] .btn-theme-mode.active {
  background: #1b4f72 !important;
  color: #ffffff !important;
}
body[data-reading-theme="light"] .btn {
  background: #ffffff !important;
  border-color: #ced4da !important;
  color: #212529 !important;
}
body[data-reading-theme="light"] .btn:hover {
  background: #f1f3f5 !important;
  color: #000000 !important;
}
body[data-reading-theme="light"] .status-pill {
  background: rgba(255, 255, 255, 0.95) !important;
  border-color: #ced4da !important;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08) !important;
}
body[data-reading-theme="light"] .status-badge {
  color: #212529 !important;
}
body[data-reading-theme="light"] .status-badge .dot {
  background: #28a745 !important;
}
body[data-reading-theme="light"] .nav-btn {
  background: #ffffff !important;
  border-color: #ced4da !important;
  color: #212529 !important;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.06) !important;
}
body[data-reading-theme="light"] .nav-btn.btn-accent {
  background: linear-gradient(135deg, #1b4f72 0%, #154360 100%) !important;
  color: #ffffff !important;
  border-color: #2e86c1 !important;
}
body[data-reading-theme="light"] .drawer-panel {
  background: rgba(255, 255, 255, 0.98) !important;
  border-left: 1px solid #ced4da !important;
  color: #212529 !important;
}
body[data-reading-theme="light"] .drawer-header {
  border-bottom: 1px solid #ced4da !important;
  color: #212529 !important;
}
body[data-reading-theme="light"] .info-card {
  background: #f8f9fa !important;
  border-color: #e9ecef !important;
}
body[data-reading-theme="light"] .info-card h4 {
  color: #1b4f72 !important;
}
body[data-reading-theme="light"] #currentDescription {
  color: #343a40 !important;
}
body[data-reading-theme="light"] .meta-list li span {
  color: #6c757d !important;
}
body[data-reading-theme="light"] .meta-list li strong,
body[data-reading-theme="light"] .meta-list li span:last-child {
  color: #212529 !important;
}

/* Gesture Toast Notification */
.gesture-toast {
  position: absolute;
  top: 48%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.85);
  background: rgba(20, 16, 12, 0.92);
  border: 1px solid #dfc26a;
  color: #f2c94c;
  padding: 10px 22px;
  border-radius: 30px;
  font-size: 0.92rem;
  font-weight: 600;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.22s ease, transform 0.22s ease;
  z-index: 999;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  white-space: nowrap;
}
.gesture-toast.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}
body[data-reading-theme="sepia"] .gesture-toast {
  background: rgba(244, 236, 216, 0.96);
  border-color: #a36214;
  color: #5c3504;
  box-shadow: 0 8px 24px rgba(90, 70, 50, 0.2);
}
body[data-reading-theme="light"] .gesture-toast {
  background: rgba(255, 255, 255, 0.96);
  border-color: #1b4f72;
  color: #1b4f72;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}
