:root {
  --bg: #111214;
  --bg-elevated: #1a1b1f;
  --ink: #f4f2ec;
  --muted: #b7b4ab;
  --line: rgba(255, 255, 255, 0.12);
  --accent: #3b82c4;
  --accent-ink: #f7fbff;
  --danger-focus: #e8c36a;
  --shadow: rgba(0, 0, 0, 0.55);
  --control: #2a2c31;
  --control-hover: #35373d;
  --page-w: 1760;
  --page-h: 1360;
  --ui-pad: 16px;
  --bar-h: 64px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

body {
  min-height: 100dvh;
  overflow: hidden;
}

.app {
  height: 100dvh;
  width: 100%;
  max-width: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  overflow: hidden;
  background:
    radial-gradient(ellipse 80% 60% at 50% 40%, #1c1e24 0%, var(--bg) 70%);
}

.topbar,
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px var(--ui-pad);
  z-index: 5;
}

.topbar {
  justify-content: space-between;
  min-height: 56px;
  border-bottom: 1px solid var(--line);
  background: rgba(17, 18, 20, 0.88);
  backdrop-filter: blur(10px);
}

.brand {
  min-width: 0;
}

.brand h1 {
  margin: 0;
  font-size: clamp(1rem, 2vw, 1.25rem);
  font-weight: 650;
  letter-spacing: 0.01em;
  line-height: 1.2;
}

.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  letter-spacing: 0.02em;
}

.top-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  padding: 12px 72px;
}

.book-shell {
  position: relative;
  filter: drop-shadow(0 18px 40px var(--shadow)) drop-shadow(0 2px 6px rgba(0, 0, 0, 0.45));
}

#book {
  margin: 0 auto;
}

#book .sheet {
  background: #fff;
  overflow: hidden;
}

#book .sheet img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

.nav-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 72px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(26, 27, 31, 0.86);
  color: var(--ink);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 4;
}

.nav-arrow:hover:not(:disabled),
.nav-arrow:focus-visible {
  background: var(--control-hover);
  outline: 2px solid var(--danger-focus);
  outline-offset: 2px;
}

.nav-arrow:disabled {
  opacity: 0.28;
  cursor: default;
}

.nav-arrow svg {
  width: 28px;
  height: 28px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-arrow.prev { left: 12px; }
.nav-arrow.next { right: 12px; }

.toolbar {
  justify-content: center;
  flex-wrap: wrap;
  min-height: var(--bar-h);
  border-top: 1px solid var(--line);
  background: rgba(17, 18, 20, 0.94);
  gap: 8px 10px;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--control);
  color: var(--ink);
  border-radius: 8px;
  min-height: 40px;
  min-width: 40px;
  padding: 0 12px;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn:hover:not(:disabled),
.btn:focus-visible {
  background: var(--control-hover);
  outline: 2px solid var(--danger-focus);
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn[aria-pressed="true"] {
  background: #3a4553;
  border-color: var(--accent);
}

.pager {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 6px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.92rem;
}

.pager label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.pager input {
  width: 4.2rem;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0d0e11;
  color: var(--ink);
  font: inherit;
  font-variant-numeric: tabular-nums;
  text-align: center;
  padding: 0 6px;
}

.pager input:focus-visible {
  outline: 2px solid var(--danger-focus);
  outline-offset: 2px;
}

.thumb-drawer {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  bottom: var(--bar-h);
  z-index: 6;
  background: rgba(14, 15, 17, 0.97);
  border-top: 1px solid var(--line);
  padding: 10px 12px 12px;
  max-height: 28vh;
}

.thumb-drawer.open {
  display: block;
}

.thumb-scroller {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-color: #555 transparent;
}

.thumb {
  flex: 0 0 auto;
  width: 112px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 6px;
  background: #000;
  cursor: pointer;
  color: var(--ink);
}

.thumb img {
  display: block;
  width: 112px;
  height: auto;
  aspect-ratio: 1760 / 1360;
  object-fit: cover;
  border-radius: 4px;
}

.thumb span {
  display: block;
  font-size: 0.68rem;
  color: var(--muted);
  text-align: center;
  padding: 3px 2px 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thumb:hover,
.thumb:focus-visible {
  outline: 2px solid var(--danger-focus);
  outline-offset: 1px;
}

.thumb.current {
  border-color: var(--accent);
}

.zoom-layer {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(0, 0, 0, 0.92);
  overflow: auto;
}

.zoom-layer.open {
  display: block;
}

.zoom-layer img {
  display: block;
  margin: 24px auto;
  max-width: none;
  width: min(1760px, 96vw);
  height: auto;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
}

.zoom-close {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 21;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

@media (max-width: 800px) {
  .stage {
    padding: 8px 52px;
  }
  .nav-arrow {
    width: 40px;
    height: 56px;
  }
  .nav-arrow.prev { left: 6px; }
  .nav-arrow.next { right: 6px; }
  .brand p {
    display: none;
  }
  .pager .of-label {
    display: none;
  }
}

@media (max-width: 520px) {
  .stage {
    padding: 6px 8px 6px 8px;
  }
  .nav-arrow {
    display: none;
  }
  .topbar {
    padding: 8px 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
  }
}

.book-shell #book,
.book-shell .stf__parent {
  width: 100%;
  height: 100%;
  min-width: 0 !important;
}

.book-shell {
  overflow: hidden;
}

.book-shell .stf__wrapper {
  padding-bottom: 0 !important;
  width: 100%;
  height: 100%;
}

.book-shell .stf__block {
  width: 100%;
  height: 100%;
}

@media (max-width: 720px) {
  .btn .btn-text {
    display: none;
  }
  .topbar {
    gap: 8px;
  }
  .brand h1 {
    font-size: 1rem;
  }
}
