:root {
  --bg: #141218;
  --ink: #f4efe6;
  --muted: #b7aea0;
  --gold: #d4b483;
  --line: rgba(244, 239, 230, 0.12);
  --shadow: 0 28px 80px rgba(0, 0, 0, 0.55);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(1200px 700px at 50% 20%, #2a2430 0%, var(--bg) 58%);
  color: var(--ink);
  font-family: "Segoe UI", "Trebuchet MS", sans-serif;
}

.stage {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.topbar,
.toolbar {
  position: relative;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 28px;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border: 1px solid var(--gold);
  color: var(--gold);
  letter-spacing: 0.08em;
  font-size: 14px;
  font-weight: 700;
}

.brand-kicker {
  margin: 0;
  font-size: 13px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

h1 {
  margin: 4px 0 0;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.ghost,
.icon,
.nav-btn {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--ink);
  cursor: pointer;
}

.ghost {
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
}

.ghost[aria-pressed="true"] {
  border-color: var(--gold);
  color: var(--gold);
}

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

.book-wrap {
  width: auto;
  height: auto;
  max-width: calc(100% - 8px);
  max-height: 100%;
  display: grid;
  place-items: center;
  transform: scale(var(--zoom, 1));
  transform-origin: center center;
  transition: transform 0.2s ease;
  filter: drop-shadow(var(--shadow));
}

#book,
.stf__parent {
  background: transparent;
  overflow: hidden;
}

.stf__item,
.stf__block {
  background: transparent !important;
}

.stf__item img,
.stf__block img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.nav-btn {
  position: absolute;
  top: 50%;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  font-size: 28px;
  line-height: 1;
  transform: translateY(-50%);
  z-index: 4;
}

.nav-prev {
  left: 16px;
}

.nav-next {
  right: 16px;
}

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

.toolbar {
  border-top: 1px solid var(--line);
  background: rgba(8, 7, 10, 0.35);
}

#pageLabel {
  min-width: 120px;
  font-size: 13px;
  color: var(--muted);
}

#pageSlider {
  flex: 1;
  accent-color: var(--gold);
}

.toolbar-btns {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  font-size: 18px;
}

#zoomLabel {
  width: 48px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

.thumbs {
  position: fixed;
  top: 52px;
  right: 12px;
  width: min(260px, 86vw);
  max-height: calc(100vh - 108px);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  background: rgba(20, 18, 24, 0.96);
  backdrop-filter: blur(12px);
  z-index: 8;
}

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

.thumbs-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 10px 8px 12px;
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}

.close {
  width: 28px;
  height: 28px;
  font-size: 20px;
  line-height: 1;
}

.thumbs-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 10px;
  overflow: auto;
}

.thumbs button {
  padding: 0;
  border: 1px solid var(--line);
  background: #000;
  cursor: pointer;
}

.thumbs img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
}

.thumbs button.active {
  outline: 2px solid var(--gold);
}

.loader {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: #121016;
  z-index: 20;
}

.loader[hidden] {
  display: none;
}

.loader-card {
  width: min(360px, 88vw);
  text-align: center;
}

.book-icon {
  width: 54px;
  height: 38px;
  margin: 0 auto 18px;
  position: relative;
}

.book-icon span {
  position: absolute;
  inset: 0;
  border: 2px solid var(--gold);
  transform-origin: left center;
}

.book-icon span:nth-child(1) {
  animation: flip 1.6s ease-in-out infinite;
}

.book-icon span:nth-child(2) {
  animation: flip 1.6s ease-in-out 0.2s infinite;
  opacity: 0.55;
}

.book-icon span:nth-child(3) {
  border-left-width: 4px;
}

@keyframes flip {
  0%,
  100% {
    transform: rotateY(0deg);
  }
  50% {
    transform: rotateY(-140deg);
  }
}

.bar {
  height: 4px;
  margin: 16px 0 10px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.bar i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--gold);
  transition: width 0.2s ease;
}

.loader small {
  color: var(--muted);
}

@media (max-width: 800px) {
  .viewport {
    padding: 8px 12px 16px;
  }

  .nav-btn {
    width: 40px;
    height: 40px;
    font-size: 24px;
  }

  .nav-prev {
    left: 4px;
  }

  .nav-next {
    right: 4px;
  }

  .topbar,
  .toolbar {
    padding: 12px 14px;
  }

  h1 {
    font-size: 16px;
    white-space: normal;
  }
}
