/* Charte inspirée d'avecdescrisdejoie.fr : bandeau or, bleu pétrole, sarcelle, Alegreya Sans.
   Thème clair uniquement : les partitions ont un fond blanc. */
@font-face { font-family: "Alegreya Sans"; font-weight: 400; font-display: swap; src: url("/fonts/alegreya-sans-400.woff2") format("woff2"); }
@font-face { font-family: "Alegreya Sans"; font-weight: 500; font-display: swap; src: url("/fonts/alegreya-sans-500.woff2") format("woff2"); }
@font-face { font-family: "Alegreya Sans"; font-weight: 700; font-display: swap; src: url("/fonts/alegreya-sans-700.woff2") format("woff2"); }

:root {
  --gold: #eeae21;
  --gold-soft: #fdf4de;
  --blue: #2d5467;
  --blue-soft: #e8eff2;
  --teal: #009d96;
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f6f7f8;
  --line: #e1e5e8;
  --text: #414042;
  --muted: #6c757d;
  --c-S: #c4503a;
  --c-A: #c98a12;
  --c-T: #009d96;
  --c-B: #2d5467;
  --c-F: #b04f7c;
  --c-H: #4f5fa3;
  --c-CHOEUR: #7d6a55;
  --c-ORCH: #7a5c98;
  --c-SOLO: #8c4a8f;
  --c-inst: #8a9197;
  --r: 4px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.35 "Alegreya Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.view { min-height: 100%; }

/* ---------- Bandeau ---------- */
.topbar {
  display: flex; align-items: center; gap: 8px; min-height: 46px;
  padding: env(safe-area-inset-top) max(10px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  background: var(--gold); color: #2b2a2b;
}
#home .topbar { position: sticky; top: 0; z-index: 2; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 6px 12px 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; height: 32px; padding: 0 12px; border-radius: var(--r);
  border: 1px solid var(--line); background: var(--surface); white-space: nowrap; font-size: .95rem; color: var(--muted);
}
.chip[aria-pressed="true"] { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 500; }

/* ---------- Recherche et filtres ---------- */
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.search-bar { gap: 6px; padding-top: calc(7px + env(safe-area-inset-top)); padding-bottom: 7px; }
.search-box {
  flex: 1; display: flex; align-items: center; gap: 6px; height: 38px; padding: 0 10px;
  background: #fff; border-radius: var(--r); color: var(--muted);
}
.search-box:focus-within { outline: 2px solid var(--blue); }
.search-box svg { width: 18px; height: 18px; }
#search { flex: 1; min-width: 0; height: 100%; border: 0; background: none; font-size: 17px; color: var(--text); outline: none; }
.filters-button { position: relative; margin-right: -6px; }
.filters-button .count {
  position: absolute; top: 3px; right: 1px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px;
  background: var(--blue); color: #fff; font-size: .72rem; font-weight: 700; display: grid; place-items: center;
}
/* Version DEV : repère discret (attribut posé par la pipeline sur la branche dev). */
html[data-environment="dev"] .search-bar::before {
  content: "DEV"; font-size: .7rem; font-weight: 700; color: var(--blue); background: rgba(255,255,255,.7); padding: 2px 4px; border-radius: 2px;
}
.active-filters { padding-top: 0; }
.chip.active { background: var(--blue-soft); border-color: var(--blue-soft); color: var(--blue); font-weight: 500; }
.chip.link { border-color: transparent; background: none; text-decoration: underline; }
.result-count { margin: 0; padding: 0 14px 4px; font-size: .85rem; color: var(--muted); }
.more { display: block; margin: 12px auto calc(20px + env(safe-area-inset-bottom)); }

/* ---------- Liste ---------- */
.song-list { list-style: none; margin: 0; padding: 0 0 calc(16px + env(safe-area-inset-bottom)); }
@media (min-width: 720px) {
  .song-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 0 24px; padding: 0 12px; }
}
.song-card {
  display: block; text-decoration: none; color: inherit;
  padding: 10px 12px 10px 14px; border-bottom: 1px solid var(--line); border-left: 3px solid transparent;
}
.song-card:active, .song-card:hover { background: var(--gold-soft); border-left-color: var(--gold); }
.song-card h2 { margin: 0 0 2px; font-size: 1.08rem; font-weight: 700; color: var(--blue); }
.meta { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; color: var(--muted); font-size: .9rem; }
.voices { display: inline-flex; gap: 5px; }
.vtag { font-weight: 700; font-size: .82rem; color: var(--c); }
.vtag.mine { background: var(--c); color: #fff; border-radius: 2px; padding: 0 4px; }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: .85rem; font-weight: 500; color: var(--teal); }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.snippet { margin: 1px 0 3px; font-size: .92rem; color: var(--text); font-style: italic; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.snippet mark { background: var(--gold-soft); color: inherit; font-weight: 700; font-style: normal; padding: 0 1px; border-radius: 2px; }
.coll { font-weight: 500; color: var(--blue); }
.list-sep { padding: 14px 14px 6px; font-size: .9rem; color: var(--muted); border-bottom: 1px solid var(--line); background: var(--surface-2); }
.empty { text-align: center; color: var(--muted); padding: 32px 16px; }

/* ---------- Fiche chant ---------- */
/* Plein écran fixe : suit la hauteur réellement visible (barres du navigateur mobile). */
#song { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--bg); }
.song-title { margin: 0; font-size: 1.08rem; font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-button { width: 40px; height: 40px; border: 0; background: none; display: grid; place-items: center; border-radius: var(--r); flex: none; color: inherit; }
#back { margin-left: -8px; }
.arr-select {
  flex: none; max-width: 42vw; height: 30px; padding: 0 6px; border-radius: var(--r);
  border: 0; background: rgba(255,255,255,.85); font-size: .92rem;
}
.text-button {
  height: 34px; padding: 0 12px; border-radius: var(--r); border: 1px solid var(--blue);
  background: var(--surface); color: var(--blue); font-size: .95rem; font-weight: 500;
}

.song-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.score-pane { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }
.score {
  flex: 1; min-height: 0; overflow: auto; background: #fff;
  touch-action: pan-x pan-y; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
}
.score-inner { width: 100%; }
.score-inner img { display: block; width: 100%; height: auto; background: #fff; }
.score-inner.pages img + img { border-top: 4px solid var(--surface-2); }
.score-toggle {
  display: block; margin: 10px auto 14px; padding: 4px 8px; border: 0; background: none;
  color: #a7adb2; font-size: .8rem; text-decoration: underline; text-underline-offset: 2px;
}
.zoom-reset { position: absolute; right: 10px; bottom: 10px; }
.zoom-reset .text-button { box-shadow: 0 1px 6px rgba(0,0,0,.18); }

/* ---------- Lecteur ---------- */
.player {
  flex: none; background: var(--surface); border-top: 1px solid var(--line);
  box-shadow: 0 -2px 8px rgba(45, 84, 103, .08);
  padding: 6px 10px calc(5px + env(safe-area-inset-bottom));
}
.tracks { display: flex; gap: 5px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.tracks::-webkit-scrollbar { display: none; }
.track {
  flex: none; height: 30px; padding: 0 9px; border-radius: var(--r);
  border: 1px solid var(--line); border-left: 4px solid var(--c); background: var(--surface);
  color: var(--text); font-weight: 500; font-size: .92rem;
  display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
}
.track small { font-weight: 400; opacity: .8; }
.track[aria-checked="true"] { background: var(--c); border-color: var(--c); color: #fff; font-weight: 700; }
.track .cached { font-size: .75rem; color: var(--teal); }
.track[aria-checked="true"] .cached { color: #fff; }
.track.unavailable { opacity: .45; border-style: dashed; }
.track.plus { border-left-width: 1px; color: var(--muted); }

.bar { display: flex; align-items: center; gap: 6px; }
.time { font-variant-numeric: tabular-nums; font-size: .82rem; color: var(--muted); flex: none; }
.seek-wrap { position: relative; flex: 1; min-width: 60px; height: 36px; display: flex; align-items: center; }
#seek { width: 100%; margin: 0; accent-color: var(--blue); height: 36px; position: relative; z-index: 1; background: transparent; }
.loop-band { position: absolute; top: 12px; bottom: 12px; background: rgba(238, 174, 33, .45); border-radius: 2px; }

.ctl {
  flex: none; min-width: 36px; height: 36px; border-radius: var(--r); border: 1px solid var(--line);
  background: var(--surface); color: var(--blue); display: inline-flex; align-items: center; justify-content: center; padding: 0 7px;
  font-size: .88rem; font-weight: 700; font-variant-numeric: tabular-nums;
}
.ctl.play { width: 42px; height: 36px; background: var(--blue); color: #fff; border: 0; padding: 0; }
.ctl.play svg { width: 22px; height: 22px; fill: currentColor; stroke: none; }
.ctl.play .i-pause { display: none; }
.ctl.play.playing .i-play { display: none; }
.ctl.play.playing .i-pause { display: inline; }
#loop.armed { border-color: var(--gold); background: var(--gold-soft); color: #8a6208; }
#loop.on { background: var(--gold); border-color: var(--gold); color: #2b2a2b; }
#speed.slow { border-color: var(--teal); color: var(--teal); }
.player-msg { margin: 2px 0 0; font-size: .86rem; color: var(--muted); }

.dl-button { position: relative; margin-right: -6px; }
.dl-dot { position: absolute; top: 8px; right: 8px; width: 9px; height: 9px; border-radius: 50%; background: var(--teal); border: 2px solid var(--gold); }

/* Tablette en paysage : commandes à côté de la partition */
@media (orientation: landscape) and (min-width: 900px) and (min-height: 600px) {
  .song-body { flex-direction: row; }
  .player { width: 320px; border-top: 0; border-left: 1px solid var(--line); box-shadow: none; display: flex; flex-direction: column; gap: 6px; padding-top: 10px; }
  .tracks { flex-wrap: wrap; overflow: visible; }
  .bar { flex-wrap: wrap; }
  .seek-wrap { flex-basis: 100%; order: -1; }
}

/* Téléphone en paysage : partition maximale, sans bandeau ni choix de piste */
@media (orientation: landscape) and (max-height: 600px) {
  #song .topbar, #song .tracks, #song .player-msg { display: none !important; }
  .player { padding: 2px max(8px, env(safe-area-inset-right)) calc(2px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); }
  .score-inner { padding: 0 env(safe-area-inset-right) 0 env(safe-area-inset-left); }
}

/* ---------- Fenêtres ---------- */
.dialog {
  border: 0; border-top: 4px solid var(--gold); border-radius: var(--r); padding: 16px 18px 18px; width: min(400px, calc(100vw - 24px));
  background: var(--surface); color: var(--text); box-shadow: 0 12px 40px rgba(20, 35, 45, .28);
}
.dialog::backdrop { background: rgba(20, 35, 45, .45); }
.dialog h2:focus { outline: none; }
.dialog h2 { margin: 0 0 12px; font-size: 1.3rem; font-weight: 700; color: var(--blue); }
.dialog h3 { margin: 14px 0 4px; font-size: 1rem; color: var(--blue); }
.dialog .close { position: absolute; top: 8px; right: 6px; width: 36px; height: 36px; border: 0; background: none; font-size: 1.5rem; color: var(--muted); }
.hint { margin: 14px 0 6px; color: var(--muted); font-size: .95rem; }
.primary {
  height: 42px; padding: 0 18px; border: 0; border-radius: var(--r);
  background: var(--blue); color: #fff; font-weight: 700; font-size: 1.02rem;
}
.primary:disabled { opacity: .35; }
.offline-box { display: grid; gap: 8px; padding: 2px 0 6px; }
.dl-row { display: flex; align-items: center; gap: 10px; }
.dl-row .text-button { flex: none; }
.dl-row .info { flex: 1; font-size: .92rem; color: var(--muted); }
.dl-row progress { width: 100%; height: 6px; accent-color: var(--teal); }
.about p { margin: 0 0 4px; font-size: .95rem; }
.about b { font-weight: 500; color: var(--muted); }
.about summary { cursor: pointer; color: var(--blue); font-weight: 500; min-height: 32px; display: flex; align-items: center; }
.paroles { white-space: pre-line; max-height: 40vh; overflow: auto; font-size: .95rem; padding: 4px 0 8px; }
.about a { color: var(--teal); font-weight: 500; display: inline-flex; min-height: 34px; align-items: center; }
.docs { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.docs a { color: var(--teal); font-weight: 500; min-height: 34px; display: inline-flex; align-items: center; }

/* Filtres avancés : panneau qui monte du bas sur téléphone */
/* display seulement quand elle est ouverte : sinon la fenêtre fermée resterait affichée. */
.sheet { padding: 14px 0 0; max-height: min(88vh, 760px); flex-direction: column; overflow: hidden; }
.sheet[open] { display: flex; }
.sheet h2 { padding: 0 16px; }
.facets { flex: 1; overflow-y: auto; padding: 0 16px 8px; overscroll-behavior: contain; }
.facet { padding: 6px 0 10px; border-bottom: 1px solid var(--line); }
.facet h3 { margin: 6px 0 4px; }
.opt { display: flex; align-items: center; gap: 10px; min-height: 36px; cursor: pointer; }
.opt input { width: 18px; height: 18px; accent-color: var(--blue); flex: none; margin: 0; }
.opt span:first-of-type { flex: 1; }
.opt .n { color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }
.facet-find { width: 100%; height: 34px; margin: 2px 0 6px; padding: 0 10px; border: 1px solid var(--line); border-radius: var(--r); font-size: 16px; }
.facet-more { border: 0; background: none; color: var(--teal); font-weight: 500; padding: 4px 0; }
.sheet-actions {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--surface);
}
.sheet-actions form { margin: 0; }
@media (max-width: 600px) {
  .sheet { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: var(--r) var(--r) 0 0; }
}

/* ---------- Nouvelle version ---------- */
.update {
  position: fixed; z-index: 11; left: 8px; right: 8px; top: calc(8px + env(safe-area-inset-top));
  max-width: 440px; margin: 0 auto; padding: 8px 8px 8px 14px; display: flex; align-items: center; gap: 10px;
  background: var(--surface); border-top: 4px solid var(--gold); border-radius: var(--r); box-shadow: 0 8px 30px rgba(20, 35, 45, .25);
}
.update span { flex: 1; color: var(--blue); font-weight: 500; }
.update .primary { height: 36px; }

/* ---------- Proposition d'installation ---------- */
.install {
  position: fixed; z-index: 10; left: 8px; right: 8px; bottom: calc(8px + env(safe-area-inset-bottom));
  max-width: 440px; margin: 0 auto; padding: 12px 14px; display: grid; grid-template-columns: 42px 1fr; gap: 2px 12px;
  background: var(--surface); border-top: 4px solid var(--gold); border-radius: var(--r); box-shadow: 0 8px 30px rgba(20, 35, 45, .25);
}
.install img { width: 42px; height: 42px; border-radius: var(--r); grid-row: span 2; }
.install strong { font-size: 1.05rem; color: var(--blue); }
.install p { margin: 0; font-size: .92rem; color: var(--muted); }
.install p svg { width: 16px; height: 16px; vertical-align: -3px; }
.install .actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.install .text-button { border-color: var(--line); color: var(--muted); }
