/* ==========================================================================
   MC — Michał Chrostek / cyfrowa obecność
   Warstwa UI nad sceną WebGL (three.js): HUD, przystanki, przejścia.
   ========================================================================== */

:root {
  --bg: #04060a;
  --bg-soft: #070c13;
  --ink: #e8fbff;
  --dim: rgba(232, 251, 255, 0.68);
  --faint: rgba(232, 251, 255, 0.30);
  --cyan: #5ef2ff;
  --cyan-deep: #0a3d4a;
  --mag: #ff3ea5;
  --violet: #8b5cf6;
  --line: rgba(94, 242, 255, 0.22);
  --line-soft: rgba(94, 242, 255, 0.12);
  --font-display: "Space Grotesk", "Helvetica Neue", Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --gutter: clamp(20px, 5.5vw, 110px);
  --hud-h: 64px;
}

* { box-sizing: border-box; }

html {
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 15px;
  line-height: 1.55;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body.is-locked { overflow: hidden; }

::selection { background: var(--cyan); color: #02121a; }

/* ── scena ─────────────────────────────────────────────────────────── */
#gl {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
  background: radial-gradient(120% 90% at 50% 0%, #071018 0%, #04060a 55%, #020306 100%);
}

.spacer { height: 540vh; position: relative; z-index: 1; pointer-events: none; }

/* ── warstwy efektów ────────────────────────────────────────────────── */
.fx { position: fixed; inset: 0; z-index: 2; pointer-events: none; }

.fx--grain {
  opacity: 0.07;
  mix-blend-mode: screen;
  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='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 160px 160px;
  animation: grain 1.1s steps(3) infinite;
}

.fx--scan {
  opacity: 0.35;
  background: repeating-linear-gradient(to bottom, rgba(190, 246, 255, 0.055) 0 1px, rgba(0, 0, 0, 0) 1px 3px);
  mix-blend-mode: soft-light;
}

.fx--vignette {
  background:
    radial-gradient(140% 110% at 50% 45%, rgba(0, 0, 0, 0) 42%, rgba(2, 4, 8, 0.55) 78%, rgba(2, 3, 6, 0.92) 100%),
    linear-gradient(to bottom, rgba(2, 4, 8, 0.55) 0%, rgba(0, 0, 0, 0) 18%, rgba(0, 0, 0, 0) 82%, rgba(2, 3, 6, 0.7) 100%);
}

@keyframes grain {
  0% { transform: translate3d(0, 0, 0); }
  33% { transform: translate3d(-4%, 2%, 0); }
  66% { transform: translate3d(3%, -3%, 0); }
  100% { transform: translate3d(0, 0, 0); }
}

/* błysk przy zmianie strony */
.flash {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  background: #dffbff;
  opacity: 0;
  mix-blend-mode: screen;
  transition: opacity 0.5s ease;
}
.flash.is-on { opacity: 0.55; transition-duration: 0.12s; }

/* ── ramka narożna ──────────────────────────────────────────────────── */
.frame { position: fixed; inset: 18px; z-index: 6; pointer-events: none; }
.frame i { position: absolute; width: 22px; height: 22px; border: 1px solid var(--line); }
.frame__tl { top: 0; left: 0; border-right: 0; border-bottom: 0; }
.frame__tr { top: 0; right: 0; border-left: 0; border-bottom: 0; }
.frame__bl { bottom: 0; left: 0; border-right: 0; border-top: 0; }
.frame__br { bottom: 0; right: 0; border-left: 0; border-top: 0; }

/* ── HUD ────────────────────────────────────────────────────────────── */
.hud {
  position: fixed;
  left: 0;
  right: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 0 clamp(26px, 3.4vw, 52px);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--dim);
  pointer-events: none;
}

.hud--top { top: 0; height: var(--hud-h); }
.hud--bottom { bottom: 0; height: 52px; border-top: 1px solid var(--line-soft); }

.hud__brand { display: flex; align-items: baseline; gap: 14px; }
.hud__name {
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.18em;
}
.hud__ver { color: var(--faint); letter-spacing: 0.2em; font-size: 10px; }

.pulse {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 0 0 rgba(94, 242, 255, 0.6);
  animation: pulse 2.4s ease-out infinite;
  align-self: center;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(94, 242, 255, 0.5); }
  70% { box-shadow: 0 0 0 9px rgba(94, 242, 255, 0); }
  100% { box-shadow: 0 0 0 0 rgba(94, 242, 255, 0); }
}

.hud__tools { display: flex; align-items: center; gap: 18px; }
.hud__clock { font-variant-numeric: tabular-nums; color: var(--faint); letter-spacing: 0.18em; }

.ghost-btn {
  pointer-events: auto;
  appearance: none;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--dim);
  font: inherit;
  font-size: 10px;
  letter-spacing: 0.18em;
  padding: 7px 12px;
  cursor: pointer;
  transition: color 0.25s ease, border-color 0.25s ease, background 0.25s ease;
}
.ghost-btn:hover, .ghost-btn:focus-visible { color: var(--ink); border-color: var(--cyan); background: rgba(94, 242, 255, 0.07); }
.ghost-btn[aria-pressed="true"] { color: var(--cyan); border-color: var(--cyan); }

.hud__status { display: flex; align-items: center; gap: 9px; }
.dot { width: 5px; height: 5px; border-radius: 50%; background: var(--cyan); box-shadow: 0 0 8px var(--cyan); }
.hud__counter { color: var(--ink); letter-spacing: 0.28em; font-variant-numeric: tabular-nums; }

.hud__legal {
  color: #ffffff;
  font-size: 9px;
  letter-spacing: 0.16em;
  text-align: center;
  white-space: nowrap;
}
@media (max-width: 1180px) {
  .hud__legal { display: none; }
}

/* ── rail ───────────────────────────────────────────────────────────── */
.rail {
  position: fixed;
  right: clamp(26px, 3.4vw, 52px);
  top: 50%;
  transform: translateY(-50%);
  z-index: 9;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 18px;
}

.rail__hint {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  opacity: 0.82;
  font-size: 10.5px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  transition: opacity 0.55s ease, transform 0.55s ease;
}
.rail__hint.is-off { opacity: 0; transform: translateY(-5px); }

.rail__mouse {
  flex: 0 0 auto;
  display: block;
  width: 24px;
  height: 46px;
  color: var(--cyan);
  filter: drop-shadow(0 0 6px rgba(94, 242, 255, 0.35));
}
.rail__mouse svg { display: block; width: 24px; height: 46px; }

.rail__mouse .wheel {
  fill: var(--cyan);
  animation: rail-wheel 2.1s cubic-bezier(0.45, 0, 0.25, 1) infinite;
}
.rail__mouse .chev {
  stroke: var(--cyan);
  opacity: 0.5;
  animation: rail-chev 2.1s ease-in-out infinite;
}
@keyframes rail-wheel {
  0%   { transform: translateY(0);    opacity: 0; }
  18%  { transform: translateY(0);    opacity: 1; }
  62%  { transform: translateY(4px);  opacity: 1; }
  100% { transform: translateY(6px);  opacity: 0; }
}
@keyframes rail-chev {
  0%, 30%   { opacity: 0.35; transform: translateY(0); }
  70%       { opacity: 1;    transform: translateY(2px); }
  100%      { opacity: 0.35; transform: translateY(0); }
}

@media (hover: none) {
  .rail__hint { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .rail__mouse .wheel, .rail__mouse .chev { animation: none; }
}

.rail ol { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }

.rail button {
  appearance: none;
  background: none;
  border: 0;
  padding: 7px 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  color: var(--faint);
  font: inherit;
  font-size: 10px;
  letter-spacing: 0.16em;
  cursor: pointer;
  transition: color 0.3s ease;
}
.rail button > b { font-weight: 400; opacity: 0; transform: translateX(6px); transition: opacity 0.3s ease, transform 0.3s ease; }
.rail button:hover > b, .rail button:focus-visible > b { opacity: 1; transform: none; }
.rail button > span { position: relative; padding-right: 26px; }
.rail button > span::after {
  content: "";
  position: absolute;
  right: 0; top: 50%;
  width: 16px; height: 1px;
  background: currentColor;
  transform-origin: right center;
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1), background-color 0.35s ease;
}
.rail li.is-active button { color: var(--cyan); }
.rail li.is-active button > span::after { transform: scaleX(0); background: var(--cyan); }

/* aktywny etap: zamiast „przekreślenia” wirująca cząsteczka DNA po prawej */
.rail button .rail__dna {
  position: absolute;
  right: 0;
  top: 50%;
  margin-top: -10px;
  width: 16px;
  height: 20px;
  display: none;
  color: var(--cyan);
  transform-origin: 50% 50%;
  pointer-events: none;
}
.rail button .rail__dna svg { display: block; width: 100%; height: 100%; overflow: visible; }
.rail li.is-active button .rail__dna {
  display: block;
  filter: drop-shadow(0 0 4px rgba(94, 242, 255, 0.55));
  animation: rail-dna-in 0.4s ease both, rail-dna-spin 4.4s linear infinite;
}
@keyframes rail-dna-spin { to { transform: rotate(360deg); } }
@keyframes rail-dna-in { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .rail li.is-active button .rail__dna { animation: none; }
}

.hud--bottom::after {
  content: "";
  position: absolute;
  left: 0; bottom: -1px;
  height: 1px;
  width: var(--progress, 0%);
  background: linear-gradient(90deg, var(--cyan), var(--mag));
  box-shadow: 0 0 12px rgba(94, 242, 255, 0.6);
  transition: width 0.12s linear;
}

/* ── typografia wspólna ─────────────────────────────────────────────── */
.eyebrow {
  margin: 0 0 18px;
  font-size: 11px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--dim);
  display: flex;
  align-items: center;
  gap: 12px;
  text-shadow: 0 2px 18px rgba(2, 4, 8, 0.9);
}
.eyebrow__num {
  color: var(--cyan);
  border: 1px solid var(--line);
  padding: 3px 7px;
  font-size: 10px;
  letter-spacing: 0.1em;
}

/* ── przystanki ─────────────────────────────────────────────────────── */
.stop {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: var(--hud-h) var(--gutter) 11vh;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  will-change: opacity, transform;
  background: linear-gradient(to top, rgba(4, 6, 10, 0.96) 0%, rgba(4, 6, 10, 0.72) 26%, rgba(4, 6, 10, 0.08) 52%, rgba(4, 6, 10, 0) 64%);
}

.stop__card {
  pointer-events: auto;
  position: relative;
  display: block;
  width: min(700px, 100%);
  padding: 24px 28px 22px;
  text-decoration: none;
  color: inherit;
  border-radius: 18px;
  background: rgba(4, 7, 12, 0.59);
  border: 1px solid var(--line-soft);
  box-shadow:
    0 0 0 1px rgba(94, 242, 255, 0.07),
    0 0 70px rgba(94, 242, 255, 0.18),
    0 0 170px rgba(94, 242, 255, 0.11),
    0 0 240px rgba(139, 92, 246, 0.06);
  transition: border-color 0.3s ease, background-color 0.3s ease, box-shadow 0.35s ease, transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  backdrop-filter: blur(8px);
}

.stop__card::before {
  content: "";
  position: absolute;
  left: 1px; top: 20px; bottom: 20px;
  width: 1px;
  border-radius: 1px;
  background: linear-gradient(to bottom, transparent, var(--line), transparent);
  opacity: 0.6;
  transition: opacity 0.3s ease, background 0.3s ease;
}

.stop__card:hover,
.stop__card:focus-visible {
  border-color: var(--cyan);
  background: rgba(8, 20, 28, 0.70);
  box-shadow:
    0 0 0 1px rgba(94, 242, 255, 0.22),
    0 0 90px rgba(94, 242, 255, 0.26),
    0 0 200px rgba(94, 242, 255, 0.12),
    0 0 240px rgba(139, 92, 246, 0.10);
  transform: translateY(-3px);
  outline: none;
}
.stop__card:hover::before,
.stop__card:focus-visible::before { background: var(--cyan); opacity: 1; }

.stop__title {
  margin: 0 0 12px;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: clamp(1.45rem, 2.95vw, 2.35rem);
  line-height: 1.08;
  letter-spacing: 0.015em;
  text-transform: uppercase;
  color: var(--ink);
  text-shadow: 0 2px 30px rgba(2, 4, 8, 0.9);
}
.stop--hero .stop__title { font-size: clamp(1.6rem, 3.7vw, 2.9rem); }

.stop__title .line { display: block; overflow: hidden; }.stop__title .line > i {
  display: block;
  font-style: normal;
  transform: translate3d(0, 106%, 0);
  transition: transform 0.9s cubic-bezier(0.16, 1, 0.3, 1);
}
.stop.is-in .stop__title .line > i { transform: none; }
.stop.is-in .stop__title .line:nth-child(2) > i { transition-delay: 0.08s; }

/* stacje, których tytuł jest już w 3D (O MNIE, KONTAKT) — karta bez duplikatu */
.stop--bare .stop__title {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.stop--bare .stop__lead { font-size: clamp(13px, 1.12vw, 14.5px); }

.stop__lead {
  margin: 0 0 16px;
  max-width: 62ch;
  font-size: clamp(12.5px, 1.05vw, 14px);
  line-height: 1.8;
  color: var(--dim);
}

.stop__cta {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 10px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--cyan);
}
.stop__cta i {
  display: inline-block;
  font-style: normal;
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}
.stop__card:hover .stop__cta i,
.stop__card:focus-visible .stop__cta i { transform: translateX(6px); }

/* przejście na podstronę */
body.is-leaving .stop,
body.is-leaving .hud,
body.is-leaving .rail,
body.is-leaving .frame {
  opacity: 0 !important;
  filter: blur(7px);
  transition: opacity 0.42s ease, filter 0.42s ease;
}
body.is-leaving #gl { filter: blur(2px); transition: filter 0.5s ease; }

/* wyjście „na prawo” do drugiego rdzenia (portfolio): scena odjeżdża w lewo,
   karty zostają widoczne — to podróż, nie zwykłe opuszczenie strony */
body.is-shift-right #gl,
body.is-shift-right .stop__card,
body.is-shift-right .rail,
body.is-shift-right .hud,
body.is-shift-right .frame,
body.is-shift-right #cursor-trail,
body.is-shift-right #cursor-fx {
  transform: translate3d(-9vw, 0, 0);
  opacity: 0.32;
  transition: transform 0.72s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.62s ease;
}
body.is-shift-right #gl { opacity: 0.55; }

/* ── ozdoba kursora + cyfrowy ślad ──────────────────────────────────── */
#cursor-trail {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 39;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.5s ease;
}

#cursor-fx {
  position: fixed;
  left: 0;
  top: 0;
  width: 240px;
  height: 240px;
  z-index: 40;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.35s ease;
  will-change: transform;
}

@media (hover: hover) and (pointer: fine) {
  body.is-ready, body.is-ready a, body.is-ready button { cursor: none; }
  body.is-ready #cursor-fx { opacity: 1; }
  body.is-ready #cursor-trail { opacity: 1; }
}

@media (hover: none) {
  #cursor-trail { display: none; }
}

/* ── loader ─────────────────────────────────────────────────────────── */
.loader {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #04060a;
  transition: opacity 0.9s ease, visibility 0.9s ease;
}
.loader.is-done { opacity: 0; visibility: hidden; }

@keyframes loader-failsafe { to { opacity: 0; visibility: hidden; } }
.loader { animation: loader-failsafe 0.8s ease 14s forwards; }

.loader__box { width: min(420px, 78vw); }
.loader__brand {
  margin: 0 0 18px;
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.42em;
  font-size: 18px;
  color: var(--ink);
}
.loader__track { height: 1px; background: rgba(94, 242, 255, 0.14); position: relative; overflow: hidden; }
.loader__track span {
  position: absolute; inset: 0;
  transform-origin: left center;
  transform: scaleX(0);
  background: linear-gradient(90deg, var(--cyan), var(--mag));
  transition: transform 0.2s linear;
}
.loader__row {
  margin-top: 12px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--faint);
}
#loader-pct { color: var(--cyan); font-variant-numeric: tabular-nums; }

/* ── fallback ───────────────────────────────────────────────────────── */
.fallback {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 30;
  padding: 28px var(--gutter);
  background: rgba(4, 7, 12, 0.96);
  border-top: 1px solid var(--line);
  color: var(--dim);
}
.fallback h2 { margin: 0 0 8px; font-family: var(--font-display); font-size: 20px; color: var(--ink); }
.fallback p { margin: 0; max-width: 70ch; font-size: 13px; }
.fallback a { color: var(--cyan); }

/* ── responsywność ──────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .hud__ver { display: none; }
  .rail b { display: none; }
  .rail span { padding-right: 20px; }
}

@media (max-width: 860px) {
  :root { --hud-h: 56px; }
  .frame { display: none; }
  .hud { font-size: 10px; }
  .hud__clock { display: none; }
  .ghost-btn { font-size: 9px; padding: 6px 9px; letter-spacing: 0.1em; }
  .hud__name { font-size: 14px; }

  .stop { padding: calc(var(--hud-h) + 12px) var(--gutter) 104px; }
  .stop__card { padding: 18px 18px 16px; border-radius: 14px; }
  .stop__title { font-size: clamp(1.5rem, 6.4vw, 2.2rem); }
  .stop--hero .stop__title { font-size: clamp(1.7rem, 7.4vw, 2.6rem); }
  .stop__lead { font-size: 12px; line-height: 1.7; }
  .eyebrow { font-size: 9.5px; letter-spacing: 0.2em; margin-bottom: 12px; }

  .rail { top: auto; bottom: 54px; right: 0; left: 0; transform: none; }
  .rail ol { flex-direction: row; justify-content: center; gap: 2px; }
  .rail button { padding: 8px 6px; }
  .rail span { padding-right: 0; }
  .rail span::after { display: none; }
  .rail button .rail__dna, .rail li.is-active button .rail__dna { display: none; }
  .rail li.is-active span { color: var(--cyan); text-shadow: 0 0 14px rgba(94, 242, 255, 0.6); }
}

@media (max-width: 520px) {
  .stop { padding-bottom: 96px; }
  .stop__lead { font-size: 12.5px; line-height: 1.65; }
}

/* ── reduced motion ─────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .fx--grain, .pulse { animation: none; }
  .stop__title .line > i { transition: none; transform: none; }
  .stop__card, .stop__cta i { transition: none; }
  .stop.is-in .stop__title .line > i { transform: none; }
}
