:root {
  --navy-950: #020914;
  --navy-900: #061326;
  --gold-300: #e5c17d;
  --paper: #f6f2e9;
  --white: #f7f8fb;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--navy-950);
}

body {
  color: var(--white);
  font-family: Cambria, Georgia, "Times New Roman", serif;
  overflow: hidden;
}

button {
  font: inherit;
}

[hidden] {
  display: none !important;
}

.flipbook-app {
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100vh;
  height: 100svh;
  padding: 14px clamp(14px, 2.2vw, 34px) 18px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 44%, rgba(21, 54, 90, 0.5), transparent 47%),
    radial-gradient(circle at 16% 5%, rgba(202, 155, 80, 0.1), transparent 28%),
    linear-gradient(145deg, #020814 0%, #061326 54%, #020812 100%);
}

.flipbook-app::before,
.flipbook-app::after {
  position: absolute;
  z-index: -1;
  width: min(28vw, 390px);
  height: min(28vw, 390px);
  border: 1px solid rgba(202, 155, 80, 0.12);
  border-radius: 50%;
  content: "";
  pointer-events: none;
}

.flipbook-app::before {
  top: -22vw;
  right: -8vw;
  box-shadow:
    0 0 0 32px rgba(202, 155, 80, 0.025),
    0 0 0 64px rgba(202, 155, 80, 0.018);
}

.flipbook-app::after {
  bottom: -24vw;
  left: -8vw;
  box-shadow:
    0 0 0 32px rgba(202, 155, 80, 0.025),
    0 0 0 64px rgba(202, 155, 80, 0.018);
}

.viewer-header {
  position: relative;
  z-index: 30;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-height: 54px;
  border-bottom: 1px solid rgba(221, 180, 109, 0.22);
  padding-bottom: 12px;
}

.wordmark {
  display: flex;
  flex-direction: column;
  width: max-content;
  letter-spacing: 0.13em;
  line-height: 1;
}

.wordmark > span {
  color: var(--gold-300);
  font-size: clamp(1.02rem, 1.45vw, 1.28rem);
}

.wordmark > small {
  margin-top: 7px;
  color: rgba(233, 237, 244, 0.6);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.57rem;
  letter-spacing: 0.19em;
}

.interaction-hint {
  margin: 0;
  color: rgba(236, 239, 245, 0.62);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.73rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.mobile-hint {
  display: none;
}

.icon-button,
.nav-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(221, 180, 109, 0.26);
  border-radius: 999px;
  color: rgba(246, 247, 250, 0.9);
  background: rgba(8, 22, 40, 0.72);
  cursor: pointer;
  transition:
    border-color 180ms ease,
    background-color 180ms ease,
    color 180ms ease,
    transform 180ms ease;
}

.icon-button:hover,
.nav-button:hover:not(:disabled) {
  border-color: rgba(229, 193, 125, 0.72);
  color: var(--gold-300);
  background: rgba(15, 35, 61, 0.94);
}

.icon-button:focus-visible,
.nav-button:focus-visible {
  outline: 2px solid var(--gold-300);
  outline-offset: 3px;
}

.fullscreen-button {
  justify-self: end;
  gap: 9px;
  min-height: 38px;
  padding: 0 14px;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.76rem;
  letter-spacing: 0.06em;
}

.button-icon {
  width: 19px;
  height: 19px;
  flex: 0 0 auto;
}

.viewer-area {
  position: relative;
  display: grid;
  min-height: 0;
  place-items: center;
  overflow: hidden;
  padding: 12px 0 8px;
}

.book-positioner {
  --book-offset: 0%;
  --book-zoom: 1;
  --book-pan-x: 0px;
  --book-pan-y: 0px;
  width: min(94vw, calc((100vh - 160px) * 1.414));
  width: min(94vw, calc((100svh - 160px) * 1.414));
  max-width: 1508px;
  filter: drop-shadow(0 24px 42px rgba(0, 0, 0, 0.38));
  transform: translate3d(var(--book-pan-x), var(--book-pan-y), 0) translateX(var(--book-offset)) scale(var(--book-zoom));
  transform-origin: center;
  transition: transform 220ms ease;
  will-change: transform;
}

.book-positioner--front {
  --book-offset: -25%;
}

.book-positioner--back {
  --book-offset: 25%;
}

.viewer-area.is-zoomed { cursor: grab; touch-action: none; }
.viewer-area.is-dragging { cursor: grabbing; }

.page-flip-book {
  width: 100%;
  min-width: 0 !important;
  min-height: 0 !important;
  user-select: none;
  -webkit-user-select: none;
}

.book-page {
  position: relative;
  overflow: hidden;
  background: var(--paper);
  box-shadow:
    inset 0 0 0 1px rgba(37, 31, 24, 0.09),
    inset 0 0 24px rgba(31, 27, 22, 0.035);
}

.book-page img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}

.book-page--blank {
  background:
    linear-gradient(90deg, rgba(28, 23, 18, 0.035), transparent 3.5%),
    linear-gradient(180deg, #fbfaf6 0%, var(--paper) 100%);
}

.stf__parent {
  position: relative;
  display: block;
  transform: translateZ(0);
  touch-action: pan-y;
}

.stf__wrapper {
  position: relative;
  width: 100%;
}

.stf__parent canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.stf__block {
  position: absolute;
  width: 100%;
  height: 100%;
  perspective: 2400px;
}

.stf__item {
  position: absolute;
  display: none;
  transform-style: preserve-3d;
}

.stf__outerShadow,
.stf__innerShadow,
.stf__hardShadow,
.stf__hardInnerShadow {
  position: absolute;
  top: 0;
  left: 0;
}

.loading-state,
.error-state {
  position: absolute;
  z-index: 25;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  color: rgba(240, 242, 247, 0.72);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-align: center;
  text-transform: uppercase;
  transition: opacity 320ms ease;
}

.loading-state--hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-state p,
.error-state p,
.error-state small {
  margin: 0;
}

.error-state small {
  max-width: 420px;
  color: rgba(240, 242, 247, 0.52);
  font-size: 0.66rem;
  line-height: 1.6;
}

.loading-mark {
  width: 34px;
  height: 34px;
  border: 1px solid rgba(229, 193, 125, 0.24);
  border-top-color: var(--gold-300);
  border-radius: 50%;
  animation: spin 900ms linear infinite;
}

.viewer-controls {
  position: relative;
  z-index: 30;
  display: grid;
  grid-template-columns: 1fr auto auto 1fr;
  gap: 14px;
  align-items: center;
  width: min(100%, 820px);
  margin: 0 auto;
  padding-top: 10px;
}

.nav-button {
  gap: 9px;
  min-width: 112px;
  min-height: 42px;
  padding: 0 16px;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.82rem;
  letter-spacing: 0.04em;
}

.nav-button:first-child {
  justify-self: end;
}

.nav-button:last-child {
  justify-self: start;
}

.nav-button:active:not(:disabled) {
  transform: translateY(1px);
}

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

.page-status {
  display: flex;
  align-items: baseline;
  justify-content: center;
  min-width: 170px;
  color: rgba(240, 242, 247, 0.64);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.page-status strong {
  min-width: 42px;
  margin: 0 7px;
  color: var(--gold-300);
  font-family: Cambria, Georgia, "Times New Roman", serif;
  font-size: 1.08rem;
  font-weight: 400;
  letter-spacing: 0.02em;
  text-align: center;
}

.page-status small {
  font-size: inherit;
}

.zoom-controls { display:flex; align-items:center; gap:6px; font-family:Arial,Helvetica,sans-serif; }
.zoom-button,.zoom-fit-button { min-height:36px; border:1px solid rgba(221,180,109,.26); color:rgba(246,247,250,.9); background:rgba(8,22,40,.72); cursor:pointer; }
.zoom-button { width:36px; border-radius:50%; font-size:1.15rem; }
.zoom-fit-button { border-radius:999px; padding:0 12px; font-size:.72rem; }
.zoom-controls output { min-width:52px; color:var(--gold-300); font-size:.78rem; text-align:center; }
.zoom-button:hover:not(:disabled),.zoom-fit-button:hover { border-color:rgba(229,193,125,.72); color:var(--gold-300); }
.zoom-button:disabled { cursor:default; opacity:.3; }

.flipbook-app:fullscreen {
  width: 100%;
  min-height: 100%;
}

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

@media (max-width: 720px) {
  .flipbook-app {
    padding: 10px 10px 14px;
  }

  .viewer-header {
    grid-template-columns: 1fr auto;
    min-height: 48px;
    padding: 0 2px 9px;
  }

  .wordmark > small {
    max-width: 230px;
    font-size: 0.51rem;
    line-height: 1.35;
  }

  .interaction-hint {
    display: none;
  }

  .fullscreen-button {
    width: 38px;
    min-height: 38px;
    padding: 0;
  }

  .fullscreen-button span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .viewer-area {
    padding: 8px 0 4px;
  }

  .book-positioner,
  .book-positioner.portrait {
    width: min(94vw, calc((100vh - 142px) * 0.707));
    width: min(94vw, calc((100svh - 142px) * 0.707));
  }

  .book-positioner--front,
  .book-positioner--back { --book-offset: 0%; }

  .viewer-controls {
    grid-template-columns: 1fr auto 1fr;
    gap: 6px;
    padding-top: 6px;
  }

  .zoom-controls { grid-column:1 / -1; grid-row:2; justify-self:center; }
  .zoom-fit-button { min-height:32px; }

  .nav-button {
    min-width: 46px;
    min-height: 42px;
    padding: 0 12px;
  }

  .nav-button span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .page-status {
    min-width: 128px;
  }
}

@media (hover: none) {
  .desktop-hint {
    display: none;
  }

  .mobile-hint {
    display: inline;
  }
}

@media (prefers-reduced-motion: reduce) {
  .book-positioner,
  .icon-button,
  .nav-button,
  .loading-state {
    transition-duration: 0.01ms;
  }

  .loading-mark {
    animation-duration: 1.8s;
  }
}
