*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --brand:        #023C71;
  --accent:       #E8A020;
  --header-h:     102px;  /* header scrolled (70px) + breadcrumb (32px) */
  --footer-h:     52px;
  --breadcrumb-h: 32px;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Sarabun', sans-serif;
  color: #fff;
}

body {
  background: #aa8a6f url('../img/catalog/catalog-bg.webp') center center / cover no-repeat fixed;
}
body::before {
  content: '';
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.38);
  z-index: 0;
}

/* ── Header ── */
#hdr {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: rgba(10, 10, 10, 0.7);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 80px;
  z-index: 100;
  box-shadow: 0 2px 12px rgba(0,0,0,0.5);
}

/* ── Breadcrumbs Catalog ── */
.breadcrumbs-catalog {
  position: fixed;
  top: 70px;
  left: 0; right: 0;
  height: var(--breadcrumb-h);
  background: transparent;
  z-index: 90;
  display: flex;
  align-items: center;
}
.breadcrumbs-catalog .container {
  padding: 0 15px;
}
.breadcrumbs-catalog ol {
  display: flex;
  flex-wrap: wrap;
  list-style: none;
  margin: 0;
  padding: 0;
  gap: 0;
  align-items: center;
}
.breadcrumbs-catalog ol li + li::before {
  content: "›";
  color: rgba(255,255,255,0.5);
  padding: 0 6px;
  font-size: 13px;
}
.breadcrumbs-catalog ol li a {
  font-size: 12px;
  color: rgba(255,255,255,0.70);
  text-decoration: none;
  letter-spacing: 0.5px;
  transition: color 0.15s;
  font-family: 'Prompt', sans-serif;
  font-weight: 300;
}
.breadcrumbs-catalog ol li a:hover { color: #fff; }
.breadcrumbs-catalog ol li a.active,
.breadcrumbs-catalog ol li:last-child a {
  color: var(--accent);
  pointer-events: none;
}

/* ── Stage ── */
#stage {
  position: fixed;
  top: 70px;             /* ขอบล่าง header — center หนังสือระหว่างนี้กับ footer */
  bottom: var(--footer-h);
  left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
  overflow: hidden; /* clip StPageFlip curl ไม่ให้หลุดออกนอก stage */
}

/* ── Side Nav Buttons ── */
.nav-btn {
  position: absolute;
  top: 50%; transform: translateY(-50%);
  width: 64px;
  height: 160px;
  background: rgba(0,0,0,0.0);
  border: none;
  color: rgba(255,255,255,0.90);
  font-size: 52px;
  font-weight: 200;
  font-family: Georgia, serif;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s, color 0.15s;
  z-index: 10;
  border-radius: 4px;
  line-height: 1;
  user-select: none;
  letter-spacing: -4px;
}
.nav-btn:hover { background: rgba(0,0,0,0.30); color: #fff; }
.nav-btn:active { transform: translateY(-50%) scale(0.96); }
#btn-prev { left: 8px; }
#btn-next { right: 8px; }
.nav-btn.hidden { display: none; }

/* ── Flipbook wrap ── */
#flipbook-wrap {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%;
  position: relative;
  transform-origin: center center;
  overflow: hidden; /* กัน curl animation ของ StPageFlip หลุดออกนอกกรอบหนังสือ */
}

#flipbook { display: none; overflow: hidden; /* clip StPageFlip curl ไม่ให้หลุดออกนอกขอบหนังสือ */ }
/* StPageFlip injects position:absolute;top:0;left:0 on .stf__wrapper inside #flipbook.
   We neutralise this by making #flipbook itself a flex container so the wrapper
   (even if position:absolute) sits inside a correctly-sized box, and we use
   margin:auto on the wrapper via JS. The real centering fix is below: */
#flipbook .page { background: #fff; overflow: hidden; position: relative; }
#flipbook .page img { width: 100%; height: 100%; object-fit: contain; display: block; }

/* Force the StPageFlip wrapper to sit centered inside #flipbook-wrap.
   Library sets it position:absolute top:0 left:0 — we override to position
   it relative to the flex container instead. */
#flipbook-wrap .stf__wrapper {
  position: relative !important;
  top: auto !important;
  left: auto !important;
  margin: auto !important;
}

/* ── Book shadow overlays — JS uses position:fixed + viewport coords ── */
.book-shadow {
  position: absolute; /* JS overrides per-element; absolute ให้ #stage clip ได้ */
  pointer-events: none;
  z-index: 10;
}
/* Spine shadow */
#spine-shadow {
  position: absolute;
  pointer-events: none;
  z-index: 11;
  display: none;
}
#spine-shadow.visible { display: block; }

/* ── Loader ── */
#loader {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
}
.spinner {
  width: 44px; height: 44px;
  border: 4px solid rgba(255,255,255,0.15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loader p { font-size: 20px; color: rgba(255,255,255,0.7); }

/* ── Footer ── */
#ftr {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--footer-h);
  background: rgba(10, 10, 10, 0.7);
  backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 80px;
  z-index: 100;
}
#ftr-left  { display: flex; align-items: center; gap: 4px; }
#ftr-center {
  display: flex; align-items: center; gap: 4px;
  position: absolute; left: 50%; transform: translateX(-50%);
}
#ftr-right { display: flex; align-items: center; margin-left: auto; }

.tool-btn {
  width: 34px; height: 34px;
  background: transparent; border: none;
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  border-radius: 4px;
  transition: background 0.15s, color 0.15s;
}
.tool-btn:hover { background: rgba(255,255,255,0.15); color: #fff; }
.tool-btn svg { width: 18px; height: 18px; fill: currentColor; }

.pg-btn {
  width: 30px; height: 30px;
  background: transparent; border: none;
  color: rgba(255,255,255,0.75);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  border-radius: 4px;
  transition: background 0.15s, color 0.15s;
}
.pg-btn:hover { background: rgba(255,255,255,0.15); color: #fff; }
.pg-btn:disabled { opacity: 0.3; cursor: default; }
.pg-btn:disabled:hover { background: transparent; }
.pg-btn svg { width: 16px; height: 16px; fill: currentColor; }

/* Open-book icon — no numbers */
#page-icon-wrap {
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px;
  color: rgba(255,255,255,0.55);
}
#page-icon-wrap svg { width: 22px; height: 22px; fill: currentColor; }

/* Thumbnail panel */
#thumb-panel {
  position: fixed;
  bottom: var(--footer-h);
  left: 0; right: 0;
  background: rgba(12,12,12,0.96);
  backdrop-filter: blur(4px);
  display: none; flex-wrap: wrap;
  gap: 8px; padding: 12px;
  max-height: 200px; overflow-y: auto;
  z-index: 99; justify-content: center;
}
#thumb-panel.open { display: flex; }
.thumb-item {
  width: 60px; height: 80px;
  cursor: pointer;
  border: 2px solid transparent; border-radius: 3px;
  overflow: hidden; transition: border-color 0.15s;
}
.thumb-item img { width: 100%; height: 100%; object-fit: cover; }
.thumb-item.active { border-color: var(--accent); }
.thumb-item:hover { border-color: rgba(255,255,255,0.5); }

/* ซ่อนปุ่มของ mobile */
  #pg-first-m, #pg-prev-m, #pg-next-m, #pg-last-m, #btn-share-m {
    display: none !important;
  }

/* ── Share popup ── */
#share-popup {
  display: none;
  position: fixed;
  bottom: calc(var(--footer-h) + 8px);
  right: 12px;
  background: rgba(20,20,20,0.97);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  padding: 12px 14px;
  z-index: 200;
  min-width: 260px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.6);
}
#share-popup.open { display: block; }
#share-url-text {
  font-size: 13px;
  color: rgba(255,255,255,0.75);
  word-break: break-all;
  margin-bottom: 10px;
  line-height: 1.4;
}
#share-copy-btn {
  width: 100%;
  padding: 7px 0;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 5px;
  font-size: 14px;
  font-family: 'Sarabun', sans-serif;
  cursor: pointer;
  transition: opacity 0.15s;
}
#share-copy-btn:hover { opacity: 0.85; }

/* Mobile spine fold shadow — JS uses position:fixed */
#mobile-spine {
  display: none;
  position: absolute;
  pointer-events: none;
  z-index: 12;
}

/* ── Page dot indicators ── */
#page-dots {
  position: absolute;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 6px;
  padding: 6px 4px;
  pointer-events: none;
  z-index: 8;
}
.page-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,0.85);
  background: transparent;
  transition: background 0.2s;
  flex-shrink: 0;
}
.page-dot.active {
  background: rgba(255,255,255,0.90);
}
/* dot ของ end-page: ซ่อนบน desktop */
.page-dot-end { display: none; }
@media (max-width: 600px) {
  .page-dot-end { display: inline-block; }
}
/* ── บังคับให้ #header แสดงผลเหมือน scrolled state ตลอดเวลา (ทุก device) ── */
/* เพราะหน้านี้ไม่มี scroll ทำให้ header-scrolled ไม่ถูก trigger จาก main.js  */
#header {
  background: rgba(10, 10, 10, 0.7) !important;
  height: 70px !important;
}
#header #logo .logo-bg {
  height: 48px !important;
}

/* ── End Page: fixed div วางไว้หลัง flipbook ── */
/* JS จะคำนวณ position/size ให้ตรงกับ book 1 หน้า (position:fixed) */
/* ── End Page: fixed div วางไว้หลัง flipbook ──
   JS set position/size ให้ตรงกับ 1 หน้าของ book (position:fixed จาก JS)
   ใช้ container-type เพื่อให้ cqw/cqh อ้างอิงขนาด element จริง ไม่ใช่ viewport */
#end-page {
  display: none;               /* JS toggle เป็น flex เมื่อถึงหน้าสุดท้าย */
  /* position: fixed — JS จะ set ให้ตรงตำแหน่ง book */
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  pointer-events: none;        /* ไม่รับ touch — ให้ swipe ทะลุไปถึง flipbook */
  overflow: hidden;
  z-index: 3;

  container-type: size;        /* ให้ cqw/cqh อ้างอิงขนาด element นี้ */

  background: #f5f0eb;
  box-shadow: inset 4px 0 18px rgba(0,0,0,0.12), inset -2px 0 8px rgba(0,0,0,0.06);

  /* padding คิดจาก container จริง ผ่าน cqw/cqh */
  padding: 4cqh 3cqw;
  gap: 0;
}
/* grain texture */
#end-page::before {
  content: '';
  position: absolute; inset: 0;
  background-image: repeating-linear-gradient(
    0deg,
    rgba(0,0,0,0.018) 0px, rgba(0,0,0,0.018) 1px,
    transparent 1px, transparent 3px
  );
  pointer-events: none;
  z-index: 0;
}
/* เงาขอบ spine */
#end-page::after {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 40px; height: 100%;
  background: linear-gradient(to right, rgba(0,0,0,0.15) 0%, transparent 100%);
  pointer-events: none;
  z-index: 0;
}

/* ── ทุก child ต้องอยู่เหนือ ::before/::after ── */
#end-page > * { position: relative; z-index: 1; }

.page-end-logo {
  font-family: 'Kanit', sans-serif;
  font-size: clamp(13px, 3.5cqw, 28px);
  font-weight: 600;
  letter-spacing: 1px;
  color: #B48200;
  margin-bottom: 2px;
  text-align: center;
  white-space: nowrap;
}
.page-end-tagline {
  font-family: 'Kanit', sans-serif;
  font-size: 12px;
  font-weight: 300;
  color: #666;
  margin-bottom: 2cqh;
  text-align: center;
}
.page-end-divider {
  width: 60px; height: 1px;
  background: #E8A020;
  margin: 0 auto 2cqh;
  flex-shrink: 0;
}
.page-end-heading {
  font-family: 'Kanit', sans-serif;
  font-size: 12px;
  font-weight: 400;
  color: #444;
  margin-bottom: 1.5cqh;
  text-align: center;
  white-space: nowrap;
}
.page-end-links {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 80%;
}
.page-end-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: clamp(4px, 1cqh, 9px) 10px;
  background: #fff;
  border: 1px solid #ddd;
  border-left: 3px solid #E8A020;
  border-radius: 4px;
  color: #333;
  text-decoration: none;
  font-family: 'Kanit', sans-serif;
  font-size: 11px;
  font-weight: 300;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.07);
  white-space: nowrap;
  pointer-events: auto;        /* เปิด pointer-events เฉพาะ link คลิกได้ปกติ */
}
.page-end-link:hover {
  background: #fffbf2;
  border-left-color: #FF6B35;
  color: #023C71;
}
.page-end-link-icon { font-size: clamp(10px, 1.6cqw, 15px); flex-shrink: 0; }
.page-end-link-label { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.page-end-link-arrow { color: #bbb; font-size: 12px; flex-shrink: 0; }
.page-end-link:hover .page-end-link-arrow { color: #E8A020; }

.page-end-footer {
  margin-top: clamp(8px, 1.5cqh, 18px);
  font-family: 'Prompt', sans-serif;
  font-size: clamp(6px, 1cqw, 10px);
  color: #aaa;
  text-align: center;
  white-space: nowrap;
}

@media (max-width: 600px) {
  #hdr {
    padding: 0 20px;
  }
  #ftr {
    padding: 0 10px;
  }
  .nav-btn {
    display: none !important;
  }
  /* zoom in/out บน mobile — ลดขนาดเล็กลง */
  #btn-zoom-in, #btn-zoom-out {
    display: flex !important;
    width: 30px;
    height: 30px;
  }
  /* ซ่อนปุ่มกลางและขวา บน mobile */
  #pg-first, #pg-prev, #pg-next, #pg-last, #btn-fullscreen, #btn-share {
    display: none !important;
  }
  /* เปิดปุ่มซ้าย บน mobile */
  #pg-first-m, #pg-prev-m, #pg-next-m, #pg-last-m, #btn-share-m {
    display: flex !important;
  }

  #ftr-left {
    gap: 2px;
  }
  #ftr-center {
    gap: 2px;
  }
  /* ย่อ share popup บน mobile */
  #share-popup {
    right: 8px;
    left: 8px;
    min-width: unset;
  }
  /* กัน shadow และ spine ล้นออกนอกพื้นที่หนังสือ */
  #flipbook-wrap {
    overflow: hidden;
  }
}
/* ── Mobile page curl overlay (back-flip animation) ── */
#mobile-curl-overlay {
  border-radius: 0;
  box-shadow: -8px 0 24px rgba(0,0,0,0.35);
  /* ป้องกัน overlay หลุดกรอบล่างของหนังสือ */
  overflow: hidden;
  max-height: 100vh;
}
/* Curl shadow strip on left edge to sell the 3D fold */
#mobile-curl-overlay::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 18px; height: 100%;
  background: linear-gradient(to right, rgba(0,0,0,0.55) 0%, transparent 100%);
  pointer-events: none;
  z-index: 2;
}*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

