/* =========================================================================
   Chapter & Worse - the look of the verse finder page only.
   (Colours, fonts, buttons and chips come from theme.css; this file just
   lays out the filters and the passage cards.)

   Layout:
     phones      filters on top (topic chips in one row you can swipe),
                 then the passages, one per row.
     big screens filters in a sidebar on the left that stays put while
                 the passages scroll past on the right.
   ========================================================================= */

/* theme.css gives buttons display:flex, which would beat the "hidden"
   attribute. On this page, hidden always means hidden. */
.page-chapter [hidden] { display: none !important; }

/* ---- Title block, with the page's chibi art ----------------------------- */

.cw-head { padding-block: 28px 20px; }

.cw-art {
  display: block;
  width: clamp(150px, 40vw, 230px);
  height: auto;
  margin: 0 auto 8px;
  filter: drop-shadow(0 0 22px rgba(179, 38, 47, 0.55));
  animation: hover-bob 6s ease-in-out infinite; /* the gentle bob from theme.css */
}

.cw-head .lead { margin-bottom: 0.5em; text-wrap: balance; }
.cw-note {
  margin: 0 auto;
  max-width: 52ch;
  font-size: 0.92rem;
  color: var(--muted);
  text-wrap: balance; /* even line lengths, no lonely last word */
}

/* ---- Two columns on big screens ------------------------------------------ */

.finder {
  display: grid;
  /* minmax(0, ...) = "never wider than the screen". Without it the long row
     of topic chips on phones would stretch the whole page sideways. */
  grid-template-columns: minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}
.filters,
.results { min-width: 0; }

@media (min-width: 960px) {
  .finder { grid-template-columns: 300px minmax(0, 1fr); }
  /* The filters stay on screen while you scroll the passages. If they are
     taller than the window they get their own little scroll bar. */
  .filters {
    position: sticky;
    top: calc(var(--header-h) + 16px);
    max-height: calc(100vh - var(--header-h) - 32px);
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .back-to-search { display: none; } /* the sidebar is always in view */
}

/* ---- The filters ----------------------------------------------------------- */

.filters { padding: 18px; }

/* Fieldsets come with a border and a stubborn minimum width; drop both
   (the minimum width would stop the swipeable chip row from fitting a phone). */
.filters fieldset {
  border: 0;
  margin: 0;
  padding: 0;
  min-width: 0;
}
.cw-controls[disabled] { opacity: 0.6; }

.filters .field { margin-bottom: 18px; }

.field-label {
  display: block;
  margin: 0 0 6px;
  padding: 0;
  font-family: var(--font-display);
  font-size: 1.05rem;
  color: var(--gold);
}

.field-hint {
  margin: 6px 0 0;
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--muted);
}
legend + .field-hint { margin: -2px 0 8px; }

.filters input[type="search"],
.filters select { width: 100%; }

/* Topic chips */
.topic-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.topic-chips .chip {
  font-size: 0.85rem;
  text-align: left;
  line-height: 1.25;
}
.chip-count {
  font-size: 0.85em;
  font-variant-numeric: tabular-nums;
  color: var(--gold);
  opacity: 0.9;
}
.chip[aria-pressed="true"] .chip-count { color: var(--cream); }

/* Old / New / Both: three joined buttons. They are real radio buttons
   underneath (so keyboards and screen readers know how to use them). */
.seg {
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill);
  background: var(--panel-2);
}
.seg label {
  position: relative;
  flex: 1 1 0;
  text-align: center;
  cursor: pointer;
}
.seg input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0;
  padding: 0;
  opacity: 0;
  cursor: pointer;
}
.seg span {
  display: block;
  padding: 9px 8px; /* 9px top and bottom makes each choice 45px tall: thumb-sized */
  border-radius: var(--radius-pill);
  font-family: var(--font-display);
  color: var(--cream);
}
.seg label:hover span { color: var(--gold); }
.seg input:checked + span {
  background: var(--red);
  color: var(--cream);
  box-shadow: 0 0 14px rgba(179, 38, 47, 0.55);
}
.seg input:focus-visible + span {
  outline: 3px solid var(--gold);
  outline-offset: 1px;
}

.field-pair { display: grid; gap: 14px; }

/* A smaller button for inside cards and the filters. */
.btn-small {
  flex-direction: row;
  min-height: 44px; /* still thumb-sized: 44px is the smallest comfortable tap */
  padding: 0.45em 1.05em;
  font-size: 0.98rem;
  box-shadow: none;
}
.btn-small:hover { transform: none; box-shadow: none; }
#cw-clear { width: 100%; }
#cw-clear:disabled { opacity: 0.45; cursor: default; }
#cw-clear:disabled:hover { background: transparent; }

/* Tablets: Book and Who side by side. */
@media (min-width: 480px) and (max-width: 959px) {
  .field-pair { grid-template-columns: 1fr 1fr; }
}

/* Phones: the topic chips become ONE row you swipe sideways (eleven
   wrapped chips would fill the whole screen before the first passage).
   Only the row scrolls - never the page. The fade on the right edge
   hints that there are more. */
@media (max-width: 720px) {
  .filters { padding: 16px; }
  .topic-chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    margin-inline: -16px;
    padding: 2px 16px 8px;
    scroll-padding-inline: 16px;
    scrollbar-width: thin;
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
    mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
  }
  .topic-chips .chip {
    flex: 0 0 auto;
    white-space: nowrap;
  }
  /* Keep the keyboard focus ring inside the row so it isn't cut off. */
  .topic-chips .chip:focus-visible { outline-offset: -3px; }
}

/* ---- Above the passages ---------------------------------------------------- */

.results-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 16px;
  margin-bottom: 12px;
}
.result-count {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.2rem;
  color: var(--cream);
}
.sort-note {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.shared-notice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  margin-bottom: 16px;
  padding: 14px 18px;
  border-color: var(--line-strong);
}
.shared-notice p { margin: 0; }

/* ---- The passage cards ------------------------------------------------------ */

.verse-list {
  display: grid;
  grid-template-columns: minmax(0, 1fr); /* cards never wider than the screen */
  gap: 18px;
  margin: 0;
  padding: 0;
  list-style: none;
}
/* Hold the space while the passages load, so the page doesn't jump. */
.verse-list:empty { min-height: 60vh; }

.verse-card {
  padding: 20px;
  overflow-wrap: break-word;
  /* Lets the browser skip drawing cards that are far off screen -
     keeps scrolling smooth after many "Show more" presses. */
  content-visibility: auto;
  /* Until a card is drawn, guess its HEIGHT only (a guess at its width
     would push the page sideways on phones). */
  contain-intrinsic-block-size: auto 640px;
}
.verse-card:focus { outline: none; }
.verse-card:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }

.verse-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 14px;
  margin-bottom: 8px;
}

/* The reference: always there, big and gold. */
.verse-ref {
  margin: 0;
  font-size: clamp(1.6rem, 5.5vw, 2.15rem);
  color: var(--gold);
  text-shadow: 0 0 18px rgba(179, 38, 47, 0.6);
}

.verse-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}
.verse-deaths {
  padding: 2px 12px;
  border: 1px solid var(--red-hi);
  border-radius: var(--radius-pill);
  background: rgba(142, 27, 34, 0.4);
  color: var(--cream);
}
.verse-deaths strong { font-variant-numeric: tabular-nums; }

.verse-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 10px;
  padding: 0;
  list-style: none;
}
.verse-tags li {
  padding: 2px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill);
  background: rgba(230, 184, 79, 0.08);
  color: var(--gold);
  font-size: 0.78rem;
  line-height: 1.5;
}

.verse-who {
  margin: 0 0 12px;
  font-size: 0.95rem;
}
.verse-who-label { color: var(--muted); }
.verse-who strong { color: var(--cream); }

.verse-label {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--red-text); /* the readable text red from theme.css */
}

.verse-block { margin-bottom: 14px; }
.verse-block .verse-text { margin: 0; }

/* The two Bible texts: side by side when there's room, stacked on phones. */
.versions {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
}
@media (min-width: 720px) {
  .versions { grid-template-columns: 1fr 1fr; }
}
.version {
  margin: 0;
  padding: 14px 16px;
  border-left: 3px solid var(--gold);
  border-radius: 12px;
  background: var(--panel-2);
}
.version figcaption { color: var(--gold); }
.version-text { margin: 0; }
.version-text p {
  margin: 0;
  font-family: Georgia, "Times New Roman", Times, serif;
  font-size: 1.04rem;
  line-height: 1.65;
  color: var(--cream);
}

.verse-defence {
  padding: 12px 14px;
  border: 1px dashed var(--line-strong);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.025);
}
.verse-defence .verse-text { color: var(--muted); }

.verse-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}
.verse-actions .btn-small { flex: 0 1 auto; }

/* Search words lit up in gold. */
.verse-card mark {
  background: rgba(230, 184, 79, 0.3);
  color: inherit;
  border-radius: 3px;
}

/* Nothing found / didn't load. */
.empty-state {
  padding: 28px 20px;
  text-align: center;
}
.empty-state p { margin: 0 0 10px; }
.empty-title {
  font-family: var(--font-display);
  font-size: 1.4rem;
  color: var(--gold);
}

/* ---- Below the passages ------------------------------------------------------ */

.more-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  margin-top: 24px;
}
/* (No "display" here on purpose: the big-screen rule near the top hides this link.)
   It sits in a flex column, so padding + min-height make it a thumb-sized 44px target. */
.back-to-search {
  min-height: 44px;
  padding: 10px 8px;
  font-size: 0.9rem;
}

/* Phones: cards a little tighter, buttons share the row evenly. */
@media (max-width: 480px) {
  .verse-card { padding: 16px; }
  .version { padding: 12px 14px; }
  .verse-actions .btn-small { flex: 1 1 auto; }
  #cw-more { width: 100%; }
}
