:root {
  color-scheme: dark;
  --bg: #09243c;
  --panel: #102f4d;
  --panel-2: #1b466a;
  --text: #fcfaf5;
  --muted: #dbe4ea;
  --line: rgba(255, 255, 255, .12);
  --accent: #e5c579;
  --shadow: 0 24px 70px rgba(0,0,0,.45);
}

@font-face { font-family: "Cormorant Garamond"; font-style: normal; font-weight: 600; font-display: swap; src: url("../fonts/cormorant-garamond-600.woff2") format("woff2"); }
@font-face { font-family: "Manrope"; font-style: normal; font-weight: 400; font-display: swap; src: url("../fonts/manrope-400.woff2") format("woff2"); }
@font-face { font-family: "Manrope"; font-style: normal; font-weight: 700; font-display: swap; src: url("../fonts/manrope-700.woff2") format("woff2"); }

* { box-sizing: border-box; }
html, body { min-height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(circle at 50% 0%, rgba(229,197,121,.12), transparent 38rem),
    var(--bg);
  color: var(--text);
  font-family: "Manrope", Arial, sans-serif;
  overflow-x: hidden;
}

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

.viewer-shell {
  width: min(100%, 1560px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: 14px clamp(10px, 2vw, 30px) 14px;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  gap: 9px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 7px 4px;
}

.identity { min-width: 0; display: flex; align-items: center; gap: 12px; }
.identity-mark { width: 42px; height: 42px; flex: 0 0 auto; object-fit: contain; filter: drop-shadow(0 2px 8px rgba(0,0,0,.25)); }

.title-block { min-width: 0; }
.eyebrow {
  color: var(--accent);
  font-size: clamp(.66rem, 1vw, .78rem);
  line-height: 1.2;
  letter-spacing: .08em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

h1 {
  margin: 3px 0 0;
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: clamp(1rem, 1.8vw, 1.35rem);
  font-weight: 600;
  letter-spacing: .01em;
}

h1 span { white-space: nowrap; }

.actions { display: flex; gap: 7px; flex: 0 0 auto; }

.icon-btn,
.nav-btn,
.zoom-btn {
  border: 1px solid var(--line);
  background: rgba(255,255,255,.045);
  color: var(--text);
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, transform .15s ease;
}

.icon-btn:hover,
.nav-btn:hover,
.zoom-btn:hover {
  background: rgba(255,255,255,.10);
  border-color: rgba(255,255,255,.22);
}

.icon-btn:active,
.nav-btn:active,
.zoom-btn:active { transform: translateY(1px); }

.icon-btn:disabled,
.nav-btn:disabled,
.zoom-btn:disabled {
  opacity: .36;
  cursor: default;
}

.icon-btn {
  min-width: 40px;
  height: 34px;
  padding: 0 10px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  font-weight: 700;
}

.text-btn { min-width: 112px; font-size: .76rem; letter-spacing: .03em; }

.stage {
  min-height: 0;
  position: relative;
  display: grid;
  place-items: center;
  padding: clamp(5px, 1vw, 12px);
  border: 1px solid var(--line);
  border-radius: 14px;
  background:
    linear-gradient(90deg, transparent 49.85%, rgba(255,255,255,.022) 50%, transparent 50.15%),
    linear-gradient(180deg, var(--panel-2), var(--panel));
  box-shadow: inset 0 1px 0 rgba(255,255,255,.025);
  overflow: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(198,161,91,.45) rgba(255,255,255,.04);
}

.stage.is-zoomed {
  overflow: auto;
  place-items: start center;
}

.book-wrap {
  --book-zoom: 1;
  grid-area: 1 / 1;
  width: 100%;
  height: clamp(520px, calc(100dvh - 167px), 960px);
  min-height: 440px;
  display: grid;
  place-items: center;
  transform: scale(var(--book-zoom));
  transform-origin: 50% 50%;
  transition: transform .16s ease;
}

.stage.is-zoomed .book-wrap {
  transform-origin: 50% 0;
  margin-top: 8px;
  margin-bottom: calc((var(--book-zoom) - 1) * 48vh);
}

.book-wrap.is-preparing {
  visibility: hidden;
  pointer-events: none;
}

.book {
  width: 100%;
  height: 100%;
  filter: drop-shadow(var(--shadow));
}

.page {
  background: #f2eee4;
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

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

.loading {
  grid-area: 1 / 1;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px 19px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(17,14,12,.92);
  box-shadow: 0 16px 50px rgba(0,0,0,.30);
}

.loading strong {
  display: block;
  color: var(--text);
  margin-bottom: 3px;
}

.loading span { font-size: .84rem; }

.loading.is-hidden,
.loading[hidden] {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

.spinner {
  width: 27px;
  height: 27px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,.15);
  border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}

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

.controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  min-height: 34px;
}

.nav-btn,
.zoom-btn {
  height: 34px;
  border-radius: 9px;
  line-height: 1;
}

.nav-btn {
  width: 38px;
  font-size: 1.55rem;
}

.page-status {
  min-width: 154px;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  color: var(--muted);
  background: rgba(255,255,255,.035);
  font-size: .80rem;
}

.page-status strong { color: var(--text); }

#pageInput {
  width: 42px;
  padding: 3px 4px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(0,0,0,.22);
  color: var(--text);
  text-align: center;
  outline: none;
  appearance: textfield;
  font-size: .8rem;
}

#pageInput::-webkit-outer-spin-button,
#pageInput::-webkit-inner-spin-button { appearance: none; margin: 0; }
#pageInput:focus { border-color: rgba(198,161,91,.65); }

.zoom-controls {
  height: 34px;
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 9px;
  overflow: hidden;
  background: rgba(255,255,255,.035);
}

.zoom-btn {
  width: 34px;
  border: 0;
  border-radius: 0;
  background: transparent;
  font-size: 1rem;
  font-weight: 700;
}

.zoom-btn + .zoom-btn { border-left: 1px solid var(--line); }

.zoom-value {
  min-width: 54px;
  height: 100%;
  padding: 0 7px;
  border: 0;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: .76rem;
  font-weight: 600;
}

.zoom-value:hover { color: var(--text); background: rgba(255,255,255,.06); }

.hint {
  margin: -1px 0 0;
  text-align: center;
  color: var(--muted);
  font-size: .71rem;
}

:fullscreen .viewer-shell,
.viewer-shell:fullscreen {
  max-width: none;
  width: 100%;
  padding: 8px 12px 10px;
  background: var(--bg);
}

:fullscreen .book-wrap,
.viewer-shell:fullscreen .book-wrap {
  height: calc(100dvh - 125px);
}

@media (max-width: 720px) {
  .viewer-shell {
    padding: 8px 6px 10px;
    gap: 7px;
  }

  .topbar { padding: 4px 2px; }
  .eyebrow { max-width: 54vw; }
  .identity-mark { width: 34px; height: 34px; }
  h1 { font-size: .96rem; }

  .stage {
    border-radius: 11px;
    padding: 3px;
  }

  .book-wrap {
    height: calc(100dvh - 145px);
    min-height: 400px;
  }

  .hint { display: none; }
  .page-status { min-width: 145px; }
  .controls { gap: 6px; }
}

@media (max-width: 520px) {
  .text-btn { display: none; }
  .controls { flex-wrap: wrap; }
  .zoom-controls { order: 2; }
}

@media (max-width: 420px) {
  .eyebrow { display: none; }
  .page-status { min-width: 140px; padding-inline: 8px; }
  .nav-btn { width: 36px; }
}
