:root {
  --primary: #fdb100;
  --secondary: #336601;
  --accent: #ff0171;
  --ink: #1c1c1e;
  --ink-soft: #6e6e73;
  --paper: #ffffff;
  --chrome-bg: rgba(255, 255, 255, 0.72);
  --chrome-border: rgba(0, 0, 0, 0.06);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.10);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
    "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1100px 520px at 50% -12%, rgba(253, 177, 0, 0.18), rgba(253, 177, 0, 0) 62%),
    linear-gradient(180deg, #fbf6ea 0%, #f1e7cd 100%);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

body.zoom-open { overflow: hidden; }

/* ---------- Top bar ---------- */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  background: rgba(253, 177, 0, 0.62);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  backdrop-filter: blur(16px) saturate(180%);
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  z-index: 20;
}

.brand { display: flex; align-items: center; min-width: 0; text-decoration: none; }
.brand-logo {
  height: 28px;
  width: auto;
  display: block;
  object-fit: contain;
}
.topbar-actions { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.counter {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ---------- iOS-style buttons ---------- */
.icon-btn,
.nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--chrome-border);
  border-radius: 999px;
  background: var(--chrome-bg);
  -webkit-backdrop-filter: blur(14px) saturate(180%);
  backdrop-filter: blur(14px) saturate(180%);
  box-shadow: var(--shadow-sm);
  color: var(--secondary);
  cursor: pointer;
  text-decoration: none;
  -webkit-user-select: none;
  user-select: none;
  transition: transform 0.16s ease, background-color 0.16s ease,
    color 0.16s ease, box-shadow 0.16s ease;
}
.icon-btn { width: 36px; height: 36px; padding: 0; }
.icon-btn svg, .nav-btn svg { width: 20px; height: 20px; }
.icon-btn:hover, .nav-btn:hover { background: rgba(253, 177, 0, 0.16); }
.icon-btn:active, .nav-btn:active {
  transform: scale(0.92);
  background: rgba(253, 177, 0, 0.30);
  color: var(--accent);
}
.icon-btn:focus-visible, .nav-btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ---------- Stage / book ---------- */
.stage {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 64px;
}
.book-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.book { position: relative; width: 100%; }

/* Page content (StPageFlip adds .stf__item to each .page) */
.page { background: var(--paper); }
.page img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
}
.stf__item { box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.05); }

/* Navigation */
.nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 46px;
  height: 46px;
  z-index: 15;
}
.nav-prev { left: 10px; }
.nav-next { right: 10px; }
.nav-btn:active { transform: translateY(-50%) scale(0.92); }

/* ---------- Floating call button ---------- */
.call-btn {
  position: fixed;
  right: 18px;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 96px);
  z-index: 30;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  padding: 0;
  border-radius: 50%;
  background: var(--secondary);
  color: #fff;
  text-decoration: none;
  box-shadow: 0 6px 20px rgba(51, 102, 1, 0.35), 0 2px 6px rgba(0, 0, 0, 0.15);
  transition: transform 0.16s ease, box-shadow 0.16s ease, background-color 0.16s ease;
  -webkit-tap-highlight-color: transparent;
}
.call-btn:hover { background: #3d7a04; transform: translateY(-2px); box-shadow: 0 10px 26px rgba(51, 102, 1, 0.4); }
.call-btn:active { transform: scale(0.94); }
.call-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.call-icon { width: 22px; height: 22px; flex: 0 0 auto; }

/* ---------- Loader ---------- */
.loader {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  z-index: 5;
  transition: opacity 0.4s ease;
}
.loader.hidden { opacity: 0; }
.spinner {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 3px solid rgba(51, 102, 1, 0.15);
  border-top-color: var(--secondary);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Thumbnails ---------- */
.thumbs {
  flex: 0 0 auto;
  display: flex;
  gap: 10px;
  padding: 10px 16px calc(env(safe-area-inset-bottom, 0px) + 10px);
  overflow-x: auto;
  background: var(--chrome-bg);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  backdrop-filter: blur(16px) saturate(180%);
  border-top: 1px solid var(--chrome-border);
  z-index: 20;
  scrollbar-width: thin;
}
.thumbs::-webkit-scrollbar { height: 6px; }
.thumbs::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, 0.15); border-radius: 3px; }
.thumb {
  position: relative;
  flex: 0 0 auto;
  width: 40px;
  height: 56px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
  cursor: pointer;
  transition: transform 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb span {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  font-size: 9px;
  font-weight: 700;
  text-align: center;
  color: #fff;
  padding: 6px 0 2px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.55));
}
.thumb:hover { transform: translateY(-2px); border-color: var(--accent); }
.thumb:active { transform: scale(0.95); }
.thumb.active {
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(253, 177, 0, 0.5);
}

/* ---------- Zoom overlay ---------- */
.zoom {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(18, 18, 20, 0.92);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.22s ease, visibility 0.22s ease;
}
.zoom.open { opacity: 1; visibility: visible; }
.zoom-stage {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
}
.zoom-stage img {
  max-width: none;
  max-height: none;
  transform-origin: center center;
  will-change: transform;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  box-shadow: 0 12px 44px rgba(0, 0, 0, 0.55);
}
.zoom-close {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  right: 14px;
  z-index: 2;
  width: 40px;
  height: 40px;
  color: #fff;
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.22);
  box-shadow: none;
}
.zoom-close:hover { background: rgba(255, 255, 255, 0.22); }
.zoom-close:active { background: rgba(255, 255, 255, 0.32); color: var(--accent); }

/* ---------- Mobile ---------- */
@media (max-width: 767px) {
  .stage { padding: 8px; }
  .brand-logo { height: 22px; }
  .nav-btn {
    top: auto;
    bottom: 8px;
    transform: none;
    width: 40px;
    height: 40px;
  }
  .nav-prev { left: calc(50% - 46px); right: auto; }
  .nav-next { left: calc(50% + 6px); right: auto; }
  .nav-btn:active { transform: scale(0.92); }
  .call-btn {
    right: 14px;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 82px);
    width: 46px;
    height: 46px;
  }
  .thumbs { gap: 8px; padding: 8px 12px calc(env(safe-area-inset-bottom, 0px) + 8px); }
  .thumb { width: 34px; height: 48px; border-radius: 7px; }
}
