/* ---------- Base ---------- */
:root{
  --ink:#18223a;
  --ink2:#2a3554;
  --paper:#fffdf7;
  --paper2:#fff8ec;
  --shadow: 0 22px 60px rgba(0,0,0,.22);
  --shadow2: 0 10px 30px rgba(0,0,0,.18);
  --radius: 22px;
}

*{ box-sizing:border-box; }
html,body{ height:100%; }
body{
  margin:0;
  font-family: ui-rounded, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 30% 15%, rgba(255,255,255,.9), rgba(255,255,255,0)),
    linear-gradient(180deg, #0f1a2e 0%, #182a4a 50%, #223a66 100%);
  overflow-x:hidden;
}

.topbar, .bottombar{
  max-width: 1200px;
  margin: 0 auto;
  padding: 18px 18px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: 12px;
}

.brand{
  display:flex;
  align-items:center;
  gap:12px;
  color: #fff;
}
.badge{
  width:44px; height:44px;
  border-radius: 14px;
  background: rgba(255,255,255,.14);
  display:grid; place-items:center;
  box-shadow: 0 10px 20px rgba(0,0,0,.2);
  border: 1px solid rgba(255,255,255,.22);
}
.brandTitle{ font-weight: 800; letter-spacing:.2px; }
.brandSub{ opacity:.85; font-size:.92rem; }

.controls{
  display:flex;
  align-items:center;
  gap: 10px;
  color: #fff;
}

.btn{
  border: 1px solid rgba(255,255,255,.25);
  background: rgba(255,255,255,.10);
  color: #fff;
  padding: 10px 14px;
  border-radius: 14px;
  cursor:pointer;
  transition: transform .12s ease, background .2s ease, border-color .2s ease;
  box-shadow: 0 10px 22px rgba(0,0,0,.18);
  user-select:none;
}
.btn:hover{ transform: translateY(-1px); background: rgba(255,255,255,.14); }
.btn:active{ transform: translateY(0px); }
.btn.primary{
  background: rgba(255,255,255,.18);
  border-color: rgba(255,255,255,.38);
}

.btn:disabled{
  opacity:.45;
  cursor:not-allowed;
  transform:none;
}

.progress{
  min-width: 84px;
  text-align:center;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255,255,255,.10);
  border: 1px solid rgba(255,255,255,.22);
  box-shadow: 0 10px 22px rgba(0,0,0,.18);
}

/* ---------- Stage / Book ---------- */
.stage{
  max-width: 1200px;
  margin: 0 auto;
  padding: 8px 18px 0 18px;
  display:grid;
  place-items:center;
}

.book{
  width: min(980px, 95vw);
  height: min(640px, 70vh);
  position: relative;
  perspective: 2200px;
  filter: drop-shadow(0 26px 80px rgba(0,0,0,.35));
}

.sheet{
  position:absolute;
  inset:0;
  transform-style: preserve-3d;
  transform-origin: left center;
  transition: transform 900ms cubic-bezier(.2,.9,.2,1);
}

/* Stacking: higher sheet on top */
.sheet{ z-index: 50; }
.sheet[data-sheet="1"]{ z-index: 58; }
.sheet[data-sheet="2"]{ z-index: 57; }
.sheet[data-sheet="3"]{ z-index: 56; }
.sheet[data-sheet="4"]{ z-index: 55; }
.sheet[data-sheet="5"]{ z-index: 54; }
.sheet[data-sheet="6"]{ z-index: 53; }
.sheet[data-sheet="7"]{ z-index: 52; }
.sheet[data-sheet="8"]{ z-index: 51; }

/* When flipped, send behind remaining pages */
.sheet.flipped{
  transform: rotateY(-180deg);
}
.sheet.flipped{
  z-index: 1 !important;
}

.page{
  position:absolute;
  inset:0;
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--paper) 0%, var(--paper2) 100%);
  box-shadow: var(--shadow);
  border: 1px solid rgba(18,34,58,.12);
  backface-visibility: hidden;
  overflow:hidden;
}

.page::before{
  content:"";
  position:absolute;
  inset:0;
  pointer-events:none;
  background:
    radial-gradient(800px 600px at 0% 50%, rgba(0,0,0,.06), rgba(0,0,0,0) 55%),
    linear-gradient(90deg, rgba(0,0,0,.10), rgba(0,0,0,0) 18%);
  opacity:.9;
}

.pageInner{
  position:relative;
  height:100%;
  padding: 26px 28px 22px 28px;
  display:flex;
  flex-direction:column;
  gap: 14px;
}

.pageHeader{
  display:flex;
  flex-direction:column;
  gap: 6px;
}

.stepTag{
  align-self:flex-start;
  padding: 6px 10px;
  border-radius: 999px;
  font-weight: 800;
  font-size: .86rem;
  background: rgba(24,34,58,.08);
  border: 1px solid rgba(24,34,58,.14);
}

.pageTitle{
  margin:0;
  font-size: clamp(1.35rem, 2.4vw, 2.1rem);
  letter-spacing: .2px;
}

.subTitle{
  opacity:.8;
  font-weight: 650;
}

.artWrap{
  background: rgba(255,255,255,.65);
  border: 1px solid rgba(18,34,58,.10);
  border-radius: 22px;
  box-shadow: var(--shadow2);
  overflow:hidden;
}
.artWrap svg{
  width:100%;
  height:auto;
  display:block;
}

.pageText{
  margin: 4px 0 0 0;
  font-size: clamp(1rem, 1.6vw, 1.08rem);
  line-height: 1.45;
  color: var(--ink2);
}

.pageFooter{
  margin-top:auto;
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap: 10px;
}

.miniNote{
  padding: 10px 12px;
  border-radius: 16px;
  background: rgba(24,34,58,.06);
  border: 1px solid rgba(24,34,58,.12);
  font-weight: 650;
  color: var(--ink);
}

.pageNumber{
  position:absolute;
  bottom: 14px;
  right: 18px;
  opacity:.55;
  font-weight: 800;
}

/* ---------- Cover special styling ---------- */
.cover{
  background: linear-gradient(180deg, #fffdf8 0%, #fff3df 100%);
}
.cover .pageInner{
  padding: 28px 28px 22px 28px;
  gap: 18px;
}
.coverTop{
  display:flex;
  flex-direction:column;
  gap: 8px;
}
.coverKicker{
  align-self:flex-start;
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(24,34,58,.08);
  border: 1px solid rgba(24,34,58,.14);
  font-weight: 900;
}
.coverTitle{
  margin:0;
  font-size: clamp(2.2rem, 4vw, 3.2rem);
  letter-spacing: .5px;
}
.coverLine{
  margin:0;
  font-size: 1.05rem;
  color: var(--ink2);
  line-height: 1.4;
}
.coverArt{
  border-radius: 26px;
  overflow:hidden;
  box-shadow: var(--shadow2);
  border: 1px solid rgba(18,34,58,.10);
}
.coverArt svg{ display:block; width:100%; height:auto; }
.coverBottom{
  display:flex;
  justify-content:flex-start;
}
.hintPill{
  padding: 10px 12px;
  border-radius: 16px;
  background: rgba(255,255,255,.70);
  border: 1px solid rgba(24,34,58,.14);
  font-weight: 700;
}

/* ---------- Final page ---------- */
.final{
  background: linear-gradient(180deg, #fff7fb 0%, #ffe9f0 100%);
}

/* ---------- Bottom bar ---------- */
.bottombar{
  color: rgba(255,255,255,.9);
  padding-bottom: 22px;
  font-size: .95rem;
}
.kbd{ opacity:.95; }
.pill{
  display:inline-grid;
  place-items:center;
  min-width: 28px;
  padding: 3px 8px;
  border-radius: 10px;
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.22);
  margin: 0 2px;
}
.tiny{ opacity:.7; }

/* ---------- Clickable page edge ---------- */
.book::after{
  content:"";
  position:absolute;
  top:0; right:0;
  width: 20%;
  height: 100%;
  cursor: pointer;
}
.book::before{
  content:"";
  position:absolute;
  top:0; left:0;
  width: 20%;
  height: 100%;
  cursor: pointer;
}

/* ---------- Snow overlay ---------- */
.snow{
  position: fixed;
  inset: 0;
  pointer-events:none;
  background-image:
    radial-gradient(2px 2px at 20px 30px, rgba(255,255,255,.55), transparent 55%),
    radial-gradient(2px 2px at 90px 120px, rgba(255,255,255,.45), transparent 55%),
    radial-gradient(2px 2px at 160px 70px, rgba(255,255,255,.50), transparent 55%),
    radial-gradient(2px 2px at 240px 160px, rgba(255,255,255,.35), transparent 55%),
    radial-gradient(2px 2px at 320px 40px, rgba(255,255,255,.48), transparent 55%),
    radial-gradient(2px 2px at 420px 140px, rgba(255,255,255,.38), transparent 55%),
    radial-gradient(2px 2px at 520px 60px, rgba(255,255,255,.44), transparent 55%),
    radial-gradient(2px 2px at 640px 170px, rgba(255,255,255,.34), transparent 55%),
    radial-gradient(2px 2px at 760px 90px, rgba(255,255,255,.40), transparent 55%),
    radial-gradient(2px 2px at 860px 150px, rgba(255,255,255,.36), transparent 55%);
  background-size: 900px 300px;
  opacity: .55;
  animation: snowFall 10s linear infinite;
}

@keyframes snowFall{
  from { transform: translateY(-40px); }
  to   { transform: translateY(260px); }
}

/* ---------- Responsive tweaks ---------- */
@media (max-width: 640px){
  .topbar{ flex-direction:column; align-items:stretch; }
  .controls{ justify-content:space-between; }
  .pageInner{ padding: 18px; }
  .miniNote{ font-size:.92rem; }
}


/* --- Photo storybook overrides --- */
.coverArt, .artWrap{ position: relative; }
.story-img{
  width: 100%;
  height: auto;
  display: block;
  border-radius: 22px;
  box-shadow: 0 18px 40px rgba(0,0,0,.25);
}

/* Fix clipping on smaller screens / long text */
.book{
  height: min(720px, calc(100vh - 220px));
}
.pageInner{
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 54px;
}
.pageTitle, .subTitle{
  overflow-wrap: anywhere;
  word-break: break-word;
}
