/* ==========================================================
   Frame 2 — Verse finder (mobile first)
   ========================================================== */

html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

.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;
}

.finder {
  --line: rgba(var(--ink), 0.14);
  --line-strong: rgba(var(--ink), 0.28);
  --surface: rgba(var(--ink), 0.035);
  position: relative;
  padding: 88px var(--pad) calc(72px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}

.finder__title {
  margin-top: 14px;
  font-size: clamp(30px, 8.6vw, 40px);
  font-weight: 400;
  line-height: 1.08;
  letter-spacing: -0.03em;
}

.finder__lede {
  margin-top: 14px;
  max-width: 32ch;
  font-size: 15px;
  line-height: 1.55;
  color: var(--muted);
}

/* ---------- Card ---------- */

.finder__card {
  margin-top: 30px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 26px;
  background:
    radial-gradient(120% 60% at 50% 0%, rgba(var(--ink), 0.05), transparent 70%),
    var(--card);
}

/* search */
.search {
  position: relative;
  display: flex;
  align-items: center;
  height: 50px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  transition: border-color 0.25s;
}

.search:focus-within { border-color: rgba(var(--ink), 0.55); }

.search__go[hidden] { display: none; }

.search__icon {
  flex: none;
  width: 18px;
  height: 18px;
  margin-left: 17px;
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.5;
  stroke-linecap: round;
}

.search__input {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0 12px;
  border: 0;
  outline: 0;
  background: none;
  color: var(--fg);
  font: 400 16px/1 var(--sans); /* 16px stops iOS zoom-on-focus */
  -webkit-appearance: none;
  appearance: none;
}

.search__input::placeholder { color: rgba(var(--ink), 0.36); }
.search__input::-webkit-search-cancel-button { display: none; }

.search__go {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: none;
  height: 38px;
  margin-right: 5px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--fg);
  color: var(--bg);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
  white-space: nowrap;
  animation: pop 0.35s var(--ease-out);
}

.search__go svg,
.finder__cta svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.search__hint {
  min-height: 18px;
  margin: 8px 18px 0;
  font-size: 12px;
  color: var(--muted);
}

/* live reference */
.ref {
  padding: 18px 6px 22px;
  text-align: center;
}

.ref__main {
  font-size: clamp(26px, 7.6vw, 34px);
  font-weight: 400;
  line-height: 1.3;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

.ref__sub {
  margin-top: 6px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.ref.is-swap .ref__main,
.ref.is-swap .ref__sub { animation: swapIn 0.6s var(--ease-out) both; }
.ref.is-swap .ref__sub { animation-delay: 0.06s; }
.ref__sub[hidden] { display: none; }

/* fields */
.fields {
  display: grid;
  grid-template-columns: 1.55fr 1fr 1fr;
  gap: 8px;
}

.field {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 5px;
  min-width: 0;
  height: 66px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  text-align: left;
  transition: border-color 0.25s, background-color 0.25s, transform 0.25s var(--ease-out);
}

.field:active { transform: scale(0.97); }

.field__label {
  font-size: 9.5px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

.field__value {
  max-width: calc(100% - 14px);
  overflow: hidden;
  font-size: 17px;
  line-height: 1.1;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}

.field__chev {
  position: absolute;
  bottom: 17px;
  right: 11px;
  width: 11px;
  height: 11px;
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn--block {
  display: flex;
  width: 100%;
  gap: 10px;
  margin-top: 12px;
  height: 54px;
}

@media (hover: hover) {
  .field:hover { border-color: var(--line-strong); background: rgba(var(--ink), 0.06); }
  .chip:hover { border-color: rgba(var(--ink), 0.6); }
}

/* ---------- Popular ---------- */

.popular { margin-top: 30px; }

.popular__label {
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
}

.popular__row {
  display: flex;
  gap: 8px;
  margin: 12px calc(var(--pad) * -1) 0;
  padding: 2px var(--pad);
  overflow-x: auto;
  scroll-snap-type: x proximity;
  scroll-padding-inline: var(--pad);
  scrollbar-width: none;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 var(--pad), #000 calc(100% - 28px), transparent);
          mask-image: linear-gradient(90deg, transparent, #000 var(--pad), #000 calc(100% - 28px), transparent);
}

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

.chip {
  flex: none;
  height: 38px;
  padding: 0 16px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  font-size: 13px;
  white-space: nowrap;
  scroll-snap-align: start;
  transition: border-color 0.25s, background-color 0.25s, color 0.25s;
}

.chip[aria-pressed="true"] { background: var(--fg); color: var(--bg); border-color: var(--fg); }

/* ---------- Scroll-in ---------- */

.rise {
  opacity: 0;
  transform: translateY(18px);
  transition: opacity 1s var(--ease-out), transform 1s var(--ease-out);
}

.finder.is-in .rise { opacity: 1; transform: none; }
.finder.is-in .rise:nth-child(2) { transition-delay: 0.08s; }
.finder.is-in .rise:nth-child(3) { transition-delay: 0.16s; }
.finder.is-in .rise:nth-child(4) { transition-delay: 0.24s; }
.finder.is-in .rise:nth-child(5) { transition-delay: 0.32s; }
.no-js .rise { opacity: 1; transform: none; }

/* ==========================================================
   Bottom sheet
   ========================================================== */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 100;
}

.sheet[hidden] { display: none; }

.sheet__scrim {
  position: absolute;
  inset: 0;
  background: var(--scrim);
  -webkit-backdrop-filter: blur(6px);
          backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity 0.4s ease;
}

.sheet__panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  height: min(88svh, 760px);
  height: min(88dvh, 760px);
  padding-bottom: env(safe-area-inset-bottom);
  border: 1px solid rgba(var(--ink), 0.14);
  border-bottom: 0;
  border-radius: 26px 26px 0 0;
  background: var(--sheet);
  box-shadow: 0 -30px 80px var(--shadow);
  transform: translateY(100%);
  transition: transform 0.55s var(--ease-out);
  will-change: transform;
}

.sheet.is-open .sheet__scrim { opacity: 1; }
.sheet.is-open .sheet__panel { transform: translateY(var(--drag, 0px)); }
.sheet.is-dragging .sheet__panel { transition: none; }

.sheet__grab {
  flex: none;
  touch-action: none;
  cursor: grab;
}

.sheet__handle {
  display: block;
  width: 38px;
  height: 4px;
  margin: 10px auto 4px;
  border-radius: 2px;
  background: rgba(var(--ink), 0.25);
}

.sheet__head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 14px 0 var(--pad);
  border-bottom: 1px solid rgba(var(--ink), 0.1);
}

.tabs {
  position: relative;
  display: flex;
  flex: 1;
  min-width: 0;
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  flex: 1;
  min-width: 0;
  padding: 10px 4px 14px 0;
  text-align: left;
  color: rgba(var(--ink), 0.42);
  transition: color 0.3s;
}

.tab:first-child { flex: 1.5; }
.tab[aria-selected="true"] { color: var(--fg); }

.tab__k {
  font-size: 9.5px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.tab__v {
  max-width: 100%;
  overflow: hidden;
  font-size: 15px;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}

.tabs__bar {
  position: absolute;
  left: 0;
  bottom: -1px;
  height: 1.5px;
  width: var(--w, 0px);
  background: var(--fg);
  transform: translateX(var(--x, 0px));
  transition: transform 0.45s var(--ease-out), width 0.45s var(--ease-out);
}

.sheet__close {
  display: grid;
  place-items: center;
  flex: none;
  width: 36px;
  height: 36px;
  border: 1px solid rgba(var(--ink), 0.3);
  border-radius: 50%;
}

.sheet__close svg {
  width: 11px;
  height: 11px;
  fill: none;
  stroke: var(--fg);
  stroke-width: 1.4;
  stroke-linecap: round;
}

.sheet__viewport {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.sheet__track {
  display: flex;
  width: 300%;
  height: 100%;
  transform: translateX(calc(var(--step, 0) * -100% / 3));
  transition: transform 0.5s var(--ease-out);
}

.view {
  width: calc(100% / 3);
  height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 0 var(--pad) 28px;
}

.view__top {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 14px 0 10px;
  background: linear-gradient(var(--sheet) 85%, rgba(var(--sheet-rgb), 0));
}

.book-filter {
  width: 100%;
  height: 46px;
  padding: 0 18px;
  border: 1px solid rgba(var(--ink), 0.14);
  border-radius: 999px;
  outline: 0;
  background: rgba(var(--ink), 0.04);
  color: var(--fg);
  font: 400 16px/1 var(--sans);
  -webkit-appearance: none;
  appearance: none;
}

.book-filter:focus { border-color: rgba(var(--ink), 0.5); }
.book-filter::placeholder { color: rgba(var(--ink), 0.36); }
.book-filter::-webkit-search-cancel-button { display: none; }

/* Old / New testament toggle */
.seg-toggle {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-top: 10px;
  padding: 3px;
  border: 1px solid rgba(var(--ink), 0.14);
  border-radius: 999px;
}

.seg-toggle button {
  position: relative;
  z-index: 1;
  height: 36px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.06em;
  color: rgba(var(--ink), 0.6);
  transition: color 0.35s;
}

.seg-toggle button[aria-pressed="true"] { color: var(--bg); }
.seg-toggle button span { font-weight: 400; letter-spacing: 0; }

.seg-toggle__thumb {
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 3px;
  width: calc(50% - 3px);
  border-radius: 999px;
  background: var(--fg);
  transition: transform 0.45s var(--ease-out);
}

.seg-toggle[data-t="NT"] .seg-toggle__thumb { transform: translateX(100%); }
.seg-toggle.is-searching { opacity: 0.35; pointer-events: none; }

/* book list */
.books { margin-top: 2px; list-style: none; }

.book {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 60px;
  padding: 10px 2px;
  border-bottom: 1px solid rgba(var(--ink), 0.07);
  text-align: left;
}

.book[hidden] { display: none; }

.book__names {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.book__primary { font-size: 16px; }

.book__secondary {
  font-size: 13px;
  color: var(--muted);
}

.book__n {
  font-size: 12px;
  color: rgba(var(--ink), 0.4);
  font-variant-numeric: tabular-nums;
}

.book__check {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  opacity: 0;
  transform: scale(0.6);
  background: var(--fg);
  transition: opacity 0.25s, transform 0.35s var(--ease-out);
}

.book__check svg { width: 11px; height: 11px; fill: none; stroke: var(--bg); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.book[aria-selected="true"] .book__check { opacity: 1; transform: none; }
.book[aria-selected="true"] .book__n { display: none; }

.books__empty {
  padding: 40px 0;
  text-align: center;
  font-size: 14px;
  color: var(--muted);
}

/* number grids */
.view__meta {
  padding: 18px 0 14px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.view__meta span[lang="ta"] {
  letter-spacing: 0;
  text-transform: none;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(54px, 1fr));
  gap: 8px;
}

.num {
  aspect-ratio: 1;
  border: 1px solid rgba(var(--ink), 0.12);
  border-radius: 16px;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  transition: background-color 0.2s, color 0.2s, border-color 0.2s, transform 0.2s var(--ease-out);
}

.num:active { transform: scale(0.92); }
.num[aria-selected="true"] { background: var(--fg); color: var(--bg); border-color: var(--fg); }

.grid.is-fresh .num {
  animation: numIn 0.5s var(--ease-out) both;
  animation-delay: calc(min(var(--i), 40) * 12ms);
}

@media (hover: hover) {
  .num:hover { border-color: rgba(var(--ink), 0.5); }
  .book:hover .book__primary { text-decoration: underline; text-underline-offset: 4px; text-decoration-thickness: 1px; }
}

/* ---------- Keyframes ---------- */

@keyframes swapIn {
  from { opacity: 0; transform: translateY(10px); filter: blur(6px); }
  to   { opacity: 1; transform: none; filter: blur(0); }
}

@keyframes numIn {
  from { opacity: 0; transform: translateY(8px) scale(0.96); }
  to   { opacity: 1; transform: none; }
}

@keyframes pop {
  from { opacity: 0; transform: scale(0.9); }
  to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .rise, .sheet__panel, .sheet__scrim, .sheet__track, .tabs__bar, .seg-toggle__thumb { transition: none !important; }
  .ref.is-swap .ref__main, .ref.is-swap .ref__sub, .grid.is-fresh .num, .search__go { animation: none !important; }
  .rise { opacity: 1; transform: none; }
}

/* Tamil sizing inside the finder */
.finder__title:lang(ta) {
  font-size: clamp(22px, 6.4vw, 30px);
  line-height: 1.3;
  letter-spacing: -0.01em;
}

.finder__lede:lang(ta) { line-height: 1.75; }
.ref__main:lang(ta) { letter-spacing: 0; }

/* Light theme: slightly stronger hairlines so cards hold their shape on white */
[data-theme="light"] .finder {
  --line: rgba(0, 0, 0, 0.12);
  --line-strong: rgba(0, 0, 0, 0.24);
  --surface: rgba(0, 0, 0, 0.025);
}

[data-theme="light"] .finder__card { box-shadow: 0 30px 60px -30px rgba(0, 0, 0, 0.18); }
[data-theme="light"] .sheet__panel { border-color: rgba(0, 0, 0, 0.08); }

/* ---------- The chosen verse ---------- */

.passage {
  position: relative;
  margin: -6px 4px 20px;
  padding: 18px 14px 4px;
  border-top: 1px solid var(--line);
  text-align: center;
}

.passage__text {
  font-size: 16px;
  line-height: 1.75;
  color: rgba(var(--ink), 0.88);
  transition: opacity 0.25s ease;
}

.passage__text--en {
  font-size: 15px;
  line-height: 1.6;
  color: var(--muted);
}

.passage__rule {
  display: block;
  width: 24px;
  height: 1px;
  margin: 14px auto;
  background: var(--line-strong);
}

/* Show only what the language mode asks for */
[data-lang-mode="en"] .passage__text[lang="ta"],
[data-lang-mode="ta"] .passage__text--en,
[data-lang-mode="en"] .passage__rule,
[data-lang-mode="ta"] .passage__rule { display: none; }

[data-lang-mode="en"] .passage__text--en {
  font-size: 16px;
  color: rgba(var(--ink), 0.88);
}

.passage__status {
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
}

/* Loading shimmer */
.passage__skeleton {
  position: absolute;
  inset: 18px 14px auto;
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.passage__skeleton i {
  display: block;
  width: 100%;
  height: 10px;
  border-radius: 5px;
  background: linear-gradient(90deg, rgba(var(--ink), 0.06), rgba(var(--ink), 0.14), rgba(var(--ink), 0.06));
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
}

.passage__skeleton i:nth-child(2) { width: 88%; }
.passage__skeleton i:nth-child(3) { width: 56%; }

.passage.is-loading .passage__skeleton { display: flex; }
.passage.is-loading .passage__text,
.passage.is-loading .passage__rule { opacity: 0; }

/* empty while the very first load is in flight: hold some height */
.passage.is-loading { min-height: 64px; }

.passage.is-swap .passage__text { animation: swapIn 0.6s var(--ease-out) both; }
.passage.is-swap .passage__text--en { animation-delay: 0.08s; }

@keyframes shimmer {
  from { background-position: 100% 0; }
  to   { background-position: -100% 0; }
}

@media (prefers-reduced-motion: reduce) {
  .passage__skeleton i, .passage.is-swap .passage__text { animation: none !important; }
}

/* Long verses (e.g. Esther 8:9) are capped so the picker stays in view */
.passage__body {
  position: relative;
  max-height: 13.5rem;
  overflow: hidden;
  transition: max-height 0.5s var(--ease-out);
}

.passage.is-clamped .passage__body {
  -webkit-mask-image: linear-gradient(#000 70%, transparent);
          mask-image: linear-gradient(#000 70%, transparent);
}

.passage.is-expanded .passage__body {
  max-height: 200rem;
  -webkit-mask-image: none;
          mask-image: none;
}

.passage__more {
  display: inline-flex;
  align-items: center;
  height: 34px;
  margin-top: 6px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
  transition: color 0.25s, border-color 0.25s;
}

.passage__more[hidden] { display: none; }

@media (hover: hover) {
  .passage__more:hover { color: var(--fg); border-color: rgba(var(--ink), 0.6); }
}

/* Both languages stacked: allow more height so common verses (John 3:16) show in full */
[data-lang-mode="both"] .passage__body { max-height: 21rem; }

/* ---------- Search inside the verses ---------- */
.search__words {
  display: block;
  min-height: 36px;
  margin: 2px 18px 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-size: 13.5px;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.search__words[hidden] { display: none; }

.finder__card.is-searching .ref,
.finder__card.is-searching .passage,
.finder__card.is-searching .fields,
.finder__card.is-searching .finder__cta { display: none; }

.finder__card .search { flex: none; } /* a long results list must not squash the box */
.vresults { margin-top: 6px; }
.vresults[hidden] { display: none; }
.vresults__note { padding: 4px 18px 10px; font-size: 13.5px; line-height: 1.45; color: var(--muted); }
.vresults__list { max-height: 60vh; margin: 0; padding: 0; overflow-y: auto; list-style: none; overscroll-behavior: contain; }
.vresults__list li + li { border-top: 1px solid rgba(var(--ink), 0.1); }
.vresult { display: block; width: 100%; padding: 12px 18px; border: 0; border-radius: 10px; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.vresult__ref { display: block; margin-bottom: 3px; font-size: 13px; font-weight: 600; }
.vresult__text { display: block; font-size: 15px; line-height: 1.55; color: rgba(var(--ink), 0.82); overflow-wrap: anywhere; }
.vresult mark { padding: 0 1px; border-radius: 3px; background: var(--fg); color: var(--bg); }
.vresults__more { display: block; min-height: 44px; margin: 8px auto 0; padding: 0 18px; border: 1px solid rgba(var(--ink), 0.3); border-radius: 999px; background: none; color: inherit; font: inherit; font-size: 13px; cursor: pointer; }
.vresults__more[hidden] { display: none; }
@media (hover: hover) {
  .vresult:hover { background: rgba(var(--ink), 0.06); }
}
