/* 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-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; }
.brand { margin: 0; font-size: 1.2rem; font-weight: 700; flex: 1; letter-spacing: .01em; position: relative; }
.brand.switchable { cursor: pointer; }
.brand span { font-weight: 400; }
/* Plusieurs saisons : tout le titre ouvre le menu natif (select invisible posé dessus). */
.brand.switchable #season-label::after {
  content: ""; display: inline-block; width: 11px; height: 8px; margin-left: 6px; vertical-align: 2px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%232b2a2b' stroke-width='1.8'/%3E%3C/svg%3E") no-repeat center / contain;
}
.season-select {
  position: absolute; inset: -6px -4px; width: calc(100% + 8px); opacity: 0; cursor: pointer;
  font-size: 16px; border: 0; appearance: none; -webkit-appearance: none;
}
.brand.switchable:focus-within { outline: 2px solid var(--blue); outline-offset: 2px; border-radius: var(--r); }
.voice-button {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 10px; border-radius: var(--r);
  border: 0; background: rgba(255,255,255,.85); font-weight: 500; font-size: .95rem;
}
.voice-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c, var(--muted)); }

.search-row { padding: 10px 12px 4px; }
#search {
  width: 100%; height: 40px; padding: 0 12px; border-radius: var(--r);
  border: 1px solid var(--line); background: var(--surface-2); font-size: 17px;
}
#search:focus { outline: 2px solid var(--teal); outline-offset: -1px; background: var(--surface); }

.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; }

/* ---------- 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; }
.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); }
.voice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.voice-grid button {
  height: 50px; border-radius: var(--r); border: 1px solid var(--line); border-left: 5px solid var(--c);
  background: var(--surface); font-size: 1.1rem; font-weight: 500; text-align: left; padding: 0 14px;
}
.voice-grid button[aria-checked="true"] { background: var(--c); border-color: var(--c); color: #fff; font-weight: 700; }
.v-S { --c: var(--c-S); } .v-A { --c: var(--c-A); } .v-T { --c: var(--c-T); } .v-B { --c: var(--c-B); }
.hint { margin: 14px 0 6px; color: var(--muted); font-size: .95rem; }
.sub-row { display: flex; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.sub-row button { flex: 1; height: 38px; border: 0; border-radius: 0; background: var(--surface); font-size: 1rem; white-space: nowrap; color: var(--muted); }
.sub-row button + button { border-left: 1px solid var(--line); }
.sub-row button[aria-checked="true"] { background: var(--blue-soft); color: var(--blue); font-weight: 700; box-shadow: inset 0 -2px 0 var(--blue); }
.primary {
  height: 42px; padding: 0 18px; border: 0; border-radius: var(--r);
  background: var(--blue); color: #fff; font-weight: 700; font-size: 1.02rem;
}
#voice-ok { margin-top: 16px; width: 100%; }
.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); }
.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; }

/* ---------- 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); }
