/* Shared styles for all MagicBook-style ebooks */
:root {
  --page-w: 461px;
  --page-h: 568px;
  --accent: #3e2684;
  --text: #131313;
}

* { box-sizing: border-box; }
/* Page content keeps the original theme's content-box sizing (width + padding), like the live books */
.side .content * { box-sizing: content-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: "Mukta", "Ek Mukta", Arial, sans-serif;
  color: #333;
  background: #ddd var(--body-bg, none);
}

/* ---------- Intro / closed book ---------- */
#intro {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 61px;
  transition: opacity .6s ease;
}
#intro.gone { opacity: 0; pointer-events: none; }

.book {
  position: relative;
  height: min(600px, 80vh);
  aspect-ratio: 369 / 600;
  perspective: 1800px;
  box-shadow: 3px 1px 13px 0 #ccc;
  flex: none;
}
.book .cover {
  position: absolute;
  inset: 0;
  transform-origin: 0 50%;
  transform-style: preserve-3d;
  transition: transform .9s ease-in-out;
  cursor: pointer;
  z-index: 2;
}
.book.open .cover { transform: rotateY(-180deg); }
.book .front, .book .inner-left {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
}
.book .front {
  background-color: #333;
  background-size: cover;
  background-position: center;
}
.book .inner-left {
  background: #fff;
  transform: rotateY(180deg);
}
.book .inner-right {
  position: absolute;
  inset: 0;
  background: #fff;
}
.book #page-corner {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 29px;
  height: 50px;
}

.intro-content { width: 320px; }
.intro-content h1 {
  margin: 0 0 10px;
  font-size: 25px;
  font-weight: 300;
  line-height: 25px;
  color: var(--accent);
}
#aline {
  width: 260px;
  height: 1px;
  margin: -5px 0 0;
  background: var(--text);
}
.intro-content p {
  margin: 0 0 4px;
  padding: 0 0 15px;
  font-size: 18px;
  font-weight: 100;
  color: var(--text);
}
#open-it {
  padding: 4px 30px;
  font: inherit;
  font-size: 16px;
  line-height: 19.2px;
  letter-spacing: 1px;
  color: #6d1b1b;
  background: transparent;
  border: 1px solid #2b2182;
  cursor: pointer;
}
#open-it:hover { background: rgba(43, 33, 130, .08); }

/* ---------- Open book (spreads) ---------- */
#stage {
  position: fixed;
  inset: 0;
  perspective: 1500px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .6s ease;
}
#stage.show { opacity: 1; pointer-events: auto; }

#wrapper {
  position: absolute;
  left: 50%;
  top: 50%;
  width: calc(var(--page-w) * 2);
  height: var(--page-h);
  margin-left: calc(var(--page-w) * -1);
  margin-top: calc(var(--page-h) / -2);
  transform-origin: 50% 50%;
  transition: transform .4s;
}

.bb {
  position: relative;
  width: 100%;
  height: 100%;
  background: var(--book-bg, #fff);
}

.spread {
  position: absolute;
  inset: 0;
  display: none;
}
.spread.current { display: flex; }

.side {
  position: relative;
  width: 50%;
  height: 100%;
  overflow: hidden;
  background: #fff;
}
/* Pages render at the original design size (default 483x624) and are scaled as a whole */
.side .content {
  position: relative;
  width: var(--dw, 483px);
  height: var(--dh, 624px);
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: none;
  transform-origin: 0 0;
  transform: scale(calc(var(--k, 1) * var(--f, 1)));
}
.side .content::-webkit-scrollbar { display: none; }
.side .content > img {
  display: block;
  width: 100%;
  height: auto;
}
.side .raw {
  display: flow-root;
  width: 503px;
  height: 630px;
  background-position: top center;
  background-repeat: no-repeat;
}
.side .raw iframe {
  display: block;
  margin-left: 94px;
  width: 323px;
  height: 195px;
  border: 0;
}

/* spine shading */
.side.left::after, .side.right::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 30px;
  pointer-events: none;
}
.side.left::after { right: 0; background: linear-gradient(to left, rgba(0,0,0,.12), rgba(0,0,0,0)); }
.side.right::after { left: 0; background: linear-gradient(to right, rgba(0,0,0,.12), rgba(0,0,0,0)); }

.bb-nav-prev, .bb-nav-next {
  position: absolute;
  bottom: 0;
  width: 34px;
  height: 40px;
  font-size: 0;
  cursor: pointer;
  z-index: 3;
}
.bb-nav-prev { left: 0; }
.bb-nav-next { right: 0; }
.bb-nav-prev img, .bb-nav-next img { width: 100%; height: 100%; }

/* Same as the original MagicBook theme: three right-aligned grey bars of 30/20/10px */
.menu-button {
  position: absolute;
  top: 0;
  right: 0;
  width: 40px;
  height: 40px;
  overflow: hidden;
  cursor: pointer;
  z-index: 3;
  font-size: 0;
  opacity: .8;
  transition: opacity .3s;
}
.menu-button:hover { opacity: 1; }
.menu-button div {
  position: relative;
  display: block;
  float: right;
  height: 4px;
  margin: 5px 8px 0 0;
  background: #ddd;
  transition: width .3s ease-out;
}
.menu-button div:nth-child(1) { margin-top: 8px; width: 30px; }
.menu-button div:nth-child(2) { width: 20px; }
.menu-button div:nth-child(3) { width: 10px; }

/* share icons on page hover */
.share {
  position: absolute;
  top: 8px;
  left: 8px;
  display: flex;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
  opacity: 0;
  transition: opacity .2s;
  z-index: 3;
}
.side:hover .share { opacity: 1; }
.share a {
  display: block;
  width: 26px;
  height: 26px;
  border-radius: 3px;
  color: #fff;
  font: bold 13px/26px Arial, sans-serif;
  text-align: center;
  text-decoration: none;
}
.share .fb { background: #3b5998; }
.share .tw { background: #1da1f2; }
.share .pin { background: #cb2027; }
.share .tum { background: #35465c; }
.share .li { background: #0077b5; }

/* ---------- Page flip ---------- */
.flip-layer {
  position: absolute;
  inset: 0;
  z-index: 5;
  perspective: 2200px;
}
.flip-layer > .side { position: absolute; top: 0; }
.flip-layer > .side.left { left: 0; }
.flip-layer > .side.right { right: 0; }
.leaf {
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform .8s ease-in-out;
}
.leaf.to-left { left: 50%; transform-origin: 0 50%; }
.leaf.to-right { left: 0; transform-origin: 100% 50%; }
.leaf.to-left.go { transform: rotateY(-180deg); }
.leaf.to-right.go { transform: rotateY(180deg); }
.leaf > .side {
  position: absolute;
  inset: 0;
  width: 100%;
  backface-visibility: hidden;
}
.leaf > .side.back { transform: rotateY(180deg); }
.leaf > .side::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  background: rgba(0,0,0,0);
  transition: background .8s ease-in-out;
}
.leaf.go > .side.front::before { background: rgba(0,0,0,.25); }
.video-ph {
  display: block;
  margin-left: 94px;
  width: 323px;
  height: 195px;
  background: #000;
}

/* ---------- Table of contents ---------- */
#stage.menu-open #wrapper { transform: translateX(-31%) rotateY(-15deg); }
#stage.menu-open #wrapper .bb { pointer-events: none; }

.outer-nav {
  position: absolute;
  left: 70%;
  top: 50%;
  width: 360px;
  transform: translateY(-50%);
  opacity: 0;
  visibility: hidden;
  transition: opacity .4s, visibility .4s;
}
#stage.menu-open .outer-nav { opacity: 1; visibility: visible; }
/* Long chapter lists scroll inside a fixed-height box (live: ~61% of the window, thin bar on hover) */
.outer-nav ul {
  margin: 0;
  padding: 0 14px 0 0;
  list-style: none;
  max-height: 61vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: transparent transparent;
}
.outer-nav ul:hover { scrollbar-color: rgba(170,170,170,.6) transparent; }
.outer-nav ul::-webkit-scrollbar { width: 8px; }
.outer-nav ul::-webkit-scrollbar-track { background: transparent; }
.outer-nav ul::-webkit-scrollbar-thumb { background: transparent; border-radius: 4px; }
.outer-nav ul:hover::-webkit-scrollbar-thumb { background: rgba(170,170,170,.6); }
.outer-nav li { margin: 0; }
.outer-nav a {
  display: block;
  margin: 0 0 20px;
  white-space: nowrap;
  font-family: Marvel, Arial, Helvetica, sans-serif;
  font-size: 16px;
  font-weight: 600;
  text-transform: uppercase;
  color: #000;
  text-decoration: none;
  cursor: pointer;
  opacity: .8;
  transition: opacity .4s;
}
.outer-nav li.bb-current a { text-decoration: underline; opacity: 1; }
.outer-nav a:hover { opacity: 1; }
.outer-nav a::before, .outer-nav a::after {
  display: inline-block;
  opacity: 0;
  transition: transform .3s, opacity .2s;
}
.outer-nav a::before { margin-right: 10px; content: "["; transform: translateX(-16px); }
.outer-nav a::after { margin-left: 10px; content: "]"; transform: translateX(16px); }
.outer-nav a:hover::before, .outer-nav a:hover::after { opacity: 1; transform: translateX(0); }
.outer-nav .close {
  position: absolute;
  top: -80px;
  left: 90px;
  font: 300 30px/1 Arial, sans-serif;
  color: #000;
  cursor: pointer;
  background: none;
  border: 0;
}
.outer-nav .copy {
  margin-top: 150px;
  margin-left: -32px;
  font-size: 13px;
  color: #d0752c;
}

/* ---------- Phones: pages stacked, no flip ---------- */
@media (max-width: 767px) {
  html, body { overflow: auto; height: auto; }
  #intro {
    position: static;
    flex-direction: column;
    gap: 24px;
    padding: 24px 16px;
  }
  #intro.gone { display: none; }
  .book { height: 423px; }
  .intro-content { width: 100%; max-width: 320px; }
  #stage {
    position: static;
    perspective: none;
    opacity: 1;
    pointer-events: auto;
    padding: 16px;
  }
  #stage:not(.show) { display: none; }
  #wrapper {
    position: static;
    width: 100%;
    height: auto;
    margin: 0;
    transform: none !important;
  }
  .bb { height: auto; background: none; }
  .spread, .spread.current {
    position: static;
    display: block;
  }
  .side { width: 100%; margin-bottom: 12px; }
  .side .content { height: auto; overflow: hidden; }
  .side::after, .bb-nav-prev, .bb-nav-next, .menu-button, .share, .outer-nav { display: none !important; }
}
