:root {
  color-scheme: dark;
  --ink: #1a1816;
  --panel: #24211e;
  --paper: #f7f4ee;
  --warm: #b79b73;
  --muted: #aaa29a;
  --line: rgba(255, 255, 255, 0.14);
  --book-ratio: 1.54545;
}

* { box-sizing: border-box; }

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

body {
  min-height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 28%, rgba(119, 98, 72, .2), transparent 40%),
    linear-gradient(145deg, #28241f 0%, #171513 56%, #0e0d0c 100%);
  color: var(--paper);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

.topbar {
  height: 72px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 20px;
  padding: 0 clamp(18px, 3vw, 44px);
  border-bottom: 1px solid var(--line);
  background: rgba(20, 18, 16, .8);
  backdrop-filter: blur(18px);
  position: relative;
  z-index: 20;
}

.brand { display: inline-flex; width: max-content; flex-direction: column; line-height: 1; }
.brand-mark { font-family: Georgia, "Times New Roman", serif; font-size: 1.25rem; letter-spacing: .16em; }
.brand-sub { margin-top: 5px; font-size: .54rem; letter-spacing: .28em; color: var(--warm); }
.catalog-title { display: flex; flex-direction: column; align-items: center; gap: 3px; font-family: Georgia, "Times New Roman", serif; font-size: 1.1rem; letter-spacing: .025em; }
.catalog-hint { color: var(--warm); font-family: Inter, ui-sans-serif, sans-serif; font-size: .58rem; font-weight: 700; letter-spacing: .13em; text-transform: uppercase; }
.header-actions { justify-self: end; display: flex; align-items: center; gap: 8px; }
.icon-button .sound-off { display: none; }
.icon-button.is-muted .sound-on { display: none; }
.icon-button.is-muted .sound-off { display: block; }

.icon-button,
.page-arrow,
.control-button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .055);
  cursor: pointer;
  transition: background .2s ease, border-color .2s ease, transform .2s ease, opacity .2s ease;
}

.icon-button:hover,
.page-arrow:hover,
.control-button:hover { background: rgba(255,255,255,.11); border-color: rgba(255,255,255,.26); }
.icon-button:focus-visible,
.page-arrow:focus-visible,
.control-button:focus-visible,
.page-status input:focus-visible { outline: 2px solid var(--warm); outline-offset: 3px; }

.icon-button {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
}

.icon-button svg,
.page-arrow svg,
.control-button svg,
.zoom-tool svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.reader-shell {
  height: calc(100dvh - 132px);
  min-height: 360px;
  display: grid;
  place-items: center;
  padding: 18px 24px;
}

.reader {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) 54px;
  align-items: center;
  gap: clamp(8px, 1.4vw, 22px);
}

.book-wrap { position: relative; display: grid; place-items: center; min-width: 0; min-height: 0; height: 100%; overflow: visible; }

.book {
  position: relative;
  width: 100% !important;
  height: 100%;
  min-width: 0 !important;
  min-height: 0 !important;
  max-width: none !important;
  display: block;
  cursor: zoom-in;
  user-select: none;
  touch-action: pan-y;
  transform: translateZ(0);
  contain: layout paint style;
}

.book .stf__wrapper { position: relative; width: 100%; height: 100%; }
.book .stf__block { overflow: visible; }
.book canvas { image-rendering: auto; }

.page-hotspots {
  position: absolute;
  inset: 0;
  z-index: 15;
  pointer-events: none;
}
.page-hotspot-layer { position: absolute; pointer-events: none; }
.catalog-hotspot {
  position: absolute;
  display: block;
  pointer-events: auto;
  border: 0;
  background: transparent;
  cursor: pointer;
}
.catalog-hotspot:focus-visible {
  outline: 2px solid rgba(255,255,255,.9);
  outline-offset: 2px;
}
.hotspot-badge {
  position: absolute;
  right: 6px;
  bottom: 6px;
  display: inline-grid;
  place-items: center;
  align-items: center;
  width: 18px;
  height: 18px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  color: rgba(80,77,72,.9);
  background: rgba(255,255,255,.88);
  box-shadow: 0 1px 5px rgba(0,0,0,.24);
  font-size: .82rem;
  font-weight: 400;
  letter-spacing: 0;
  line-height: 1;
  white-space: nowrap;
  opacity: .86;
  transition: opacity .18s ease, transform .18s ease, background .18s ease;
}
.catalog-hotspot:hover .hotspot-badge,
.catalog-hotspot:focus-visible .hotspot-badge {
  opacity: 1;
  transform: scale(1.08);
  background: #fff;
}

.page-arrow {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  display: grid;
  place-items: center;
}
.page-arrow:active { transform: scale(.96); }
.page-arrow[disabled], .control-button[disabled] { opacity: .26; cursor: default; pointer-events: none; }

.controls {
  height: 60px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 18px;
  padding: 0 18px max(0px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(20, 18, 16, .9);
  backdrop-filter: blur(18px);
  position: relative;
  z-index: 20;
}

.control-button {
  min-width: 120px;
  height: 38px;
  padding: 0 14px;
  border-radius: 999px;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  font-size: .82rem;
  letter-spacing: .03em;
}

.page-status {
  min-width: 118px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
  font-size: .82rem;
}

.page-status input {
  width: 50px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(255,255,255,.06);
  color: var(--paper);
  text-align: center;
  appearance: textfield;
}
.page-status input::-webkit-outer-spin-button,
.page-status input::-webkit-inner-spin-button { appearance: none; margin: 0; }

.zoom-viewer {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  grid-template-rows: 58px minmax(0, 1fr);
  background: rgba(13, 12, 11, .96);
  backdrop-filter: blur(18px);
}
.zoom-viewer[hidden] { display: none; }

.zoom-toolbar {
  display: grid;
  grid-template-columns: 46px minmax(130px, 1fr) auto 46px;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(20, 18, 16, .92);
}
.zoom-title {
  min-width: 0;
  text-align: center;
  color: var(--muted);
  font-size: .86rem;
  letter-spacing: .03em;
}
.zoom-actions { display: flex; align-items: center; justify-content: center; gap: 8px; }
.zoom-tool {
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--paper);
  background: rgba(255,255,255,.06);
  cursor: pointer;
}
.zoom-tool:hover { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.28); }
.zoom-tool:focus-visible { outline: 2px solid var(--warm); outline-offset: 2px; }
.zoom-tool:disabled { opacity: .25; pointer-events: none; }
.zoom-level { min-width: 48px; text-align: center; color: var(--muted); font-size: .76rem; }
.zoom-close { margin-left: 8px; }

.zoom-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 22px;
  overscroll-behavior: contain;
  cursor: zoom-in;
}
.zoom-stage.is-max-zoom { cursor: zoom-out; }
.zoom-stage.is-dragging { cursor: grabbing; user-select: none; }
.zoom-page {
  position: relative;
  width: 0;
  margin: 0 auto;
  background: var(--paper);
  box-shadow: 0 24px 55px rgba(0,0,0,.5);
}
.zoom-image { display: block; width: 100%; height: auto; opacity: 0; transition: opacity .18s ease; }
.zoom-image.is-ready { opacity: 1; }
.zoom-hotspots { position: absolute; inset: 0; pointer-events: none; }
.zoom-hotspot {
  position: absolute;
  pointer-events: auto;
}
.zoom-hotspot .hotspot-badge { right: 8px; bottom: 8px; }
.zoom-loading {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  color: var(--muted);
  font-size: .82rem;
  letter-spacing: .04em;
}
.zoom-loading.is-hidden { display: none; }

.loading {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: #191714;
  transition: opacity .5s ease, visibility .5s ease;
}
.loading.is-hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.loading-mark { font-family: Georgia, "Times New Roman", serif; font-size: 2rem; letter-spacing: .22em; }
.loading-line { width: 150px; height: 1px; margin-top: 20px; overflow: hidden; background: rgba(255,255,255,.13); }
.loading-line span { display: block; width: 45%; height: 100%; background: var(--warm); animation: load 1.2s ease-in-out infinite; }
.loading p { margin: 13px 0 0; color: var(--muted); font-size: .78rem; letter-spacing: .08em; }
@keyframes load { from { transform: translateX(-110%); } to { transform: translateX(330%); } }

.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; }

@media (max-width: 760px) {
  .topbar { height: 60px; grid-template-columns: 1fr auto; padding: 0 16px; }
  .catalog-title { display: none; }
  .reader-shell { height: calc(100dvh - 116px); padding: 12px 8px; }
  .reader { grid-template-columns: 42px minmax(0, 1fr) 42px; gap: 3px; }
  .page-arrow { width: 38px; height: 38px; border: 0; background: transparent; }
  .book { width: 100% !important; height: 100%; }
  .controls { height: 56px; gap: 10px; padding-inline: 12px; }
  .control-button { min-width: 42px; width: 42px; padding: 0; border: 0; background: transparent; }
  .control-button span { display: none; }
  .page-status { min-width: 106px; }
  .zoom-toolbar { grid-template-columns: 40px minmax(76px, 1fr) auto 40px; gap: 5px; padding-inline: 8px; }
  .zoom-tool { width: 36px; height: 36px; }
  .zoom-tool svg { width: 19px; height: 19px; }
  .zoom-level { display: none; }
  .zoom-close { margin-left: 0; }
  .zoom-stage { padding: 12px; }
}

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