@import url('https://fonts.googleapis.com/css2?family=Oswald:wght@300;400&display=swap');

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

:root {
  --gold: #c8a84b;
  --gold-dim: rgba(200,168,75,0.45);
  --bar-h: 68px;
}

html, body {
  width: 100%; height: 100%;
  background: #000;
  overflow: hidden;
  font-family: 'Oswald', sans-serif;
  color: #fff;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* ══════════════════════════════════
   HEADER
══════════════════════════════════ */
#header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  z-index: 300;
  background: linear-gradient(to bottom, rgba(0,0,0,0.82), transparent);
  pointer-events: none;
}
#header-title {
  font-size: 0.58rem;
  font-weight: 300;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.22);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#fs-btn {
  pointer-events: all;
  background: transparent;
  border: 1px solid rgba(255,255,255,0.14);
  color: rgba(255,255,255,0.28);
  font-family: 'Oswald', sans-serif;
  font-size: 0.56rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 3px 9px;
  cursor: pointer;
  border-radius: 2px;
  transition: all 0.2s;
  flex-shrink: 0;
}
#fs-btn:hover { color: #fff; border-color: rgba(255,255,255,0.4); }

/* ══════════════════════════════════
   STAGE  – centred between top and bottom bar
══════════════════════════════════ */
#stage {
  position: fixed;
  top: 0;
  bottom: var(--bar-h);
  left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 12px 0;       /* small breathing room */
}

/* ══════════════════════════════════
   BOOK  – desktop (two pages)
══════════════════════════════════ */
#book {
  position: relative;
  display: flex;
  /* Use aspect-ratio so the browser calculates the other dimension.
     Two A4 pages side-by-side: width = height × √2 × 2 / √2 = height × √2
     i.e. aspect = √2 : 1  ≈  1.4142 : 1                              */
  aspect-ratio: 1.4142 / 1;
  /* Constrain to fit the available space, whichever is smaller */
  max-width: calc(100% - 100px);   /* leave room for nav arrows */
  max-height: 100%;
  width: auto;
  height: 100%;
  cursor: pointer;
  box-shadow:
    0 0 0 1px rgba(255,255,255,0.05),
    0 20px 70px rgba(0,0,0,0.95),
    0 50px 100px rgba(0,0,0,0.5);
}

/* single page: cover / back cover  */
#book.single {
  aspect-ratio: 0.7071 / 1;
}

/* ── static pages ── */
.book-page {
  width: 50%;
  height: 100%;
  overflow: hidden;
  background: #111;
  position: relative;
  flex-shrink: 0;
}
.book-page img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
#book.single .book-page        { width: 100%; }
#book.single #page-right-st    { display: none; }

/* inner-edge shadow instead of visible spine */
#page-left-st::after {
  content: '';
  position: absolute;
  top: 0; right: 0; bottom: 0; width: 20px;
  background: linear-gradient(to left, rgba(0,0,0,0.38), transparent);
  pointer-events: none; z-index: 1;
}
#page-right-st::before {
  content: '';
  position: absolute;
  top: 0; left: 0; bottom: 0; width: 20px;
  background: linear-gradient(to right, rgba(0,0,0,0.38), transparent);
  pointer-events: none; z-index: 1;
}
#book.single #page-left-st::after { display: none; }

/* ── flip layer (3D, desktop) ── */
#flip-layer {
  position: absolute;
  top: 0; bottom: 0;
  width: 50%;
  transform-style: preserve-3d;
  z-index: 10;
  display: none;
  pointer-events: none;
}
#flip-front, #flip-back {
  position: absolute; inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
}
#flip-front img, #flip-back img {
  width: 100%; height: 100%;
  object-fit: cover; display: block;
}
#flip-back { transform: rotateY(180deg); }
#flip-back img { filter: brightness(0.88); }
#flip-front::after {
  content: '';
  position: absolute; top: 0; right: 0; bottom: 0; width: 24px;
  background: linear-gradient(to left, rgba(0,0,0,0.30), transparent);
  pointer-events: none; z-index: 2;
}

@keyframes turnFwd {
  from { transform: perspective(2000px) rotateY(0deg); }
  to   { transform: perspective(2000px) rotateY(-180deg); }
}
@keyframes turnBwd {
  from { transform: perspective(2000px) rotateY(-180deg); }
  to   { transform: perspective(2000px) rotateY(0deg); }
}
#flip-layer.fwd {
  display: block;
  left: 50%; right: auto;
  transform-origin: left center;
  animation: turnFwd 0.52s cubic-bezier(0.77,0,0.175,1) forwards;
}
#flip-layer.bwd {
  display: block;
  left: auto; right: 50%;
  transform-origin: right center;
  animation: turnBwd 0.52s cubic-bezier(0.77,0,0.175,1) forwards;
}

/* ── mobile slide animation ── */
@keyframes slideInR {
  from { opacity: 0; transform: translateX(6%); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes slideInL {
  from { opacity: 0; transform: translateX(-6%); }
  to   { opacity: 1; transform: translateX(0); }
}
.slide-r #page-left-st { animation: slideInR 0.26s ease-out forwards; }
.slide-l #page-left-st { animation: slideInL 0.26s ease-out forwards; }

/* ── hover arrows (desktop only) ── */
.hover-zone {
  position: absolute;
  top: 0; bottom: 0; width: 68px;
  z-index: 20;
  display: flex; align-items: center; justify-content: center;
  opacity: 0;
  transition: opacity 0.22s;
  cursor: pointer;
}
#book:hover .hover-zone { opacity: 1; }
.hover-zone.left  { left: 0;  background: linear-gradient(to right, rgba(0,0,0,0.14), transparent); }
.hover-zone.right { right: 0; background: linear-gradient(to left,  rgba(0,0,0,0.14), transparent); }
.arrow-icon {
  width: 32px; height: 32px;
  border: 1.5px solid rgba(255,255,255,0.42);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px;
  color: rgba(255,255,255,0.68);
  background: rgba(0,0,0,0.28);
  backdrop-filter: blur(4px);
  transition: all 0.18s;
}
.hover-zone:hover .arrow-icon {
  border-color: var(--gold); color: var(--gold); transform: scale(1.12);
}

/* ══════════════════════════════════
   BOTTOM BAR
══════════════════════════════════ */
#bottom-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--bar-h);
  z-index: 300;
  background: linear-gradient(to top, rgba(0,0,0,0.94) 60%, transparent);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  padding-bottom: 8px;
}

#thumb-strip {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding: 0 10px;
  max-width: 100vw;
  scrollbar-width: none;
}
#thumb-strip::-webkit-scrollbar { display: none; }

.thumb {
  flex-shrink: 0;
  width: 26px; height: 37px;
  border: 1.5px solid transparent;
  border-radius: 1px;
  overflow: hidden;
  cursor: pointer;
  opacity: 0.3;
  transition: opacity 0.15s, border-color 0.15s;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb:hover { opacity: 0.7; }
.thumb.active { opacity: 1; border-color: var(--gold); box-shadow: 0 0 5px rgba(200,168,75,0.4); }

#nav-row {
  display: flex; align-items: center; gap: 10px;
}
#page-info {
  font-size: 0.62rem; font-weight: 300;
  letter-spacing: 0.14em; text-transform: uppercase;
  color: rgba(255,255,255,0.32);
  min-width: 80px; text-align: center;
}
.nav-btn {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.13);
  color: rgba(255,255,255,0.5);
  width: 30px; height: 30px;
  border-radius: 50%; font-size: 12px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.18s;
}
.nav-btn:hover:not(:disabled) {
  border-color: var(--gold-dim); color: var(--gold);
  background: rgba(255,255,255,0.09);
}
.nav-btn:disabled { opacity: 0.18; cursor: not-allowed; }

/* ══════════════════════════════════
   ZOOM OVERLAY
══════════════════════════════════ */
#zoom-overlay {
  position: fixed; inset: 0;
  z-index: 500;
  background: rgba(0,0,0,0.97);
  display: none;
  align-items: center;
  justify-content: center;
  touch-action: none;
  overflow: hidden;
}
#zoom-overlay.active { display: flex; }
#zoom-img {
  max-width: 100%; max-height: 100%;
  object-fit: contain;
  cursor: zoom-out;
  transform-origin: center center;
  transition: transform 0.05s linear;
}
#zoom-close {
  position: absolute; top: 12px; right: 12px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.2);
  color: #fff; width: 36px; height: 36px;
  border-radius: 50%; font-size: 17px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  z-index: 10; transition: background 0.2s;
}
#zoom-close:hover { background: rgba(255,255,255,0.18); }

/* ══════════════════════════════════
   MOBILE  ≤ 600px  –  single page
══════════════════════════════════ */
@media (max-width: 600px) {
  :root { --bar-h: 60px; }

  #stage {
    /* tighter padding on mobile, leave no horizontal gap */
    padding: 6px 6px 0;
  }

  #book {
    /* single A4: height / width = √2  →  aspect = 1 / √2 */
    aspect-ratio: 1 / 1.4142;
    /* fill width first, then constrain height */
    width: 100%;
    height: auto;
    max-width: 100%;
    max-height: calc(100svh - var(--bar-h) - 10px);
    /* if width-derived height is too tall, switch to height-based sizing */
    /* We use the smaller of: full-width or height-constrained width */
    /* CSS can't do this directly but the two constraints above handle it:
       browser picks whichever satisfies BOTH max-width and max-height.    */
    cursor: default;
  }

  /* Force single-page layout */
  #book .book-page      { width: 100% !important; }
  #book #page-right-st  { display: none !important; }
  #book #page-left-st::after { display: none !important; }

  /* No 3D flip on mobile – use slide */
  #flip-layer { display: none !important; }

  /* Hide desktop hover arrows */
  .hover-zone { display: none !important; }

  /* Slightly bigger tap targets */
  .nav-btn { width: 34px; height: 34px; font-size: 14px; }

  #header-title { display: none; }

  /* Thumbs a bit smaller on narrow screens */
  .thumb { width: 22px; height: 31px; }
}
