/* Praying Scripture — warm paper, ink, a little gilt. */

:root {
  --bg: #f5efe3;
  --glow: rgba(255, 255, 255, .75);
  --panel: #fbf7ee;
  --ink: #1e1914;
  --muted: #756a5b;
  --rule: #d9cdb9;
  --field: #faf6ec;
  --inset: inset 0 2px 4px rgba(70, 45, 10, .16), inset 0 0 0 1px rgba(70, 45, 10, .07), 0 1px 0 rgba(255, 255, 255, .8);
  --accent: #8a5b27;
  --mark: rgba(190, 140, 60, .28);
  --serif: 'Baskervville', Baskerville, 'Iowan Old Style', Georgia, 'Times New Roman', serif;
  --sans: 'Jost', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  --gutter: clamp(20px, 4vw, 48px);
  --scale: 1;
  --ease-out: cubic-bezier(.22, 1, .36, 1);
  --ease-in: cubic-bezier(.55, 0, .8, .3);
  --ease-in-out: cubic-bezier(.65, 0, .35, 1);
  color-scheme: light;
}

:root[data-theme="night"] {
  --bg: #15110d;
  --glow: rgba(201, 161, 92, .09);
  --panel: #1c1712;
  --ink: #f0e8d9;
  --muted: #a09482;
  --rule: #342d24;
  --field: #221c15;
  --inset: inset 0 2px 5px rgba(0, 0, 0, .55), inset 0 0 0 1px rgba(0, 0, 0, .25), 0 1px 0 rgba(255, 235, 200, .06);
  --accent: #cfa762;
  --mark: rgba(207, 167, 98, .3);
  color-scheme: dark;
}

:root[data-font="dm"] { --serif: 'DM Serif Display', 'Iowan Old Style', Georgia, 'Times New Roman', serif; }
:root[data-font="baskerville"] { --serif: 'Libre Baskerville', Baskerville, Georgia, 'Times New Roman', serif; }
:root[data-font="noto"] { --serif: 'Noto Serif', Georgia, 'Times New Roman', serif; }

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: #15110d;
    --glow: rgba(201, 161, 92, .09);
    --panel: #1c1712;
    --ink: #f0e8d9;
    --muted: #a09482;
    --rule: #342d24;
  --field: #221c15;
  --inset: inset 0 2px 5px rgba(0, 0, 0, .55), inset 0 0 0 1px rgba(0, 0, 0, .25), 0 1px 0 rgba(255, 235, 200, .06);
    --accent: #cfa762;
    --mark: rgba(207, 167, 98, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: radial-gradient(1100px 640px at 50% -8%, var(--glow), transparent 70%), var(--bg);
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color .4s ease, color .4s ease;
}

button { font: inherit; color: inherit; cursor: pointer; }
button, a, input, .cell { touch-action: manipulation; }
button:focus-visible, input:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
svg { width: 1.1em; height: 1.1em; fill: none; stroke: currentColor; stroke-width: 1.3; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Header ---------- */

.bar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 1.25rem 2rem;
  padding: 22px var(--gutter);
  padding-top: max(22px, env(safe-area-inset-top));
}

.mark {
  font-size: 1.65rem;
  font-weight: 400;
  letter-spacing: .01em;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}
.mark em { font-weight: 400; color: var(--accent); }

.search {
  justify-self: center;
  display: flex;
  align-items: center;
  gap: .65rem;
  width: min(100%, 22rem);
  padding: .6rem 1.15rem .62rem;
  background: var(--field);
  border-radius: 999px;
  box-shadow: var(--inset);
  color: var(--muted);
  transition: box-shadow .25s, color .25s;
}
.search:focus-within { color: var(--accent); box-shadow: var(--inset), 0 0 0 2px var(--accent); }
.search svg { flex: none; }
.search input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  padding: 0;
  font-family: var(--serif);
  font-size: 1.15rem;
  color: var(--ink);
}
.search input:focus-visible { outline: none; }
.search input::placeholder { color: var(--muted); font-style: italic; }
.search input::-webkit-search-cancel-button { filter: grayscale(1); opacity: .6; }

.bar-end { display: flex; align-items: center; gap: 1.5rem; }

.seg { display: inline-flex; gap: 1.4rem; }
.seg button {
  background: none;
  border: 0;
  padding: .5rem 0;
  font-family: var(--sans);
  font-size: .75rem;
  font-weight: 400;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid transparent;
  transition: color .2s, border-color .2s;
}
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.seg-sm { gap: 1.1rem; }

.ghost {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  background: none;
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: .45rem 1rem .45rem .85rem;
  font-family: var(--sans);
  font-size: .75rem;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--muted);
  transition: color .2s, border-color .2s, background-color .2s;
}
.ghost:hover, .ghost[aria-expanded="true"] { color: var(--ink); border-color: var(--accent); }

/* ---------- Options panel ---------- */

/* The pane floats over the content instead of pushing it down. */
.top { position: relative; z-index: 30; }
.panel {
  position: absolute;
  top: calc(100% - 6px);
  left: var(--gutter);
  right: var(--gutter);
  max-height: calc(100vh - 7rem);
  max-height: calc(100dvh - 7rem);
  display: grid;
  grid-template-rows: 0fr;                 /* collapsed; 1fr when .open */
  opacity: 0;
  transform: translateY(-10px) scale(.992);
  transform-origin: top right;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 4px;
  box-shadow: 0 30px 70px -24px rgba(40, 25, 5, .45), 0 2px 8px rgba(40, 25, 5, .06);
  transition:
    grid-template-rows .55s var(--ease-out),
    opacity .35s var(--ease-in-out),
    transform .55s var(--ease-out);
}
.panel.open { grid-template-rows: 1fr; opacity: 1; transform: none; }
.panel-clip { overflow-x: hidden; overflow-y: auto; min-height: 0; overscroll-behavior: contain; }

/* Fields settle in one after another */
.panel .field {
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .3s var(--ease-in-out), transform .3s var(--ease-in-out);
}
.panel.open .field {
  opacity: 1;
  transform: none;
  transition: opacity .6s var(--ease-out), transform .7s var(--ease-out);
  transition-delay: calc(var(--i, 0) * 55ms + 140ms);
}
.panel .field:nth-child(1) { --i: 0; }
.panel .field:nth-child(2) { --i: 1; }
.panel .field:nth-child(3) { --i: 2; }
.panel .field:nth-child(4) { --i: 3; }
.panel .field:nth-child(5) { --i: 4; }
.panel .field:nth-child(6) { --i: 5; }
.panel .field:nth-child(7) { --i: 6; }
.close {
  position: absolute;
  top: .9rem;
  right: .9rem;
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  background: none;
  border: 1px solid var(--rule);
  border-radius: 50%;
  color: var(--muted);
  transition: color .2s, border-color .2s;
}
.close:hover { color: var(--ink); border-color: var(--accent); }
.panel-inner {
  max-width: 980px;
  margin: 0 auto;
  padding: 1.8rem clamp(18px, 3vw, 36px) 2rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 1.9rem 2.5rem;
}
.field-wide { grid-column: 1 / -1; }
.field h2 {
  margin: 0 0 .85rem;
  font-family: var(--sans);
  font-size: .75rem;
  font-weight: 400;
  letter-spacing: .26em;
  text-transform: uppercase;
  color: var(--accent);
}

.pills { display: flex; flex-wrap: wrap; gap: .5rem; }
.pill {
  background: none;
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: .28rem .95rem .32rem;
  font-family: var(--serif);
  font-size: 1.1rem;
  line-height: 1.2;
  color: var(--ink);
  transition: background-color .2s, color .2s, border-color .2s;
}
.pill small { font-family: var(--sans); font-size: .75rem; letter-spacing: .08em; color: var(--muted); margin-left: .4rem; }
.pill:hover { border-color: var(--accent); }
.pill[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.pill[aria-pressed="true"] small { color: inherit; opacity: .7; }

.size { display: flex; align-items: baseline; gap: .9rem; max-width: 17rem; }
.size .a-sm { font-size: .95rem; color: var(--muted); }
.size .a-lg { font-size: 1.7rem; color: var(--muted); }
.size input { flex: 1; accent-color: var(--accent); align-self: center; }

/* ---------- Main ---------- */

main { flex: 1; display: flex; flex-direction: column; outline: none; }

/* Focus view */

.focus { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 4vh clamp(24px, 8vw, 120px) 6vh;
}
/* Verses: slide + soften in; the old one eases out ahead of it. Ref and topic travel half as far for depth. */
.stage > * { --k: 1; }
.stage > .ref, .stage > .topic-link { --k: .5; }
.stage.enter > * { animation: verse-in .85s var(--ease-out) both; }
.stage.enter > *:nth-child(2) { animation-delay: .05s; }
.stage.enter > *:nth-child(3) { animation-delay: .12s; }
.stage.leave > * { animation: verse-out .24s var(--ease-in) both; }

.ref {
  font-family: var(--sans);
  font-size: .78rem;
  font-weight: 400;
  letter-spacing: .32em;
  text-transform: uppercase;
  color: var(--accent);
  padding-bottom: 1.6rem;
  position: relative;
}
.ref::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 1px;
  height: .9rem;
  background: var(--accent);
  opacity: .55;
}
.ref b { font-weight: 500; }
button.ref { background: none; border: 0; border-radius: 2px; cursor: pointer; padding-top: .35rem; transition: color .3s var(--ease-out); }
button.ref:hover { color: var(--ink); }
.caret {
  display: inline-block;
  width: .42em;
  height: .42em;
  margin-left: .75em;
  border-right: 1px solid currentColor;
  border-bottom: 1px solid currentColor;
  transform: translateY(-.2em) rotate(45deg);
  transition: transform .3s var(--ease-out);
}
button.ref:hover .caret { transform: translateY(-.08em) rotate(45deg); }

.prayer {
  margin: 1.3rem 0 1.5rem;
  font-family: var(--serif);
  font-weight: 500;
  font-size: calc(clamp(2.2rem, 5.6vw, 4.6rem) * var(--scale));
  line-height: 1.16;
  letter-spacing: -.008em;
  text-wrap: balance;
  color: var(--ink);
  quotes: none;
}
.prayer.long { font-size: calc(clamp(1.8rem, 4.2vw, 3.3rem) * var(--scale)); line-height: 1.2; }

.topic-link {
  background: none;
  border: 0;
  padding: .25rem 0;
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.15rem;
  color: var(--muted);
  border-bottom: 1px solid transparent;
  transition: color .2s, border-color .2s;
}
.topic-link:hover { color: var(--accent); border-bottom-color: var(--accent); }

.pager {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(1.4rem, 5vw, 3rem);
  padding: 1.6rem var(--gutter) max(2rem, env(safe-area-inset-bottom));
}
.pager::before {
  content: '';
  position: absolute;
  top: 0;
  left: var(--gutter);
  right: var(--gutter);
  height: 1px;
  background: linear-gradient(to right, var(--accent) var(--progress, 0%), var(--rule) var(--progress, 0%));
  transition: background .4s;
}
.nav {
  display: grid;
  place-items: center;
  width: 3rem;
  height: 3rem;
  background: none;
  border: 1px solid var(--rule);
  border-radius: 50%;
  color: var(--ink);
  transition: border-color .2s, color .2s, opacity .2s, background-color .2s;
}
.nav svg { width: 1.2rem; height: 1.2rem; }
.nav:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.nav:disabled { opacity: .3; cursor: default; }
.count {
  min-width: 6rem;
  text-align: center;
  font-family: var(--sans);
  font-size: .78rem;
  letter-spacing: .24em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.count b { color: var(--ink); font-weight: 400; }

/* List view */

.list-wrap {
  width: 100%;
  max-width: 880px;
  margin: 0 auto;
  padding: 1.2rem var(--gutter) 7rem;
  animation: rise .6s var(--ease-out) both;
}
.meta {
  margin: 0 0 .5rem;
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.15rem;
  color: var(--muted);
}
.group h2 {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 3rem 0 0;
  padding-bottom: .85rem;
  border-bottom: 1px solid var(--accent);
  font-family: var(--sans);
  font-size: .75rem;
  font-weight: 400;
  letter-spacing: .28em;
  text-transform: uppercase;
  color: var(--accent);
}
.group h2 span { color: var(--muted); letter-spacing: .12em; }
.group:first-of-type h2 { margin-top: 1.6rem; }
.group ol, .plain { list-style: none; margin: 0; padding: 0; }
.plain { margin-top: 1.2rem; border-top: 1px solid var(--accent); }

.row {
  display: grid;
  grid-template-columns: clamp(3.6rem, 12vw, 5.2rem) 1fr;
  gap: .5rem 1rem;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--rule);
  padding: 1.25rem .4rem 1.3rem;
  transition: background-color .25s;
}
.row:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.row .r {
  padding-top: .3rem;
  font-style: italic;
  font-size: 1.3rem;
  color: var(--accent);
  white-space: nowrap;
}
.row .t {
  font-size: calc(1.7rem * var(--scale));
  line-height: 1.28;
  font-weight: 500;
  text-wrap: pretty;
}
.row .tp {
  grid-column: 2;
  font-family: var(--sans);
  font-size: .75rem;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--muted);
}

mark { background: var(--mark); color: inherit; border-radius: 2px; padding: 0 .06em; }

.empty {
  margin: auto;
  padding: 4rem var(--gutter);
  text-align: center;
  color: var(--muted);
}
.empty p { margin: 0 0 1rem; font-size: 1.8rem; font-style: italic; }
.empty button {
  background: none;
  border: 0;
  border-bottom: 1px solid var(--accent);
  padding: .2rem 0;
  font-family: var(--sans);
  font-size: .75rem;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--accent);
}

/* ---------- Motion ---------- */

@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes verse-in {
  from { opacity: 0; transform: translate(calc(var(--dx, 0px) * var(--k)), calc(var(--dy, 14px) * var(--k))); filter: blur(4px); }
  to   { opacity: 1; transform: none; filter: blur(0); }
}
@keyframes verse-out {
  from { opacity: 1; transform: none; filter: blur(0); }
  to   { opacity: 0; transform: translateX(calc(var(--dx, 0px) * var(--k))); filter: blur(4px); }
}

/* ---------- Small screens ---------- */

@media (max-width: 760px) {
  html { font-size: 115%; }  /* all rem-based text +15% */
  /* Focus prayer: +40% over the previous mobile size (px so the root bump doesn't compound) */
  .prayer { font-size: calc(clamp(35.2px, 5.6vw, 73.6px) * var(--scale) * 1.4); }
  .prayer.long { font-size: calc(clamp(28.8px, 4.2vw, 52.8px) * var(--scale) * 1.4); }
  .bar { grid-template-columns: 1fr auto; row-gap: 1rem; padding-top: max(16px, env(safe-area-inset-top)); }
  .search { grid-column: 1 / -1; grid-row: 2; justify-self: stretch; width: 100%; }
  .panel { max-height: calc(100vh - 9.5rem); max-height: calc(100dvh - 9.5rem); }  /* taller header on phones */
  .bar { column-gap: .75rem; }
  .mark { font-size: 1.2rem; }
  .bar-end { gap: .55rem; }
  .bar .seg { gap: .7rem; }
  .bar .seg button { letter-spacing: .08em; }
  .ghost span { display: none; }
  .ghost { padding: .5rem; }
  .stage { padding-left: 22px; padding-right: 22px; }
  .row { grid-template-columns: 3.4rem 1fr; }
  .row .t { font-size: calc(1.45rem * var(--scale)); }
}

@media print {
  .bar, .panel, .pager { display: none; }
  body { background: #fff; color: #000; }
}

/* ---------- Psalm picker ---------- */

.picker {
  width: min(640px, calc(100vw - 32px));
  max-height: min(86vh, 720px);
  max-height: min(86dvh, 720px);
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 40px 90px -30px rgba(40, 25, 5, .55);
  overflow: hidden;
}
.picker[open] { display: flex; flex-direction: column; animation: pop .4s var(--ease-out) both; }
.picker::backdrop { background: rgba(32, 22, 10, .4); backdrop-filter: blur(3px); animation: fade .3s var(--ease-out) both; }
.picker-head { padding: 1.5rem 4.2rem 1rem 1.6rem; }
.picker h2 { margin: 0; font-family: var(--serif); font-weight: 400; font-size: 1.9rem; line-height: 1.15; }
.picker .hint { margin: .45rem 0 0; font-family: var(--sans); font-size: .7rem; letter-spacing: .2em; text-transform: uppercase; color: var(--muted); }
.picker-body { overflow-y: auto; padding: .4rem 1.6rem 1.7rem; overscroll-behavior: contain; }
.picker .book { margin: 1.6rem 0 .8rem; font-family: var(--sans); font-size: .7rem; font-weight: 400; letter-spacing: .26em; text-transform: uppercase; color: var(--accent); }
.cells { display: grid; grid-template-columns: repeat(10, 1fr); gap: .4rem; }
.cell {
  aspect-ratio: 1;
  min-height: 2.75rem;
  display: grid;
  place-items: center;
  background: none;
  border: 1px solid var(--rule);
  border-radius: 6px;
  font-family: var(--serif);
  font-size: 1.15rem;
  color: var(--ink);
  font-variant-numeric: lining-nums;
  transition: background-color .2s var(--ease-out), color .2s var(--ease-out), border-color .2s var(--ease-out), transform .2s var(--ease-out);
}
.cell:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); transform: translateY(-1px); }
.cell:disabled { border-color: transparent; color: var(--muted); opacity: .38; cursor: default; }
.cell.current { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.cell.current:hover:not(:disabled) { color: var(--bg); }

.row.flash { animation: flash 1.8s var(--ease-in-out) both; }

@keyframes pop  { from { opacity: 0; transform: translateY(16px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes flash { 0%, 100% { background-color: transparent; } 20%, 60% { background-color: var(--mark); } }

@media (max-width: 760px) {
  .cells { grid-template-columns: repeat(6, 1fr); }
  .picker-head { padding-left: 1.2rem; }
  .picker-body { padding-left: 1.2rem; padding-right: 1.2rem; }
}

/* ---------- Accessibility & touch refinements ---------- */

.brand { margin: 0; font: inherit; }
.skip {
  position: absolute;
  left: 1rem;
  top: -4rem;
  z-index: 100;
  padding: .7rem 1.1rem;
  background: var(--ink);
  color: var(--bg);
  font-family: var(--sans);
  font-size: .8rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  text-decoration: none;
  border-radius: 999px;
  transition: top .25s var(--ease-out);
}
.skip:focus { top: 1rem; }

/* Finger-sized targets on touch screens (44px) */
@media (pointer: coarse) {
  .seg button, .ghost, .pill, .topic-link, button.ref, .empty button { min-height: 44px; }
  .seg button { display: inline-flex; align-items: center; }
  .pill { padding-top: .5rem; padding-bottom: .5rem; }
  .pills { gap: .6rem; }
  .nav { width: 3.25rem; height: 3.25rem; }
}
