:root {
  --stage-bg: #1c1613;
  --stage-surface: #271f1b;
  --stage-border: rgba(212, 175, 106, 0.24);
  --parchment-ink: #f7f1e3;
  --muted-ink: #cbbba6;
  --gold: #d4af6a;
  --gold-soft: rgba(212, 175, 106, 0.16);
  --crimson: #9e2a2b;
  --crimson-hover: #b63233;
  --font-sans: 'Noto Sans Thai', 'Noto Sans SC', system-ui, -apple-system, sans-serif;
  --font-serif: 'Noto Serif Thai', 'Noto Serif SC', Georgia, serif;
}

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

html {
  scroll-behavior: smooth;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  color: var(--parchment-ink);
  background:
    radial-gradient(circle at 50% 25%, #2d221c 0%, #1c1613 62%, #130e0c 100%);
  display: flex;
  flex-direction: column;
}

img {
  display: block;
  max-width: 100%;
}

button, a {
  font: inherit;
}

.hidden {
  display: none !important;
}

.container {
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 14px;
}

/* === Sticky Top Bar === */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(22, 17, 15, 0.94);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--stage-border);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 9px;
  padding-bottom: 9px;
  flex-wrap: wrap;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid var(--gold);
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-title {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 1.02rem;
  color: var(--gold);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-meta {
  font-size: 0.74rem;
  color: var(--muted-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.call-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  text-decoration: none;
  background: var(--gold-soft);
  border: 1px solid var(--gold);
  color: var(--parchment-ink);
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  transition: background-color 0.16s ease;
}

.call-pill:hover {
  background: rgba(212, 175, 106, 0.28);
}

.pill-group {
  display: inline-flex;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  padding: 3px;
}

.pill-btn {
  border: none;
  background: transparent;
  color: var(--muted-ink);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.16s ease;
}

.pill-btn.active {
  background: var(--crimson);
  color: #fff;
}

.mode-group .pill-btn.active {
  background: var(--gold);
  color: #1c1613;
}

/* === Chapter Strip === */
.chapter-strip-wrap {
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  background: rgba(18, 13, 11, 0.85);
}

.chapter-strip-inner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 7px;
  padding-bottom: 7px;
}

.chapter-strip-label {
  font-size: 0.75rem;
  color: var(--muted-ink);
  white-space: nowrap;
  flex-shrink: 0;
}

.chapter-strip {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 1px 0;
}

.chapter-strip::-webkit-scrollbar {
  display: none;
}

.chapter-pill {
  flex: 0 0 auto;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.04);
  color: var(--parchment-ink);
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.16s ease;
}

.chapter-pill:hover {
  border-color: var(--gold);
}

.chapter-pill.active {
  background: var(--crimson);
  border-color: var(--gold);
  color: #fff;
  font-weight: 700;
}

/* === Main Stage === */
.book-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 14px 0 92px;
}

/* === Flipbook Stage === */
.flip-view {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.book-stage {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.stage-arrow {
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--stage-border);
  background: rgba(255, 255, 255, 0.08);
  color: var(--gold);
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color 0.16s ease, transform 0.14s ease;
}

.stage-arrow:hover:not(:disabled) {
  background: rgba(212, 175, 106, 0.22);
}

.stage-arrow:disabled {
  opacity: 0.25;
  cursor: default;
}

@media (min-width: 720px) {
  .stage-arrow {
    display: inline-flex;
  }
}

.book-spread-frame {
  flex: 1;
  max-width: 1040px;
  display: flex;
  justify-content: center;
  perspective: 1600px;
}

.book-spread {
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  border-radius: 8px;
  box-shadow:
    0 22px 54px rgba(0, 0, 0, 0.65),
    0 4px 14px rgba(0, 0, 0, 0.45);
  transition: opacity 0.2s ease, transform 0.24s ease;
}

.book-spread.turning-next {
  animation: pageTurnNext 0.26s ease;
}

.book-spread.turning-prev {
  animation: pageTurnPrev 0.26s ease;
}

@keyframes pageTurnNext {
  0% { opacity: 0.55; transform: translateX(18px) scale(0.99); }
  100% { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes pageTurnPrev {
  0% { opacity: 0.55; transform: translateX(-18px) scale(0.99); }
  100% { opacity: 1; transform: translateX(0) scale(1); }
}

.book-leaf {
  position: relative;
  background: #f5efe2;
  overflow: hidden;
  cursor: zoom-in;
  border: 1px solid rgba(212, 175, 106, 0.28);
}

.book-leaf img {
  height: min(74vh, 760px);
  width: auto;
  max-width: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

/* Two-page spread spine gutter shadow on desktop */
.book-spread.two-pages .book-leaf.left {
  border-radius: 8px 0 0 8px;
  border-right: none;
}

.book-spread.two-pages .book-leaf.left::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 26px;
  background: linear-gradient(to left, rgba(20, 12, 8, 0.28), transparent);
  pointer-events: none;
}

.book-spread.two-pages .book-leaf.right {
  border-radius: 0 8px 8px 0;
  border-left: 1px solid rgba(35, 22, 14, 0.22);
}

.book-spread.two-pages .book-leaf.right::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 22px;
  background: linear-gradient(to right, rgba(20, 12, 8, 0.22), transparent);
  pointer-events: none;
}

.book-spread.single-page .book-leaf {
  border-radius: 8px;
}

@media (max-width: 899px) {
  .book-leaf img {
    height: auto;
    max-height: 70vh;
    width: min(94vw, 480px);
  }
}

.leaf-badge {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(24, 17, 14, 0.72);
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  pointer-events: none;
}

.swipe-hint {
  margin: 10px 0 0;
  font-size: 0.78rem;
  color: var(--muted-ink);
  text-align: center;
}

/* === Vertical Scroll Mode === */
.scroll-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  padding-top: 6px;
}

.scroll-page-card {
  width: 100%;
  max-width: 760px;
  background: var(--stage-surface);
  border: 1px solid var(--stage-border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.45);
  cursor: zoom-in;
  scroll-margin-top: 118px;
}

.scroll-page-card img {
  width: 100%;
  aspect-ratio: 1414 / 2000;
  object-fit: cover;
}

.scroll-page-caption {
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  color: var(--parchment-ink);
  background: rgba(18, 13, 11, 0.92);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.scroll-page-num {
  color: var(--gold);
  font-weight: 700;
}

/* === Footer === */
.site-footer {
  padding: 16px 14px 100px;
  text-align: center;
  font-size: 0.78rem;
  color: var(--muted-ink);
}

/* === Bottom Book Control Dock === */
.book-dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 42;
  background: rgba(20, 15, 13, 0.96);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--stage-border);
}

.book-dock-inner {
  max-width: 1060px;
  margin: 0 auto;
  padding: 0 12px 10px;
}

.progress-track {
  width: 100%;
  height: 3px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 8px;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--crimson), var(--gold));
  width: 7%;
  transition: width 0.22s ease;
}

.dock-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.dock-nav-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--stage-border);
  background: rgba(255, 255, 255, 0.08);
  color: var(--gold);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}

.dock-nav-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

.dock-page-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.dock-page-num {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--gold);
}

.dock-page-title {
  font-size: 0.75rem;
  color: var(--muted-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.dock-tools {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.dock-tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.07);
  color: var(--parchment-ink);
  padding: 7px 11px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.dock-tool-btn.primary {
  background: var(--crimson);
  border-color: var(--gold);
  color: #fff;
}

@media (max-width: 520px) {
  .dock-tool-btn span:last-child {
    display: none;
  }
  .dock-tool-btn {
    padding: 8px 11px;
  }
}

/* === Thumbnails Drawer === */
.thumbs-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(10, 7, 6, 0.76);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

@media (min-width: 700px) {
  .thumbs-backdrop {
    align-items: center;
    padding: 20px;
  }
}

.thumbs-sheet {
  width: 100%;
  max-width: 880px;
  max-height: 86vh;
  background: #221a16;
  border: 1px solid var(--stage-border);
  border-radius: 20px 20px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

@media (min-width: 700px) {
  .thumbs-sheet {
    border-radius: 18px;
  }
}

.thumbs-head {
  padding: 14px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.thumbs-head h2 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1.15rem;
  color: var(--gold);
}

.thumbs-head p {
  margin: 2px 0 0;
  font-size: 0.8rem;
  color: var(--muted-ink);
}

.icon-close-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  cursor: pointer;
  font-size: 1rem;
  flex-shrink: 0;
}

.thumbs-grid {
  padding: 14px 16px 20px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

@media (min-width: 560px) {
  .thumbs-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (min-width: 820px) {
  .thumbs-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

.thumb-card {
  border: 2px solid transparent;
  background: #17120f;
  border-radius: 10px;
  overflow: hidden;
  padding: 0;
  text-align: left;
  cursor: pointer;
  color: var(--parchment-ink);
  transition: border-color 0.16s ease, transform 0.14s ease;
}

.thumb-card:hover {
  transform: translateY(-2px);
  border-color: rgba(212, 175, 106, 0.55);
}

.thumb-card.active {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(212, 175, 106, 0.25);
}

.thumb-card img {
  width: 100%;
  aspect-ratio: 212 / 300;
  object-fit: cover;
}

.thumb-meta {
  padding: 6px 8px;
  font-size: 0.72rem;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.thumb-num {
  color: var(--gold);
  font-weight: 700;
}

.thumb-title {
  color: var(--muted-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* === Fullscreen Zoom Lightbox === */
.lightbox-backdrop {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(10, 8, 7, 0.96);
  display: flex;
  flex-direction: column;
}

.lightbox-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  background: rgba(20, 15, 13, 0.92);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  z-index: 2;
  flex-wrap: wrap;
}

.lightbox-caption {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--gold);
}

.lightbox-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
}

.zoom-level-btn {
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.07);
  color: var(--parchment-ink);
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
}

.zoom-level-btn.active {
  background: var(--gold);
  border-color: var(--gold);
  color: #1c1613;
}

.lightbox-viewport {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.lightbox-viewport.zoomed-mode {
  align-items: flex-start;
  justify-content: flex-start;
}

.lightbox-img {
  max-height: calc(100vh - 88px);
  width: auto;
  max-width: 100%;
  border-radius: 6px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.65);
  cursor: zoom-in;
  margin: auto;
}

.lightbox-arrow {
  position: fixed;
  top: 54%;
  transform: translateY(-50%);
  z-index: 75;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(212, 175, 106, 0.45);
  background: rgba(20, 15, 13, 0.76);
  color: var(--gold);
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
}

.lightbox-arrow.prev { left: 12px; }
.lightbox-arrow.next { right: 12px; }
