* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --noir: #050505;
  --texte: #e9e5dc;
  --doux: rgba(233, 229, 220, 0.5);
  --ligne: rgba(233, 229, 220, 0.16);
  --accent: #d8cfbd;            /* changé par page dans script.js */
  --pad: clamp(14px, 2.6vw, 34px);
  --ease: cubic-bezier(.7, 0, .2, 1);

  /* Position du cadre vidéo, calculée par script.js */
  --fx: 50vw; --fy: 50vh; --fw: 0px; --fh: 0px;
}

html, body {
  height: 100%;
  background: var(--noir);
  color: var(--texte);
  font-family: "Courier New", ui-monospace, monospace;
  overflow: hidden;
  cursor: default;
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--accent); color: #000; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 1px dashed var(--accent); outline-offset: 4px; }

/* ================= Voile d'entrée ================= */
#veil {
  position: fixed; inset: 0; z-index: 50;
  background: #000;
  display: grid; place-items: center;
  transition: opacity 1.4s ease, transform 1.4s ease, filter 1.4s ease;
}
#veil.gone { opacity: 0; transform: scale(1.5); filter: blur(14px); pointer-events: none; }
.veil-inner { display: flex; flex-direction: column; align-items: center; gap: 20px; }
.veil-tag { font-size: .68rem; letter-spacing: 5px; color: var(--doux); text-transform: uppercase; }
#enter {
  background: none; border: 1px solid var(--ligne);
  color: #fff; font-size: 1.6rem; letter-spacing: 6px;
  padding: 14px 36px; cursor: pointer;
  text-shadow: 0 0 8px rgba(255,255,255,.6);
  animation: breathe 3s ease-in-out infinite;
  transition: border-color .3s, box-shadow .3s, letter-spacing .4s;
}
#enter:hover { border-color: #fff; box-shadow: 0 0 26px rgba(255,255,255,.18); letter-spacing: 12px; }
.hint { font-size: .72rem; color: var(--doux); letter-spacing: 4px; transition: opacity .5s; }
.veil-track {
  display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 10px; margin-top: 18px;
  max-width: calc(100vw - 32px); text-align: center;
  font-size: .66rem; letter-spacing: 3px; color: var(--doux);
  opacity: 0; transform: translateY(6px); transition: opacity 1.2s ease, transform 1.2s ease;
}
.veil-track .eq { height: 10px; }
.veil-track .eq i { width: 2px; }
#veil.awake .veil-track { opacity: 1; transform: none; }
#veil:not(.awake) #enter { opacity: .35; animation: none; }
.scan {
  position: absolute; left: 0; right: 0; height: 30%;
  background: linear-gradient(transparent, rgba(255,255,255,.035), transparent);
  animation: scan 7s linear infinite; pointer-events: none;
}
@keyframes scan { from { top: -30%; } to { top: 100%; } }
@keyframes breathe { 50% { opacity: .45; } }

/* ================= Ambiance (vidéo floutée plein écran) ================= */
.ambient { position: fixed; inset: 0; z-index: 0; overflow: hidden; }
#bgBlur {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; filter: blur(34px) brightness(.3) saturate(.8);
  transform: scale(1.2); transition: opacity 1s ease;
}
body.switching #bgBlur { opacity: 0; }
.vignette {
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at center, rgba(0,0,0,.15) 30%, rgba(0,0,0,.9) 100%);
}
.grain {
  position: absolute; inset: -50%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.5'/%3E%3C/svg%3E");
  opacity: .09; animation: grain .6s steps(4) infinite;
  pointer-events: none;
}
@keyframes grain {
  25% { transform: translate(-3%, 2%); }
  50% { transform: translate(2%, -3%); }
  75% { transform: translate(-1%, 3%); }
}

/* ================= Cadre vidéo ================= */
#frame {
  position: fixed; z-index: 5;
  left: var(--fx); top: var(--fy); width: var(--fw); height: var(--fh);
}
body.ready #frame { transition: left .9s var(--ease), top .9s var(--ease), width .9s var(--ease), height .9s var(--ease); }

.screen {
  position: absolute; inset: 0; overflow: hidden; background: #000;
  box-shadow: 0 0 0 1px var(--ligne), 0 30px 80px rgba(0,0,0,.7), 0 0 60px rgba(0,0,0,.5);
}
#bgMain {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; filter: brightness(.9) contrast(1.06);
  transform-origin: center;
  transition: transform .35s var(--ease), filter .35s ease, opacity .35s ease;
}
/* Changement de page : la vidéo s'éteint comme une vieille télé, puis se rallume */
body.switching #bgMain { transform: scale(1.04, .004); filter: brightness(4); opacity: 0; }

.scanlines {
  position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(to bottom, rgba(0,0,0,.18) 0 1px, transparent 1px 3px);
  mix-blend-mode: multiply; opacity: .5;
}

/* Page sans vidéo : neige + "signal perdu", à l'intérieur du cadre */
.nosignal {
  position: absolute; inset: 0; display: none; place-items: center;
  background: radial-gradient(circle, #1a1a1a, #000 75%);
}
.nosignal::before {
  content: ""; position: absolute; inset: -50%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.4' numOctaves='1'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  opacity: .22; animation: grain .3s steps(3) infinite;
}
.nosignal span {
  position: relative; font-size: clamp(.7rem, 1.4vw, .95rem); letter-spacing: 6px;
  color: var(--doux); animation: breathe 2.4s ease-in-out infinite;
}
#frame.missing .nosignal { display: grid; }
#frame.missing #bgMain { visibility: hidden; }

/* Coins de viseur, juste à l'extérieur de l'image */
.corner { position: absolute; width: 12px; height: 12px; border: 0 solid var(--accent); opacity: .7; transition: border-color 1s; }
.corner.tl { left: -8px;  top: -8px;    border-left-width: 1px;  border-top-width: 1px; }
.corner.tr { right: -8px; top: -8px;    border-right-width: 1px; border-top-width: 1px; }
.corner.bl { left: -8px;  bottom: -8px; border-left-width: 1px;  border-bottom-width: 1px; }
.corner.br { right: -8px; bottom: -8px; border-right-width: 1px; border-bottom-width: 1px; }

/* Avancement de la boucle vidéo, sous l'image */
.progress { position: absolute; left: 0; right: 0; bottom: -5px; height: 1px; background: var(--ligne); }
.progress span { display: block; height: 100%; width: 0; background: var(--accent); box-shadow: 0 0 6px var(--accent); }

/* ================= Navigation ================= */
#nav { position: fixed; z-index: 10; display: flex; gap: 6px; }
#nav a {
  color: var(--doux); text-decoration: none;
  font-size: .82rem; letter-spacing: 3px; text-transform: lowercase;
  padding: 8px 14px; border: 1px solid transparent;
  background: rgba(0,0,0,.35); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  display: flex; align-items: baseline; gap: 10px; white-space: nowrap;
  transition: color .3s, border-color .3s, text-shadow .3s, padding .3s;
}
#nav a b { font-weight: normal; font-size: .62rem; letter-spacing: 1px; opacity: .55; }
#nav a:hover { color: #fff; border-color: var(--ligne); }
#nav a.active { color: #fff; border-color: color-mix(in srgb, var(--accent) 55%, transparent); text-shadow: 0 0 8px var(--accent); }
#nav a.active b { opacity: 1; color: var(--accent); }

/* ================= Titre ================= */
#label { position: fixed; z-index: 10; }
.meta {
  display: flex; align-items: center; gap: 14px;
  font-size: .66rem; letter-spacing: 3px; color: var(--doux); margin-block-end: 8px;
  white-space: nowrap;
}
.rec { width: 6px; height: 6px; border-radius: 50%; background: #c0392b; box-shadow: 0 0 6px #c0392b; animation: breathe 1.6s steps(2) infinite; }
body.paused-all .rec { animation: none; opacity: .3; }
#title {
  font-weight: normal; font-size: clamp(1.3rem, 3.6vw, 2.6rem);
  letter-spacing: .3em; text-transform: lowercase; line-height: 1.1;
  white-space: nowrap;
  text-shadow: 0 0 12px rgba(255,255,255,.45);
  animation: flicker 5s infinite;
}
/* Animation d'apparition sans changer la taille (le calcul du cadre reste juste) */
#title.swap { animation: titleIn 1.1s ease both, flicker 5s 1.1s infinite; }
@keyframes titleIn {
  from { opacity: 0; filter: blur(8px); clip-path: inset(0 100% 0 0); }
  60%  { opacity: 1; filter: blur(0); }
  to   { clip-path: inset(0 0 0 0); }
}
@keyframes flicker { 0%, 92%, 100% { opacity: 1; } 93% { opacity: .3; } 95% { opacity: .9; } 96% { opacity: .2; } }

/* ================= Contrôles musique ================= */
.controls {
  position: fixed; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  background: rgba(0,0,0,.42); padding: 9px 14px; border: 1px solid var(--ligne);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
#toggle { background: none; border: none; cursor: pointer; width: 22px; height: 18px; display: grid; place-items: center; flex: none; }
.eq { display: flex; align-items: flex-end; gap: 2px; height: 14px; }
.eq i { width: 3px; height: 100%; background: var(--accent); box-shadow: 0 0 5px var(--accent); transform-origin: bottom; animation: eq 1s ease-in-out infinite; }
.eq i:nth-child(2) { animation-duration: .7s; animation-delay: -.3s; }
.eq i:nth-child(3) { animation-duration: 1.2s; animation-delay: -.5s; }
.eq i:nth-child(4) { animation-duration: .85s; animation-delay: -.1s; }
@keyframes eq { 0%, 100% { transform: scaleY(.25); } 50% { transform: scaleY(1); } }
#toggle.paused .eq i, .controls.nosound .eq i { animation: none; transform: scaleY(.15); opacity: .5; }

.track { width: 15ch; overflow: hidden; font-size: .7rem; letter-spacing: 2px; color: var(--doux); white-space: nowrap; }
.track.long {
  mask-image: linear-gradient(90deg, transparent, #000 1ch, #000 calc(100% - 2ch), transparent);
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 1ch, #000 calc(100% - 2ch), transparent);
}
#track { display: inline-block; }
.track.long #track { animation: marquee 11s linear infinite; padding: 0 3ch 0 1ch; }
@keyframes marquee { 0%, 15% { transform: translateX(0); } 85%, 100% { transform: translateX(calc(-100% + 15ch)); } }

#volume {
  -webkit-appearance: none; appearance: none; width: 90px; height: 14px; background: transparent; cursor: pointer; flex: none;
  --v: 60%;
}
#volume::-webkit-slider-runnable-track { height: 2px; background: linear-gradient(90deg, var(--accent) var(--v), var(--ligne) var(--v)); }
#volume::-moz-range-track { height: 2px; background: var(--ligne); }
#volume::-moz-range-progress { height: 2px; background: var(--accent); }
#volume::-webkit-slider-thumb { -webkit-appearance: none; width: 10px; height: 10px; margin-top: -4px; border-radius: 50%; background: #fff; box-shadow: 0 0 6px rgba(255,255,255,.6); }
#volume::-moz-range-thumb { width: 10px; height: 10px; border: none; border-radius: 50%; background: #fff; }

/* =================================================================
   Deux dispositions. script.js choisit, pour chaque page, celle qui
   laisse la vidéo la plus grande — l'interface reste toujours autour.
   ================================================================= */

/* --- Lignes : navigation en haut, titre et son en bas --- */
.mode-rows #nav   { top: var(--pad); left: 50%; transform: translateX(-50%); flex-wrap: wrap; justify-content: center; max-width: calc(100vw - 2 * var(--pad)); }
.mode-rows #label { left: var(--pad); bottom: var(--pad); max-width: calc(100vw - 2 * var(--pad)); }
.mode-rows .controls { right: var(--pad); bottom: var(--pad); }

/* --- Colonnes : titre vertical à gauche, navigation et son à droite --- */
.mode-cols #label {
  left: var(--pad); top: 50%;
  writing-mode: vertical-rl; transform: translateY(-50%) rotate(180deg);
  max-height: calc(100vh - 2 * var(--pad));
}
.mode-cols .meta { margin-block-end: 12px; }
.mode-cols #title { font-size: clamp(1.3rem, 3.4vh, 2.6rem); }
.mode-cols #nav { top: var(--pad); right: var(--pad); flex-direction: column; align-items: stretch; }
.mode-cols #nav a { justify-content: space-between; }
.mode-cols .controls { right: var(--pad); bottom: var(--pad); flex-wrap: wrap; width: 196px; row-gap: 10px; }
.mode-cols .track { flex: 1; width: auto; }
.mode-cols #volume { width: 100%; }
.mode-cols .track.long #track { animation-name: marquee-col; }
@keyframes marquee-col { 0%, 15% { transform: translateX(0); } 85%, 100% { transform: translateX(-45%); } }

/* --- Petits écrans : titre au-dessus de la barre de son --- */
@media (max-width: 640px) {
  #nav a { padding: 6px 9px; font-size: .7rem; letter-spacing: 1px; gap: 6px; }
  #nav a b { display: none; }
  .mode-rows #nav { gap: 2px; }
  .mode-rows .controls { left: var(--pad); right: var(--pad); }
  .mode-rows .track { flex: 1; width: auto; }
  .mode-rows #label { bottom: calc(var(--pad) + 52px); }
  #title { letter-spacing: .2em; }
}

@media (prefers-reduced-motion: reduce) {
  .grain, .nosignal::before, #title, .scan, .eq i, .track.long #track { animation: none !important; }
  body.ready #frame { transition: none; }
}
