:root {
  --bg: #f7f4ef;
  --bg-alt: #efe8db;
  --surface: #ffffff;
  --surface-alt: #faf8f4;
  --text: #2b2440;
  --text-muted: #6b6478;
  --accent: #6a4c93;
  --accent-strong: #55397a;
  --accent-contrast: #ffffff;
  --accent-soft: rgba(106, 76, 147, 0.1);
  --accent-soft-strong: rgba(106, 76, 147, 0.18);
  --border: #e2dcd3;
  --gold: #b8933a;
  --gold-soft: rgba(184, 147, 58, 0.14);
  --shadow: rgba(43, 36, 64, 0.1);
  --shadow-strong: rgba(43, 36, 64, 0.16);
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16121f;
    --bg-alt: #1c1728;
    --surface: #211b30;
    --surface-alt: #262038;
    --text: #ece7f5;
    --text-muted: #a99fc0;
    --accent: #9878c9;
    --accent-strong: #ac8ddb;
    --accent-contrast: #16121f;
    --accent-soft: rgba(152, 120, 201, 0.16);
    --accent-soft-strong: rgba(152, 120, 201, 0.28);
    --border: #362c4a;
    --gold: #d4b05e;
    --gold-soft: rgba(212, 176, 94, 0.16);
    --shadow: rgba(0, 0, 0, 0.3);
    --shadow-strong: rgba(0, 0, 0, 0.45);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: radial-gradient(ellipse at top, var(--bg-alt) 0%, var(--bg) 55%);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font-serif);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* --- En-tête ---------------------------------------------------------- */

.app-header {
  text-align: center;
  padding: 1.5rem 1rem 1.1rem;
  position: relative;
}

.app-header h1 {
  margin: 0;
  font-size: 1.45rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
}

.header-motif {
  width: 1.05em;
  height: 1.05em;
  color: var(--gold);
  flex-shrink: 0;
}

.app-header::after {
  content: "";
  display: block;
  width: 64px;
  height: 2px;
  margin: 0.7rem auto 0;
  border-radius: 2px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}

/* --- Sélecteur de langue (fr / en / la) --------------------------------- */

.lang-switch {
  --lang-btn-w: 2.6rem;
  position: relative;
  display: inline-flex;
  margin-top: 0.8rem;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: inset 0 1px 2px var(--shadow);
}

/* Pastille glissante : c'est elle qui marque la langue active. */
.lang-switch-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: var(--lang-btn-w);
  height: calc(100% - 6px);
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  box-shadow: 0 2px 8px var(--accent-soft-strong);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

.lang-btn {
  position: relative;
  z-index: 1;
  width: var(--lang-btn-w);
  padding: 0.3rem 0;
  border: none;
  background: none;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: color 0.2s ease;
}

.lang-btn.active {
  color: var(--accent-contrast);
}

.lang-btn:not(.active):hover {
  color: var(--accent);
}

@media (prefers-reduced-motion: reduce) {
  .lang-switch-thumb {
    transition: none;
  }
}

#app {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 1.1rem 6rem;
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
}

.tab-panel h2 {
  font-size: 1.1rem;
  color: var(--accent);
  margin: 1.4rem 0 0.7rem;
  letter-spacing: 0.02em;
}

.today-date {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.95rem;
  margin: 0.6rem 0 1.1rem;
  letter-spacing: 0.02em;
}

/* Seule l'initiale : `capitalize` donnerait « Feria Quinta » en latin. */
.today-date::first-letter {
  text-transform: uppercase;
}

/* --- Sélecteur de série ------------------------------------------------- */

.series-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin-bottom: 0.5rem;
}

.series-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease,
    box-shadow 0.15s ease, transform 0.1s ease;
}

.series-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent-soft-strong);
}

.series-btn:active {
  transform: scale(0.97);
}

.series-btn.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: var(--accent-contrast);
  border-color: transparent;
  box-shadow: 0 3px 10px var(--accent-soft-strong);
}

.series-btn.is-today:not(.active)::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 0.4rem;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 5px var(--gold);
  vertical-align: middle;
}

/* --- Liste des mystères -------------------------------------------------- */

.mystery-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.mystery-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--gold);
  border-radius: 14px;
  padding: 0.95rem 1.1rem;
  box-shadow: 0 1px 2px var(--shadow);
}

.mystery-item-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.45rem;
}

.mystery-index {
  flex-shrink: 0;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 50%;
  background: var(--gold-soft);
  color: var(--gold);
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mystery-item h3 {
  margin: 0;
  font-size: 1.03rem;
  color: var(--text);
}

.mystery-ref {
  margin: 0 0 0.45rem;
  font-size: 0.85rem;
  color: var(--gold);
  font-style: italic;
}

.mystery-meditation {
  margin: 0;
  font-size: 0.94rem;
  line-height: 1.6;
  color: var(--text-muted);
}

/* --- Boutons ------------------------------------------------------------- */

.btn-primary {
  display: block;
  width: 100%;
  padding: 0.95rem;
  margin: 1.3rem 0 0.5rem;
  border: none;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: var(--accent-contrast);
  font-size: 1rem;
  font-family: var(--font-sans);
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: 0 6px 16px var(--accent-soft-strong);
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}

.btn-primary:hover {
  filter: brightness(1.06);
}

.btn-primary:active {
  transform: translateY(1px);
  box-shadow: 0 3px 10px var(--accent-soft-strong);
}

.btn-secondary {
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.btn-secondary:hover:not(:disabled) {
  background: var(--accent-soft);
  border-color: var(--accent-soft-strong);
}

.btn-secondary:active:not(:disabled) {
  transform: scale(0.97);
}

.btn-secondary:disabled {
  opacity: 0.4;
  cursor: default;
}

.btn-link {
  display: block;
  margin: 0.7rem auto 0;
  background: none;
  border: none;
  color: var(--text-muted);
  text-decoration: underline;
  text-underline-offset: 2px;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  cursor: pointer;
  transition: color 0.15s ease;
}

.btn-link:hover {
  color: var(--accent);
}

/* --- Onglet Prier ---------------------------------------------------------- */

/* --- Interrupteur latin (onglet Prier) ---------------------------------- */

.latin-row {
  display: flex;
  justify-content: flex-end;
  margin: 0.4rem 0 0.2rem;
}

.latin-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.3rem 0.6rem 0.3rem 0.35rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.latin-switch.on {
  color: var(--accent);
  border-color: var(--accent-soft-strong);
}

.latin-switch-track {
  position: relative;
  width: 1.85rem;
  height: 1.05rem;
  border-radius: 999px;
  background: var(--border);
  transition: background-color 0.24s ease;
}

.latin-switch.on .latin-switch-track {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
}

.latin-switch-thumb {
  position: absolute;
  top: 0.13rem;
  left: 0.13rem;
  width: 0.79rem;
  height: 0.79rem;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 3px var(--shadow-strong);
  transition: transform 0.24s cubic-bezier(0.4, 0, 0.2, 1);
}

.latin-switch.on .latin-switch-thumb {
  transform: translateX(0.8rem);
}

@media (prefers-reduced-motion: reduce) {
  .latin-switch-thumb,
  .latin-switch-track {
    transition: none;
  }
}

.pray-progress {
  margin: 0.6rem 0 0.3rem;
}

.pray-progress-text {
  text-align: center;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.8rem;
  letter-spacing: 0.02em;
  margin: 0 0 0.4rem;
}

.pray-progress-bar {
  height: 4px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
  max-width: 340px;
  margin: 0 auto;
}

.pray-progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--gold), var(--accent));
  transition: width 0.3s ease;
}

.rosary-svg {
  width: 100%;
  max-width: 340px;
  display: block;
  margin: 1.3rem auto 0.5rem;
  overflow: visible;
}

.rosary-chain line {
  stroke: var(--border);
  stroke-width: 2;
}

.bead {
  fill: var(--surface);
  stroke: var(--gold);
  stroke-width: 1.5;
  transition: fill 0.25s ease, stroke 0.25s ease, filter 0.25s ease;
}

.bead-cross rect {
  fill: var(--gold);
  transition: fill 0.25s ease;
}

.bead.done {
  fill: var(--gold);
  opacity: 0.55;
}

.bead.current {
  fill: var(--accent);
  stroke: var(--accent);
  filter: drop-shadow(0 0 5px var(--accent-soft-strong)) drop-shadow(0 0 2px var(--accent));
}

.bead-cross.current rect {
  fill: var(--accent);
}

.pray-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.1rem 1.2rem;
  margin: 0.9rem 0;
  min-height: 5rem;
  box-shadow: 0 2px 10px var(--shadow);
}

.pray-card.step-enter {
  animation: step-fade 0.28s ease;
}

@keyframes step-fade {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.pray-card h2 {
  margin: 0 0 0.5rem;
  font-size: 1.08rem;
  color: var(--accent);
}

.prayer-text {
  white-space: pre-wrap;
  line-height: 1.65;
  font-size: 1rem;
}

.prayer-text.placeholder {
  font-style: italic;
  color: var(--text-muted);
}

.pray-controls {
  display: flex;
  gap: 0.6rem;
  align-items: stretch;
}

.pray-controls .btn-tap {
  flex: 2;
  margin: 0;
  font-size: 1.05rem;
  padding: 1.1rem;
}

.pray-controls .btn-secondary {
  flex: 1;
}

/* `display: flex` primerait sur le `display: none` de l'attribut hidden. */
.btn-skip[hidden] {
  display: none;
}

.btn-skip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  width: 100%;
  margin-top: 0.6rem;
  padding: 0.6rem;
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: none;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
}

.btn-skip:hover {
  color: var(--accent);
  border-color: var(--accent-soft-strong);
  background: var(--accent-soft);
}

.btn-skip svg {
  width: 1rem;
  height: 1rem;
}

/* --- Onglet Prières : bibliothèque ------------------------------------------ */

.prayer-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.95rem 1.1rem;
  box-shadow: 0 1px 2px var(--shadow);
}

/* Barre de recherche + filtres, collée en haut pendant le défilement. */
.library-toolbar {
  position: sticky;
  top: 0;
  z-index: 2;
  margin: 0 -1.1rem;
  padding: 0.6rem 1.1rem 0.5rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.library-search {
  position: relative;
  display: flex;
  align-items: center;
}

.library-search-icon {
  position: absolute;
  left: 0.8rem;
  width: 1.1rem;
  height: 1.1rem;
  color: var(--text-muted);
  pointer-events: none;
}

#library-search {
  width: 100%;
  padding: 0.7rem 2.4rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 0.92rem;
  appearance: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

#library-search::-webkit-search-cancel-button {
  display: none;
}

#library-search:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* `display: flex` primerait sur le `display: none` de l'attribut hidden. */
.library-search-clear[hidden] {
  display: none;
}

.library-search-clear {
  position: absolute;
  right: 0.5rem;
  width: 1.7rem;
  height: 1.7rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
}

/* Hors français : rappel que la traduction est libre et encore partielle. */
.library-note[hidden] {
  display: none;
}

.library-note {
  margin: 0.5rem 0 0.1rem;
  font-size: 0.78rem;
  font-style: italic;
  text-align: center;
  color: var(--text-muted);
}

.library-empty {
  text-align: center;
  color: var(--text-muted);
  font-style: italic;
  margin: 2.5rem 0;
}

/* Fil d'Ariane : retour au dossier parent. */
.library-crumb {
  margin: 0.8rem 0 0.2rem;
}

.library-back {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.35rem 0.7rem 0.35rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--accent);
  font-family: var(--font-sans);
  font-size: 0.82rem;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.library-back:hover {
  background: var(--accent-soft);
  border-color: var(--accent-soft-strong);
}

.library-back svg {
  width: 1.05rem;
  height: 1.05rem;
}

/* Doit primer sur `.tab-panel h2` (spécificité supérieure). */
.tab-panel .library-heading {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  font-family: var(--font-sans);
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 1rem 0 0.7rem;
}

.library-count {
  font-size: 0.72rem;
  letter-spacing: 0;
  padding: 0.08rem 0.42rem;
  border-radius: 999px;
  background: var(--gold-soft);
  color: var(--gold);
  flex-shrink: 0;
}

/* Lignes de navigation : dossiers et prières. */
.library-row {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  width: 100%;
  margin-bottom: 0.4rem;
  padding: 0.8rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 1px 2px var(--shadow);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease,
    transform 0.1s ease;
}

.library-row:hover {
  border-color: var(--accent-soft-strong);
  background: var(--surface-alt);
}

.library-row:active {
  transform: scale(0.99);
}

.row-icon {
  flex-shrink: 0;
  width: 1.55rem;
  height: 1.55rem;
  color: var(--gold);
}

.library-row-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.library-row-title {
  color: var(--accent);
  font-size: 0.98rem;
  line-height: 1.35;
}

.library-row-sub {
  font-family: var(--font-sans);
  font-size: 0.76rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.library-row-chevron {
  flex-shrink: 0;
  width: 0.45rem;
  height: 0.45rem;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  transform: rotate(-45deg);
}

/* Vue lecture d'une prière. */
.library-reader {
  padding: 1.1rem 1.2rem 1.2rem;
  animation: step-fade 0.24s ease;
}

.tab-panel .library-reader-title {
  margin: 0 0 0.8rem;
  font-size: 1.2rem;
  color: var(--accent);
  line-height: 1.3;
}

.library-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.7rem;
}

.library-chip {
  font-family: var(--font-sans);
  font-size: 0.72rem;
  padding: 0.16rem 0.55rem;
  border-radius: 999px;
  white-space: nowrap;
}

.library-chip-type {
  background: var(--accent-soft);
  color: var(--accent);
}

.library-chip-plain {
  background: var(--gold-soft);
  color: var(--gold);
}

.library-patronage {
  font-family: var(--font-sans);
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--text-muted);
  margin: 0 0 0.75rem;
}

/* Avertissement de traduction libre : lisible, mais nettement en retrait
   du texte de la prière. */
.library-free-translation {
  font-family: var(--font-sans);
  font-size: 0.74rem;
  line-height: 1.5;
  color: var(--text-muted);
  margin: 0 0 0.9rem;
  padding-left: 0.6rem;
  border-left: 2px solid var(--accent-soft-strong);
}

.library-reader .prayer-text {
  margin: 0 0 0.85rem;
  font-size: 0.98rem;
}

.library-reader .prayer-text:last-child {
  margin-bottom: 0;
}

.library-reader em {
  color: var(--text-muted);
  font-style: italic;
}

.library-subtitle {
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--gold);
  margin: 1.1rem 0 0.5rem;
}

.library-list {
  margin: 0 0 0.85rem;
  padding-left: 1.1rem;
  line-height: 1.6;
  font-size: 0.98rem;
}

.library-list li {
  margin-bottom: 0.2rem;
}

.library-source {
  display: inline-block;
  margin-top: 0.3rem;
  font-family: var(--font-sans);
  font-size: 0.76rem;
  color: var(--text-muted);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.library-source:hover {
  color: var(--accent);
}

/* --- Navigation basse ------------------------------------------------------- */

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 16px var(--shadow);
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  padding: 0.7rem 0.4rem 0.6rem;
  border: none;
  background: none;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.78rem;
  cursor: pointer;
  position: relative;
  transition: color 0.15s ease;
}

.nav-btn .nav-icon {
  width: 1.35rem;
  height: 1.35rem;
}

.nav-btn::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  width: 22px;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--accent);
  transform: translateX(-50%) scaleX(0);
  transition: transform 0.2s ease;
}

.nav-btn.active {
  color: var(--accent);
  font-weight: 600;
}

.nav-btn.active::before {
  transform: translateX(-50%) scaleX(1);
}
