:root {
  --ink: #173f4a;
  --ink-soft: #466770;
  --paper: #eef3f4;
  --cover: #b9ccd1;
  --line: rgba(23, 63, 74, .18);
  --shadow: 0 20px 55px rgba(7, 30, 36, .22);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% 0, rgba(255,255,255,.95), transparent 44%),
    linear-gradient(145deg, #dfe9eb, #afc5ca);
  font-family: Inter, Helvetica, Arial, sans-serif;
  overflow-x: hidden;
}

button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.reader {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 14px;
  padding: clamp(14px, 2vw, 28px);
}

.reader__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  max-width: 1500px;
  width: 100%;
  margin: 0 auto;
}

.reader__identity h1 {
  margin: 2px 0 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.15rem, 2.2vw, 1.8rem);
  font-weight: 500;
  letter-spacing: -.02em;
}

.reader__identity p,
.reader__eyebrow { margin: 0; color: var(--ink-soft); }
.reader__identity p { margin-top: 3px; font-size: .88rem; }
.reader__eyebrow { font-size: .66rem; font-weight: 800; letter-spacing: .17em; text-transform: uppercase; }
.reader__actions { display: flex; gap: 8px; }

.icon-button,
.toolbar__button,
.toolbar__zoom,
.nav-button {
  border: 1px solid var(--line);
  color: var(--ink);
  background: rgba(255, 255, 255, .62);
  cursor: pointer;
  transition: transform .18s ease, background .18s ease, opacity .18s ease;
}

.icon-button:hover,
.toolbar__button:hover,
.toolbar__zoom:hover,
.nav-button:hover { background: #fff; transform: translateY(-1px); }

.icon-button:focus-visible,
.toolbar__button:focus-visible,
.toolbar__zoom:focus-visible,
.nav-button:focus-visible,
input:focus-visible { outline: 3px solid rgba(23, 63, 74, .28); outline-offset: 2px; }

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

.icon-button svg,
.nav-button svg,
.toolbar__zoom svg {
  width: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.stage {
  min-height: 0;
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) 52px;
  align-items: center;
  gap: clamp(8px, 2vw, 22px);
  max-width: 1500px;
  width: 100%;
  margin: 0 auto;
}

.book-shell {
  position: relative;
  min-height: 300px;
  height: min(72vh, 930px);
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 16px;
}

.book { width: 100%; height: 100%; }

.page {
  position: relative;
  background: white;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.04);
}

.page canvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
}

.page::after {
  content: attr(data-label);
  position: absolute;
  right: 10px;
  bottom: 8px;
  padding: 3px 7px;
  border-radius: 999px;
  color: rgba(23,63,74,.66);
  background: rgba(255,255,255,.72);
  font-size: 10px;
  opacity: 0;
  transition: opacity .2s;
}
.page:hover::after { opacity: 1; }

.loading {
  position: absolute;
  z-index: 20;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 8px;
  background: rgba(225, 235, 237, .94);
  text-align: center;
  transition: opacity .35s ease, visibility .35s ease;
}
.loading.is-hidden { opacity: 0; visibility: hidden; }
.loading__mark {
  width: 38px;
  height: 38px;
  border: 3px solid rgba(23,63,74,.18);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
.loading small { color: var(--ink-soft); }
@keyframes spin { to { transform: rotate(360deg); } }

.nav-button {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  box-shadow: 0 8px 25px rgba(23,63,74,.12);
}
.nav-button:disabled,
.toolbar__button:disabled { opacity: .3; pointer-events: none; }

.toolbar {
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  max-width: max-content;
  margin: 0 auto;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(243, 247, 248, .78);
  box-shadow: 0 10px 32px rgba(23,63,74,.12);
  backdrop-filter: blur(14px);
}

.toolbar__button {
  width: 39px;
  height: 39px;
  border-radius: 10px;
  font-size: 1.25rem;
}

.page-control { display: flex; align-items: center; gap: 7px; padding: 0 5px; font-size: .83rem; }
.page-control input {
  width: 58px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  text-align: center;
}
.page-control input::-webkit-inner-spin-button { appearance: none; }
.toolbar__divider { width: 1px; height: 27px; margin: 0 3px; background: var(--line); }
.toolbar__zoom {
  height: 39px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  border-radius: 10px;
  font-size: .83rem;
}
.toolbar__zoom svg { width: 18px; }

.zoom {
  width: min(96vw, 1100px);
  height: min(96vh, 1100px);
  padding: 0;
  border: 0;
  border-radius: 14px;
  background: #dfe9eb;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.zoom::backdrop { background: rgba(8, 27, 32, .8); backdrop-filter: blur(4px); }
.zoom__bar {
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px 0 16px;
  color: white;
  background: var(--ink);
}
.zoom__bar button {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  color: white;
  background: transparent;
  font-size: 1.7rem;
  cursor: pointer;
}
.zoom__viewport { height: calc(100% - 48px); overflow: auto; padding: 18px; text-align: center; }
.zoom canvas { max-width: none; height: auto; background: white; box-shadow: var(--shadow); }

noscript { display: block; padding: 20px; text-align: center; }

@media (max-width: 700px) {
  .reader { gap: 8px; padding: 10px; }
  .reader__identity h1 { max-width: 250px; }
  .stage { grid-template-columns: 1fr; }
  .book-shell { height: 68vh; min-height: 360px; }
  .nav-button { position: fixed; z-index: 30; top: 50%; width: 44px; height: 44px; background: rgba(255,255,255,.88); }
  .nav-button--prev { left: 8px; }
  .nav-button--next { right: 8px; }
  .toolbar { width: 100%; max-width: 520px; }
  .toolbar__button:first-child,
  .toolbar__button:nth-of-type(4),
  .toolbar__divider,
  .toolbar__zoom span { display: none; }
  .toolbar__zoom { width: 39px; padding: 0; justify-content: center; }
  .page-control { flex: 1; justify-content: center; }
}

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