/* ============================================================
   Inkshelf — chapter reader (#/read/...)
   Black, edge-to-edge pages; floating dark frosted-glass overlays.
   Everything is scoped under body.reading / .reader-* classes.
   ============================================================ */
html:has(body.reading) { background: #000; }
body.reading {
  background: #000;
  color: #f0ece6;
  --reader-glass: rgba(16, 16, 20, .58);
  --reader-glass-strong: rgba(18, 18, 22, .74);
  --reader-edge: rgba(255, 255, 255, .10);
  --reader-highlight: rgba(255, 255, 255, .14);
  --reader-text-2: rgba(255, 255, 255, .62);
  --reader-safe-t: env(safe-area-inset-top, 0px);
  --reader-safe-r: env(safe-area-inset-right, 0px);
  --reader-safe-l: env(safe-area-inset-left, 0px);
  --reader-bar-h: 58px;
}
.reader-view { min-height: 100vh; background: #000; }

/* ---------- dark liquid glass ---------- */
.reader-glass {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .07), rgba(255, 255, 255, 0) 55%),
    var(--reader-glass);
  -webkit-backdrop-filter: blur(24px) saturate(170%);
  backdrop-filter: blur(24px) saturate(170%);
  border: 1px solid var(--reader-edge);
  box-shadow: inset 0 1px 0 var(--reader-highlight), 0 10px 34px rgba(0, 0, 0, .45);
  color: #f2f2f5;
}

/* ---------- stage ---------- */
.reader-stage { position: relative; background: #000; }
.reader-stage .reader-img {
  display: block; user-select: none; -webkit-user-select: none; -webkit-user-drag: none;
  -webkit-touch-callout: none;
}
.reader-dim {
  position: fixed; inset: 0; z-index: 5; background: #000; opacity: 0;
  pointer-events: none; transition: opacity .15s;
}

/* vertical continuous: full-width, no gaps; capped by the width setting on large screens */
.reader-stage.width-narrow { --reader-w: 520px; }
.reader-stage.width-medium { --reader-w: 760px; }
.reader-stage.width-wide { --reader-w: 1040px; }
.reader-stage.width-full { --reader-w: none; }
.reader-strip { width: 100%; cursor: default; }
.reader-strip .reader-img { width: 100%; height: auto; max-width: var(--reader-w); margin: 0 auto; }
.reader-strip .reader-img:not(.is-loaded) { min-height: 70vh; background: #0b0b0e; }
.reader-strip .reader-img.is-missing { min-height: 40vh; background: repeating-linear-gradient(135deg, #0d0d10 0 12px, #121216 12px 24px); }

/* paged */
.reader-paged {
  min-height: 100vh; min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  touch-action: pan-y; user-select: none; -webkit-user-select: none;
  overflow: hidden;
}
/* pinch / double-tap zoom (handled in JS) */
.reader-paged .reader-img { transform-origin: 0 0; will-change: transform; }
.reader-paged.is-zoomed { touch-action: none; }

/* pull past the ends of a vertical chapter */
.reader-pull {
  --pull: 0;
  position: fixed; left: 50%; z-index: 25;
  padding: 9px 16px; border-radius: 999px;
  font-size: 13.5px; font-weight: 500; color: #f0ece6; white-space: nowrap;
  background: rgba(28, 28, 34, .72);
  -webkit-backdrop-filter: blur(18px) saturate(160%); backdrop-filter: blur(18px) saturate(160%);
  border: 1px solid rgba(255, 255, 255, .1);
  opacity: 0; pointer-events: none;
  transform: translate(-50%, 0) scale(.9);
  transition: opacity .15s, transform .15s, background .15s;
}
.reader-pull.is-bottom { bottom: calc(var(--safe-b) + 24px + var(--pull) * 40px); opacity: calc(.4 + var(--pull) * .6); transform: translate(-50%, 0) scale(1); }
.reader-pull.is-top { top: calc(env(safe-area-inset-top, 0px) + 20px + var(--pull) * 40px); opacity: calc(.4 + var(--pull) * .6); transform: translate(-50%, 0) scale(1); }
.reader-pull.is-ready { background: rgba(214, 54, 15, .85); border-color: rgba(255, 255, 255, .25); }
.fit-screen .reader-paged .reader-img { width: 100%; height: 100vh; height: 100dvh; object-fit: contain; }
.fit-width .reader-paged { align-items: flex-start; }
.fit-width .reader-paged .reader-img { width: 100%; height: auto; }
.reader-paged .reader-img.is-missing { background: repeating-linear-gradient(135deg, #0d0d10 0 12px, #121216 12px 24px); }

/* end-of-chapter card (vertical) */
.reader-end {
  padding: 48px 16px calc(var(--safe-b) + var(--reader-bar-h) + 56px);
  display: flex; justify-content: center;
}
.reader-end-card {
  width: 100%; max-width: 420px; padding: 24px 20px 20px; border-radius: 24px;
  display: flex; flex-direction: column; gap: 12px; text-align: center;
}
.reader-end-title { font-size: 17px; font-weight: 600; margin-bottom: 6px; overflow-wrap: anywhere; }
.reader-end-done { margin: 0 0 4px; color: var(--reader-text-2); font-size: 15px; }
.reader-end-next { min-width: 0; }
.reader-btn-ghost { background: rgba(255, 255, 255, .08); color: #f0ece6; border: 1px solid rgba(255, 255, 255, .08); }
.reader-btn-ghost:active { background: rgba(255, 255, 255, .14); }

/* ---------- overlays ---------- */
.reader-top, .reader-bottom {
  position: fixed; z-index: 20;
  left: calc(8px + var(--reader-safe-l)); right: calc(8px + var(--reader-safe-r));
  max-width: 760px; margin: 0 auto;
  display: flex; align-items: center; gap: 2px;
  border-radius: 22px; padding: 6px;
  transition: transform .28s cubic-bezier(.2, .8, .2, 1), opacity .22s;
}
.reader-top { top: calc(8px + var(--reader-safe-t)); }
.reader-bottom { bottom: calc(8px + var(--safe-b)); min-height: var(--reader-bar-h); }
body.reader-ui-hidden .reader-top { transform: translateY(calc(-100% - 16px - var(--reader-safe-t))); opacity: 0; pointer-events: none; }
body.reader-ui-hidden .reader-bottom { transform: translateY(calc(100% + 16px + var(--safe-b))); opacity: 0; pointer-events: none; }

.reader-top .icon-btn, .reader-bottom .icon-btn { width: 42px; height: 42px; color: #f2f2f5; }
.reader-top .icon-btn .icon, .reader-bottom .icon-btn .icon { width: 24px; height: 24px; }
.reader-bottom .icon-btn .icon { width: 22px; height: 22px; }
.reader-top .icon-btn:active, .reader-bottom .icon-btn:active { background: rgba(255, 255, 255, .14); }
.reader-bottom .icon-btn:disabled { opacity: .3; cursor: default; background: none; }

.reader-top-title { flex: 1; min-width: 0; padding: 0 4px; line-height: 1.25; }
.reader-top-manga { font-size: 15px; font-weight: 600; }
.reader-top-chapter { font-size: 12.5px; color: var(--reader-text-2); }

.reader-scrub { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; padding: 0 4px; }
.reader-page-label { flex-shrink: 0; min-width: 52px; text-align: right; font-size: 13px; font-variant-numeric: tabular-nums; color: var(--reader-text-2); }

/* range slider (page scrubber + brightness) */
.reader-slider {
  -webkit-appearance: none; appearance: none;
  flex: 1; min-width: 0; height: 30px; margin: 0; background: transparent; cursor: pointer;
  accent-color: var(--accent-light);
}
.reader-slider:disabled { opacity: .4; cursor: default; }
.reader-slider::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: rgba(255, 255, 255, .22); }
.reader-slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 18px; height: 18px; margin-top: -7px; border-radius: 50%;
  background: #fff; box-shadow: 0 0 0 4px rgba(240, 80, 42, .45), 0 2px 8px rgba(0, 0, 0, .4);
}
.reader-slider::-moz-range-track { height: 4px; border-radius: 2px; background: rgba(255, 255, 255, .22); }
.reader-slider::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--accent-light); }
.reader-slider::-moz-range-thumb {
  width: 18px; height: 18px; border: 0; border-radius: 50%;
  background: #fff; box-shadow: 0 0 0 4px rgba(240, 80, 42, .45), 0 2px 8px rgba(0, 0, 0, .4);
}

/* ---------- info pill (always visible) ---------- */
.reader-pill {
  position: fixed; z-index: 15;
  right: calc(6px + var(--reader-safe-r)); bottom: calc(6px + var(--safe-b));
  display: flex; align-items: center; gap: 7px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 11px; line-height: 1.45; letter-spacing: .01em; font-variant-numeric: tabular-nums; white-space: nowrap;
  color: rgba(255, 255, 255, .9);
  background: linear-gradient(180deg, rgba(255, 255, 255, .06), rgba(255, 255, 255, 0)), rgba(10, 10, 13, .55);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  backdrop-filter: blur(16px) saturate(160%);
  border: 1px solid rgba(255, 255, 255, .08);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .10), 0 4px 14px rgba(0, 0, 0, .35);
  pointer-events: none;
  transition: bottom .28s cubic-bezier(.2, .8, .2, 1);
}
body.reading:not(.reader-ui-hidden) .reader-pill { bottom: calc(8px + var(--safe-b) + var(--reader-bar-h) + 14px); }
.reader-pill-batwrap { display: inline-flex; align-items: center; gap: 4px; }
.reader-bat-glyph {
  position: relative; display: inline-block; width: 19px; height: 9px; padding: 1px;
  border: 1px solid rgba(255, 255, 255, .85); border-radius: 3px;
}
.reader-bat-glyph::after {
  content: ""; position: absolute; right: -3px; top: 2px; width: 1.5px; height: 3px;
  border-radius: 0 1px 1px 0; background: rgba(255, 255, 255, .85);
}
.reader-bat-glyph > i { display: block; height: 100%; width: 0; border-radius: 1px; background: #fff; }
.reader-bat-glyph.is-charging > i { background: #4cd964; }
.reader-bat-glyph.is-low > i { background: #ff5a52; }

/* ---------- dark sheets (chapters / settings) ---------- */
.sheet.reader-sheet {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .06), rgba(255, 255, 255, 0) 120px),
    var(--reader-glass-strong, rgba(18, 18, 22, .74));
  -webkit-backdrop-filter: blur(28px) saturate(170%);
  backdrop-filter: blur(28px) saturate(170%);
  color: #f0ece6;
  border-top: 1px solid rgba(255, 255, 255, .12);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .10), 0 -12px 44px rgba(0, 0, 0, .55);
  color-scheme: dark;
}
.reader-sheet .sheet-grabber { background: rgba(255, 255, 255, .28); }
.reader-sheet .sheet-title { font-weight: 600; }
.reader-sheet .chip { background: rgba(255, 255, 255, .07); color: rgba(255, 255, 255, .66); border-color: rgba(255, 255, 255, .06); }
.reader-sheet .chip.pill { font-size: 15px; min-height: 40px; }
.reader-sheet .chip.is-active { background: rgba(240, 80, 42, .24); color: #ffc2b0; border-color: #b97df7; box-shadow: 0 0 18px rgba(240, 80, 42, .25); }

.reader-set { padding: 6px 0 14px; }
.reader-set-label { font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: rgba(255, 255, 255, .5); margin: 0 2px 10px; }
html:lang(mn) .reader-set-label { text-transform: none; letter-spacing: 0; font-size: 13.5px; font-weight: 500; }
.reader-bright { display: flex; align-items: center; gap: 12px; padding: 0 2px; }
.reader-bright-icon { width: 22px; height: 22px; color: rgba(255, 255, 255, .7); }
.reader-bright-val { min-width: 40px; text-align: right; font-size: 13px; font-variant-numeric: tabular-nums; color: rgba(255, 255, 255, .7); }

.reader-ch-list { padding-bottom: 4px; }
.reader-sheet .sheet-list-item { border-bottom-color: rgba(255, 255, 255, .07); color: #f0ece6; padding: 0 10px; gap: 10px; border-radius: 0; }
.reader-ch-title { flex: 1; min-width: 0; }
.reader-ch-item.is-read { color: rgba(255, 255, 255, .5); }
.reader-ch-check { width: 18px; height: 18px; color: rgba(255, 255, 255, .4); }
.reader-ch-item.is-current {
  color: #ffc2b0; background: rgba(240, 80, 42, .18); border-radius: 12px; border-bottom-color: transparent;
  box-shadow: inset 0 0 0 1px rgba(185, 125, 247, .45);
}
.reader-ch-tag { flex-shrink: 0; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: rgba(240, 80, 42, .3); font-variant-numeric: tabular-nums; }

@media (prefers-reduced-motion: reduce) {
  .reader-top, .reader-bottom, .reader-pill { transition: none; }
}
