/* Colors from the official SDA logo: green #004c3f, gold #f9a825 */
:root {
  --bg: #02241d;
  --bg-2: #004c3f;
  --surface: #073a30;
  --surface-press: #0e4d40;
  --line: #1a5a4b;
  --text: #f6f1e4;
  --muted: #a6c2b8;
  --accent: #f9a825;
  --accent-ink: #1f1500;
  --logo: #ffffff;
  --hit: 64px;
  --radius: 18px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f2e9;
    --bg-2: #dfece6;
    --surface: #ffffff;
    --surface-press: #e8f1ec;
    --line: #d2e0d9;
    --text: #0f2620;
    --muted: #586f66;
    --accent: #004c3f;
    --accent-ink: #ffffff;
    --logo: #004c3f; /* white would vanish on the light background */
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
/* Stop iPhone browsers from enlarging text on their own (mainly in landscape):
   the presenter sizes lyrics itself, and autosizing made them overflow the screen. */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  background: radial-gradient(120% 70% at 50% 0%, var(--bg-2), var(--bg) 70%) fixed, var(--bg);
  color: var(--text);
  font: 18px/1.4 var(--sans);
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; touch-action: manipulation; }

/* ---------- Home ---------- */
.home {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: max(28px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.brand { text-align: center; padding-top: 3vh; }
/* Church logo, traced to a one-colour SVG (assets/sda-logo.svg): white on green, green on light */
.logo { display: block; width: clamp(84px, 24vw, 120px); height: auto; margin: 0 auto 16px; color: var(--logo); }

/* Credit under the title: small caps between two thin gold rules */
.credit {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  margin: 14px 0 0; color: var(--muted);
  font-size: 11px; letter-spacing: .2em; text-transform: uppercase;
}
.credit strong { color: var(--text); font-weight: 600; }
.credit .rule { width: 28px; height: 1px; background: var(--accent); opacity: .6; }
.eyebrow { margin: 0; color: var(--accent); letter-spacing: .18em; text-transform: uppercase; font-size: 13px; font-weight: 600; }
.brand h1 { margin: 4px 0 0; font: 600 clamp(44px, 12vw, 72px)/1 var(--serif); letter-spacing: -.01em; }

.search { position: relative; }
.search-box {
  display: flex; align-items: center; gap: 10px;
  height: 72px; padding: 0 10px 0 20px;
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  transition: border-color .15s;
}
.search-box:focus-within { border-color: var(--accent); }
.search-box svg { width: 26px; height: 26px; flex: none; fill: none; stroke: var(--muted); stroke-width: 2.2; stroke-linecap: round; }
.search-box input {
  flex: 1; min-width: 0; height: 100%;
  border: 0; outline: 0; background: none; color: var(--text);
  font: 500 22px var(--sans);
}
.search-box input::placeholder { color: var(--muted); font-weight: 400; }
.search-box input::-webkit-search-cancel-button { display: none; }
.clear { width: 52px; height: 52px; border-radius: 50%; font-size: 30px; color: var(--muted); }
.clear:active { background: var(--surface-press); }

.mode-toggle { display: flex; gap: 10px; margin-top: 12px; }
.chip {
  flex: 1; height: 48px; border-radius: 999px;
  border: 1.5px solid var(--line); color: var(--muted);
  font-size: 16px; font-weight: 600;
}
.chip[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.chip:active { background: var(--surface-press); }

.suggest {
  list-style: none; margin: 8px 0 0; padding: 6px;
  position: absolute; left: 0; right: 0; top: 76px; z-index: 5;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 18px 50px rgba(0,0,0,.35);
  max-height: min(60vh, 520px); overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Shared row (suggestions + A–Z list) */
.row {
  display: flex; align-items: center; gap: 14px;
  width: 100%; min-height: var(--hit); padding: 10px 14px;
  border-radius: 12px; text-align: left;
}
.row:active, .row.active { background: var(--surface-press); }
.row .num {
  flex: none; min-width: 58px; height: 40px; padding: 0 8px;
  display: grid; place-items: center;
  border-radius: 10px; background: var(--bg-2);
  color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums;
}
.row .title { font: 500 19px/1.25 var(--serif); }
.row mark { background: none; color: var(--accent); font-weight: 700; }
.empty { padding: 18px 14px; color: var(--muted); }

.actions { display: grid; gap: 14px; }
.tile {
  display: flex; align-items: center; gap: 18px;
  min-height: 96px; padding: 16px 20px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); text-align: left;
  transition: transform .08s, background .15s;
}
.tile:active { transform: scale(.98); background: var(--surface-press); }
.tile-icon {
  flex: none; width: 64px; height: 64px; border-radius: 16px;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink);
  font: 700 20px var(--serif);
}
.tile-text { flex: 1; display: grid; gap: 2px; }
.tile-text strong { font-size: 20px; }
.tile-text small { color: var(--muted); font-size: 15px; }
.chev { font-size: 34px; color: var(--muted); }

.link { min-height: 44px; padding: 0 12px; color: var(--accent); font-weight: 600; font-size: 16px; border-radius: 10px; }
.link:active { background: var(--surface-press); }
.row-star { margin-left: auto; color: var(--accent); font-size: 18px; padding-left: 8px; }

/* Install card (only when the app can be installed) */
.install { display: grid; gap: 8px; }
.install[hidden] { display: none; }
.install-btn {
  display: flex; align-items: center; gap: 14px; width: 100%;
  min-height: 72px; padding: 12px 16px; text-align: left;
  border-radius: var(--radius); border: 1.5px dashed var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}
.install-btn img { width: 40px; height: 40px; border-radius: 10px; flex: none; }
.install-btn span { display: grid; gap: 2px; }
.install-btn strong { font-size: 17px; }
.install-btn small { color: var(--muted); font-size: 14px; }
.install-btn:active { background: var(--surface-press); }
.install-ios { margin: 0; text-align: center; color: var(--muted); font-size: 15px; }
.install-ios[hidden] { display: none; }
.install-ios strong { color: var(--text); }
.install-ios svg { width: 18px; height: 18px; vertical-align: -3px; fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.foot {
  margin-top: auto; padding-top: 12px;
  display: grid; justify-items: center; gap: 2px;
  text-align: center; color: var(--muted); font-size: 14px;
}
.contact-label { font-size: 11px; font-weight: 600; letter-spacing: .16em; text-transform: uppercase; opacity: .85; }
.contact {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 0 14px; border-radius: 999px;
  color: var(--text); font-weight: 600; text-decoration: none;
}
.contact svg { width: 18px; height: 18px; fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linejoin: round; }
.contact:active { background: var(--surface-press); }
@media (hover: hover) { .contact:hover { color: var(--accent); } }

/* ---------- Sheets ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 10;
  display: flex; flex-direction: column;
  background: var(--bg);
  transform: translateY(100%);
  transition: transform .28s cubic-bezier(.2,.8,.2,1);
  padding-bottom: env(safe-area-inset-bottom);
}
.sheet.open { transform: none; }
.sheet-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: max(10px, env(safe-area-inset-top)) 8px 10px;
  border-bottom: 1px solid var(--line);
}
.sheet-bar h2 { margin: 0; font: 600 22px var(--serif); }
.icon-btn { width: 56px; height: 56px; border-radius: 50%; font-size: 34px; line-height: 1; display: grid; place-items: center; }
.icon-btn:active { background: var(--surface-press); }
.icon-btn[hidden] { display: grid; visibility: hidden; }

.letters {
  flex: 1; overflow-y: auto;
  display: grid; gap: 10px; padding: 16px;
  grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
  align-content: start;
  max-width: 720px; width: 100%; margin: 0 auto;
}
.letters[hidden] { display: none; }
.letter {
  aspect-ratio: 1; border-radius: 16px;
  background: var(--surface); border: 1px solid var(--line);
  display: grid; place-items: center; align-content: center; gap: 2px;
  transition: transform .08s;
}
.letter b { font: 600 32px/1 var(--serif); }
.letter small { font-size: 12px; color: var(--muted); }
.letter:active { transform: scale(.94); background: var(--accent); color: var(--accent-ink); }
.letter:disabled { opacity: .3; pointer-events: none; }

.list {
  flex: 1; overflow-y: auto; list-style: none; margin: 0; padding: 8px;
  max-width: 720px; width: 100%; margin-inline: auto;
}
.list li + li { border-top: 1px solid var(--line); }

.hymn-card { flex: 1; display: grid; place-content: center; text-align: center; gap: 14px; padding: 24px 16px; }
.hymn-num { font: 700 clamp(72px, 22vw, 140px)/1 var(--serif); color: var(--accent); }
.hymn-title { font: 500 clamp(26px, 6vw, 40px)/1.2 var(--serif); max-width: 18ch; margin: 0 auto; }
.present {
  margin-top: 18px; height: 64px; padding: 0 28px; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 18px;
}
.present:disabled { opacity: .5; }
.fav-toggle {
  height: 64px; padding: 0 28px; border-radius: 999px;
  border: 2px solid var(--line); font-weight: 700; font-size: 18px;
}
.fav-toggle[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.fav-toggle:active { background: var(--surface-press); }
.star-btn { color: var(--accent); font-size: 30px; }

.hymn-card { overflow-y: auto; }
.hymn-credits { display: grid; gap: 4px; color: var(--muted); font-size: 15px; line-height: 1.35; max-width: 26em; margin: 0 auto; }
.hymn-credits span {
  margin-right: .6em; color: var(--accent); font-size: 11px; font-weight: 700;
  letter-spacing: .14em; text-transform: uppercase;
}
.hymn-credits[hidden] { display: none; }
.crumb {
  justify-self: center; min-height: 44px; padding: 0 16px; border-radius: 999px;
  color: var(--accent); font-size: 15px; font-weight: 600;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}
.crumb:active { background: var(--surface-press); }

/* Category rows */
.cat-row .title { flex: 1; font-size: 20px; }
.cat-row .meta { color: var(--muted); font-size: 15px; font-variant-numeric: tabular-nums; }
.cat-row .chev { font-size: 28px; }
.segment[hidden] { display: none; }

/* Browse by number */
.jump {
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
  padding: 10px 16px; border-bottom: 1px solid var(--line);
}
.jump::-webkit-scrollbar { display: none; }
.jump button {
  flex: 1 1 0; min-width: 40px; height: 48px; padding: 0 4px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line);
  font-weight: 700; font-variant-numeric: tabular-nums;
}
.jump button:active { background: var(--accent); color: var(--accent-ink); }
.list .list-head {
  position: sticky; top: 0; z-index: 1;
  padding: 14px 14px 8px; background: var(--bg);
  color: var(--accent); font-size: 13px; font-weight: 700;
  letter-spacing: .14em; text-transform: uppercase;
}
.list .list-head + li { border-top: 0; }
.list [data-row] { scroll-margin-top: 44px; }
.sections { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; max-width: 520px; margin: 10px auto 0; }
.section-chip {
  min-height: 48px; padding: 0 16px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line);
  font-size: 15px; font-weight: 600;
}
.section-chip:active { background: var(--accent); color: var(--accent-ink); }
.hymn-note { max-width: 420px; margin: 4px auto 0; color: var(--muted); font-size: 13px; }

/* ---------- Presenter (big screen) ---------- */
body.presenting { overflow: hidden; }
.presenter {
  --p-bg: #021612; /* near-black with a hint of the logo green: best contrast on projectors */
  --p-text: #f7f3ea;
  --p-accent: #f9a825;
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column;
  background: var(--p-bg); color: var(--p-text);
  user-select: none; touch-action: none;
  cursor: none;
}
.presenter[hidden] { display: none; }
.presenter.controls-on { cursor: default; }

.p-slide {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column;
  padding: 4vh 6vw 2vh;
}
.p-label {
  flex: none; text-align: center;
  font: 700 clamp(18px, min(4.2vh, 6.5vw), 56px)/1.15 var(--sans); /* vw cap: long names on a narrow phone */
  letter-spacing: .14em; text-transform: uppercase;
  color: var(--p-accent);
  padding-bottom: 2.5vh;
}
/* Lyrics always start below the corner ••• button (only matters on short phone screens) */
.p-label {
  min-height: calc(76px + env(safe-area-inset-top) - 4vh);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .25em;
  /* keep long names clear of the ••• button (equal on both sides so the label stays centred) */
  padding-inline: max(0px, calc(76px - 6vw));
}
.p-label > span:first-child { text-wrap: balance; } /* long names wrap evenly: "WE HAVE / THIS HOPE" */
/* "1 of 2" sits on its own smaller line under the section name */
.p-page { font-size: .55em; letter-spacing: .12em; opacity: .65; white-space: nowrap; }
.p-strip small { opacity: .7; font-weight: 500; }
.p-body { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.p-text {
  text-align: center; white-space: nowrap;
  font-family: var(--serif); line-height: 1.32;
  text-wrap-style: balance; /* not the text-wrap shorthand: that would undo nowrap */
}
.p-text { flex: none; width: max-content; } /* box = widest line (never squeezed), so fit() can measure it */
.p-text.wrap { white-space: normal; width: 100%; }
.p-text .ln + .ln { margin-top: .12em; }
.p-text.wrap .ln + .ln { margin-top: .4em; } /* wrapped: keep each hymn line visibly grouped */

.presenter.is-title .p-label { visibility: hidden; } /* keeps its room, so the title clears the ••• */
.t-num { font-size: 2.4em; font-weight: 700; color: var(--p-accent); line-height: 1; }
.t-title { font-size: 1em; font-weight: 500; margin-top: .3em; white-space: normal; max-width: 16ch; margin-inline: auto; }

/* End screen after the last verse: hymn name + two big buttons (not sized to fit like lyrics) */
.presenter.is-end .p-label { visibility: hidden; }
.presenter.is-end .p-text { width: 100%; white-space: normal; }
.e-title { font: 500 clamp(18px, 3.4vh, 36px)/1.3 var(--serif); color: rgba(247,243,234,.75); }
.e-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 14px; margin-top: clamp(20px, 5vh, 48px); }
.e-btn {
  min-height: clamp(56px, 9vh, 84px); padding: 0 clamp(22px, 3vw, 40px); border-radius: 999px;
  font: 700 clamp(17px, 2.8vh, 28px) var(--sans); color: #fff; white-space: nowrap;
  border: 2px solid rgba(255,255,255,.3);
}
.e-btn.e-home { background: var(--p-accent); border-color: var(--p-accent); color: #1a1306; }
.e-btn:active { transform: scale(.97); }

.p-foot {
  flex: none; display: flex; justify-content: space-between; gap: 16px;
  padding: 0 3vw 2.2vh;
  font-size: clamp(12px, 2vh, 22px); color: rgba(247,243,234,.45);
}
.p-foot span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-foot #p-hymn { min-width: 0; }
.p-foot #p-count { flex: none; } /* the slide counter never gets cut; the title shortens instead */
.p-progress { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgba(255,255,255,.06); }
.p-progress i { display: block; height: 100%; background: var(--p-accent); transition: width .25s; }
.p-blackout { position: absolute; inset: 0; background: #000; z-index: 2; }

/* Controls: invisible to the congregation until the operator touches the screen */
.p-controls { position: absolute; inset: 0; z-index: 3; pointer-events: none; opacity: 0; transition: opacity .2s; }
.controls-on .p-controls { opacity: 1; }
.controls-on .p-controls button { pointer-events: auto; }
.p-top {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; gap: 10px;
  padding: max(12px, env(safe-area-inset-top)) 12px 24px;
  background: linear-gradient(rgba(0,0,0,.7), transparent);
}
.p-top-right { display: flex; gap: 10px; }
.p-btn {
  min-width: 56px; height: 56px; padding: 0 14px; border-radius: 14px;
  background: rgba(255,255,255,.12); color: #fff; font-size: 18px; font-weight: 600;
  backdrop-filter: blur(8px);
}
.p-btn:active, .p-btn[aria-pressed="true"] { background: var(--p-accent); color: #1a1306; }
.p-btn:not(.wide) { font-size: 22px; }
.p-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 72px; height: 112px; border-radius: 18px;
  background: rgba(255,255,255,.1); color: #fff; font-size: 56px; line-height: 1;
}
.p-nav:active { background: var(--p-accent); color: #1a1306; }
.p-nav.prev { left: 12px; }
.p-nav.next { right: 12px; }
.p-strip {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
  padding: 28px 12px max(14px, env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0,0,0,.8));
}
.p-strip::-webkit-scrollbar { display: none; }
/* Quick guide over the slide: left/right tap zones, a callout under the ••• button, and "Got it" */
.p-help {
  position: absolute; inset: 0; z-index: 4;
  display: grid; grid-template-columns: 1fr 1fr;
  background: rgba(2, 16, 13, .9); color: #fff;
  animation: help-in .2s ease-out;
}
.p-help[hidden] { display: none; }
@keyframes help-in { from { opacity: 0; } }
.h-zone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  padding: 0 12px 22vh; text-align: center;
}
.h-left { border-right: 2px dashed rgba(255,255,255,.22); }
.h-zone strong { font-size: clamp(20px, 3.4vh, 34px); }
.h-zone span:last-child { color: rgba(255,255,255,.65); font-size: clamp(14px, 2.2vh, 20px); }
.h-arrow {
  width: clamp(56px, 9vh, 88px); aspect-ratio: 1; border-radius: 50%; margin-bottom: 10px;
  display: grid; place-items: center;
  background: var(--p-accent); color: #1a1306; font-size: clamp(36px, 6vh, 60px); line-height: 1;
}
.h-callout {
  position: absolute; top: calc(max(12px, env(safe-area-inset-top)) + 70px); right: max(12px, env(safe-area-inset-right));
  max-width: min(240px, 60vw); padding: 10px 14px; border-radius: 14px;
  background: #fff; color: #0f2620; font-size: 13px; line-height: 1.35; text-align: left;
  display: grid; gap: 2px;
}
.h-callout strong { font-size: 15px; }
.h-callout::before { /* little pointer up to the ••• button */
  content: ""; position: absolute; top: -7px; right: 21px;
  border: 7px solid transparent; border-top: 0; border-bottom-color: #fff;
}
@media (max-height: 520px) { /* phone in landscape: put the callout beside the ••• so it doesn't cover the right arrow */
  .h-callout { top: max(12px, env(safe-area-inset-top)); right: calc(max(12px, env(safe-area-inset-right)) + 70px); }
  .h-zone { padding: 96px 12px 140px; } /* keep the arrows between the callout and the bottom text */
  .h-callout::before {
    top: 21px; right: -7px;
    border: 7px solid transparent; border-right: 0; border-left-color: #fff;
  }
}
.h-bottom {
  position: absolute; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  width: min(560px, calc(100% - 32px)); text-align: center;
  display: grid; gap: 6px; justify-items: center;
}
.h-bottom p { margin: 0; font-size: clamp(14px, 2.2vh, 18px); color: rgba(255,255,255,.8); }
.h-keys { font-size: 13px !important; color: rgba(255,255,255,.6) !important; }
.h-keys kbd {
  display: inline-block; min-width: 1.6em; padding: 0 .35em; border-radius: 5px;
  border: 1px solid rgba(255,255,255,.35); font: inherit; font-weight: 600; color: #fff;
}
@media (hover: none) { .h-keys { display: none; } } /* phones and tablets: no keyboard tips */
.h-ok {
  margin-top: 8px; min-width: 160px; height: 56px; padding: 0 28px; border-radius: 999px;
  background: var(--p-accent); color: #1a1306; font-size: 18px; font-weight: 700;
}

/* The only always-visible control: a faint "•••" button in the top-right corner */
.p-toggle {
  position: absolute; z-index: 5;
  top: max(12px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right));
  width: 56px; height: 56px; border-radius: 16px;
  display: flex; align-items: center; justify-content: center; gap: 5px;
  background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.16);
  opacity: .5; transition: opacity .2s, background .2s;
}
.p-toggle i { width: 6px; height: 6px; border-radius: 50%; background: #fff; }
.p-toggle:active, .p-toggle[aria-expanded="true"] { opacity: 1; background: rgba(255,255,255,.18); }
@media (hover: hover) { .p-toggle:hover { opacity: .8; } }
.p-top { padding-right: calc(max(12px, env(safe-area-inset-right)) + 66px); } /* Blank / Full screen sit left of it */
.p-strip button {
  flex: none; height: 52px; padding: 0 16px; border-radius: 12px;
  background: rgba(255,255,255,.12); color: #fff; font-weight: 600; font-size: 15px;
}
.p-strip button[aria-current="true"] { background: var(--p-accent); color: #1a1306; }

/* Favorites / Recent switcher */
.segment {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
  margin: 12px 16px 4px; padding: 6px;
  background: var(--surface); border-radius: 999px;
  max-width: 688px; width: calc(100% - 32px); align-self: center;
}
.segment button { height: 52px; border-radius: 999px; font-weight: 700; color: var(--muted); }
.segment button[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); }
.saved-foot { display: flex; justify-content: center; padding: 8px; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
