/* ==========================================================================
   LECTOR
   ========================================================================== */
.view-reader { padding: 0; overflow: hidden; }
.view-reader > * { max-width: none; }

/* ---------- Barra superior ---------- */
.reader-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: var(--panel-space, 0px);
  z-index: 30;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: var(--space-2);
  height: 64px;
  padding: 0 var(--space-3);
  background: color-mix(in oklab, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.3) blur(16px);
  -webkit-backdrop-filter: saturate(1.3) blur(16px);
  border-bottom: 1px solid transparent;
  transition: transform var(--dur-3) var(--ease-out), border-color var(--dur-2), right var(--dur-3) var(--ease-out);
}
.reader-bar.is-scrolled { border-bottom-color: var(--line); }
.view-reader.is-bar-hidden .reader-bar { transform: translateY(-100%); }
.rb-side { display: flex; align-items: center; gap: 2px; }
.rb-right { justify-content: flex-end; }
.rb-title {
  display: inline-flex;
  align-items: baseline;
  gap: .4em;
  padding: .45em 1em;
  border-radius: var(--radius-pill);
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 600;
  letter-spacing: -.01em;
  white-space: nowrap;
  transition: background-color var(--dur-1);
}
.rb-title:hover { background: var(--sunk); }
.rb-chapter { color: var(--accent); font-variant-numeric: lining-nums; }
.rb-caret { width: .8em; height: .8em; color: var(--ink-3); align-self: center; }
.rb-progress { position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; }
.rb-progress span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 80ms linear; }

.reader-settings { top: 68px; right: 12px; }
.reader-settings .rc { gap: var(--space-4); }

/* ---------- Cuerpo ---------- */
.reader-body { position: absolute; inset: 0; display: flex; }
.reader-scroll {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-padding-top: 96px;
  scroll-behavior: smooth;
}

.reader-page {
  --v-gutter: 2.4em;
  max-width: calc(var(--read-measure) + 2 * var(--gutter));
  margin: 0 auto;
  padding: 112px var(--gutter) calc(160px + var(--tabbar-h));
  font-family: var(--font-reading);
  font-size: var(--read-size);
  line-height: var(--read-leading);
  color: var(--ink);
  font-feature-settings: "kern", "liga", "onum";
  hyphens: manual;
  text-wrap: pretty;
}
.reader-page.is-changing { animation: page-in var(--dur-3) var(--ease-out); }
.reader-page.from-prev { --dir: -1; }
@keyframes page-in {
  from { opacity: 0; transform: translateX(calc(var(--dir, 1) * 24px)); }
}

/* Cabecera de capítulo */
.ch-head {
  display: grid;
  justify-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-7);
  text-align: center;
}
.ch-book {
  font-family: var(--font-ui);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.ch-num {
  font-feature-settings: "lnum";
  font-family: var(--font-display);
  font-size: clamp(5rem, 3rem + 9vw, 9.5rem);
  font-weight: 300;
  line-height: .85;
  letter-spacing: -.04em;
  color: var(--ink);
  font-variant-numeric: lining-nums;
}
.ch-num em {
  display: block;
  margin-bottom: .2em;
  font-size: .16em;
  font-style: italic;
  font-weight: 400;
  letter-spacing: 0;
  color: var(--accent);
}
.ch-meta { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: var(--space-3); }
.ch-meta .chip { font-family: var(--font-ui); }
.ch-rule { width: 56px; height: 1px; background: var(--accent-line); margin-top: var(--space-4); }

/* Texto */
.ch-text { position: relative; }
.justify .ch-text { text-align: justify; }

.v {
  position: relative;
  border-radius: 4px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.vn {
  font-feature-settings: "lnum", "tnum";
  font-family: var(--font-ui);
  font-size: .56em;
  font-weight: 700;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums lining-nums;
  vertical-align: baseline;
  position: relative;
  top: -.62em;
  margin-right: .3em;
  user-select: none;
  transition: color var(--dur-1);
}
.no-numbers .vn { display: none; }
.vt { transition: background-color var(--dur-2), text-decoration-color var(--dur-2); }
.woj { color: inherit; }
.red-letter .woj { color: var(--woj); }

/* Modo estudio: un versículo por línea, número colgado en el margen */
.mode-study .v { display: block; padding-left: var(--v-gutter); margin-bottom: .32em; }
.mode-study .vn {
  position: absolute;
  left: 0;
  top: .62em;
  width: calc(var(--v-gutter) - .7em);
  text-align: right;
  font-size: .56em;
  margin: 0;
  line-height: 1;
}
.mode-study.no-numbers .v { padding-left: 0; }

/* Modo párrafo / enfoque: texto corrido */
.mode-paragraph .v, .mode-focus .v { display: inline; }
.mode-paragraph .ch-text, .mode-focus .ch-text { text-indent: 0; }

/* Poesía */
.pl { display: block; }
.pl + .pl { padding-left: 1.4em; }
.mode-paragraph .v.is-poetry, .mode-focus .v.is-poetry { display: block; margin: .15em 0; }

/* Capitular */
/* (con capitular, el versículo 1 se pinta sin número) */
.dropcap.mode-study .v-first::first-letter,
.dropcap:not(.mode-study) .ch-text::first-letter {
  float: left;
  font-family: var(--font-display);
  font-size: 3.3em;
  line-height: .82;
  font-weight: 500;
  margin: .07em .1em 0 0;
  color: var(--accent);
}
.dropcap.mode-study .v-first { padding-left: 0; display: flow-root; margin-bottom: .6em; }
.dropcap:not(.mode-study) .ch-text::after { content: ""; display: table; clear: both; }

/* Títulos de sección del usuario */
.v-heading {
  display: block;
  margin: 1.6em 0 .6em;
  font-family: var(--font-ui);
  font-size: .64em;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--accent);
}
.v-heading:first-child { margin-top: 0; }
.no-headings .v-heading { display: none; }

/* Subrayados (efecto rotulador) */
.v[data-hl] .vt {
  background-image: linear-gradient(to bottom, transparent 14%, var(--hl-bg) 14%, var(--hl-bg) 92%, transparent 92%);
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  border-radius: 3px;
  padding: 0 .06em;
}
[data-hl="yellow"] { --hl-bg: var(--hl-yellow-bg); }
[data-hl="green"] { --hl-bg: var(--hl-green-bg); }
[data-hl="blue"] { --hl-bg: var(--hl-blue-bg); }
[data-hl="red"] { --hl-bg: var(--hl-red-bg); }
[data-hl="purple"] { --hl-bg: var(--hl-purple-bg); }
[data-hl="orange"] { --hl-bg: var(--hl-orange-bg); }
.hl-mark { background: var(--hl-bg); }

/* Selección */
.v.is-selected .vt {
  text-decoration: underline;
  text-decoration-style: dotted;
  text-decoration-thickness: 2px;
  text-decoration-color: var(--accent);
  text-underline-offset: .3em;
}
.v.is-selected .vn { color: var(--accent); }
.v.is-flash .vt { animation: flash 1.8s var(--ease-out); }
@keyframes flash { 0%, 30% { background-color: color-mix(in oklab, var(--accent) 18%, transparent); } }
@media (hover: hover) {
  .mode-study .v:hover .vn { color: var(--accent); }
}

/* Marcas junto al versículo */
.v-marks { display: inline-flex; gap: .2em; margin-left: .3em; vertical-align: middle; position: relative; top: -.08em; }
.v-marks .icon { width: .78em; height: .78em; stroke-width: 2; }
.v-marks .m-note { color: var(--accent); }
.v-marks .m-important { color: #C98A0B; fill: color-mix(in oklab, #E0A526 55%, transparent); }
.v-marks .m-pending { color: #3F8A4A; }
.v-marks .m-bookmark { color: var(--accent); fill: var(--accent); }
.v-tags { display: inline-flex; gap: 4px; margin-left: .4em; vertical-align: middle; }
.v-tags .chip { font-size: .6rem; min-height: 20px; padding: 0 .55em; font-family: var(--font-ui); }
.mode-paragraph .v-tags, .mode-focus .v-tags { display: none; }

/* Fin de capítulo */
.ch-end { display: grid; gap: var(--space-6); margin-top: var(--space-8); font-family: var(--font-ui); font-size: var(--fs-md); line-height: 1.4; }
.read-toggle {
  justify-self: center;
  display: inline-flex;
  align-items: center;
  gap: .7em;
  padding: .8em 1.4em .8em .9em;
  border-radius: 99px;
  border: 1px solid var(--line-2);
  background: var(--surface);
  font-weight: 600;
  color: var(--ink-2);
  transition: all var(--dur-2) var(--ease-out);
}
.read-toggle:hover { border-color: var(--accent); color: var(--ink); }
.rt-check {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1.5px solid var(--line-2);
  transition: all var(--dur-2) var(--ease-spring);
}
.rt-check .icon { width: 16px; height: 16px; stroke-width: 2.4; opacity: 0; transform: scale(.4); transition: all var(--dur-2) var(--ease-spring); }
.read-toggle.is-read { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
.read-toggle.is-read .rt-check { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.read-toggle.is-read .rt-check .icon { opacity: 1; transform: none; }
.read-toggle.just-read .rt-check { animation: pulse-ring .7s var(--ease-out); }
@keyframes pulse-ring { from { box-shadow: 0 0 0 0 color-mix(in oklab, var(--accent) 50%, transparent); } to { box-shadow: 0 0 0 14px transparent; } }

.ch-pager { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.ch-pager a {
  display: grid;
  gap: 2px;
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  transition: border-color var(--dur-2), background-color var(--dur-2), transform var(--dur-2) var(--ease-out);
}
.ch-pager a:hover { border-color: var(--accent-line); background: var(--surface); transform: translateY(-2px); }
.ch-pager small { font-size: .7rem; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-3); }
.ch-pager b { font-family: var(--font-display); font-size: 1.35rem; font-weight: 500; }
.ch-pager .next { text-align: right; grid-column: 2; }
.ch-pager .prev { grid-column: 1; }

/* ---------- Panel de estudio ---------- */
.study-panel {
  width: 0;
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--line);
  overflow: hidden;
  visibility: hidden;
  transition: width var(--dur-3) var(--ease-out), visibility var(--dur-3);
}
.view-reader.panel-open .study-panel { width: 400px; visibility: visible; }
.view-reader.panel-open { --panel-space: 400px; }
.sheet-grip { display: none; }
.sp-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-5) var(--space-3);
  min-width: 400px;
}
.sp-ref { font-family: var(--font-display); font-size: 1.7rem; font-weight: 500; line-height: 1.1; margin-top: 4px; }
.sp-body { flex: 1; overflow-y: auto; padding: 0 var(--space-5) var(--space-6); min-width: 400px; display: grid; gap: var(--space-5); align-content: start; }
.sp-quote {
  font-family: var(--font-reading);
  font-size: 1.02rem;
  line-height: 1.6;
  color: var(--ink-2);
  padding-left: var(--space-4);
  border-left: 2px solid var(--line-2);
  max-height: 11em;
  overflow-y: auto;
}
.sp-section { display: grid; gap: var(--space-2); }
.sp-label { display: flex; align-items: center; justify-content: space-between; font-size: .7rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); }
.sp-label small { font-weight: 500; letter-spacing: 0; text-transform: none; }
textarea.sp-note {
  min-height: 150px;
  max-height: 45vh;
  field-sizing: content;
  font-family: var(--font-reading);
  font-size: 1rem;
  line-height: 1.65;
  resize: vertical;
  background: var(--bg);
}
.sp-flags { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.flag-btn {
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: .7em .4em;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  font-size: .75rem;
  font-weight: 600;
  color: var(--ink-3);
  transition: all var(--dur-2) var(--ease-out);
}
.flag-btn .icon { width: 20px; height: 20px; }
.flag-btn:hover { border-color: var(--line-2); color: var(--ink); }
.flag-btn[aria-pressed="true"] { border-color: var(--accent-line); background: var(--accent-soft); color: var(--accent); }
.flag-btn[data-flag="important"][aria-pressed="true"] .icon { fill: currentColor; }
.flag-btn[data-flag="bookmark"][aria-pressed="true"] .icon { fill: currentColor; }
.sp-colors { display: flex; gap: 8px; flex-wrap: wrap; }

.tag-input {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  min-height: 44px;
  padding: 6px 8px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  background: var(--bg);
}
.tag-input:focus-within { border-color: var(--accent); }
.tag-input input { flex: 1; min-width: 110px; border: 0; outline: 0; background: transparent; font-size: var(--fs-sm); padding: 4px; }
.tag-suggest { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-suggest .chip { cursor: pointer; opacity: .8; }

.mention {
  display: flex;
  align-items: flex-start;
  text-align: left;
  gap: var(--space-2);
  padding: .6em .8em;
  border-radius: var(--radius);
  background: var(--sunk);
  font-size: var(--fs-sm);
  font-weight: 500;
}
.mention:hover { background: var(--accent-soft); color: var(--accent); }

.sheet-backdrop { display: none; }

/* ---------- Barra de acciones del versículo ---------- */
.verse-dock {
  position: absolute;
  left: 50%;
  bottom: calc(var(--space-5) + var(--safe-b));
  z-index: 50;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 6px 6px 6px var(--space-4);
  max-width: calc(100% - 24px);
  translate: calc(-50% - var(--panel-space, 0px) / 2) 0;
  border-radius: 99px;
  background: var(--ink);
  color: var(--bg);
  box-shadow: var(--shadow-3);
  animation: dock-in var(--dur-3) var(--ease-spring);
}
@keyframes dock-in { from { opacity: 0; transform: translateY(24px) scale(.94); } }
.vd-ref { font-family: var(--font-ui); font-size: var(--fs-sm); font-weight: 700; white-space: nowrap; padding-right: var(--space-2); }
.vd-colors { display: flex; gap: 5px; padding: 0 var(--space-2); border-left: 1px solid color-mix(in oklab, var(--bg) 20%, transparent); border-right: 1px solid color-mix(in oklab, var(--bg) 20%, transparent); }
.vd-color {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--sw);
  box-shadow: inset 0 0 0 1px color-mix(in oklab, black 15%, transparent);
  transition: transform var(--dur-2) var(--ease-spring);
}
.vd-color:hover { transform: scale(1.18); }
.vd-color.is-active { box-shadow: 0 0 0 2px var(--ink), 0 0 0 4px var(--sw); }
.vd-clear { display: grid; place-items: center; background: transparent; box-shadow: inset 0 0 0 1.5px color-mix(in oklab, var(--bg) 40%, transparent); }
.vd-clear .icon { width: 12px; height: 12px; }
.vd-actions { display: flex; gap: 2px; }
.vd-btn {
  display: inline-flex;
  align-items: center;
  gap: .4em;
  height: 38px;
  padding: 0 .75em;
  border-radius: 99px;
  font-size: .78rem;
  font-weight: 600;
  color: color-mix(in oklab, var(--bg) 82%, transparent);
  transition: background-color var(--dur-1), color var(--dur-1);
}
.vd-btn:hover { background: color-mix(in oklab, var(--bg) 12%, transparent); color: var(--bg); }
.vd-btn[aria-pressed="true"] { color: var(--bg); background: color-mix(in oklab, var(--accent) 55%, transparent); }
.vd-btn .icon { width: 18px; height: 18px; }
.vd-close { width: 38px; height: 38px; color: color-mix(in oklab, var(--bg) 70%, transparent); }
.vd-close:hover { background: color-mix(in oklab, var(--bg) 12%, transparent); color: var(--bg); }

.sp-colors .vd-color { width: 30px; height: 30px; }
.sp-colors .vd-color.is-active { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--sw); }
.sp-colors .vd-clear { box-shadow: inset 0 0 0 1.5px var(--line-2); color: var(--ink-3); }

/* Volver al marcador */
.bookmark-return {
  position: absolute;
  left: 50%;
  bottom: calc(var(--space-5) + var(--safe-b) + var(--tabbar-h));
  translate: calc(-50% - var(--panel-space, 0px) / 2) 0;
  z-index: 45;
  display: inline-flex;
  align-items: center;
  gap: .5em;
  padding: .7em 1.2em;
  border-radius: 99px;
  background: var(--surface);
  border: 1px solid var(--line-2);
  box-shadow: var(--shadow-2);
  font-size: var(--fs-sm);
  font-weight: 600;
  animation: dock-in var(--dur-3) var(--ease-spring);
}
.bookmark-return .icon { color: var(--accent); fill: var(--accent); width: 16px; height: 16px; }

/* ---------- Modo enfoque ---------- */
.focus-exit { position: absolute; top: 16px; right: 16px; z-index: 40; opacity: 0; pointer-events: none; background: var(--surface); box-shadow: var(--shadow-2); transition: opacity var(--dur-3); }
.mode-focus .view-reader .focus-exit { opacity: .55; pointer-events: auto; }
.mode-focus .view-reader .focus-exit:hover { opacity: 1; }
.mode-focus .view-reader .reader-bar { transform: translateY(-100%); }
.mode-focus .view-reader .study-panel { width: 0; visibility: hidden; }
.mode-focus .view-reader { --panel-space: 0px; }
[data-view-active="reader"].mode-focus .tabbar { transform: translateY(110%); }
.mode-focus .view-reader .reader-page { padding-top: 14vh; }
.mode-focus .view-reader .ch-meta, .mode-focus .view-reader .v-marks, .mode-focus .view-reader .v-tags { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1560px) and (min-width: 761px) {
  .vd-btn span { display: none; }
  .vd-btn { width: 38px; padding: 0; justify-content: center; }
}
@media (max-width: 1180px) {
  .view-reader.panel-open .study-panel { width: 360px; }
  .view-reader.panel-open { --panel-space: 360px; }
  .sp-head, .sp-body { min-width: 360px; }
}

@media (max-width: 960px) {
  /* El panel se convierte en hoja inferior */
  .view-reader.panel-open { --panel-space: 0px; }
  .study-panel,
  .view-reader.panel-open .study-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 120;
    width: 100%;
    height: min(78dvh, 720px);
    border-left: 0;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    box-shadow: var(--shadow-3);
    transform: translateY(105%);
    visibility: hidden;
    transition: transform var(--dur-3) var(--ease-out), visibility var(--dur-3);
  }
  .study-panel.is-sheet-open { transform: none; visibility: visible; }
  .sp-head, .sp-body { min-width: 0; }
  .sp-body { padding-bottom: calc(var(--space-6) + var(--safe-b)); }
  .sheet-grip { display: block; width: 40px; height: 4px; border-radius: 4px; background: var(--line-2); margin: 10px auto 0; flex: none; }
  .sheet-backdrop { display: block; position: fixed; inset: 0; z-index: 110; background: var(--overlay); animation: fade var(--dur-2); }
}

@media (max-width: 760px) {
  .reader-bar { height: 56px; padding: 0 var(--space-1); }
  .rb-title { font-size: 1.15rem; padding: .4em .6em; }
  .reader-page { padding-top: 92px; --v-gutter: 1.9em; }
  .reader-settings { right: 8px; left: 8px; width: auto; top: 60px; }
  .ch-head { margin-bottom: var(--space-6); }
  .verse-dock {
    bottom: calc(var(--tabbar-h) + var(--safe-b) + var(--space-2));
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    width: calc(100% - 16px);
    padding: var(--space-3);
    border-radius: var(--radius-lg);
    translate: -50% 0;
  }
  .is-immersive .verse-dock { bottom: calc(var(--safe-b) + var(--space-2)); }
  .vd-ref { width: 100%; text-align: center; padding: 0; }
  .vd-colors { border: 0; padding: 0; }
  .vd-actions { width: 100%; justify-content: space-between; gap: 0; }
  .vd-btn { flex: 1; min-width: 0; flex-direction: column; height: auto; padding: .45em 0; gap: 2px; font-size: .6rem; }
  .vd-btn span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
  .vd-btn span { display: block; }
  .vd-close { position: absolute; top: 4px; right: 4px; width: 32px; height: 32px; }
  .ch-pager { grid-template-columns: 1fr; }
  .ch-pager .next, .ch-pager .prev { grid-column: auto; }
  .bookmark-return { translate: -50% 0; }
  .is-immersive .bookmark-return { bottom: calc(var(--safe-b) + var(--space-4)); }
}

/* Enlace a la ficha del libro (Aprende) */
.chip-learn { color: var(--accent); border-color: var(--accent-line); }
.chip-learn:hover { background: var(--accent-soft); }

/* Derechos del texto al pie del capítulo */
.ch-copy { text-align: center; font-size: .72rem; line-height: 1.5; color: var(--ink-3); max-width: 52ch; justify-self: center; }
.ch-copy a { color: var(--ink-2); text-decoration: underline; text-underline-offset: 2px; }
.mode-focus .view-reader .ch-copy { display: none; }
