/**
 * A Sip of Living Waters - modern interface layer.
 *
 * Everything here is scoped to body[data-ui="modern"], so turning the flag off
 * in the Lab reveals the original v0.1.1 stylesheet underneath, unchanged and
 * complete. Nothing is duplicated: this layer only overrides.
 *
 * It is built entirely from the theme custom properties styles.css already
 * defines, so all 25 themes - including the five animated premium ones -
 * continue to work without any of them being edited.
 *
 * The design intent is a reading instrument, not an application: typography
 * carries the page, chrome recedes until touched, and motion is used only to
 * explain what moved where.
 */

/* ============================================================ design tokens */

body[data-ui="modern"] {
  /* Sitka Text ships with Windows and was drawn by Matthew Carter for reading
     at length on screen; the rest of the stack degrades gracefully. */
  --font-read: "Sitka Text", "Iowan Old Style", "Palatino Linotype", Palatino,
    Georgia, "Times New Roman", serif;
  --font-ui: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "Cascadia Mono", Consolas, "SF Mono", monospace;

  --fs-2xs: clamp(0.62rem, 0.6rem + 0.08vw, 0.68rem);
  --fs-xs: clamp(0.7rem, 0.68rem + 0.1vw, 0.76rem);
  --fs-sm: clamp(0.79rem, 0.76rem + 0.14vw, 0.87rem);
  --fs-base: clamp(0.88rem, 0.85rem + 0.18vw, 0.96rem);
  --fs-lg: clamp(1.02rem, 0.96rem + 0.3vw, 1.16rem);
  --fs-xl: clamp(1.3rem, 1.14rem + 0.7vw, 1.75rem);
  --fs-read: clamp(1.04rem, 0.97rem + 0.4vw, 1.26rem);

  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 22px;
  --s6: 30px;
  --s7: 44px;
  --s8: 64px;

  --r-sm: 9px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 28px;
  --r-pill: 999px;

  /* Layered rather than single-blur shadows: closer to how light actually
     falls, and far less muddy on the dark themes. */
  --sh-1: 0 1px 2px rgba(0, 0, 0, 0.05), 0 2px 8px rgba(0, 0, 0, 0.04);
  --sh-2: 0 2px 6px rgba(0, 0, 0, 0.07), 0 12px 28px rgba(0, 0, 0, 0.08);
  --sh-3: 0 10px 26px rgba(0, 0, 0, 0.12), 0 34px 72px rgba(0, 0, 0, 0.16);

  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --dur-1: 130ms;
  --dur-2: 240ms;
  --dur-3: 420ms;

  --edge: color-mix(in srgb, var(--line) 62%, transparent);
  --edge-strong: color-mix(in srgb, var(--ink) 12%, transparent);
  --raise: color-mix(in srgb, var(--ink) 4%, transparent);
  --accent: var(--sage-dark);
  --accent-soft: color-mix(in srgb, var(--accent) 22%, transparent);

  /* Text drawn on top of --accent.
     In the light themes --sage-dark is a deep green, so white reads well. In
     the dark themes styles.css redefines --sage-dark as a *light* accent while
     leaving --primary-text white, which would put white on mint. The dark
     block below flips this to the page colour instead. */
  --accent-ink: #ffffff;

  /* Solid fills carrying text get a slightly deepened accent, because a few of
     the lighter themes (Morning Manna's olive, for one) fall just under 4.5:1
     against white otherwise. The dark themes override this back to the plain
     accent, where the ink is dark and deepening would hurt instead. */
  --accent-solid: color-mix(in srgb, var(--accent) 87%, #000);

  font-family: var(--font-ui);
  font-size: var(--fs-base);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* The dark themes, matching the grouping styles.css already uses. Their
   --sage-dark is a light accent, so anything sitting on it needs dark text. */
body[data-ui="modern"][data-theme="candlelight"],
body[data-ui="modern"][data-theme="river-night"],
body[data-ui="modern"][data-theme="midnight-psalm"],
body[data-ui="modern"][data-theme="olive-grove"],
body[data-ui="modern"][data-theme="royal-plum"],
body[data-ui="modern"][data-theme="bethlehem-night"],
body[data-ui="modern"][data-theme="temple-veil"],
body[data-ui="modern"][data-theme="red-sea-dusk"],
body[data-ui="modern"][data-theme="premium-living-river"],
body[data-ui="modern"][data-theme="premium-burning-bush"],
body[data-ui="modern"][data-theme="premium-stained-glass"],
body[data-ui="modern"][data-theme="premium-celestial-scroll"],
body[data-ui="modern"][data-theme="premium-desert-stars"] {
  --accent-ink: var(--page);
  --accent-solid: var(--accent);
  --edge: color-mix(in srgb, var(--line) 82%, transparent);
  --edge-strong: color-mix(in srgb, var(--ink) 26%, transparent);
  --raise: color-mix(in srgb, var(--ink) 8%, transparent);
  /* Shadows have to be much deeper to register against a dark ground. */
  --sh-1: 0 1px 2px rgba(0, 0, 0, 0.3), 0 2px 8px rgba(0, 0, 0, 0.24);
  --sh-2: 0 2px 6px rgba(0, 0, 0, 0.34), 0 12px 28px rgba(0, 0, 0, 0.32);
  --sh-3: 0 10px 26px rgba(0, 0, 0, 0.44), 0 34px 72px rgba(0, 0, 0, 0.5);
}

body[data-ui="modern"] * {
  scrollbar-width: thin;
  scrollbar-color: var(--edge) transparent;
}

body[data-ui="modern"] *::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

body[data-ui="modern"] *::-webkit-scrollbar-thumb {
  background: var(--edge);
  border-radius: var(--r-pill);
  border: 3px solid transparent;
  background-clip: content-box;
}

body[data-ui="modern"] *::-webkit-scrollbar-thumb:hover {
  background: var(--edge-strong);
  background-clip: content-box;
}

body[data-ui="modern"] *::-webkit-scrollbar-track {
  background: transparent;
}

/* ==================================================================== shell */

body[data-ui="modern"] {
  /* One source of truth for the shell inset, so the panel heights below can
     fill the viewport exactly instead of overflowing it by a few pixels. */
  --shell-pad: var(--s4);
  --shell-h: calc(100vh - (var(--shell-pad) * 2));
}

/* The page itself never scrolls. Anything that does not fit becomes a page
   turn, a tab, or its own scroll region inside a panel. */
html:has(body[data-ui="modern"]),
body[data-ui="modern"] {
  height: 100%;
  overflow: hidden;
}

body[data-ui="modern"] .app-shell {
  grid-template-columns: minmax(232px, 268px) minmax(460px, 1fr) minmax(300px, 348px);
  gap: var(--s4);
  padding: var(--shell-pad);
  align-items: stretch;
  height: 100vh;
  min-height: 0;
}

body[data-ui="modern"] .library-panel,
body[data-ui="modern"] .control-panel,
body[data-ui="modern"] .reader-panel {
  background: var(--surface-glass);
  border: 1px solid var(--edge);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-2);
  backdrop-filter: blur(18px) saturate(1.25);
  -webkit-backdrop-filter: blur(18px) saturate(1.25);
  transition: box-shadow var(--dur-2) var(--ease), transform var(--dur-2) var(--ease);
}

body[data-ui="modern"] .library-panel,
body[data-ui="modern"] .control-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  padding: var(--s5) var(--s4);
}

/* Only the results list and the active tab body may scroll, and only when
   their own content genuinely exceeds the panel. */
body[data-ui="modern"] .search-results {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* A fixed height rather than a minimum: the reading surface scrolls inside
   the panel, which is what keeps the header, its progress bar and the
   controls all fixed while the text moves. */
body[data-ui="modern"] .reader-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  padding: 0;
  overflow: hidden;
}

/* ================================================================== branding */

body[data-ui="modern"] .brand-lockup {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding-bottom: var(--s4);
  margin-bottom: var(--s4);
  border-bottom: 1px solid var(--edge);
}

body[data-ui="modern"] .brand-mark {
  width: 42px;
  height: 42px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: var(--r-md);
  background: linear-gradient(150deg, var(--accent-solid), var(--water));
  color: var(--accent-ink);
  font-weight: 700;
  font-size: var(--fs-sm);
  letter-spacing: 0.06em;
  box-shadow: var(--sh-1), inset 0 1px 0 rgba(255, 255, 255, 0.22);
}

body[data-ui="modern"] .eyebrow {
  font-size: var(--fs-2xs);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 700;
  color: var(--muted);
  margin: 0 0 2px;
}

body[data-ui="modern"] .brand-lockup h1 {
  font-family: var(--font-read);
  font-size: var(--fs-lg);
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
  line-height: 1.2;
}

/* ============================================================ reader surface */

body[data-ui="modern"] .reader-header {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--s4);
  padding: var(--s5) var(--s6) var(--s4);
  background: linear-gradient(
    to bottom,
    var(--surface-glass) 62%,
    color-mix(in srgb, var(--surface-glass) 40%, transparent)
  );
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--edge);
}

body[data-ui="modern"] #passage-title {
  font-family: var(--font-read);
  font-size: var(--fs-xl);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.05;
  margin: 0;
}

body[data-ui="modern"] .chapter-actions {
  display: flex;
  gap: var(--s2);
  flex: none;
}

body[data-ui="modern"] .reader-surface {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  padding: var(--s5) var(--s6) var(--s4);
  scroll-behavior: smooth;
}

/* Columns exactly one viewport wide. column-width and the stride are set by
   the pager; the gap doubles as the margin between one page and the next. */
body[data-ui="modern"] .lw-page-flow {
  height: 100%;
  column-fill: auto;
}

/* Only individual verses resist being split. Putting this on the flow's
   direct children would tell the whole .verses block not to fragment, which
   collapses the pagination entirely. */
body[data-ui="modern"] .verse-card {
  break-inside: avoid;
}

body[data-ui="modern"] .chapter-intro {
  break-after: avoid;
}

/* Without the pager the surface simply scrolls, as it always did. */
body[data-ui="modern"]:not(.lw-paged) .reader-surface {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: var(--s7);
}

body[data-ui="modern"] .chapter-intro {
  font-family: var(--font-read);
  font-size: var(--fs-sm);
  font-style: italic;
  color: var(--muted);
  text-align: center;
  max-width: 62ch;
  margin: 0 auto var(--s6);
  padding-bottom: var(--s5);
  border-bottom: 1px solid var(--edge);
  letter-spacing: 0.01em;
}

body[data-ui="modern"] .verses {
  max-width: none;
  margin: 0;
  padding-left: 0;
}

/* Centred inside whichever column it lands in, rather than inside the flow -
   padding on a multi-column box applies once, not per column, so the gutter
   for the hanging verse numbers has to live on each card. */
body[data-ui="modern"] .verse-card,
body[data-ui="modern"] .chapter-intro,
body[data-ui="modern"] .loading-state,
body[data-ui="modern"] .empty-state,
body[data-ui="modern"] .error-state {
  max-width: 64ch;
  margin-inline: auto;
}

/* Verses stop being cards and become typeset text, with the number hanging in
   the margin the way it does in a printed Bible. */
body[data-ui="modern"] .verse-card {
  position: relative;
  display: block;
  background: none;
  border: none;
  border-radius: var(--r-sm);
  box-shadow: none;
  padding: var(--s2) var(--s3) var(--s2) 38px;
  margin: 0 auto var(--s1);
  transition: background var(--dur-2) var(--ease);
  cursor: pointer;
}

body[data-ui="modern"] .verse-card::before {
  content: "";
  position: absolute;
  left: 32px;
  top: 8px;
  bottom: 8px;
  width: 2px;
  border-radius: var(--r-pill);
  background: var(--accent);
  opacity: 0;
  transform: scaleY(0.4);
  transition: opacity var(--dur-2) var(--ease), transform var(--dur-2) var(--ease-out);
}

body[data-ui="modern"] .verse-card:hover {
  background: color-mix(in srgb, var(--ink) 3.5%, transparent);
}

body[data-ui="modern"] .verse-card.active {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

body[data-ui="modern"] .verse-card.active::before {
  opacity: 0.85;
  transform: scaleY(1);
}

body[data-ui="modern"] .verse-number {
  position: absolute;
  left: 0;
  top: 0.66em;
  width: 26px;
  text-align: right;
  font-family: var(--font-ui);
  font-size: var(--fs-2xs);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--muted);
  opacity: 0.5;
  background: none;
  padding: 0;
  transition: opacity var(--dur-2) var(--ease), color var(--dur-2) var(--ease);
}

body[data-ui="modern"] .verse-card:hover .verse-number,
body[data-ui="modern"] .verse-card.active .verse-number {
  opacity: 1;
  color: var(--accent);
}

body[data-ui="modern"] .verse-text {
  font-family: var(--font-read);
  font-size: calc(var(--fs-read) * var(--read-scale, 1));
  line-height: 1.78;
  letter-spacing: 0.005em;
  color: var(--ink);
  display: block;
}

/* The spoken word. Kept as a soft shape rather than a hard block so it reads
   as emphasis rather than as a selection. */
body[data-ui="modern"] .word-token {
  border-radius: 4px;
  padding: 0.06em 0.1em;
  margin: 0 -0.1em;
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
}

body[data-ui="modern"] .word-current {
  background: var(--word-highlight);
  color: var(--ink);
  box-shadow: 0 1px 0 var(--highlight-strong);
}

body[data-ui="modern"] .loading-state {
  max-width: 68ch;
  margin: 0 auto;
  display: grid;
  gap: var(--s3);
}

body[data-ui="modern"] .loading-line {
  height: 14px;
  border-radius: var(--r-pill);
  background: linear-gradient(
    90deg,
    var(--raise) 25%,
    color-mix(in srgb, var(--ink) 8%, transparent) 37%,
    var(--raise) 63%
  );
  background-size: 400% 100%;
  animation: lw-shimmer 1.6s ease-in-out infinite;
}

@keyframes lw-shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: 0 0; }
}

body[data-ui="modern"] .empty-state,
body[data-ui="modern"] .error-state {
  max-width: 52ch;
  margin: var(--s7) auto;
  text-align: center;
  color: var(--muted);
  font-size: var(--fs-sm);
  line-height: 1.6;
  padding: var(--s5);
  border: 1px dashed var(--edge);
  border-radius: var(--r-md);
}

/* ================================================================= controls */

body[data-ui="modern"] .control-section {
  padding: 0 0 var(--s5);
  margin-bottom: var(--s5);
  border-bottom: 1px solid var(--edge);
  background: none;
  border-radius: 0;
  box-shadow: none;
}

body[data-ui="modern"] .control-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: var(--s2);
}

body[data-ui="modern"] .section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s2);
  margin-bottom: var(--s3);
}

body[data-ui="modern"] .section-heading h3 {
  font-size: var(--fs-2xs);
  text-transform: uppercase;
  letter-spacing: 0.13em;
  font-weight: 700;
  color: var(--muted);
  margin: 0;
}

body[data-ui="modern"] .section-heading > span {
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: var(--raise);
  border-radius: var(--r-pill);
  padding: 2px 9px;
  font-weight: 600;
}

body[data-ui="modern"] label {
  display: block;
  font-size: var(--fs-xs);
  color: var(--muted);
  margin-bottom: var(--s3);
}

body[data-ui="modern"] label > span:first-child {
  display: block;
  margin-bottom: 5px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

body[data-ui="modern"] select,
body[data-ui="modern"] input[type="search"],
body[data-ui="modern"] input[type="number"],
body[data-ui="modern"] input[type="text"] {
  width: 100%;
  font: inherit;
  font-size: var(--fs-sm);
  color: var(--ink);
  background: var(--field);
  border: 1px solid var(--edge);
  border-radius: var(--r-sm);
  padding: 9px 11px;
  transition: border-color var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease);
  appearance: none;
}

body[data-ui="modern"] select {
  /* A chevron drawn inline, so no icon font or image file is needed. */
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) center, calc(100% - 10px) center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 30px;
  cursor: pointer;
}

body[data-ui="modern"] select:hover,
body[data-ui="modern"] input:hover {
  border-color: var(--edge-strong);
}

body[data-ui="modern"] select:focus-visible,
body[data-ui="modern"] input:focus-visible,
body[data-ui="modern"] textarea:focus-visible,
body[data-ui="modern"] button:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus);
}

/* Buttons ---------------------------------------------------------------- */

body[data-ui="modern"] button {
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--ink);
  background: var(--button-bg);
  border: 1px solid var(--edge);
  border-radius: var(--r-sm);
  padding: 9px 14px;
  cursor: pointer;
  transition: background var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease),
    transform var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease);
}

body[data-ui="modern"] button:hover:not(:disabled) {
  border-color: var(--edge-strong);
  background: color-mix(in srgb, var(--button-bg) 88%, var(--ink));
  transform: translateY(-1px);
  box-shadow: var(--sh-1);
}

body[data-ui="modern"] button:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: none;
}

body[data-ui="modern"] button:disabled {
  opacity: 0.4;
  cursor: default;
}

body[data-ui="modern"] .primary-button {
  background: var(--accent-solid);
  border-color: transparent;
  color: var(--accent-ink);
  box-shadow: var(--sh-1);
}

body[data-ui="modern"] .primary-button:hover:not(:disabled) {
  background: var(--accent-solid);
  filter: brightness(1.1);
  box-shadow: var(--sh-2);
}

body[data-ui="modern"] .button-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--s2);
  margin-bottom: var(--s3);
}

body[data-ui="modern"] .button-grid.two-buttons {
  grid-template-columns: repeat(2, 1fr);
}

/* Toggle switches -------------------------------------------------------- */

body[data-ui="modern"] .toggle-row {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: 7px 0;
  margin-bottom: 0;
  color: var(--ink);
  font-size: var(--fs-sm);
  cursor: pointer;
  user-select: none;
}

body[data-ui="modern"] .toggle-row > span {
  flex: 1;
  font-weight: 500;
  color: var(--ink);
}

body[data-ui="modern"] .toggle-row input[type="checkbox"],
body[data-ui="modern"] .lw-flag-top input[type="checkbox"] {
  appearance: none;
  flex: none;
  position: relative;
  width: 34px;
  height: 20px;
  margin: 0;
  border-radius: var(--r-pill);
  background: color-mix(in srgb, var(--ink) 16%, transparent);
  border: none;
  cursor: pointer;
  transition: background var(--dur-2) var(--ease);
}

body[data-ui="modern"] .toggle-row input[type="checkbox"]::after,
body[data-ui="modern"] .lw-flag-top input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--sh-1);
  transition: transform var(--dur-2) var(--ease-out);
}

body[data-ui="modern"] .toggle-row input[type="checkbox"]:checked,
body[data-ui="modern"] .lw-flag-top input[type="checkbox"]:checked {
  background: var(--accent);
}

body[data-ui="modern"] .toggle-row input[type="checkbox"]:checked::after,
body[data-ui="modern"] .lw-flag-top input[type="checkbox"]:checked::after {
  transform: translateX(14px);
}

body[data-ui="modern"] .toggle-row input[type="checkbox"]:disabled {
  opacity: 0.4;
  cursor: default;
}

body[data-ui="modern"] .indented-toggle {
  margin-left: var(--s5);
}

/* Sliders ---------------------------------------------------------------- */

body[data-ui="modern"] .range-label {
  margin-bottom: var(--s4);
}

body[data-ui="modern"] .range-label > span:first-child {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s2);
}

body[data-ui="modern"] output {
  font-variant-numeric: tabular-nums;
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--accent);
}

body[data-ui="modern"] input[type="range"] {
  appearance: none;
  width: 100%;
  height: 22px;
  background: none;
  cursor: pointer;
  margin: 0;
}

body[data-ui="modern"] input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: var(--r-pill);
  background: color-mix(in srgb, var(--ink) 13%, transparent);
}

body[data-ui="modern"] input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 15px;
  height: 15px;
  margin-top: -5.5px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--accent);
  box-shadow: var(--sh-1);
  transition: transform var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease);
}

body[data-ui="modern"] input[type="range"]:hover::-webkit-slider-thumb {
  transform: scale(1.18);
}

body[data-ui="modern"] input[type="range"]:active::-webkit-slider-thumb {
  transform: scale(1.05);
  box-shadow: 0 0 0 6px var(--focus);
}

/* ============================================================ picker/search */

body[data-ui="modern"] .scripture-picker {
  display: grid;
  grid-template-columns: 1fr 84px;
  gap: var(--s2);
  align-items: end;
  margin-bottom: var(--s4);
}

body[data-ui="modern"] .scripture-picker .primary-button {
  grid-column: 1 / -1;
}

body[data-ui="modern"] .search-box {
  margin-bottom: var(--s4);
}

body[data-ui="modern"] .search-box > label {
  font-size: var(--fs-2xs);
  text-transform: uppercase;
  letter-spacing: 0.13em;
  font-weight: 700;
  margin-bottom: var(--s2);
}

body[data-ui="modern"] .search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--s2);
}

body[data-ui="modern"] .search-results {
  display: grid;
  gap: var(--s1);
}

body[data-ui="modern"] .result-button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  padding: var(--s3);
  transition: background var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease);
}

body[data-ui="modern"] .result-button:hover {
  background: var(--raise);
  border-color: var(--edge);
  transform: none;
  box-shadow: none;
}

body[data-ui="modern"] .result-ref {
  display: block;
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.02em;
  margin-bottom: 3px;
}

body[data-ui="modern"] .result-text {
  display: block;
  font-family: var(--font-read);
  font-size: var(--fs-sm);
  line-height: 1.55;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ============================================================== theme picker */

body[data-ui="modern"] .theme-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--s2);
  margin-top: var(--s3);
}

body[data-ui="modern"] .theme-choice {
  display: flex;
  flex-direction: column;
  gap: 7px;
  align-items: flex-start;
  padding: var(--s3);
  border-radius: var(--r-md);
  border: 1px solid var(--edge);
  background: var(--surface-soft);
  text-align: left;
  transition: border-color var(--dur-1) var(--ease), transform var(--dur-1) var(--ease),
    box-shadow var(--dur-1) var(--ease);
}

body[data-ui="modern"] .theme-choice:hover {
  transform: translateY(-2px);
  box-shadow: var(--sh-2);
}

body[data-ui="modern"] .theme-choice.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

body[data-ui="modern"] .theme-choice-name {
  font-size: var(--fs-2xs);
  font-weight: 600;
  line-height: 1.25;
  color: var(--ink);
}

body[data-ui="modern"] .theme-swatches {
  display: flex;
  gap: 3px;
  width: 100%;
}

body[data-ui="modern"] .theme-swatches span {
  flex: 1;
  height: 16px;
  border-radius: 4px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}

body[data-ui="modern"] .premium-tag {
  display: inline-block;
  font-size: 8.5px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-weight: 800;
  color: var(--gold);
  border: 1px solid var(--gold);
  border-radius: var(--r-pill);
  padding: 1px 5px;
  margin-left: 4px;
  vertical-align: 1px;
}

/* ========================================================= injected chrome */

body[data-ui="modern"] .lw-icon-button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: var(--r-sm);
  background: none;
  border: 1px solid transparent;
  color: var(--muted);
}

body[data-ui="modern"] .lw-icon-button:hover:not(:disabled) {
  background: var(--raise);
  border-color: var(--edge);
  color: var(--ink);
}

body[data-ui="modern"] .lw-icon-button svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Reading progress ------------------------------------------------------- */

body[data-ui="modern"] .lw-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  background: none;
  overflow: hidden;
  pointer-events: none;
}

body[data-ui="modern"] .lw-progress span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--water));
  transition: width 90ms linear;
}

/* Collapsible sections --------------------------------------------------- */

body[data-ui="modern"] .section-heading[data-collapsible] {
  cursor: pointer;
  border-radius: var(--r-sm);
  padding: 3px 5px;
  margin-left: -5px;
  margin-right: -5px;
  transition: background var(--dur-1) var(--ease);
}

body[data-ui="modern"] .section-heading[data-collapsible]:hover {
  background: var(--raise);
}

body[data-ui="modern"] .lw-chevron {
  width: 13px;
  height: 13px;
  flex: none;
  color: var(--muted);
  transition: transform var(--dur-2) var(--ease);
}

body[data-ui="modern"] .control-section.lw-collapsed .lw-chevron {
  transform: rotate(-90deg);
}

body[data-ui="modern"] .control-section.lw-collapsed > *:not(.section-heading) {
  display: none;
}

body[data-ui="modern"] .control-section.lw-collapsed {
  padding-bottom: var(--s3);
}

/* Command palette --------------------------------------------------------- */

body[data-ui="modern"] .lw-palette-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: color-mix(in srgb, var(--page) 55%, rgba(0, 0, 0, 0.45));
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: grid;
  place-items: start center;
  padding-top: 14vh;
  animation: lw-fade var(--dur-2) var(--ease);
}

body[data-ui="modern"] .lw-palette {
  width: min(620px, calc(100vw - 32px));
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-3);
  overflow: hidden;
  animation: lw-rise var(--dur-3) var(--ease-out);
}

body[data-ui="modern"] .lw-palette-input {
  width: 100%;
  border: none;
  border-bottom: 1px solid var(--edge);
  border-radius: 0;
  background: none;
  padding: var(--s4) var(--s5);
  font-size: var(--fs-lg);
  font-family: var(--font-read);
  color: var(--ink);
}

body[data-ui="modern"] .lw-palette-input:focus-visible {
  outline: none;
  box-shadow: none;
  border-color: var(--edge);
}

body[data-ui="modern"] .lw-palette-list {
  max-height: min(46vh, 420px);
  overflow-y: auto;
  padding: var(--s2);
}

body[data-ui="modern"] .lw-palette-group {
  font-size: var(--fs-2xs);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 700;
  color: var(--muted);
  padding: var(--s3) var(--s3) var(--s1);
}

body[data-ui="modern"] .lw-palette-item {
  display: flex;
  align-items: center;
  gap: var(--s3);
  width: 100%;
  text-align: left;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  padding: 9px var(--s3);
  font-size: var(--fs-sm);
  color: var(--ink);
}

body[data-ui="modern"] .lw-palette-item:hover,
body[data-ui="modern"] .lw-palette-item.lw-selected {
  background: var(--raise);
  border-color: var(--edge);
  transform: none;
  box-shadow: none;
}

body[data-ui="modern"] .lw-palette-item.lw-selected {
  border-color: var(--accent);
}

body[data-ui="modern"] .lw-palette-item b {
  font-weight: 600;
  flex: 1;
}

body[data-ui="modern"] .lw-palette-item small {
  color: var(--muted);
  font-size: var(--fs-xs);
  font-family: var(--font-read);
  max-width: 46%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body[data-ui="modern"] .lw-palette-empty {
  padding: var(--s6) var(--s4);
  text-align: center;
  color: var(--muted);
  font-size: var(--fs-sm);
}

body[data-ui="modern"] .lw-palette-footer {
  display: flex;
  gap: var(--s4);
  padding: var(--s3) var(--s5);
  border-top: 1px solid var(--edge);
  font-size: var(--fs-2xs);
  color: var(--muted);
}

body[data-ui="modern"] kbd {
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 700;
  background: var(--raise);
  border: 1px solid var(--edge);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 5px;
  margin: 0 2px;
  color: var(--ink);
}

@keyframes lw-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes lw-rise {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

/* ================================================================ focus mode */

body[data-ui="modern"].lw-focus .library-panel,
body[data-ui="modern"].lw-focus .control-panel {
  display: none;
}

body[data-ui="modern"].lw-focus .app-shell {
  grid-template-columns: minmax(0, 1fr);
  max-width: 1080px;
  margin: 0 auto;
  padding: var(--s4) var(--s5);
}

body[data-ui="modern"].lw-focus .reader-panel {
  border: none;
  background: none;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

body[data-ui="modern"].lw-focus .reader-header {
  background: none;
  border-bottom-color: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

body[data-ui="modern"].lw-focus .verses {
  max-width: 66ch;
}

body[data-ui="modern"].lw-focus .reader-surface {
  padding-top: var(--s5);
}

/* ================================================================= overlays */

body[data-ui="modern"] .lw-overlay {
  background: var(--surface-glass);
  backdrop-filter: blur(22px) saturate(1.2);
  -webkit-backdrop-filter: blur(22px) saturate(1.2);
  padding: var(--s7) var(--s6) var(--s8);
  animation: lw-fade var(--dur-2) var(--ease);
}

body[data-ui="modern"] .lw-overlay h2 {
  font-family: var(--font-read);
  font-size: var(--fs-xl);
  font-weight: 600;
  letter-spacing: -0.02em;
  max-width: 880px;
  margin: 0 auto var(--s3);
}

body[data-ui="modern"] .lw-overlay > *:not(h2) {
  max-width: 880px;
  margin-left: auto;
  margin-right: auto;
}

body[data-ui="modern"] .lw-overlay table {
  border-radius: var(--r-md);
  overflow: hidden;
  border: 1px solid var(--edge);
}

body[data-ui="modern"] .lw-overlay th {
  background: var(--raise);
}

body[data-ui="modern"] .lw-overlay th,
body[data-ui="modern"] .lw-overlay td {
  border-bottom: 1px solid var(--edge);
}

/* Lab + Library panels ---------------------------------------------------- */

body[data-ui="modern"] .lw-flag {
  border-bottom: 1px solid var(--edge);
  padding: var(--s3) 0;
}

body[data-ui="modern"] .lw-badge {
  border-radius: var(--r-pill);
  border-color: var(--edge);
  font-size: 9px;
  padding: 2px 7px;
}

body[data-ui="modern"] .lw-count {
  border-radius: var(--r-md);
  border-color: var(--edge);
  padding: var(--s3) var(--s2);
  transition: transform var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease);
}

body[data-ui="modern"] .lw-count:hover {
  transform: translateY(-2px);
  box-shadow: var(--sh-1);
}

body[data-ui="modern"] .lw-count b {
  font-family: var(--font-read);
  font-size: 20px;
  font-weight: 600;
}

body[data-ui="modern"] .lw-plan {
  border-radius: var(--r-md);
  border-color: var(--edge);
  background: var(--surface-soft);
}

body[data-ui="modern"] .lw-bar {
  height: 4px;
  background: color-mix(in srgb, var(--ink) 12%, transparent);
}

body[data-ui="modern"] .lw-bar span {
  background: linear-gradient(90deg, var(--accent), var(--water));
  transition: width var(--dur-3) var(--ease-out);
}

body[data-ui="modern"] .lw-panic {
  border-radius: var(--r-sm);
  background: color-mix(in srgb, var(--gold) 12%, transparent);
}

body[data-ui="modern"] .lw-verse-menu {
  border-radius: var(--r-md);
  box-shadow: var(--sh-3);
  animation: lw-rise var(--dur-2) var(--ease-out);
}

/* ============================================================== responsive */

/* Narrower than three comfortable columns, the side panels become drawers
   rather than stacking - stacking would reintroduce the scrolling this layout
   exists to remove. */
@media (max-width: 1180px) {
  body[data-ui="modern"] .app-shell {
    grid-template-columns: minmax(216px, 250px) minmax(0, 1fr);
  }
  body[data-ui="modern"] .control-panel {
    position: fixed;
    top: var(--shell-pad);
    right: var(--shell-pad);
    bottom: var(--shell-pad);
    width: min(340px, calc(100vw - 32px));
    z-index: 60;
    transform: translateX(calc(100% + var(--shell-pad)));
    transition: transform var(--dur-3) var(--ease-out);
    box-shadow: var(--sh-3);
  }
  body[data-ui="modern"].lw-drawer-open .control-panel {
    transform: none;
  }
  body[data-ui="modern"] .lw-drawer-toggle {
    display: grid;
  }
}

@media (max-width: 820px) {
  body[data-ui="modern"] .app-shell {
    grid-template-columns: minmax(0, 1fr);
  }
  body[data-ui="modern"] .library-panel {
    position: fixed;
    top: var(--shell-pad);
    left: var(--shell-pad);
    bottom: var(--shell-pad);
    width: min(300px, calc(100vw - 32px));
    z-index: 60;
    transform: translateX(calc(-100% - var(--shell-pad)));
    transition: transform var(--dur-3) var(--ease-out);
    box-shadow: var(--sh-3);
  }
  body[data-ui="modern"].lw-library-open .library-panel {
    transform: none;
  }
  body[data-ui="modern"] .lw-library-toggle {
    display: grid;
  }
  body[data-ui="modern"] .reader-surface,
  body[data-ui="modern"] .reader-header {
    padding-left: var(--s4);
    padding-right: var(--s4);
  }
}

/* Scrim behind an open drawer. */
body[data-ui="modern"] .lw-scrim {
  position: fixed;
  inset: 0;
  z-index: 55;
  background: color-mix(in srgb, var(--page) 40%, rgba(0, 0, 0, 0.4));
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: lw-fade var(--dur-2) var(--ease);
}

body[data-ui="modern"] .lw-drawer-toggle,
body[data-ui="modern"] .lw-library-toggle {
  display: none;
}

/* ================================================================== motion */

@media (prefers-reduced-motion: reduce) {
  body[data-ui="modern"],
  body[data-ui="modern"] * {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* =============================================================== page turning */

body[data-ui="modern"] .lw-pager {
  flex: none;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: var(--s3);
  padding: var(--s3) var(--s5);
  border-top: 1px solid var(--edge);
  background: color-mix(in srgb, var(--surface) 55%, transparent);
}

body[data-ui="modern"] .lw-page-arrow {
  display: grid;
  place-items: center;
  width: 44px;
  height: 40px;
  padding: 0;
  border-radius: var(--r-md);
  background: var(--raise);
  border: 1px solid var(--edge);
  color: var(--ink);
}

body[data-ui="modern"] .lw-page-arrow svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

body[data-ui="modern"] .lw-page-arrow:hover:not(:disabled) {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-ink);
  transform: none;
}

body[data-ui="modern"] .lw-page-arrow:disabled {
  opacity: 0.22;
}

body[data-ui="modern"] .lw-page-middle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s4);
}

body[data-ui="modern"] .lw-page-label {
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--muted);
  min-width: 84px;
  text-align: center;
}

body[data-ui="modern"] .lw-size {
  display: flex;
  align-items: baseline;
  gap: 1px;
  padding: 5px 10px;
  border-radius: var(--r-pill);
  background: none;
  border: 1px solid var(--edge);
  color: var(--muted);
  font-family: var(--font-read);
  font-size: 14px;
  line-height: 1;
}

body[data-ui="modern"] .lw-size span {
  font-size: 10px;
  font-weight: 700;
}

body[data-ui="modern"] .lw-size:hover {
  color: var(--ink);
  border-color: var(--edge-strong);
}

/* ====================================================================== tabs */

body[data-ui="modern"] .lw-tabs {
  flex: none;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 2px;
  padding: 3px;
  margin-bottom: var(--s4);
  border-radius: var(--r-md);
  background: var(--raise);
  border: 1px solid var(--edge);
}

body[data-ui="modern"] .lw-tab {
  padding: 7px 4px;
  border: none;
  border-radius: calc(var(--r-md) - 4px);
  background: none;
  color: var(--muted);
  font-size: var(--fs-2xs);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
}

body[data-ui="modern"] .lw-tab:hover {
  color: var(--ink);
  background: none;
  transform: none;
  box-shadow: none;
}

body[data-ui="modern"] .lw-tab-active,
body[data-ui="modern"] .lw-tab-active:hover {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--sh-1);
}

/* The active tab owns the rest of the panel and scrolls only if its own
   content genuinely cannot fit. */
body[data-ui="modern"] .control-panel .control-section:not([hidden]) {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: var(--s3);
  padding-right: 2px;
}

body[data-ui="modern"] .control-panel .control-section[hidden] {
  display: none;
}

/* Two tabs can share a screen when both are short, so keep the divider. */
body[data-ui="modern"] .control-panel .control-section:not([hidden]) + .control-section:not([hidden]) {
  border-top: 1px solid var(--edge);
  padding-top: var(--s4);
  margin-top: var(--s2);
  flex: none;
  overflow: visible;
}

/* ============================================================ compact library */

body[data-ui="modern"] .library-panel .scripture-picker,
body[data-ui="modern"] .library-panel .search-box {
  flex: none;
}

body[data-ui="modern"] .theme-grid {
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

body[data-ui="modern"] .theme-choice {
  padding: 7px;
  gap: 5px;
}

body[data-ui="modern"] .theme-swatches span {
  height: 12px;
}
