:root {
  --cream: #f6f0e6;
  --cream-2: #efe6d8;
  --paper: #fffaf3;
  --brown: #2c1a12;
  --brown-soft: #4a3226;
  --wood: #8b5e3c;
  --wood-light: #c4a484;
  --sage: #7a8f6e;
  --gold: #c9a227;
  --muted: #6e5b4e;
  --shadow: 0 18px 50px rgba(44, 26, 18, 0.18);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --radius: 22px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

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

html,
body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  color: var(--brown);
  font-family: "Noto Sans Thai", "Nunito", system-ui, sans-serif;
  background:
    radial-gradient(900px 500px at 80% -10%, rgba(201, 162, 39, 0.12), transparent 55%),
    radial-gradient(700px 400px at 10% 100%, rgba(122, 143, 110, 0.12), transparent 50%),
    linear-gradient(180deg, var(--cream) 0%, var(--cream-2) 100%);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

.is-hidden,
[hidden] {
  display: none !important;
}

/* ---------- Welcome ---------- */
.welcome {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(20px + var(--safe-top)) 18px calc(24px + var(--safe-bottom));
  position: relative;
  overflow: hidden;
  animation: fadeIn 0.55s var(--ease) both;
}

.welcome-bg {
  position: absolute;
  inset: 0;
  background:
    url("../assets/cover.png") center 28% / cover no-repeat;
  filter: blur(0px) saturate(1.05);
  transform: scale(1.08);
  opacity: 0.28;
}

.welcome-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    180deg,
    rgba(246, 240, 230, 0.55) 0%,
    rgba(246, 240, 230, 0.92) 48%,
    rgba(239, 230, 216, 0.98) 100%
  );
}

.welcome-card {
  position: relative;
  z-index: 1;
  width: min(100%, 420px);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
}

.welcome-logo {
  width: 108px;
  height: 108px;
  object-fit: contain;
  border-radius: 28px;
  background: #fff;
  box-shadow: 0 12px 30px rgba(44, 26, 18, 0.16);
  animation: riseIn 0.7s var(--ease) both;
}

.welcome-cover {
  width: 100%;
  max-height: 42vh;
  object-fit: cover;
  object-position: center 40%;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 3px solid rgba(255, 250, 243, 0.9);
  animation: riseIn 0.8s var(--ease) 0.08s both;
}

.welcome-tag {
  margin: 8px 0 0;
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 500;
  letter-spacing: 0.02em;
}

.welcome-title {
  margin: 0;
  font-family: "Nunito", "Noto Sans Thai", sans-serif;
  font-weight: 800;
  font-size: clamp(1.8rem, 6vw, 2.35rem);
  color: var(--brown);
  letter-spacing: 0.01em;
  line-height: 1.15;
}

.welcome-sub {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
  max-width: 28ch;
}

.btn-primary,
.btn-secondary,
.btn-order {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  width: min(100%, 280px);
  padding: 0 22px;
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-weight: 700;
  font-size: 1.05rem;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.btn-primary {
  background: linear-gradient(135deg, var(--brown) 0%, var(--brown-soft) 100%);
  color: #fff8ef;
  box-shadow: 0 10px 28px rgba(44, 26, 18, 0.28);
  animation: riseIn 0.75s var(--ease) 0.16s both;
}

.btn-secondary {
  background: transparent;
  color: var(--brown-soft);
  border: 1.5px solid rgba(44, 26, 18, 0.18);
  margin-top: 4px;
}

.btn-primary:active,
.btn-secondary:active,
.btn-order:active,
.icon-btn:active,
.nav-arrow:active {
  transform: scale(0.97);
}

/* ---------- App shell ---------- */
.app {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  min-height: 100dvh;
  max-width: 760px;
  margin: 0 auto;
  animation: fadeIn 0.35s var(--ease) both;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + var(--safe-top)) 12px 10px;
  background: rgba(246, 240, 230, 0.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(44, 26, 18, 0.06);
  position: sticky;
  top: 0;
  z-index: 30;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  border: 0;
  background: rgba(44, 26, 18, 0.06);
  color: var(--brown);
  font-size: 1.15rem;
  cursor: pointer;
  flex-shrink: 0;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  object-fit: contain;
  background: #fff;
  box-shadow: 0 4px 12px rgba(44, 26, 18, 0.12);
  flex-shrink: 0;
}

.brand-en {
  margin: 0;
  font-family: "Nunito", sans-serif;
  font-weight: 800;
  font-size: 1rem;
  line-height: 1.1;
  color: var(--brown);
}

.brand-th {
  margin: 1px 0 0;
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 500;
}

.page-pill {
  flex-shrink: 0;
  min-width: 52px;
  text-align: center;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--brown);
  color: #fff8ef;
  font-size: 0.8rem;
  font-weight: 700;
}

/* Tabs — easy page jumping by title */
.page-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 14px 6px;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.page-tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  flex: 0 0 auto;
  scroll-snap-align: start;
  border: 0;
  border-radius: 999px;
  padding: 9px 14px;
  background: rgba(255, 250, 243, 0.85);
  color: var(--brown-soft);
  font: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(44, 26, 18, 0.06);
  cursor: pointer;
  white-space: nowrap;
  border: 1.5px solid transparent;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.tab.is-active {
  background: var(--brown);
  color: #fff8ef;
  border-color: var(--brown);
}

.tab:focus-visible {
  outline: 2px solid var(--wood);
  outline-offset: 2px;
}

/* Viewer */
.viewer {
  position: relative;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 8px;
  min-height: 0;
}

.menu-stage {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.menu-frame {
  position: relative;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
}

.menu-sheet {
  position: relative;
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
  cursor: zoom-in;
  line-height: 0;
  z-index: 1;
  will-change: transform, opacity;
  transition:
    transform 0.32s var(--ease),
    opacity 0.32s var(--ease);
}

.menu-sheet.is-exit-next {
  transform: translateX(-28%) scale(0.98);
  opacity: 0;
}

.menu-sheet.is-exit-prev {
  transform: translateX(28%) scale(0.98);
  opacity: 0;
}

.menu-sheet.is-enter-next {
  transform: translateX(28%) scale(0.98);
  opacity: 0;
}

.menu-sheet.is-enter-prev {
  transform: translateX(-28%) scale(0.98);
  opacity: 0;
}

.menu-sheet.is-enter-active {
  transform: translateX(0) scale(1);
  opacity: 1;
}

.menu-sheet img {
  display: block;
  width: 100%;
  height: auto;
  max-height: calc(100dvh - 210px);
  object-fit: contain;
  object-position: center top;
  background: transparent;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

.zoom-hint {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(44, 26, 18, 0.72);
  color: #fff8ef;
  font-size: 0.75rem;
  font-weight: 600;
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.4s ease;
  z-index: 2;
}

.menu-sheet.is-hint-faded .zoom-hint {
  opacity: 0;
}

.sheet-caption {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--brown-soft);
  text-align: center;
}

.nav-arrow {
  display: grid;
  place-items: center;
  width: 44px;
  height: 56px;
  min-width: 44px;
  padding: 0;
  border: 0;
  border-radius: 16px;
  background: rgba(255, 250, 243, 0.94);
  color: var(--brown);
  font: inherit;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(44, 26, 18, 0.14);
  border: 1px solid rgba(44, 26, 18, 0.08);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  align-self: center;
  z-index: 5;
}

.nav-arrow .nav-chevron {
  font-size: 1.85rem;
  line-height: 1;
  font-weight: 400;
}

.nav-arrow:disabled {
  opacity: 0.28;
  cursor: default;
  box-shadow: none;
}

.nav-arrow:not(:disabled):active {
  transform: scale(0.96);
  background: rgba(255, 250, 243, 1);
}

.bottombar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 8px 16px calc(14px + var(--safe-bottom));
  background: rgba(246, 240, 230, 0.94);
  border-top: 1px solid rgba(44, 26, 18, 0.06);
}

.progress {
  display: flex;
  gap: 5px;
  justify-content: center;
  flex-wrap: wrap;
  max-width: 100%;
}

.progress span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(44, 26, 18, 0.18);
  transition: transform 0.2s ease, background 0.2s ease, width 0.2s ease;
}

.progress span.is-active {
  background: var(--brown);
  width: 22px;
  border-radius: 999px;
}

.btn-order {
  background: linear-gradient(135deg, var(--gold) 0%, #dfc056 100%);
  color: var(--brown);
  box-shadow: 0 8px 20px rgba(201, 162, 39, 0.35);
  width: min(100%, 320px);
}

/* States inside viewer */
.state {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 40vh;
  padding: 24px;
  text-align: center;
  color: var(--muted);
}

.state strong {
  color: var(--brown);
  font-size: 1.05rem;
}

.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid rgba(44, 26, 18, 0.12);
  border-top-color: var(--brown);
  animation: spin 0.8s linear infinite;
}

/* Lightbox — full menu readable with scroll */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(20, 12, 8, 0.96);
  display: grid;
  grid-template-rows: auto 1fr auto;
  animation: fadeIn 0.25s ease both;
}

.lightbox-close {
  justify-self: end;
  margin: calc(10px + var(--safe-top)) 14px 0;
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 248, 239, 0.16);
  color: #fff8ef;
  font-size: 1.15rem;
  cursor: pointer;
  z-index: 2;
  touch-action: manipulation;
}

.lightbox-stage {
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y;
  min-height: 0;
  padding: 4px 0 20px;
  position: relative;
}

.lightbox-stage img {
  display: block;
  width: 100%;
  max-width: none;
  height: auto;
  margin: 0 auto;
  transform-origin: top center;
  user-select: none;
  -webkit-user-drag: none;
  will-change: width;
}

.lightbox-hint {
  margin: 0;
  padding: 10px 16px calc(12px + var(--safe-bottom));
  text-align: center;
  color: rgba(255, 248, 239, 0.75);
  font-size: 0.8rem;
  background: rgba(20, 12, 8, 0.85);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 120;
  background: rgba(44, 26, 18, 0.92);
  color: #fff8ef;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: var(--shadow);
  animation: riseIn 0.3s var(--ease) both;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes riseIn {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes sheetIn {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

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

@media (min-width: 768px) {
  .welcome-cover {
    max-height: 360px;
  }

  .viewer {
    grid-template-columns: 52px 1fr 52px;
    gap: 10px;
    padding: 8px 12px;
  }

  .nav-arrow {
    width: 52px;
    height: 64px;
    min-width: 52px;
  }
}

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