/* ==========================================================
   Reader — one verse per screen, swipe up for the next.
   Uses the theme tokens from styles.css (light / dark).
   ========================================================== */

.reader-page {
  overflow: hidden;           /* the feed scrolls, not the page */
  height: 100vh;
  height: 100dvh;
  --serif-ta: "Noto Serif Tamil", "Noto Sans Tamil", serif;
  --serif-en: "Source Serif 4", Georgia, "Times New Roman", serif;
}

/* ---------- Top bar ---------- */

.rbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: max(12px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 12px max(14px, env(safe-area-inset-left));
  background: linear-gradient(var(--bg) 55%, rgba(var(--sheet-rgb), 0));
  pointer-events: none;
}

[data-theme="light"] .rbar { background: linear-gradient(#fff 55%, rgba(255, 255, 255, 0)); }

.rbar > * { pointer-events: auto; }

.rbar__left,
.rbar__right {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.rbtn {
  display: grid;
  place-items: center;
  flex: none;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(var(--ink), 0.3);
  border-radius: 50%;
  background: rgba(var(--sheet-rgb), 0.6);
  -webkit-backdrop-filter: blur(10px);
          backdrop-filter: blur(10px);
  color: var(--fg);
  transition: background-color 0.25s, color 0.25s, border-color 0.25s, transform 0.25s var(--ease-out);
}

.rbtn:active { transform: scale(0.92); }

.rbtn svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.rbar .pill,
.rbar .theme-toggle {
  height: 38px;
  background: rgba(var(--sheet-rgb), 0.6);
  -webkit-backdrop-filter: blur(10px);
          backdrop-filter: blur(10px);
}

.rbar .theme-toggle { width: 38px; background: none; -webkit-backdrop-filter: none; backdrop-filter: none; }
.rbar .pill { padding: 0 14px; gap: 8px; }

.rbar .langmenu__btn { flex: none; white-space: nowrap; }

.rbar .logo { flex: none; }
.rbar__left { flex: none; }
.rbar__right { flex: 1 1 0; justify-content: flex-end; }
.rbar .theme-toggle { flex: none; }

/* Phones: the logo, language, theme and chapter all share one row */
@media (max-width: 480px) {
  .rbar .logo { font-size: 22px; }
  .rbar .logo__sym { display: none; } /* keeps room for the chapter name */
  .rbar .logo__sub { font-size: 11px; }
  .rbar .pill { padding: 0 10px; gap: 4px; }
  .rbar .langmenu__btn .langmenu__chev { display: none; }
  .rbar .langmenu__btn { font-size: 12px; letter-spacing: 0.02em; }
}

.chapter-pill {
  min-width: 0;
  max-width: 46vw;
  text-decoration: none;
  letter-spacing: 0.02em;
  font-size: 13px;
}

.chapter-pill__label {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}

.chapter-pill__label .n { color: var(--muted); margin-left: 4px; }

/* ---------- Feed ---------- */

.feed {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-snap-type: y mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  outline: none;
}

.feed::-webkit-scrollbar { display: none; }

.slide {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr); /* never wider than the screen, even for one long word */
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 88px 46px 128px; /* room for top bar, rail (left) and actions (bottom right) */
  scroll-snap-align: start;
  scroll-snap-stop: always;
}

.slide__inner {
  width: 100%;
  max-width: 680px;
  text-align: center;
}

/* ---------- A verse ---------- */

.vtext {
  font-weight: 400;
  color: var(--fg);
  text-wrap: pretty;
  overflow-wrap: break-word; /* last resort for a word wider than the screen */
}

.vtext--ta {
  font-family: var(--serif-ta);
  line-height: 1.7;
}

.vtext--en {
  font-family: var(--serif-en);
  line-height: 1.45;
  letter-spacing: -0.005em;
}

/* Sizes step down with verse length (set by reader.js as data-size) */
.slide[data-size="xl"] .vtext--ta { font-size: 30px; }
.slide[data-size="l"]  .vtext--ta { font-size: 25px; }
.slide[data-size="m"]  .vtext--ta { font-size: 21px; }
.slide[data-size="s"]  .vtext--ta { font-size: 18px; }
.slide[data-size="xs"] .vtext--ta { font-size: 16px; line-height: 1.6; }
.slide[data-size="xxs"] .vtext--ta { font-size: 14.5px; line-height: 1.55; }

.slide[data-size="xl"] .vtext--en { font-size: 32px; }
.slide[data-size="l"]  .vtext--en { font-size: 27px; }
.slide[data-size="m"]  .vtext--en { font-size: 23px; }
.slide[data-size="s"]  .vtext--en { font-size: 20px; }
.slide[data-size="xs"] .vtext--en { font-size: 17px; }
.slide[data-size="xxs"] .vtext--en { font-size: 15px; }

/* English + Tamil: Tamil leads; English follows, smaller but still bright */
[data-lang-mode="both"] .vtext--en {
  font-size: 0.72em;
  color: rgba(var(--ink), 0.9);
}

[data-lang-mode="both"] .slide[data-size="xl"] .vtext--en { font-size: 22px; }
[data-lang-mode="both"] .slide[data-size="l"]  .vtext--en { font-size: 19px; }
[data-lang-mode="both"] .slide[data-size="m"]  .vtext--en { font-size: 17px; }
[data-lang-mode="both"] .slide[data-size="s"]  .vtext--en { font-size: 15.5px; }
[data-lang-mode="both"] .slide[data-size="xs"] .vtext--en { font-size: 14.5px; }
[data-lang-mode="both"] .slide[data-size="xxs"] .vtext--en { font-size: 13px; line-height: 1.4; }
.slide[data-size="xxs"] .vrule { margin: 14px auto; }
.slide[data-size="xxs"] .vref { margin-top: 16px; }

.vrule {
  display: block;
  width: 28px;
  height: 1px;
  margin: 22px auto;
  background: rgba(var(--ink), 0.28);
}

[data-lang-mode="en"] .vtext--ta,
[data-lang-mode="ta"] .vtext--en,
[data-lang-mode="en"] .vrule,
[data-lang-mode="ta"] .vrule { display: none; }

.vref {
  margin-top: 28px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.vref :lang(ta) { letter-spacing: 0.01em; text-transform: none; font-size: 13px; }

/* Each verse settles in as it arrives */
.slide .slide__inner > * {
  opacity: 0.12;
  filter: blur(4px);
  transform: translateY(14px);
  transition: opacity 0.7s var(--ease-out), filter 0.7s var(--ease-out), transform 0.7s var(--ease-out);
}

.slide.is-active .slide__inner > * { opacity: 1; filter: none; transform: none; }
.slide.is-active .slide__inner > :nth-child(2) { transition-delay: 0.05s; }
.slide.is-active .slide__inner > :nth-child(3) { transition-delay: 0.1s; }
.slide.is-active .slide__inner > :nth-child(4) { transition-delay: 0.16s; }

/* ---------- Chapter title screen ---------- */

.slide--chapter .slide__inner { max-width: 520px; }

.ch__eyebrow {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
}

.ch__eyebrow:lang(ta),
.ch__eyebrow :lang(ta) { letter-spacing: 0.01em; text-transform: none; font-size: 13px; }

.ch__num {
  margin-top: 10px;
  font-size: clamp(120px, 34vw, 220px);
  font-weight: 300;
  line-height: 1;
  letter-spacing: -0.06em;
  font-variant-numeric: tabular-nums;
}

.ch__book {
  margin-top: 6px;
  font-family: var(--serif-ta);
  font-size: 26px;
}

.ch__book--en {
  margin-top: 4px;
  font-family: var(--serif-en);
  font-size: 18px;
  color: var(--muted);
}

[data-lang-mode="en"] .ch__book[lang="ta"],
[data-lang-mode="ta"] .ch__book--en { display: none; }
[data-lang-mode="en"] .ch__book--en { font-size: 26px; color: var(--fg); }

.ch__meta {
  margin-top: 22px;
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ---------- End of the Bible ---------- */

.end__title {
  font-size: clamp(30px, 8vw, 44px);
  font-weight: 400;
  letter-spacing: -0.03em;
}

.end__text { margin-top: 12px; color: var(--muted); line-height: 1.6; }
.end__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin-top: 28px; }

/* ---------- Swipe hint (first screen only) ---------- */

.hint {
  position: fixed;
  left: 0;
  right: 0;
  bottom: max(26px, env(safe-area-inset-bottom));
  z-index: 15;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  pointer-events: none;
  transition: opacity 0.5s ease;
}

.hint svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  animation: nudge 1.8s var(--ease-out) infinite;
}

.hint.is-gone { opacity: 0; }

@keyframes nudge {
  0%, 100% { transform: translateY(4px); opacity: 0.4; }
  50% { transform: translateY(-4px); opacity: 1; }
}

/* ---------- Verse rail (left) ---------- */

.rail {
  position: fixed;
  left: max(16px, env(safe-area-inset-left));
  top: 18vh;
  bottom: 22vh;
  z-index: 12;
  width: 24px;
  pointer-events: auto;
  cursor: pointer;
  transition: opacity 0.4s ease;
}

.rail__track {
  position: absolute;
  left: 3px;
  top: 0;
  bottom: 0;
  width: 1px;
  background: repeating-linear-gradient(rgba(var(--ink), 0.35) 0 4px, transparent 4px 9px);
}

.rail__marker {
  position: absolute;
  left: 1px;
  top: calc(var(--p, 0) * 100%);
  width: 5px;
  height: 22px;
  margin-top: -11px;
  border-radius: 3px;
  background: var(--fg);
  transition: top 0.45s var(--ease-out);
}

.rail__num {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  font-weight: 500;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.rail.is-hidden { opacity: 0; pointer-events: none; }

/* ---------- Save / share (bottom right) ---------- */

.ractions {
  position: fixed;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(24px, env(safe-area-inset-bottom));
  z-index: 16;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.rbtn--lg { width: 48px; height: 48px; }
.rbtn--lg svg { width: 20px; height: 20px; }

.rsave[aria-pressed="true"] { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.rsave[aria-pressed="true"] svg { fill: currentColor; }
.rsave.is-pop svg { animation: pop 0.45s var(--ease-out); }

.ractions.is-hidden { opacity: 0; pointer-events: none; }
.ractions { transition: opacity 0.3s ease; }

@keyframes pop {
  0% { transform: scale(0.6); }
  60% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

/* ---------- Toast ---------- */

.rtoast {
  position: fixed;
  left: 50%;
  bottom: max(34px, env(safe-area-inset-bottom));
  z-index: 30;
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--fg);
  color: var(--bg);
  font-size: 13px;
  white-space: nowrap;
  opacity: 0;
  transform: translate(-50%, 10px);
  transition: opacity 0.3s ease, transform 0.4s var(--ease-out);
  pointer-events: none;
}

.rtoast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Status (loading / errors) ---------- */

.rstatus {
  max-width: 34ch;
  margin: 0 auto;
  font-size: 15px;
  line-height: 1.6;
  color: var(--muted);
}

@media (hover: hover) {
  .rbtn:hover { background: var(--fg); color: var(--bg); border-color: var(--fg); }
  .rail:hover .rail__track { background: repeating-linear-gradient(rgba(var(--ink), 0.7) 0 4px, transparent 4px 9px); }
}

/* ---------- Larger screens ---------- */

/* The reader's top bar sits on the same margin as every other page */
.rbar { padding-left: var(--edge); padding-right: var(--edge); }
.rbar__right { margin-right: -9px; }

@media (min-width: 720px) {
  .rbar { padding-top: 20px; }
  .slide { padding: 110px 120px 110px; }
  .rail { left: 36px; top: 22vh; bottom: 22vh; }
  .ractions { right: 32px; bottom: 50%; transform: translateY(50%); }
  .ractions.is-hidden { transform: translateY(50%); }

  .slide[data-size="xl"] .vtext--ta { font-size: 40px; }
  .slide[data-size="l"]  .vtext--ta { font-size: 33px; }
  .slide[data-size="m"]  .vtext--ta { font-size: 27px; }
  .slide[data-size="s"]  .vtext--ta { font-size: 22px; }
  .slide[data-size="xs"] .vtext--ta { font-size: 19px; }
  .slide[data-size="xxs"] .vtext--ta { font-size: 17px; }

  .slide[data-size="xl"] .vtext--en { font-size: 44px; }
  .slide[data-size="l"]  .vtext--en { font-size: 36px; }
  .slide[data-size="m"]  .vtext--en { font-size: 30px; }
  .slide[data-size="s"]  .vtext--en { font-size: 24px; }
  .slide[data-size="xs"] .vtext--en { font-size: 20px; }
  .slide[data-size="xxs"] .vtext--en { font-size: 18px; }

  [data-lang-mode="both"] .slide[data-size="xl"] .vtext--en { font-size: 26px; }
  [data-lang-mode="both"] .slide[data-size="l"]  .vtext--en { font-size: 23px; }
  [data-lang-mode="both"] .slide[data-size="m"]  .vtext--en { font-size: 20px; }
  [data-lang-mode="both"] .slide[data-size="s"]  .vtext--en { font-size: 18px; }
  [data-lang-mode="both"] .slide[data-size="xs"] .vtext--en { font-size: 16px; }
  [data-lang-mode="both"] .slide[data-size="xxs"] .vtext--en { font-size: 15px; }

  .slide__inner { max-width: 760px; }
}

/* Landscape phones: less vertical padding */
@media (max-height: 540px) and (min-aspect-ratio: 3/2) {
  .slide { padding: 64px 96px 40px 64px; }
  .rail { top: 20vh; bottom: 14vh; }
  .ractions { bottom: 50%; transform: translateY(50%); }
  .hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .slide .slide__inner > * { transition: none; opacity: 1; filter: none; transform: none; }
  .hint svg, .rsave.is-pop svg { animation: none; }
  .rail__marker { transition: none; }
}

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

/* The very longest verses get a little more of the screen */
.slide[data-size="xxs"] { padding-top: 76px; padding-bottom: 104px; }

/* While reader.js measures, long words must not wrap mid-word (so overflow is detectable) */
.feed.is-measuring .vtext { overflow-wrap: normal; zoom: 1; }
.feed.is-settling .slide { visibility: hidden; }

/* A verse taller than the screen at large text sizes has to scroll freely */
.feed.is-free { scroll-snap-type: y proximity; }

/* The card sits over the heart and share buttons, so hide them while it is open */
.has-wordtip .ractions { opacity: 0; pointer-events: none; }

/* Phones: three action buttons, so keep them compact and clear of the verse */
@media (max-width: 480px) {
  .ractions { gap: 8px; bottom: max(16px, env(safe-area-inset-bottom)); }
  .ractions .rbtn--lg { width: 42px; height: 42px; }
  .slide--verse { padding-bottom: 164px; }
}
