:root {
  --bg: #f5f3ef;
  --fg: #2b2b2b;
  --accent: #6D9DF0;
  --accent-dark: #4877c8;
  --muted: #6b6b6b;
  --border: #d8d2c4;
  --card: #fffefb;
  --highlight: #fff59d;
  /* Lien Signet déjà visité — vert d'eau désaturé qui se distingue du jaune
     (réservé aux liens cliquables non-visités) sans crier. */
  --visited-link: #b9d8c2;
  --visited-link-fg: #2b2b2b;
  /* Safe-area iOS (notch + home indicator) */
  --safe-top: env(safe-area-inset-top, 0);
  --safe-bottom: env(safe-area-inset-bottom, 0);
  --safe-left: env(safe-area-inset-left, 0);
  --safe-right: env(safe-area-inset-right, 0);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.5;
}
header.topbar {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 4px rgba(0,0,0,0.04);
}
header.topbar .logo { font-weight: 700; font-size: 18px; color: var(--accent-dark); }
header.topbar .spacer { flex: 1; }
header.topbar select, header.topbar input {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: white;
  font: inherit;
}
header.topbar button {
  padding: 6px 12px;
  border: 1px solid var(--border);
  background: var(--accent);
  color: white;
  border-radius: 4px;
  cursor: pointer;
  font: inherit;
}
header.topbar button:hover { background: var(--accent-dark); }
header.topbar button.ghost { background: transparent; color: var(--fg); }
header.topbar button.ghost:hover { background: rgba(0,0,0,0.05); }
header.topbar a { color: var(--accent-dark); text-decoration: none; }
header.topbar a:hover { text-decoration: underline; }

main { max-width: 920px; margin: 24px auto; padding: 0 16px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 24px;
  margin-bottom: 16px;
}

.btn {
  padding: 8px 16px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  border-radius: 4px;
  cursor: pointer;
  font: inherit;
}
.btn:hover { background: var(--accent-dark); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--accent-dark); }

input[type=email], input[type=text] {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font: inherit;
  width: 100%;
}

.error { color: #b53737; padding: 8px; background: #fee; border-radius: 4px; }
.info  { color: var(--muted); }

.grid-months {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}
.month {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
}
.month h3 {
  margin: 0 0 8px;
  font-size: 16px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--accent-dark);
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
}
.month .day {
  display: block;
  padding: 4px 6px;
  margin: 1px 0;
  border-radius: 3px;
  cursor: pointer;
  font-size: 14px;
  text-decoration: none;
  color: var(--fg);
}
.month .day:hover { background: var(--bg); }
.month .day .ref { color: var(--muted); font-size: 12px; }
.month .day.today {
  background: var(--highlight);
  font-weight: 600;
  color: var(--accent-dark);
}
.month .day.today:hover { background: #ffe066; }

.passage { margin: 24px 0; }
.passage h2 {
  font-size: 22px;
  letter-spacing: 1px;
  color: var(--accent-dark);
  border-bottom: 2px solid var(--border);
  padding-bottom: 4px;
}
.passage h3 {
  font-size: 16px;
  font-weight: normal;
  font-style: italic;
  color: var(--muted);
  margin-top: 0;
}
.verse { margin: 6px 0; }
.verse .num {
  display: inline-block;
  font-size: 11px;
  color: var(--accent-dark);
  vertical-align: super;
  margin-right: 3px;
  font-weight: bold;
}
.verse a {
  color: inherit;
  text-decoration: none;
  background: linear-gradient(to bottom, transparent 65%, var(--highlight) 65%);
  padding: 0 1px;
}
.verse a:hover { background: var(--highlight); }

/* Lien Signet déjà visité — couleur de soulignage différente pour distinguer
   visité / non-visité. La couleur du texte reste lisible. */
.verse a.signet-link.visited {
  background: linear-gradient(to bottom, transparent 65%, var(--visited-link) 65%);
  color: var(--visited-link-fg);
}
.verse a.signet-link.visited:hover { background: var(--visited-link); }

/* Modal overlay (signet) */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(20, 18, 12, 0.55);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  padding: 16px;
  animation: bm-fade 120ms ease-out;
}
.modal-card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.25);
  max-width: min(720px, 92vw);
  max-height: 84vh;
  width: auto;
  overflow: hidden;
  display: flex; flex-direction: column;
  animation: bm-pop 140ms ease-out;
}
.modal-close {
  position: absolute; top: 8px; right: 12px;
  background: transparent; border: none;
  font-size: 26px; line-height: 1; cursor: pointer;
  color: var(--muted); padding: 4px 8px; border-radius: 4px;
}
.modal-close:hover { background: rgba(0,0,0,0.06); color: var(--fg); }
.modal-content {
  padding: 24px 28px 20px;
  overflow-y: auto;
}
.modal-title { margin: 0 28px 8px 0; color: var(--accent-dark); font-size: 20px; }
.modal-main { font-size: 16px; margin: 8px 0 12px; }
.modal-content .related {
  border-left: 3px solid var(--accent);
  padding-left: 14px; margin-top: 12px;
}
.modal-content .related .item { margin-bottom: 10px; }
.modal-content .related .item .ref {
  font-weight: bold; color: var(--accent-dark); font-size: 14px;
}

body.modal-open { overflow: hidden; }

@keyframes bm-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes bm-pop  { from { opacity: 0; transform: translateY(8px) scale(.98); }
                     to   { opacity: 1; transform: none; } }

/* Passages "Palatino" : citations Word d'origine en italique gras.
   Pas de surlignage — le jaune (--highlight) est déjà utilisé pour le
   soulignage des liens cliquables ; doubler créerait de la confusion. */
.verse .palatino,
.passage .palatino {
  font-family: "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  font-weight: bold;
  font-style: italic;
}

.passage .section { margin-bottom: 16px; }
.passage .section h3 {
  font-size: 16px;
  font-weight: normal;
  font-style: italic;
  color: var(--muted);
  margin: 16px 0 6px;
}
.passage .verses-block { margin-bottom: 4px; }

.search-results .result {
  border-bottom: 1px solid var(--border);
  padding: 12px 0;
}
.search-results .ref {
  font-weight: bold;
  color: var(--accent-dark);
  font-size: 14px;
}
.search-results .meta {
  font-size: 11px;
  color: var(--muted);
  margin-left: 8px;
}
.search-results .snip { margin-top: 4px; }
.search-results .snip b { background: var(--highlight); padding: 0 2px; }

.signet .related {
  border-left: 3px solid var(--accent);
  padding-left: 16px;
  margin-top: 16px;
}
.signet .related .item { margin-bottom: 12px; }
.signet .related .item .ref { font-weight: bold; color: var(--accent-dark); }

footer.bottom {
  margin: 32px auto 16px;
  text-align: center;
  font-size: 11px;
  color: var(--muted);
}

/* ===========================================================
   Mobile (< 720 px) — ajustements pour les apps Android/iOS
   et les navigateurs mobiles.
   =========================================================== */
@media (max-width: 720px) {
  /* Typo : system font sur mobile (lisibilité native + perf) */
  html, body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 "Helvetica Neue", Arial, sans-serif;
    /* Empêche les double-tap zoom sur iOS sans bloquer le pinch-zoom */
    touch-action: manipulation;
    -webkit-text-size-adjust: 100%;
  }
  body {
    /* Safe-area iOS bottom (home indicator) */
    padding-bottom: var(--safe-bottom);
  }

  /* Topbar : flou translucide façon iOS, safe-area top, plus dense */
  header.topbar {
    flex-wrap: wrap;
    gap: 6px;
    padding: calc(8px + var(--safe-top)) 10px 8px;
    background: rgba(255, 254, 251, 0.85);
    backdrop-filter: saturate(180%) blur(14px);
    -webkit-backdrop-filter: saturate(180%) blur(14px);
  }
  header.topbar .logo { font-size: 16px; }
  header.topbar .spacer { display: none; }
  header.topbar select,
  header.topbar input,
  header.topbar button {
    font-size: 15px;
    padding: 8px 10px;
    min-height: 40px;       /* touch-target — Apple HIG : 44 px idéal, 40 ok */
  }

  main {
    margin: 12px auto;
    padding: 0 max(10px, var(--safe-left)) 0 max(10px, var(--safe-right));
  }
  .card { padding: 16px; }

  /* Calendrier : 1 colonne, headers sticky (le mois reste visible en scroll) */
  .grid-months { grid-template-columns: 1fr; gap: 8px; }
  .month { padding: 10px; }
  .month h3 {
    position: sticky;
    top: calc(48px + var(--safe-top));   /* sous le topbar */
    background: var(--card);
    margin: -10px -10px 8px;
    padding: 10px;
    z-index: 5;
  }
  .month .day {
    font-size: 16px;
    padding: 12px 10px;     /* touch-target */
    min-height: 44px;
    margin: 2px 0;
    display: flex;
    align-items: center;
  }

  /* Lecture du jour */
  .passage h2 { font-size: 18px; }
  .passage h3 { font-size: 14px; }
  .verse { font-size: 17px; line-height: 1.6; }
  .verse .num { font-size: 12px; }

  /* Boutons : tous touch-friendly */
  .btn {
    padding: 12px 18px;
    font-size: 16px;
    min-height: 44px;
  }

  /* Recherche : input fullscreen + bouton large */
  input[type=email], input[type=text] {
    padding: 12px 14px;
    font-size: 16px;        /* ≥ 16px évite le zoom auto iOS sur focus */
    min-height: 44px;
  }

  /* Footer collé en bas avec safe-area */
  footer.bottom {
    padding-bottom: var(--safe-bottom);
  }
}

/* Plus petit encore (téléphones étroits, < 380 px) */
@media (max-width: 380px) {
  .card { padding: 12px; }
  .verse { font-size: 16px; }
  header.topbar { gap: 4px; padding: calc(6px + var(--safe-top)) 8px 6px; }
}
