:root {
  color-scheme: dark;
  --navy: #06335d;
  --navy-deep: #031d35;
  --blue: #075aa8;
  --aqua: #55c9d5;
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--navy-deep);
  color: white;
  font-family: Arial, Helvetica, sans-serif;
}

button,
a {
  font: inherit;
}

.flipbook-shell {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: 100%;
  height: 100dvh;
  min-height: 420px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 26%, rgba(25, 105, 162, 0.42), transparent 38%),
    linear-gradient(145deg, #052c50 0%, #031d35 72%);
}

.flipbook-shell:fullscreen {
  width: 100vw;
  height: 100vh;
}

.toolbar {
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto minmax(180px, 1fr);
  align-items: center;
  gap: 16px;
  min-height: 66px;
  padding: 10px clamp(12px, 2vw, 28px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(3, 29, 53, 0.88);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
  backdrop-filter: blur(16px);
}

.book-title {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 2px;
  line-height: 1.15;
}

.book-title strong {
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.eyebrow {
  color: var(--aqua);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.controls,
.actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.actions {
  justify-content: flex-end;
}

.toolbar button,
.toolbar a {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 11px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.07);
  color: white;
  text-decoration: none;
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.toolbar button:hover,
.toolbar a:hover {
  border-color: rgba(85, 201, 213, 0.6);
  background: rgba(85, 201, 213, 0.14);
}

.toolbar button:active,
.toolbar a:active {
  transform: translateY(1px);
}

.toolbar button:focus-visible,
.toolbar a:focus-visible,
.thumbnails button:focus-visible {
  outline: 3px solid var(--aqua);
  outline-offset: 2px;
}

.toolbar button:disabled {
  cursor: not-allowed;
  opacity: 0.34;
}

.page-counter {
  min-width: 62px;
  color: rgba(255, 255, 255, 0.82);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.viewer {
  position: relative;
  min-height: 0;
  overflow: hidden;
}

.viewer::after {
  position: absolute;
  right: 12%;
  bottom: 7%;
  left: 12%;
  height: 24px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.48);
  filter: blur(18px);
  content: '';
}

.book-scroll {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  overflow: auto;
  padding: 24px 44px 48px;
  scrollbar-color: rgba(85, 201, 213, 0.55) transparent;
}

.book-zoom {
  display: grid;
  place-items: center;
  width: min(100%, 1400px);
  height: 100%;
  transform-origin: center center;
  transition: transform 180ms ease;
}

.book {
  filter: drop-shadow(0 22px 32px rgba(0, 0, 0, 0.34));
}

.book canvas {
  image-rendering: auto;
}

.loading {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: rgba(255, 255, 255, 0.78);
  font-size: 14px;
  pointer-events: none;
}

.loading[hidden] {
  display: none;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-top-color: var(--aqua);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

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

.hint {
  position: absolute;
  z-index: 4;
  right: 0;
  bottom: 9px;
  left: 0;
  margin: 0;
  color: rgba(255, 255, 255, 0.54);
  font-size: 11px;
  letter-spacing: 0.02em;
  text-align: center;
  pointer-events: none;
}

.thumbnails {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 15;
  padding: 10px 14px 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(2, 18, 33, 0.94);
  box-shadow: 0 -18px 40px rgba(0, 0, 0, 0.28);
  transform: translateY(110%);
  transition: transform 220ms ease;
  backdrop-filter: blur(16px);
}

.thumbnails.is-open {
  transform: translateY(0);
}

.thumbnail-track {
  display: flex;
  gap: 9px;
  overflow-x: auto;
  padding: 3px 2px 7px;
  scrollbar-color: rgba(85, 201, 213, 0.55) transparent;
}

.thumbnails button {
  position: relative;
  flex: 0 0 72px;
  height: 102px;
  overflow: hidden;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 6px;
  background: white;
  cursor: pointer;
}

.thumbnails button.is-current {
  border-color: var(--aqua);
  box-shadow: 0 0 0 2px rgba(85, 201, 213, 0.22);
}

.thumbnails img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumbnails span {
  position: absolute;
  right: 3px;
  bottom: 3px;
  min-width: 20px;
  padding: 2px 4px;
  border-radius: 3px;
  background: rgba(3, 29, 53, 0.88);
  color: white;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 900px) {
  .toolbar {
    grid-template-columns: 1fr auto;
  }

  .controls {
    grid-row: 2;
    grid-column: 1 / -1;
    justify-content: center;
  }

  .actions {
    grid-column: 2;
  }
}

@media (max-width: 620px) {
  .flipbook-shell {
    min-height: 520px;
  }

  .toolbar {
    gap: 7px;
    min-height: 102px;
    padding: 8px 9px;
  }

  .book-title strong {
    max-width: 155px;
    font-size: 12px;
  }

  .toolbar button,
  .toolbar a {
    min-width: 38px;
    padding: 7px 9px;
  }

  .actions .button-label {
    display: none;
  }

  .controls .button-label {
    font-size: 12px;
  }

  .book-scroll {
    padding: 12px 14px 42px;
  }

  .hint {
    font-size: 10px;
  }
}

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