/* Immersive, mobile-first reading layer.  It intentionally keeps controls
   compact while letting the text, rather than the shell, own the viewport. */
.reader-app {
  --reader-font-size: 18px;
  --reader-line-height: 1.95;
  --reader-measure: 40rem;
}

.reader-stage {
  overscroll-behavior: contain;
  scroll-behavior: smooth;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
}

.reader-app[data-mode="text"][data-reading-mode="scroll"] .reader-stage {
  overflow-x: hidden;
  overflow-y: auto;
  scroll-padding-block: clamp(28px, 7vh, 72px);
}

.reader-app[data-mode="text"] .text-stage {
  box-sizing: border-box;
  width: min(calc(100% - clamp(20px, 6vw, 80px)), var(--reader-measure));
  max-width: none;
  min-height: 100%;
  margin: 0 auto;
  padding: clamp(30px, 7vw, 88px) clamp(20px, 6vw, 68px) calc(clamp(52px, 10vh, 112px) + env(safe-area-inset-bottom));
  border-inline: 1px solid rgba(103, 72, 39, .08);
  font-size: var(--reader-font-size);
  line-height: var(--reader-line-height);
  letter-spacing: .015em;
  text-wrap: pretty;
  text-rendering: optimizeLegibility;
  box-shadow: 0 0 80px rgba(4, 4, 8, .1);
}

.reader-app[data-theme="night"] .text-stage {
  background: radial-gradient(circle at 50% -20%, rgba(78, 75, 111, .35), transparent 42%), #121319;
  color: #e9dfcf;
  border-color: rgba(238, 214, 175, .08);
}

.reader-app[data-theme="ink"] .text-stage { box-shadow: none; }
.reader-app[data-mode="text"] .text-stage > :first-child { margin-top: 0; }
.reader-app[data-mode="text"] .text-stage > :last-child { margin-bottom: 0; }
.reader-app[data-mode="text"] .text-stage h1,
.reader-app[data-mode="text"] .text-stage h2,
.reader-app[data-mode="text"] .text-stage h3 {
  margin: 1.9em 0 .85em;
  letter-spacing: .04em;
}
.reader-app[data-mode="text"] .text-stage p { margin: 0 0 1em; }
.reader-app[data-mode="text"] .reader-font-control { display: inline-flex; }

.reader-app[data-mode="epub"] .epub-stage {
  overflow: hidden;
  overscroll-behavior: contain;
}

.reader-footer {
  min-height: 48px;
  padding-bottom: calc(7px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, #121116 92%, transparent);
  backdrop-filter: blur(16px);
}

.reader-nav {
  min-width: 72px;
  min-height: 36px;
  font-weight: 600;
}

.reader-position {
  min-height: 34px;
  padding-inline: 4px;
  border-radius: 999px;
}

.reader-settings-toggle { font: 700 12px/1 var(--mono); }
.reader-settings-toggle:disabled { opacity: .42; cursor: not-allowed; }

.reader-settings-panel {
  position: absolute;
  z-index: 19;
  right: 12px;
  bottom: 54px;
  left: 12px;
  max-height: min(66dvh, 500px);
  overflow: auto;
  padding: 16px;
  border: 1px solid rgba(224, 181, 101, .48);
  border-radius: 18px;
  background: radial-gradient(circle at 84% 0, rgba(89, 112, 163, .3), transparent 35%), linear-gradient(150deg, rgba(29, 28, 36, .98), rgba(12, 12, 17, .99));
  box-shadow: 0 20px 56px rgba(0, 0, 0, .62);
  backdrop-filter: blur(16px);
}
.reader-settings-panel[hidden] { display: none; }
.reader-settings-panel header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.reader-settings-panel header p { margin: 0 0 3px; color: #a8c7ed; font: 9px var(--mono); letter-spacing: .12em; }
.reader-settings-panel h2 { margin: 0; color: #f4e2bf; font: 600 19px var(--serif); }
.reader-settings-panel header button {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid rgba(230, 195, 128, .3);
  border-radius: 50%;
  background: transparent;
  color: #ebd4a9;
  font-size: 19px;
  cursor: pointer;
}
.reader-settings-note { margin: 12px 0 14px; color: #c2b8a9; font-size: 10px; line-height: 1.65; }
.reader-setting { display: grid; gap: 7px; margin-top: 13px; color: #eadbc0; font-size: 11px; }
.reader-setting span { display: flex; align-items: center; justify-content: space-between; }
.reader-setting output { color: #e5b96d; font: 10px var(--mono); }
.reader-setting input { width: 100%; accent-color: #dfaf5d; }
.reader-settings-reset {
  width: 100%;
  min-height: 35px;
  margin-top: 18px;
  border: 1px solid rgba(171, 199, 232, .44);
  border-radius: 9px;
  background: rgba(77, 104, 150, .16);
  color: #d7e4f3;
  font: 600 11px var(--sans);
  cursor: pointer;
}

.reader-tool:focus-visible,
.reader-nav:focus-visible,
.reader-position:focus-visible,
.reader-settings-panel button:focus-visible,
.reader-settings-panel input:focus-visible {
  outline: 2px solid #f0c675;
  outline-offset: 2px;
}

@media (max-width: 640px) {
  .reader-app[data-mode="text"] .text-stage {
    width: 100%;
    padding: 28px 20px calc(72px + env(safe-area-inset-bottom));
    border-inline: 0;
    box-shadow: none;
  }
  .reader-footer { gap: 6px; padding-inline: 8px; }
  .reader-nav { min-width: 68px; padding-inline: 7px; }
  .reader-position { min-width: 48px; font-size: 9px; }
  .reader-settings-panel { right: 7px; left: 7px; bottom: 54px; }
}

@media (prefers-reduced-motion: reduce) {
  .reader-stage { scroll-behavior: auto; }
}
