:root {
  --bg: #14171c;
  --panel: #1e232b;
  --accent: #e5a00d;
  --text: #e8eaed;
  --muted: #9aa0a6;
  --border: #333a44;
  --panel-2: #2a303a;
  --hover: #262c36;
  /* Tokens structurels partagés (rayons homogènes). */
  --radius: 10px;
  --radius-sm: 6px;
}

* { box-sizing: border-box; }

/* Garantit que l'attribut hidden masque même les éléments à display explicite (ex. #app-view flex). */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  background: var(--panel);
}

header h1 { margin: 0; color: var(--accent); font-size: 1.3rem; }

main { padding: 1.25rem; }

form { display: flex; flex-direction: column; gap: 0.6rem; max-width: 320px; }

input, button, textarea {
  padding: 0.6rem 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}

button {
  cursor: pointer;
  background: var(--accent);
  color: #14171c;
  border: none;
  font-weight: 600;
}

button.secondary { background: var(--panel); color: var(--text); border: 1px solid var(--border); }

button.small { padding: 0.25rem 0.5rem; font-size: 0.8rem; margin-left: 0.4rem; }

.header-actions { display: flex; gap: 0.75rem; align-items: center; }

.user-info { color: var(--muted); font-size: 0.9rem; }

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  text-align: center;
  color: var(--muted);
  padding: 4rem 1.5rem;
  margin: auto;
  max-width: 480px;
}

.empty h2 { color: var(--text); margin: 0; }
.empty p { margin: 0; }

dialog#admin {
  background: var(--bg);
  color: var(--text);
  border: none;
  border-radius: 0;
  max-width: 100vw;
  width: 100vw;
  max-height: 100vh;
  height: 100vh;
  margin: 0;
  padding: 1.5rem 2rem 3rem;
  overflow-y: auto;
}

/* Contenu centré en colonne lisible plutôt qu'étiré sur toute la largeur. */
dialog#admin > * { max-width: 1000px; margin-left: auto; margin-right: auto; }

dialog#admin section {
  margin-bottom: 1.25rem;
  background: var(--panel);
  border: 1px solid var(--panel-2);
  border-radius: 10px;
  padding: 1rem 1.25rem;
}

/* Médias groupés par bibliothèque. */
.admin-lib-group { margin: 0.75rem 0 1rem; }
.admin-lib-group h4 { color: var(--accent); margin: 0 0 0.35rem; font-size: 0.95rem; }
.admin-lib-group ul { list-style: none; padding: 0; margin: 0; }

.scan-status { color: var(--accent); font-size: 0.85rem; margin-left: 0.4rem; }

/* Boutons-icônes d'action (admin) sur les vignettes et épisodes. */
.card-actions {
  display: flex;
  flex-wrap: wrap; /* passe à la ligne dans les zones étroites (ex. tranche VHS) */
  gap: 0.3rem;
  margin-top: 0.4rem;
}
/* Vues jaquettes et mosaïque : au plus 3 icônes par ligne. */
.grid:not(.vhs):not(.list) .card .card-actions {
  display: grid;
  grid-template-columns: repeat(3, max-content);
  justify-content: start;
}
.icon-btn {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.15rem 0.4rem;
  font-size: 0.95rem;
  line-height: 1;
  cursor: pointer;
}
.icon-btn:hover { background: var(--accent); }
.icon-btn.active { background: var(--accent); color: #14171c; }
.episode .icon-btn { margin-left: 0.25rem; }
.ep-still {
  width: 96px;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
  background: #10131a;
}

.watched-badge { color: var(--accent); font-weight: 600; }

/* Vue Succès : badges. */
.stats-summary { color: var(--text); font-size: 1rem; margin: 0.25rem 0 0.5rem; }
.badge-card { text-align: center; cursor: default; }
.badge-card:hover { outline: none; }
.badge-emoji { font-size: 2.6rem; margin: 0.4rem 0; }
.badge-card.locked { opacity: 0.45; filter: grayscale(1); }

/* Quiz : jaquette mystère + choix. */
.quiz-poster {
  width: 220px;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 8px;
  justify-self: start;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
}
.quiz-choices { display: flex; flex-direction: column; gap: 0.5rem; max-width: 480px; }

/* Radios : cartes cliquables + lecteur persistant en bas. */
.radio-card { text-align: center; }
.tv-logo {
  width: 80px;
  height: 80px;
  object-fit: contain;
  margin: 0.4rem auto;
  display: block;
}
#radio-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.4rem 1rem;
  background: var(--panel);
  border-top: 1px solid var(--border);
}
#radio-bar[hidden] { display: none; }
#radio-bar audio { flex: 1; max-width: 420px; height: 32px; }
#radio-name { color: var(--accent); font-weight: 600; }
#toasts {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.toast {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 0.6rem 0.9rem;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transform: translateX(20px);
  transition: opacity 0.3s, transform 0.3s;
  max-width: 340px;
}
.toast.visible { opacity: 1; transform: translateX(0); }

/* Économiseur d'écran : jaquettes qui dérivent du bas vers le haut + horloge. */
#screensaver {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #000;
  overflow: hidden;
  cursor: none;
}
#screensaver[hidden] { display: none; }
.ss-poster {
  position: absolute;
  bottom: -240px;
  width: 150px;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 8px;
  opacity: 0.85;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.8);
  animation: ss-drift linear infinite;
}
@keyframes ss-drift {
  from { transform: translateY(0) rotate(var(--rot, 0deg)); }
  to { transform: translateY(calc(-100vh - 260px)) rotate(var(--rot, 0deg)); }
}
.ss-clock {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 5rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.85);
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.9);
  z-index: 101;
  letter-spacing: 0.05em;
}

/* Titres de sections dans la grille (accueil) : occupent toute la largeur. */
.grid-heading { grid-column: 1 / -1; margin: 0.5rem 0 0; color: var(--accent); }
.grid.list .grid-heading { margin: 0.75rem 0 0.25rem; }

/* Mode mosaïque : mur d'affiches bord à bord, titre au survol. */
.grid.mosaic { grid-template-columns: repeat(auto-fill, minmax(calc(130px * var(--zoom, 1)), 1fr)); gap: 4px; }
.grid.mosaic .card { padding: 0; border-radius: 0; position: relative; overflow: hidden; }
.grid.mosaic .card .poster { margin: 0; border-radius: 0; display: block; }
.grid.mosaic .card h3 {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  margin: 0;
  padding: 1.2rem 0.4rem 0.35rem;
  font-size: 0.8rem;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.92));
  opacity: 0;
  transition: opacity 0.2s;
}
.grid.mosaic .card:hover h3 { opacity: 1; }
.grid.mosaic .card p { display: none; }
.grid.mosaic .card .card-actions {
  position: absolute;
  top: 0.3rem;
  right: 0.3rem;
  margin: 0;
  opacity: 0;
  transition: opacity 0.2s;
}
.grid.mosaic .card:hover .card-actions { opacity: 1; }
.grid.mosaic .grid-heading { padding: 0 0.25rem; }

/* Mode VHS : étagère de cassettes — tranches verticales, on « tire » la cassette au survol. */
.grid.vhs {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 14px 3px;
  padding: 14px 14px 0;
  background: linear-gradient(#241b12, #191009);
  border-radius: 10px;
}
.grid.vhs .card {
  width: calc(46px * var(--zoom, 1));
  height: calc(232px * var(--zoom, 1));
  padding: 0;
  position: relative;
  overflow: visible;
  background: linear-gradient(90deg, #05050a, #14141c 30%, #0a0a10);
  border: 1px solid #000;
  border-radius: 2px 5px 5px 2px;
  box-shadow: inset -3px 0 5px rgba(255, 255, 255, 0.05), 2px 2px 5px rgba(0, 0, 0, 0.6);
  transition: transform 0.15s;
  /* Chaque tranche repose sur l'étagère. */
  border-bottom: 6px solid #3a2a18;
}
.grid.vhs .card:hover { transform: translateY(-12px); outline: none; z-index: 6; }
/* Au survol : la jaquette « sort » de l'étagère au-dessus de la tranche. */
.grid.vhs .card .poster {
  display: block;
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  width: 150px;
  aspect-ratio: 2 / 3;
  margin: 0;
  border-radius: 4px;
  border: 2px solid #0a0a10;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.85);
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(20px) scale(0.4) rotate(-5deg);
  transform-origin: bottom center;
  transition: transform 0.22s ease-out, opacity 0.16s ease-out;
}
.grid.vhs .card:hover .poster {
  opacity: 1;
  transform: translateX(-50%) translateY(0) scale(1) rotate(0deg);
}
/* Pas de place au-dessus (haut de page) : la jaquette poppe SOUS la cassette. */
.grid.vhs .card.pop-below .poster {
  bottom: auto;
  top: calc(100% + 8px);
  transform-origin: top center;
  transform: translateX(-50%) translateY(-20px) scale(0.4) rotate(5deg);
}
.grid.vhs .card.pop-below:hover .poster {
  transform: translateX(-50%) translateY(0) scale(1) rotate(0deg);
}
.grid.vhs .card h3 {
  writing-mode: vertical-rl;
  margin: 0;
  position: absolute;
  top: 18px;
  bottom: 18px;
  left: 7px;
  width: 30px;
  padding: 6px 3px;
  background: #e8e2d0; /* étiquette papier */
  color: #1c1b18;
  font-size: 0.68rem;
  line-height: 1.1;
  border-radius: 1px;
  overflow: hidden;
  display: block;
  -webkit-line-clamp: unset;
  line-clamp: unset;
}
.grid.vhs .card p,
.grid.vhs .card .progress { display: none; }
.grid.vhs .card .card-actions {
  position: absolute;
  bottom: 2px;
  left: 0;
  right: 0;
  justify-content: center;
  margin: 0;
  opacity: 0;
}
.grid.vhs .card:hover .card-actions { opacity: 1; }
.grid.vhs .grid-heading { width: 100%; }

dialog#admin h3 { margin: 0 0 0.5rem; color: var(--accent); }

dialog#admin form { max-width: none; flex-direction: row; flex-wrap: wrap; }

dialog#admin ul { list-style: none; padding: 0; margin: 0; }

dialog#admin li { padding: 0.4rem 0; border-bottom: 1px solid var(--panel-2); }

.error { color: #ff6b6b; min-height: 1.2em; }

.oauth { display: flex; flex-direction: column; gap: 0.5rem; max-width: 320px; margin-top: 0.5rem; }

#app-view { display: flex; gap: 1.25rem; }

#libraries { display: flex; flex-direction: column; gap: 0.4rem; min-width: 180px; }

#libraries button { text-align: left; }

#main-col { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.search-input { flex: 1; max-width: 360px; }

.grid {
  --zoom: 1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(calc(160px * var(--zoom, 1)), 1fr));
  gap: 1rem;
}

/* Mode liste : une entrée par ligne, jaquette à droite pour laisser le texte respirer. */
.grid.list { display: flex; flex-direction: column; gap: 0.5rem; }
.grid.list .card {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 1rem;
  padding: 0.5rem 1rem;
}
.grid.list .card h3 { -webkit-line-clamp: 2; line-clamp: 2; margin: 0; }
.grid.list .card p { margin: 0; white-space: nowrap; }
.grid.list .card .progress { width: 160px; margin-top: 0; flex-shrink: 0; }
.grid.list .card .card-actions { margin-top: 0; }

.card {
  background: var(--panel);
  border-radius: 8px;
  padding: 0.9rem;
  cursor: pointer;
}

.card:hover { outline: 2px solid var(--accent); }

.card.preparing { opacity: 0.85; }

.card .poster {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 6px;
  margin-bottom: 0.4rem;
}
.grid.list .card .poster {
  order: 99; /* jaquette déplacée tout à droite */
  width: calc(64px * var(--zoom, 1));
  aspect-ratio: 2 / 3;
  margin: 0 0 0 auto;
  flex-shrink: 0;
}

.hint { color: var(--muted); font-size: 0.85rem; }

.progress { height: 6px; background: var(--border); border-radius: 3px; margin-top: 0.5rem; overflow: hidden; }
/* Conversion en cours : bleu, pour ne pas confondre avec la reprise (jaune). */
.progress-fill { height: 100%; background: #3d8bfd; transition: width 0.3s; }

.track-label { color: var(--text); font-size: 0.85rem; display: flex; align-items: center; gap: 0.3rem; }
.track-label select {
  padding: 0.25rem;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
}

.card h3 {
  margin: 0 0 0.3rem;
  font-size: 1rem;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card p { margin: 0; color: var(--muted); font-size: 0.85rem; }

dialog#player {
  border: none;
  background: #000;
  padding: 0;
  width: min(1100px, 94vw);
  max-width: 94vw;
}

/* La vidéo occupe toute la largeur du lecteur : pas d'espace mort à droite. */
#video { width: 100%; display: block; }

.player-actions {
  display: flex;
  flex-wrap: wrap; /* les contrôles passent à la ligne au lieu d'élargir le lecteur */
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
}

#player-error { margin: 0; padding: 0.5rem 0.75rem; background: #2a1113; font-size: 0.9rem; }

#resume-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.75rem;
  background: #14171c;
  color: var(--text);
  font-size: 0.9rem;
}
#resume-bar[hidden] { display: none; }

dialog#edit-item {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: min(480px, 92vw);
}
dialog#edit-item h2 { margin: 0 0 0.75rem; color: var(--accent); font-size: 1.1rem; }
dialog#edit-item form { max-width: none; }

/* Fiche série : plein écran (comme l'administration), contenu en colonne lisible. */
dialog#show {
  background: var(--bg);
  color: var(--text);
  border: none;
  border-radius: 0;
  max-width: 100vw;
  width: 100vw;
  max-height: 100vh;
  height: 100vh;
  margin: 0;
  padding: 1.5rem 2rem 3rem;
  overflow-y: auto;
}
dialog#show .show-inner { max-width: 1100px; margin: 0 auto; }
dialog#show .show-actions { display: flex; gap: 0.5rem; margin: 0.5rem 0 1rem; }
#close-show { position: fixed; top: 1rem; right: 1.25rem; z-index: 5; }
dialog#show h2 { margin: 0 0 0.25rem; color: var(--accent); }
dialog#show h3 { margin: 1rem 0 0.4rem; font-size: 1rem; }
.episode-list { list-style: none; padding: 0; margin: 0; }
.episode {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--panel-2);
}
.episode.playable { cursor: pointer; border-radius: 6px; }
.episode.playable:hover { background: var(--hover); }
.episode .ep-status { margin-left: auto; color: var(--muted); font-size: 0.85rem; }

/* Photos : vignettes carrées + diaporama plein écran. */
.photo-thumb { aspect-ratio: 1 / 1; }
#slideshow {
  position: fixed;
  inset: 0;
  z-index: 110;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}
#slideshow[hidden] { display: none; }
#slideshow img { max-width: 100vw; max-height: 100vh; object-fit: contain; }
#slideshow-close { position: absolute; top: 1rem; right: 1rem; }

/* Boutons « Passer l'intro » / « Épisode suivant » en surimpression du lecteur. */
#skip-intro-btn,
#next-episode-btn {
  position: absolute;
  right: 1rem;
  bottom: 5.5rem;
  z-index: 5;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.6);
}
dialog#player { position: relative; }

/* Trickplay : barre de prévisualisation sous la vidéo. */
#trickplay-bar {
  position: relative;
  height: 14px;
  background: repeating-linear-gradient(90deg, #222833 0 6px, #1a1f28 6px 12px);
  cursor: pointer;
}
#trickplay-bar[hidden] { display: none; }
#trickplay-preview {
  position: absolute;
  bottom: 18px;
  width: 160px;
  height: 90px;
  background-color: #000;
  background-repeat: no-repeat;
  border: 2px solid var(--accent);
  border-radius: 4px;
  pointer-events: none;
  z-index: 6;
}
#trickplay-preview[hidden] { display: none; }
#trickplay-time {
  position: absolute;
  bottom: 2px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.75);
  padding: 0 4px;
  border-radius: 3px;
  font-size: 0.75rem;
}

/* Réglages : formulaire lisible avec libellés et sous-titres de groupe. */
.settings-grid { max-width: 640px; }
.settings-grid h4 { margin: 0.75rem 0 0.1rem; color: var(--accent); font-size: 0.95rem; }
.settings-grid label { font-size: 0.9rem; color: var(--muted); display: flex; flex-direction: column; gap: 0.25rem; }
.settings-grid label input, .settings-grid label select { color: var(--text); }
.settings-grid a { color: var(--accent); }

/* Thèmes d'interface (variables surchargées par data-theme). */
:root[data-theme="light"] {
  --bg: #eef0f4;
  --panel: #ffffff;
  --accent: #b26f00;
  --text: #1c1e22;
  --muted: #5b626b;
  --border: #cfd4db;
  --panel-2: #e4e7ec;
  --hover: #e2e5ea;
}
:root[data-theme="light"] .icon-btn { background: #e4e7ec; border-color: #cfd4db; }
:root[data-theme="light"] input,
:root[data-theme="light"] button.secondary,
:root[data-theme="light"] select,
:root[data-theme="light"] textarea { border-color: #cfd4db; }

:root[data-theme="crt"] {
  --bg: #050b05;
  --panel: #0a140a;
  --accent: #a5ff45;
  --text: #7dff7d;
  --muted: #3f8f3f;
  --border: #1d3a1d;
  --panel-2: #10240f;
  --hover: #143214;
}
:root[data-theme="crt"] body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 200;
  background: repeating-linear-gradient(
    0deg, rgba(0, 0, 0, 0.18) 0 1px, transparent 1px 3px
  );
}
:root[data-theme="crt"] img { filter: sepia(0.3) hue-rotate(60deg) saturate(0.7); }

:root[data-theme="cinema"] {
  --bg: #170a0d;
  --panel: #241016;
  --accent: #e0b34c;
  --text: #f3e9dc;
  --muted: #a08c7d;
  --border: #4a2a33;
  --panel-2: #331821;
  --hover: #3b1d27;
}

/* Visualiseur audio de la barre radio/musique. */
#radio-viz { height: 34px; width: 220px; flex-shrink: 0; }

/* Fiche média enrichie. */
dialog#item-sheet {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: min(720px, 94vw);
  padding: 1.25rem;
  position: relative;
  overflow: hidden;
}
/* Fond dynamique : la jaquette floutée derrière la fiche. */
dialog#item-sheet::before {
  content: "";
  position: absolute;
  inset: -30px;
  background-image: var(--sheet-bg);
  background-size: cover;
  background-position: center 20%;
  filter: blur(28px) brightness(0.35) saturate(1.2);
  z-index: 0;
}
dialog#item-sheet .sheet-body { position: relative; z-index: 1; }
.sheet-body { display: flex; gap: 1.25rem; }
#sheet-poster { width: 200px; aspect-ratio: 2 / 3; object-fit: cover; border-radius: 8px; flex-shrink: 0; }
.sheet-info { min-width: 0; }
.sheet-info h2 { margin: 0 0 0.3rem; color: var(--accent); }
#sheet-summary { max-height: 40vh; overflow-y: auto; }
.genre-chip {
  display: inline-block;
  background: var(--panel-2);
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
  margin: 0 0.3rem 0.3rem 0;
  font-size: 0.85rem;
  cursor: pointer;
}
.genre-chip:hover { background: var(--accent); color: #14171c; }
@media (max-width: 640px) { .sheet-body { flex-direction: column; } #sheet-poster { width: 140px; } }

/* Fiche : vignettes des titres similaires. */
.similar-thumb {
  width: 56px;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 4px;
  margin: 0 0.3rem 0.3rem 0;
  cursor: pointer;
}
.similar-thumb:hover { outline: 2px solid var(--accent); }

/* Karaoké : paroles synchronisées au-dessus de la barre audio. */
#karaoke {
  position: fixed;
  bottom: 56px;
  left: 0;
  right: 0;
  z-index: 89;
  text-align: center;
  padding: 1rem 1rem 0.5rem;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.85));
  pointer-events: none;
}
#karaoke[hidden] { display: none; }
#karaoke-line { font-size: 1.6rem; font-weight: 700; color: var(--accent); min-height: 1.3em; }
#karaoke-prev, #karaoke-next { color: var(--muted); font-size: 1rem; min-height: 1.2em; }

/* Défi ciné de la semaine (encart accueil). */
.challenge-banner {
  padding: 0.5rem 0.75rem;
  border: 1px dashed var(--accent);
  border-radius: 8px;
  color: var(--accent);
  font-weight: 600;
}
.challenge-banner.done { border-style: solid; }

/* Éditeur de collection : barre d'outils admin. */
.collection-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.collection-toolbar select { max-width: 320px; }

/* Quiz multijoueur : buzzer. */
.buzzer {
  font-size: 1.4rem;
  padding: 0.8rem 2.5rem;
  background: #b23b3b;
  border-radius: 999px;
  font-weight: 700;
}
.buzzer:hover { background: #d04545; }

/* Navigation : fond jaune au survol + vue courante en surbrillance persistante (grasse). */
#libraries button { transition: border-color 0.15s, background 0.15s, color 0.15s; }
#libraries button:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #14181f;
}
#libraries button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #14181f;
  font-weight: 700;
}

/* Reprise en cours : fine barre de progression sous la jaquette. */
.progress-strip {
  height: 4px;
  background: rgba(128, 128, 128, 0.35);
  border-radius: 2px;
  overflow: hidden;
  margin: 2px 0 4px;
}
.progress-strip div { height: 100%; background: var(--accent); }

/* Recherche instantanée : liste de suggestions sous le champ. */
.toolbar { position: relative; }
#search-suggest {
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 280px;
  max-width: 90%;
  max-height: 320px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  z-index: 95;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}
.suggest-row { padding: 0.45rem 0.7rem; cursor: pointer; white-space: nowrap; }
.suggest-row:hover,
.suggest-row.selected { background: var(--accent); color: #14181f; }

/* Squelettes de chargement : cartes fantômes animées. */
.skeleton-card { pointer-events: none; }
.skeleton-poster { aspect-ratio: 2 / 3; border-radius: 8px; }
.skeleton-line { height: 0.9rem; width: 70%; margin-top: 0.55rem; border-radius: 4px; }
.skeleton-poster,
.skeleton-line {
  background: linear-gradient(100deg, var(--panel-2) 40%, var(--hover) 50%, var(--panel-2) 60%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.2s infinite linear;
}
@keyframes skeleton-shimmer {
  from { background-position: 180% 0; }
  to { background-position: -20% 0; }
}

/* Sentinelle du rendu progressif (invisible, déclenche le lot suivant au scroll). */
.render-sentinel { height: 1px; }

/* État vide soigné : emoji + message + action suggérée. */
.empty-view { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }
.empty-view .empty-emoji { font-size: 3rem; margin-bottom: 0.4rem; }
.empty-view h3 { color: var(--text); margin: 0.2rem 0; }
.empty-view p { margin: 0.3rem auto 0; max-width: 420px; }

/* Bandeau de maintenance (visible par tous, écritures désactivées). */
#maintenance-banner {
  position: sticky;
  top: 0;
  z-index: 96;
  background: #7a5b00;
  color: #ffe9b0;
  text-align: center;
  padding: 0.45rem 1rem;
  font-weight: 600;
}

/* Palette de commandes (Ctrl+K) : modal en haut d'écran. */
dialog#cmdk {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: min(560px, 92vw);
  margin-top: 10vh;
  padding: 0.6rem;
}
dialog#cmdk input { width: 100%; }
#cmdk-results { max-height: 50vh; overflow-y: auto; margin-top: 0.4rem; }

/* Résultat de la dernière lecture (✅/⚠️) sur chaînes TV et jaquettes. */
.playcheck { font-size: 0.85em; }

/* Toast avec bouton Annuler (undo 5 s). */
.toast { display: flex; align-items: center; gap: 0.6rem; }
.toast button { flex-shrink: 0; }

/* Puces des filtres actifs au-dessus de la grille. */
.filter-chips { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.filter-chips .chip { margin-left: 0; border-color: var(--accent); }

/* Badge non-lu de la cloche de notifications. */
#notif-badge {
  background: #d04545;
  color: #fff;
  border-radius: 999px;
  font-size: 0.7rem;
  padding: 0 0.35rem;
  margin-left: 0.25rem;
  vertical-align: top;
}
dialog#notif-center {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  max-width: 560px;
  width: 92vw;
  max-height: 70vh;
  overflow-y: auto;
}

/* Menu contextuel des jaquettes (clic droit / appui long). */
.context-menu {
  position: fixed;
  z-index: 130;
  display: flex;
  flex-direction: column;
  min-width: 220px;
  max-height: 330px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
  padding: 0.3rem;
}
.context-menu button {
  background: transparent;
  border: none;
  color: var(--text);
  text-align: left;
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.context-menu button:hover { background: var(--accent); color: #14181f; }

/* Sélection multiple (admin) : voile cliquable + barre d'actions en lot. */
.select-mask {
  position: absolute;
  inset: 0;
  z-index: 6;
  cursor: pointer;
  border: 3px solid rgba(61, 139, 253, 0.45);
  border-radius: 10px;
}
.select-mask.selected { background: rgba(61, 139, 253, 0.3); border-color: #3d8bfd; }
.select-mask.selected::after {
  content: "✓";
  position: absolute;
  top: 6px;
  left: 8px;
  font-size: 1.4rem;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
}
#bulkbar {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 95;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--panel);
  border: 1px solid #3d8bfd;
  border-radius: 999px;
  padding: 0.5rem 1rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
}

/* Formulaire du relais IA (prompt copiable + réponse collée). */
dialog#relay-dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: min(640px, 94vw);
}
dialog#relay-dialog textarea { width: 100%; font-family: ui-monospace, monospace; font-size: 0.85rem; }
dialog#relay-dialog .error { color: #ff7b72; min-height: 1.1em; }

/* Focus clavier visible sur tous les éléments interactifs (navigation au clavier). */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}
.card:focus-visible { outline-offset: 0; }

/* Barre latérale : collée au viewport pendant le scroll, repliable en colonne d'icônes. */
#libraries {
  position: sticky;
  top: 0.75rem;
  align-self: flex-start;
  max-height: calc(100vh - 1.5rem);
  overflow-y: auto;
}
#libraries.collapsed { min-width: 0; width: 56px; }
#libraries.collapsed button {
  width: 44px;
  overflow: hidden;
  white-space: nowrap;
  padding: 0.6rem 0 0.6rem 0.65rem;
  letter-spacing: 4px; /* pousse le texte hors de la zone visible : seule l'icône reste */
}

/* Dialogue générique stylé. */
dialog#ui-dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: min(440px, 92vw);
}
dialog#ui-dialog input { width: 100%; }

/* Visite guidée : voile + encadré d'étape. */
#tour-overlay {
  position: fixed;
  inset: 0;
  z-index: 140;
  background: rgba(0, 0, 0, 0.55);
}
#tour-box {
  position: fixed;
  max-width: 330px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.6);
}
#tour-box p { margin: 0 0 0.6rem; }

/* Navigation mobile : barre fixe en bas, menu complet en panneau latéral. */
#mobile-nav { display: none; }
@media (max-width: 720px) {
  #mobile-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 94;
    background: var(--panel);
    border-top: 1px solid var(--border);
    justify-content: space-around;
  }
  #mobile-nav button {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.1rem;
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 1.15rem;
    padding: 0.45rem 0;
  }
  #mobile-nav button span { font-size: 0.62rem; color: var(--muted); }
  main { padding-bottom: 4.5rem; } /* laisse la place à la barre */
  #radio-bar { bottom: 3.4rem; } /* la barre audio se pose au-dessus de la navigation */
  #libraries {
    position: fixed;
    top: 0;
    bottom: 0;
    left: -80vw;
    width: 72vw;
    max-height: none;
    z-index: 96;
    background: var(--bg);
    padding: 1rem;
    transition: left 0.25s;
    box-shadow: 6px 0 24px rgba(0, 0, 0, 0.5);
  }
  #libraries.open { left: 0; }
}

/* Télécommande : gros boutons tactiles. */
dialog#remote-dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: min(380px, 92vw);
}
.remote-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; margin: 0.6rem 0; }
.remote-grid button { padding: 0.9rem 0.5rem; font-size: 1.05rem; }
.remote-grid #remote-next { grid-column: 1 / -1; }

/* Bandeau handoff : cliquable (bouton) mais visuellement comme un encart. */
.handoff-banner { cursor: pointer; text-align: left; font-weight: 600; width: 100%; }

/* Mode télé (10-feet) : typo agrandie, focus très visible pour la navigation aux flèches. */
body.tv-mode { font-size: 1.15em; }
body.tv-mode .card:focus-visible {
  outline: 4px solid var(--accent);
  outline-offset: 2px;
  transform: scale(1.03);
}
body.tv-mode #libraries button:focus-visible { outline-width: 3px; }

/* Supervision : tuiles de compteurs + mini-courbes. */
.metric-tiles { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-bottom: 0.6rem; }
.tile {
  flex: 1;
  min-width: 96px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.6rem;
  text-align: center;
}
.tile span { display: block; font-size: 1.35rem; font-weight: 700; color: var(--accent); }
.tile label { font-size: 0.75rem; color: var(--muted); }
.charts { display: flex; gap: 0.8rem; flex-wrap: wrap; margin-bottom: 0.4rem; }
.charts label { display: block; font-size: 0.75rem; color: var(--muted); margin-bottom: 0.2rem; }
.charts canvas { background: var(--bg); border-radius: var(--radius-sm); max-width: 100%; }

/* Supervision : ligne de lecture en cours (barre au milieu, temps à droite). */
.now-playing-row .playing-strip { flex: 1; min-width: 80px; margin: 0 0.4rem; }

/* Supervision : journal serveur en direct. */
.log-header { margin: 0.6rem 0 0.3rem; }
.log-view {
  max-height: 220px;
  overflow: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.7rem;
  font-family: ui-monospace, monospace;
  font-size: 0.75rem;
  white-space: pre-wrap;
  word-break: break-word;
}
