/* Flip-book reader */
.reader-body {
  --bar-h: 68px;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: radial-gradient(1000px 600px at 50% 45%, #1a2c52 0%, transparent 70%), radial-gradient(600px 400px at 90% 100%, rgba(201, 164, 92, 0.15), transparent 70%), #070e1c;
  color: #fff;
  display: flex;
  flex-direction: column;
}

.reader-bar {
  height: var(--bar-h);
  flex-shrink: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  background: rgba(7, 14, 28, 0.7);
  backdrop-filter: blur(14px);
  position: relative;
  z-index: 20;
}
.rb-left, .rb-right { display: flex; align-items: center; gap: 12px; min-width: 0; }
.rb-right { justify-content: flex-end; }
.rb-btn { width: 42px; height: 42px; flex-shrink: 0; border-radius: 12px; display: grid; place-items: center; border: 1px solid rgba(255, 255, 255, 0.1); background: rgba(255, 255, 255, 0.04); color: #fff; cursor: pointer; transition: all 0.25s; }
.rb-btn:hover { border-color: var(--gold); color: var(--gold-2); }
.rb-toc-toggle, #fitBtn { display: none; }
#fitBtn[aria-pressed="true"] { border-color: var(--gold); color: var(--gold-2); background: rgba(201, 164, 92, 0.12); }
.rb-title { min-width: 0; }
.rb-title strong { display: block; font-family: var(--font-display); font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rb-title span { font-size: 12px; color: var(--muted-light); }
.rb-center { font-size: 13px; font-weight: 700; letter-spacing: 0.06em; padding: 8px 18px; border-radius: 999px; background: rgba(255, 255, 255, 0.06); border: 1px solid rgba(255, 255, 255, 0.08); color: var(--gold-2); white-space: nowrap; font-variant-numeric: tabular-nums; }

.reader-layout { flex: 1; display: flex; min-height: 0; position: relative; }

.reader-toc {
  width: 310px;
  flex-shrink: 0;
  overflow-y: auto;
  padding: 24px 18px;
  border-right: 1px solid rgba(255, 255, 255, 0.07);
  background: rgba(7, 14, 28, 0.55);
  display: flex;
  flex-direction: column;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}
.toc-book { display: flex; gap: 14px; align-items: center; padding: 0 6px 22px; border-bottom: 1px solid rgba(255, 255, 255, 0.07); margin-bottom: 18px; }
.toc-book img { width: 52px; border-radius: 3px; box-shadow: 0 8px 20px rgba(0, 0, 0, 0.5); }
.toc-book strong { display: block; font-family: var(--font-display); font-size: 16px; line-height: 1.3; }
.toc-book span { font-size: 12.5px; color: var(--muted-light); }
.toc-label { font-size: 11px; letter-spacing: 0.22em; text-transform: uppercase; color: var(--gold-2); font-weight: 700; padding: 0 8px 10px; }
.toc-nav { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.toc-nav button, .toc-nav .locked {
  width: 100%;
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 10px;
  align-items: center;
  text-align: left;
  padding: 11px 10px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: none;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.85);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
  transition: background 0.25s, border-color 0.25s;
}
.toc-nav button:hover { background: rgba(255, 255, 255, 0.05); }
.toc-nav button.current { background: rgba(201, 164, 92, 0.12); border-color: rgba(201, 164, 92, 0.35); }
.toc-nav button > .icon { color: var(--gold-2); }
.toc-nav .n { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; background: rgba(255, 255, 255, 0.07); font-family: var(--font-display); font-size: 14px; color: var(--gold-2); }
.toc-nav .t em { display: block; font-style: italic; font-weight: 400; font-size: 12.5px; color: var(--muted-light); }
.toc-nav .p { font-size: 12px; color: var(--muted-light); font-variant-numeric: tabular-nums; }
.toc-nav .locked { cursor: not-allowed; opacity: 0.45; }
.toc-cta { margin-top: auto; padding: 20px; border-radius: 16px; background: linear-gradient(160deg, rgba(201, 164, 92, 0.18), rgba(201, 164, 92, 0.04)); border: 1px solid rgba(201, 164, 92, 0.25); }
.toc-cta strong { font-family: var(--font-display); font-size: 18px; }
.toc-cta p { font-size: 13px; color: var(--muted-light); margin: 4px 0 14px; }
.toc-nav + .toc-cta { margin-top: 26px; }
.toc-scrim { display: none; }

.reader-stage { flex: 1; min-width: 0; position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 20px 80px 16px; }
.book-wrap {
  width: min(100%, calc((100dvh - var(--bar-h) - 110px) * 1.412));
  position: relative;
}
.book-wrap::after { content: ""; position: absolute; left: 6%; right: 6%; bottom: -26px; height: 30px; background: radial-gradient(ellipse, rgba(0, 0, 0, 0.6), transparent 70%); filter: blur(8px); z-index: -1; }
#flipbook { margin: 0 auto; }
.page { background: #fdfcf8; overflow: hidden; position: relative; }
.page img { width: 100%; height: 100%; object-fit: contain; user-select: none; -webkit-user-drag: none; background: #fdfcf8; }
.page img:not([src]) { visibility: hidden; }
.page::before { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, #f3efe4 0%, #fdfcf8 100%); }
.page img { position: relative; }
.page-num { position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%); font-size: 10px; color: rgba(0, 0, 0, 0); }
.page-cover { background: #0f2442; }
.page-cover img { object-fit: cover; }
.page-cover-back { background: #e9e6df; }
.page-end { background: radial-gradient(circle at 50% 30%, #fff, #f1ead9); color: var(--ink); }
.page-end::before { display: none; }
.end-inner { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 10%; gap: 6px; }
.end-inner h2 { font-size: clamp(1.2rem, 2.4vw, 2rem); color: var(--ink); margin: 10px 0 6px; }
.end-inner p { font-size: clamp(0.8rem, 1.2vw, 0.98rem); color: var(--muted); }
.end-icon { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; background: var(--ink); color: var(--gold-2); }
.end-link { margin-top: 12px; font-size: 13px; font-weight: 700; color: var(--gold-deep); border-bottom: 1px solid currentColor; }

.stage-nav { position: absolute; top: 50%; transform: translateY(-50%); z-index: 5; width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center; border: 1px solid rgba(255, 255, 255, 0.12); background: rgba(255, 255, 255, 0.05); color: #fff; cursor: pointer; backdrop-filter: blur(10px); transition: all 0.3s var(--ease); }
.stage-nav:hover { background: var(--gold); color: var(--ink); border-color: var(--gold); }
.stage-nav:disabled { opacity: 0.25; pointer-events: none; }
.stage-nav.prev { left: 16px; }
.stage-nav.next { right: 16px; }

.reader-foot { width: min(560px, 100%); margin-top: 34px; text-align: center; }
#scrubber { width: 100%; -webkit-appearance: none; appearance: none; height: 4px; border-radius: 4px; background: linear-gradient(90deg, var(--gold) var(--pct, 0%), rgba(255, 255, 255, 0.12) var(--pct, 0%)); outline: none; cursor: pointer; }
#scrubber::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%; background: var(--gold-2); border: 3px solid #070e1c; box-shadow: 0 0 0 1px var(--gold); }
#scrubber::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--gold-2); border: 3px solid #070e1c; }
.foot-hint { font-size: 12px; color: rgba(255, 255, 255, 0.4); margin-top: 12px; }

.reader-empty { text-align: center; max-width: 420px; color: var(--muted-light); display: grid; justify-items: center; gap: 6px; }
.reader-empty h2 { color: #fff; margin-top: 16px; }

/* Laptops and smaller: the contents become a slide-out drawer so the book gets the full width. */
@media (max-width: 1440px) {
  .rb-toc-toggle { display: grid; }
  .reader-toc { position: absolute; inset: 0 auto 0 0; z-index: 30; background: #0a1426; transform: translateX(-105%); transition: transform 0.45s var(--ease); box-shadow: 20px 0 60px rgba(0, 0, 0, 0.5); }
  .reader-toc.open { transform: none; }
  .toc-scrim { display: block; position: absolute; inset: 0; z-index: 25; background: rgba(0, 0, 0, 0.5); opacity: 0; pointer-events: none; transition: opacity 0.3s; }
  .toc-scrim.open { opacity: 1; pointer-events: auto; }
}
/* Laptops: "fit width" lets the book fill the stage and scroll, so the text is large enough to read. */
@media (min-width: 701px) and (max-width: 1440px) {
  #fitBtn { display: grid; }
  .reader-stage.fit-width { justify-content: flex-start; overflow-y: auto; padding-top: 16px; padding-bottom: 0; scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, 0.2) transparent; }
  .fit-width .book-wrap { width: 100%; flex-shrink: 0; }
  .fit-width .stage-nav { position: fixed; top: calc(50% + var(--bar-h) / 2); }
  .fit-width .reader-foot { position: sticky; bottom: 12px; z-index: 4; flex-shrink: 0; width: min(420px, 100%); margin: 24px 0 12px; padding: 9px 18px; border-radius: 999px; border: 1px solid rgba(255, 255, 255, 0.1); background: rgba(7, 14, 28, 0.72); backdrop-filter: blur(12px); line-height: 0; }
  .fit-width .foot-hint { display: none; }
}

/* Short screens (most laptops): slimmer bar and footer so the book can be taller. */
@media (min-width: 701px) and (max-height: 900px) {
  .reader-body { --bar-h: 58px; }
  .rb-btn { width: 38px; height: 38px; }
  .reader-stage { padding: 12px 80px 8px; }
  .book-wrap { width: min(100%, calc((100dvh - var(--bar-h) - 64px) * 1.412)); }
  .reader-foot { margin-top: 16px; }
  .foot-hint { display: none; }
}

@media (max-width: 700px) {
  .reader-body { --bar-h: 60px; }
  .reader-bar { grid-template-columns: 1fr auto; padding: 0 12px; }
  .rb-center { position: absolute; left: 50%; top: calc(var(--bar-h) + 12px); transform: translateX(-50%); font-size: 12px; padding: 6px 14px; }
  .rb-title span, .hide-sm, #fullscreenBtn { display: none; }
  .rb-title strong { font-size: 15px; max-width: 42vw; }
  .reader-stage { padding: 56px 14px 14px; }
  .book-wrap { width: min(100%, calc((100dvh - var(--bar-h) - 150px) * 0.706)); }
  .stage-nav { display: none; }
  .reader-foot { margin-top: 26px; }
}
