/* ==========================================================================
   Galerie : « la nuit »
   --------------------------------------------------------------------------
   La pièce est dans le noir. Le visiteur tient la seule source de lumière,
   une flamme, comme dans les toiles du Caravage. Les vingt-sept toiles sont
   accrochées en frise, dans l'ordre chronologique, à une taille proportionnelle
   à leur format réel. La salle prend la lumière de la toile qui est devant vous.
   ========================================================================== */

@font-face { font-family: "IM Fell English"; font-style: normal; font-weight: 400; font-display: swap; src: url("../assets/fonts/im-fell-english-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "IM Fell English"; font-style: italic; font-weight: 400; font-display: swap; src: url("../assets/fonts/im-fell-english-latin-400-italic.woff2") format("woff2"); }
@font-face { font-family: "Hanken Grotesk"; font-style: normal; font-weight: 400; font-display: swap; src: url("../assets/fonts/hanken-grotesk-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Hanken Grotesk"; font-style: normal; font-weight: 500; font-display: swap; src: url("../assets/fonts/hanken-grotesk-latin-500-normal.woff2") format("woff2"); }

:root {
  --soot: #060504;
  --soot-rgb: 6, 5, 4;
  --ink: #EFE5D1;
  --ink-2: #A99F8B;
  --ink-3: #7A7262;
  --gilt: #D8B477;
  --rule: rgba(239, 229, 209, 0.12);
  --fell: "IM Fell English", "Iowan Old Style", Garamond, Georgia, serif;
  --sans: "Hanken Grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

  /* pilotés par night.js */
  --x: 50vw;
  --y: 55vh;
  --r: 260px;
  --dark: 0.965;
}

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

body.night {
  margin: 0;
  background: var(--soot);
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}

body.night .site-nav {
  background: rgba(var(--soot-rgb), 0.9);
  border-bottom-color: rgba(239, 229, 209, 0.07);
}

body.night :focus-visible { outline: 2px solid var(--gilt); outline-offset: 4px; }

/* ---------- La frise ---------- */
.frieze { position: relative; }

.frieze-stage {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100svh;
  overflow: hidden;
}

.frieze-row {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  display: flex;
  align-items: center;
  padding: 56px 0 0;
  will-change: transform;
}

.night-intro {
  flex: 0 0 auto;
  width: min(520px, 80vw);
  margin: 0 12vw 0 max(24px, 7vw);
  align-self: center;
}

.night-title {
  margin: 0 0 18px;
  font-family: var(--fell);
  font-style: italic;
  font-weight: 400;
  font-size: clamp(64px, 10vw, 150px);
  line-height: 0.9;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.night-lede {
  margin: 0;
  max-width: 34ch;
  font-size: 18px;
  line-height: 1.5;
  color: var(--ink-2);
}

.hint-coarse { display: none; }
@media (hover: none), (pointer: coarse) {
  .hint-fine { display: none; }
  .hint-coarse { display: inline; }
}

.frieze-track {
  display: flex;
  align-items: center;
  gap: clamp(90px, 11vw, 200px);
  margin: 0;
  padding: 0 40vw 0 0;
  list-style: none;
}

.canvas-item { flex: 0 0 auto; }

.canvas-item button {
  display: block;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: zoom-in;
}

.canvas-item img {
  display: block;
  height: var(--h, 300px);
  width: auto;
  max-width: none;
  box-shadow: 0 30px 60px -20px rgba(0, 0, 0, 0.9);
  background: #15110D;
}

.canvas-item figure { margin: 0; }

.canvas-item figcaption {
  margin-top: 18px;
  max-width: max(220px, 100%);
}

.canvas-title {
  display: block;
  font-family: var(--fell);
  font-style: italic;
  font-size: 22px;
  line-height: 1.15;
  color: var(--ink);
}

.canvas-meta {
  display: block;
  margin-top: 4px;
  font-size: 13px;
  color: var(--ink-3);
}

/* L'année de la toile qui est devant vous */
.frieze-years {
  position: absolute;
  left: max(24px, 3vw);
  bottom: 22px;
  font-family: var(--fell);
  font-size: clamp(40px, 6vw, 84px);
  line-height: 1;
  color: rgba(239, 229, 209, 0.16);
  pointer-events: none;
  z-index: 60;
  font-variant-numeric: lining-nums;
}

/* ---------- L'obscurité et la flamme ---------- */
.darkness {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  background: radial-gradient(
    circle at var(--x) var(--y),
    rgba(var(--soot-rgb), 0) 0,
    rgba(var(--soot-rgb), calc(var(--dark) * 0.35)) calc(var(--r) * 0.42),
    rgba(var(--soot-rgb), calc(var(--dark) * 0.8)) calc(var(--r) * 0.78),
    rgba(var(--soot-rgb), var(--dark)) var(--r)
  );
  transition: opacity 0.9s ease;
}

/* Lueur chaude de la flamme */
.darkness::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at var(--x) var(--y), rgba(255, 168, 82, 0.12) 0, rgba(255, 140, 60, 0.05) calc(var(--r) * 0.5), transparent var(--r));
  mix-blend-mode: screen;
}

body.lights-on .darkness { opacity: 0; }

.lights-btn {
  position: fixed;
  right: max(16px, 2.4vw);
  bottom: 20px;
  z-index: 70;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: rgba(var(--soot-rgb), 0.7);
  color: var(--ink-2);
  font: 500 13px/1 var(--sans);
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease;
}
.lights-btn:hover { color: var(--ink); border-color: rgba(216, 180, 119, 0.5); }
.lights-btn kbd { font: 12px/1 var(--sans); padding: 2px 6px; border: 1px solid var(--rule); border-radius: 4px; color: var(--ink-3); }
.lights-btn .lights-off-label { display: none; }
body.lights-on .lights-btn .lights-on-label { display: none; }
body.lights-on .lights-btn .lights-off-label { display: inline; }
@media (hover: none), (pointer: coarse) { .lights-btn kbd { display: none; } }

/* ==========================================================================
   Détail d'une toile
   ========================================================================== */
.study {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  background: #040302;
  color: var(--ink-2);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.study[hidden] { display: none; }

.study.is-opening { animation: study-in 0.45s ease both; }
@keyframes study-in { from { opacity: 0; } }

.study-media {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100svh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 64px clamp(20px, 4vw, 64px);
}

.study-canvas-wrap {
  position: relative;
  line-height: 0;
  box-shadow: 0 40px 90px -30px rgba(0, 0, 0, 1);
}

.study-canvas-wrap img,
.study-canvas-wrap canvas {
  display: block;
  max-width: 100%;
  max-height: calc(100svh - 128px);
  width: auto;
  height: auto;
}

.study-canvas-wrap canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-height: none;
  opacity: 0;
  transition: opacity 0.6s ease;
  pointer-events: none;
}
.study-canvas-wrap.is-masked canvas { opacity: 1; }

/* Entrée : un rai de lumière rasante balaie la toile en diagonale */
.study-canvas-wrap.is-raking {
  -webkit-mask-image: linear-gradient(112deg, #000 0%, #000 42%, rgba(0,0,0,0.15) 52%, transparent 60%);
          mask-image: linear-gradient(112deg, #000 0%, #000 42%, rgba(0,0,0,0.15) 52%, transparent 60%);
  -webkit-mask-size: 300% 100%;
          mask-size: 300% 100%;
  animation: rake 1.6s cubic-bezier(0.55, 0.05, 0.25, 1) both;
}
@keyframes rake {
  from { -webkit-mask-position: 100% 0; mask-position: 100% 0; }
  to   { -webkit-mask-position: 0% 0;   mask-position: 0% 0; }
}

.study-text {
  padding: 96px clamp(24px, 3vw, 44px) 80px 8px;
}

.study-artist { margin: 0 0 6px; font-size: 14px; color: var(--ink-3); }

.study-title {
  margin: 0 0 6px;
  font-family: var(--fell);
  font-style: italic;
  font-weight: 400;
  font-size: clamp(34px, 3vw, 46px);
  line-height: 1.04;
  color: var(--ink);
}

.study-orig { margin: 0 0 28px; font-family: var(--fell); font-size: 17px; color: var(--ink-3); }

.study-facts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 20px;
  margin: 0 0 40px;
  padding-top: 16px;
  border-top: 1px solid var(--rule);
}
.study-facts dt { font-size: 12.5px; color: var(--ink-3); }
.study-facts dd { margin: 2px 0 0; font-size: 15px; color: var(--ink); line-height: 1.4; }

.pigments-title {
  margin: 0 0 6px;
  font-family: var(--fell);
  font-weight: 400;
  font-size: 26px;
  color: var(--ink);
}
.pigments-help { margin: 0 0 18px; font-size: 14px; color: var(--ink-3); max-width: 36ch; }

.pigment-list { list-style: none; margin: 0 0 40px; padding: 0; display: grid; gap: 4px; }

.pigment {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 8px 10px 8px 6px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}
.pigment:hover { background: rgba(239, 229, 209, 0.04); }
.pigment[aria-pressed="true"] { border-color: rgba(216, 180, 119, 0.55); background: rgba(216, 180, 119, 0.06); }

/* Un petit tas de pigment, pas une pastille parfaite */
.pigment-blob {
  width: 36px;
  height: 32px;
  border-radius: 48% 52% 44% 56% / 58% 50% 50% 42%;
  background: var(--c);
  box-shadow: inset 0 -6px 10px rgba(0, 0, 0, 0.35), inset 0 3px 4px rgba(255, 255, 255, 0.12), 0 4px 10px rgba(0, 0, 0, 0.6);
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}
.pigment[aria-pressed="true"] .pigment-blob { transform: scale(1.12) rotate(-6deg); }

.pigment-name { display: block; color: var(--ink); font-size: 15px; }
.pigment-hex { display: block; font-size: 12px; color: var(--ink-3); }
.pigment-share {
  font-family: var(--fell);
  font-size: 22px;
  color: var(--ink);
  font-variant-numeric: lining-nums;
}

.study-desc { margin: 0; font-size: 15.5px; line-height: 1.7; color: var(--ink-2); max-width: 46ch; }

.study-close,
.study-nav {
  position: fixed;
  z-index: 3010;
  width: 44px;
  height: 44px;
  border: 1px solid var(--rule);
  border-radius: 50%;
  background: rgba(4, 3, 2, 0.7);
  color: var(--ink);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  transition: border-color 0.2s ease;
}
.study-close { top: 18px; right: 18px; font-size: 26px; }
.study-prev { bottom: 20px; left: 20px; }
.study-next { bottom: 20px; left: 72px; }
.study-close:hover, .study-nav:hover { border-color: rgba(216, 180, 119, 0.6); }

.study-count {
  position: fixed;
  z-index: 3010;
  bottom: 31px;
  left: 132px;
  margin: 0;
  font-size: 13px;
  color: var(--ink-3);
}

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
  .study { grid-template-columns: 1fr; }
  /* la toile reste en haut de l'écran pendant qu'on parcourt les pigments */
  .study-media { position: sticky; top: 0; z-index: 2; height: 48svh; padding: 56px 16px 12px; background: #040302; box-shadow: 0 12px 24px #040302; }
  .study-canvas-wrap img { max-height: calc(48svh - 68px); }
  .study-text { padding: 12px 20px 110px; }
  .canvas-title { font-size: 19px; }
  .night-lede { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .study-canvas-wrap.is-raking { animation: none; -webkit-mask-image: none; mask-image: none; }
  .study.is-opening { animation: none; }
  .darkness { transition: none; }
}

.pigment-wait { padding: 12px 6px; font-size: 14px; color: var(--ink-3); }
