/* ==========================================================
   Lords of Echoes — page Galerie (galerie.html)
   Propriété de l’agent de la page Galerie. Socle commun : monde.css
   (en-tête .m-hero, titres de section .sec-head, boutons .chips, .eyebrow, .lnk, ornement).
   Deux salles, deux accrochages, une seule identité :
   - Salle I, « Dans le jeu » : des fenêtres sur le jeu. Mosaïque à six colonnes
     (une grande et deux petites, trois, deux), filet d’or très fin, cartel dessous.
   - Salle II, « Les tableaux du monde » : chaque tableau garde sa proportion,
     en rangées justifiées ; ses bords se perdent dans la nuit, sans cadre.
   La visionneuse plein écran est à la fin du fichier.
   ========================================================== */

/* ---------- En-tête : l’atelier. Le texte reste sur le mur noir, les esquisses épinglées à sa droite. ---------- */
@media (min-width: 901px) {
  .page-galerie .m-hero > img { object-position: 82% 50%; }
  .page-galerie .m-hero-lead { max-width: 26em; }
}
/* Sur mobile, le voile qui suit le texte vient du socle (monde.css) : le tableau du chevalet reste clair au-dessus du titre. */

/* ---------- Salles ---------- */
.gal-room { padding-bottom: clamp(80px, 9vw, 140px); scroll-margin-top: var(--header-h); }
.gal-room--monde { background: linear-gradient(180deg, var(--night-2) 0%, var(--night) 75%); border-top: 1px solid var(--line-soft); }
.gal-room .sec-head { padding-bottom: clamp(24px, 2.6vw, 36px); }
.gal-chips { justify-content: center; padding: 0 var(--gutter); }
.gal-chips button { padding: 7px 14px; font-size: 11px; }
.gal-count { min-height: 1.5em; margin-top: 12px; padding: 0 var(--gutter); text-align: center; font-family: var(--font-tale); font-style: italic; font-size: 17px; color: var(--muted); }

/* ---------- Travées : une par lieu du jeu (salle I), une par page d’origine (salle II) ---------- */
.gal-bay { width: 100%; max-width: calc(1280px + 2 * var(--gutter)); margin: clamp(36px, 4vw, 60px) auto 0; padding: 0 var(--gutter); scroll-margin-top: calc(var(--header-h) + 24px); }
.gal-bay + .gal-bay { margin-top: clamp(72px, 8vw, 128px); }
.gal-bay[hidden] { display: none; }
.gal-bay-head { display: flex; align-items: flex-end; gap: 0 24px; margin-bottom: clamp(24px, 2.6vw, 38px); }
.gal-bay-head h3 { font-size: clamp(30px, 2.8vw, 42px); line-height: 1.08; }
.gal-bay-head .eyebrow { margin-bottom: 10px; }
.gal-rule { flex: 1; min-width: 40px; height: 1px; margin-bottom: .62em; background: linear-gradient(90deg, var(--line), rgba(196, 154, 92, .06)); }
.gal-bay-head .lnk { flex: none; margin: 0 0 .45em; }

/* ---------- Œuvres et cartels ---------- */
.work { display: flex; flex-direction: column; min-width: 0; }
.work-frame { position: relative; display: block; overflow: hidden; aspect-ratio: var(--ar, 16 / 9); background: var(--night-3); cursor: zoom-in; }
.work-frame img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transition: transform 1.6s cubic-bezier(.2, .7, .2, 1), filter .5s ease; }
.work-frame:focus-visible { outline: 1px solid var(--gold-light); outline-offset: 4px; }
.cartel { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; padding: 14px 2px 0; font-style: normal; }
.cartel-t { font-family: var(--font-tale); font-size: 18px; line-height: 1.3; color: var(--tale); }
.cartel-v { font-family: var(--font-tale); font-style: italic; font-size: 15px; line-height: 1.3; color: var(--cream-2); }
.cartel-k { font-family: var(--font-display); font-size: 10.5px; line-height: 1.5; letter-spacing: .2em; text-transform: uppercase; color: var(--muted); }
a.cartel-k { color: var(--gold-light); border-bottom: 1px solid transparent; transition: color .2s, border-color .2s; }
a.cartel-k::after { content: " →"; font-family: var(--font-body); letter-spacing: 0; }
a.cartel-k:hover, a.cartel-k:focus-visible { color: #fff3dc; border-color: var(--line); }
/* Œuvre très étroite (portrait dans une rangée, écran moyen) : cartel resserré ; le lieu reste dans la visionneuse. */
.work { container-type: inline-size; }
@container (max-width: 150px) {
  .cartel-t { font-size: 14px; }
  .cartel-k { display: none; }
}

/* ---------- Salle I : mosaïque de captures ---------- */
.gal-mosaic { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: clamp(28px, 2.8vw, 40px) clamp(16px, 1.8vw, 26px); }
.gal-mosaic .work { grid-column: var(--c); grid-row: var(--r); }
.work--shot .work-frame { border: 1px solid rgba(196, 154, 92, .26); box-shadow: 0 28px 60px rgba(0, 0, 0, .5); transition: border-color .35s; }
.work--shot .work-frame::after { content: ""; position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .5), inset 0 0 90px rgba(0, 0, 0, .3); }
.work--shot .work-frame:hover { border-color: var(--gold); }
.work--shot .work-frame:hover img, .work--shot .work-frame:focus-visible img { transform: scale(1.035); }
/* La grande capture d’une rangée occupe deux rangs : son image remplit la hauteur des deux petites. */
.gal-mosaic .is-lead .work-frame { aspect-ratio: auto; flex: 1 1 0; min-height: 0; }

/* ---------- Salle II : rangées justifiées de tableaux ---------- */
/* Les rangées sont calculées par build_galerie.py : dans une rangée, chaque tableau prend une largeur proportionnelle
   à son format, si bien que la rangée a une seule hauteur et remplit le mur. Une dernière rangée « is-ragged »
   garde la hauteur visée sans s’étirer. */
.gal-hang { --gap-x: clamp(18px, 2vw, 30px); --row-h: min(270px, 21vw); display: flex; flex-direction: column; gap: clamp(32px, 3.2vw, 48px); }
.gal-hang-row { display: flex; align-items: flex-start; gap: var(--gap-x); }
.gal-hang-row .work { flex: var(--k) 1 0%; }
.gal-hang-row.is-ragged .work { flex: 0 1 calc(var(--k) * var(--row-h)); }
.work--paint .work-frame { aspect-ratio: var(--ar); background: none; }
.work--paint .work-frame img {
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 6%, #000 94%, transparent), linear-gradient(180deg, transparent, #000 7%, #000 93%, transparent);
  -webkit-mask-composite: source-in;
  mask-image: linear-gradient(90deg, transparent, #000 6%, #000 94%, transparent), linear-gradient(180deg, transparent, #000 7%, #000 93%, transparent);
  mask-composite: intersect;
}
.work--paint .work-frame:hover img, .work--paint .work-frame:focus-visible img { filter: brightness(1.1); }
.work--paint .cartel { padding-top: 8px; }

/* =================================================
   VISIONNEUSE
   ================================================= */
.viewer { position: fixed; inset: 0; z-index: 200; display: grid; grid-template-columns: 104px minmax(0, 1fr) 104px; align-items: center; background: rgba(8, 8, 9, .985); }
.viewer[hidden], .viewer [hidden] { display: none !important; }
/* Commandes rondes au trait d’or, comme la visionneuse du carnet et la poignée des seuils de l’accueil. */
.viewer-prev, .viewer-next, .viewer-close { display: grid; place-items: center; width: 52px; height: 52px; margin: 0 auto; border: 1px solid var(--line); border-radius: 50%; color: var(--cream-2); background: rgba(10, 10, 11, .5); transition: color .25s, border-color .25s, background .25s; }
.viewer-close { position: absolute; top: 18px; right: 18px; z-index: 2; width: 46px; height: 46px; }
.viewer-prev:hover, .viewer-next:hover, .viewer-close:hover { color: var(--gold-light); border-color: var(--gold-light); background: rgba(196, 154, 92, .1); }
.viewer button svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }
.viewer-stage { grid-column: 2; display: flex; flex-direction: column; align-items: center; gap: 20px; min-width: 0; padding: 28px 0 24px; }
.viewer-stage img { display: block; width: auto; height: auto; max-width: 100%; max-height: calc(100vh - 230px); max-height: calc(100dvh - 230px); object-fit: contain; box-shadow: 0 40px 100px rgba(0, 0, 0, .7); transition: opacity .35s ease; }
.viewer-stage img.is-loading { opacity: .25; }
.viewer-meta { display: flex; flex-direction: column; align-items: center; gap: 6px; max-width: min(900px, 100%); text-align: center; }
.viewer-label { font-family: var(--font-display); font-size: 11px; letter-spacing: .3em; text-transform: uppercase; color: var(--gold-light); }
.viewer-caption { font-family: var(--font-tale); font-size: clamp(22px, 2vw, 28px); line-height: 1.25; color: var(--tale); }
.viewer-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px 24px; margin-top: 8px; }
.viewer-variants { justify-content: center; }
.viewer-variants button { padding: 6px 12px; font-size: 11px; }
.viewer-link { display: inline-flex; align-items: center; gap: .7em; padding-bottom: 3px; border-bottom: 1px solid var(--line); font-family: var(--font-display); font-size: 11px; letter-spacing: .16em; text-transform: uppercase; color: var(--gold-light); transition: color .2s, border-color .2s; }
.viewer-link::after { content: "→"; font-family: var(--font-body); letter-spacing: 0; }
.viewer-link:hover { color: #fff3dc; border-color: var(--gold-light); }
.viewer-count { font-family: var(--font-display); font-size: 11px; letter-spacing: .2em; color: var(--muted); }
html.viewer-open { overflow: hidden; }

/* =================================================
   Écrans petits
   ================================================= */
@media (max-width: 760px) {
  .gal-chips > p { width: 100%; margin: 0 0 4px; text-align: center; }
  .gal-chips button { padding: 6px 11px; }
  .gal-bay-head { flex-wrap: wrap; align-items: baseline; }
  .gal-bay-head .gal-rule { display: none; }
  .gal-bay-head .lnk { margin-top: 12px; }
  .cartel-t { font-size: 16px; }
  /* Mosaïque sur deux colonnes : la grande capture et la dernière d’une rangée de trois prennent la largeur. */
  .gal-mosaic { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 26px 14px; }
  .gal-mosaic .work { grid-column: auto; grid-row: auto; }
  .gal-mosaic .work.m-full { grid-column: 1 / -1; }
  .gal-mosaic .is-lead .work-frame { aspect-ratio: var(--ar, 16 / 9); flex: none; }
  .gal-mosaic .work:not(.m-full) .cartel-t { font-size: 15px; }
  .gal-mosaic .work:not(.m-full) .cartel-k { display: none; }
  /* Rangées libres sur mobile : les tableaux s’enchaînent et chaque ligne se justifie ; la dernière ne s’étire pas. */
  .gal-hang { --row-h: 120px; --gap-x: 14px; flex-direction: row; flex-wrap: wrap; align-items: flex-start; gap: 26px var(--gap-x); }
  .gal-hang::after { content: ""; flex: 100000 1 0px; margin-left: calc(-1 * var(--gap-x)); }
  .gal-hang-row { display: contents; }
  .gal-hang .work, .gal-hang-row.is-ragged .work { flex: var(--k) 1 calc(var(--k) * var(--row-h)); max-width: calc(var(--k) * var(--row-h) * 1.8); }
  .viewer { grid-template-columns: 0 minmax(0, 1fr) 0; }
  .viewer-stage { padding: 70px 14px 96px; }
  .viewer-stage img { max-height: calc(100vh - 300px); max-height: calc(100dvh - 300px); }
  .viewer-prev, .viewer-next { position: absolute; bottom: 20px; }
  .viewer-prev { left: 18px; }
  .viewer-next { right: 18px; }
  .viewer-caption { font-size: 21px; }
}
@media (prefers-reduced-motion: reduce) {
  .work-frame img, .viewer-stage img { transition: none; }
  .work--shot .work-frame:hover img { transform: none; }
}
