/* Page publique de la Vidéothèque. Couleurs issues de constants/colors.ts (thème sombre : EmbedDark),
   gardées par scripts/verify-video-embed.cjs. Échelle du DS 2.0. Sans réglage, aucune classe de thème :
   les variables valent exactement ce que rendaient les codes déjà posés. */
@font-face { font-family: 'Outfit'; font-weight: 600; font-display: swap; src: url('fonts/Outfit_600SemiBold.ttf') format('truetype'); }
@font-face { font-family: 'DM Sans'; font-weight: 400; font-display: swap; src: url('fonts/DMSans_400Regular.ttf') format('truetype'); }
@font-face { font-family: 'DM Sans'; font-weight: 600; font-display: swap; src: url('fonts/DMSans_600SemiBold.ttf') format('truetype'); }

:root {
  color-scheme: light;
  --bg: #F7F9FC;
  --surface: #FFFFFF;
  --surface-alt: #F4F7FC;
  --ink: #191919;
  --muted: #5A6473;
  --line: #DEE6F0;
  --field: #8A93A1;
  --brand: #003E7E;
  --on-brand: #FFFFFF;
  --focus: #003E7E;
  --frame: #191919;
  --on-frame: #FFFFFF;
  --panel: var(--surface);
  --rad-card: 12px;
  --rad-frame: 8px;
  --rad-ctl: 6px;
  --error: #B3352F;
  --error-bg: #FAE6E4;
  --heading: 'Outfit', system-ui, sans-serif;
  --body: 'DM Sans', system-ui, sans-serif;
  --touch: 44px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 400 14px/20px var(--body); color: var(--ink); background: transparent; overflow-wrap: anywhere; }
body.share { background: var(--bg); }
/* Marge pour que l'anneau de focus ne soit pas coupé par le bord de l'iframe. */
body:not(.share) #app { padding: 4px; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
h1, h2 { margin: 0; font-family: var(--heading); font-weight: 600; }
h1 { font-size: 24px; line-height: 30px; }
h2 { font-size: 15px; line-height: 20px; }
p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }

.topbar { background: var(--surface); border-bottom: 1px solid var(--line); padding: 12px 16px; font: 600 20px/24px var(--heading); color: var(--brand); }
.share-main { max-width: 1100px; margin: 0 auto; padding: 16px; display: grid; gap: 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; line-height: 16px; }

/* États */
.state { display: grid; gap: 8px; justify-items: center; text-align: center; padding: 32px 16px; }
.btn { min-height: var(--touch); padding: 0 16px; border: 0; border-radius: var(--rad-ctl); font-weight: 600; background: var(--brand); color: var(--on-brand); }
.btn:disabled { opacity: 0.6; }
.btn.secondary { background: var(--line); color: var(--ink); }

/* Formulaire de mot de passe */
.card-form { width: 100%; max-width: 420px; margin: 32px auto; padding: 24px; display: grid; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.lock-banner { display: block; position: relative; height: 96px; margin: -24px -24px 4px; background: var(--brand); }
.lock-banner::before { content: ''; position: absolute; top: 24px; left: 50%; width: 20px; height: 22px; margin-left: -13px; border: 3px solid var(--on-brand); border-bottom: 0; border-radius: 13px 13px 0 0; }
.lock-banner::after { content: ''; position: absolute; top: 49px; left: 50%; width: 34px; height: 24px; margin-left: -17px; border-radius: 4px; background: var(--on-brand); }
.field { display: grid; gap: 4px; font-size: 13px; line-height: 18px; font-weight: 600; }
.field input { width: 100%; min-height: var(--touch); padding: 0 12px; font-size: 16px; font-weight: 400; background: var(--surface); border: 1px solid var(--field); border-radius: 6px; }
.password-row { display: flex; gap: 8px; }
.password-row input { flex: 1; min-width: 0; }
.notice { padding: 8px 12px; font-size: 12px; line-height: 16px; color: var(--muted); background: var(--surface-alt); border-radius: 6px; }
.form-error:not(:empty) { padding: 8px 12px; color: var(--error); background: var(--error-bg); border-radius: 6px; }

/* Lecteur */
.video-block { display: grid; gap: 8px; min-width: 0; }
.frame { position: relative; width: 100%; aspect-ratio: 16 / 9; background: var(--frame); overflow: hidden; border-radius: var(--rad-frame); }
.frame video { display: block; width: 100%; height: 100%; object-fit: contain; background: var(--frame); }
.poster { position: absolute; inset: 0; width: 100%; height: 100%; padding: 0; border: 0; background: var(--frame); }
.poster img { width: 100%; height: 100%; object-fit: cover; display: block; }
.poster:focus-visible { outline-offset: -4px; outline-color: var(--on-frame); }
.play-mark { position: absolute; top: 50%; left: 50%; width: 64px; height: 64px; margin: -32px 0 0 -32px; border-radius: 50%; background: var(--brand); }
.play-mark::after { content: ''; position: absolute; inset: 20px 18px 20px 24px; background: var(--on-brand); clip-path: polygon(0 0, 100% 50%, 0 100%); }
.overlay { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 16px; text-align: center; color: var(--on-frame); pointer-events: none; }
.overlay.failed { background: var(--frame); pointer-events: auto; }
.controls-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.controls-row label { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.controls-row select { min-height: var(--touch); min-width: 160px; padding: 0 8px; background: var(--surface); border: 1px solid var(--field); border-radius: var(--rad-ctl); }

/* Sections */
.sections { display: grid; gap: 2px; }
.section { width: 100%; min-height: var(--touch); padding: 4px 8px; display: flex; align-items: center; gap: 12px; text-align: left; border: 0; border-radius: var(--rad-ctl); background: transparent; }
.section:hover, .section[aria-current='true'] { background: var(--surface-alt); }
.section .time { min-width: 48px; font-size: 12px; color: var(--muted); }

/* Grille et carrousel */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: var(--touch); padding: 0 16px; border: 0; border-radius: 22px; background: var(--surface-alt); }
.chip[aria-pressed='true'] { background: var(--brand); color: var(--on-brand); font-weight: 600; }
.catalog { display: grid; gap: 16px; }
.videos.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.videos.track { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(240px, 300px); gap: 12px; overflow-x: auto; scroll-snap-type: x proximity; padding-bottom: 4px; }
.videos.track li { scroll-snap-align: start; }
.video-card { width: 100%; height: 100%; padding: 0; display: flex; flex-direction: column; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: var(--rad-card); overflow: hidden; }
.video-card:hover { background: var(--surface-alt); }
.video-card[aria-current='true'] { border-color: var(--brand); }
.thumb { position: relative; display: block; width: 100%; aspect-ratio: 16 / 9; background: var(--line); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.duration { position: absolute; right: 8px; bottom: 8px; padding: 0 6px; font-size: 12px; line-height: 18px; color: var(--on-frame); background: var(--frame); border-radius: 4px; }
.card-text { display: grid; gap: 4px; padding: 12px; }
.card-title { font: 600 15px/20px var(--heading); }
.catalog-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 12px; }
.carousel-nav { display: flex; justify-content: flex-end; gap: 8px; }
.nav-btn { position: relative; width: var(--touch); height: var(--touch); padding: 0; border: 0; border-radius: 50%; background: var(--surface-alt); }
.nav-btn:disabled { opacity: 0.4; }
.nav-btn::after { content: ''; position: absolute; top: 17px; left: 14px; width: 10px; height: 10px; border-top: 2px solid var(--ink); border-right: 2px solid var(--ink); transform: rotate(45deg); }
.nav-btn.prev::after { left: 18px; transform: rotate(-135deg); }

/* Liste de lecture */
.playlist { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr) 320px; align-items: start; }
.playlist-side { display: grid; gap: 8px; min-width: 0; }
.playlist-items { display: grid; gap: 4px; max-height: 480px; overflow-y: auto; }
.playlist-item { width: 100%; min-height: var(--touch); padding: 8px; display: flex; gap: 8px; align-items: center; text-align: left; border: 0; border-radius: var(--rad-ctl); background: transparent; }
.playlist-item:hover, .playlist-item[aria-current='true'] { background: var(--surface-alt); }
.playlist-item .index { min-width: 20px; font-size: 12px; color: var(--muted); }
.playlist-item .label { flex: 1; min-width: 0; }

@media (max-width: 800px) {
  .playlist, .playlist.pl-rows { grid-template-columns: minmax(0, 1fr); }
  .playlist-items { max-height: none; }
}

/* Réglages : thème, accent, coins. Posés sur <html> par applyLook, jamais par défaut. */
.t-sombre {
  color-scheme: dark;
  --bg: #0F1A2B;
  --surface: #172539;
  --surface-alt: #1F3047;
  --ink: #F9FAFB;
  --muted: #A9B4C4;
  --line: #26374F;
  --field: #A9B4C4;
  --brand: #00C4D6;
  --on-brand: #0F1A2B;
  --focus: #00C4D6;
}
.t-sombre body { background: var(--bg); }
.t-transparent { --surface: transparent; --surface-alt: color-mix(in srgb, var(--ink) 6%, transparent); --panel: #FFFFFF; }
.a-turquoise { --brand: #008A96; --on-brand: #FFFFFF; }
.t-sombre.a-turquoise { --brand: #00C4D6; --on-brand: #0F1A2B; }
.a-ink-dark { --on-brand: #191919; }
.a-ink-light { --on-brand: #FFFFFF; }
.r-droit { --rad-card: 0px; --rad-frame: 0px; --rad-ctl: 0px; }
.r-arrondi { --rad-card: 20px; --rad-frame: 16px; --rad-ctl: 10px; }

/* Vignettes et colonnes */
.ratio-4-3 .thumb { aspect-ratio: 4 / 3; }
.ratio-1-1 .thumb { aspect-ratio: 1 / 1; }
.ratio-9-16 .thumb { aspect-ratio: 9 / 16; }
.cols-2 .videos.grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 .videos.grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-4 .videos.grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cols-2 .videos.track { grid-auto-columns: calc((100% - 12px) / 2); }
.cols-3 .videos.track { grid-auto-columns: calc((100% - 24px) / 3); }
.cols-4 .videos.track { grid-auto-columns: calc((100% - 36px) / 4); }

/* Rangées, et rail de la vedette */
.videos.rows { display: grid; gap: 8px; }
.rows .video-card { flex-direction: row; height: auto; }
.rows .thumb { flex: 0 0 200px; width: 200px; }
.rows .card-text { flex: 1; min-width: 0; align-content: center; }
.vedette { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 12px; }
.vedette:has(.rail:empty) { grid-template-columns: minmax(0, 1fr); }
.rail { height: 0; min-height: 100%; overflow-y: auto; }
/* Billet 570 : vignette pleine largeur de la colonne, texte dessous (sélecteur à trois classes : bat .rows et son media query). */
.videos.rail .video-card { flex-direction: column; padding: 6px; gap: 8px; border: 0; background: transparent; }
.rail .video-card:hover, .rail .video-card[aria-current='true'] { background: var(--surface-alt); }
.videos.rail .thumb { flex: 0 0 auto; width: 100%; overflow: hidden; border-radius: var(--rad-frame); }
.rail .card-text { padding: 0; }
.rail .card-title { font-size: 15px; line-height: 20px; }

/* Texte sur l'image : mosaïque et vedette */
.video-card.over { position: relative; border: 0; }
.over .thumb { position: absolute; inset: 0; height: 100%; aspect-ratio: auto; }
.over .card-text { position: absolute; left: 0; right: 0; bottom: 0; padding: 32px 12px 10px; color: var(--on-frame); background: linear-gradient(to top, color-mix(in srgb, var(--frame) 88%, transparent), transparent); }
.over .muted { color: inherit; }
.over .duration { top: 8px; bottom: auto; }
.video-card.hero { aspect-ratio: 16 / 9; }
.hero .card-text { padding: 56px 20px 16px; }
.hero .card-title { font-size: 20px; line-height: 26px; }
.videos.mosaic { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); grid-auto-rows: 170px; grid-auto-flow: dense; gap: 8px; }
.videos.mosaic li:nth-child(6n + 1) { grid-column: span 2; grid-row: span 2; }
.videos.mosaic li:nth-child(6n + 4) { grid-column: span 2; }

/* Liste de lecture en rangées */
.playlist.pl-rows { grid-template-columns: minmax(0, 1fr) 344px; }
.pl-rows .playlist-side { padding: 12px; background: var(--surface-alt); border-radius: var(--rad-card); }
.pl-rows .playlist-item { gap: 10px; padding: 6px; }
.pl-rows .playlist-item:hover, .pl-rows .playlist-item[aria-current='true'] { background: var(--panel); }
.pl-rows .playlist-item[aria-current='true'] .row-title { color: var(--brand); }
.t-sombre .pl-rows .playlist-item[aria-current='true'] .row-title { color: var(--ink); }
.pl-rows .playlist-item[aria-current='true'] { box-shadow: 0 1px 3px color-mix(in srgb, var(--frame) 16%, transparent); }
.pl-rows .index { min-width: 14px; text-align: right; }
.pl-rows .thumb { flex: 0 0 84px; width: 84px; overflow: hidden; border-radius: var(--rad-ctl); }
.pl-rows .label { display: grid; gap: 2px; }
.row-title { font-size: 13px; line-height: 17px; font-weight: 600; }
.title-row { display: flex; align-items: center; gap: 8px; }
.title-row h2 { flex: 1; min-width: 0; }

/* Fenêtre de lecture : empilée sur le catalogue dans la même case de grille, pour que la hauteur de
   #app, donc celle de l'iframe, suive aussi la fenêtre. Sortie du flux, elle échapperait au calcul. */
#app.win-open { display: grid; }
#app.win-open > * { grid-area: 1 / 1; min-width: 0; }
.win { position: relative; z-index: 1; padding: calc(var(--win-top, 0px) + 8px) 8px 8px; background: var(--frame); background: color-mix(in srgb, var(--frame) 88%, transparent); animation: win-fade 200ms ease-out; }
.win-panel { max-width: 960px; margin: 0 auto; padding: 12px; display: grid; gap: 8px; background: var(--panel); border-radius: var(--rad-card); }
.win-panel h2 { flex: 1; min-width: 0; }
.win-head { display: flex; align-items: center; gap: 8px; }
.nav-btn.close::before, .nav-btn.close::after { content: ''; position: absolute; top: 21px; left: 12px; width: 20px; height: 2px; border: 0; background: var(--ink); transform: rotate(45deg); }
.nav-btn.close::before { transform: rotate(-45deg); }
@keyframes win-fade { from { opacity: 0; } to { opacity: 1; } }

@media (max-width: 720px) {
  .cols-3 .videos.grid, .cols-4 .videos.grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cols-2 .videos.track, .cols-3 .videos.track, .cols-4 .videos.track { grid-auto-columns: 78%; }
  .vedette { grid-template-columns: minmax(0, 1fr); }
  .rail { height: auto; min-height: 0; overflow: visible; }
}
@media (max-width: 600px) {
  .rows .thumb { flex-basis: 128px; width: 128px; }
  .videos.mosaic { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-rows: 130px; }
}
@media (max-width: 480px) {
  .cols-2 .videos.grid, .cols-3 .videos.grid, .cols-4 .videos.grid { grid-template-columns: minmax(0, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
