:root{
  --bg:#0b1220;
  --text:#eaf0ff;
  --muted:rgba(234,240,255,.6);
  --stroke:rgba(255,255,255,.12);
  --card:rgba(255,255,255,.06);
}

*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  font-family:system-ui,"Kanit",sans-serif;
  background:radial-gradient(circle at top,#1c2f60,#050a14);
  color:var(--text);
}

/* topbar */
.topbar{
  position:sticky; top:0; z-index:10;
  display:flex; justify-content:space-between; align-items:center;
  padding:12px 16px;
  background:rgba(0,0,0,.38);
  border-bottom:1px solid var(--stroke);
  backdrop-filter: blur(10px);
}
.brand{display:flex;gap:10px;align-items:baseline}
.title{font-weight:700}
.sub{font-size:12px;color:var(--muted)}

.actions{display:flex;gap:10px;align-items:center}
.btn{
  background:rgba(255,255,255,.08);
  border:1px solid var(--stroke);
  color:#fff;
  border-radius:12px;
  padding:8px 12px;
  cursor:pointer;
}
.btn:hover{background:rgba(255,255,255,.15)}
.btn.ghost{background:transparent}

.wrap{max-width:980px;margin:20px auto;padding:0 12px}

/* viewer card */
.book{
  background:var(--card);
  border:1px solid var(--stroke);
  border-radius:18px;
  padding:16px;
  box-shadow: 0 24px 90px rgba(0,0,0,.45);
}

/* sheet */
.sheet{
  position:relative;
  width:100%;
  aspect-ratio:3/4;
  background:#000;
  overflow:hidden;
  border-radius:14px;
  border:1px solid rgba(255,255,255,.10);

  /* iBook perspective feel */
  perspective: 1400px;
  touch-action: pan-y; /* allow vertical scroll, we handle horizontal swipe */
}

.page{
  position:absolute;
  inset:0;
  width:100%;
  height:100%;
  object-fit:contain;
  user-select:none;
  -webkit-user-drag:none;
}

.back{z-index:1}

.flip{
  position:absolute;
  inset:0;
  z-index:2;
  transform-origin:left center;
  transform: rotateY(0deg);
  will-change: transform;
  backface-visibility:hidden;
}

/* soft shadow layer during turn */
.shade{
  position:absolute;
  inset:0;
  z-index:3;
  pointer-events:none;
  opacity:0;
  background: linear-gradient(90deg, rgba(0,0,0,.0) 0%, rgba(0,0,0,.18) 55%, rgba(0,0,0,.35) 100%);
  transition: opacity .2s ease;
}

/* smoother, more iBook-like */
.flip.turn{
  animation: flipSoft .72s cubic-bezier(.18,.86,.2,1) forwards;
}
@keyframes flipSoft{
  0%   { transform: rotateY(0deg); }
  45%  { transform: rotateY(-72deg) translateZ(0); }
  100% { transform: rotateY(-180deg); }
}

.hint{
  text-align:center;
  font-size:12px;
  color:var(--muted);
  margin-top:10px;
}

/* -------- Modals (Overview + Reader) -------- */
.modal{
  position:fixed;
  inset:0;
  background: rgba(0,0,0,.55);
  display:none;
  z-index:50;

  /* allow page inside modal to scroll (fallback) */
  overflow:auto;
  -webkit-overflow-scrolling: touch;
}

/* ✅ use flex so card centers nicely and works on mobile */
.modal.show{
  display:flex;
  align-items:flex-start;
  justify-content:center;
}

.modalCard{
  width:min(980px, 96vw);
  margin: 16px auto;
  max-height: calc(100vh - 32px);

  background: rgba(15,20,35,.92);
  border:1px solid var(--stroke);
  border-radius:18px;
  overflow:hidden;
  box-shadow: 0 30px 120px rgba(0,0,0,.55);

  display:flex;
  flex-direction:column;
}

/* header row inside modal */
.modalHead{
  display:flex;
  align-items:center;
  gap:10px;
  padding:12px 12px;
  border-bottom:1px solid rgba(255,255,255,.10);
}
.modalTitle{font-weight:700}
.modalSub{font-size:12px;color:var(--muted)}

/* Overview grid */
.grid{
  padding:12px;

  overflow:auto;
  -webkit-overflow-scrolling: touch;

  display:grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap:12px;

  flex:1;
  min-height: 0;
}

.thumb{
  background: rgba(255,255,255,.06);
  border:1px solid rgba(255,255,255,.10);
  border-radius:14px;
  padding:10px;
  cursor:pointer;
  transition: transform .18s ease, background .18s ease;
}
.thumb:hover{
  transform: translateY(-2px);
  background: rgba(255,255,255,.09);
}
.thumb img{
  width:100%;
  height:150px;
  object-fit:cover;
  border-radius:10px;
  display:block;
}
.thumb .cap{
  margin-top:8px;
  font-size:12px;
  color: var(--muted);
  display:flex;
  justify-content:space-between;
  gap:8px;
}
.thumb .cap span:last-child{
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
  max-width:60%;
}

/* zoom-in feel when jumping from overview */
.sheet.zoomIn{
  animation: zoomIn .28s cubic-bezier(.2,.9,.2,1);
}
@keyframes zoomIn{
  from{ transform: scale(.985); filter: blur(.5px); }
  to{ transform: scale(1); filter: blur(0); }
}

/* -------- Reader modal -------- */
.readerCard{
  width:min(1100px, 96vw);
  height:min(86vh, 900px);
  display:flex;
  flex-direction:column;
}

.readerBtns{
  display:flex;
  gap:8px;
  align-items:center;
  margin-left:auto;
  margin-right:10px;
}

.readerBody{
  position:relative;
  flex:1;
  overflow:auto;
  background:#0b0f14;
  border-radius:14px;
  padding:18px;
  touch-action: pan-x pan-y;
}

#rdImg{
  display:block;
  max-width:100%;
  height:auto;
  margin:0 auto;
  transform-origin: 50% 0%;
  will-change: transform;
  cursor: zoom-in;
  user-select:none;
  -webkit-user-drag:none;
}

.readerBody.isZoomed #rdImg{ cursor: grab; }
.readerBody.isPanning #rdImg{ cursor: grabbing; }

.readerHint{
  font-size:12px;
  opacity:.8;
  padding:10px 12px 12px;
}
