:root {
  --eu-blue: #003399;      /* bleu du drapeau européen */
  --eu-blue-dark: #002266;
  --eu-gold: #ffcc00;       /* jaune des étoiles */
  --eu-gold-ink: #7a5a00;
  --bg: #f4f6fc;
  --card: #ffffff;
  --ink: #1a1f2e;
  --muted: #5b6478;
  --line: #d7ddee;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

/* emblème dans le coin */
#emblem {
  position: fixed;
  top: 10px;
  right: 12px;
  width: 76px;
  height: 76px;
  z-index: 60;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .35);
}

header {
  background: var(--eu-blue);
  color: #fff;
  padding: 1.3rem 1.2rem 1.4rem;
  border-bottom: 4px solid var(--eu-gold);
}
.header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding-right: 90px;           /* place pour l'emblème */
}
header h1 { margin: 0; font-size: 1.4rem; }
header p { margin: .5rem 0 0; max-width: 62ch; color: #dfe6ff; font-size: .95rem; }

.ui-lang {
  display: flex;
  flex-direction: column;
  gap: .2rem;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: #cdd7ff;
}
.ui-lang select {
  font-size: .9rem;
  padding: .3rem .4rem;
  border-radius: 6px;
  border: 1px solid var(--eu-blue-dark);
}

main { max-width: 900px; margin: 0 auto; padding: 1.2rem; }
section { margin-bottom: 2rem; }

h2 {
  font-size: 1.05rem;
  border-bottom: 2px solid var(--line);
  padding-bottom: .3rem;
  margin: 0 0 .9rem;
}
h2 small { font-weight: 400; color: var(--muted); }
.counter { float: right; font-weight: 400; color: var(--muted); font-size: .9rem; }

/* chips langues */
.chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.chip {
  display: inline-flex; align-items: center; gap: .4rem;
  border: 1.5px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 999px; padding: .4rem .8rem; font-size: .9rem; cursor: pointer;
}
.chip:hover:not(:disabled) { border-color: var(--eu-blue); }
.chip.on { background: var(--eu-blue); border-color: var(--eu-blue); color: #fff; }
.chip.on .flag-abbr { background: var(--eu-gold); color: var(--eu-gold-ink); }
.chip:disabled { opacity: .4; cursor: not-allowed; }

.flag { font-size: 1.1rem; line-height: 1; }
.flag-img {
  width: 1.35em; height: 1em; object-fit: cover; flex-shrink: 0;
  border-radius: 2px; box-shadow: 0 0 0 1px rgba(0, 0, 0, .15); vertical-align: -.12em;
}
.flag-abbr {
  font: 700 .62rem/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--eu-blue); color: #fff;
  padding: .18rem .3rem; border-radius: 4px; letter-spacing: .02em;
}

.info { color: var(--muted); margin-bottom: 1rem; font-size: .95rem; }

/* cartes chant */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; padding: .9rem 1rem; margin-bottom: .9rem;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: .8rem; }
.card h3 { margin: 0; font-size: 1.05rem; color: var(--eu-blue-dark); }
.canonical { font-weight: 400; font-size: .8em; color: var(--muted); margin-left: .45rem; }
#tray-list .canonical { display: block; margin: 0; font-size: .78em; }
.badges { display: flex; gap: .25rem; flex-wrap: wrap; flex-shrink: 0; }
.badge { font-size: .95rem; opacity: .85; }

.add-btn {
  display: inline-flex; align-items: center; gap: .4rem;
  margin-top: .5rem;
  border: 1.5px solid var(--eu-blue); background: #fff; color: var(--eu-blue);
  border-radius: 8px; padding: .35rem .7rem; font-size: .85rem; cursor: pointer;
}
.add-btn:hover { background: #eef2ff; }
.add-btn.on { background: var(--eu-blue); color: #fff; }
.add-btn svg { width: 16px; height: 16px; }

.media { margin: .5rem 0 .2rem; display: flex; flex-wrap: wrap; gap: .5rem; }
.media-link {
  font-size: .8rem; color: var(--eu-gold-ink); text-decoration: none;
  border: 1px solid var(--line); border-radius: 6px; padding: .1rem .5rem;
}
.media-link:hover { background: #fff8dd; border-color: var(--eu-gold); }

.version {
  display: grid; grid-template-columns: 160px 1fr; gap: .8rem;
  padding: .6rem 0; border-top: 1px dashed var(--line);
}
.version:first-of-type { border-top: 1px solid var(--line); margin-top: .5rem; }
.v-label { display: flex; align-items: center; gap: .4rem; }
.v-lang { font-weight: 600; font-size: .9rem; }
.v-title { font-style: italic; margin-bottom: .2rem; }
.no-lyrics { color: var(--muted); font-size: .85rem; }

.lyrics summary { cursor: pointer; color: var(--eu-blue); font-size: .85rem; }
.lyrics pre {
  white-space: pre-wrap; font: inherit;
  background: #f0f3ff; border-left: 3px solid var(--eu-gold);
  border-radius: 4px; padding: .7rem .9rem; margin: .5rem 0 0;
}

#apart details {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; padding: .7rem 1rem; margin-bottom: .8rem;
}
#apart summary { cursor: pointer; font-weight: 600; }
#apart .card.apart { border: none; border-top: 1px solid var(--line); border-radius: 0; padding: .7rem 0; }

/* index alphabétique par langue (en bas de page) */
#index-az { margin-top: 2.5rem; }
#az-box > summary {
  cursor: pointer; color: var(--eu-blue-dark); font-size: 1.05rem; font-weight: 600;
  list-style: none;
  border-bottom: 2px solid var(--line); padding-bottom: .3rem;
}
#az-box > summary::-webkit-details-marker { display: none; }
#az-box > summary::before { content: "▸ "; color: var(--muted); }
#az-box[open] > summary::before { content: "▾ "; }
#az-box > summary:hover { color: var(--eu-blue); }
#az-body { margin-top: .6rem; }
.az-lang { border-bottom: 1px solid var(--line); }
.az-lang > summary {
  cursor: pointer; padding: .5rem 0; font-size: .95rem; font-weight: 700;
  color: var(--eu-blue-dark);
  display: flex; align-items: center; gap: .4rem;
  list-style: none;
}
.az-lang > summary::-webkit-details-marker { display: none; }
.az-lang > summary::before { content: "▸"; color: var(--muted); width: .8em; }
.az-lang[open] > summary::before { content: "▾"; }
.az-lang > summary:hover { color: var(--eu-blue); }
.az-count { font-weight: 400; color: var(--muted); }
.az-songs { display: flex; flex-direction: column; gap: 0; padding: 0 0 .6rem 1.2rem; }
.az-song { border-bottom: 1px dashed var(--line); }
.az-song summary {
  cursor: pointer; padding: .4rem 0; font-size: .95rem; color: var(--ink);
  display: flex; align-items: center; gap: .6rem;
  list-style: none;
}
.az-song summary::-webkit-details-marker { display: none; }
.az-song summary::before { content: "▸"; color: var(--muted); width: .8em; flex-shrink: 0; }
.az-song[open] summary::before { content: "▾"; }
.az-title { flex: 1 1 auto; min-width: 0; }
.az-also { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .2rem; max-width: 55%; }
.az-flag {
  display: inline-flex; padding: 2px; border: none; border-radius: 3px;
  background: none; cursor: pointer; line-height: 0;
}
.az-flag:hover, .az-flag:focus-visible { background: #dfe6ff; }
.az-flag .flag-img { width: 1.15em; height: .86em; }
.az-song summary:hover { color: var(--eu-blue); }
.az-song pre {
  white-space: pre-wrap; font: inherit; font-size: .88rem;
  background: #f0f3ff; border-left: 3px solid var(--eu-gold);
  border-radius: 4px; padding: .7rem .9rem; margin: 0 0 .5rem;
}
.az-song .no-lyrics { font-size: .85rem; margin: 0 0 .5rem; }
.az-song { scroll-margin-top: 1rem; }
.az-song.flash > summary { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: #fff1b3; } to { background: transparent; } }

/* recherche : volontairement discrète */
.search { position: relative; width: min(240px, 100%); margin-left: auto; }
#search-input {
  width: 100%; font: inherit; font-size: .85rem;
  padding: .3rem .6rem; border: 1px solid var(--line); border-radius: 6px;
  background: var(--card); color: var(--ink);
}
#search-input:focus { outline: 2px solid var(--eu-blue); outline-offset: -1px; border-color: var(--eu-blue); }
#search-results {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 50;
  width: min(320px, calc(100vw - 2.4rem)); max-height: 50vh; overflow: auto;
  list-style: none; margin: 0; padding: .25rem 0;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .15);
}
#search-results button {
  display: flex; align-items: center; gap: .45rem; width: 100%;
  background: none; border: none; text-align: left; cursor: pointer;
  padding: .35rem .7rem; font: inherit; font-size: .85rem; color: var(--ink);
}
#search-results button:hover, #search-results button:focus { background: #eef2ff; }
.search-none { padding: .35rem .7rem; font-size: .85rem; color: var(--muted); }

/* onglets veillée / spirituels + recherche */
.top-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: .8rem;
  margin-bottom: 1.4rem;
}
.themes { display: flex; gap: .4rem; flex-wrap: wrap; }
.themes button {
  border: 1.5px solid var(--eu-blue); background: var(--card); color: var(--eu-blue);
  border-radius: 8px; padding: .45rem .9rem; font: inherit; font-size: .95rem;
  font-weight: 600; cursor: pointer;
}
.themes button:hover { background: #eef2ff; }
.themes button.on { background: var(--eu-blue); color: #fff; }
.theme-count { font-weight: 400; opacity: .75; font-size: .85em; }

/* contact : bouton sous les langues + fenêtre formulaire */
.header-side { display: flex; flex-direction: column; align-items: stretch; gap: .4rem; flex-shrink: 0; }
.header-side .contact-btn { padding: .25rem .7rem; font-size: .85rem; }
.contact-btn {
  border: 1.5px solid var(--eu-gold); background: #fff8dd; color: var(--eu-gold-ink);
  border-radius: 8px; padding: .4rem .9rem; font: inherit; font-size: .9rem;
  font-weight: 600; cursor: pointer;
}
.contact-btn:hover { background: var(--eu-gold); color: var(--ink); }
@media (max-width: 560px) { .header-side { align-items: flex-start; } }

#contact-dialog {
  width: min(520px, calc(100vw - 24px)); max-height: calc(100vh - 24px);
  border: none; border-top: 4px solid var(--eu-gold); border-radius: 12px;
  padding: 1.1rem 1.2rem; background: var(--card); color: var(--ink);
  box-shadow: 0 10px 40px rgba(0, 0, 0, .3);
}
#contact-dialog::backdrop { background: rgba(0, 20, 60, .45); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; }
.dlg-head h2 { border: none; margin: 0; padding: 0; color: var(--eu-blue-dark); font-size: 1.15rem; }
.dlg-head .link { font-size: 1.1rem; }
.dlg-intro { margin: .5rem 0 .3rem; font-size: .92rem; }
.dlg-who { margin: 0 0 .9rem; font-size: .85rem; color: var(--muted); }
#contact-form label {
  display: flex; flex-direction: column; gap: .2rem;
  font-size: .85rem; font-weight: 600; margin-bottom: .65rem;
}
.f-row { display: flex; gap: .7rem; }
.f-row label { flex: 1 1 0; min-width: 0; }
#contact-form input, #contact-form select, #contact-form textarea {
  font: inherit; font-size: .92rem; font-weight: 400; color: var(--ink);
  padding: .4rem .55rem; border: 1px solid var(--line); border-radius: 6px; background: #fff;
}
#contact-form textarea { resize: vertical; min-height: 6rem; }
#contact-form :is(input, select, textarea):focus {
  outline: 2px solid var(--eu-blue); outline-offset: -1px; border-color: var(--eu-blue);
}
.honey { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.dlg-status { font-size: .88rem; min-height: 1.2em; }
.dlg-status.ok { color: #1d6b2f; font-weight: 600; }
.dlg-status.err { color: #a12a1f; }
.dlg-status a { color: var(--eu-blue); word-break: break-all; }
.dlg-actions { display: flex; justify-content: flex-end; margin-top: .4rem; }
#contact-send {
  border: none; border-radius: 8px; padding: .5rem 1.2rem;
  font: inherit; font-weight: 600; cursor: pointer;
  background: var(--eu-blue); color: #fff;
}
#contact-send:hover { background: var(--eu-blue-dark); }
#contact-send:disabled { opacity: .5; cursor: wait; }
@media (max-width: 560px) { .f-row { flex-direction: column; gap: 0; } }

footer {
  max-width: 900px; margin: 0 auto; padding: 1rem 1.2rem 6rem;
  color: var(--muted); font-size: .8rem;
}
code { background: #eef2ff; padding: .05rem .35rem; border-radius: 4px; }

/* panneau carnet (style « panier ») */
#tray {
  position: fixed; right: 12px; bottom: 12px; z-index: 55;
  width: min(360px, calc(100vw - 24px));
  background: var(--card); border: 1px solid var(--line);
  border-top: 4px solid var(--eu-gold);
  border-radius: 10px; box-shadow: 0 6px 24px rgba(0, 0, 0, .18);
}
.tray-head {
  display: flex; align-items: center; gap: .5rem;
  padding: .6rem .8rem; cursor: pointer;
}
.tray-head strong { color: var(--eu-blue-dark); }
.tray-count {
  background: var(--eu-blue); color: #fff; font-size: .75rem; font-weight: 700;
  border-radius: 999px; padding: .05rem .5rem; margin-left: auto;
}
.link { background: none; border: none; cursor: pointer; color: var(--muted); font-size: .9rem; }
#tray-body { padding: 0 .8rem .8rem; }
#tray-list { list-style: none; margin: 0 0 .6rem; padding: 0; max-height: 40vh; overflow: auto; }
#tray-list li {
  display: flex; align-items: center; gap: .5rem;
  padding: .3rem 0; border-bottom: 1px solid var(--line); font-size: .88rem;
}
#tray-list button { margin-left: auto; }
#tray-list li.tray-theme {
  font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--eu-gold-ink); border-bottom: 2px solid var(--eu-gold); padding-top: .6rem;
}
#tray-list li.tray-theme:first-child { padding-top: 0; }
.tray-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.tray-actions button {
  flex: 1 1 auto;
  border: none; border-radius: 8px; padding: .5rem .7rem;
  font-size: .85rem; font-weight: 600; cursor: pointer;
  background: var(--eu-blue); color: #fff;
}
.tray-actions button:hover { background: var(--eu-blue-dark); }
.tray-actions button.ghost { background: #eef2ff; color: var(--eu-blue-dark); flex: 0 0 auto; }
.tray-actions button:disabled { opacity: .5; cursor: not-allowed; }

/* ---- carnet imprimable A5 ---- */
#print-area { display: none; }

/* typographie du carnet : hors @media print pour pouvoir le mesurer à l'écran
   (calcul des n° de page de l'index, voir fillPdfPageNumbers dans app.js) */
#print-area section { display: flow-root; }
.booklet-cover { text-align: center; padding-top: 30mm; }
.booklet-cover h1 { font-size: 20pt; color: #000; }
.bk-index h1 { font-size: 16pt; margin: 0 0 5mm; }
.bk-index-part { font-weight: 700; font-size: 11pt; margin: 4mm 0 1mm; display: flex; }
.bk-index ol { list-style: none; margin: 0; padding: 0 0 0 5mm; font-size: 10pt; }
.bk-index li { margin: .6mm 0; display: flex; }
.bk-index a { color: #000; text-decoration: none; flex: 1 1 auto; }
.bk-pg { flex-shrink: 0; padding-left: 3mm; min-width: 8mm; text-align: right; }
.bk-part { text-align: center; padding-top: 55mm; }
.bk-part h1 { font-size: 18pt; color: #000; }
.bk-song h2 { font-size: 14pt; margin: 0 0 4mm; }
.bk-lang { font-size: 10pt; font-weight: 700; margin: 4mm 0 1mm; }
.bk-vtitle { font-style: italic; font-size: 10pt; margin: 0 0 1mm; }
.bk-lyrics { white-space: pre-wrap; font-size: 10.5pt; margin: 0; }
/* mesure hors écran : largeur utile d'une page A5 (148 mm − 2 × 13 mm) */
#print-area.measuring {
  display: block; position: absolute; left: -10000px; top: 0; width: 122mm;
  background: #fff;
}

@media print {
  @page { size: A5; margin: 14mm 13mm; }
  @page { @bottom-center { content: counter(page); font-size: 9pt; } }
  @page :first { @bottom-center { content: none; } }      /* couverture */
  body { background: #fff; }
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block !important; }
  .booklet-cover, .bk-index, .bk-part, .bk-song { page-break-before: always; }
  .booklet-cover { page-break-before: avoid; }
}

@media (max-width: 560px) {
  #emblem { width: 52px; height: 52px; }
  .header-row { padding-right: 60px; flex-direction: column; }
  .version { grid-template-columns: 1fr; gap: .3rem; }
}
