@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@200;300;400;500;600;700&family=Sora:wght@200;300;400;500;600;700&family=Space+Grotesk:wght@300;400;500;600;700&display=swap');

/* ════════════════════ MANGA LOADER ════════════════════ */
#loader {
  position: fixed; inset: 0; z-index: 9999;
  background: #111;
  overflow: hidden;
  transition: opacity .6s ease, visibility .6s ease;
}
#loader.fade-out { opacity: 0; visibility: hidden; }

/* ── 4-panel grid ── */
.mg-grid {
  position: absolute; inset: 0;
  display: grid;
  grid-template-columns: 5fr 3fr;
  grid-template-rows: 3fr 2fr;
  gap: 10px;
  padding: 10px;
}

.mg-panel {
  position: relative; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}

/* alternating paper / dark */
.mg-p1 { background: #f5f2ec; }   /* paper  — top-left  */
.mg-p2 { background: #0d0d0d; }   /* dark   — top-right */
.mg-p3 { background: #0d0d0d; }   /* dark   — bottom-left */
.mg-p4 { background: #f0ece4; }   /* paper  — bottom-right */

/* wipe-in from alternating sides */
.mg-p1 { animation: mg-wipe-r .4s cubic-bezier(.77,0,.18,1) .04s both; }
.mg-p2 { animation: mg-wipe-l .4s cubic-bezier(.77,0,.18,1) .14s both; }
.mg-p3 { animation: mg-wipe-r .4s cubic-bezier(.77,0,.18,1) .24s both; }
.mg-p4 { animation: mg-wipe-l .4s cubic-bezier(.77,0,.18,1) .34s both; }

@keyframes mg-wipe-r {
  from { clip-path: inset(0 100% 0 0); }
  to   { clip-path: inset(0 0%   0 0); }
}
@keyframes mg-wipe-l {
  from { clip-path: inset(0 0 0 100%); }
  to   { clip-path: inset(0 0 0 0%);   }
}

/* accent line bottom of p1 */
.mg-p1::after {
  content: ''; position: absolute;
  bottom: 0; left: 0; right: 0; height: 3px;
  background: #ff4d2d;
  transform: scaleX(0); transform-origin: left;
  animation: mg-stripe .5s ease .55s forwards;
}
@keyframes mg-stripe { to { transform: scaleX(1); } }

/* ── P1: Japanese vertical ── */
.mg-jp {
  font-family: 'Sora', sans-serif;
  font-weight: 700;
  /* panel row-1 ≈ 60vh; 6 chars × 9vh = 54vh — fits with margin */
  font-size: clamp(22px, 8.5vh, 72px);
  color: #111;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  letter-spacing: 0;
  line-height: 1;
  white-space: nowrap;
  opacity: 0;
  transform: translateX(16px);
  animation: mg-fade-up .5s ease .52s forwards;
}

/* ── P2: ARTBOOK vertical ── */
.mg-en {
  font-family: 'Sora', sans-serif;
  font-weight: 700;
  font-size: clamp(18px, 3vw, 36px);
  color: #fff;
  letter-spacing: 8px;
  text-transform: uppercase;
  writing-mode: vertical-rl;
  opacity: 0;
  animation: mg-fade-up .5s ease .6s forwards;
}

/* ── P3: loading label + bouncing dots ── */
.mg-p3 { flex-direction: column; gap: 10px; }

.mg-loading-label {
  font-family: 'Outfit', sans-serif;
  font-weight: 300;
  font-size: clamp(10px, 1.3vw, 13px);
  letter-spacing: 6px;
  text-transform: uppercase;
  color: rgba(255,255,255,.28);
  opacity: 0;
  animation: mg-fade-up .4s ease .7s forwards;
}

.mg-dots {
  display: flex; gap: 8px;
  opacity: 0;
  animation: mg-fade-up .4s ease .74s forwards;
}
.mg-dots span {
  width: clamp(6px, 1vw, 9px);
  height: clamp(6px, 1vw, 9px);
  border-radius: 50%;
  background: #ff4d2d;
  animation: mg-bounce .7s ease-in-out infinite;
}
.mg-dots span:nth-child(2) { animation-delay: .15s; background: #ff8a00; }
.mg-dots span:nth-child(3) { animation-delay: .30s; background: rgba(255,255,255,.25); }
@keyframes mg-bounce {
  0%,100% { transform: translateY(0);    opacity: 1; }
  50%      { transform: translateY(-7px); opacity: .5; }
}

/* ── P4: edition mark ── */
.mg-edition {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.mg-ed-label {
  font-family: 'Outfit', sans-serif;
  font-weight: 300;
  font-size: clamp(9px, 1.2vw, 13px);
  letter-spacing: 5px;
  text-transform: uppercase;
  color: rgba(0,0,0,.35);
  opacity: 0;
  animation: mg-fade-up .4s ease .6s forwards;
}
.mg-ed-year {
  font-family: 'Sora', sans-serif;
  font-weight: 700;
  font-size: clamp(28px, 4.5vw, 54px);
  color: #111;
  letter-spacing: 4px;
  line-height: 1;
  opacity: 0;
  transform: translateY(8px);
  animation: mg-slam .42s cubic-bezier(0.175, 0.885, 0.32, 1.275) .68s forwards;
}
.mg-ed-vol {
  font-family: 'Outfit', sans-serif;
  font-weight: 400;
  font-size: clamp(9px, 1.2vw, 13px);
  letter-spacing: 4px;
  text-transform: uppercase;
  color: #ff4d2d;
  opacity: 0;
  animation: mg-fade-up .4s ease .78s forwards;
}
@keyframes mg-slam   { to { opacity: 1; transform: none; } }
@keyframes mg-rule   { to { width: clamp(44px, 7vw, 80px); } }
@keyframes mg-fade-up { to { opacity: 1; transform: none; } }



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

:root {
  --bh: min(88vh, 900px);           /* book height — drives size */
  --bw: calc(var(--bh) * 0.732);    /* book width  — 1920×2624 ratio */
  --bd: clamp(52px, 6vw, 72px);     /* book depth  */

  --cover: #0f0f0f;
  --accent: #ffde24;
  --accent2: #ffde24;
  --title-overlay: rgba(0,0,0,0.55);
  --paper: #faf9f7;
  --paper-edge: #e8e4de;
  --ui-bg: rgba(12,12,12,.94);
  --ui-border: rgba(255,255,255,.07);
  --flip: .9s cubic-bezier(0.645, 0.045, 0.355, 1.000);
}

html, body {
  width: 100%; height: 100%;
  font-family: 'Outfit', sans-serif;
  background: #080808;
  color: #eee;
  overflow: hidden;
}
body { display: flex; align-items: center; justify-content: center; }

/* ── BG ── */
#bg {
  position: fixed; inset: 0; z-index: 0;
  background:
    radial-gradient(ellipse at 25% 15%, rgba(255,77,45,.04), transparent 50%),
    radial-gradient(ellipse at 75% 85%, rgba(255,138,0,.03), transparent 50%),
    #080808;
}

/* ═══════════ TOPBAR ═══════════ */
#topbar {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  z-index: 300;
  display: flex; gap: 2px;
  background: var(--ui-bg);
  backdrop-filter: blur(30px);
  border: 1px solid var(--ui-border);
  border-radius: 12px; padding: 5px;
}
.tab { 
  padding: 9px 24px; border: none; background: transparent;
  font-family: 'Outfit'; font-size: 11px; font-weight: 500;
  letter-spacing: 1.2px; text-transform: uppercase;
  color: #999; border-radius: 9px; cursor: pointer; transition: .2s;
  text-decoration: none; display: inline-flex; align-items: center;
  white-space: nowrap; gap: 7px;
}
/* Override SVG inline margin-right so gap drives spacing */
.tab svg { margin-right: 0 !important; vertical-align: middle; flex-shrink: 0; }
.tab:hover { color: #ddd; }
.tab.active { background: rgba(255,255,255,.08); color: #fff; }
/* Library back-link */
.tab-library { color: #888; gap: 2px; }
.tab-library:hover { color: var(--accent); }
/* Mobile-only elements hidden on desktop */
.mob-only { display: none !important; }
/* Floating editor-toggle replaced by in-topbar #btn-panel */
#editor-toggle { display: none !important; }
/* Hamburger wrapper: transparent on desktop so children flow inline in topbar flex */
.tb-head   { display: contents; }
.tb-links  { display: contents; }
.tb-hamburger { display: none; }

/* ═══════════ 3D SCENE ═══════════ */
#scene {
  position: relative; z-index: 1;
  perspective: 1800px;
  perspective-origin: 50% 42%;
  width: 100vw; height: 100vh;
  display: flex; align-items: center; justify-content: center;
  cursor: default;
}
/* Grab only over the actual closed book, not the whole viewport */
body.book-closed #closed { cursor: grab; }
body.book-closed #scene.dragging,
body.book-closed #scene.dragging #closed { cursor: grabbing; }
#opened { cursor: default; }
/* Sliding inner wrapper — transparent on desktop, slides on mobile */
#mob-inner {
  position: absolute; left: 0; top: 0;
  width: 100%; height: 100%;
}

/* Drag hint icon */
#drag-hint {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  z-index: 200;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 20px;
  background: var(--ui-bg); backdrop-filter: blur(24px);
  border: 1px solid var(--ui-border); border-radius: 12px;
  animation: hintPulse 2.5s ease-in-out infinite, hintFadeOut 6s ease forwards;
  pointer-events: none;
}
#drag-hint svg {
  width: 20px; height: 20px; stroke: var(--accent); fill: none; stroke-width: 1.5;
  animation: hintSwing 1.5s ease-in-out infinite;
}
#drag-hint span {
  font-family: 'Outfit'; font-size: 10px; letter-spacing: 1.5px;
  text-transform: uppercase; color: #777;
}
@keyframes hintSwing {
  0%, 100% { transform: rotate(-12deg); }
  50% { transform: rotate(12deg); }
}
@keyframes hintPulse {
  0%, 100% { opacity: .7; }
  50% { opacity: 1; }
}
@keyframes hintFadeOut {
  0%, 70% { opacity: 1; transform: translateX(-50%) translateY(0); }
  100% { opacity: 0; transform: translateX(-50%) translateY(10px); pointer-events: none; }
}

/* This is the rotation pivot for the whole book */
#book-root {
  transform-style: preserve-3d;
  transition: transform 1.2s cubic-bezier(.22,.68,.35,1);
  position: relative;
}

/* Floor shadow */
#shadow {
  position: absolute;
  bottom: calc(50% - var(--bh) / 2 - 60px);
  left: 50%; transform: translateX(-50%);
  width: 130%; height: 80px;
  background: radial-gradient(ellipse, rgba(0,0,0,.65) 0%, transparent 68%);
  filter: blur(20px);
  pointer-events: none; transition: opacity .3s;
  z-index: 0;
}

/* ═══════════════════════════════════════════════
   CLOSED BOOK — PROPER 3D CUBOID
   
   Box is W×H×D. Container is W×H, centered at its center.
   Each face is centered inside the container, then
   rotated + translated to its correct edge.
   
   Front:   translateZ(D/2)
   Back:    rotateY(180deg) translateZ(D/2)
   Left:    rotateY(-90deg) translateZ(W/2)   ← SPINE
   Right:   rotateY(90deg)  translateZ(W/2)   ← PAGE EDGE
   Top:     rotateX(90deg)  translateZ(H/2)
   Bottom:  rotateX(-90deg) translateZ(H/2)
   ═══════════════════════════════════════════════ */

#closed {
  width: var(--bw); height: var(--bh);
  transform-style: preserve-3d;
  position: relative;
}

/* All faces centered in parent, then transformed to edges */
.face {
  position: absolute;
  backface-visibility: hidden;
}

/* centering helpers for non-WxH faces */
.face-lr { /* left/right faces: D×H */
  width: var(--bd); height: var(--bh);
  left: calc((var(--bw) - var(--bd)) / 2);
  top: 0;
}
.face-tb { /* top/bottom faces: W×D */
  width: var(--bw); height: var(--bd);
  left: 0;
  top: calc((var(--bh) - var(--bd)) / 2);
}

/* ─── FRONT COVER ─── */
#cf {
  width: var(--bw); height: var(--bh);
  left: 0; top: 0;
  transform: translateZ(calc(var(--bd) / 2));
  background: var(--cover);
  border-radius: 0;
  overflow: hidden;
  display: flex; flex-direction: column;
  box-shadow: 0 10px 40px rgba(0,0,0,.5);
}
/* Light overlay */
#cf::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,.08) 0%, transparent 40%, rgba(0,0,0,.15) 100%);
  z-index: 1; pointer-events: none;
}
.cf-content {
  position: relative; z-index: 2;
  display: flex; flex-direction: column;
  height: 100%; padding: 44px 40px 40px;
}
.cf-label {
  font-family: 'Space Grotesk'; font-size: 9px; font-weight: 500;
  letter-spacing: 4px; text-transform: uppercase;
  color: rgba(255,255,255,.5); margin-bottom: auto;
  display: block; width: fit-content; max-width: calc(100% - 90px);
  background: var(--title-overlay);
  padding: 3px 10px; border-radius: 3px;
}
.cf-label:empty { display: none; }
.cf-title-block {
  margin-top: auto;
}
.cf-title {
  font-family: 'Sora'; font-weight: 700; font-size: 42px;
  line-height: 1.05; color: #fff;
  text-transform: uppercase; letter-spacing: -1px; margin-bottom: 12px;
}
.cf-title span {
  display: block; width: fit-content;
  background: var(--title-overlay);
  padding: 3px 12px; margin-bottom: 3px; border-radius: 3px;
}
.cf-title span:empty { display: none; }
.cf-title .thin { font-weight: 200; opacity: .9; }
.cf-subtitle {
  font-family: 'Outfit'; font-weight: 300; font-size: 12px;
  letter-spacing: 2px; color: rgba(255,255,255,.6);
  text-transform: uppercase; margin-bottom: 12px;
  display: block; width: fit-content; background: var(--title-overlay);
  padding: 2px 10px; border-radius: 3px;
}
.cf-subtitle:empty { display: none; }
.cf-author {
  font-family: 'Space Grotesk'; font-weight: 500; font-size: 13px;
  letter-spacing: 1px; color: #fff;
  display: flex; width: fit-content; align-items: center; gap: 12px;
  background: var(--title-overlay);
  padding: 5px 12px; border-radius: 3px;
}
.cf-author:empty { display: none; }
.cf-author:has(span:empty) { display: none; }
.cf-author::before {
  content: ''; width: 30px; height: 2px; background: #fff; opacity: .4;
}
.cf-year {
  position: absolute; top: 40px; right: 40px; z-index: 4;
  font-family: 'Space Grotesk'; font-size: 11px; font-weight: 600;
  color: rgba(255,255,255,.4); letter-spacing: 2px;
  background: var(--title-overlay); padding: 3px 10px; border-radius: 3px;
}
.cf-year:empty { display: none; }
.cf-stamp {
  position: absolute; bottom: 40px; right: 40px; z-index: 2;
  width: 44px; height: 44px;
  border: 2px solid rgba(255,255,255,.2); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.cf-stamp-inner {
  font-family: 'Sora'; font-weight: 700; font-size: 14px;
  color: rgba(255,255,255,.3);
}

/* ─── BACK COVER ─── */
#cb {
  width: var(--bw); height: var(--bh);
  left: 0; top: 0;
  transform: rotateY(180deg) translateZ(calc(var(--bd) / 2));
  background: var(--cover);
  border-radius: 0;
  overflow: hidden;
  display: flex; flex-direction: column;
  align-items: flex-start; justify-content: flex-end;
  padding: 48px 44px;
  box-shadow: 0 10px 40px rgba(0,0,0,.5);
}

#cb::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(255,255,255,.03), transparent 40%, rgba(0,0,0,.15));
  pointer-events: none;
}
.cb-text-block {
  margin-bottom: 24px;
  position: relative; z-index: 1;
}
.cb-quote {
  font-family: 'Outfit'; font-weight: 300; font-size: 15px;
  line-height: 2.4; color: #666;
  display: inline;
  background: var(--title-overlay);
  padding: 2px 8px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  border-radius: 2px;
}
.cb-quote:empty { display: none; }
.cb-attr {
  font-family: 'Space Grotesk'; font-size: 10px; font-weight: 500;
  letter-spacing: 2px; text-transform: uppercase; color: #444;
  display: block; width: fit-content; background: var(--title-overlay);
  padding: 2px 8px; border-radius: 2px;
  position: relative; z-index: 1; margin-top: 10px;
}
.cb-attr:empty { display: none; }
.cb-logo {
  position: absolute; top: 44px; left: 44px;
  font-family: 'Space Grotesk'; font-size: 9px; font-weight: 500;
  letter-spacing: 3px; text-transform: uppercase; color: #333; z-index: 1;
  background: var(--title-overlay); padding: 3px 10px; border-radius: 3px;
}
.cb-logo:empty { display: none; }

/* ─── SPINE (left face) ─── */
#cs {
  transform: rotateY(-90deg) translateZ(calc(var(--bw) / 2));
  background: var(--cover);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 18px;
  overflow: hidden;
}
/* Accent bars top & bottom */
#cs::before {
  content: ''; position: absolute; top: 0; left: 0;
  width: 100%; height: 5px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
}
#cs::after {
  content: ''; position: absolute; bottom: 0; left: 0;
  width: 100%; height: 5px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
}
.sp-band-top, .sp-band-bot {
  position: absolute; left: 0; width: 100%; height: 6px; z-index: 2;
}
.sp-band-top {
  top: 5px;
  background: repeating-linear-gradient(90deg,
    var(--accent) 0 3px, var(--accent2) 3px 6px);
  opacity: .4;
}
.sp-band-bot {
  bottom: 5px;
  background: repeating-linear-gradient(90deg,
    var(--accent) 0 3px, var(--accent2) 3px 6px);
  opacity: .4;
}
.sp-title {
  writing-mode: vertical-rl; text-orientation: mixed;
  font-family: 'Sora'; font-weight: 600; font-size: 13px;
  letter-spacing: 4px; text-transform: uppercase; color: #fff;
}
.sp-dot {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--accent); opacity: .8;
}
.sp-author {
  writing-mode: vertical-rl; text-orientation: mixed;
  font-family: 'Outfit'; font-weight: 400; font-size: 9px;
  letter-spacing: 3px; text-transform: uppercase; color: #888;
}

/* ─── PAGE EDGES ─── */
/* Right (fore-edge) — stacked pages with concave depth shadow */
#er {
  transform: rotateY(90deg) translateZ(calc(var(--bw) / 2));
  background-color: #ece6da;
  background-image:
    /* Individual page lines */
    repeating-linear-gradient(
      180deg,
      transparent        0px,
      transparent        1.6px,
      rgba(0,0,0,.07)    1.6px,
      rgba(0,0,0,.07)    2px
    ),
    /* Concave depth: darker at outer edge, lighter center */
    linear-gradient(
      90deg,
      rgba(0,0,0,.22) 0%,
      rgba(0,0,0,.05) 18%,
      rgba(255,255,255,.12) 50%,
      rgba(0,0,0,.06) 82%,
      rgba(0,0,0,.20) 100%
    );
  box-shadow:
    inset -4px 0 10px rgba(0,0,0,.18),
    inset  4px 0 6px  rgba(0,0,0,.10);
}
/* Top-to-bottom sheen */
#er::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(
    180deg,
    rgba(255,255,255,.22) 0%,
    transparent           35%,
    transparent           70%,
    rgba(0,0,0,.12)       100%
  );
  pointer-events: none;
}

/* Top edge */
#et {
  transform: rotateX(90deg) translateZ(calc(var(--bh) / 2));
  background-color: #e8e2d6;
  background-image:
    repeating-linear-gradient(
      90deg,
      transparent        0px,
      transparent        1.6px,
      rgba(0,0,0,.06)    1.6px,
      rgba(0,0,0,.06)    2px
    ),
    linear-gradient(180deg, rgba(0,0,0,.18) 0%, rgba(0,0,0,.04) 100%);
  box-shadow: inset 0 -3px 8px rgba(0,0,0,.15), inset 0 3px 5px rgba(0,0,0,.08);
}

/* Bottom edge */
#eb {
  transform: rotateX(-90deg) translateZ(calc(var(--bh) / 2));
  background-color: #e8e2d6;
  background-image:
    repeating-linear-gradient(
      90deg,
      transparent        0px,
      transparent        1.6px,
      rgba(0,0,0,.06)    1.6px,
      rgba(0,0,0,.06)    2px
    ),
    linear-gradient(180deg, rgba(0,0,0,.04) 0%, rgba(0,0,0,.18) 100%);
  box-shadow: inset 0 4px 10px rgba(0,0,0,.18);
}

/* ═══════════ PAGE-TURN HOVER ZONES ═══════════ */
.pg-turn-zone {
  position: absolute; top: 72px; bottom: 72px;
  width: 70px; z-index: 600;
  display: flex; align-items: center;
  pointer-events: none; /* don't block page content — arrow inside handles click */
}
.pg-turn-prev { left: 0; justify-content: flex-start; padding-left: 12px; }
.pg-turn-next { right: 0; justify-content: flex-end; padding-right: 12px; }
.pg-turn-arrow {
  width: 44px; height: 44px; border-radius: 50%;
  background: rgba(0,0,0,.55); backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,.12);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transform: scale(.85);
  transition: opacity .2s, transform .2s;
  cursor: pointer;
  pointer-events: auto; /* only the visible arrow circle is clickable */
}
.pg-turn-arrow svg { width: 18px; height: 18px; stroke: #fff; fill: none; stroke-width: 2; }
.pg-turn-zone.hovered .pg-turn-arrow,
.pg-turn-zone:hover .pg-turn-arrow { opacity: 1; transform: scale(1); }
.pg-turn-prev.hovered .pg-turn-arrow,
.pg-turn-prev:hover .pg-turn-arrow { transform: scale(1) translateX(4px); }
.pg-turn-next.hovered .pg-turn-arrow,
.pg-turn-next:hover .pg-turn-arrow { transform: scale(1) translateX(-4px); }
/* Disabled state */
.pg-turn-zone.disabled { pointer-events: none; }
.pg-turn-zone.disabled .pg-turn-arrow { opacity: 0 !important; }

/* ═══════════ OPEN BOOK ═══════════ */
#opened {
  display: none;
  position: relative;
  width: calc(var(--bw) * 2);
  height: var(--bh);
}
/* Spine gutter — always on top, even above flipping sheet */
#opened::after {
  content: '';
  position: absolute;
  top: 0; bottom: 0;
  left: var(--bw);
  transform: translateX(-50%);
  width: 3px;
  background: #1a1a1a;
  z-index: 10001;
  pointer-events: none;
}
#left-base {
  position: absolute; left: 0; top: 0;
  width: var(--bw); height: var(--bh);
  background: #ffffff;
  border-radius: 0;
  overflow: hidden;
  z-index: 200;
  pointer-events: auto;
}
/* Right-base: desktop hidden, mobile right panel */
#right-base {
  display: none;
  position: absolute; left: var(--bw); top: 0;
  width: var(--bw); height: var(--bh);
  background: #ffffff;
  border-radius: 0;
  overflow: hidden;
  z-index: 200;
  pointer-events: auto;
}
.sheet {
  position: absolute;
  width: var(--bw); height: var(--bh);
  right: 0; top: 0;
  /* perspective(1800px) on the sheet itself = perspective centered on right half, like the demo */
  transform: perspective(1800px) rotateY(0deg);
  transform-origin: left center;
  transform-style: preserve-3d;
  transition: transform var(--flip);
  will-change: transform;
  cursor: default;
  pointer-events: none;
}
.sheet.flipped { transform: perspective(1800px) rotateY(-180deg); }
.pg {
  position: absolute; width: 100%; height: 100%;
  backface-visibility: hidden;
  background: #ffffff; overflow: hidden;
  pointer-events: none;
}
.pg-back { pointer-events: none; }
.sheet.flipped .pg-front { pointer-events: none; }
.sheet.flipped .pg-back  { pointer-events: none; }
.sheet .pg-front         { pointer-events: none; }
.sheet.sheet--active .pg-front { pointer-events: auto; }
.pg-front {
  border-radius: 0;
  border-right: 1px solid var(--paper-edge);
}
.pg-back {
  transform: rotateY(180deg);
  border-radius: 0;
  background: #ffffff;
}

/* ═══════════ PAGE LAYOUTS ═══════════ */
.pg-inner {
  width: 100%; height: 100%;
  display: flex; flex-direction: column;
  padding: 20px 15px;
  position: relative;
}
.art-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px; flex-shrink: 0;
}
.art-title {
  font-family: 'Outfit'; font-weight: 500; font-size: 13px; color: #333;
  border: none; outline: none; background: transparent; max-width: 70%;
}
.art-num {
  font-family: 'Space Grotesk'; font-weight: 500; font-size: 10px; color: #ccc;
  border: none; outline: none; background: transparent; text-align: right; width: 40px;
  cursor: default;
}
body:not(.view-mode) .art-num {
  cursor: text; border-bottom: 1px dashed #ddd; transition: border-color .2s;
}
body:not(.view-mode) .art-num:hover { border-color: var(--accent); color: var(--accent); }
body:not(.view-mode) .art-num:focus { border-color: var(--accent); color: var(--accent); outline: none; }
.art-frame {
  flex: 1;
  position: relative;
  background: #ffffff; border-radius: 3px;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; cursor: pointer; transition: .3s;
  min-height: 0;
}
.art-frame:hover { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.art-frame img {
  position: absolute; inset: 0;
  width: 100%; height: 100%; object-fit: cover;
  transform: translateZ(0); image-rendering: auto;
  display: block;
}
.ph {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  pointer-events: none;
}
.ph svg { width: 32px; height: 32px; stroke: #d5d0c8; fill: none; stroke-width: 1.2; }
.ph span { font-family: 'Outfit'; font-size: 9px; letter-spacing: 2px; text-transform: uppercase; color: #c5c0b8; }
.art-foot { margin-top: 10px; flex-shrink: 0; }
.art-cap {
  font-family: 'Outfit'; font-weight: 300; font-size: 9px;
  letter-spacing: 1.5px; text-transform: uppercase; color: #bbb;
  border: none; outline: none; background: transparent; text-align: center; width: 100%;
}

.layout-halftitle { align-items: center; justify-content: center; text-align: center; gap: 10px; }
.ht-label { font-family: 'Space Grotesk'; font-size: 9px; font-weight: 500; letter-spacing: 4px; text-transform: uppercase; color: #ccc; }
.ht-label:empty { display: none; }
.ht-title1 { font-family: 'Outfit'; font-weight: 300; font-size: 13px; color: #999; letter-spacing: 3px; text-transform: uppercase; border: none; outline: none; background: transparent; text-align: center; width: 85%; }
.ht-title2 { font-family: 'Sora'; font-weight: 600; font-size: 26px; color: #222; text-transform: uppercase; letter-spacing: 1px; line-height: 1.15; border: none; outline: none; background: transparent; text-align: center; width: 85%; }
.ht-sub { font-family: 'Outfit'; font-weight: 300; font-size: 11px; letter-spacing: 2px; color: #aaa; border: none; outline: none; background: transparent; text-align: center; width: 90%;}
.ht-line { width: 30px; height: 2px; background: var(--accent); opacity: .5; border-radius: 1px; }

.layout-dedication { align-items: center; justify-content: center; text-align: center; }
.ded-label { font-family: 'Space Grotesk'; font-size: 8px; font-weight: 500; letter-spacing: 4px; text-transform: uppercase; color: #ccc; margin-bottom: 24px; }
.ded-text { font-family: 'Outfit'; font-weight: 300; font-size: 16px; line-height: 2; color: #555; max-width: 300px; border: none; outline: none; background: transparent; text-align: center; resize: none; width: 100%; min-height: 100px; }

.layout-toc { padding: 40px 38px; }
.toc-label { font-family: 'Space Grotesk'; font-size: 8px; font-weight: 500; letter-spacing: 4px; text-transform: uppercase; color: #ccc; margin-bottom: 6px; }
.toc-title { font-family: 'Sora'; font-weight: 600; font-size: 20px; color: #222; margin-bottom: 24px; text-transform: uppercase; letter-spacing: 1px; }
.toc-list { list-style: none; flex: 1; overflow-y: auto; }
.toc-row { display: flex; align-items: baseline; padding: 9px 0; border-bottom: 1px solid #f0ece6; cursor: pointer; transition: .2s; }
.toc-row:hover .toc-name { color: var(--accent); }
.toc-idx { font-family: 'Space Grotesk'; font-size: 10px; font-weight: 500; color: #ddd; width: 28px; flex-shrink: 0; }
.toc-name { font-family: 'Outfit'; font-weight: 400; font-size: 13px; color: #444; flex: 1; transition: .2s; }
.toc-dots { flex: 1; min-width: 20px; border-bottom: 1px dotted #e0dbd4; margin: 0 8px; align-self: center; }
.toc-pg { font-family: 'Space Grotesk'; font-size: 10px; font-weight: 500; color: #ccc; }

.layout-blank { align-items: center; justify-content: center; }

/* ─── Text page ─── */
.layout-text {
  align-items: center; justify-content: center;
  text-align: center; padding: 52px 48px;
  position: relative;
}
.pg-text-title {
  font-family: 'Space Grotesk'; font-size: 9px; font-weight: 500;
  letter-spacing: 4px; text-transform: uppercase; color: #ccc;
  border: none; outline: none; background: transparent; width: 100%;
  margin-bottom: 32px; flex-shrink: 0; text-align: center;
}
.pg-text-body {
  font-family: 'Outfit'; font-weight: 300; font-size: 20px;
  line-height: 1.2; color: #888; font-style: italic;
  border: none; outline: none; background: transparent;
  width: 100%;
  padding: 0; min-height: 40px; max-height: 70%;
  flex-shrink: 0; flex-grow: 0;
  overflow-y: auto; overflow-wrap: break-word;
  cursor: text;
}

/* Alignment toolbar — only in edit mode */
.pg-align-toolbar {
  display: none;
  align-items: center; gap: 3px;
}
body:not(.view-mode) .pg-align-toolbar { display: flex; }

.pg-align-btn {
  width: 20px; height: 20px; border-radius: 3px;
  border: 1px solid #e0dbd4; background: #fff;
  font-size: 11px; color: #bbb; line-height: 1;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  padding: 0; transition: .15s; flex-shrink: 0;
}
body.view-mode .pg-align-btn { display: none; }
.pg-align-btn:hover  { border-color: var(--accent); color: var(--accent); }
.pg-align-btn.active { border-color: var(--accent); background: var(--accent); color: #fff; }
/* Flip the right-align icon */
.pg-align-btn[data-align="right"] { transform: scaleX(-1); }
/* Separator between align and format buttons */
.pg-toolbar-sep {
  width: 1px; height: 12px; background: #e0dbd4;
  margin: 0 2px; flex-shrink: 0;
}
/* Bold / italic buttons */
.pg-fmt-btn {
  width: 20px; height: 20px; border-radius: 3px;
  border: 1px solid #e0dbd4; background: #fff;
  font-size: 11px; color: #bbb; line-height: 1;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  padding: 0; transition: .15s; flex-shrink: 0;
  font-family: Georgia, serif;
}
body.view-mode .pg-fmt-btn { display: none; }
.pg-fmt-btn:hover { border-color: var(--accent); color: var(--accent); }
/* Type toggle button — only visible in edit mode */
.pg-type-btn {
  display: none;
  width: 22px; height: 22px; border-radius: 4px;
  border: 1px solid #e0dbd4; background: #fff;
  font-family: 'Outfit'; font-size: 10px; color: #aaa;
  cursor: pointer; align-items: center; justify-content: center;
  flex-shrink: 0; transition: .2s;
  padding: 0;
}
body:not(.view-mode) .pg-type-btn { display: flex; }
.pg-type-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ═══════════ BOTTOM NAV ═══════════ */
#nav {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  z-index: 300;
  display: none; align-items: center; gap: 8px;
  background: var(--ui-bg); backdrop-filter: blur(30px);
  border: 1px solid var(--ui-border); border-radius: 14px; padding: 10px 22px;
}
.nav-btn {
  width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid var(--ui-border); background: transparent; color: #999;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: .2s;
}
.nav-btn:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-btn:disabled { opacity: .2; pointer-events: none; }
.nav-btn svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 1.8; }
/* Edit-only controls — hidden in view mode */
body.view-mode .nav-edit-only { display: none !important; }
body.view-mode #mob-editor-btn,
body.view-mode #btn-panel { display: none !important; }
body.auth-pending .nav-edit-only,
body.auth-pending #mode-toggle,
body.auth-pending #mob-editor-btn,
body.auth-pending #btn-panel,
body.auth-pending #btn-open-fab,
body.auth-pending #editor-toggle { display: none !important; }
#btn-add-spread:not(:disabled) { color: var(--accent); border-color: var(--accent); }
#btn-add-spread:not(:disabled):hover { background: rgba(255,77,45,.12); }
#btn-del-spread:not(:disabled) { color: #888; }
#btn-del-spread:not(:disabled):hover { background: rgba(255,77,45,.08); color: var(--accent); border-color: var(--accent); }
.nav-info {
  min-width: 90px; text-align: center;
  font-family: 'Space Grotesk'; font-size: 10px; font-weight: 500;
  letter-spacing: 1.5px; text-transform: uppercase; color: #999;
}
.nav-div { width: 1px; height: 20px; background: var(--ui-border); margin: 0 6px; }
.nav-close {
  width: 30px; height: 30px; border-radius: 50%;
  border: 1px solid var(--ui-border); background: transparent; color: #999;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: .2s;
}
.nav-close:hover { background: rgba(255,77,45,.12); color: var(--accent); }
.nav-close svg { width: 13px; height: 13px; stroke: currentColor; fill: none; stroke-width: 1.8; }

/* Open Book FAB — shown when book is closed, hidden when open */
#btn-open-fab {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  z-index: 300;
  display: none; align-items: center; gap: 8px;
  background: var(--ui-bg); backdrop-filter: blur(30px);
  border: 1px solid var(--ui-border); border-radius: 999px;
  padding: 12px 28px;
  font-family: 'Space Grotesk'; font-size: 11px; font-weight: 500;
  letter-spacing: 2px; text-transform: uppercase; color: #999;
  cursor: pointer; transition: background .2s, color .2s, box-shadow .2s;
  white-space: nowrap;
}
#btn-open-fab:hover { background: rgba(255,255,255,.12); color: #fff; box-shadow: 0 4px 24px rgba(0,0,0,.18); }
#btn-open-fab svg { width: 16px; height: 16px; stroke: currentColor; flex-shrink: 0; }
body.book-closed #btn-open-fab { display: flex; }
body:not(.book-closed) #btn-open-fab { display: none !important; }

/* Prevent text selection while dragging */
body.dragging, body.dragging * { user-select: none !important; -webkit-user-select: none !important; }

/* View mode — no pointer/text cursors on editable page elements */
body.view-mode .pg-inner input,
body.view-mode .pg-inner textarea { pointer-events: none; cursor: default; }
body.view-mode .art-frame { cursor: zoom-in; }
body.view-mode .art-frame:hover { border-color: transparent; box-shadow: none; }
body.view-mode .art-frame .ph { display: none; }

/* ═══════════ LIGHTBOX ═══════════ */
#lightbox {
  display: none; position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,.93); backdrop-filter: blur(12px);
  align-items: center; justify-content: center;
  animation: lbFadeIn .2s ease;
}
#lightbox.open { display: flex; }
@keyframes lbFadeIn { from { opacity: 0; } to { opacity: 1; } }
#lb-img {
  max-width: 88vw; max-height: 88vh;
  object-fit: contain; border-radius: 4px;
  box-shadow: 0 30px 80px rgba(0,0,0,.8);
  animation: lbZoomIn .25s cubic-bezier(.22,.68,.35,1);
}
@keyframes lbZoomIn { from { transform: scale(.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }
#lb-close {
  position: absolute; top: 20px; right: 24px;
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid rgba(255,255,255,.15); background: rgba(255,255,255,.07);
  color: #fff; font-size: 20px; cursor: pointer; transition: .2s;
  display: flex; align-items: center; justify-content: center;
}
#lb-close:hover { background: rgba(255,77,45,.25); border-color: var(--accent); }
#lb-caption {
  position: absolute; bottom: 30px; left: 50%; transform: translateX(-50%);
  font-family: 'Outfit'; font-size: 11px; letter-spacing: 2px; text-transform: uppercase;
  color: rgba(255,255,255,.35); white-space: nowrap;
}

/* Editable */
[contenteditable]:focus, input:focus, textarea:focus {
  outline: none; box-shadow: 0 0 0 1.5px var(--accent); border-radius: 2px;
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

.topbar-sep { width: 1px; height: 20px; background: var(--ui-border); margin: 0 4px; align-self: center; }
.mode-tab {
  color: #888;
  width: 72px;   /* fixed — never resizes */
  padding-left: 10px; padding-right: 10px;
  display: flex; align-items: center; justify-content: center;
}
.mode-icon { display: none; align-items: center; gap: 5px; white-space: nowrap; }
.mode-icon svg { flex-shrink: 0; vertical-align: middle; }
#mode-toggle[data-mode="edit"] .mode-edit { display: flex; }
#mode-toggle[data-mode="view"] .mode-view { display: flex; }
#mode-toggle[data-mode="view"] { color: var(--accent); }

/* Responsive — height shrinks, width follows ratio */
@media (max-width: 1100px) { :root { --bh: min(82vh, 720px); } }

/* ═══════════ EDITOR PANEL ═══════════ */
#editor-toggle {
  position: fixed; top: 20px; right: 20px; z-index: 400;
  width: 40px; height: 40px; border-radius: 10px;
  background: var(--ui-bg); backdrop-filter: blur(30px);
  border: 1px solid var(--ui-border);
  color: #888; cursor: pointer; transition: .2s;
  display: flex; align-items: center; justify-content: center;
}
#editor-toggle:hover { color: #fff; background: rgba(255,255,255,.08); }
#editor-toggle svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.6; }

#editor {
  position: fixed; top: 0; right: -360px; z-index: 350;
  width: 340px; height: 100vh;
  background: var(--ui-bg); backdrop-filter: blur(40px);
  border-left: 1px solid var(--ui-border);
  transition: right .4s cubic-bezier(.22,.68,.35,1);
  overflow-y: auto; padding: 70px 24px 30px;
  scrollbar-width: thin; scrollbar-color: #333 transparent;
}
#editor.open { right: 0; }

/* Admin-only editor section — hidden in view mode */
body.view-mode .ed-section-admin { display: none; }
.ed-btn-active {
  width: 100%; padding: 9px 14px;
  background: rgba(255,255,255,.04); border: 1px solid var(--ui-border);
  border-radius: 8px; color: #888;
  font-family: 'Outfit'; font-size: 12px; font-weight: 400; letter-spacing: .5px;
  cursor: pointer; transition: .2s;
  display: flex; align-items: center; gap: 8px;
}
.ed-btn-active svg { fill: currentColor; flex-shrink: 0; }
.ed-btn-active:hover { border-color: var(--accent); color: var(--accent); }

.ed-section { margin-bottom: 28px; }
.ed-section-title {
  font-family: 'Space Grotesk'; font-size: 9px; font-weight: 600;
  letter-spacing: 3px; text-transform: uppercase; color: var(--accent);
  margin-bottom: 14px;
  display: flex; align-items: center; gap: 8px;
}
.ed-section-title::after {
  content: ''; flex: 1; height: 1px; background: var(--ui-border);
}
.ed-field { margin-bottom: 12px; }
.ed-label {
  font-family: 'Outfit'; font-size: 10px; font-weight: 500;
  letter-spacing: 1px; text-transform: uppercase; color: #555;
  margin-bottom: 5px; display: block;
}
.ed-input {
  width: 100%; padding: 9px 12px;
  background: rgba(255,255,255,.04); border: 1px solid var(--ui-border);
  border-radius: 8px; color: #ddd;
  font-family: 'Outfit'; font-size: 13px; font-weight: 400;
  transition: border-color .2s;
}
.ed-input:focus { outline: none; border-color: var(--accent); }
textarea.ed-input { resize: vertical; min-height: 60px; }

.ed-img-upload {
  width: 100%; height: 80px;
  border: 1.5px dashed rgba(255,255,255,.12); border-radius: 8px;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  color: #555; cursor: pointer; transition: .2s;
  font-family: 'Outfit'; font-size: 10px; letter-spacing: 1px; text-transform: uppercase;
  position: relative; overflow: hidden;
}
.ed-img-upload:hover { border-color: var(--accent); color: var(--accent); }
.ed-img-upload svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.5; flex-shrink: 0; }
.ed-img-upload img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
  border-radius: 7px; opacity: .6;
}
.ed-img-upload input { display: none; }

.ed-color-row {
  display: flex; align-items: center; gap: 10px;
}
.ed-color {
  -webkit-appearance: none; appearance: none;
  width: 36px; height: 36px; border: 2px solid var(--ui-border);
  border-radius: 8px; cursor: pointer; background: transparent;
  padding: 2px;
}
.ed-color::-webkit-color-swatch-wrapper { padding: 0; }
.ed-color::-webkit-color-swatch { border: none; border-radius: 5px; }
.ed-color::-moz-color-swatch { border: none; border-radius: 5px; }
.ed-color-val {
  font-family: 'Space Grotesk'; font-size: 11px; font-weight: 500;
  color: #666; letter-spacing: 1px; text-transform: uppercase;
}
@media (max-width: 900px)  { :root { --bh: min(80vh, 680px); --bd: 48px; } }

/* ═══════════ MOBILE ═══════════ */
@media (max-width: 700px) {
  :root { --bh: min(72vh, 520px); --bw: min(calc(var(--bh) * 0.732), 88vw); --bd: 40px; }

  /* ── Topbar: hamburger layout ── */
  #topbar {
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    flex-direction: column;
    gap: 0;
    padding: 2px 4px;
    max-height: 52px;
    overflow: hidden;
    transition: max-height .3s ease;
    border-radius: 14px;
  }
  #topbar.mob-open { max-height: 640px; }

  .tb-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    height: 48px;
    flex-shrink: 0;
  }
  .tb-hamburger {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 8px;
    flex-shrink: 0;
  }
  .tb-hamburger span {
    display: block;
    width: 18px; height: 1.5px;
    background: #aaa;
    border-radius: 2px;
    transition: transform .2s, opacity .2s;
  }
  .tb-hamburger.open span:nth-child(1) { transform: translateY(6.5px) rotate(45deg); }
  .tb-hamburger.open span:nth-child(2) { opacity: 0; }
  .tb-hamburger.open span:nth-child(3) { transform: translateY(-6.5px) rotate(-45deg); }

  .tb-links {
    display: flex;
    flex-direction: column;
    width: 100%;
    padding: 0 2px 10px;
    gap: 2px;
  }
  #topbar:not(.mob-open) .tb-links { display: none; }
  .topbar-sep { display: none !important; }
  .tab {
    padding: 12px 14px;
    font-size: 11px;
    width: 100%;
    justify-content: flex-start;
    border-radius: 8px;
    color: #bbb;
    gap: 10px;
  }
  .tab.active { color: #fff; }
  .tab-brand { color: #999 !important; }

  /* ── Open book: individual panel slide ── */
  body:not(.book-closed) #opened {
    width: var(--bw) !important;
    overflow: hidden;
  }
  /* mob-inner: transparent wrapper, no special sizing */
  body:not(.book-closed) #mob-inner {
    position: absolute; left: 0; top: 0;
    width: 100%; height: 100%;
  }
  /* Both panels overlap at left:0 -- incoming (#right-base) always on top */
  body:not(.book-closed) #left-base,
  body:not(.book-closed) #right-base {
    left: 0 !important;
  }
  body:not(.book-closed) #right-base {
    display: block !important;
    z-index: 201 !important;
  }
  body:not(.book-closed) .sheet { display: none !important; }
  body:not(.book-closed) #opened::after { display: none !important; }
  /* Hide desktop hover-zones — use bottom nav */
  .pg-turn-zone { display: none !important; }

  /* Flatten 3D perspective for open book */
  body:not(.book-closed) #scene { perspective: none; }
  body:not(.book-closed) #book-root { transform: none !important; }

  /* Hide extras */
  #drag-hint { display: none !important; }
  #shadow    { display: none !important; }

  /* Editor toggle gone — now in topbar */
  .mob-only { display: flex !important; }

  /* Bottom nav: tighter */
  #nav { bottom: 14px; padding: 8px 14px; gap: 4px; }
  .nav-btn { width: 30px; height: 30px; }
  .nav-close { width: 26px; height: 26px; }
  .nav-info { min-width: 60px; font-size: 9px; letter-spacing: 1px; }
  .nav-div { margin: 0 3px; }

  .pg-text-body { font-size: 16px; }
  .layout-text { padding: 28px 22px; }
  .pg-text-title { margin-bottom: 18px; }

  /* TOC: scale down for single-page mobile view */
  .layout-toc { padding: 22px 18px; }
  .toc-title { font-size: 14px; margin-bottom: 14px; }
  .toc-label { margin-bottom: 4px; }
  .toc-row { padding: 6px 0; }
  .toc-name { font-size: 11px; }
  .toc-idx, .toc-pg { font-size: 9px; }

  /* Open FAB: tighter on mobile */
  #btn-open-fab { padding: 10px 24px; font-size: 10px; }
}

@media (max-width: 380px) {
  #nav { padding: 6px 8px; gap: 10px; border-radius: 10px; }
  .nav-btn { width: 26px; height: 26px; }
  .nav-btn svg { width: 12px; height: 12px; }
  .nav-close { width: 22px; height: 22px; }
  .nav-info { min-width: 48px; font-size: 8px; letter-spacing: .5px; }
  .nav-div { display: none; }
}
