/* ── ครกนัว · เมนูออนไลน์ ─────────────────────────────── */

:root {
  --wood-900: #150d07;
  --wood-800: #1f1409;
  --wood-700: #2c1c0e;
  --wood-600: #3d2814;
  --chili:    #e02b25;
  --chili-lo: #b81f1a;
  --gold:     #f5c542;
  --leaf:     #4f9d3a;
  --cream:    #fdf6e8;
  --muted:    #b39a7d;
  --line:     rgba(255, 233, 199, .14);
  --bar-h:    58px;
  --safe-b:   env(safe-area-inset-bottom, 0px);
  --z-book:   10;
  --z-bar:    60;
  --z-thumbs: 70;
  --z-modal:  80;
  --z-splash: 95;
  --z-toast:  99;
}

* { box-sizing: border-box; }

/* กันไม่ให้ display: ในคลาสด้านล่างไปทับ [hidden] จนโมดัลที่ปิดอยู่ยังบังคลิก */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: 'Kanit', -apple-system, 'Noto Sans Thai', sans-serif;
  font-weight: 400;
  color: var(--cream);
  background: radial-gradient(120% 90% at 50% 0%, #35220f 0%, var(--wood-800) 45%, var(--wood-900) 100%);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

/* ลายไม้จาง ๆ เป็นพื้นหลัง ให้หน้าเมนูลอยเด่นขึ้น */
.bg-grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .5;
  background:
    repeating-linear-gradient(93deg, rgba(255,255,255,.014) 0 2px, transparent 2px 7px),
    repeating-linear-gradient(87deg, rgba(0,0,0,.10) 0 3px, transparent 3px 11px);
}

svg { fill: currentColor; }
.ico { width: 18px; height: 18px; flex: none; }

/* ── หน้าจอโหลด ───────────────────────────────────────── */
.splash {
  position: fixed;
  inset: 0;
  z-index: var(--z-splash);
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 18px;
  background: var(--wood-900);
  transition: opacity .45s ease, visibility .45s;
}
.splash.gone { opacity: 0; visibility: hidden; }
.splash-logo {
  width: 140px; height: 140px;
  border-radius: 28px;
  box-shadow: 0 18px 50px rgba(0,0,0,.6);
  animation: breathe 2.4s ease-in-out infinite;
}
@keyframes breathe { 0%,100% { transform: scale(1); } 50% { transform: scale(1.045); } }
.splash-bar {
  width: 180px; height: 4px;
  border-radius: 99px;
  background: rgba(255,255,255,.12);
  overflow: hidden;
}
.splash-bar i {
  display: block;
  height: 100%;
  width: 8%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--gold), var(--chili));
  transition: width .3s ease;
}
.splash-text { margin: 0; font-size: 13px; color: var(--muted); letter-spacing: .04em; }

/* ── แถบบน ────────────────────────────────────────────── */
.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  height: var(--bar-h);
  z-index: var(--z-bar);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 12px;
  background: linear-gradient(180deg, rgba(12,7,3,.94), rgba(12,7,3,.55) 70%, transparent);
  backdrop-filter: blur(10px);
}
.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.brand-mark { border-radius: 9px; box-shadow: 0 2px 8px rgba(0,0,0,.5); }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-text strong { font-size: 16px; font-weight: 600; letter-spacing: .01em; }
.brand-text span {
  font-size: 10.5px; color: var(--muted); font-weight: 300;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

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

.btn, .pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255,255,255,.055);
  color: var(--cream);
  font: inherit;
  font-size: 13px;
  font-weight: 400;
  text-decoration: none;
  cursor: pointer;
  transition: background .16s, border-color .16s, transform .1s;
}
.btn:hover, .pill:hover { background: rgba(255,255,255,.12); border-color: rgba(255,233,199,.3); }
.btn:active, .pill:active { transform: scale(.95); }
.btn-call {
  background: linear-gradient(160deg, var(--chili), var(--chili-lo));
  border-color: rgba(255,255,255,.22);
  font-weight: 500;
}
.btn-call:hover { background: linear-gradient(160deg, #f03b34, #c9241e); }

/* ── เวทีหนังสือ ──────────────────────────────────────── */
.stage {
  position: fixed;
  inset: var(--bar-h) 0 calc(var(--bar-h) + var(--safe-b)) 0;
  z-index: var(--z-book);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px;
}
.book-wrap {
  position: relative;
  height: 100%;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
}
/* PageFlip (โหมด stretch) คำนวณขนาดหน้าจาก offsetWidth/offsetHeight ของกล่องนี้
   จึงต้องกางเต็มพื้นที่ที่เหลือ ไม่งั้นจะได้เล่มจิ๋วและถูกบังคับเป็นหน้าเดี่ยว */
.book { width: 100%; height: 100%; }
.book.ready { animation: bookIn .55s cubic-bezier(.2,.8,.3,1) both; }
@keyframes bookIn { from { opacity: 0; transform: translateY(18px) scale(.97); } }

/* หน้าเมนูแต่ละหน้า */
.pg {
  background: #1a1108;
  overflow: hidden;
}
.pg img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity .35s ease;
}
.pg img.on { opacity: 1; }
.pg-skel {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  color: rgba(255,233,199,.22);
  font-size: 26px;
  font-weight: 600;
  background: linear-gradient(115deg, #1e1409, #2a1c0e 50%, #1e1409);
}
.pg.loaded .pg-skel { display: none; }

/* ── แผงข้างปก ────────────────────────────────────────── */
.cover-panel {
  position: absolute;
  display: grid;
  place-items: center;
  padding: 6% 7%;
  pointer-events: none;
  animation: panelIn .5s .1s ease both;
}
@keyframes panelIn { from { opacity: 0; transform: translateY(10px); } }
.cp-inner { text-align: center; max-width: 340px; }
.cp-logo {
  width: 96px; height: 96px;
  border-radius: 22px;
  box-shadow: 0 12px 34px rgba(0,0,0,.55);
}
.cp-title {
  margin: 16px 0 6px;
  font-size: clamp(26px, 3.2vw, 40px);
  font-weight: 600;
  letter-spacing: .01em;
  color: var(--cream);
  text-shadow: 0 3px 18px rgba(0,0,0,.6);
}
.cp-title-sm { font-size: clamp(20px, 2.2vw, 27px); }
.cp-sub {
  margin: 0;
  font-size: 13.5px;
  font-weight: 300;
  line-height: 1.75;
  color: var(--muted);
}
.cp-rule {
  width: 68px;
  height: 2px;
  margin: 18px auto;
  border-radius: 99px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}
.cp-line {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 17px;
  font-weight: 500;
  color: var(--gold);
  text-decoration: none;
  pointer-events: auto;
}
.cp-line .ico { width: 16px; height: 16px; }
.cp-social { margin: 6px 0 0; font-size: 12px; font-weight: 300; color: var(--muted); }
.cp-cta {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-top: 22px;
  height: 40px;
  padding: 0 20px;
  border: 1px solid rgba(255,233,199,.28);
  border-radius: 999px;
  background: rgba(255,255,255,.06);
  color: var(--cream);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  pointer-events: auto;
  transition: background .16s, transform .1s;
}
.cp-cta svg { width: 16px; height: 16px; }
.cp-cta:hover { background: rgba(255,255,255,.15); }
.cp-cta:active { transform: scale(.96); }

/* ปุ่มลูกศรซ้าย/ขวา (จอใหญ่) */
.nav-arrow {
  flex: none;
  width: 44px; height: 74px;
  display: grid;
  place-content: center;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,.05);
  color: var(--cream);
  cursor: pointer;
  transition: background .16s, opacity .16s, transform .1s;
}
.nav-arrow svg { width: 24px; height: 24px; }
.nav-arrow:hover { background: rgba(255,255,255,.14); }
.nav-arrow:active { transform: scale(.93); }
.nav-arrow[disabled] { opacity: .22; pointer-events: none; }

/* ── แถบล่าง ──────────────────────────────────────────── */
.bottombar {
  position: fixed;
  inset: auto 0 0 0;
  height: calc(var(--bar-h) + var(--safe-b));
  padding: 0 12px var(--safe-b);
  z-index: var(--z-bar);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: linear-gradient(0deg, rgba(12,7,3,.94), rgba(12,7,3,.55) 70%, transparent);
  backdrop-filter: blur(10px);
}
.bottom-right { display: flex; gap: 6px; }

.pager {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(0,0,0,.35);
}
.pager-btn {
  width: 30px; height: 30px;
  display: grid;
  place-content: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--cream);
  cursor: pointer;
}
.pager-btn svg { width: 19px; height: 19px; }
.pager-btn:hover { background: rgba(255,255,255,.12); }
.pager-btn[disabled] { opacity: .25; pointer-events: none; }
.pager-label {
  min-width: 58px;
  text-align: center;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.pager-label b { color: var(--gold); font-weight: 600; }
.pager-label i { color: var(--muted); font-style: normal; margin: 0 3px; }
.pager-label span { color: var(--muted); }

/* ── สารบัญ (thumbnail strip) ─────────────────────────── */
.thumbs {
  position: fixed;
  inset: auto 0 0 0;
  z-index: var(--z-thumbs);
  padding: 12px 0 calc(10px + var(--safe-b));
  background: rgba(10,6,2,.97);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  transform: translateY(100%);
  transition: transform .3s cubic-bezier(.2,.8,.3,1);
}
.thumbs.open { transform: none; }
.thumbs-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px 10px;
}
.thumbs-head h2 { margin: 0; font-size: 14px; font-weight: 500; letter-spacing: .02em; }
.thumbs-strip {
  display: flex;
  gap: 10px;
  padding: 2px 14px 6px;
  overflow-x: auto;
  scrollbar-width: thin;
  scroll-snap-type: x proximity;
}
.thumbs-strip::-webkit-scrollbar { height: 6px; }
.thumbs-strip::-webkit-scrollbar-thumb { background: rgba(255,233,199,.22); border-radius: 99px; }
.thumb {
  flex: none;
  width: 76px;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  cursor: pointer;
  scroll-snap-align: center;
  text-align: center;
}
.thumb img {
  display: block;
  width: 76px;
  height: 107px;
  object-fit: cover;
  border-radius: 6px;
  border: 2px solid transparent;
  background: #241708;
  transition: border-color .16s, transform .16s;
}
.thumb:hover img { transform: translateY(-3px); }
.thumb.on img { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(245,197,66,.2); }
.thumb small {
  display: block;
  margin-top: 5px;
  font-size: 10px;
  line-height: 1.25;
  color: var(--muted);
  font-weight: 300;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.thumb.on small { color: var(--gold); }

.icon-btn {
  width: 32px; height: 32px;
  display: grid;
  place-content: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(255,255,255,.06);
  color: var(--cream);
  cursor: pointer;
}
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn:hover { background: rgba(255,255,255,.15); }

/* ── โมดัลซูม ─────────────────────────────────────────── */
.zoom {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  background: rgba(6,3,1,.97);
  touch-action: none;
  animation: fade .2s ease;
}
@keyframes fade { from { opacity: 0; } }
.zoom-canvas {
  position: absolute;
  inset: 0;
  overflow: hidden;
  cursor: grab;
  display: grid;
  place-content: center;
}
.zoom-canvas.dragging { cursor: grabbing; }
#zoom-img {
  max-width: 100vw;
  max-height: 100vh;
  transform-origin: center center;
  will-change: transform;
  user-select: none;
}
.zoom-bar {
  position: absolute;
  left: 50%;
  bottom: calc(18px + var(--safe-b));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(20,12,5,.9);
  backdrop-filter: blur(10px);
}
#zoom-level {
  min-width: 50px;
  text-align: center;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--gold);
}
.zoom-close { margin-left: 4px; background: rgba(224,43,37,.85); border-color: transparent; }
.zoom-hint {
  position: absolute;
  left: 50%;
  top: calc(14px + env(safe-area-inset-top, 0px));
  transform: translateX(-50%);
  margin: 0;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(20,12,5,.8);
  font-size: 12px;
  font-weight: 300;
  color: var(--muted);
  white-space: nowrap;
  transition: opacity .5s;
}
.zoom-hint.hide { opacity: 0; }

/* ── โมดัลทั่วไป (แชร์ / QR) ──────────────────────────── */
.sheet {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(6,3,1,.7);
  backdrop-filter: blur(4px);
  animation: fade .2s ease;
}
.sheet-card {
  width: min(400px, 100%);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: linear-gradient(165deg, #2b1c0e, #1a1108);
  box-shadow: 0 26px 70px rgba(0,0,0,.7);
  animation: pop .28s cubic-bezier(.2,.9,.3,1) both;
}
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(.96); } }
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.sheet-head h2 { margin: 0; font-size: 16px; font-weight: 500; }

.share-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.share-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 6px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255,255,255,.04);
  color: var(--cream);
  font: inherit;
  font-size: 12px;
  text-decoration: none;
  cursor: pointer;
  transition: background .16s, transform .1s;
}
.share-item:hover { background: rgba(255,255,255,.1); }
.share-item:active { transform: scale(.96); }
.share-ico {
  width: 42px; height: 42px;
  display: grid;
  place-content: center;
  border-radius: 13px;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
}
.share-item b { font-weight: 400; }

.qr-card { text-align: center; }
.qr-frame {
  width: 220px;
  height: 220px;
  margin: 0 auto;
  padding: 12px;
  border-radius: 16px;
  background: #fff;
  display: grid;
  place-content: center;
}
.qr-frame svg, .qr-frame canvas { display: block; width: 196px; height: 196px; }
.qr-url {
  margin: 14px 0 4px;
  font-size: 13px;
  color: var(--gold);
  word-break: break-all;
}
.qr-note { margin: 0 0 16px; font-size: 12px; font-weight: 300; color: var(--muted); }
.btn-solid {
  width: 100%;
  height: 42px;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(160deg, var(--chili), var(--chili-lo));
  color: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.btn-solid:active { transform: scale(.98); }

/* ── toast ────────────────────────────────────────────── */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bar-h) + var(--safe-b) + 16px);
  transform: translate(-50%, 12px);
  z-index: var(--z-toast);
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(20,12,5,.96);
  border: 1px solid var(--line);
  font-size: 13px;
  opacity: 0;
  transition: opacity .22s, transform .22s;
  pointer-events: none;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* ── จอเล็ก ───────────────────────────────────────────── */
@media (max-width: 820px) {
  .nav-arrow { display: none; }
  .btn-label { display: none; }
  .btn, .pill { padding: 0 10px; }
  .stage { padding: 6px; }
}
@media (max-width: 480px) {
  :root { --bar-h: 54px; }
  .brand-text span { display: none; }
  .topbar-actions { gap: 5px; }
  .btn-call .btn-label { display: inline; }
}
@media (max-width: 360px) {
  .btn-call .btn-label { display: none; }
}

/* จอสูงมาก ๆ ในโหมดแนวนอน — ให้พื้นที่หนังสือมากขึ้น */
@media (max-height: 480px) and (orientation: landscape) {
  :root { --bar-h: 46px; }
  .thumb img { width: 54px; height: 76px; }
  .thumb { width: 54px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
