:root {
  color-scheme: dark;
  --wine: #681514;
  --wine-dark: #2b0909;
  --red: #cf1c1c;
  --gold: #ffbd18;
  --paper: #fff;
  --muted: #d7caca;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  overflow-x: hidden;
  color: #fff;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 50% 10%, rgba(207, 28, 28, .32), transparent 34rem),
    linear-gradient(145deg, #160505 0%, var(--wine-dark) 50%, #120303 100%);
}

button, input { font: inherit; }
button { color: inherit; }

.reader {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.toolbar {
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px clamp(16px, 4vw, 48px);
  border-bottom: 1px solid rgba(255,255,255,.12);
  background: rgba(31, 5, 5, .72);
  backdrop-filter: blur(16px);
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 13px; }
.brand-logo { display: block; width: auto; height: 42px; object-fit: contain; }
.brand-copy { color: var(--muted); font-size: .87rem; letter-spacing: .06em; text-transform: uppercase; }
.toolbar-actions { display: flex; gap: 8px; }

.icon-button, .nav-button, .text-button, .zoom-close {
  border: 0;
  cursor: pointer;
}
.icon-button {
  width: 42px;
  height: 42px;
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 50%;
  background: rgba(255,255,255,.08);
  font-size: 1.35rem;
  transition: background .2s, transform .2s;
}
.icon-button:hover { background: rgba(255,255,255,.16); transform: translateY(-1px); }

.stage {
  min-height: 420px;
  display: grid;
  grid-template-columns: minmax(48px, 1fr) auto minmax(48px, 1fr);
  align-items: center;
  gap: clamp(10px, 3vw, 38px);
  padding: clamp(18px, 3vh, 30px) clamp(8px, 2vw, 32px);
  perspective: 1800px;
  touch-action: pan-y;
}

.book-shell {
  position: relative;
  width: min(104vh, 1192px, 76vw);
  aspect-ratio: 1192 / 842;
  filter: drop-shadow(0 28px 28px rgba(0,0,0,.46));
}
.single-page-preview {
  position: absolute;
  top: 0;
  left: 25%;
  z-index: 6;
  display: block;
  width: 50%;
  height: 100%;
  border-radius: 5px;
  object-fit: contain;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  box-shadow: 0 18px 35px rgba(0,0,0,.25);
}
.book-shell.show-single-preview .book { opacity: 0; }
.book-shell.show-single-preview .single-page-preview { opacity: 1; visibility: visible; }
.book-shell::after {
  content: "";
  position: absolute;
  left: 7%; right: 7%; bottom: -14px;
  height: 22px;
  border-radius: 50%;
  background: rgba(0,0,0,.38);
  filter: blur(11px);
  z-index: -1;
}
.book {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 6px;
  background: transparent;
  cursor: grab;
  touch-action: none;
}
.book:active { cursor: grabbing; }
.book canvas { border-radius: 5px; }
.book .stf__parent { margin: 0 auto; }
.catalog-page {
  overflow: hidden;
  border-radius: 4px;
  background: #fff;
}
.catalog-page img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
  user-select: none;
  pointer-events: none;
}
.page { position: absolute; top: 0; bottom: 0; width: 50%; overflow: hidden; background: #fff; transition: left .35s, right .35s, width .35s; }
.page-left { left: 0; border-radius: 6px 0 0 6px; }
.page-right { right: 0; border-radius: 0 6px 6px 0; }
.page img { display: block; width: 100%; height: 100%; object-fit: contain; user-select: none; cursor: zoom-in; touch-action: manipulation; }
.book.single .page-left { display: none; }
.book.single .page-right { right: 25%; width: 50%; border-radius: 6px; box-shadow: inset 8px 0 12px rgba(0,0,0,.08); }
.book-gutter { position: absolute; top: 0; bottom: 0; left: 50%; width: 18px; z-index: 5; transform: translateX(-50%); background: linear-gradient(90deg, rgba(0,0,0,.18), rgba(255,255,255,.12) 46%, rgba(0,0,0,.15)); pointer-events: none; }
.book.single .book-gutter { display: none; }
.turn-sheet { position: absolute; top: 0; right: 0; width: 50%; height: 100%; z-index: 12; transform-origin: left center; transform-style: preserve-3d; pointer-events: none; visibility: hidden; }
.book.single .turn-sheet { right: 25%; }
.turn-sheet.active { visibility: visible; }
.turn-face { position: absolute; inset: 0; overflow: hidden; background: #fff; backface-visibility: hidden; }
.turn-face img { width: 100%; height: 100%; display: block; object-fit: contain; }
.turn-front { border-radius: 0 6px 6px 0; }
.turn-back { border-radius: 6px 0 0 6px; transform: rotateY(180deg); }
.turn-shadow { position: absolute; inset: 0; opacity: 0; background: linear-gradient(90deg, rgba(0,0,0,.36), transparent 40%, rgba(255,255,255,.18)); backface-visibility: hidden; pointer-events: none; }
.turn-sheet.settling { transition: transform .42s cubic-bezier(.22,.75,.25,1); }
.page-drag-hint { position: absolute; right: -7px; top: 50%; width: 38px; height: 84px; z-index: 15; transform: translateY(-50%); border: 0; border-radius: 30px 0 0 30px; color: #fff; background: rgba(207,28,28,.9); cursor: grab; box-shadow: -4px 5px 16px rgba(0,0,0,.25); touch-action: none; }
.book.single .page-drag-hint { right: calc(25% - 7px); }
.page-drag-hint:active { cursor: grabbing; }
.page-drag-hint span::before { content: "‹"; font-size: 2rem; line-height: 1; }
.page-drag-hint::after { content: "puxe"; position: absolute; right: 5px; bottom: -24px; color: rgba(255,255,255,.7); font-size: .62rem; letter-spacing: .08em; text-transform: uppercase; }
.book.at-end .page-drag-hint { display: none; }

.loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 5px;
  color: #5b4747;
  background: #f6f1ef;
  z-index: 8;
}
.loading.hidden { opacity: 0; visibility: hidden; transition: opacity .3s, visibility .3s; }

.nav-button {
  display: flex;
  align-items: center;
  justify-content: center;
  justify-self: end;
  width: clamp(44px, 5vw, 60px);
  height: clamp(70px, 9vw, 92px);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 999px;
  background: rgba(255,255,255,.08);
  font-size: clamp(2.5rem, 5vw, 4rem);
  line-height: 1;
  padding: 0;
  transition: background .2s, transform .2s, opacity .2s;
}
.nav-next { justify-self: start; }
.nav-button span { display: block; line-height: 1; transform: translateY(-.06em); }
.nav-previous span { transform: translate(-.04em, -.06em); }
.nav-next span { transform: translate(.04em, -.06em); }
.nav-button:hover:not(:disabled) { background: var(--red); transform: scale(1.04); }
.nav-button:disabled { cursor: default; opacity: .2; }

.pagination {
  position: relative;
  display: grid;
  gap: 12px;
  padding: 12px clamp(12px, 4vw, 44px) max(14px, env(safe-area-inset-bottom));
  border-top: 1px solid rgba(255,255,255,.1);
  background: rgba(20, 3, 3, .78);
  backdrop-filter: blur(14px);
}
.page-status { display: flex; align-items: center; justify-content: center; gap: 9px; color: var(--muted); font-size: .9rem; }
.page-status strong { color: #fff; }
.page-status input {
  width: 54px;
  height: 34px;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 7px;
  color: #fff;
  background: rgba(255,255,255,.1);
  text-align: center;
}
.text-button { padding: 7px 10px; color: #f5dada; background: transparent; font-size: .82rem; }
.text-button:hover { color: var(--gold); }
.thumbnails {
  display: flex;
  gap: 8px;
  max-width: 100%;
  padding: 3px 2px 6px;
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: #9b3737 transparent;
}
.thumbnail {
  flex: 0 0 44px;
  width: 44px;
  height: 62px;
  padding: 0;
  overflow: hidden;
  border: 2px solid transparent;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  opacity: .55;
  transition: opacity .2s, border-color .2s, transform .2s;
}
.thumbnail img { display: block; width: 100%; height: 100%; object-fit: cover; }
.thumbnail:hover { opacity: .9; transform: translateY(-2px); }
.thumbnail.active { border-color: var(--gold); opacity: 1; box-shadow: 0 0 0 2px rgba(255,189,24,.18); }

.zoom-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 32px;
  overflow: auto;
  background: rgba(10, 2, 2, .94);
  backdrop-filter: blur(10px);
}
.zoom-overlay[hidden] { display: none; }
.zoom-overlay img { max-width: none; width: min(90vw, 900px); height: auto; box-shadow: 0 20px 60px #000; }
.zoom-close { position: fixed; top: 16px; right: 20px; z-index: 2; width: 46px; height: 46px; border-radius: 50%; background: var(--red); font-size: 2rem; line-height: 1; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }

@media (max-width: 700px) {
  .toolbar { min-height: 58px; padding-block: 8px; }
  .brand-copy { display: none; }
  .stage { min-height: 0; grid-template-columns: 42px minmax(0, 1fr) 42px; gap: 5px; padding: 12px 4px; }
  .book-shell { width: min(calc(100vw - 94px), 62vh); aspect-ratio: 596 / 842; }
  .book.single .page-right { right: 0; width: 100%; }
  .book.single .turn-sheet { right: 0; width: 100%; }
  .book.single .page-drag-hint { right: -7px; }
  .nav-button { width: 40px; height: 64px; font-size: 2.6rem; background: transparent; border-color: transparent; }
  .pagination { padding-inline: 10px; }
  .text-button { display: none; }
}

@media (max-height: 700px) and (min-width: 701px) {
  .toolbar { min-height: 56px; padding-block: 7px; }
  .book-shell { width: min(55vh, 420px, 65vw); }
  .pagination { padding-block: 8px; }
  .thumbnail { flex-basis: 34px; width: 34px; height: 48px; }
}

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