:root {
  --chrome-bg: rgba(22, 22, 24, .68);
  --chrome-text: #f5f5f7;
  --chrome-muted: #9a9aa0;
  --chrome-border: rgba(255, 255, 255, .09);
  --accent: #4cff8e;
  --accent-hover: #6fffa6;
  --stage-bg: radial-gradient(ellipse 90% 70% at 50% 38%, #232327 0%, #131315 55%, #060607 100%);
  --page-bg: #ffffff;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    "Noto Sans Thai", "Helvetica Neue", Arial, sans-serif;
  letter-spacing: -0.011em;
  color: var(--chrome-text);
  background: #000;
}

.reader {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Top bar */
.reader-bar {
  flex: none;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  background: var(--chrome-bg);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--chrome-border);
}

.icon-btn {
  width: 36px;
  height: 36px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--chrome-text);
  background: rgba(255, 255, 255, .08);
  text-decoration: none;
  border: none;
  cursor: pointer;
  transition: background .15s ease, transform .12s ease;
}

.icon-btn:hover { background: rgba(255, 255, 255, .16); }
.icon-btn:active { transform: scale(.92); }
.icon-btn svg { width: 18px; height: 18px; }

.reader-title-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  min-width: 0;
  flex: 1;
}

.reader-title {
  font-size: .93rem;
  font-weight: 600;
  max-width: 60vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-indicator {
  font-size: .74rem;
  color: var(--chrome-muted);
  font-variant-numeric: tabular-nums;
  margin-top: 1px;
}

/* Stage — a single page, sized as large as possible without being
   cropped, with zero wasted padding so it reads as truly full-screen */
.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--stage-bg);
  padding: 20px 76px;
}

.page-viewport {
  position: relative;
  flex: 1;
  min-width: 0;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  /* we handle pinch/pan/double-tap ourselves — stop the browser's own
     touch scrolling and zooming from fighting our gesture handling */
  touch-action: none;
  cursor: zoom-in;
}

.page-viewport.is-zoomed { cursor: grab; }
.page-viewport.is-panning { cursor: grabbing; }

#page-canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  background: var(--page-bg);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .35), 0 24px 60px rgba(0, 0, 0, .55);
  transition: opacity .2s ease;
  transform-origin: center center;
  will-change: transform;
}

.page-viewport.is-gesturing #page-canvas { transition: none; }

.zoom-indicator {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%) translateY(6px);
  padding: 5px 12px;
  border-radius: 980px;
  background: var(--chrome-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  font-size: .76rem;
  font-variant-numeric: tabular-nums;
  color: var(--chrome-text);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 15;
}

/* Scoped to #page-viewport (not the whole .stage) on purpose — it must
   never cover the prev/next arrows, which sit outside the viewport in the
   stage's side padding, so the reader stays fully navigable while this
   is showing */
.preview-limit {
  position: absolute;
  inset: 0;
  z-index: 18;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
  padding: 32px;
  background: rgba(6, 6, 7, .88);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.preview-limit[hidden] { display: none; }

#preview-limit-text {
  margin: 0;
  max-width: 34ch;
  color: var(--chrome-text);
  font-size: .95rem;
  line-height: 1.6;
}

.zoom-indicator.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Nav arrows */
.nav-arrow {
  flex: none;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, .08);
  color: var(--chrome-text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .15s ease, transform .12s ease, opacity .15s ease;
  z-index: 10;
}

.nav-arrow svg { width: 22px; height: 22px; }
.nav-arrow:hover { background: rgba(255, 255, 255, .18); }
.nav-arrow:active { transform: scale(.9); }
.nav-arrow:disabled { opacity: .25; cursor: default; }
.nav-arrow:disabled:hover { background: rgba(255, 255, 255, .08); }

/* Footer / slider */
.reader-footer {
  flex: none;
  padding: 10px 24px 18px;
  background: var(--chrome-bg);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--chrome-border);
  display: flex;
  justify-content: center;
}

.page-slider {
  width: min(420px, 70vw);
  appearance: none;
  -webkit-appearance: none;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .18);
  outline: none;
}

.page-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .5);
  cursor: pointer;
  transition: transform .12s ease;
}

.page-slider::-webkit-slider-thumb:hover { transform: scale(1.15); }

.page-slider::-moz-range-thumb {
  width: 15px;
  height: 15px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

/* Status overlay */
.reader-status {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  padding: 24px;
  color: var(--chrome-muted);
  background: var(--stage-bg);
}

#reader-status[hidden] {
  display: none;
}

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

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

.btn {
  padding: 9px 18px;
  border-radius: 980px;
  font-size: .87rem;
  font-weight: 600;
  text-decoration: none;
  border: 1px solid transparent;
  cursor: pointer;
}

.btn-primary {
  background: var(--accent);
  /* dark text — white had poor contrast against this bright mint green */
  color: #063823;
  font-weight: 700;
}

.btn-primary:hover { background: var(--accent-hover); }

/* Below this width the page fills the screen edge-to-edge: no stage
   padding, no side arrows eating into page space (tap zones + swipe +
   the bottom slider cover navigation instead) */
@media (max-width: 720px) {
  .stage { padding: 0; }
  .nav-arrow { display: none; }
  .reader-title { max-width: 42vw; }
  #page-canvas { box-shadow: none; }
}

@media (prefers-reduced-motion: reduce) {
  .icon-btn, .nav-arrow, .page-slider::-webkit-slider-thumb, #page-canvas { transition: none; }
  .spinner { animation-duration: 1.6s; }
}
