/* ============================================================
   GOLDEN ROK — Interactive Digital Catalogue
   Premium architectural brochure styling
   ============================================================ */

/* ── Design tokens ────────────────────────────────────────── */
:root {
  /* Viewport-height unit with a graceful fallback for browsers
     that don't support `dvh` (iOS Safari < 15.4, etc.). The
     dynamic viewport unit overrides the static one below. */
  --vh: 100vh;
}
@supports (height: 100dvh) {
  :root { --vh: 100dvh; }
}

:root {
  /* Brand palette pulled from the brochure */
  --gold:        #a98b4b;
  --gold-soft:   #c5a96b;
  --gold-deep:   #876c34;
  --bronze:      #6b5a36;
  --cream:       #f4ecdc;
  --cream-soft:  #faf5ea;
  --ink:         #1f1a14;
  --ink-soft:    #3a3127;
  --paper:       #ffffff;
  --paper-edge:  #e7dec8;
  --shadow:      0 30px 80px -20px rgba(0,0,0,.55), 0 10px 30px -10px rgba(0,0,0,.35);

  /* Stage backdrop – rich warm gradient like a leather desk */
  --stage-bg: radial-gradient(ellipse at 50% 30%, #2c2419 0%, #1a140d 55%, #0d0a06 100%);

  /* Animation */
  --flip-ease: cubic-bezier(.36,.04,.31,1);
  --flip-dur:  1100ms;

  /* Layout */
  --toolbar-h: 64px;
  --footer-h:  64px;

  /* Page aspect from PDF – A4: 595.276 × 841.89 = ~1:1.4142 */
  --page-ratio: calc(841.89 / 595.276);
}

/* ── Reset / base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  color: var(--cream);
  background: var(--stage-bg);
  background-attachment: fixed;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }

/* Subtle paper texture overlay on the stage */
body::before {
  content: '';
  position: fixed; inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 20% 10%, rgba(169,139,75,.08), transparent 50%),
    radial-gradient(circle at 80% 90%, rgba(107,90,54,.10), transparent 55%);
  z-index: 0;
}

/* ── Loader ───────────────────────────────────────────────── */
.loader {
  position: fixed; inset: 0; z-index: 1000;
  background: radial-gradient(ellipse at center, #2c2419 0%, #0d0a06 100%);
  display: grid; place-items: center;
  transition: opacity .9s ease, visibility .9s ease;
}
.loader.is-done { opacity: 0; visibility: hidden; pointer-events: none; }
.loader-inner { text-align: center; padding: 32px; }
.loader-mark {
  width: 96px; height: 96px;
  animation: pulse 2s ease-in-out infinite, slow-spin 8s linear infinite;
  filter: drop-shadow(0 8px 24px rgba(169,139,75,.45));
}
.loader-brand {
  margin-top: 24px;
  font-family: 'Cormorant Garamond', serif;
  font-weight: 600;
  letter-spacing: .5em;
  font-size: 1.4rem;
  color: var(--gold-soft);
}
.loader-tagline {
  margin-top: 6px;
  font-size: .72rem;
  letter-spacing: .35em;
  text-transform: uppercase;
  color: rgba(244,236,220,.55);
}
.loader-bar {
  margin: 36px auto 12px;
  width: min(280px, 70vw);
  height: 2px;
  background: rgba(169,139,75,.18);
  border-radius: 2px;
  overflow: hidden;
  position: relative;
}
.loader-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--gold), var(--gold-soft));
  transition: width .35s ease;
  box-shadow: 0 0 10px rgba(197,169,107,.6);
}
.loader-status {
  font-size: .68rem;
  letter-spacing: .25em;
  text-transform: uppercase;
  color: rgba(244,236,220,.5);
}
@keyframes pulse { 0%,100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.06); opacity: .85; } }
@keyframes slow-spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }

/* ── App shell ────────────────────────────────────────────── */
.app {
  position: relative;
  z-index: 1;
  height: 100vh;            /* fallback for older iOS Safari (< 15.4) */
  height: 100dvh;
  min-height: 100vh;
  display: grid;
  grid-template-rows: var(--toolbar-h) 1fr var(--footer-h);
  opacity: 0;
  transition: opacity 1s ease;
}
.app.is-ready { opacity: 1; }

/* ── Toolbar ──────────────────────────────────────────────── */
.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  background: linear-gradient(180deg, rgba(20,16,11,.85), rgba(20,16,11,.55));
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(169,139,75,.18);
  position: relative;
  z-index: 50;
}
.toolbar-brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark { width: 36px; height: 36px; flex-shrink: 0; }
.brand-text { line-height: 1.1; min-width: 0; }
.brand-name {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 700;
  letter-spacing: .22em;
  font-size: 1.05rem;
  color: var(--gold-soft);
}
.brand-sub {
  font-size: .65rem;
  letter-spacing: .25em;
  text-transform: uppercase;
  color: rgba(244,236,220,.55);
  margin-top: 3px;
}

.toolbar-actions { display: flex; align-items: center; gap: 8px; }
.tool-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  color: rgba(244,236,220,.85);
  font-size: .8rem;
  letter-spacing: .08em;
  border: 1px solid rgba(169,139,75,.18);
  background: rgba(244,236,220,.03);
  transition: all .25s ease;
}
.tool-btn:hover { color: var(--gold-soft); border-color: rgba(169,139,75,.45); background: rgba(169,139,75,.08); }
.tool-btn:active { transform: translateY(1px); }
.tool-btn.icon-only { padding: 8px; }
.tool-btn.primary {
  color: var(--ink);
  background: linear-gradient(180deg, var(--gold-soft), var(--gold));
  border-color: transparent;
  font-weight: 500;
}
.tool-btn.primary:hover { color: var(--ink); background: linear-gradient(180deg, #d3b87b, var(--gold-soft)); }
.tool-btn svg { width: 18px; height: 18px; }
.tool-label { display: inline-block; }

.tool-group {
  display: inline-flex; align-items: center;
  padding: 2px;
  border-radius: 999px;
  border: 1px solid rgba(169,139,75,.18);
  background: rgba(244,236,220,.03);
}
.tool-group .tool-btn { border: 0; background: transparent; }
.tool-group .tool-btn:hover { background: rgba(169,139,75,.08); }
.tool-group .tool-btn:disabled { opacity: .3; cursor: default; background: transparent; }
.tool-group-nav { padding: 2px 4px; }
.zoom-level {
  min-width: 46px; text-align: center;
  font-size: .72rem; letter-spacing: .12em;
  color: rgba(244,236,220,.7);
  font-variant-numeric: tabular-nums;
}

/* ── Stage ────────────────────────────────────────────────── */
.stage {
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-columns: 64px 1fr 64px;
  align-items: center;
}

/* Side arrows */
.nav-arrow {
  position: relative;
  width: 48px; height: 48px;
  margin: 0 auto;
  border-radius: 50%;
  display: grid; place-items: center;
  color: rgba(244,236,220,.7);
  border: 1px solid rgba(169,139,75,.25);
  background: rgba(20,16,11,.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: all .25s ease;
  z-index: 30;
}
.nav-arrow:hover { color: var(--gold-soft); border-color: rgba(169,139,75,.6); transform: scale(1.06); }
.nav-arrow:disabled { opacity: .25; cursor: default; transform: none; }
.nav-arrow svg { width: 22px; height: 22px; }

/* ── Zoom wrapper ─────────────────────────────────────────── */
.zoom-wrap {
  width: 100%; height: 100%;
  display: grid; place-items: center;
  transition: transform .3s ease;
  transform: scale(var(--zoom, 1));
  transform-origin: center center;
  overflow: visible;
}

/* ── Book ─────────────────────────────────────────────────── */
.book-wrap {
  position: relative;
  perspective: 2800px;
  perspective-origin: center 55%;
  display: grid; place-items: center;
  /* Compute available book size from stage minus toolbar/footer/arrows */
  --avail-w: min(94vw, calc(100vw - 160px));
  --avail-h: calc(var(--vh, 100vh) - var(--toolbar-h) - var(--footer-h) - 40px);
  /* Book outer dimensions – two pages wide */
  --book-h: min(var(--avail-h), calc(var(--avail-w) / (2 / var(--page-ratio))));
  --book-w: calc(var(--book-h) * 2 / var(--page-ratio));
  width: var(--book-w);
  height: var(--book-h);
}

.book {
  position: relative;
  width: 100%; height: 100%;
  transform-style: preserve-3d;
  transition: transform .9s var(--flip-ease);
  /* When closed, slide so the cover (right half) sits centered */
  transform: translateX(0);
}
.book.closed { transform: translateX(-25%); }

/* Soft drop shadow under the book (mimics depth on a desk) */
.book-shadow {
  position: absolute; inset: auto -3% -5% -3%;
  height: 60px;
  background: radial-gradient(ellipse at center, rgba(0,0,0,.55), transparent 70%);
  filter: blur(10px);
  z-index: -1;
  pointer-events: none;
}
/* Faux "stack of pages" base showing the book's thickness */
.book-base {
  position: absolute;
  top: 1.5%; bottom: 1.5%;
  left: 0; right: 0;
  background:
    linear-gradient(180deg, rgba(0,0,0,.18), transparent 8%, transparent 92%, rgba(0,0,0,.18)),
    repeating-linear-gradient(180deg, #f1e7d0 0 2px, #ddd0b4 2px 4px);
  border-radius: 2px 6px 6px 2px;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.12), 0 18px 50px -10px rgba(0,0,0,.6);
  z-index: 0;
}
.book.closed .book-base { display: none; }

/* Center spine shadow (visible when book is open) */
.book-spine {
  position: absolute;
  top: 0; bottom: 0;
  left: 50%;
  width: 28px;
  transform: translateX(-50%);
  pointer-events: none;
  background:
    linear-gradient(90deg,
      transparent 0%,
      rgba(0,0,0,.0) 35%,
      rgba(0,0,0,.45) 50%,
      rgba(0,0,0,.0) 65%,
      transparent 100%);
  opacity: .9;
  z-index: 6;
  transition: opacity .4s ease;
}
.book.closed .book-spine { opacity: 0; }

/* Leaves layer */
.leaves {
  position: absolute; inset: 0;
  transform-style: preserve-3d;
}

/* Each leaf occupies right half by default (acts like the next page in the right stack) */
.leaf {
  position: absolute;
  top: 0;
  left: 50%;
  width: 50%;
  height: 100%;
  transform-origin: left center;
  transform-style: preserve-3d;
  transition: transform var(--flip-dur) var(--flip-ease);
  will-change: transform;
}
.leaf.flipped { transform: rotateY(-180deg); }

/* Two faces */
.face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
  background: var(--paper);
  box-shadow:
    inset 0 0 0 1px rgba(0,0,0,.04);
}
.face img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}
.face.back { transform: rotateY(180deg); }

/* Inner-edge shading on each face (next to the spine) – sells the curvature */
.face.front::before,
.face.back::before {
  content: '';
  position: absolute;
  top: 0; bottom: 0;
  width: 28px;
  pointer-events: none;
  z-index: 2;
}
.face.front::before {
  left: 0;
  background: linear-gradient(90deg, rgba(0,0,0,.22), rgba(0,0,0,0));
}
.face.back::before {
  right: 0;
  background: linear-gradient(270deg, rgba(0,0,0,.22), rgba(0,0,0,0));
}

/* Outer edge highlight (sells the paper edge thickness) */
.face::after {
  content: '';
  position: absolute;
  top: 0; bottom: 0;
  width: 2px;
  background: linear-gradient(180deg, rgba(0,0,0,.05), rgba(0,0,0,.18), rgba(0,0,0,.05));
  pointer-events: none;
}
.face.front::after { right: 0; }
.face.back::after  { left: 0; }

/* Animated highlight that sweeps across the page during a flip */
.leaf .glare {
  position: absolute; inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity .25s ease;
  z-index: 3;
}
.leaf.is-flipping .glare { opacity: 1; }
.leaf.is-flipping .glare.front {
  background: linear-gradient(90deg, rgba(255,255,255,0) 0%, rgba(255,255,255,.0) 60%, rgba(255,255,255,.35) 100%);
}
.leaf.is-flipping .glare.back {
  background: linear-gradient(270deg, rgba(0,0,0,.0) 0%, rgba(0,0,0,.0) 60%, rgba(0,0,0,.25) 100%);
}

/* Page number badge (small, bottom-corner) – optional decorative */
.page-num {
  position: absolute;
  bottom: 10px;
  font-size: 10px;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: rgba(0,0,0,.35);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  z-index: 4;
}
.face.front .page-num { right: 14px; }
.face.back  .page-num { left:  14px; }
/* Hide page number on the cover and back cover */
.leaf[data-cover] .face.front .page-num,
.leaf[data-back-cover] .face.back .page-num { display: none; }

/* Corner hot-zones for click-to-flip */
.corner {
  position: absolute;
  width: 12%; height: 22%;
  z-index: 20;
  background: transparent;
  border: 0;
  cursor: pointer;
  transition: background .25s ease;
}
.corner-tl { top: 0;    left: 0;    border-radius: 0 0 50% 0; }
.corner-tr { top: 0;    right: 0;   border-radius: 0 0 0 50%; }
.corner-bl { bottom: 0; left: 0;    border-radius: 0 50% 0 0; }
.corner-br { bottom: 0; right: 0;   border-radius: 50% 0 0 0; }
.corner:hover {
  background: radial-gradient(circle at var(--cx,100%) var(--cy,100%), rgba(169,139,75,.18), transparent 70%);
}
.corner-tl { --cx: 0;    --cy: 0;    }
.corner-tr { --cx: 100%; --cy: 0;    }
.corner-bl { --cx: 0;    --cy: 100%; }
.corner-br { --cx: 100%; --cy: 100%; }

/* ── Footer ───────────────────────────────────────────────── */
.footer {
  display: flex; align-items: center; justify-content: center;
  flex-direction: column;
  gap: 4px;
  background: linear-gradient(0deg, rgba(20,16,11,.85), rgba(20,16,11,.45));
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid rgba(169,139,75,.18);
  padding: 8px 16px;
  position: relative;
  z-index: 50;
}
.page-indicator {
  display: flex; align-items: center; gap: 14px;
  color: rgba(244,236,220,.85);
  font-size: .8rem;
  letter-spacing: .12em;
}
.page-label {
  font-family: 'Cormorant Garamond', serif;
  font-size: 1rem;
  color: var(--gold-soft);
  letter-spacing: .06em;
  font-variant-numeric: tabular-nums;
  min-width: 100px;
  text-align: right;
}
.page-total { color: rgba(244,236,220,.55); font-size: .72rem; letter-spacing: .14em; }
.progress-track {
  width: 240px; height: 2px;
  background: rgba(169,139,75,.18);
  border-radius: 2px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--gold), var(--gold-soft));
  width: 0%;
  transition: width .55s var(--flip-ease);
}
.hint {
  font-size: .65rem;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: rgba(244,236,220,.4);
}

/* ── TOC overlay ──────────────────────────────────────────── */
.toc-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(8,6,4,.75);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: grid; place-items: center;
  opacity: 0; visibility: hidden;
  transition: opacity .35s ease, visibility .35s ease;
}
.toc-overlay.is-open { opacity: 1; visibility: visible; }
.toc-panel {
  width: min(680px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
  position: relative;
  background:
    radial-gradient(ellipse at top, rgba(169,139,75,.10), transparent 50%),
    linear-gradient(180deg, #1d1810, #14110b);
  border: 1px solid rgba(169,139,75,.25);
  border-radius: 4px;
  padding: 44px 40px 32px;
  box-shadow: 0 40px 100px -20px rgba(0,0,0,.8);
  transform: translateY(20px);
  transition: transform .4s var(--flip-ease);
}
.toc-overlay.is-open .toc-panel { transform: translateY(0); }
.toc-close {
  position: absolute; top: 14px; right: 14px;
  width: 36px; height: 36px;
  border-radius: 50%;
  display: grid; place-items: center;
  color: rgba(244,236,220,.6);
  border: 1px solid rgba(169,139,75,.2);
  transition: all .2s ease;
}
.toc-close:hover { color: var(--gold-soft); border-color: rgba(169,139,75,.5); }
.toc-close svg { width: 18px; height: 18px; }
.toc-eyebrow {
  font-size: .65rem; letter-spacing: .4em; text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 8px;
}
.toc-title {
  margin: 0 0 26px;
  font-family: 'Cormorant Garamond', serif;
  font-weight: 500;
  font-size: 2.2rem;
  letter-spacing: .02em;
  color: var(--cream);
}
.toc-title em { color: var(--gold-soft); font-style: italic; }

.toc-list { list-style: none; padding: 0; margin: 0; }
.toc-item {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  align-items: center;
  gap: 18px;
  padding: 18px 4px;
  border-top: 1px solid rgba(169,139,75,.15);
  cursor: pointer;
  transition: all .25s ease;
}
.toc-item:last-child { border-bottom: 1px solid rgba(169,139,75,.15); }
.toc-item:hover { background: rgba(169,139,75,.07); padding-left: 12px; padding-right: 12px; }
.toc-num {
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.6rem;
  font-weight: 500;
  color: var(--gold-soft);
  letter-spacing: .04em;
}
.toc-meta { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.toc-label {
  font-size: 1rem;
  font-weight: 500;
  color: var(--cream);
  letter-spacing: .04em;
}
.toc-desc {
  font-size: .8rem;
  color: rgba(244,236,220,.55);
  line-height: 1.45;
}
.toc-page {
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.15rem;
  color: var(--gold);
  letter-spacing: .08em;
  font-variant-numeric: tabular-nums;
}
.toc-footer {
  margin-top: 24px;
  font-size: .68rem;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: rgba(244,236,220,.4);
  text-align: center;
}

/* ── Swipe hint (mobile) ──────────────────────────────────── */
.swipe-hint {
  position: fixed;
  bottom: calc(var(--footer-h) + 18px);
  left: 50%;
  transform: translateX(-50%);
  display: none;
  align-items: center; gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(20,16,11,.75);
  border: 1px solid rgba(169,139,75,.3);
  color: var(--gold-soft);
  font-size: .72rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  opacity: 0;
  transition: opacity .5s ease;
  z-index: 100;
  pointer-events: none;
}
.swipe-hint svg { width: 18px; height: 18px; }
.swipe-hint.is-visible { opacity: 1; }

/* ────────────────────────────────────────────────────────────
   PHONE BOOK — single-page flipbook used at mobile widths
   ──────────────────────────────────────────────────────────── */
.phone-book {
  display: none;
  position: relative;
  width: var(--phone-w, 90vw);
  height: var(--phone-h, 80vh);          /* fallback for older iOS Safari */
  height: var(--phone-h, 80dvh);
  perspective: 2200px;
  -webkit-perspective: 2200px;
  perspective-origin: 50% 55%;
  -webkit-perspective-origin: 50% 55%;
  transform: translateZ(0);              /* force compositing layer */
}
.phone-shadow {
  position: absolute;
  inset: auto -4% -4% -4%;
  height: 50px;
  background: radial-gradient(ellipse at center, rgba(0,0,0,.55), transparent 70%);
  filter: blur(12px);
  z-index: -1;
}
.phone-pages {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
}
.m-page {
  position: absolute;
  inset: 0;
  transform-origin: left center;
  -webkit-transform-origin: left center;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: var(--paper);
  border-radius: 2px;
  overflow: hidden;
  box-shadow:
    0 18px 40px -10px rgba(0,0,0,.45),
    0 0 0 1px rgba(0,0,0,.06);
  transition: transform 0.7s var(--flip-ease), box-shadow .4s ease;
  will-change: transform;
  /* Hidden by default — applyMobileStacking() reveals the right ones */
  visibility: hidden;
  pointer-events: none;
}
.m-page > img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: var(--paper);
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}
/* Subtle inner-spine gradient on each page for a printed-paper feel */
.m-page::before {
  content: '';
  position: absolute;
  top: 0; bottom: 0; left: 0;
  width: 18px;
  background: linear-gradient(90deg, rgba(0,0,0,.18), rgba(0,0,0,0));
  pointer-events: none;
  z-index: 2;
}
/* Page-edge thin highlight on the right */
.m-page::after {
  content: '';
  position: absolute;
  top: 0; bottom: 0; right: 0;
  width: 2px;
  background: linear-gradient(180deg, rgba(0,0,0,.05), rgba(0,0,0,.18), rgba(0,0,0,.05));
  pointer-events: none;
  z-index: 2;
}

/* Tap zones for prev/next in mobile mode */
.tap-zone {
  position: absolute;
  top: 0; bottom: 0;
  width: 32%;
  z-index: 50;
  background: transparent;
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.tap-zone.tap-prev { left: 0; }
.tap-zone.tap-next { right: 0; }
.tap-zone:active {
  background: radial-gradient(ellipse at var(--tx,50%) 50%, rgba(169,139,75,.18), transparent 60%);
}
.tap-zone.tap-prev:active { --tx: 0%; }
.tap-zone.tap-next:active { --tx: 100%; }

/* ── Fullscreen body lock ─────────────────────────────────── */
:fullscreen .app { background: var(--stage-bg); }
:-webkit-full-screen .app { background: var(--stage-bg); }

/* ────────────────────────────────────────────────────────────
   IMMERSIVE FULL-VIEW MODE
   Hides the toolbar + footer so the book fills the entire
   viewport. A compact floating control bar appears centered
   at the bottom. Tap the book to toggle the floating bar.
   Particularly useful in landscape on phones and tablets.
   ──────────────────────────────────────────────────────────── */
.app.is-immersive {
  grid-template-rows: 0 1fr 0;
}
.app.is-immersive .toolbar,
.app.is-immersive .footer {
  transform: translateY(-110%);
  opacity: 0;
  pointer-events: none;
}
.app.is-immersive .footer { transform: translateY(110%); }
.toolbar, .footer {
  transition: transform .45s var(--flip-ease), opacity .35s ease;
}

/* Recompute the available book size to use the FULL viewport */
.app.is-immersive .book-wrap {
  --avail-w: calc(100vw - 90px);
  --avail-h: calc(var(--vh, 100vh) - 16px);
}
.app.is-immersive .phone-book {
  --phone-pad: 6px;
  --phone-avail-w: calc(100vw - 12px);
  --phone-avail-h: calc(var(--vh, 100vh) - 12px);
}
/* Auto-hide the side arrows in immersive — corner clicks and the floating bar drive navigation */
.app.is-immersive .nav-arrow { opacity: 0; pointer-events: none; }

/* Floating control bar */
.immersive-bar {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%) translateY(0);
  display: none;
  align-items: center;
  gap: 4px;
  padding: 6px;
  background: rgba(20,16,11,.78);
  border: 1px solid rgba(169,139,75,.3);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-radius: 999px;
  box-shadow: 0 18px 40px -10px rgba(0,0,0,.6);
  z-index: 300;
  transition: opacity .35s ease, transform .35s var(--flip-ease);
  opacity: 0;
}
.app.is-immersive .immersive-bar {
  display: inline-flex;
  opacity: 1;
}
.app.is-immersive .immersive-bar.is-faded {
  opacity: 0;
  transform: translateX(-50%) translateY(20px);
  pointer-events: none;
}
.imm-btn {
  display: inline-grid;
  place-items: center;
  width: 40px; height: 40px;
  border-radius: 50%;
  color: rgba(244,236,220,.85);
  transition: all .2s ease;
}
.imm-btn:hover { color: var(--gold-soft); background: rgba(169,139,75,.12); }
.imm-btn:disabled { opacity: .28; cursor: default; background: transparent; }
.imm-btn svg { width: 18px; height: 18px; }
.imm-page {
  min-width: 96px;
  padding: 0 12px;
  text-align: center;
  font-family: 'Cormorant Garamond', serif;
  font-size: .95rem;
  color: var(--gold-soft);
  letter-spacing: .04em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 50vw;
}
.imm-sep {
  width: 1px; height: 20px;
  background: rgba(169,139,75,.22);
  margin: 0 2px;
}

/* Subtle "tap the book to toggle controls" hint on first immersive entry */
.imm-tap-hint {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(20,16,11,.85);
  color: var(--gold-soft);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: .75rem;
  letter-spacing: .18em;
  text-transform: uppercase;
  pointer-events: none;
  opacity: 0;
  transition: opacity .4s ease;
  z-index: 350;
  border: 1px solid rgba(169,139,75,.3);
}
.imm-tap-hint.is-visible { opacity: 1; }

/* ── Responsive : tablet & small desktop ─────────────────── */
@media (max-width: 1024px) {
  :root { --toolbar-h: 58px; --footer-h: 60px; }
  .brand-sub { display: none; }
  .tool-label { display: none; }
  .tool-btn { padding: 8px; }
  .toolbar { padding: 0 12px; gap: 8px; }
  .toolbar-actions { gap: 4px; }
}

@media (max-width: 900px) {
  .progress-track { width: 160px; }
  .page-label { min-width: 80px; font-size: .9rem; }
  .hint { display: none; }
}

/* Tablet portrait : keep the two-page spread but tighter */
@media (max-width: 900px) and (orientation: portrait) and (min-width: 561px) {
  .book-wrap {
    --avail-w: calc(100vw - 80px);
    --avail-h: calc(var(--vh, 100vh) - var(--toolbar-h) - var(--footer-h) - 30px);
  }
  .page-num { font-size: 9px; }
}

/* Landscape phones / small landscape tablets : enlarged spread view */
@media (orientation: landscape) and (max-width: 1024px) and (min-width: 561px) {
  :root { --toolbar-h: 50px; --footer-h: 50px; }
  .stage { grid-template-columns: 44px 1fr 44px; }
  .nav-arrow { width: 40px; height: 40px; }
  .book-wrap {
    --avail-w: calc(100vw - 100px);
    --avail-h: calc(var(--vh, 100vh) - var(--toolbar-h) - var(--footer-h) - 16px);
  }
  .hint { display: none; }
  .footer { padding: 4px 12px; }
}

/* ────────────────────────────────────────────────────────────
   PHONE  : narrow screens or any portrait phone
   Switches into single-page phone-book mode
   ──────────────────────────────────────────────────────────── */
@media (max-width: 560px), (max-width: 720px) and (orientation: portrait) {
  :root { --toolbar-h: 54px; --footer-h: 64px; }

  body { overflow: hidden; touch-action: pan-y; }

  /* Toolbar : compact, icon-only, balanced spacing */
  .toolbar { padding: 0 10px; }
  .toolbar-brand { gap: 8px; }
  .brand-mark { width: 30px; height: 30px; }
  .brand-name { font-size: .85rem; letter-spacing: .18em; }
  .brand-text { display: block; }
  .tool-btn { padding: 9px; min-width: 40px; min-height: 40px; justify-content: center; }
  .tool-btn.primary { padding: 9px 12px; }
  .tool-btn svg { width: 19px; height: 19px; }
  .zoom-level { min-width: 38px; font-size: .7rem; }
  /* Zoom group is rarely needed on mobile (pinch zoom works) — hide to save space */
  .tool-group { display: none; }
  /* The download keeps its primary look but loses the label */
  .tool-btn.primary .tool-label { display: none; }

  /* Stage : no side arrows on phones, full-bleed */
  .stage { grid-template-columns: 1fr; }
  .nav-arrow { display: none; }

  /* Hide the spread book entirely */
  .book-wrap { display: none; }

  /* Show the phone book */
  .phone-book { display: block; }
  .phone-book {
    --phone-pad: 14px;
    --phone-avail-w: calc(100vw  - (var(--phone-pad) * 2));
    --phone-avail-h: calc(var(--vh, 100vh) - var(--toolbar-h) - var(--footer-h) - (var(--phone-pad) * 2));
    /* Fit a single A4 page into the available area, maintaining aspect */
    --phone-h: min(var(--phone-avail-h), calc(var(--phone-avail-w) * var(--page-ratio)));
    --phone-w: calc(var(--phone-h) / var(--page-ratio));
    width: var(--phone-w);
    height: var(--phone-h);
  }

  /* Footer : page indicator stays, hint hidden */
  .hint { display: none; }
  .footer { padding: 6px 14px; gap: 2px; }
  .page-indicator { gap: 10px; font-size: .75rem; }
  .progress-track { width: clamp(120px, 40vw, 200px); height: 2px; }
  .page-label { font-size: .95rem; min-width: 0; max-width: 56vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .page-total { font-size: .68rem; }

  /* TOC : mobile becomes a bottom-sheet */
  .toc-overlay { align-items: flex-end; }
  .toc-panel {
    width: 100%;
    max-height: 82vh;
    border-radius: 18px 18px 0 0;
    padding: 26px 22px 26px;
    transform: translateY(60px);
    border-bottom: 0;
  }
  .toc-overlay.is-open .toc-panel { transform: translateY(0); }
  /* Drag-handle indicator */
  .toc-panel::before {
    content: '';
    position: absolute; top: 8px; left: 50%;
    transform: translateX(-50%);
    width: 44px; height: 4px;
    background: rgba(169,139,75,.3);
    border-radius: 4px;
  }
  .toc-close { top: 12px; right: 12px; width: 32px; height: 32px; }
  .toc-eyebrow { margin-top: 8px; }
  .toc-title { font-size: 1.6rem; margin-bottom: 18px; }
  .toc-item { grid-template-columns: 42px 1fr auto; gap: 12px; padding: 14px 4px; }
  .toc-num { font-size: 1.3rem; }
  .toc-label { font-size: .95rem; }
  .toc-desc { font-size: .76rem; }
  .toc-page { font-size: 1rem; }

  /* Show swipe hint briefly on first load */
  .swipe-hint { display: inline-flex; bottom: calc(var(--footer-h) + 14px); }
}

@media (max-width: 480px) {
  .brand-name { letter-spacing: .14em; }
  .toolbar-brand .brand-text { display: none; }
  .brand-mark { width: 32px; height: 32px; }
  .toc-title { font-size: 1.45rem; }
  .toc-item { grid-template-columns: 38px 1fr auto; gap: 10px; padding: 12px 4px; }
  .toc-num { font-size: 1.2rem; }
  .toc-label { font-size: .9rem; }
  .toc-desc { font-size: .72rem; line-height: 1.4; }
  .toc-page { font-size: .95rem; }
}

/* Landscape on phones — tighter vertical padding */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  :root { --toolbar-h: 46px; --footer-h: 48px; }
  .toolbar { padding: 0 8px; }
  .footer .hint { display: none; }
  .phone-book { --phone-pad: 8px; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .leaf, .m-page { transition: transform .35s ease; }
  .loader-mark { animation: none; }
}
