:root {
  color-scheme: dark;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #edf0f3;
  background: #24272c;
  font-synthesis: none;
  --muted: #b1b7bf;
  --panel: #202328;
  --line: #3b4048;
  --focus: #aecdf0;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { min-width: 0; }
button, input, a { -webkit-tap-highlight-color: transparent; }
button, input { font: inherit; }
button, a { touch-action: manipulation; }
button { color: inherit; cursor: pointer; }
button:disabled { opacity: .35; cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible,
.stage:focus-visible, .zoom-viewport:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
}

.reader {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  width: 100%;
  height: 100%;
  height: 100dvh;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 40%, #34383f 0%, #25282d 70%);
}
.reader-header {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  min-height: 45px;
  padding: 9px max(14px, env(safe-area-inset-right)) 9px max(14px, env(safe-area-inset-left));
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.reader-header h1 {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 14px;
  font-weight: 550;
  line-height: 1.4;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.pdf-download {
  flex: none;
  padding: 6px 0;
  color: #c6cdd6;
  font-size: 12px;
  line-height: 1.25;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.pdf-download:hover { color: #fff; }
.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 12px 18px;
  overflow: hidden;
}
.book {
  position: relative;
  width: 100%;
  height: 100%;
  min-width: 0 !important;
  min-height: 0 !important;
  max-width: none !important;
  overflow: hidden;
  isolation: isolate;
}
/* autoSize:false keeps the iframe's available height authoritative. The
   upstream bundle contains a .sft__wrapper typo; use the actual class. */
.book .stf__wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  padding: 0 !important;
}
.book .stf__block { inset: 0; width: 100%; height: 100%; }
.book.stf__parent { touch-action: pan-y; }
.reader-page {
  position: absolute;
  overflow: hidden;
  background: #fff;
  color: #49525e;
  user-select: none;
  -webkit-user-select: none;
}
.page-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  pointer-events: none;
}
.reader-page[data-state="loaded"] .page-image { opacity: 1; }
.page-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  text-align: center;
  font-size: 12px;
  line-height: 1.5;
}
.reader-page[data-state="loaded"] .page-placeholder { display: none; }
.reader-page[data-state="error"] .page-placeholder { color: #843c32; }
.stage-message {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 28px;
  text-align: center;
  background: #272b30;
}
.stage-message p { max-width: 44ch; margin: 0; font-size: 14px; line-height: 1.6; }
.loading-mark {
  width: 24px;
  height: 24px;
  border: 2px solid #555d68;
  border-top-color: #d8e2ef;
  border-radius: 50%;
  animation: loading-turn 1s linear infinite;
}
.stage-message.is-error .loading-mark { display: none; }
@keyframes loading-turn { to { transform: rotate(360deg); } }
.reader-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
  min-height: 27px;
  padding: 3px 12px 5px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}
.reader-status p { min-width: 0; margin: 0; text-align: center; overflow-wrap: anywhere; }
.text-button { flex: none; border: 0; padding: 4px; background: transparent; color: #dce7f5; font-size: 11px; text-decoration: underline; text-underline-offset: 2px; }
.reader-footer { min-width: 0; padding-bottom: env(safe-area-inset-bottom); background: var(--panel); border-top: 1px solid var(--line); }
.reader-toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  min-width: 0;
  padding: 5px 12px;
}
.navigation, .page-form, .view-tools, .zoom-controls {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 4px;
}
.icon-button, .small-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
}
.icon-button { width: 38px; padding: 8px; }
.icon-button svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.icon-button:hover:not(:disabled), .small-button:hover:not(:disabled) { background: #373d46; }
.small-button { padding: 5px 9px; font-size: 12px; }
.page-position { min-width: 94px; padding: 0 5px; text-align: center; color: #d4d9e0; font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.page-form { gap: 7px; }
.page-form label { color: var(--muted); font-size: 12px; }
.page-form input {
  width: 48px;
  min-width: 0;
  height: 32px;
  padding: 3px 5px;
  border: 1px solid #4c5560;
  border-radius: 5px;
  background: #292e35;
  color: #f4f6f8;
  text-align: center;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}
.page-form input[aria-invalid="true"] { border-color: #e2a395; }
.reading-progress { display: block; width: 100%; height: 3px; border: 0; appearance: none; background: #343940; color: #91a4ba; }
.reading-progress::-webkit-progress-bar { background: #343940; }
.reading-progress::-webkit-progress-value { background: #91a4ba; }
.reading-progress::-moz-progress-bar { background: #91a4ba; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.noscript-message { position: fixed; inset: 55px 20px auto; z-index: 30; padding: 20px; margin: 0; background: #202328; line-height: 1.6; }

.zoom-dialog {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: #22262c;
  color: #edf0f3;
  overflow: hidden;
}
.zoom-dialog[open] { display: grid; grid-template-rows: auto auto minmax(0, 1fr); }
.zoom-dialog::backdrop { background: #17191d; }
.zoom-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-width: 0; padding: 6px 12px; border-bottom: 1px solid var(--line); background: var(--panel); }
.zoom-header h2 { min-width: 0; margin: 0; font-size: 13px; font-weight: 550; line-height: 1.4; }
.zoom-controls { flex: none; gap: 2px; }
.zoom-status { margin: 0; min-height: 26px; padding: 5px 12px; color: #bdc5cf; font-size: 11px; text-align: center; }
.zoom-viewport { min-width: 0; min-height: 0; overflow: auto; overscroll-behavior: contain; touch-action: pan-x pan-y pinch-zoom; -webkit-overflow-scrolling: touch; }
.zoom-sheet { display: flex; align-items: center; justify-content: center; min-width: 100%; min-height: 100%; padding: 12px; }
.zoom-image { display: block; flex: none; max-width: none; max-height: none; object-fit: contain; background: #fff; box-shadow: 0 6px 28px #0005; }

@media (max-width: 680px) {
  .reader-header { gap: 10px; min-height: 44px; padding: 8px 12px; }
  .reader-header h1 { font-size: 13px; }
  .pdf-download { max-width: 108px; font-size: 10px; }
  .stage { padding: 8px 10px; }
  .reader-toolbar { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 4px 10px; }
  .navigation { grid-column: 1 / -1; justify-content: center; }
  .page-form { justify-self: center; }
  .view-tools { justify-self: end; }
  .page-position { min-width: 96px; }
  .icon-button { width: 38px; min-height: 38px; }
  .zoom-header { flex-wrap: wrap; justify-content: center; gap: 3px; padding: 6px 8px; }
  .zoom-header h2 { width: 100%; text-align: center; }
  .zoom-controls { gap: 1px; }
  .zoom-controls .icon-button { width: 36px; min-height: 36px; }
}
@media (max-height: 400px) and (min-width: 600px) {
  .reader-header { min-height: 35px; padding-top: 4px; padding-bottom: 4px; }
  .stage { padding-top: 5px; padding-bottom: 5px; }
  .reader-toolbar { display: flex; gap: 10px; padding-top: 2px; padding-bottom: 2px; }
  .reader-status { min-height: 23px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
  .loading-mark { border-top-color: #d8e2ef; }
}
