/* Latin prayers — shared by every page under /latin/.
   Latin is set in Alegreya, a serif drawn from calligraphy, as a glossed
   manuscript would be; everything else is Alegreya Sans. Colour carries one
   meaning everywhere: blue is how a word sounds (and anything that plays
   sound), red is what it means. The show/hide toggles use the same colours,
   so they double as the key. */

:root {
  --paper: #fbfbfa;
  --paper-2: #f2f2ee;
  --ink: #0d0d0c;
  --ink-soft: #5f5e5a;
  --ink-faint: #9a9994;
  --hair: #e4e4e0;
  --sound: #1d5591;
  --gloss: #b0261c; /* missal red */
  --mark: #fbe7a0;  /* the word being spoken */
  --mark-ink: #0d0d0c;

  --font-la: "Alegreya", Georgia, "Times New Roman", serif;
  --font-ui: "Alegreya Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --measure: 46rem;
  --gutter: clamp(1rem, 5vw, 3rem);
  color-scheme: light dark;
}

/* bedtime prayers happen in the dark */
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #131312;
    --paper-2: #1f1f1d;
    --ink: #f2f1ed;
    --ink-soft: #b5b3ac;
    --ink-faint: #7f7d77;
    --hair: #2f2e2b;
    --sound: #93bdf2;
    --gloss: #f2917f;
    --mark: #5b4b14;
    --mark-ink: #fff7da;
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 1.125rem;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation; /* quick repeated taps shouldn't zoom the page */
}
:where(a, button):focus-visible {
  outline: 2px solid var(--sound);
  outline-offset: 3px;
  border-radius: 0.4rem;
}

.i {
  width: 1.15em;
  height: 1.15em;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.i.solid { fill: currentColor; }

[hidden] { display: none !important; }

/* ---------- Top bar ---------- */
.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.25rem var(--gutter);
  border-bottom: 1px solid var(--hair);
}
.bar a {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 1rem;
  transition: color 0.16s ease;
}
.bar a:hover { color: var(--ink); }
.bar .site {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.bar .site .sl { color: var(--ink-faint); margin: 0 0.15em; }

main {
  flex: 1 0 auto;
  width: min(var(--measure), 100%);
  margin-inline: auto;
  padding: clamp(2.25rem, 8vw, 4.5rem) var(--gutter) clamp(3rem, 10vw, 5rem);
}

/* ---------- A glossed word: Latin over sound over meaning ---------- */
.w {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 2.75rem; /* "a", "in", "es" stay a finger-sized target */
  text-align: left;
  padding: 0.2rem 0.4rem 0.3rem;
  margin: -0.2rem -0.4rem -0.3rem;
  border-radius: 0.55rem;
  transition: background-color 0.15s ease;
}
@media (hover: hover) {
  .w:hover { background: var(--paper-2); }
}
.w.on { background: var(--mark); }
.w.on .w-la { color: var(--mark-ink); }

.w-la {
  font-family: var(--font-la);
  font-size: clamp(1.6rem, 6vw, 2.2rem);
  font-weight: 500;
  line-height: 1.15;
}
.w-la .p { color: var(--ink-soft); }

.w-sound,
.w-gloss {
  font-size: 1rem;
  line-height: 1.3;
  white-space: nowrap;
}
.w-sound { margin-top: 0.2rem; color: var(--sound); letter-spacing: 0.01em; }
.w-sound b { font-weight: 800; }
.w-gloss { color: var(--gloss); font-style: italic; }

/* ---------- Hero: the prayer's name, glossed like every line below it ---------- */
.hero .title {
  display: flex;
  flex-wrap: wrap;
  column-gap: 0.35em;
  row-gap: 0.75rem;
  font-size: clamp(3.1rem, 15vw, 6.25rem);
  font-weight: inherit;
}
.hero .title .w-la {
  font-size: 1em;
  line-height: 0.95;
  letter-spacing: -0.015em;
}
.hero .title .w-sound,
.hero .title .w-gloss { font-size: clamp(1.05rem, 3.4vw, 1.4rem); }
.hero .title .w-sound { margin-top: 0.55rem; }
.initial { color: var(--gloss); }

.hero .sub {
  margin-top: clamp(1.5rem, 5vw, 2.25rem);
  font-family: var(--font-la);
  font-size: clamp(1.35rem, 4vw, 1.65rem);
  font-style: italic;
  line-height: 1.3;
}
.hero .intro {
  margin-top: 0.6rem;
  max-width: 34rem;
  color: var(--ink-soft);
  text-wrap: pretty;
}

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: clamp(1.5rem, 6vw, 2.5rem);
  margin-top: clamp(2.5rem, 8vw, 3.5rem);
  border-bottom: 1px solid var(--hair);
}
.tab {
  padding: 0.55rem 0.35rem 0.65rem;
  margin: 0 -0.35rem -1px;
  border-bottom: 3px solid transparent;
  font-size: 1.3rem;
  font-weight: 500;
  color: var(--ink-soft);
  transition: color 0.15s ease, border-color 0.15s ease;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }
.tab:focus-visible { outline-offset: -2px; }

/* ---------- Toolbar: what's showing ---------- */
.tools {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-inline: calc(-1 * var(--gutter));
  padding: 0.75rem var(--gutter);
  background: color-mix(in srgb, var(--paper) 90%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--hair);
}

.pill {
  --c: var(--ink);
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 2.75rem;
  padding: 0.35rem 0.85rem 0.35rem 0.7rem;
  border: 1.5px solid var(--hair);
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 500;
  color: var(--ink-soft);
  white-space: nowrap;
  transition: color 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
}
.pill:hover { border-color: var(--ink-faint); }
.pill .key {
  width: 0.7rem;
  height: 0.7rem;
  border: 2px solid currentColor;
  border-radius: 50%;
}
.pill[aria-pressed="true"] {
  color: var(--c);
  border-color: color-mix(in srgb, var(--c) 45%, transparent);
  background: color-mix(in srgb, var(--c) 9%, transparent);
}
.pill[aria-pressed="true"] .key { background: currentColor; }
.pill[data-toggle="sound"],
.pill[data-toggle="slow"] { --c: var(--sound); }
.pill[data-toggle="gloss"] { --c: var(--gloss); }

#learn.hide-sound .w-sound,
#learn.hide-gloss .w-gloss,
#learn.hide-en .en,
#learn.hide-en .note { display: none; }

/* ---------- Big play buttons and hints ---------- */
.lead {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin: 1.5rem 0 0.75rem;
}
.big {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 3rem;
  padding: 0.6rem 1.35rem 0.6rem 1.1rem;
  border-radius: 999px;
  background: var(--sound);
  color: var(--paper);
  font-size: 1.1rem;
  font-weight: 700;
}
.big .i { width: 1rem; height: 1rem; }
.hint { color: var(--ink-soft); font-size: 1rem; }
.caveat {
  margin-top: 0.5rem;
  max-width: 36rem;
  color: var(--ink-soft);
  font-size: 0.95rem;
  text-wrap: pretty;
}
.caveat b { color: var(--ink); font-weight: 500; }
.voice-note {
  margin: 1.5rem 0 0.75rem;
  padding-left: 0.9rem;
  border-left: 3px solid var(--sound);
  color: var(--ink-soft);
  font-size: 1rem;
  max-width: 36rem;
}

/* Audio controls wait until we know a voice exists, then show or go. */
.voice-pending [data-audio] { visibility: hidden; }
.no-voice [data-audio] { display: none !important; }
body:not(.no-voice) .voice-note { display: none; }

/* ---------- Learn: one line of the prayer ---------- */
.line {
  --pad: clamp(0.5rem, 2vw, 1rem);
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: clamp(0.75rem, 3vw, 1.25rem);
  margin-inline: calc(-1 * var(--pad));
  padding: 1.4rem var(--pad);
  border-radius: 1rem;
  transition: background-color 0.2s ease;
}
/* the rule between lines stays straight; only the playing line's band is rounded */
.line::before {
  content: "";
  position: absolute;
  top: 0;
  inset-inline: var(--pad);
  border-top: 1px solid var(--hair);
}
.line:first-child::before,
.line.active::before,
.line.active + .line::before { display: none; }
.line.active { background: var(--paper-2); }
.line .body { min-width: 0; }

.say {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  margin-top: 0.3rem;
  border: 1.5px solid var(--sound);
  border-radius: 50%;
  color: var(--sound);
  transition: background-color 0.15s ease, color 0.15s ease;
}
.say .i { width: 1rem; height: 1rem; }
.say .i.play { translate: 1px 0; } /* optical centre of the triangle */
.say[aria-pressed="true"],
.big[aria-pressed="true"] { background: var(--sound); color: var(--paper); }
.say[aria-pressed="true"] .i.play { translate: none; }

.ws {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  column-gap: clamp(1rem, 3.5vw, 1.5rem);
  row-gap: 0.9rem;
}
.en {
  margin-top: 0.85rem;
  font-family: var(--font-la);
  font-size: 1.2rem;
  font-style: italic;
  color: var(--ink-soft);
}
/* what your hands do: a rubric, in the missal's sense */
.do,
.pdo {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  color: var(--ink);
}
.do { margin-top: 0.55rem; font-size: 1.05rem; font-weight: 500; }
.pdo { margin-top: 0.15rem; font-size: 1rem; }
.do .i,
.pdo .i { width: 1.1em; height: 1.1em; margin-top: 0.2em; color: var(--ink-soft); }
.do i,
.pdo i { font-family: var(--font-la); }

.note {
  margin-top: 0.45rem;
  max-width: 36rem;
  font-size: 1rem;
  color: var(--ink-soft);
  text-wrap: pretty;
}
.note i { font-family: var(--font-la); color: var(--ink); }

/* ---------- How Church Latin sounds ---------- */
.guide {
  margin-top: clamp(2.5rem, 8vw, 3.5rem);
  padding-top: clamp(2rem, 6vw, 2.75rem);
  border-top: 1px solid var(--hair);
}
.guide h2 {
  font-family: var(--font-la);
  font-size: clamp(1.6rem, 5vw, 2rem);
  font-weight: 500;
  line-height: 1.2;
}
.guide > p {
  margin-top: 0.5rem;
  max-width: 34rem;
  color: var(--ink-soft);
}
.rules { margin-top: 1.5rem; }
.rules > div {
  display: grid;
  grid-template-columns: minmax(5rem, 8.5rem) 1fr;
  gap: 0.25rem 1.25rem;
  align-items: start;
  padding: 0.9rem 0;
  border-top: 1px solid var(--hair);
}
.rules dt { font-family: var(--font-la); font-size: 1.5rem; font-weight: 500; line-height: 1.2; }
.rules dt small {
  display: block;
  font-family: var(--font-ui);
  font-size: 0.9rem;
  font-weight: 400;
  color: var(--ink-soft);
}
.rules dd {
  display: grid;
  justify-items: start;
  gap: 0.5rem 1.25rem;
}
@media (min-width: 40rem) {
  .rules dd { grid-template-columns: 1fr minmax(11rem, auto); }
}
.rules .says { padding-top: 0.3rem; }
.rules .says b { color: var(--sound); font-weight: 700; }
.rules .w-la { font-size: 1.4rem; }

/* ---------- Pray ---------- */
.pray { margin-top: 0.5rem; }
.pl { padding: 0.55rem 0; }
.pl.end { padding-bottom: 1.25rem; }
/* verse setting: a line that wraps hangs indented, so each line of the prayer starts flush */
.pla,
.practice p {
  padding-left: 1em;
  text-indent: -1em;
}
.pla {
  font-family: var(--font-la);
  font-size: clamp(1.4rem, 4.6vw, 1.75rem);
  font-weight: 500;
  line-height: 1.35;
}
.pla .t { padding: 0 0.08em; margin: 0 -0.08em; border-radius: 0.3rem; }
.pla .t.on { background: var(--mark); color: var(--mark-ink); }
.pen { margin-top: 0.1rem; color: var(--ink-soft); font-size: clamp(1.05rem, 2.6vw, 1.15rem); }
.pray.hide-en .pen { display: none; }

/* ---------- Practice ---------- */
#pray > :first-child,
#practice > :first-child { margin-top: 1.5rem; }

.stepper {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.5rem;
  margin: 1.25rem 0 0.5rem;
}
.steps { display: flex; gap: 0.5rem; }
.stepper .pill { padding-inline: 1rem; }
.stepper .pill:disabled { opacity: 0.4; cursor: default; }
.level { display: flex; align-items: center; gap: 0.75rem; }
.dots { display: flex; gap: 0.3rem; }
.dots span {
  width: 1.6rem;
  height: 0.45rem;
  border-radius: 999px;
  background: var(--hair);
  transition: background-color 0.2s ease;
}
.dots span.f { background: var(--ink); }
.level-name { font-weight: 500; }

.practice {
  margin-top: 1.25rem;
  font-family: var(--font-la);
  font-size: clamp(1.45rem, 4.8vw, 1.85rem);
  font-weight: 500;
  line-height: 2;
  word-spacing: 0.12em; /* room between the words' enlarged tap areas */
}
.practice p.end { margin-bottom: 0.6rem; }
.pw {
  position: relative;
  text-indent: 0; /* inherited from the hanging indent; a button would shift its own text */
  word-spacing: normal;
  border-radius: 0.3rem;
  font-weight: inherit;
  line-height: 1.2;
  padding: 0 0.04em;
  transition: background-color 0.15s ease;
}
/* a word is a small target for a child's finger; the tap area reaches past it */
.pw::after {
  content: "";
  position: absolute;
  inset: -0.5rem -0.45rem;
}
.pw.on { background: var(--mark); color: var(--mark-ink); }
.pw.blank,
.pw.peek {
  min-width: 1.75em; /* a hidden "a" or "in" is still a blank you can see and tap */
  text-align: left;
  border-radius: 0;
  border-bottom: 2.5px solid var(--ink-faint);
}
.pw.blank .rest { color: transparent; }
.pw.peek { border-bottom-color: var(--sound); color: var(--sound); }
.again { margin-top: 1.5rem; }

/* ---------- Footer ---------- */
.foot {
  width: min(var(--measure), 100%);
  margin-inline: auto;
  padding: 2rem var(--gutter) 3rem;
  border-top: 1px solid var(--hair);
  color: var(--ink-soft);
  font-size: 0.95rem;
}
.foot p { max-width: 36rem; }
.foot p + p { margin-top: 0.5rem; }

/* ---------- Index of prayers ---------- */
.list { margin-top: clamp(2.25rem, 7vw, 3.25rem); list-style: none; }
.list li { border-top: 1px solid var(--hair); }
.list li:last-child { border-bottom: 1px solid var(--hair); }
.list a {
  display: block;
  padding: 1.25rem 0;
  color: inherit;
  text-decoration: none;
}
.list .name {
  display: block;
  font-family: var(--font-la);
  font-size: clamp(1.9rem, 7vw, 2.6rem);
  font-weight: 500;
  line-height: 1.1;
  transition: color 0.15s ease;
}
.list a:hover .name { color: var(--sound); }
.list .known-as { display: block; margin-top: 0.3rem; font-size: 1.1rem; }
.list .opening { display: block; margin-top: 0.15rem; color: var(--ink-soft); font-size: 1rem; }
.hero .page-title {
  font-family: var(--font-la);
  font-size: clamp(3rem, 13vw, 5.5rem);
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.015em;
}

/* keep the three toggles on one row on the smallest phones */
@media (max-width: 22.5rem) {
  .tools { gap: 0.4rem; }
  .tools .pill { gap: 0.35rem; padding: 0.3rem 0.65rem 0.3rem 0.55rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.001ms !important; }
}

@media print {
  .bar, .tools, .tabs, .lead, .say, .stepper, .again, .voice-note { display: none !important; }
  body { background: #fff; color: #000; }
}
