/* Feuille unique de la PWA (gestion + télécommande).
 *
 * Points repris du gabarit (section 5) :
 *  — la hauteur de la coquille vient d'ici, jamais d'une mesure JavaScript ;
 *  — aucun `position: fixed` sur html/body ;
 *  — marges de sécurité prises telles que le système les annonce ;
 *  — `svh` pour les tailles internes (la barre d'adresse ne les fait pas sauter) ;
 *  — `touch-action: manipulation` pour éviter le zoom au double appui.
 */

:root {
  color-scheme: dark;

  --accent: #7c5cff;
  --accent-clair: #a08cff;
  --or: #e0b341;
  --vert: #2f7d5a;
  --vert-clair: #45a97b;
  --rouge: #c0453c;
  --ambre: #cf9a2c;
  --bleu: #3d7ab8;

  --fond: #14161a;
  --fond-2: #1c1f25;
  --fond-3: #252932;
  --bord: #333846;
  --texte: #f2f4f7;
  --texte-doux: #a8b0bd;
  --texte-faible: #79808d;

  --r: 12px;
  --r-s: 8px;
  --pad: 14px;
  --entete: 56px;
}

* { box-sizing: border-box; }

html, body {
  height: 100dvh;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: var(--fond);
  color: var(--texte);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 16px;
  line-height: 1.4;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

/* En mode installé, iOS retranche la barre d'état de innerHeight : on garde vh. */
html.standalone, html.standalone body { height: 100vh; }

/* Le conteneur de montage doit relayer la hauteur, sinon la coquille se réduit
   à la taille de son contenu et l'entête flotte au milieu de l'écran. */
#racine { height: 100%; }

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-clair); }

/* --------------------------------------------------------------------------
   Coquille : entête figée, onglets, contenu qui défile, marges système
   -------------------------------------------------------------------------- */

.coquille {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.entete {
  flex: 0 0 auto;
  min-height: var(--entete);
  padding: 8px var(--pad);
  padding-top: calc(8px + env(safe-area-inset-top));
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--fond-2);
  border-bottom: 1px solid var(--bord);
}
.entete h1 {
  font-size: 1.05rem;
  margin: 0;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1 1 auto;
  min-width: 0;
}
.entete .sous { display: block; font-size: .74rem; color: var(--texte-doux); font-weight: 400; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entete .retour {
  flex: 0 0 auto;
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid var(--bord);
  background: var(--fond-3);
  font-size: 1.2rem;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.entete .actions { flex: 0 0 auto; display: flex; gap: 6px; }
.entete .actions .bouton { min-height: 38px; padding: 6px 10px; }

.onglets {
  flex: 0 0 auto;
  display: flex;
  gap: 4px;
  padding: 6px var(--pad);
  background: var(--fond-2);
  border-bottom: 1px solid var(--bord);
  overflow-x: auto;
  scrollbar-width: none;
}
.onglets::-webkit-scrollbar { display: none; }
.onglets button {
  flex: 0 0 auto;
  background: transparent;
  border: 1px solid transparent;
  color: var(--texte-doux);
  padding: 7px 13px;
  border-radius: 999px;
  cursor: pointer;
  font-size: .9rem;
  white-space: nowrap;
}
.onglets button[aria-selected="true"] { background: var(--accent); color: #fff; font-weight: 600; }

.contenu {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: var(--pad);
  padding-bottom: calc(var(--pad) + env(safe-area-inset-bottom));
  min-height: 0;
}
.contenu > * + * { margin-top: 14px; }

/* --------------------------------------------------------------------------
   Éléments de base
   -------------------------------------------------------------------------- */

.carte {
  background: var(--fond-2);
  border: 1px solid var(--bord);
  border-radius: var(--r);
  padding: var(--pad);
  min-width: 0;
}
.carte h2, .carte h3 { margin: 0 0 10px; font-size: 1rem; }
.carte > * + * { margin-top: 10px; }

h2.titre-section {
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--texte-faible);
  margin: 0 0 8px;
}

.bouton {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--fond-3);
  border: 1px solid var(--bord);
  color: var(--texte);
  border-radius: var(--r-s);
  padding: 10px 14px;
  min-height: 42px;
  cursor: pointer;
  font-size: .92rem;
  white-space: nowrap;
  text-decoration: none;
  min-width: 0;
}
.bouton:hover { border-color: var(--texte-faible); }
.bouton:active { transform: translateY(1px); }
.bouton.principal { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.bouton.valide { background: var(--vert); border-color: var(--vert); color: #fff; font-weight: 600; }
.bouton.danger { color: #ffb3ad; border-color: #6d2f2b; }
.bouton.petit { padding: 6px 10px; min-height: 34px; font-size: .82rem; }
.bouton.large { width: 100%; white-space: normal; line-height: 1.15; }
.bouton.enorme { min-height: 72px; font-size: 1.5rem; font-weight: 700; border-radius: var(--r); }
.bouton.actif { background: var(--accent); border-color: var(--accent-clair); color: #fff; }
.bouton.spotify { background: #1db954; border-color: #1db954; color: #08210f; font-weight: 700; }
.bouton:disabled { opacity: .45; cursor: not-allowed; }

.ligne { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; min-width: 0; }
.ligne.serre { gap: 6px; }
.ligne.colle { flex-wrap: nowrap; }
.pousse { margin-left: auto; }

.champ { display: block; margin-bottom: 10px; min-width: 0; }
.champ > span { display: block; font-size: .78rem; color: var(--texte-doux); margin-bottom: 4px; }
.champ input, .champ select, .champ textarea {
  width: 100%;
  background: var(--fond);
  border: 1px solid var(--bord);
  border-radius: var(--r-s);
  padding: 10px;
  min-height: 42px;
}
.champ input:focus, .champ select:focus, .champ textarea:focus { outline: 2px solid var(--accent-clair); outline-offset: -1px; }
.champ.coche { display: flex; align-items: center; gap: 10px; }
.champ.coche input { width: 22px; height: 22px; min-height: 0; margin: 0; }
.champ.coche > span { margin: 0; color: var(--texte); font-size: .92rem; }

.grille { display: grid; gap: 10px; }
.grille.deux { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.grille.cartes { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

.etiquette {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
  border: 1px solid var(--bord);
  background: var(--fond-3);
  color: var(--texte-doux);
  white-space: nowrap;
  vertical-align: middle;
}
.etiquette.vert { background: #1d3d30; border-color: var(--vert); color: #9fe0c0; }
.etiquette.violet { background: #2a2350; border-color: var(--accent); color: #cfc3ff; }
.etiquette.bleu { background: #1b2c3d; border-color: var(--bleu); color: #a8cdf0; }
.etiquette.rouge { background: #3d2020; border-color: var(--rouge); color: #f2b0aa; }
.etiquette.or { background: #3d3216; border-color: var(--or); color: #f5d98a; }

.doux { color: var(--texte-doux); font-size: .85rem; }
.faible { color: var(--texte-faible); font-size: .8rem; }
.tronque { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.centre { text-align: center; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85rem; overflow-wrap: anywhere; }

.liste { display: flex; flex-direction: column; gap: 8px; }
.item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--fond-2);
  border: 1px solid var(--bord);
  border-radius: var(--r-s);
  min-width: 0;
  color: inherit;
  text-decoration: none;
}
.item.cliquable { cursor: pointer; }
.item.cliquable:hover { border-color: var(--texte-faible); }
.item .corps { flex: 1 1 auto; min-width: 0; }
.item .corps strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .corps .doux { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item.eteint { opacity: .55; }

.message {
  padding: 10px 12px;
  border-radius: var(--r-s);
  font-size: .88rem;
  border: 1px solid var(--bord);
  background: var(--fond-3);
}
.message.erreur { background: #3a1f1d; border-color: var(--rouge); color: #f5c2bd; }
.message.succes { background: #1d3529; border-color: var(--vert); color: #b6e7ce; }
.message.info { background: #1b2c3d; border-color: var(--bleu); color: #cfe3f7; }

.vide { text-align: center; color: var(--texte-faible); padding: 26px 12px; font-size: .9rem; }

/* --------------------------------------------------------------------------
   Tableaux : jamais de débordement horizontal de la page
   -------------------------------------------------------------------------- */

.defile-x { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }

table.classement { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.classement th, table.classement td {
  padding: 7px 6px;
  text-align: right;
  border-bottom: 1px solid var(--bord);
  white-space: nowrap;
}
table.classement th { color: var(--texte-faible); font-weight: 600; font-size: .74rem; }
table.classement td.nom, table.classement th.nom {
  text-align: left; white-space: normal; width: 99%; overflow-wrap: anywhere;
}
table.classement td.nom .etiquette { margin-left: 6px; }
table.classement td:last-child, table.classement th:last-child { padding-right: 0; }
table.classement td.rang { color: var(--texte-faible); font-variant-numeric: tabular-nums; }
table.classement td.points { font-weight: 700; font-variant-numeric: tabular-nums; }
table.classement tr.podium td.rang { color: var(--or); font-weight: 700; }
table.classement tr.p1 td { background: rgba(224, 179, 65, .12); }

/* Grille de saisie des points */
table.points { border-collapse: collapse; font-size: .88rem; }
table.points th, table.points td { padding: 4px; border-bottom: 1px solid var(--bord); white-space: nowrap; }
table.points th { color: var(--texte-faible); font-weight: 600; font-size: .74rem; text-align: center; }
table.points td.nom, table.points th.nom {
  text-align: left; position: sticky; left: 0; background: var(--fond); z-index: 1;
  max-width: 44vw; overflow: hidden; text-overflow: ellipsis;
}
table.points input {
  width: 62px; min-height: 40px; text-align: center;
  background: var(--fond-2); border: 1px solid var(--bord); border-radius: var(--r-s);
  font-variant-numeric: tabular-nums;
}
table.points input.modifie { border-color: var(--accent-clair); background: #241f3d; }
table.points td.total { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------------------
   Diapos et sons
   -------------------------------------------------------------------------- */

.zone-depot {
  border: 2px dashed var(--bord);
  border-radius: var(--r);
  padding: 18px;
  text-align: center;
  color: var(--texte-doux);
  cursor: pointer;
}
.zone-depot:hover, .zone-depot.survol { border-color: var(--accent-clair); color: var(--texte); }
.zone-depot input { display: none; }

.diapos { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.diapo {
  position: relative;
  border: 1px solid var(--bord);
  border-radius: var(--r-s);
  overflow: hidden;
  background: #000;
  cursor: pointer;
  aspect-ratio: 16 / 9;
}
.diapo img { width: 100%; height: 100%; object-fit: contain; display: block; }
.diapo .numero {
  position: absolute; left: 6px; top: 6px;
  background: rgba(0, 0, 0, .7); color: #fff;
  font-size: .72rem; font-weight: 700; padding: 1px 6px; border-radius: 999px;
}
.diapo .son {
  position: absolute; right: 6px; bottom: 6px;
  background: var(--accent); color: #fff;
  font-size: .72rem; padding: 1px 7px; border-radius: 999px;
}
.diapo.courante { outline: 3px solid var(--accent-clair); }
.apercu-diapo { width: 100%; aspect-ratio: 16 / 9; object-fit: contain; background: #000; border-radius: var(--r-s); display: block; }

.jingles { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; }
.jingle {
  min-height: 64px;
  padding: 8px;
  border-radius: var(--r);
  border: 1px solid var(--bord);
  background: var(--fond-3);
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  white-space: normal;
  overflow-wrap: anywhere;
  text-align: center;
  line-height: 1.2;
  font-size: .9rem;
}
.jingle .faible { font-size: .72rem; }
.jingle.en-cours { background: var(--accent); border-color: var(--accent-clair); color: #fff; animation: pulse 1.2s ease-in-out infinite; }
.jingle.lie { border-color: var(--or); }

/* --------------------------------------------------------------------------
   Télécommande
   -------------------------------------------------------------------------- */

.direct { display: flex; flex-direction: column; gap: 12px; }
.puces { display: flex; gap: 6px; flex-wrap: wrap; }
.puce {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: .74rem; padding: 3px 9px; border-radius: 999px;
  border: 1px solid var(--bord); background: var(--fond-3); color: var(--texte-doux);
}
.puce::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--texte-faible); }
.puce.ok::before { background: var(--vert-clair); }
.puce.ko::before { background: var(--rouge); }
.puce.attente::before { background: var(--ambre); animation: pulse 1.2s ease-in-out infinite; }

.direct-diapo { display: grid; grid-template-columns: minmax(0, 150px) minmax(0, 1fr); gap: 10px; align-items: start; }
.direct-diapo .vignette-diapo {
  width: 100%; aspect-ratio: 16 / 9; object-fit: contain; background: #000;
  border-radius: var(--r-s); border: 1px solid var(--bord); display: block;
}
.direct-diapo .compteur { font-size: .8rem; color: var(--texte-doux); margin-top: 4px; text-align: center; font-variant-numeric: tabular-nums; }
.notes {
  max-height: 26svh;
  overflow-y: auto;
  font-size: .9rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--texte);
  background: var(--fond);
  border: 1px solid var(--bord);
  border-radius: var(--r-s);
  padding: 8px 10px;
  min-height: 42px;
}
.notes:empty::before { content: 'Aucune note pour cette diapo.'; color: var(--texte-faible); }
.nav-diapos { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.vue-active { color: var(--accent-clair); }

.lecteur { display: flex; flex-direction: column; gap: 8px; }
.lecteur .piste { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lecteur .temps { font-variant-numeric: tabular-nums; color: var(--texte-doux); font-size: .82rem; white-space: nowrap; }
.barre { height: 6px; background: var(--fond-3); border-radius: 999px; overflow: hidden; }
.barre > div { height: 100%; background: var(--accent-clair); width: 0; transition: width .5s linear; }
.transport { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.transport .bouton { font-size: 1.25rem; min-height: 50px; padding: 6px; }
.fondus { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.volume { display: flex; align-items: center; gap: 8px; }
.volume input[type="range"] { flex: 1 1 auto; min-width: 0; accent-color: var(--accent-clair); }

.choix-classement { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* Manche musicale */
.reponse-musique { font-size: 1.35rem; font-weight: 750; line-height: 1.2; overflow-wrap: anywhere; margin-top: 4px; }
.barre.chrono { flex: 1 1 auto; height: 10px; }
.barre.chrono > div { transition: width 1s linear; }
.barre.chrono.ambre > div { background: var(--ambre); }
.barre.chrono.rouge > div { background: var(--rouge); width: 100% !important; }
.carte.musique .temps { min-width: 78px; text-align: right; }
table.pistes input { width: 64px; min-height: 36px; text-align: center; background: var(--fond); border: 1px solid var(--bord); border-radius: var(--r-s); }
table.classement.pistes td.nom strong { font-weight: 650; }
.choix-classement select { width: 100%; }

/* --------------------------------------------------------------------------
   Fenêtre modale
   -------------------------------------------------------------------------- */

.voile {
  position: absolute;
  inset: 0;
  background: rgba(6, 8, 11, .82);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 40;
}
.modale {
  background: var(--fond-2);
  border: 1px solid var(--bord);
  border-radius: var(--r) var(--r) 0 0;
  width: min(560px, 100%);
  max-height: 92svh;
  overflow-y: auto;
  padding: var(--pad);
  padding-bottom: calc(var(--pad) + env(safe-area-inset-bottom));
}
@media (min-width: 700px) {
  .voile { align-items: center; }
  .modale { border-radius: var(--r); max-height: 88svh; }
}
.modale h2 { margin: 0 0 10px; font-size: 1.05rem; }
.modale p { margin: 0 0 8px; }

/* --------------------------------------------------------------------------
   Divers
   -------------------------------------------------------------------------- */

.brulant { animation: pulse 2.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .62; } }
@media (prefers-reduced-motion: reduce) { .brulant, .jingle.en-cours, .puce.attente { animation: none; } }

.zone-qr { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.zone-qr img { width: 150px; height: 150px; background: #fff; border-radius: var(--r-s); padding: 6px; }

.connexion { display: flex; align-items: center; justify-content: center; height: 100%; padding: var(--pad); overflow-y: auto; }
.connexion .carte { width: min(380px, 100%); }
.connexion h1 { margin: 0 0 4px; font-size: 1.3rem; }

.toasts {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 50; display: flex; flex-direction: column; gap: 6px;
  width: min(420px, calc(100% - 24px));
  pointer-events: none;
}
.toasts .message { box-shadow: 0 6px 24px rgba(0, 0, 0, .5); pointer-events: auto; }

.pied { padding: 16px 0 4px; text-align: center; color: var(--texte-faible); font-size: .76rem; }
