:root{
  --bg:#0f1115;
  --paper:#ffffff;
  --ink:#111318;
  --muted:rgba(255,255,255,.7);
  --shadow:0 20px 60px rgba(0,0,0,.45);
  --radius:18px;

  /* BOOK SIZE */
  --w: min(96vw, 1120px);
  --h: min(78vh, 1180px);

  /* SPREAD */
  --spine:16px;
}

*{ box-sizing:border-box; }
html,body{ height:auto; }

body{
  margin:0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
  background: radial-gradient(1200px 800px at 50% 20%, #1b2140 0%, var(--bg) 55%, #090a0d 100%);
  color:#fff;
  overflow-x:hidden;
  overflow-y:auto;
}

/* =========================
   TOP BAR
========================= */
.topbar{
  position:sticky;
  top:0;
  z-index:50;
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:14px 16px;
  background:rgba(12,14,18,.65);
  backdrop-filter:blur(12px);
  border-bottom:1px solid rgba(255,255,255,.08);
}

.brand{
  font-weight:900;
  letter-spacing:.12em;
  font-size:14px;
  padding:8px 10px;
  border:1px solid rgba(255,255,255,.16);
  border-radius:999px;
}

.controls{ display:flex; align-items:center; gap:10px; }
.status{ font-size:13px; color:var(--muted); min-width:110px; text-align:center; }

.btn{
  appearance:none;
  border:1px solid rgba(255,255,255,.18);
  background:rgba(255,255,255,.06);
  color:#fff;
  padding:10px 12px;
  border-radius:12px;
  cursor:pointer;
  transition: transform .08s ease, background .2s ease;
}
.btn:hover{ background:rgba(255,255,255,.10); }
.btn:active{ transform:scale(.98); }
.btn.ghost{ background:transparent; }

/* =========================
   STAGE / BOOK
========================= */
.stage{
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:flex-start;
  padding:18px 12px 28px;
  min-height: calc(100vh - 64px);
}

.book-wrap{
  width:var(--w);
  height:var(--h);
  perspective:2200px;
  display:flex;
  align-items:center;
  justify-content:center;
}

.book{
  width:100%;
  height:100%;
  position:relative;
  transform-style:preserve-3d;
  filter: drop-shadow(var(--shadow));
}

/* =========================
   SHEETS / SPREADS
========================= */
.sheet{
  position:absolute;
  inset:0;
  transform-style:preserve-3d;
  transform-origin:left center;
  transition:transform 700ms cubic-bezier(.2,.8,.2,1);
}
.sheet.flipped{ transform:rotateY(-180deg); }
.sheet.stacked{ pointer-events:none; }

.spread{
  position:absolute;
  inset:0;
  display:flex;
  gap:var(--spine);
  transform-style:preserve-3d;
  backface-visibility:hidden;
}
.spread.back{ transform:rotateY(180deg); }

.page{
  flex:1 1 50%;
  background:var(--paper);
  color:var(--ink);
  border-radius:var(--radius);
  border:1px solid rgba(0,0,0,.08);
  overflow:hidden;
  position:relative;
}

.page.left{
  border-top-right-radius:10px;
  border-bottom-right-radius:10px;
}
.page.right{
  border-top-left-radius:10px;
  border-bottom-left-radius:10px;
}

.spine{
  position:absolute;
  top:0; bottom:0;
  left:calc(50% - (var(--spine)/2));
  width:var(--spine);
  background:linear-gradient(90deg, rgba(0,0,0,.12), rgba(0,0,0,.03), rgba(0,0,0,.12));
  border-radius:999px;
  opacity:.35;
  pointer-events:none;
}

/* CLICK AREAS */
.edge{
  position:absolute;
  top:0; bottom:0;
  width:16%;
  z-index:40;
}
.edge.left{ left:0; }
.edge.right{ right:0; }

/* =========================
   PAGE CONTENT (shared)
========================= */
.p-content{
  height:100%;
  display:flex;
  flex-direction:column;
}

/* HERO */
.p-hero{
  flex:0 0 auto;
  min-height:34%;
}
.p-hero img{
  width:100%;
  height:100%;
  object-fit:cover;
  display:block;
}

/* Hero height presets */
.page[data-hero-size="half"] .p-hero{ min-height:50%; }
.page[data-hero-size="third"] .p-hero{ min-height:33%; }
.page[data-hero-size="quarter"] .p-hero{ min-height:25%; }

/* BODY */
.p-body{
  padding:18px;
  display:flex;
  flex-direction:column;
  gap:10px;
  flex:1;
  min-height:0;
}

.h{
  margin:0;
  font-size:clamp(16px,1.6vw,26px);
  line-height:1.15;
}
.sub{
  margin:0;
  font-size:13px;
  font-weight:600;
  color:rgba(17,19,24,.75);
}

/* KICKER + INTRO */
.kicker{
  display:inline-block;
  font-weight:900;
  letter-spacing:.14em;
  text-transform:uppercase;
  font-size:12px;
  color:rgba(17,19,24,.65);
  border-left:4px solid rgba(17,19,24,.18);
  padding:6px 10px;
}
.intro{
  font-family:Georgia,"Times New Roman",serif;
  font-size:14px;
  line-height:1.5;
  color:rgba(17,19,24,.85);
  max-width: 92%;
}

/* ARTICLE TEXT */
.article{
  flex:1;
  font-family:Georgia,"Times New Roman",serif;
  font-size:15.5px;
  line-height:1.65;
  column-count:2;
  column-gap:22px;
}
.article p{ margin:0 0 12px; }

.footer{
  display:flex;
  justify-content:space-between;
  padding-top:10px;
  border-top:1px solid rgba(0,0,0,.10);
  font-size:12px;
  color:rgba(17,19,24,.65);
}

/* =========================
   IMAGE RIGHT LAYOUT (DESKTOP)
========================= */
.page[data-layout="image-right"] .p-content{
  display:grid;
  grid-template-columns:1fr 40%;
  grid-template-rows:auto auto 1fr;
  gap:16px;
}

.page[data-layout="image-right"] .kicker{
  grid-column:1;
  grid-row:1;
  margin:18px 0 0 18px;
}
.page[data-layout="image-right"] .intro{
  grid-column:1;
  grid-row:2;
  margin:0 0 0 18px;
}

.page[data-layout="image-right"] .p-hero{
  grid-column:2;
  grid-row:1 / span 2;
  min-height:220px;
}

.page[data-layout="image-right"] .p-body{
  grid-column:1 / -1;
  grid-row:3;
}

.page[data-layout="image-right"] .article{
  column-count:1;
}

/* =========================
   COVER (IMAGE ONLY)
========================= */
.cover-only{
  width:100%;
  height:100%;
  background:#000;
  display:flex;
  align-items:center;
  justify-content:center;
  overflow:hidden;
}
.cover-only-img{
  width:100%;
  height:100%;
  object-fit:contain;
  display:block;
}

/* =========================
   QUIZ
========================= */
.quiz{ margin-top:6px; }
.quiz-q{
  margin:0 0 10px;
  font-weight:800;
  font-size:15px;
}

.quiz-form{
  display:flex;
  flex-direction:column;
  gap:10px;
  max-width:520px;
}

.quiz-form input{
  padding:12px 12px;
  border-radius:12px;
  border:1px solid rgba(0,0,0,.15);
  font-size:14px;
}

.quiz-opts{
  display:flex;
  flex-direction:column;
  gap:8px;
}

.quiz-opt{
  display:flex;
  gap:10px;
  align-items:flex-start;
  padding:10px 12px;
  border:1px solid rgba(0,0,0,.12);
  border-radius:12px;
  cursor:pointer;
  background: rgba(0,0,0,.03);
}
.quiz-opt:hover{ background: rgba(0,0,0,.06); }
.quiz-opt input{ margin-top:2px; }

.quiz-btn{
  align-self:flex-start;
  background:#111318 !important;
  color:#ffffff !important;
  border:1px solid rgba(0,0,0,.25) !important;
}
.quiz-btn:hover{ filter:brightness(1.08); }

/* Honeypot hidden */
.hp{
  position:absolute !important;
  left:-9999px !important;
  width:1px !important;
  height:1px !important;
  opacity:0 !important;
}
/* =========================
   DESKTOP: allow long pages to scroll inside page
========================= */
@media (min-width: 821px){

  .page[data-type="article"],
  .page[data-type="quiz"],
  .page[data-type="back"]{
    overflow: auto;
  }

  .page[data-type="article"] .p-body,
  .page[data-type="quiz"] .p-body,
  .page[data-type="back"] .p-body{
    overflow: visible;
  }

}


/* =========================
   MOBILE FIXES
========================= */
@media (max-width:820px){
  :root{
    --w:min(94vw,520px);
    --h:min(82dvh,980px);
    --spine:0;
    --radius:16px;
  }

  .spine{ display:none; }
  .article{ column-count:1; font-size:16px; }

  /* Better mobile UX: scroll the whole page for articles/quizzes/back */
  .page[data-type="article"],
  .page[data-type="quiz"],
  .page[data-type="back"]{
    overflow:auto;
    -webkit-overflow-scrolling:touch;
  }
  .page[data-type="article"] .p-body,
  .page[data-type="quiz"] .p-body,
  .page[data-type="back"] .p-body{
    overflow:visible;
  }

  /* Lock cover */
  .page[data-type="cover"],
  .page.cover{
    overflow:hidden;
  }

  /* Image-right stacks + prevents huge image on mobile */
  .page[data-layout="image-right"] .p-content{
    display:flex;
    flex-direction:column;
  }

  .page[data-layout="image-right"] .p-hero{
    max-height:38vh;
    min-height:0;
  }

  .page[data-layout="image-right"] .p-hero img{
    object-fit:contain;
  }

  .page[data-layout="image-right"] .kicker{
    margin:18px 18px 0 18px;
  }
  .page[data-layout="image-right"] .intro{
    margin:10px 18px 0 18px;
  }

  /* ✅ MOBILE CHROME FIX: prevent blank pages due to 3D transform + filter compositing */
  .book{
    filter:none !important;
  }

  .sheet, .spread, .page{
    -webkit-backface-visibility:hidden;
    backface-visibility:hidden;
    transform: translateZ(0);
    will-change: transform;
  }
}

.hint{
  margin-top:12px;
  font-size:12px;
  color:rgba(255,255,255,.65);
}
