:root {
  --bg-0: #d8dce3;
  --bg-1: #e8eaee;
  --bg-2: #f3f4f6;
  --ink: #1a1f2a;
  --muted: #5c6678;
  --line: rgba(30, 40, 60, 0.12);
  --accent: #0091ff;
  --accent-strong: #0077d6;
  --accent-soft: rgba(0, 145, 255, 0.12);
  --paper: #ffffff;
  --topbar-h: 0px;
  --toolbar-h: 0px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: "Manrope", "Segoe UI", sans-serif;
  --display: "Syne", "Manrope", sans-serif;
  --serif: "Fraunces", Georgia, serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  font-family: var(--font);
  color: var(--ink);
  background-color: #0a1a2a;
  background-image: url("../assets/stage-bg.png");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-attachment: fixed;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* iOS / mobile: fixed backgrounds often glitch; use scroll instead */
body.is-compact {
  background-attachment: scroll;
}

button,
input,
a {
  font: inherit;
}

.app {
  min-height: 100%;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: 1fr;
  background: transparent;
}

body.is-immersive .topbar,
body.is-immersive .toolbar,
body.is-immersive .spread-badge {
  display: none !important;
}

.stage {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 4px;
  padding: 8px 4px;
  min-height: 0;
  min-height: 100dvh;
  overflow: visible;
  background-color: #0a1a2a;
  background-image: url("../assets/stage-bg.png");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

/* Open book: 2×A4 ≈ √2. Cover/end use one A4 leaf via showCover. */
.book-shell {
  position: relative;
  width: min(100%, 1100px);
  height: auto;
  max-height: calc(100dvh - 16px);
  aspect-ratio: calc(2 * 210 / 297);
  margin: 0 auto;
  display: grid;
  place-items: center;
  min-height: 0;
  overflow: visible;
}

@supports (height: 100dvh) {
  .book-shell {
    width: min(100%, 1100px, calc((100dvh - 20px) * 1.414));
    max-height: calc(100dvh - 16px);
  }
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 clamp(14px, 3vw, 28px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(14px);
  z-index: 5;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
  min-width: 0;
  margin-left: auto;
}

.brand img {
  width: 36px;
  height: 36px;
  object-fit: contain;
}

.brand-text {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-align: right;
  min-width: 0;
}

.brand-name {
  font-family: var(--display);
  font-weight: 800;
  letter-spacing: 0.1em;
  font-size: 0.92rem;
  line-height: 1.1;
}

.brand-tag {
  color: var(--muted);
  font-size: 0.7rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-start;
}

.engine-badge {
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border: 1px solid rgba(0, 145, 255, 0.28);
  border-radius: 999px;
  padding: 6px 10px;
}

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
  transition: transform 0.18s ease, background 0.18s ease, border-color 0.18s ease;
  text-decoration: none;
  color: var(--ink);
  white-space: nowrap;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn.ghost {
  background: rgba(255, 255, 255, 0.65);
  border-color: var(--line);
}

.btn.ghost:hover {
  background: #fff;
  border-color: rgba(0, 145, 255, 0.35);
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent), #2d6bff);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 8px 20px rgba(0, 119, 214, 0.28);
}

.flipbook {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: visible;
  background: transparent;
  border-radius: 2px;
  filter: drop-shadow(0 28px 60px rgba(20, 30, 50, 0.42))
    drop-shadow(0 10px 22px rgba(20, 30, 50, 0.24));
}

.flipbook.is-closing {
  transform-origin: center center;
  animation: book-close 0.65s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.flipbook.is-opening {
  transform-origin: center center;
  animation: book-open 0.45s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes book-close {
  0% {
    transform: perspective(1600px) rotateY(0deg) scale(1);
    opacity: 1;
  }
  100% {
    transform: perspective(1600px) rotateY(-70deg) scale(0.92);
    opacity: 0;
  }
}

@keyframes book-open {
  0% {
    transform: perspective(1600px) rotateY(55deg) scale(0.92);
    opacity: 0;
  }
  100% {
    transform: perspective(1600px) rotateY(0deg) scale(1);
    opacity: 1;
  }
}

.flipbook .stf__parent,
.flipbook .stf__wrapper,
.flipbook .stf__block {
  width: 100% !important;
  height: 100% !important;
  overflow: visible !important;
  background: transparent !important;
}

.flipbook .stf__item {
  background: #0b1d35 !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  overflow: hidden !important;
}

.flipbook .flip-page {
  width: 100%;
  height: 100%;
  background: #0a1220;
  overflow: hidden;
}

.flipbook .flip-page-face {
  position: relative;
  width: 100%;
  height: 100%;
  background-color: #0a1220;
  background-repeat: no-repeat;
}

/* Real3D-style center fold / gutter */
.page-fold {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

.flip-page--left .page-fold,
.static-spread-left .page-fold {
  background: linear-gradient(
    to right,
    transparent 0%,
    transparent 55%,
    rgba(0, 0, 0, 0.04) 72%,
    rgba(0, 0, 0, 0.14) 88%,
    rgba(0, 0, 0, 0.38) 100%
  );
}

.flip-page--right .page-fold,
.static-spread-right .page-fold {
  background: linear-gradient(
    to left,
    transparent 0%,
    transparent 55%,
    rgba(0, 0, 0, 0.04) 72%,
    rgba(0, 0, 0, 0.14) 88%,
    rgba(0, 0, 0, 0.38) 100%
  );
}

/* Outer edge soft lift (paper thickness) */
.flipbook .flip-page--left .flip-page-face {
  box-shadow: inset -1px 0 0 rgba(0, 0, 0, 0.22);
}

.flipbook .flip-page--right .flip-page-face {
  box-shadow: inset 1px 0 0 rgba(0, 0, 0, 0.22);
}

/* Bottom page count — Real3D style footers */
.page-footer {
  display: none !important;
}

.page-footer--left {
  left: 10px;
  text-align: left;
}

.page-footer--right {
  right: 10px;
  text-align: right;
}

/* Floating page range badge (like Real3D "2-3 / 22") */
.spread-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 6;
  padding: 6px 11px;
  border-radius: 8px;
  background: rgba(45, 52, 64, 0.78);
  color: #fff;
  font-family: "Manrope", system-ui, sans-serif;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1;
  pointer-events: none;
  box-shadow: 0 4px 14px rgba(20, 30, 50, 0.22);
}

.flipbook.is-back-flip .stf__block {
  transform: scaleX(-1);
  transform-origin: center center;
}

.flipbook.is-back-flip .flip-page-face {
  transform: scaleX(-1);
  transform-origin: center center;
}

/* A4 book covers */
.book-cover {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: #fff;
  background: #0b1d35;
  font-family: var(--font);
  -webkit-user-select: none;
  user-select: none;
  container-type: size;
  container-name: cover;
}

.book-cover--front {
  padding: 0;
  display: flex;
  flex-direction: column;
  background: #0b1d35;
}

.cover-copy-block {
  position: relative;
  z-index: 2;
  flex: 0 0 auto;
  padding: clamp(22px, 5.5%, 36px) clamp(20px, 5%, 34px) clamp(12px, 2.5%, 18px);
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 1.5%, 12px);
  background: #0b1d35;
}

.cover-brand-sm {
  margin: 0 0 6px;
  font-family: var(--display);
  font-size: clamp(0.68rem, 3.2cqw, 0.88rem);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: lowercase;
  color: rgba(255, 255, 255, 0.92);
}

.cover-stack-title {
  margin: 0;
  display: flex;
  flex-direction: column;
  font-family: var(--display);
  font-size: clamp(1.35rem, 14cqw, 3.6rem);
  font-weight: 800;
  line-height: 0.92;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  color: #fff;
}

.cover-author-line {
  margin: 4px 0 0;
  font-family: var(--display);
  font-size: clamp(0.78rem, 4.2cqw, 1.2rem);
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #6ec8ff;
}

.cover-sub-line {
  margin: 0;
  max-width: 28ch;
  font-size: clamp(0.7rem, 3cqw, 0.95rem);
  font-weight: 500;
  line-height: 1.4;
  color: rgba(255, 255, 255, 0.88);
}

.cover-art-panel {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: #071525;
}

.cover-art-panel img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 78%;
  pointer-events: none;
  -webkit-user-drag: none;
  user-select: none;
}

.book-cover--art {
  background: #0b1d35;
}

.book-cover-fullart {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center center;
  pointer-events: none;
  -webkit-user-drag: none;
  user-select: none;
}

.cover-atmosphere {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  background: linear-gradient(160deg, #050d18 0%, #0b1d35 42%, #0a2748 100%);
}

.cover-atmosphere--back {
  background:
    radial-gradient(90% 60% at 100% 0%, rgba(0, 145, 255, 0.18), transparent 55%),
    radial-gradient(80% 50% at 0% 100%, rgba(20, 90, 120, 0.35), transparent 55%),
    linear-gradient(200deg, #07111f 0%, #0b1d35 55%, #081525 100%);
}

.cover-orb--c {
  width: 70%;
  height: 45%;
  right: -20%;
  bottom: 10%;
  background: radial-gradient(circle, rgba(0, 145, 255, 0.22), transparent 70%);
}

.cover-orb--d {
  width: 55%;
  height: 40%;
  left: -18%;
  top: 8%;
  background: radial-gradient(circle, rgba(110, 200, 255, 0.14), transparent 70%);
}

.cover-grain {
  position: absolute;
  inset: 0;
  opacity: 0.45;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.55'/%3E%3C/svg%3E");
  background-size: 180px 180px;
  pointer-events: none;
}

.cover-back-texture {
  position: absolute;
  inset: auto 0 0;
  width: 100%;
  height: 58%;
  object-fit: cover;
  object-position: center 85%;
  opacity: 0.38;
  filter: saturate(0.9) contrast(1.05);
  mask-image: linear-gradient(180deg, transparent 0%, #000 28%, #000 100%);
  -webkit-mask-image: linear-gradient(180deg, transparent 0%, #000 28%, #000 100%);
  pointer-events: none;
  -webkit-user-drag: none;
}

.cover-back-leaves {
  position: absolute;
  inset: auto 0 0;
  height: 42%;
  pointer-events: none;
  background:
    radial-gradient(ellipse 40% 70% at 0% 100%, rgba(15, 70, 75, 0.75), transparent 70%),
    radial-gradient(ellipse 45% 75% at 100% 100%, rgba(12, 55, 70, 0.7), transparent 70%);
}

.cover-back-leaves::before,
.cover-back-leaves::after {
  content: "";
  position: absolute;
  bottom: -6%;
  width: 48%;
  height: 110%;
  background:
    radial-gradient(ellipse at 30% 40%, rgba(26, 120, 110, 0.55), transparent 62%),
    radial-gradient(ellipse at 70% 70%, rgba(10, 50, 60, 0.65), transparent 60%);
  filter: blur(0.5px);
}

.cover-back-leaves::before {
  left: -12%;
  transform: rotate(-8deg);
}

.cover-back-leaves::after {
  right: -14%;
  transform: rotate(10deg);
}

.cover-grid {
  position: absolute;
  inset: 0;
  opacity: 0.22;
  background-image:
    linear-gradient(rgba(110, 200, 255, 0.12) 1px, transparent 1px),
    linear-gradient(90deg, rgba(110, 200, 255, 0.12) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: radial-gradient(ellipse at 70% 30%, #000 20%, transparent 70%);
}

.cover-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(8px);
}

.cover-orb--a {
  width: 70%;
  height: 48%;
  right: -18%;
  top: -8%;
  background: radial-gradient(circle, rgba(0, 145, 255, 0.45), transparent 68%);
  animation: cover-drift 8s ease-in-out infinite alternate;
}

.cover-orb--b {
  width: 80%;
  height: 55%;
  left: -30%;
  bottom: -18%;
  background: radial-gradient(circle, rgba(46, 120, 255, 0.28), transparent 70%);
  animation: cover-drift 10s ease-in-out infinite alternate-reverse;
}

@keyframes cover-drift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to { transform: translate3d(4%, -3%, 0) scale(1.06); }
}

@keyframes cover-rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

.cover-watermark {
  position: absolute;
  right: -8%;
  bottom: 6%;
  width: min(78%, 280px);
  opacity: 0.1;
  filter: saturate(1.2);
  transform: rotate(-8deg);
  pointer-events: none;
  -webkit-user-drag: none;
}

.cover-top,
.cover-hero,
.cover-base {
  position: relative;
  z-index: 1;
}

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

.cover-edition {
  font-family: var(--display);
  font-size: clamp(0.68rem, 1.5vw, 0.78rem);
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.55);
}

.cover-pill {
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(110, 200, 255, 0.35);
  background: rgba(0, 145, 255, 0.12);
  font-size: clamp(0.62rem, 1.4vw, 0.72rem);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #9fd6ff;
  white-space: nowrap;
}

.cover-hero {
  display: flex;
  flex-direction: column;
  gap: clamp(10px, 2%, 16px);
  margin: auto 0;
  padding: 8% 0;
}

.cover-eyebrow {
  margin: 0;
  font-size: clamp(0.72rem, 1.7vw, 0.88rem);
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #6ec8ff;
  animation: cover-rise 0.9s cubic-bezier(0.22, 1, 0.36, 1) 0.05s both;
}

.cover-brand {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(2.4rem, 9.5vw, 4.4rem);
  font-weight: 800;
  line-height: 0.92;
  letter-spacing: -0.04em;
  color: #fff;
  text-shadow: 0 10px 40px rgba(0, 100, 200, 0.35);
  animation: cover-rise 0.9s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.cover-title {
  margin: 4px 0 0;
  font-family: var(--serif);
  font-size: clamp(1.25rem, 3.6vw, 1.85rem);
  font-weight: 600;
  line-height: 1.15;
  color: rgba(255, 255, 255, 0.92);
  animation: cover-rise 0.9s cubic-bezier(0.22, 1, 0.36, 1) 0.12s both;
}

.cover-line {
  margin: 8px 0 0;
  max-width: 18ch;
  font-family: var(--serif);
  font-size: clamp(1rem, 2.5vw, 1.25rem);
  font-style: italic;
  font-weight: 500;
  color: #7ec8ff;
  animation: cover-rise 0.9s cubic-bezier(0.22, 1, 0.36, 1) 0.18s both;
}

.cover-base {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.cover-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
}

.cover-stats div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cover-stats strong {
  font-family: var(--display);
  font-size: clamp(1.15rem, 3vw, 1.55rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #fff;
}

.cover-stats span {
  font-size: clamp(0.62rem, 1.4vw, 0.72rem);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.5);
}

.cover-url {
  margin: 0;
  font-family: var(--display);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.45);
}

/* Back cover */
.book-cover--back {
  padding: clamp(28px, 7%, 48px) clamp(22px, 6%, 40px) clamp(22px, 5%, 34px);
  justify-content: space-between;
  gap: 24px;
  background: #0b1d35;
}

.book-cover-back-copy {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: clamp(14px, 2.4%, 20px);
  max-width: 34ch;
}

.book-cover-kicker {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(0.7rem, 3cqw, 0.88rem);
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #6ec8ff;
}

.book-cover-headline {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(1.1rem, 6.5cqw, 2rem);
  font-weight: 600;
  line-height: 1.18;
  letter-spacing: -0.02em;
  color: #fff;
}

.book-cover-body {
  margin: 0;
  font-size: clamp(0.72rem, 2.8cqw, 0.95rem);
  font-weight: 500;
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.86);
}

.book-cover-quote {
  margin: 6px 0 0;
  font-family: var(--serif);
  font-size: clamp(0.95rem, 4.2cqw, 1.35rem);
  font-style: italic;
  font-weight: 600;
  line-height: 1.3;
  color: #6ec8ff;
}

.book-cover-back-foot {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  margin-top: auto;
  padding-top: 8px;
}

.book-cover-mark {
  display: flex;
  align-items: center;
  gap: 12px;
}

.book-cover-mark img {
  width: 40px;
  height: 40px;
  object-fit: contain;
}

.book-cover-mark strong {
  display: block;
  font-family: var(--display);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: lowercase;
}

.book-cover-mark span {
  display: block;
  margin-top: 2px;
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.6);
  letter-spacing: 0.02em;
}

.flipbook .flip-page--hard {
  background: #0b1d35;
  overflow: hidden !important;
}

.flipbook .flip-page--hard .page-footer,
.flipbook .flip-page--cover .page-footer,
.flipbook .flip-page--end .page-footer {
  display: none !important;
}

body.is-cover .hint,
body.is-end .hint,
body.is-cover .spread-badge,
body.is-end .spread-badge,
body.is-cover .page-meta,
body.is-end .page-meta {
  display: none !important;
}

.static-host {
  width: 100%;
  height: 100%;
}

.static-host--single {
  display: grid;
  place-items: center;
}

.static-host--single .flip-page--hard {
  width: 100%;
  height: 100%;
}

.static-host .static-spread {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.static-spread-left,
.static-spread-right {
  position: relative;
  width: 100%;
  height: 100%;
  background-size: 200% 100%;
  background-repeat: no-repeat;
}

.static-spread-left {
  background-position: left center;
  box-shadow: inset -1px 0 0 rgba(0, 0, 0, 0.22);
}

.static-spread-right {
  background-position: right center;
  box-shadow: inset 1px 0 0 rgba(0, 0, 0, 0.22);
}

.nav-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: rgba(80, 90, 110, 0.28);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.18s ease, opacity 0.18s ease;
  z-index: 3;
}

.nav-btn svg {
  width: 22px;
  height: 22px;
}

.nav-btn:hover:not(:disabled) {
  background: rgba(60, 70, 90, 0.45);
}

.nav-btn:disabled {
  opacity: 0.28;
  cursor: default;
}

.loader {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 14px;
  background: rgba(232, 234, 238, 0.82);
  z-index: 4;
  transition: opacity 0.35s ease, visibility 0.35s ease;
}

.loader.hide {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loader p {
  margin: 0;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.loader-ring {
  width: 44px;
  height: 44px;
  margin: 0 auto;
  border-radius: 50%;
  border: 3px solid rgba(0, 145, 255, 0.2);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr;
  justify-items: center;
  gap: 8px;
  padding: 10px clamp(14px, 3vw, 28px) calc(12px + var(--safe-b));
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(14px);
}

.page-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  color: var(--muted);
}

.page-meta #pageTitle {
  color: var(--ink);
  font-weight: 600;
}

.dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
}

#pageSlider {
  width: min(560px, 92vw);
  accent-color: var(--accent-strong);
  cursor: pointer;
}

.hint {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
}

.toc {
  position: fixed;
  inset: 0;
  background: rgba(20, 28, 40, 0.35);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 40;
}

.toc[hidden] {
  display: none !important;
}

.toc-panel {
  width: min(480px, 100%);
  max-height: min(80vh, 720px);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(20, 30, 50, 0.22);
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr;
}

.toc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.toc-head h2 {
  margin: 0;
  font-size: 1rem;
}

.icon-btn {
  border: none;
  background: transparent;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
}

#tocList {
  list-style: none;
  margin: 0;
  padding: 8px;
  overflow: auto;
}

#tocList button {
  width: 100%;
  display: grid;
  grid-template-columns: 42px 1fr auto;
  gap: 10px;
  align-items: center;
  text-align: left;
  border: none;
  background: transparent;
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  color: inherit;
}

#tocList button:hover,
#tocList button.active {
  background: var(--accent-soft);
}

#tocList .num {
  font-weight: 700;
  color: var(--accent-strong);
}

#tocList .sec {
  color: var(--muted);
  font-size: 0.75rem;
}

.page-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
}

body.is-fullscreen .topbar,
body.is-fullscreen .toolbar {
  display: none;
}

body.is-fullscreen .app {
  grid-template-rows: 1fr;
}

body.is-fullscreen .stage {
  padding: 12px;
}

@media (max-width: 900px) {
  .brand-tag {
    display: none;
  }

  .btn.primary {
    display: none;
  }

  .hint {
    display: none;
  }
}

/* Narrow / phone / tablet: single-page landscape spreads */
body.is-compact .stage {
  grid-template-columns: 1fr;
  gap: 0;
  padding: max(8px, env(safe-area-inset-top, 0px))
    max(6px, env(safe-area-inset-right, 0px))
    max(8px, env(safe-area-inset-bottom, 0px))
    max(6px, env(safe-area-inset-left, 0px));
  min-height: 100dvh;
}

body.is-compact .book-shell {
  width: min(100%, calc((100dvh - 20px) * 1.414));
  max-width: 100%;
  max-height: calc(100dvh - 20px);
  aspect-ratio: calc(2 * 210 / 297);
}

body.is-compact .nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  opacity: 0.9;
  background: rgba(12, 24, 40, 0.55);
  backdrop-filter: blur(8px);
  z-index: 6;
}

body.is-compact .nav-btn.prev {
  left: max(4px, env(safe-area-inset-left, 0px));
}

body.is-compact .nav-btn.next {
  right: max(4px, env(safe-area-inset-right, 0px));
}

body.is-compact .nav-btn svg {
  width: 18px;
  height: 18px;
}

/* Cover sits in a landscape frame on compact — text + art side by side */
body.is-compact .book-cover--front {
  flex-direction: row;
}

body.is-compact .cover-copy-block {
  flex: 0 0 44%;
  max-width: 44%;
  justify-content: center;
  padding: clamp(12px, 4%, 28px) clamp(12px, 3.5%, 24px);
  gap: clamp(6px, 1.2%, 10px);
}

body.is-compact .cover-art-panel {
  flex: 1 1 auto;
}

body.is-compact .cover-stack-title {
  font-size: clamp(1.05rem, 7.5cqw, 2.4rem);
}

body.is-compact .book-cover--back {
  padding: clamp(16px, 4%, 36px) clamp(16px, 4%, 32px);
  gap: 16px;
}

body.is-compact .book-cover-back-copy {
  max-width: 42ch;
}

body.is-compact .flip-page-face--full {
  background-color: #0a1220;
}

@media (max-width: 640px) {
  .engine-badge {
    display: none;
  }
}

/* Very short landscape phones */
@media (orientation: landscape) and (max-height: 480px) {
  body.is-compact .book-shell {
    width: min(100%, calc((100dvh - 12px) * 1.414));
    max-height: calc(100dvh - 12px);
  }

  body.is-compact .nav-btn {
    width: 34px;
    height: 34px;
  }

  body.is-compact .cover-copy-block {
    flex-basis: 40%;
    max-width: 40%;
    padding: 10px 12px;
  }

  body.is-compact .cover-sub-line {
    display: none;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  :root {
    --topbar-h: 48px;
    --toolbar-h: 60px;
  }

  .brand-tag,
  .hint,
  .engine-badge {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
