:root {
  --bleu: #1f3a6e; --bordeaux: #7a1f2b; --vert: #2e6b3a; --or: #b07d10;
  --creme: #fbf6e9; --vert-pale: #eef6ef; --fond: #f4f1ea; --texte: #1d1d1f; --gris: #5f5f66; --ligne: #e1dccf;
  --rayon: 14px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--fond); color: var(--texte);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.barre {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--bleu); color: #fff; padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top));
}
.barre-titre { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; }
.barre-titre svg { width: 22px; height: 22px; fill: #e9c46a; }
.barre .btn-fantome { color: #fff; border-color: rgba(255,255,255,.35); }

main { max-width: 860px; margin: 0 auto; padding: 16px; }
.carte { background: #fff; border-radius: var(--rayon); padding: 20px; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
h1 { font-size: 22px; margin: 0 0 6px; color: var(--bleu); }
.aide-intro { color: var(--gris); margin: 0 0 18px; font-size: 15px; }

.champ { display: block; margin-bottom: 14px; border: 0; padding: 0; min-width: 0; }
.champ > span, .champ > legend { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; color: #333; }
.champ em { font-weight: 400; color: var(--gris); font-style: normal; }
input[type=text], input[type=date], input[type=password], select, textarea {
  width: 100%; padding: 12px; border: 1.5px solid var(--ligne); border-radius: 10px; background: #fff; font-size: 16px;
  -webkit-appearance: none; appearance: none;
}
select { background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23555' stroke-width='2'/%3E%3C/svg%3E") no-repeat right 12px center; padding-right: 34px; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--bleu); box-shadow: 0 0 0 3px rgba(31,58,110,.12); }
fieldset.champ input { margin-bottom: 6px; }
.aide { display: block; color: var(--gris); font-size: 13px; margin-top: 5px; }
.ligne-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
@media (max-width: 560px) { .ligne-2 { grid-template-columns: 1fr; } }
.case { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; padding-top: 26px; margin-bottom: 14px; }
.case input { width: 20px; height: 20px; margin: 1px 0 0; accent-color: var(--bleu); flex: none; }
@media (max-width: 560px) { .case { padding-top: 0; } }

.suggestions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: -4px 0 14px; font-size: 13px; color: var(--gris); }
.puce { border: 1px solid var(--vert); color: var(--vert); background: var(--vert-pale); border-radius: 999px; padding: 5px 12px; font-size: 13px; cursor: pointer; }

.apercu-refs { margin: -6px 0 14px; display: grid; gap: 6px; }
.ref { border-radius: 10px; padding: 8px 12px; font-size: 14px; }
.ref.ok { background: var(--vert-pale); color: var(--vert); }
.ref.ok summary { cursor: pointer; font-weight: 600; list-style: none; }
.ref.ok summary::-webkit-details-marker { display: none; }
.ref.ok summary small { font-weight: 400; color: var(--gris); margin-left: 6px; }
.ref-texte { color: var(--texte); margin-top: 8px; max-height: 220px; overflow: auto; font-size: 14px; line-height: 1.6; }
.ref-texte sup { color: var(--vert); font-weight: 700; margin: 0 2px 0 4px; }
.ref.ko { background: #fdecec; color: #a12622; }

.options { border: 1.5px solid var(--ligne); border-radius: 12px; padding: 4px 14px; margin-bottom: 16px; }
.options summary { cursor: pointer; padding: 10px 0; font-weight: 600; color: var(--bleu); }
.options[open] summary { margin-bottom: 8px; }

.btn-principal {
  width: 100%; border: 0; border-radius: 12px; background: var(--bordeaux); color: #fff; font-weight: 700; font-size: 17px;
  padding: 15px; cursor: pointer;
}
.btn-principal:active { transform: translateY(1px); }
.btn { border: 1.5px solid var(--ligne); background: #fff; border-radius: 10px; padding: 8px 12px; cursor: pointer; font-size: 14px; font-weight: 600; color: var(--bleu); }
.btn:disabled { opacity: .45; cursor: default; }
.btn-fantome { border: 1.5px solid var(--ligne); background: transparent; border-radius: 10px; padding: 7px 12px; cursor: pointer; font-size: 14px; }
.btn-fantome.petit { padding: 4px 10px; font-size: 13px; }
.erreur { background: #fdecec; color: #a12622; border-radius: 10px; padding: 10px 12px; font-size: 14px; }

.actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.actions-droite { display: flex; gap: 6px; flex-wrap: wrap; }
@media (max-width: 560px) {
  .actions { position: sticky; top: 56px; z-index: 5; background: var(--fond); padding: 6px 0; }
  .actions-droite { width: 100%; display: grid; grid-template-columns: repeat(5, 1fr); }
  .actions-droite .btn { padding: 8px 4px; font-size: 12.5px; }
}

.progression { background: #fff; border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; align-items: center; }
.progression-texte { font-size: 14px; color: var(--bleu); font-weight: 600; display: flex; align-items: center; gap: 8px; }
.point { width: 9px; height: 9px; border-radius: 50%; background: var(--or); animation: pulse 1s infinite alternate; }
@keyframes pulse { to { opacity: .25; } }
.jauge { grid-column: 1 / -1; height: 6px; background: var(--ligne); border-radius: 3px; overflow: hidden; }
.jauge div { height: 100%; background: linear-gradient(90deg, var(--or), var(--bordeaux)); transition: width .6s; }

/* ---- Document (charte du Temple Emmanuel) ---- */
.document {
  background: #fff; border-radius: var(--rayon); padding: 28px 24px; box-shadow: 0 1px 3px rgba(0,0,0,.06);
  font-size: 17px; line-height: 1.7;
}
@media (max-width: 560px) { .document { padding: 20px 16px; font-size: 16.5px; } }
.doc-entete { text-align: center; border-bottom: 3px double var(--or); padding-bottom: 12px; margin-bottom: 18px; }
.e-eglise { font-weight: 700; color: var(--bleu); font-size: 15px; letter-spacing: .02em; }
.e-ligne { color: var(--bleu); font-size: 14px; }
.e-temple { font-weight: 800; color: var(--bordeaux); font-size: 18px; margin-top: 4px; }
.doc-titre { text-align: center; }
.d-sur { color: var(--bleu); font-weight: 800; font-size: 19px; letter-spacing: .02em; }
.d-date { color: var(--gris); }
.d-journee { color: var(--vert); font-weight: 700; }
.d-theme {
  margin: 16px 0; padding: 14px 12px; background: var(--creme); border-top: 2px solid var(--bordeaux); border-bottom: 2px solid var(--bordeaux);
  color: var(--bordeaux); font-weight: 800; font-size: 21px; line-height: 1.35;
}
.d-theme span { font-size: 15px; font-weight: 700; }
.d-textes { color: var(--vert); font-size: 15.5px; display: grid; gap: 2px; margin-top: 4px; }
.d-textes strong { color: var(--texte); font-size: 14px; margin-bottom: 2px; }
.d-pred { color: var(--gris); font-style: italic; font-size: 14px; margin-top: 4px; }
.sep { text-align: center; color: var(--or); letter-spacing: .5em; margin: 22px 0 16px; }
.document h2 { font-size: 18px; letter-spacing: .03em; margin: 0 0 12px; padding-bottom: 6px; border-bottom: 2px solid currentColor; }
.document h3 { font-size: 17px; color: var(--bleu); margin: 18px 0 6px; }
.c-or { color: var(--or); } .c-bleu { color: var(--bleu); } .c-vert { color: var(--vert) !important; } .c-bordeaux { color: var(--bordeaux); }
.document p { margin: 0 0 12px; }
.document blockquote {
  margin: 14px 0 16px; padding: 12px 16px; background: var(--vert-pale); border-left: 5px solid var(--vert);
  border-radius: 0 10px 10px 0; font-style: italic; color: #1e4d2b;
}
.document blockquote.meditation {
  text-align: center; background: var(--creme); border: 3px solid var(--or); border-radius: 12px;
  color: var(--bordeaux); font-weight: 700; font-size: 19px; padding: 18px;
}
.curseur { display: inline-block; width: 8px; height: 18px; background: var(--or); vertical-align: -3px; animation: pulse .6s infinite alternate; }
.editeur { width: 100%; font: 15px/1.6 ui-monospace, Menlo, Consolas, monospace; padding: 14px; border-radius: var(--rayon); border: 1.5px solid var(--ligne); }

/* ---- Panneaux ---- */
.panneau { position: fixed; inset: 0; z-index: 50; display: flex; justify-content: flex-end; }
.panneau-fond { position: absolute; inset: 0; background: rgba(0,0,0,.35); }
.panneau-contenu { position: relative; background: #fff; width: min(440px, 100%); height: 100%; overflow: auto; padding: 18px; padding-top: calc(18px + env(safe-area-inset-top)); }
.panneau-tete { display: flex; justify-content: space-between; align-items: center; }
.panneau-tete h2 { margin: 0; color: var(--bleu); font-size: 19px; }
#liste-historique { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 8px; }
#liste-historique li { display: flex; gap: 6px; }
.hist { flex: 1; text-align: left; background: var(--fond); border: 0; border-radius: 10px; padding: 10px 12px; cursor: pointer; display: grid; gap: 2px; }
.hist strong { color: var(--bordeaux); font-size: 15px; }
.hist span { font-size: 13px; color: var(--gris); }
.hist-refs { color: var(--vert) !important; }
.suppr { border: 0; background: transparent; color: var(--gris); cursor: pointer; font-size: 16px; padding: 0 8px; }
.vide { color: var(--gris); padding: 20px 0; }
#modal-code { justify-content: center; align-items: center; }
.modal { height: auto; width: min(380px, 92%); border-radius: var(--rayon); display: grid; gap: 12px; }
.modal h2 { margin: 0; color: var(--bleu); }

.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #222; color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 14px; z-index: 60; }

/* ---- Impression / PDF ---- */
@media print {
  @page { size: A4; margin: 18mm 16mm; }
  body { background: #fff; }
  .barre, .actions, .progression, #ecran-formulaire, .erreur, .toast, .panneau { display: none !important; }
  main { padding: 0; max-width: none; }
  .document { box-shadow: none; padding: 0; font-size: 12pt; line-height: 1.6; }
  .document h2, .document h3 { break-after: avoid; }
  .document blockquote, .d-theme { break-inside: avoid; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .curseur { display: none; }
}
.barre .btn-fantome { white-space: nowrap; }
@media (max-width: 420px) { .barre-titre { font-size: 15px; } .barre .btn-fantome { font-size: 13px; padding: 6px 10px; } }

/* ---- Lectionnaire ---- */
.bloc-lect { background: var(--creme); border: 1.5px solid #ead9a8; border-radius: 12px; padding: 12px 14px 2px; margin-bottom: 16px; }
.bloc-lect select { background-color: #fff; }
.lect-carte { margin: -2px 0 12px; font-size: 14px; display: grid; gap: 3px; }
.lc-tete { color: var(--or); font-weight: 700; font-size: 13px; }
.lc-theme { color: var(--bordeaux); font-weight: 700; font-size: 15.5px; }
.lc-ligne { color: #444; }
.lc-textes { color: var(--vert); font-weight: 600; }
.lc-offr { color: var(--gris); font-size: 12.5px; letter-spacing: .03em; }
.lect-carte .btn { justify-self: start; margin-top: 6px; }
.lc-ok { color: var(--vert); font-weight: 600; margin-top: 4px; }
.lien { border: 0; background: none; color: var(--gris); text-decoration: underline; cursor: pointer; padding: 0; font-size: 13px; font-weight: 400; }
.d-cant { color: var(--bleu); font-size: 15px; }

.pied { text-align: center; padding: 8px 0 28px; font-size: 13px; }
.pied a { color: var(--gris); }
@media print { .pied { display: none; } }
