/* Direction « salle de projection » (docs/ARCHITECTURE.md) : thème sombre, un seul
   accent (le jaune sous-titre), police système. La régie est projetée et lue
   de loin ; les joueurs sont sur téléphone (mise en page mobile d'abord). */

/* ===== JETONS ===== */
:root {
  color-scheme: dark;

  --color-bg: #0e1014;
  --color-surface: #171a21;
  --color-surface-2: #20242d;
  --color-surface-3: #2c313c;
  --color-border: #2c313c;
  --color-border-strong: #3a404c;
  --color-text: #f2f4f8;
  --color-text-muted: #a3abba;
  --color-text-faint: #7d8594;
  --color-accent: #ffd23f;
  --color-accent-hover: #ffe27a;
  --color-accent-soft: #262214;
  --color-on-accent: #1a1400;
  --color-info: #8ad8ff;
  --color-info-soft: #123447;
  --color-danger: #ff8a8a;
  --color-danger-soft: #3a1f22;
  --color-focus: #8ad8ff;
  --color-success: #7ee2a8;
  --color-success-soft: #173326;
  --color-warning: #ffb547;
  --color-video: #000;

  --font-family:
    system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif,
    "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji";
  --fs-small: 13px;
  --fs-body: 17px;
  --fs-button: 16px;
  --fs-title: 20px;
  --fs-brand: 20px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  --tap: 44px; /* cible tactile minimale */
  --control-height: 48px;

  --duration-fast: 120ms;
  --duration-base: 250ms;

  /* Sous-titres : blanc gras, ombre noire en contour, bandeau translucide */
  --subtitle-color: #fff;
  --subtitle-band: rgb(0 0 0 / 45%);
  --subtitle-shadow: 0 0 3px #000, 0 0 1px #000, 0 2px 5px rgb(0 0 0 / 90%);
}

/* Régie sur grand écran : tout plus grand, lisible à quelques mètres */
@media (min-width: 1280px) {
  body[data-view="remoteView"],
  body[data-view="hallOfFameView"] {
    --fs-small: 17px;
    --fs-body: 22px;
    --fs-button: 21px;
    --fs-title: 28px;
    --fs-brand: 26px;
    --control-height: 60px;
  }
}

/* ===== BASE ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font-family);
  font-size: var(--fs-body);
  line-height: 1.4;
  background: var(--color-bg);
  color: var(--color-text);
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

h2 {
  margin: 0;
}

:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
}

.visuallyHidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ===== BOUTONS ET CHAMPS ===== */
.btn,
.pill {
  display: inline-flex;
  text-decoration: none;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--control-height);
  min-width: var(--tap);
  padding: 0 var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
  color: var(--color-text);
  font-size: var(--fs-button);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition:
    background-color var(--duration-fast) ease,
    border-color var(--duration-fast) ease,
    transform var(--duration-fast) ease;
}

.btn:hover:not(:disabled),
.pill:hover {
  background: var(--color-surface-3);
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn-primary {
  border-color: transparent;
  background: var(--color-accent);
  color: var(--color-on-accent);
  font-weight: 800;
}

.btn-primary:hover:not(:disabled) {
  background: var(--color-accent-hover);
}

.btn-danger {
  border-color: transparent;
  background: var(--color-danger-soft);
  color: var(--color-danger);
  font-weight: 700;
}

.btn-danger:hover:not(:disabled) {
  background: #4a262a;
}

.btn:disabled {
  border-style: dashed;
  border-color: var(--color-border-strong);
  background: transparent;
  color: var(--color-text-faint);
  cursor: not-allowed;
}

.btn-small {
  min-height: var(--tap);
  padding: 0 var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--fs-small);
}

.pill {
  border-radius: var(--radius-pill);
  font-size: var(--fs-small);
}

.field {
  min-height: var(--control-height);
  min-width: 0;
  padding: 0 var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: var(--fs-body);
}

select.field {
  background: var(--color-surface-2);
  font-weight: 600;
}

.field:focus {
  border-color: var(--color-accent);
}

.field-time {
  font-variant-numeric: tabular-nums;
}

.fieldGroup {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.fieldGroup label {
  font-size: var(--fs-small);
  color: var(--color-text-muted);
}

.row {
  display: flex;
  gap: var(--space-2);
}

.row > .field {
  flex: 1;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.card {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
}

.cardTitle {
  font-size: var(--fs-title);
  font-weight: 800;
}

.emptyState {
  color: var(--color-text-muted);
  font-style: italic;
}

/* ===== MISE EN PAGE ===== */
/* Téléphone (par défaut) : vidéo, vue qui défile, barre en bas */
.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  grid-template-areas: "video" "view" "reactions" "bar";
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

#videoContainer {
  grid-area: video;
}

.viewContainer {
  grid-area: view;
  overflow-y: auto;
  padding: var(--space-3) var(--space-4);
}

.appBar {
  grid-area: bar;
}

/* ===== BARRE ===== */
.appBar {
  position: relative;
  z-index: 300;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4)
    max(var(--space-3), env(safe-area-inset-bottom));
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
}

.brand {
  display: none;
  font-size: var(--fs-brand);
  font-weight: 800;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.appBarSpacer {
  flex: 1;
}

#playerName {
  max-width: 40vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Connexion au serveur : pastille seule sur téléphone, libellé sur grand écran */
.connection {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--tap);
  font-size: var(--fs-small);
  color: var(--color-text-muted);
  white-space: nowrap;
}

.connection::before {
  content: "";
  width: 12px;
  height: 12px;
  border-radius: var(--radius-pill);
  background: var(--color-warning);
}

.connection[data-state="online"]::before {
  background: var(--color-success);
}

.connection[data-state="offline"]::before {
  background: var(--color-danger);
}

.connection[data-state="offline"] {
  color: var(--color-danger);
}

@media (max-width: 1023px) {
  .connection:not([data-state="offline"]) .connectionLabel {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}

#submitButton {
  flex: 1 1 12rem;
  font-size: calc(var(--fs-button) + 2px);
}

body:not([data-view="playerView"]) #submitButton {
  display: none;
}

/* ===== MENUS (vues, réactions) ===== */
.action-menu {
  position: relative;
}

.action-menu-panel {
  position: absolute;
  bottom: calc(100% + var(--space-2)); /* ouvre vers le haut */
  left: 0;
  z-index: 400;
  display: none;
  gap: var(--space-1);
  padding: var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
  box-shadow: 0 8px 24px rgb(0 0 0 / 50%);
}

.action-menu.open .action-menu-panel {
  display: grid;
}

.action-menu-item {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: var(--tap);
  min-height: var(--tap);
  padding: var(--space-1) var(--space-3);
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text);
  font-size: var(--fs-button);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.action-menu-item:hover {
  background: var(--color-surface-3);
}

.action-menu-item[aria-current="page"] {
  background: var(--color-surface-3);
  font-weight: 800;
}

.viewMenu .action-menu-panel {
  grid-auto-rows: auto;
  min-width: 12rem;
}

.viewMenu .action-menu-item {
  justify-content: flex-start;
}

.emoticonMenu .action-menu-panel {
  left: auto;
  right: 0;
  grid-auto-flow: column;
  grid-template-rows: repeat(9, auto);
}

.emoticonMenu .action-menu-item {
  font-size: 28px;
  padding: var(--space-1);
}

/* ===== RÉACTIONS (vue ✍️) ===== */
.reactionBar {
  grid-area: reactions;
  position: relative;
  z-index: 300;
  display: flex;
  justify-content: space-between;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-3);
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
}

body:not([data-view="playerView"]) .reactionBar {
  display: none;
}

.reactionQuick {
  min-width: var(--tap);
  min-height: var(--tap);
  border: none;
  border-radius: var(--radius-pill);
  background: transparent;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}

.reactionQuick:hover {
  background: var(--color-surface-3);
}

.reactionQuick:disabled {
  opacity: 0.35;
  cursor: default;
}

/* ===== VIDÉO ===== */
#videoContainer {
  position: relative;
  container-type: size;
  height: min(56.25vw, 40dvh);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--color-video);
}

/* Remplit le cadre, même pour une vidéo de petite définition */
#videoContainer video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

body[data-view="libraryView"] #gameVideo,
body:not([data-view="libraryView"]) #libraryVideo {
  display: none;
}

video::-webkit-media-controls-fullscreen-button {
  display: none;
}

#viewInfo {
  position: absolute;
  top: var(--space-2);
  left: var(--space-3);
  z-index: 210;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  background: rgb(14 16 20 / 75%);
  font-size: var(--fs-small);
  font-weight: 700;
  pointer-events: none;
}

/* Minuteur de manche : en haut à droite de la vidéo */
.timerDisplay {
  position: absolute;
  top: var(--space-2);
  right: var(--space-3);
  z-index: 210;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  background: rgb(14 16 20 / 75%);
  font-size: var(--fs-small);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.timerDisplay[hidden],
body[data-view="libraryView"] .timerDisplay {
  display: none;
}

.timerDisplay-urgent {
  color: var(--color-danger);
}

.subtitleOverlay {
  position: absolute;
  left: 6%;
  right: 6%;
  bottom: 6%;
  z-index: 200;
  text-align: center;
  pointer-events: none;
  /* Taille relative à la hauteur de la vidéo : ~19 px au téléphone, ~40 px
     sur la régie, ~55 px en plein écran 1080p */
  font-size: 20px;
  font-size: clamp(16px, calc(4.5cqh + 8px), 72px);
  font-weight: 800;
  line-height: 1.35;
  white-space: pre-line;
}

/* Bandeau qui suit chaque ligne du sous-titre */
.subtitleLine {
  padding: 0.08em 0.4em;
  border-radius: 0.25em;
  background: var(--subtitle-band);
  color: var(--subtitle-color);
  text-shadow: var(--subtitle-shadow);
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

/* Vue joueur : la vidéo garde ses commandes natives, le sous-titre passe au-dessus */
#subtitleOverlayLocal {
  bottom: max(6%, 52px);
}

body:not([data-view="playerView"]) #subtitleOverlayLocal,
body:not([data-view="remoteView"], [data-view="hallOfFameView"])
  #subtitleOverlayRemote {
  display: none;
}

#videoContainer:fullscreen {
  width: 100vw;
  height: 100vh;
}

#videoContainer:fullscreen #viewInfo {
  display: none;
}

/* Aperçu local de la régie : bandeau en haut de la vidéo */
.previewBar {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  right: var(--space-2);
  z-index: 220;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-1) var(--space-1) var(--space-1) var(--space-3);
  border: 1px solid var(--color-info);
  border-radius: var(--radius-md);
  background: rgb(14 16 20 / 85%);
}

.previewTitle {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--color-info);
  font-weight: 700;
}

#videoContainer:has(.previewBar:not([hidden])) #viewInfo {
  display: none;
}

/* ===== VUE JOUEUR ===== */
#subtitlesList {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  max-width: 56rem;
  margin: 0 auto;
}

.subtitleItem {
  display: flex;
  align-items: stretch;
  gap: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  transition:
    background-color var(--duration-base) ease,
    border-color var(--duration-base) ease;
}

.subtitleItem.active {
  border: 2px solid var(--color-accent);
  background: var(--color-accent-soft);
}

.seekButton {
  flex: none;
  width: var(--tap);
  min-height: var(--tap);
  border: none;
  border-radius: var(--radius-sm);
  background: var(--color-surface-2);
  color: var(--color-text);
  font-size: 18px;
  cursor: pointer;
}

.subtitleItem.active .seekButton {
  background: var(--color-accent);
  color: var(--color-on-accent);
}

.subtitleText {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}

.subtitleTime {
  font-size: var(--fs-small);
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

.subtitleItem.active .subtitleTime {
  color: var(--color-accent-hover);
}

.subtitleInput {
  width: 100%;
  min-height: var(--tap);
}

.subtitleItem.active .subtitleInput {
  border-color: var(--color-accent);
}

/* Écran tactile : pendant la saisie, le clavier cache le bas de l'écran ; on
   masque les répliques au-dessus de la précédente pour garder la courante
   visible sous la vidéo */
@media (pointer: coarse) {
  #subtitlesList.editing .subtitleItem.beforeEditing {
    display: none;
  }
}

.pulse-once {
  animation: pulseOnce 600ms ease-out;
}

@keyframes pulseOnce {
  0% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgb(255 210 63 / 60%);
  }
  60% {
    transform: scale(1.05);
    box-shadow: 0 0 0 12px rgb(255 210 63 / 0%);
  }
  100% {
    transform: scale(1);
    box-shadow: none;
  }
}

/* ===== VUE RÉGIE ===== */
#remoteView {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.remoteControls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

#saveNameInput {
  flex: 1 1 10rem;
}

.remoteSide {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.playerItem {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: calc(var(--control-height) + 8px);
  padding: 0 var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
  color: var(--color-text);
  text-align: left;
  cursor: pointer;
}

.playerItem:not(.submitted) {
  border-style: dashed;
  border-color: var(--color-border-strong);
  background: transparent;
  color: var(--color-text-muted);
}

.playerItem.selected {
  border: 2px solid var(--color-accent);
  background: var(--color-accent-soft);
  color: var(--color-text);
}

.playerName {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: calc(var(--fs-body) + 3px);
  font-weight: 700;
}

.status {
  flex: none;
  padding: 2px var(--space-3);
  border-radius: var(--radius-pill);
  font-size: var(--fs-small);
  font-weight: 700;
}

.status-onScreen {
  background: var(--color-accent);
  color: var(--color-on-accent);
}

.status-toShow {
  background: var(--color-info-soft);
  color: var(--color-info);
}

.status-shown {
  background: var(--color-surface-3);
  color: #c9cfda;
}

.status-writing {
  padding: 0;
  color: var(--color-text-muted);
}

.saveItem {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
}

.saveName {
  flex: 1 1 8rem;
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 600;
}

.saveItem .btn {
  background: var(--color-surface-3);
}

.saveItem .btn-danger {
  background: var(--color-danger-soft);
}

/* Sauvegardes groupées par clip : le clip en cours, puis les autres repliés */
.saveGroup {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.saveGroupTitle {
  font-size: var(--fs-small);
  font-weight: 700;
  color: var(--color-text-muted);
}

.saveOthersTitle {
  margin-top: var(--space-2);
}

details.saveGroup > summary {
  display: flex;
  align-items: center;
  min-height: var(--tap);
  padding: 0 var(--space-3);
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
  color: var(--color-text);
  cursor: pointer;
}

.cardHint,
.playerKey {
  font-size: var(--fs-small);
  font-weight: 600;
  color: var(--color-text-faint);
}

.playerKey {
  flex: none;
  min-width: 1.6em;
  padding: 0 var(--space-1);
  border: 1px solid var(--color-border-strong);
  border-radius: 6px;
  font-family: inherit;
  text-align: center;
}

/* La régie est lue de loin : l'indice des touches n'apparaît qu'avec un
   pointeur précis (clavier et souris) */
@media (pointer: coarse) {
  .cardHint,
  .playerKey {
    display: none;
  }
}

/* Film : timeline et rendu */
.filmBar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
}

#timelineContainer {
  flex: 1 1 20rem;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  min-height: calc(var(--control-height) + 16px);
  padding: var(--space-2);
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg);
}

.timelineLabel {
  flex: none;
  padding: 0 var(--space-2);
  font-weight: 800;
  white-space: nowrap;
}

.timelineClipItem {
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  max-width: 24rem;
  min-height: var(--control-height);
  padding: 0 var(--space-1) 0 var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
}

.timelineClipLabel {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.timelineList {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
}

.timelineClipItem {
  cursor: grab;
  transition: opacity var(--duration-fast) ease;
}

.timelineClipItem.dragging {
  opacity: 0.4;
}

/* Emplacement du dépôt pendant un glisser-déposer */
.timelineClipItem.dropBefore {
  box-shadow: -4px 0 0 var(--color-accent);
}

.timelineClipItem.dropAfter {
  box-shadow: 4px 0 0 var(--color-accent);
}

.timelineClipItem .btn {
  flex: none;
}

.timelineEmpty {
  margin: 0;
  white-space: nowrap;
}

.progress {
  width: 10rem;
  height: 12px;
  accent-color: var(--color-accent);
}

.filmActions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

/* ===== ANIMATIONS (P6) ===== */
/* Réactions des joueurs et salve du film prêt : flottent au-dessus de la
   vidéo. Position posée par effects.js (--float-x, --float-y, --float-drift) */
.emoticon {
  position: absolute;
  left: var(--float-x, 50%);
  top: var(--float-y, 80%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
  font-size: clamp(40px, 9cqh, 96px);
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -50%);
  animation: floatUp 3s ease-out var(--float-delay, 0ms) forwards;
}

.emoticon .emoticonName {
  padding: 2px var(--space-2);
  border-radius: 6px;
  background: rgb(14 16 20 / 85%);
  color: var(--color-text);
  font-size: clamp(14px, 2.5cqh, 24px);
  font-weight: 600;
}

@keyframes floatUp {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.4);
  }
  12% {
    opacity: 1;
    transform: translate(-50%, -60%) scale(1.15);
  }
  25% {
    transform: translate(calc(-50% + var(--float-drift, 0) * 12px), -75%)
      scale(1);
  }
  75% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(
        calc(-50% + var(--float-drift, 0) * 48px),
        calc(-50% - 22cqh)
      )
      scale(1);
  }
}

/* Mode présentation : nom du joueur dont la copie passe à l'écran */
.revealBanner {
  position: absolute;
  top: 12%;
  left: 50%;
  z-index: 300;
  max-width: 90%;
  padding: var(--space-3) var(--space-5);
  border: 2px solid var(--color-accent);
  border-radius: var(--radius-pill);
  background: rgb(14 16 20 / 85%);
  color: var(--color-accent);
  font-size: clamp(20px, calc(4cqh + 8px), 56px);
  font-weight: 800;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  opacity: 0;
  transform: translateX(-50%);
}

.revealBanner-play {
  animation: revealBanner 2.6s ease-out forwards;
}

@keyframes revealBanner {
  0% {
    opacity: 0;
    transform: translateX(-50%) translateY(-24px) scale(0.85);
  }
  12% {
    opacity: 1;
    transform: translateX(-50%) translateY(0) scale(1.06);
  }
  20% {
    transform: translateX(-50%) scale(1);
  }
  80% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateX(-50%) scale(1);
  }
}

body:not([data-view="remoteView"]) .revealBanner,
body:not([data-view="remoteView"]) .voteButton {
  display: none;
}

.voteButton {
  position: absolute;
  bottom: 12%;
  left: 50%;
  z-index: 300;
  transform: translateX(-50%);
}

.voteButton[hidden] {
  display: none;
}

.voteCount {
  font-weight: 700;
  color: var(--color-accent);
}

/* Régie : chaque nouvelle réplique entre en glissant */
.subtitleOverlay.subtitleEnter {
  animation: subtitleEnter var(--duration-base) ease-out;
}

@keyframes subtitleEnter {
  from {
    opacity: 0;
    transform: translateY(0.4em) scale(0.96);
  }
}

/* Joueur qui rend sa copie (régie et écran d'accueil), joueur qui arrive */
.pop {
  animation: pop 500ms ease-out;
}

@keyframes pop {
  0% {
    transform: scale(1);
  }
  35% {
    transform: scale(1.08);
    box-shadow: 0 0 0 6px rgb(126 226 168 / 45%);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 12px rgb(126 226 168 / 0%);
  }
}

@media (prefers-reduced-motion: reduce) {
  /* Plus de mouvement, mais un fondu : animationend part toujours (les
     éléments animés sont retirés ou masqués à la fin) */
  .emoticon {
    transform: translate(-50%, -50%);
    animation-name: fadeOut;
  }

  .revealBanner-play {
    animation-name: fadeOut;
  }

  .podium[open] .podiumStep {
    animation-name: podiumFade;
  }

  .subtitleOverlay.subtitleEnter,
  .lobbyPlayer-enter {
    animation-name: fadeIn;
  }

  /* Sans effet visible, mais même durée (un libellé suit animationend) */
  .pulse-once,
  .pop {
    animation-name: still;
  }

  @keyframes still {
    to {
      opacity: 1;
    }
  }

  @keyframes fadeOut {
    0%,
    80% {
      opacity: 1;
    }
    100% {
      opacity: 0;
    }
  }

  @keyframes fadeIn {
    from {
      opacity: 0;
    }
  }
}

/* ===== ÉCRAN D'ACCUEIL DE PARTIE (régie, lisible de loin) ===== */
.cardHeader {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.lobby {
  width: min(100% - 2 * var(--space-4), 72rem);
  max-height: calc(100% - 2 * var(--space-4));
  padding: var(--space-6);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  color: var(--color-text);
}

.lobby::backdrop {
  background: rgb(0 0 0 / 80%);
}

.lobby[open] {
  animation: toastIn var(--duration-base) ease-out;
}

.lobbyInner {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.lobbyTitle {
  color: var(--color-accent);
  font-size: clamp(28px, 5vw, 56px);
  font-weight: 800;
  text-align: center;
}

.lobbyBody {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: center;
  gap: var(--space-6);
}

.lobbyQr {
  flex: none;
  width: min(100%, 60vh, 26rem);
  aspect-ratio: 1;
  border-radius: var(--radius-md);
}

/* Modules sombres sur fond clair : contraste attendu par les lecteurs de QR */
.lobbyQrBackground {
  fill: #fff;
}

.lobbyQrModules {
  fill: var(--color-bg);
  shape-rendering: crispEdges;
}

.lobbyInfo {
  display: flex;
  flex: 1 1 18rem;
  flex-direction: column;
  gap: var(--space-3);
  min-width: 0;
}

.lobbyHint {
  margin: 0;
  color: var(--color-text-muted);
  font-size: var(--fs-title);
}

.lobbyUrl {
  margin: 0;
  color: var(--color-info);
  font-size: clamp(24px, 3.5vw, 48px);
  font-weight: 800;
  overflow-wrap: anywhere;
}

.lobbyPlayers {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
}

.lobbyPlayer {
  padding: var(--space-2) var(--space-4);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-pill);
  background: var(--color-surface-2);
  font-size: var(--fs-title);
  font-weight: 700;
}

.lobbyPlayer.submitted {
  border-color: var(--color-success);
  background: var(--color-success-soft);
}

.lobbyPlayer-enter {
  animation: lobbyPlayerEnter 450ms ease-out;
}

@keyframes lobbyPlayerEnter {
  0% {
    opacity: 0;
    transform: translateY(12px) scale(0.6);
  }
  60% {
    opacity: 1;
    transform: scale(1.1);
  }
}

.lobbyStart {
  align-self: center;
  min-width: 14rem;
}

@media (prefers-reduced-motion: reduce) {
  .lobby[open] {
    animation: none;
  }
}

/* ===== CLASSEMENT ET PODIUM ===== */
.scoreboard,
.podiumRest {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
}

.scoreboard li,
.podiumRest li {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.scoreRank {
  min-width: 1.5em;
  color: var(--color-text-muted);
  font-weight: 700;
  text-align: center;
}

.podiumSteps {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: var(--space-4);
  margin: 0;
  padding: 0;
  list-style: none;
}

.podiumStep {
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: var(--space-2);
  max-width: 16rem;
  padding: var(--space-4) var(--space-3);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  background: var(--color-surface-2);
  text-align: center;
}

.podiumStep-1 {
  order: 2;
  min-height: 14rem;
  border-color: var(--color-accent);
  background: var(--color-accent-soft);
}

.podiumStep-2 {
  order: 1;
  min-height: 10.5rem;
}

.podiumStep-3 {
  order: 3;
  min-height: 8rem;
}

.podiumMedal {
  font-size: clamp(36px, 7vw, 72px);
  line-height: 1;
}

.podiumName {
  max-width: 100%;
  overflow: hidden;
  font-size: clamp(18px, 3vw, 32px);
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.podiumPoints {
  color: var(--color-accent);
  font-weight: 700;
}

.podiumRest {
  align-self: center;
  min-width: min(100%, 20rem);
}

.podium[open] .podiumStep {
  animation: podiumRise 600ms ease-out backwards;
}

.podium[open] .podiumStep-1 {
  animation-delay: 500ms;
}

.podium[open] .podiumStep-2 {
  animation-delay: 250ms;
}

@keyframes podiumFade {
  from {
    opacity: 0;
  }
}

@keyframes podiumRise {
  from {
    opacity: 0;
    transform: translateY(40px);
  }
}

/* ===== RETOURS : TOASTS ET CONFIRMATION ===== */
.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(var(--control-height) + var(--space-6));
  z-index: 900;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  width: min(100% - 2 * var(--space-4), 32rem);
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
  color: var(--color-text);
  box-shadow: 0 8px 24px rgb(0 0 0 / 50%);
  font-weight: 600;
  pointer-events: auto;
  cursor: pointer;
  animation: toastIn var(--duration-base) ease-out;
}

.toast-success {
  border-color: var(--color-success);
  background: var(--color-success-soft);
}

.toast-error {
  border-color: var(--color-danger);
  background: var(--color-danger-soft);
  color: var(--color-danger);
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

.confirmDialog {
  width: min(100% - 2 * var(--space-4), 28rem);
  padding: var(--space-5);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  color: var(--color-text);
}

.confirmDialog::backdrop {
  background: rgb(0 0 0 / 60%);
}

.confirmMessage {
  margin: 0;
  color: var(--color-text-muted);
}

.confirmActions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

@media (prefers-reduced-motion: reduce) {
  .toast {
    animation: none;
  }
}

/* ===== VUE LIBRAIRIE ===== */
#libraryView {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.libraryTimes {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
}

/* ===== VUE HALL OF FAME ===== */
/* Pas de vidéo dans cette vue : la liste prend toute la hauteur */
body[data-view="hallOfFameView"] {
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas: "view" "bar";
}

body[data-view="hallOfFameView"]:not(:has(#previewBar:not([hidden])))
  #videoContainer {
  display: none;
}

/* « ▶️ Revoir » une copie : le lecteur revient au-dessus de la liste */
body[data-view="hallOfFameView"]:has(#previewBar:not([hidden])) {
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "video" "view" "bar";
}

#hallOfFameView {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.hallList {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.hallRound {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.hallRoundTitle {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-1) var(--space-2);
  margin: 0;
  font-size: var(--fs-body);
  font-weight: 800;
}

.hallDate,
.hallTie,
.hallMissing {
  font-size: var(--fs-small);
  font-weight: 600;
  color: var(--color-text-muted);
}

.hallMissing {
  color: var(--color-warning);
}

.hallRoundCopies {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 24rem), 1fr));
  gap: var(--space-3);
}

.hallCopy,
.hallPodium {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
}

.hallCopy {
  border-color: var(--color-accent);
}

.hallCopyHeader {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2);
}

.hallCopyName,
.hallRankingName {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 800;
}

/* Les répliques, comme des sous-titres à l'écran */
.hallCopyText {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin: 0;
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--color-video);
  color: var(--subtitle-color);
  font-size: calc(var(--fs-body) * 1.15);
  font-weight: 700;
  text-align: center;
  text-shadow: var(--subtitle-shadow);
}

.hallCopyText p {
  margin: 0;
  overflow-wrap: anywhere;
  white-space: pre-line;
}

.hallRemove {
  align-self: flex-end;
  margin-top: auto;
}

.hallCopyActions {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-2);
  margin-top: auto;
}

.hallPodiums {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 18rem), 1fr));
  gap: var(--space-3);
}

.hallRanking {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
}

.hallRankingRow {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.hallRankingName {
  flex: 1 1 auto;
}

.hallRankingRow:not(.hallRankingTop) {
  color: var(--color-text-muted);
}

@media (max-width: 1023px) {
  .remoteControls .appBarSpacer {
    display: none;
  }
}

/* ===== GRAND ÉCRAN ===== */
@media (min-width: 1024px) {
  .app {
    grid-template-rows: auto minmax(0, 1fr) minmax(0, 1fr) auto;
    grid-template-areas: "bar" "video" "view" "reactions";
  }

  .toasts {
    top: calc(var(--control-height) + var(--space-6));
    bottom: auto;
  }

  .appBar {
    padding: var(--space-3) var(--space-5);
    border-top: none;
    border-bottom: 1px solid var(--color-border);
  }

  .brand {
    display: inline;
    margin-right: var(--space-4);
  }

  #videoContainer {
    height: auto;
  }

  #viewInfo {
    display: none;
  }

  .viewContainer {
    padding: var(--space-4) var(--space-5);
  }

  #submitButton {
    flex: 0 0 auto;
  }

  /* Le menu ⚙️ devient des onglets */
  .viewMenu {
    order: -1;
  }

  .viewMenu .action-menu-toggle {
    display: none;
  }

  .viewMenu .action-menu-panel {
    position: static;
    display: flex;
    min-width: 0;
    padding: var(--space-1);
    background: var(--color-bg);
    box-shadow: none;
  }

  .viewMenu .action-menu-item {
    color: var(--color-text-muted);
  }

  .viewMenu .action-menu-item[aria-current="page"] {
    color: var(--color-text);
  }

  .brand {
    order: -2;
  }

  /* Régie : grande vidéo à gauche, joueurs à droite, film en bas */
  body[data-view="remoteView"] {
    grid-template-columns: minmax(0, 1fr) clamp(360px, 30vw, 620px);
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    grid-template-areas:
      "bar bar"
      "video side"
      "controls side"
      "film film";
    column-gap: var(--space-5);
  }

  body[data-view="remoteView"] #remoteView {
    display: contents;
  }

  body[data-view="remoteView"] #videoContainer {
    margin: var(--space-5) 0 0 var(--space-5);
    border-radius: var(--radius-lg);
  }

  .remoteControls {
    grid-area: controls;
    padding: var(--space-4) 0 var(--space-4) var(--space-5);
  }

  .remoteSide {
    grid-area: side;
    min-height: 0;
    overflow-y: auto;
    padding: var(--space-5) var(--space-5) var(--space-4) 0;
  }

  .filmBar {
    grid-area: film;
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--color-border);
    background: var(--color-surface);
  }

  /* Librairie : vidéo à gauche, formulaire à droite */
  body[data-view="libraryView"] {
    grid-template-columns: minmax(0, 1fr) clamp(360px, 32vw, 520px);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas:
      "bar bar"
      "video view";
    column-gap: var(--space-5);
  }

  body[data-view="libraryView"] #videoContainer {
    margin: var(--space-5) 0 var(--space-5) var(--space-5);
    border-radius: var(--radius-lg);
  }

  body[data-view="libraryView"] .viewContainer {
    padding: var(--space-5) var(--space-5) var(--space-5) 0;
  }

  body[data-view="hallOfFameView"] {
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "bar" "view";
  }

  body[data-view="hallOfFameView"] .viewContainer {
    padding: var(--space-5);
  }

  /* Copie revue : vidéo à gauche, liste à droite (comme 📚) */
  body[data-view="hallOfFameView"]:has(#previewBar:not([hidden])) {
    grid-template-columns: minmax(0, 1fr) clamp(360px, 32vw, 520px);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas:
      "bar bar"
      "video view";
    column-gap: var(--space-5);
  }

  body[data-view="hallOfFameView"] #videoContainer {
    margin: var(--space-5) 0 var(--space-5) var(--space-5);
    border-radius: var(--radius-lg);
  }

  body[data-view="hallOfFameView"]:has(#previewBar:not([hidden]))
    .viewContainer {
    padding: var(--space-5) var(--space-5) var(--space-5) 0;
  }
}

/* ===== PAGE DE CONNEXION ===== */
.loginPage {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: var(--space-4);
}

.loginBox {
  width: min(100%, 22rem);
}

.loginBox h1 {
  margin: 0;
  font-size: var(--fs-title);
}

.loginBox .field,
.loginBox .btn {
  width: 100%;
}

.loginError {
  min-height: 1.4em;
  color: var(--color-danger);
}
