:root {
  --navy-950: #071526;
  --navy-900: #0a1e35;
  --navy-800: #102b49;
  --gold: #c6a34a;
  --gold-soft: #e4cf91;
  --paper: #f7f3ea;
  --ink: #102338;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--navy-950);
  color: #f8f4eb;
  font-family: "Segoe UI", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, a { font: inherit; }
button { color: inherit; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--gold-soft); outline-offset: 3px; }
[hidden] { display: none !important; }
.symbol { display: inline-grid; place-items: center; min-width: 18px; font-size: 20px; line-height: 1; }

.reader-shell {
  min-height: 100svh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 48%, rgba(47, 80, 111, .38), transparent 42%),
    linear-gradient(135deg, #06111f 0%, #0c223a 48%, #071523 100%);
}

.topbar {
  height: 76px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 clamp(18px, 3vw, 48px);
  border-bottom: 1px solid rgba(255,255,255,.08);
  background: rgba(5, 17, 30, .72);
  backdrop-filter: blur(18px);
  z-index: 20;
}

.brand-mark {
  width: 39px;
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 1px solid rgba(228, 207, 145, .7);
  box-shadow: inset 0 0 0 4px rgba(198, 163, 74, .12);
  color: var(--gold-soft);
  font-family: Georgia, serif;
  font-size: 10px;
  letter-spacing: .12em;
}

.brand-copy { min-width: 0; }
.eyebrow {
  margin: 0 0 3px;
  color: var(--gold-soft);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .16em;
  text-transform: uppercase;
}
.brand-copy h1 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(17px, 2vw, 22px); font-weight: 500; white-space: nowrap; }

.header-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.text-button, .download-button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 13px;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 10px;
  background: rgba(255,255,255,.055);
  color: rgba(255,255,255,.86);
  text-decoration: none;
  cursor: pointer;
  transition: background .2s ease, border-color .2s ease, transform .2s ease;
}
.text-button:hover, .download-button:hover { background: rgba(255,255,255,.11); border-color: rgba(255,255,255,.24); transform: translateY(-1px); }
.text-button svg, .download-button svg { width: 18px; height: 18px; }
.download-button { background: linear-gradient(135deg, #c9a64e, #a9822e); color: #101d2a; border-color: transparent; font-weight: 700; }
.download-button:hover { background: linear-gradient(135deg, #d7b964, #b7923c); border-color: transparent; }

.reader-stage {
  position: relative;
  min-height: 0;
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) 64px;
  align-items: center;
  padding: 22px clamp(10px, 2.4vw, 36px) 14px;
  perspective: 2200px;
  isolation: isolate;
}

.reader-stage:fullscreen { background: var(--navy-950); padding-block: 48px; }
.ambient { position: absolute; border-radius: 50%; filter: blur(70px); opacity: .16; pointer-events: none; z-index: -1; }
.ambient-one { width: 300px; height: 300px; background: #d4a73d; left: 8%; top: 5%; }
.ambient-two { width: 390px; height: 390px; background: #376e9a; right: 2%; bottom: -15%; }

.book-wrap {
  --book-zoom: 1;
  min-width: 0;
  display: grid;
  place-items: center;
  transform: scale(var(--book-zoom));
  transition: transform .25s ease;
  transform-origin: center;
}

.book {
  position: relative;
  width: min(76vw, 920px, calc((100svh - 190px) * 1.41));
  aspect-ratio: 1.41;
  transform-style: preserve-3d;
  filter: drop-shadow(0 30px 24px rgba(0,0,0,.42));
}

.book-depth {
  position: absolute;
  inset: 1.1% -.7% -1.4%;
  border-radius: 4px 8px 8px 4px;
  background: repeating-linear-gradient(90deg, #b8ae99 0 1px, #e0d9cb 1px 3px);
  transform: translateZ(-12px);
  box-shadow: 0 12px 30px rgba(0,0,0,.36);
}

.paper {
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
  padding: 0;
  overflow: hidden;
  border: 0;
  background: var(--paper);
  cursor: pointer;
  backface-visibility: hidden;
}
.page-left { left: 0; border-radius: 7px 1px 1px 7px; box-shadow: inset -18px 0 24px -22px rgba(0,0,0,.9); }
.page-right { right: 0; border-radius: 1px 7px 7px 1px; box-shadow: inset 18px 0 24px -22px rgba(0,0,0,.9); }
.page-image { width: 100%; height: 100%; object-fit: contain; display: block; user-select: none; background: #f7f4ed; }
.page-sheen { position: absolute; inset: 0; pointer-events: none; }
.page-left .page-sheen { background: linear-gradient(90deg, transparent 78%, rgba(10, 20, 31, .14) 100%); }
.page-right .page-sheen { background: linear-gradient(90deg, rgba(255,255,255,.28), transparent 7%, transparent 91%, rgba(0,0,0,.03)); }

.cover-mode .page-left { left: 25%; border-radius: 4px 8px 8px 4px; box-shadow: 9px 3px 0 #d9d1c0, 13px 7px 0 #8f877a, 20px 24px 40px rgba(0,0,0,.38); }
.cover-mode .book-depth { left: 25%; right: 25%; }

.spine-light {
  position: absolute;
  top: .4%; bottom: .4%; left: 50%; width: 2px;
  transform: translateX(-50%) translateZ(4px);
  background: linear-gradient(90deg, rgba(0,0,0,.3), rgba(255,255,255,.28), rgba(0,0,0,.2));
  box-shadow: 0 0 15px rgba(0,0,0,.44);
  pointer-events: none;
}
.cover-mode .spine-light { display: none; }

.flip-sheet {
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
  transform-style: preserve-3d;
  z-index: 8;
  pointer-events: none;
}
.flip-next { left: 50%; transform-origin: left center; animation: turnNext 720ms cubic-bezier(.55,.08,.22,.98) forwards; }
.cover-mode .flip-next { left: 25%; }
.flip-next.from-cover { left: 25%; }
.flip-prev { left: 0; transform-origin: right center; animation: turnPrev 720ms cubic-bezier(.55,.08,.22,.98) forwards; }
.flip-face { position: absolute; inset: 0; overflow: hidden; backface-visibility: hidden; background: var(--paper); }
.flip-front { box-shadow: inset 18px 0 24px -22px rgba(0,0,0,.8), 5px 0 12px rgba(0,0,0,.12); }
.flip-back { transform: rotateY(180deg); box-shadow: inset -18px 0 24px -22px rgba(0,0,0,.8), -5px 0 12px rgba(0,0,0,.12); }

@keyframes turnNext {
  0% { transform: rotateY(0deg); filter: brightness(1); }
  45% { filter: brightness(.78); }
  100% { transform: rotateY(-180deg); filter: brightness(1); }
}
@keyframes turnPrev {
  0% { transform: rotateY(0deg); filter: brightness(1); }
  45% { filter: brightness(.78); }
  100% { transform: rotateY(180deg); filter: brightness(1); }
}

.open-hint { position: absolute; top: calc(100% + 16px); margin: 0; color: rgba(255,255,255,.58); font-size: 12px; letter-spacing: .02em; animation: fadePulse 2.5s ease-in-out infinite; }
@keyframes fadePulse { 50% { opacity: .55; } }

.edge-nav {
  width: 46px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  justify-self: center;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,.16);
  background: rgba(255,255,255,.075);
  cursor: pointer;
  z-index: 5;
  backdrop-filter: blur(10px);
  transition: background .2s ease, transform .2s ease, opacity .2s ease;
}
.edge-nav svg { width: 25px; height: 25px; }
.edge-nav:hover:not(:disabled) { background: rgba(198,163,74,.24); transform: scale(1.06); }
.edge-nav:disabled { opacity: .18; cursor: default; }

.floating-tools {
  position: absolute;
  right: clamp(22px, 4vw, 66px);
  bottom: 22px;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 5px;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 12px;
  background: rgba(5,17,30,.76);
  backdrop-filter: blur(14px);
  box-shadow: 0 10px 28px rgba(0,0,0,.2);
  z-index: 12;
}
.floating-tools button { width: 34px; height: 32px; display: grid; place-items: center; border: 0; border-radius: 8px; background: transparent; cursor: pointer; }
.floating-tools button:hover { background: rgba(255,255,255,.1); }
.floating-tools button svg { width: 17px; height: 17px; }
.floating-tools span { min-width: 44px; text-align: center; color: rgba(255,255,255,.68); font-size: 11px; }
.floating-tools i { width: 1px; height: 22px; background: rgba(255,255,255,.12); margin: 0 3px; }

.reader-footer { min-height: 66px; padding: 10px clamp(18px, 4vw, 64px) 13px; border-top: 1px solid rgba(255,255,255,.07); background: rgba(4,14,25,.7); z-index: 15; }
.page-status { max-width: 920px; margin: 0 auto 7px; display: flex; justify-content: space-between; color: rgba(255,255,255,.72); font-size: 11px; }
.progress-track { max-width: 920px; height: 3px; margin: auto; overflow: hidden; border-radius: 20px; background: rgba(255,255,255,.12); }
.progress-track span { height: 100%; display: block; border-radius: inherit; background: linear-gradient(90deg, #9b7526, #e0c778); transition: width .5s ease; }
.reader-footer p { margin: 7px 0 0; text-align: center; color: rgba(255,255,255,.38); font-size: 10px; }

.toast { position: fixed; left: 50%; bottom: 88px; transform: translateX(-50%); z-index: 80; padding: 11px 17px; border-radius: 10px; color: #17202a; background: var(--paper); box-shadow: 0 12px 35px rgba(0,0,0,.35); font-size: 13px; }

.thumb-overlay { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; padding: 20px; background: rgba(1,8,15,.78); backdrop-filter: blur(12px); }
.thumb-panel { width: min(1040px, 96vw); max-height: 90svh; display: grid; grid-template-rows: auto minmax(0,1fr) auto; border: 1px solid rgba(255,255,255,.12); border-radius: 18px; overflow: hidden; background: #0b1d31; box-shadow: 0 30px 80px rgba(0,0,0,.5); }
.thumb-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid rgba(255,255,255,.09); }
.thumb-header h2 { margin: 0; font-family: Georgia, serif; font-size: 24px; font-weight: 500; }
.thumb-header button { width: 40px; height: 40px; display: grid; place-items: center; border: 1px solid rgba(255,255,255,.12); border-radius: 50%; background: rgba(255,255,255,.05); cursor: pointer; }
.thumb-header button svg { width: 20px; height: 20px; }
.thumb-grid { overflow-y: auto; padding: 22px; display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 16px; }
.thumb-grid button { position: relative; padding: 0; border: 2px solid transparent; border-radius: 5px; overflow: hidden; background: #fff; cursor: pointer; box-shadow: 0 8px 16px rgba(0,0,0,.22); transition: transform .2s ease, border-color .2s ease; }
.thumb-grid button:hover { transform: translateY(-3px); }
.thumb-grid button.active { border-color: var(--gold); }
.thumb-grid img { width: 100%; aspect-ratio: .705; object-fit: cover; display: block; }
.thumb-grid span { position: absolute; right: 5px; bottom: 5px; min-width: 22px; height: 22px; display: grid; place-items: center; border-radius: 5px; background: rgba(6,19,33,.86); color: #fff; font-size: 10px; }
.thumb-downloads { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid rgba(255,255,255,.09); }
.thumb-downloads a { display: inline-flex; align-items: center; gap: 7px; padding: 10px 14px; border: 1px solid rgba(255,255,255,.12); border-radius: 9px; color: #fff; text-decoration: none; font-size: 12px; }
.thumb-downloads a:first-child { background: var(--gold); color: #132234; border-color: transparent; font-weight: 700; }
.thumb-downloads svg { width: 17px; height: 17px; }

@media (max-width: 760px) {
  .topbar { height: 64px; padding-inline: 13px; gap: 9px; }
  .brand-mark { width: 34px; }
  .brand-copy .eyebrow { display: none; }
  .brand-copy h1 { max-width: 42vw; overflow: hidden; text-overflow: ellipsis; font-size: 15px; }
  .text-button { width: 40px; padding: 0; }
  .text-button span { display: none; }
  .download-button { min-width: 42px; padding: 0 11px; }
  .download-button span { display: none; }
  .reader-stage { grid-template-columns: 44px minmax(0,1fr) 44px; padding: 14px 2px 44px; }
  .book { width: min(72vw, calc((100svh - 190px) * .705)); aspect-ratio: .705; }
  .book-depth { inset: .8% -1.3% -1.2%; }
  .paper { width: 100%; }
  .page-left { left: 0; border-radius: 4px 7px 7px 4px; }
  .cover-mode .page-left { left: 0; }
  .cover-mode .book-depth { left: 0; right: 0; }
  .spine-light { left: 0; display: none; }
  .flip-sheet, .flip-single { left: 0; width: 100%; }
  .flip-next, .cover-mode .flip-next { left: 0; transform-origin: left center; }
  .flip-next.from-cover { left: 0; }
  .flip-prev { left: 0; transform-origin: right center; }
  .edge-nav { width: 38px; }
  .edge-nav svg { width: 21px; height: 21px; }
  .open-hint { width: 100%; top: calc(100% + 13px); text-align: center; font-size: 10px; }
  .floating-tools { right: 50%; bottom: 5px; transform: translateX(50%); }
  .reader-footer { min-height: 58px; padding: 8px 18px 10px; }
  .reader-footer p { display: none; }
  .thumb-overlay { padding: 8px; }
  .thumb-panel { max-height: 96svh; border-radius: 14px; }
  .thumb-grid { padding: 15px; grid-template-columns: repeat(3, 1fr); gap: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
