:root {
  color-scheme: light;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  --purple: #47449D;
  --lavender: #A6A6E2;
  --lavender-soft: #EFEEF9;
  --ink: #29283A;
  --muted: #747286;
  --border: #E6E5EF;
  --background: #F8F8FC;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--background);
  color: var(--ink);
}
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .42; }
button:focus-visible, a:focus-visible, input:focus-visible {
  outline: 3px solid var(--lavender);
  outline-offset: 2px;
}
[hidden] { display: none !important; }

.site-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 56px;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 20px 8px;
  background: var(--purple);
  color: #fff;
}
.brand {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: inherit;
  text-decoration: none;
  font-weight: 500;
  letter-spacing: .01em;
  font-size: 14px;
  line-height: 1.2;
  white-space: nowrap;
}
.brand strong { font-weight: 800; }
.brand-mark {
  flex: 0 0 32px;
  height: 32px;
  display: grid;
  place-items: center;
  background: #fff;
  color: var(--purple);
  border-radius: 9px;
  font-size: 20px;
  font-weight: 800;
}
.pdf-link {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 35px;
  padding: 8px 10px;
  border-radius: 10px;
  background: #fff;
  color: var(--purple);
  font-size: 12px;
  font-weight: 750;
  text-decoration: none;
  white-space: nowrap;
}
.pdf-link:hover { background: var(--lavender-soft); }

.reader {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  width: 100%;
  max-width: 1500px;
  margin: 0 auto;
  padding: 4px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
}
.reader-stage {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  overflow: hidden;
  isolation: isolate;
}
.book-host {
  position: relative;
  min-width: 1px;
  max-width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 5px 18px rgba(41, 40, 58, .14);
}
#book { margin: 0 auto; }
.page {
  background: #fff;
  overflow: hidden;
  position: relative;
  box-shadow: inset -1px 0 0 var(--border);
}
.page-canvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
}
.page-placeholder {
  display: grid;
  position: absolute;
  inset: 0;
  place-items: center;
  background: #fff;
  color: #a3a3b3;
  font-size: 12px;
}
.loading {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  background: #f8f8fcf5;
  color: var(--muted);
  text-align: center;
  font-size: 14px;
}
.loader {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 3px solid var(--lavender-soft);
  border-top-color: var(--purple);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.reader-error {
  position: absolute;
  z-index: 11;
  inset: 14px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 22px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--ink);
  border-radius: 16px;
  max-width: 620px;
  margin: auto;
  min-height: 140px;
}

.pagination {
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  width: max-content;
  max-width: 100%;
  min-height: 52px;
  margin: 0 auto;
}
.nav-button {
  flex: 0 0 100px;
  width: 100px;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  color: var(--purple);
  font-weight: 750;
  font-size: 14px;
}
.nav-button:hover:not(:disabled) { background: var(--lavender-soft); }
.page-control { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.page-control input {
  width: 56px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 10px;
  text-align: center;
  font-size: 16px;
  background: #fff;
  color: var(--ink);
  appearance: textfield;
}
.page-control input::-webkit-inner-spin-button,
.page-control input::-webkit-outer-spin-button { appearance: none; margin: 0; }
.page-total { white-space: nowrap; }
.no-js { color: var(--muted); text-align: center; }

@media (max-width: 680px) {
  .site-header { padding-left: 12px; padding-right: 12px; }
  .brand { gap: 7px; font-size: 11px; }
  .brand-mark { flex-basis: 29px; height: 29px; font-size: 18px; }
  .pdf-link { padding: 7px 8px; font-size: 11px; min-height: 34px; }
  .reader { padding: 2px 6px calc(14px + env(safe-area-inset-bottom, 0px)); }
  .pagination { width: max-content; justify-content: center; gap: 10px; }
  .nav-button { flex: 0 0 90px; width: 90px; padding: 8px; font-size: 13px; }
  .page-control { gap: 5px; font-size: 12px; }
  .page-control input { width: 45px; }
}
@media (max-width: 350px) {
  .brand-mark { display: none; }
  .brand { font-size: 10.5px; }
  .nav-button span { display: none; }
  .nav-button { flex: 0 0 68px; width: 68px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; }
}
