:root{
  --paper: #ffffff;
  --paper-deep: #f2f4f1;
  --linen: #fdfdfd;
  --charcoal: #454847;
  --charcoal-soft: #86898a;
  --accent: #4a86c9;
  --accent-deep: #33639e;
  --accent2: #7ec8e3;
  --shadow-color: 16 24 30;
  --panel-bg: rgba(255,255,255,0.72);
  --panel-border: rgba(69,72,71,0.12);
  --focus-ring: #33639e;
}

@media (prefers-color-scheme: dark){
  :root:not([data-theme="light"]){
    --paper: #1d201f;
    --paper-deep: #151716;
    --linen: #262928;
    --charcoal: #eef1ef;
    --charcoal-soft: #c1c6c3;
    --accent: #7fb4e8;
    --accent-deep: #a8d0f2;
    --accent2: #9fdcef;
    --shadow-color: 0 0 0;
    --panel-bg: rgba(28,31,30,0.72);
    --panel-border: rgba(238,241,239,0.14);
    --focus-ring: #a8d0f2;
  }
}
:root[data-theme="dark"]{
  --paper: #1d201f;
  --paper-deep: #151716;
  --linen: #262928;
  --charcoal: #eef1ef;
  --charcoal-soft: #c1c6c3;
  --accent: #7fb4e8;
  --accent-deep: #a8d0f2;
  --accent2: #9fdcef;
  --shadow-color: 0 0 0;
  --panel-bg: rgba(28,31,30,0.72);
  --panel-border: rgba(238,241,239,0.14);
  --focus-ring: #a8d0f2;
}

*{box-sizing:border-box;}
html,body{height:100%;}
body{
  margin:0;
  min-height:100vh;
  background:transparent;
  color:var(--charcoal);
  font-family:'Poppins', 'Helvetica Neue', Arial, sans-serif;
  display:flex;
  flex-direction:column;
  align-items:center;
  overflow-x:hidden;
}

.top-actions{
  position:absolute;
  top:14px;
  right:14px;
  z-index:6;
  display:flex;
  gap:8px;
  align-items:center;
}
.icon-btn{
  width:38px;
  height:38px;
  border-radius:50%;
  border:1px solid var(--panel-border);
  background:var(--panel-bg);
  color:var(--charcoal);
  display:flex;
  align-items:center;
  justify-content:center;
  cursor:pointer;
  backdrop-filter:blur(6px);
  transition:transform .15s ease, background .15s ease, border-color .15s ease;
}
.icon-btn:hover{ transform:translateY(-1px); border-color:var(--accent); }
.icon-btn:focus-visible, .nav-btn:focus-visible, .pill-btn:focus-visible, .thumb:focus-visible{
  outline:2px solid var(--focus-ring);
  outline-offset:2px;
}
.icon-btn svg{ width:17px; height:17px; }

.stage{
  position:relative;
  width:100%;
  max-width:1200px;
  flex:1;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:56px 12px min(130px, 22vh);
  min-height:0;
}

.book-wrap{
  position:relative;
  width:min(92vw, 1100px);
  aspect-ratio:720/504;
  max-height:78vh;
  display:flex;
  align-items:center;
  justify-content:center;
}

.book-shadow-plane{
  position:absolute;
  left:50%;
  bottom:2%;
  width:70%;
  height:28px;
  transform:translateX(-50%);
  background:radial-gradient(ellipse at center, rgba(var(--shadow-color),0.28) 0%, rgba(var(--shadow-color),0) 72%);
  filter:blur(2px);
  pointer-events:none;
}

#book{
  filter: drop-shadow(0 18px 34px rgba(var(--shadow-color),0.22));
}

.page{
  background:var(--linen);
  overflow:hidden;
}
.page img{
  width:100%;
  height:100%;
  object-fit:cover;
  display:block;
  user-select:none;
  -webkit-user-drag:none;
}
.page.--cover img{
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.06);
}

.nav-btn{
  position:absolute;
  top:50%;
  transform:translateY(-50%);
  width:46px;
  height:46px;
  border-radius:50%;
  border:1px solid var(--panel-border);
  background:var(--panel-bg);
  backdrop-filter:blur(6px);
  color:var(--charcoal);
  display:flex;
  align-items:center;
  justify-content:center;
  cursor:pointer;
  z-index:5;
  transition:transform .15s ease, background .15s ease, border-color .15s ease, opacity .15s ease;
}
.nav-btn:hover{ border-color:var(--accent); transform:translateY(-50%) scale(1.06); }
.nav-btn:disabled{ opacity:0.25; cursor:default; }
.nav-btn:disabled:hover{ transform:translateY(-50%); border-color:var(--panel-border); }
.nav-btn.prev{ left:-6px; }
.nav-btn.next{ right:-6px; }
.nav-btn svg{ width:19px; height:19px; }
@media (min-width:760px){
  .nav-btn.prev{ left:12px; }
  .nav-btn.next{ right:12px; }
}

.control-dock{
  position:fixed;
  left:50%;
  bottom:22px;
  transform:translateX(-50%);
  z-index:20;
  display:flex;
  align-items:center;
  gap:10px;
  padding:9px 14px;
  border-radius:999px;
  background:var(--panel-bg);
  border:1px solid var(--panel-border);
  backdrop-filter:blur(10px);
  box-shadow:0 10px 30px rgba(var(--shadow-color),0.16);
}
.pill-btn{
  border:none;
  background:transparent;
  color:var(--charcoal);
  width:34px;
  height:34px;
  border-radius:50%;
  display:flex;
  align-items:center;
  justify-content:center;
  cursor:pointer;
}
.pill-btn:hover{ background:rgba(var(--shadow-color),0.08); }
.pill-btn svg{ width:16px; height:16px; }

.page-indicator{
  font-variant-numeric:tabular-nums;
  font-size:13.5px;
  letter-spacing:0.03em;
  color:var(--charcoal-soft);
  padding:0 4px;
  white-space:nowrap;
  min-width:72px;
  text-align:center;
}
.page-indicator b{ color:var(--charcoal); font-weight:600; }

.progress-track{
  position:fixed;
  left:0; right:0; bottom:0;
  height:3px;
  background:rgba(var(--shadow-color),0.08);
  z-index:19;
}
.progress-fill{
  height:100%;
  width:0%;
  background:#e4ff00;
  transition:width .25s ease;
}

/* thumbnail drawer */
.drawer{
  position:fixed;
  inset:0;
  z-index:30;
  display:flex;
  align-items:flex-end;
  justify-content:center;
  background:rgba(20,20,20,0.42);
  opacity:0;
  pointer-events:none;
  transition:opacity .2s ease;
}
.drawer.open{ opacity:1; pointer-events:auto; }
.drawer-panel{
  width:100%;
  max-width:1100px;
  max-height:72vh;
  background:var(--linen);
  border-radius:18px 18px 0 0;
  padding:18px 20px 26px;
  transform:translateY(16px);
  transition:transform .22s ease;
  display:flex;
  flex-direction:column;
  gap:14px;
  box-shadow:0 -20px 50px rgba(var(--shadow-color),0.28);
}
.drawer.open .drawer-panel{ transform:translateY(0); }
.drawer-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
}
.drawer-head h2{
  margin:0;
  font-family:'Poppins', 'Helvetica Neue', Arial, sans-serif;
  font-size:16px;
  font-weight:600;
}
.drawer-grid{
  overflow-y:auto;
  display:grid;
  grid-template-columns:repeat(auto-fill, minmax(84px, 1fr));
  gap:10px;
  padding-right:4px;
}
.thumb{
  border:1px solid var(--panel-border);
  border-radius:6px;
  overflow:hidden;
  cursor:pointer;
  background:var(--paper-deep);
  aspect-ratio:360/504;
  padding:0;
  position:relative;
}
.thumb img{ width:100%; height:100%; object-fit:cover; display:block; }
.thumb span{
  position:absolute;
  right:3px;
  bottom:3px;
  font-size:9.5px;
  background:rgba(0,0,0,0.55);
  color:#fff;
  padding:1px 4px;
  border-radius:3px;
  font-variant-numeric:tabular-nums;
}
.thumb.active{ outline:2px solid var(--accent-deep); outline-offset:-2px; }

/* loading veil */
.veil{
  position:fixed;
  inset:0;
  z-index:50;
  background:transparent;
  display:flex;
  align-items:center;
  justify-content:center;
  transition:opacity .4s ease;
}
.veil.hide{ opacity:0; pointer-events:none; }
.spinner{
  width:22px; height:22px;
  border-radius:50%;
  border:2px solid var(--panel-border);
  border-top-color:var(--accent-deep);
  animation:spin 0.9s linear infinite;
}
@keyframes spin{ to{ transform:rotate(360deg); } }

.hint{
  position:fixed;
  bottom:70px;
  left:50%;
  transform:translateX(-50%);
  font-size:11.5px;
  letter-spacing:0.05em;
  color:var(--charcoal-soft);
  background:var(--panel-bg);
  border:1px solid var(--panel-border);
  padding:5px 12px;
  border-radius:999px;
  opacity:0;
  transition:opacity .3s ease;
  pointer-events:none;
  z-index:18;
}
.hint.show{ opacity:1; }

@media (max-width:600px){
  .stage{ padding-top:48px; padding-bottom:118px; }
  .drawer-grid{ grid-template-columns:repeat(auto-fill, minmax(68px,1fr)); }
}

@media (prefers-reduced-motion: reduce){
  *{ animation-duration:0.001ms !important; transition-duration:0.001ms !important; }
}
