/* ───────────────────────── DÉRIVE · base ───────────────────────── */
@font-face {
  font-family: 'derive';
  src: url('../assets/fonts/derive.woff') format('woff');
  font-weight: 700; font-style: normal; font-display: block;
}

:root {
  --paper: #ffffff;
  --ink: #0b0b0b;
  --red: #ff2a00;
  --blue: #0000ff;
  --mute: #8a8a8a;
  --line: rgba(11, 11, 11, .14);
  --fg: var(--ink);
  --bg: var(--paper);
  --accent: var(--red);
  --display: 'derive', 'Helvetica Neue', Arial, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --serif: 'Instrument Serif', 'Times New Roman', serif;
  --gutter: clamp(16px, 2.2vw, 36px);
  --ease: cubic-bezier(.7, 0, .2, 1);
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; scrollbar-width: thin; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.45;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  cursor: none;
}
@media (hover: none) { body { cursor: auto; } .cursor { display: none !important; } }
img { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; cursor: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: none; }
@media (hover: none) { a, button { cursor: pointer; } }
::selection { background: var(--accent); color: var(--paper); }
.defs { position: absolute; width: 0; height: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* ── canvases globaux ── */
#trip-gl, #preview-gl {
  position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none;
}
/* sous le contenu (z négatif) : le texte de #app peut se fondre en « difference » avec le WebGL */
#trip-gl { z-index: -2; opacity: 0; transition: opacity 1.2s; }
#preview-gl { z-index: -1; opacity: 0; transition: opacity .5s; }
body.psyche #trip-gl { opacity: 1; }
body.preview-on #preview-gl { opacity: 1; }

.grain {
  position: fixed; inset: -50%; z-index: 90; pointer-events: none; opacity: .06;
  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='.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grain 1s steps(6) infinite;
}
@keyframes grain {
  0% { transform: translate(0, 0); } 20% { transform: translate(-3%, 2%); }
  40% { transform: translate(2%, -4%); } 60% { transform: translate(-4%, -1%); }
  80% { transform: translate(3%, 3%); } 100% { transform: translate(0, 0); }
}

#app { position: relative; min-height: 100vh; outline: none; }

/* ── HUD ── */
.hud {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  padding: var(--gutter);
  pointer-events: none;
  mix-blend-mode: difference; color: #fff;
}
.hud > * { pointer-events: auto; }
.hud-logo { font-family: var(--display); font-size: 26px; line-height: .8; letter-spacing: -.02em; }
.hud-logo i { font-style: normal; display: inline-block; transform: translateY(-.18em); }
.hud-logo sup { font-size: .5em; }
.hud-nav { display: flex; gap: clamp(10px, 2vw, 28px); letter-spacing: .18em; font-size: 11px; }
.hud-nav a { position: relative; padding: 4px 0; }
.hud-nav a::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 1px; background: currentColor;
  transform: scaleX(0); transform-origin: right; transition: transform .5s var(--ease);
}
.hud-nav a:hover::after, .hud-nav a.on::after { transform: scaleX(1); transform-origin: left; }
.hud-nav a.on::before { content: '●'; position: absolute; left: -12px; font-size: 7px; top: 7px; }
.hud-tools { display: flex; gap: 10px; }
.hud-mode, .hud-sound {
  border: 1px solid currentColor; padding: 7px 12px; font-size: 11px; letter-spacing: .14em;
  border-radius: 99px; transition: background .3s, color .3s;
}
.hud-mode:hover, .hud-sound:hover { background: #fff; color: #000; }
.hud-mode .m-p { display: none; }
body.psyche .hud-mode .m-n { display: none; }
body.psyche .hud-mode .m-p { display: inline; }

.hud-foot {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; pointer-events: none;
  display: flex; justify-content: space-between; padding: 12px var(--gutter);
  font-size: 10px; letter-spacing: .16em; mix-blend-mode: difference; color: #fff;
}
body.is-gate .hud, body.is-gate .hud-foot { opacity: 0; pointer-events: none; }
.hud, .hud-foot { transition: opacity .8s; }

@media (max-width: 760px) {
  .hud { flex-wrap: wrap; }
  .hud-nav { order: 3; width: 100%; justify-content: space-between; font-size: 10px; letter-spacing: .1em; }
  .hud-nav a.on::before { display: none; }
  .hud-foot .hf-route { display: none; }
}

/* ── curseur ── */
.cursor { position: fixed; left: 0; top: 0; z-index: 200; pointer-events: none; mix-blend-mode: difference; }
.c-h, .c-v { display: none; position: fixed; left: 0; top: 0; background: var(--red); pointer-events: none; }
.c-h { width: 100vw; height: 1px; } .c-v { width: 1px; height: 100vh; }
.c-dot { position: absolute; width: 6px; height: 6px; margin: -3px 0 0 -3px; background: #fff; border-radius: 50%; }
.c-ring {
  position: absolute; width: 38px; height: 38px; margin: -19px 0 0 -19px;
  border: 1px solid #fff; border-radius: 50%;
  display: grid; place-items: center;
  transition: width .4s var(--ease-out), height .4s var(--ease-out), margin .4s var(--ease-out), background .3s, border-radius .4s;
}
.c-label { font-size: 9px; letter-spacing: .14em; color: #000; opacity: 0; transition: opacity .2s; white-space: nowrap; }
.cursor.hover .c-ring { width: 70px; height: 70px; margin: -35px 0 0 -35px; }
.cursor.label .c-ring { width: 92px; height: 92px; margin: -46px 0 0 -46px; background: #fff; }
.cursor.label .c-label { opacity: 1; }
.cursor.drag .c-ring { border-radius: 0; width: 56px; height: 56px; margin: -28px 0 0 -28px; }

/* ── ENTRÉE ── */
#gate {
  position: fixed; inset: 0; z-index: 100; overflow: hidden; background: #fff;
  transition: clip-path 1.1s var(--ease);
  clip-path: inset(0 0 0 0);
}
#gate.out { clip-path: inset(0 0 100% 0); }
body:not(.is-gate) #gate { pointer-events: none; }
#gate-gl { position: absolute; inset: 0; width: 100%; height: 100%; }
.gate-ui {
  position: relative; z-index: 2; height: 100%;
  display: grid; grid-template-rows: auto 1fr auto auto auto; align-items: center; justify-items: center;
  padding: var(--gutter); mix-blend-mode: difference; color: #fff;
}
.gate-top, .gate-bottom {
  width: 100%; display: flex; justify-content: space-between; gap: 12px;
  font-size: 10px; letter-spacing: .2em; text-transform: uppercase;
}
.gate-title {
  font-family: var(--display); font-weight: 700;
  font-size: clamp(64px, min(22vw, 30vh), 380px); line-height: .78; letter-spacing: -.04em;
  display: flex; align-items: baseline; user-select: none;
}
.gate-title span { display: inline-block; transition: transform .8s var(--ease-out); will-change: transform; }
.gate-title .tilde { transform: translateY(-.25em); font-size: .7em; }
.gate-title .up { transform: translateY(-.32em); }
.gate-title .down { transform: translateY(.22em); }
.gate-title .exp { font-size: .55em; transform: translateY(-.6em); }
.gate-q {
  font-family: var(--serif); font-style: italic; font-size: clamp(22px, 3vw, 44px);
  letter-spacing: -.01em; margin: 1vh 0 3vh;
}
.gate-choices { display: grid; grid-template-columns: 1fr 1fr; gap: clamp(10px, 3vw, 60px); width: min(980px, 100%); margin-bottom: 4vh; }
.gate-btn {
  position: relative; text-align: left; padding: 18px 20px 20px;
  border: 1px solid #fff; display: grid; grid-template-columns: auto 1fr; gap: 6px 16px;
  transition: background .35s, color .35s, transform .6s var(--ease-out);
}
.gate-btn:hover { background: #fff; color: #000; transform: translateY(-6px); }
.gb-k { font-size: 11px; letter-spacing: .1em; grid-row: span 2; }
.gb-t { font-family: var(--display); font-size: clamp(30px, 4.6vw, 70px); line-height: .82; letter-spacing: -.02em; }
.gb-s { font-size: 10px; letter-spacing: .12em; text-transform: uppercase; opacity: .8; }
.gate-flash { position: absolute; inset: 0; z-index: 5; pointer-events: none; opacity: 0; display: grid; place-items: center; }
@media (max-width: 640px), (max-height: 560px) {
  .gate-btn { padding: 10px 12px 12px; }
  .gb-t { font-size: clamp(24px, 6vw, 44px); }
  .gate-q { margin: 0 0 1.5vh; }
}
@media (max-height: 520px) { .gb-s { display: none; } }
@media (max-width: 640px) {
  .gate-choices { grid-template-columns: 1fr; gap: 8px; }
  .gate-top span:nth-child(3), .gate-bottom span:nth-child(1), .gate-bottom span:nth-child(3) { display: none; }
}

/* ── visionneuse ── */
#lb {
  position: fixed; inset: 0; z-index: 150; background: #050505; color: #fff;
  display: grid; opacity: 0; transition: opacity .45s;
}
#lb.open { opacity: 1; }
#lb[hidden] { display: none; }
.lb-stage {
  position: absolute; inset: 56px 64px 104px; display: grid; place-items: center; overflow: hidden;
}
.lb-img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; user-select: none;
  transition: transform .6s var(--ease-out), opacity .35s, filter .5s;
  transform-origin: center;
}
.lb-img.loading { opacity: .25; filter: blur(14px); }
.lb-img.zoomed { object-fit: none; transition: none; }
.lb-top {
  position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: center;
  padding: 18px var(--gutter); font-size: 11px; letter-spacing: .16em;
}
.lb-title { font-family: var(--display); font-size: 20px; letter-spacing: 0; }
.lb-close { letter-spacing: .16em; font-size: 11px; padding: 6px 10px; border: 1px solid #fff; border-radius: 99px; }
.lb-close:hover { background: #fff; color: #000; }
.lb-prev, .lb-next {
  position: absolute; top: 56px; bottom: 104px; width: 30%; font-size: 28px; z-index: 2;
  display: flex; align-items: center; padding: 0 var(--gutter); opacity: .35; transition: opacity .3s;
}
.lb-prev:hover, .lb-next:hover { opacity: 1; }
.lb-prev { left: 0; } .lb-next { right: 0; justify-content: flex-end; }
.lb-strip {
  position: absolute; left: 0; right: 0; bottom: 0; height: 92px; display: flex; gap: 6px;
  padding: 12px var(--gutter); overflow-x: auto; scrollbar-width: none;
}
.lb-strip button { flex: 0 0 auto; height: 100%; opacity: .35; transition: opacity .3s, transform .3s; }
.lb-strip button img { height: 100%; width: auto; }
.lb-strip button.on { opacity: 1; transform: translateY(-4px); outline: 1px solid #fff; outline-offset: 2px; }
.lb-strip button:hover { opacity: .8; }
.lb-load { position: absolute; width: 40px; height: 1px; background: #fff; animation: lbl 1s infinite var(--ease); opacity: 0; }
#lb.busy .lb-load { opacity: 1; }
@keyframes lbl { 0% { transform: scaleX(0); transform-origin: left; } 50% { transform: scaleX(1); transform-origin: left; } 51% { transform-origin: right; } 100% { transform: scaleX(0); transform-origin: right; } }
@media (max-width: 760px) {
  .lb-stage { inset: 52px 0 96px; }
  .lb-prev, .lb-next { width: 50%; }
}

/* ── utilitaires reveal ── */
.rv { opacity: 0; transform: translateY(40px); transition: opacity 1s var(--ease-out), transform 1.2s var(--ease-out); }
.rv.in { opacity: 1; transform: none; }
.clip { clip-path: inset(100% 0 0 0); transition: clip-path 1.3s var(--ease); }
.clip.in { clip-path: inset(0 0 0 0); }
.split-line { display: block; overflow: hidden; }
.split-line > span { display: inline-block; transform: translateY(105%); transition: transform 1.1s var(--ease-out); }
.in .split-line > span, .split-line.in > span { transform: none; }

.page-enter { animation: pageIn .9s var(--ease-out) both; }
@keyframes pageIn { from { opacity: 0; transform: translateY(30px); } to { opacity: 1; transform: none; } }

.wipe {
  position: fixed; inset: 0; z-index: 140; pointer-events: none; background: var(--fg);
  transform: scaleY(0); transform-origin: bottom;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  .rv, .clip, .split-line > span { opacity: 1; transform: none; clip-path: none; }
}
