:root {
  --warrior-navy: #07182f;
  --warrior-blue: #2463ad;
  --warrior-blue-bright: #2e72c5;
  --reader-height: 100dvh;
  --edge-blend: 5px;
  --mobile-book-width: 104vw;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--warrior-navy);
  overscroll-behavior: none;
}

body {
  position: fixed;
  inset: 0;
  color: #fff;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

button {
  font: inherit;
}

.reader {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: var(--reader-height);
  overflow: hidden;
  isolation: isolate;
  background:
    radial-gradient(circle at 50% 44%, rgba(39, 99, 173, 0.18), transparent 48%),
    var(--warrior-navy);
  touch-action: none;
}

.book-stage {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 0;
}

.book {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  filter: drop-shadow(0 10px 20px rgba(0, 0, 0, 0.42));
}

.book canvas,
.book > div {
  max-width: 100%;
  max-height: 100%;
}

.blue-overlay {
  position: fixed;
  left: 0;
  right: 0;
  z-index: 30;
  pointer-events: none;
}

.blue-overlay-top {
  top: 0;
  height: calc(var(--edge-blend) + var(--safe-top));
  background: linear-gradient(to bottom, var(--warrior-navy) 0%, rgba(7, 24, 47, 0.88) calc(var(--safe-top) + 1px), rgba(7, 24, 47, 0) 100%);
}

.blue-overlay-bottom {
  bottom: 0;
  height: calc(var(--edge-blend) + var(--safe-bottom));
  background: linear-gradient(to top, var(--warrior-navy) 0%, rgba(7, 24, 47, 0.88) calc(var(--safe-bottom) + 1px), rgba(7, 24, 47, 0) 100%);
}

.nav-button {
  position: fixed;
  top: 50%;
  z-index: 50;
  width: 48px;
  height: 72px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: rgba(19, 65, 122, 0.60);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  transform: translateY(-50%);
  opacity: 0.28;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: opacity 180ms ease, background 180ms ease, transform 180ms ease;
  touch-action: manipulation;
}

.controls-visible .nav-button,
.nav-button:focus-visible,
.nav-button:active {
  opacity: 0.90;
  background: rgba(25, 86, 160, 0.86);
}

.nav-button:active {
  transform: translateY(-50%) scale(0.94);
}

.nav-button:focus-visible,
.pdf-link:focus-visible,
.utility-button:focus-visible,
.overlay-icon-button:focus-visible,
.thumbnail-item:focus-visible {
  outline: 3px solid rgba(255, 255, 255, 0.88);
  outline-offset: 3px;
}

.nav-button svg {
  width: 29px;
  height: 29px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.25;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-button-previous {
  left: max(8px, var(--safe-left));
}

.nav-button-next {
  right: max(8px, var(--safe-right));
}

.nav-button[hidden] {
  display: none;
}

.utility-controls {
  position: fixed;
  top: calc(12px + var(--safe-top));
  right: calc(12px + var(--safe-right));
  z-index: 62;
  display: flex;
  gap: 8px;
}

.utility-button,
.overlay-icon-button {
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.20);
  border-radius: 999px;
  background: rgba(5, 20, 42, 0.72);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: opacity 180ms ease, background 180ms ease, transform 180ms ease;
  touch-action: manipulation;
}

.utility-button {
  opacity: 0.22;
}

.controls-visible .utility-button,
.utility-button:hover,
.utility-button:focus-visible,
.utility-button:active,
.drawer-open .utility-button,
.zoom-open .utility-button {
  opacity: 0.92;
}

.utility-button:active,
.overlay-icon-button:active,
.thumbnail-item:active {
  transform: scale(0.94);
}

.utility-button svg,
.overlay-icon-button svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.15;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.thumbnail-backdrop {
  position: fixed;
  inset: 0;
  z-index: 84;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: rgba(5, 20, 42, 0.22);
  cursor: default;
}

.thumbnail-backdrop[hidden] {
  display: none;
}

.thumbnail-drawer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 92;
  max-height: min(72vh, 620px);
  display: flex;
  flex-direction: column;
  border-top: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(5, 20, 42, 0.94);
  color: #fff;
  box-shadow: 0 -18px 38px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.thumbnail-drawer[hidden] {
  display: none;
}

.thumbnail-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px max(18px, var(--safe-right)) 10px max(18px, var(--safe-left));
}

.thumbnail-drawer-header h2 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.2;
  font-weight: 750;
}

.thumbnail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(86px, 1fr));
  gap: 10px;
  overflow-y: auto;
  padding: 0 max(18px, var(--safe-right)) calc(18px + var(--safe-bottom)) max(18px, var(--safe-left));
  scrollbar-color: rgba(255, 255, 255, 0.35) transparent;
}

.thumbnail-item {
  min-width: 0;
  padding: 6px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.90);
  cursor: pointer;
  display: grid;
  gap: 6px;
  text-align: left;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.thumbnail-item img {
  display: block;
  width: 100%;
  aspect-ratio: 2 / 3;
  border-radius: 5px;
  object-fit: cover;
  background: rgba(255, 255, 255, 0.08);
}

.thumbnail-item span {
  overflow: hidden;
  color: inherit;
  font-size: 0.74rem;
  font-weight: 700;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thumbnail-item:hover,
.thumbnail-item.is-current {
  border-color: rgba(255, 138, 24, 0.92);
  background: rgba(255, 138, 24, 0.14);
}

.zoom-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  overflow: hidden;
  background: rgba(5, 20, 42, 0.97);
  color: #fff;
}

.zoom-overlay[hidden] {
  display: none;
}

.zoom-toolbar {
  position: fixed;
  top: calc(10px + var(--safe-top));
  left: max(10px, var(--safe-left));
  right: max(10px, var(--safe-right));
  z-index: 104;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  pointer-events: none;
}

.zoom-toolbar .overlay-icon-button,
.zoom-label {
  pointer-events: auto;
}

.zoom-label {
  min-width: 58px;
  padding: 10px 8px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: rgba(5, 20, 42, 0.72);
  color: rgba(255, 255, 255, 0.94);
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1;
  text-align: center;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.overlay-icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.38;
}

.zoom-viewport {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(62px + var(--safe-top));
  bottom: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 10px 12px calc(18px + var(--safe-bottom));
  cursor: zoom-in;
  touch-action: none;
}

.zoom-viewport.is-pannable {
  cursor: grab;
}

.zoom-viewport.is-pannable:active {
  cursor: grabbing;
}

.zoom-image {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  transform-origin: center center;
  user-select: none;
  -webkit-user-drag: none;
  will-change: transform;
  filter: drop-shadow(0 12px 26px rgba(0, 0, 0, 0.42));
}

.pdf-link {
  position: fixed;
  top: calc(12px + var(--safe-top));
  right: calc(12px + var(--safe-right));
  z-index: 55;
  padding: 7px 10px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  background: rgba(5, 20, 42, 0.72);
  color: rgba(255, 255, 255, 0.94);
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
  letter-spacing: 0.04em;
  opacity: 0.18;
  transition: opacity 180ms ease, background 180ms ease;
}

.controls-visible .pdf-link,
.pdf-link:hover,
.pdf-link:focus-visible {
  opacity: 0.92;
}

.preview-ribbon {
  position: fixed;
  left: calc(12px + var(--safe-left));
  top: calc(12px + var(--safe-top));
  z-index: 70;
  padding: 7px 10px;
  border-radius: 999px;
  background: rgba(255, 138, 24, 0.90);
  color: #111827;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  pointer-events: none;
}

.loading {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  background: var(--warrior-navy);
  opacity: 1;
  transition: opacity 240ms ease, visibility 240ms ease;
}

.loading.is-complete {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-spinner {
  width: 38px;
  height: 38px;
  border: 3px solid rgba(255, 255, 255, 0.22);
  border-top-color: var(--warrior-blue-bright);
  border-radius: 50%;
  animation: spin 720ms linear infinite;
}

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

.swipe-hint {
  position: fixed;
  left: 50%;
  bottom: calc(64px + var(--safe-bottom));
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  background: rgba(5, 20, 42, 0.72);
  color: rgba(255, 255, 255, 0.94);
  font-size: 13px;
  font-weight: 650;
  transform: translateX(-50%);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  animation: hint-in-out 4.2s 800ms ease both;
  pointer-events: none;
  white-space: nowrap;
}

.swipe-hint svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.swipe-hint.dismissed {
  display: none;
}

@keyframes hint-in-out {
  0% { opacity: 0; transform: translate(-50%, 8px); }
  12%, 72% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, 0); }
}

.library-error {
  position: fixed;
  left: 50%;
  bottom: calc(66px + var(--safe-bottom));
  z-index: 90;
  width: min(90vw, 460px);
  margin: 0;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(5, 20, 42, 0.88);
  color: rgba(255, 255, 255, 0.92);
  font-size: 13px;
  text-align: center;
  transform: translateX(-50%);
  pointer-events: none;
}

.fallback-book {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  filter: drop-shadow(0 10px 20px rgba(0, 0, 0, 0.42));
}

.fallback-book[hidden] {
  display: none;
}

.fallback-book img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.noscript-message,
.unavailable-state {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  margin: 0;
  padding: 30px;
  background: var(--warrior-navy);
  color: #fff;
  text-align: center;
}

.unavailable-state h1 {
  margin: 0;
  font-size: clamp(1.5rem, 4vw, 2.5rem);
}

.unavailable-state p {
  margin: 0;
  color: rgba(255, 255, 255, 0.78);
}

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

@media (hover: hover) and (pointer: fine) {
  .reader:hover .nav-button,
  .reader:hover .utility-button {
    opacity: 0.72;
  }
}

@media (max-width: 700px) and (orientation: portrait) {
  .book.stf__parent {
    width: var(--mobile-book-width) !important;
    max-width: none !important;
  }

  .fallback-book img {
    max-width: var(--mobile-book-width);
    max-height: none;
  }

  .utility-controls {
    top: calc(9px + var(--safe-top));
    right: calc(9px + var(--safe-right));
  }

  .utility-button,
  .overlay-icon-button {
    width: 42px;
    height: 42px;
  }

  .thumbnail-grid {
    grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  .loading-spinner,
  .swipe-hint {
    animation: none;
  }

  .swipe-hint {
    opacity: 1;
  }

  .nav-button,
  .loading,
  .pdf-link,
  .utility-button,
  .overlay-icon-button,
  .thumbnail-item {
    transition: none;
  }
}
