/* The comic reader: one page or a book spread, big soft controls, art first. */

.reader {
  --top-h: 60px;
  --bottom-h: 104px;
  --ui-fade: 0.35s;
  position: fixed; inset: 0;
  overflow: hidden;
  background:
    radial-gradient(90% 70% at 50% 0%, rgba(47, 134, 255, 0.16), transparent 70%),
    radial-gradient(60% 50% at 50% 110%, rgba(255, 193, 92, 0.08), transparent 70%),
    var(--night-950);
  color: var(--text);
  user-select: none; -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* ------------------------------------------------------------ stage */
.r-stage {
  position: absolute; inset: 0;
  touch-action: none;
  cursor: pointer;
  outline: none;
}
.r-zoom {
  position: absolute; inset: 0;
  transform-origin: 0 0;
  will-change: transform;
}
.r-zoom.is-animating { transition: transform 0.3s var(--ease); }
.r-spread {
  position: absolute;
  left: 50%; top: var(--stage-top, 0px);
  height: var(--stage-h, 100%);
  display: flex; align-items: center; justify-content: center;
  transform: translateX(calc(-50% + var(--drag, 0px)));
  transition: top 0.35s var(--ease), height 0.35s var(--ease);
}
.r-spread.is-dragging { transition: none; }
.r-spread.is-settling { transition: transform 0.28s var(--ease), top 0.35s var(--ease), height 0.35s var(--ease); }
.r-slot {
  position: relative; flex: none;
  width: var(--pw); height: var(--ph);
  overflow: hidden;
  background: var(--cream-100);
  box-shadow: 0 24px 60px -24px rgba(0, 0, 0, 0.85), 0 0 0 1px rgba(255, 255, 255, 0.04);
  transition: width 0.35s var(--ease), height 0.35s var(--ease);
}
.r-thumb, .r-page {
  position: absolute; inset: 0; display: block;
  width: 100%; height: 100%; max-width: none;
  -webkit-user-drag: none; user-drag: none;
  pointer-events: none;
}
/* Upscaled thumbnail as a soft placeholder; scaled a touch so the blur has no pale rim. */
.r-thumb { filter: blur(5px); transform: scale(1.04); }
.r-page { opacity: 0; transition: opacity 0.35s ease; }
.r-page.is-loaded { opacity: 1; }
.r-page.is-instant { transition: none; }
.r-slot:only-child { border-radius: 6px; }
.r-spread.is-pair .r-slot:first-child {
  border-radius: 6px 0 0 6px;
  -webkit-mask-image: linear-gradient(90deg, #000 94%, rgba(0, 0, 0, 0.82));
  mask-image: linear-gradient(90deg, #000 94%, rgba(0, 0, 0, 0.82));
}
.r-spread.is-pair .r-slot:last-child {
  border-radius: 0 6px 6px 0;
  -webkit-mask-image: linear-gradient(270deg, #000 94%, rgba(0, 0, 0, 0.82));
  mask-image: linear-gradient(270deg, #000 94%, rgba(0, 0, 0, 0.82));
}
.r-spread.turn-next { animation: turn-next 0.32s var(--ease); }
.r-spread.turn-prev { animation: turn-prev 0.32s var(--ease); }
@keyframes turn-next { from { opacity: 0.35; translate: 28px 0; } to { opacity: 1; translate: 0 0; } }
@keyframes turn-prev { from { opacity: 0.35; translate: -28px 0; } to { opacity: 1; translate: 0 0; } }

.r-loading { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; transition: opacity 0.3s; }
.r-loading.is-hidden { opacity: 0; }
.r-loading .face { --w: 96px; }
.r-noscript { position: absolute; inset: auto 0 40% 0; text-align: center; padding: 0 24px; }
.r-error { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 24px; }

/* ------------------------------------------------------------ chrome */
.r-top, .r-bottom {
  position: absolute; left: 0; right: 0; z-index: 10;
  transition: transform var(--ui-fade) var(--ease), opacity var(--ui-fade);
}
.r-top {
  top: 0; height: calc(var(--top-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left));
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px;
  background: linear-gradient(180deg, rgba(5, 8, 23, 0.9), rgba(5, 8, 23, 0.55));
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.r-bottom {
  bottom: 0;
  padding: 0 max(10px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  background: linear-gradient(0deg, rgba(5, 8, 23, 0.94), rgba(5, 8, 23, 0.7));
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.reader:not(.is-ui) .r-top { transform: translateY(-100%); opacity: 0; pointer-events: none; }
.reader:not(.is-ui) .r-bottom { transform: translateY(100%); opacity: 0; pointer-events: none; }

.r-back {
  display: inline-flex; align-items: center; gap: 6px; height: 44px; padding: 0 12px 0 6px;
  border-radius: 999px; text-decoration: none; font-weight: 800; color: var(--text);
  transition: background-color 0.2s;
}
.r-back:hover { background: rgba(255, 255, 255, 0.08); }
.r-back svg { width: 20px; height: 20px; }
.r-back img { width: 30px; height: 30px; }
.r-title {
  margin: 0; text-align: center; min-width: 0;
  font-family: var(--font-display); font-weight: 600; font-variation-settings: "SOFT" 100; font-size: 1.02rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text);
}
.r-top__tools { display: flex; align-items: center; gap: 6px; }
.r-count { font-weight: 800; font-size: 0.88rem; color: var(--text-muted); font-variant-numeric: tabular-nums; padding: 0 6px; white-space: nowrap; }
.r-icon {
  width: 44px; height: 44px; border-radius: 50%; border: 0; background: transparent; color: var(--text);
  display: grid; place-items: center; cursor: pointer; transition: background-color 0.2s;
}
.r-icon:hover { background: rgba(255, 255, 255, 0.08); }
.r-icon svg { width: 22px; height: 22px; }
.r-icon .fs-exit { display: none; }
.is-fullscreen .r-icon .fs-enter { display: none; }
.is-fullscreen .r-icon .fs-exit { display: inline; }
@media (max-width: 479px) {
  .r-back__label { display: none; }
  .r-title { font-size: 0.92rem; }
}

/* progress */
.r-progress {
  position: relative; height: 18px; margin: 0 4px; cursor: pointer; touch-action: none;
}
.r-progress::before {
  content: ""; position: absolute; left: 0; right: 0; top: 7px; height: 4px; border-radius: 4px; background: rgba(188, 195, 230, 0.18);
}
.r-progress__fill {
  position: absolute; left: 0; top: 7px; height: 4px; border-radius: 4px; width: 0;
  background: linear-gradient(90deg, var(--honey-500), var(--honey-400));
  box-shadow: 0 0 10px rgba(255, 193, 92, 0.6);
  transition: width 0.3s var(--ease);
}
.r-progress:focus-visible { outline-offset: 0; }

.r-bar { display: flex; align-items: center; gap: 12px; }
.r-chapters {
  flex: 1 1 auto; min-width: 0;
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
  padding: 4px 2px; scroll-padding: 0 40px;
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 12px, #000 calc(100% - 24px), transparent);
  mask-image: linear-gradient(90deg, transparent 0, #000 12px, #000 calc(100% - 24px), transparent);
}
.r-chapters::-webkit-scrollbar { display: none; }
.r-chip {
  flex: 0 0 auto; display: inline-flex; align-items: center; gap: 8px;
  height: 44px; padding: 0 16px 0 6px; border-radius: 999px;
  border: 1.5px solid rgba(188, 195, 230, 0.22); background: rgba(19, 29, 75, 0.6);
  color: var(--text-muted); font-weight: 700; font-size: 0.92rem; cursor: pointer; white-space: nowrap;
  transition: background-color 0.2s, border-color 0.2s, color 0.2s;
}
.r-chip b {
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 700; font-size: 0.95rem;
  background: rgba(255, 193, 92, 0.16); color: var(--honey-300);
}
.r-chip:hover { color: var(--text); border-color: rgba(188, 195, 230, 0.45); }
.r-chip[aria-current="true"] { background: var(--honey-400); border-color: var(--honey-400); color: var(--night-900); }
.r-chip[aria-current="true"] b { background: var(--night-900); color: var(--honey-400); }

.r-tools { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; }
.r-lang { display: inline-flex; padding: 3px; border-radius: 999px; background: rgba(19, 29, 75, 0.8); border: 1.5px solid rgba(188, 195, 230, 0.22); }
.r-lang button {
  height: 36px; min-width: 46px; padding: 0 12px; border: 0; border-radius: 999px; cursor: pointer;
  background: transparent; color: var(--text-muted); font-weight: 800; font-size: 0.9rem; transition: background-color 0.2s, color 0.2s;
}
.r-lang button[aria-pressed="true"] { background: var(--cream-100); color: var(--night-900); }
.r-listen {
  display: inline-flex; align-items: center; gap: 8px; height: 44px; padding: 0 18px 0 14px;
  border-radius: 999px; border: 0; cursor: pointer;
  background: var(--ocean-500); color: #fff; font-weight: 800; font-size: 0.95rem;
  box-shadow: 0 8px 24px -10px rgba(47, 134, 255, 0.9);
  transition: background-color 0.2s, transform 0.2s var(--ease);
}
.r-listen:hover { background: var(--ocean-400); }
.r-listen svg { width: 16px; height: 16px; }
.r-listen .i-pause { display: none; }
.r-listen[aria-pressed="true"] { background: var(--honey-400); color: var(--night-900); }
.r-listen[aria-pressed="true"] .i-play { display: none; }
.r-listen[aria-pressed="true"] .i-pause { display: inline; }

.r-audio {
  display: flex; align-items: center; gap: 10px; margin-top: 8px; padding: 0 6px;
  font-size: 0.82rem; color: var(--text-muted); font-variant-numeric: tabular-nums;
}
.r-audio__title { font-weight: 800; color: var(--honey-300); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 45%; }
.r-audio__track { flex: 1; height: 3px; border-radius: 3px; background: rgba(188, 195, 230, 0.18); overflow: hidden; }
.r-audio__fill { display: block; height: 100%; width: 0; background: var(--honey-400); }

/* Phones: chapters get their own row, tools below. */
@media (max-width: 639px) {
  .r-bar { flex-wrap: wrap; gap: 8px; }
  .r-chapters { flex-basis: 100%; }
  .r-tools { flex: 1 1 100%; justify-content: space-between; }
  .r-chip { height: 40px; font-size: 0.88rem; }
  .r-chip b { width: 28px; height: 28px; }
}

/* ------------------------------------------------------------ arrows */
.r-arrow {
  position: absolute; top: 50%; z-index: 9;
  width: 60px; height: 60px; margin-top: -30px; border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.22);
  background: rgba(12, 20, 54, 0.55);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  color: var(--cream-50);
  display: grid; place-items: center; cursor: pointer;
  box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.7);
  transition: opacity 0.5s, transform 0.25s var(--ease), background-color 0.2s;
}
.r-arrow svg { width: 26px; height: 26px; }
.r-arrow:hover { background: rgba(29, 42, 102, 0.85); transform: scale(1.06); }
.r-arrow--prev { left: max(12px, env(safe-area-inset-left)); }
.r-arrow--next { right: max(12px, env(safe-area-inset-right)); }
.r-arrow[disabled] { opacity: 0 !important; pointer-events: none; }
.reader.is-idle .r-arrow, .reader:not(.is-ui) .r-arrow, .reader.is-zoomed .r-arrow { opacity: 0; pointer-events: none; }
@media (max-width: 639px) {
  .r-arrow { width: 48px; height: 48px; margin-top: -24px; }
  .r-arrow svg { width: 22px; height: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  .r-spread.turn-next, .r-spread.turn-prev { animation: none; }
  .r-slot, .r-page, .r-spread, .r-zoom.is-animating { transition: none; }
}
