/* ============================================================
   SCENY — warstwa ruchu i kompozycji newAIorder (sierpień 2026)
   Wszystko natywne: scroll-driven animations (animation-timeline),
   View Transitions, :has(), color-mix(), container queries.
   Zero bibliotek, zero JS. Progressive enhancement:
   gdy przeglądarka nie zna funkcji — strona zostaje statyczna i czytelna.
   ============================================================ */

/* --- 1. PRZEJŚCIA MIĘDZY STRONAMI ---------------------------
   Nawigacja przestaje być przeładowaniem, staje się ruchem. */
@view-transition { navigation: auto; }

::view-transition-old(root) {
  animation: vt-out .26s cubic-bezier(.16,1,.3,1) both;
}
::view-transition-new(root) {
  animation: vt-in .34s cubic-bezier(.16,1,.3,1) both;
}
@keyframes vt-out { to { opacity: 0; transform: translateY(-8px) scale(.995); } }
@keyframes vt-in  { from { opacity: 0; transform: translateY(14px) scale(.997); } }

/* logo trwa między stronami — jedyny element, który się nie przeładowuje */
a.brand { view-transition-name: znak; }

/* --- 2. PASEK POSTĘPU LEKTURY — teraz na kompositorze -------
   scaleX zamiast width: bez layoutu, bez skryptu. */
@supports (animation-timeline: scroll()) {
  #progress {
    width: 100% !important;
    transform: scaleX(0);
    transform-origin: 0 50%;
    background: linear-gradient(90deg, var(--gold), var(--ember, #d98056), var(--moon, #a9c8dc));
    animation: pasek linear both;
    animation-timeline: scroll(root block);
  }
  @keyframes pasek { to { transform: scaleX(1); } }
}

/* --- 3. WEJŚCIA SEKCJI — bez IntersectionObserver ----------- */
@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    .reveal { opacity: 1; transform: none; transition: none; }
    .reveal > * {
      animation: wejscie linear both;
      animation-timeline: view();
      animation-range: entry 4% entry 46%;
    }
    /* rytm: kolejne elementy sekcji wchodzą z przesunięciem */
    .reveal > *:nth-child(2) { animation-range: entry 8% entry 50%; }
    .reveal > *:nth-child(3) { animation-range: entry 12% entry 54%; }
    .reveal > *:nth-child(n+4) { animation-range: entry 16% entry 58%; }
  }
  @keyframes wejscie {
    from { opacity: 0; transform: translateY(26px); filter: blur(6px); }
    to   { opacity: 1; transform: none; filter: blur(0); }
  }
}

/* --- 4. HERO — głębia paralaksy i oddech --------------------- */
@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    .hero {
      animation: hero-glebia linear both;
      animation-timeline: view();
      animation-range: cover 0% cover 100%;
    }
    @keyframes hero-glebia {
      from { background-position: 60% 38%; }
      to   { background-position: 60% 62%; }
    }
    /* treść odjeżdża wolniej niż tło — warstwy zamiast płaszczyzny */
    .hero .wrap {
      animation: hero-tresc linear both;
      animation-timeline: view();
      animation-range: exit 0% exit 100%;
    }
    @keyframes hero-tresc {
      from { opacity: 1; transform: none; }
      to   { opacity: 0; transform: translateY(-64px); }
    }
  }
}

/* pierwsze wejście strony — tylko raz, po załadowaniu */
@media (prefers-reduced-motion: no-preference) {
  .hero h1 { animation: tytul .9s cubic-bezier(.16,1,.3,1) both; }
  .hero .lede { animation: tytul .9s .1s cubic-bezier(.16,1,.3,1) both; }
  .hero .sub { animation: tytul .9s .18s cubic-bezier(.16,1,.3,1) both; }
  .hero .qrow { animation: tytul .9s .26s cubic-bezier(.16,1,.3,1) both; }
  .hero .alive, .hero .cue { animation: tytul .9s .34s cubic-bezier(.16,1,.3,1) both; }
  @keyframes tytul {
    from { opacity: 0; transform: translateY(20px); letter-spacing: .04em; }
    to   { opacity: 1; transform: none; }
  }
}

/* --- 5. DZIELNICE — kompozycja bento zamiast równej siatki --- */
@media (min-width: 900px) {
  .grid {
    grid-template-columns: repeat(6, 1fr);
    grid-auto-rows: minmax(10px, auto);
    gap: 22px;
  }
  .grid > .panel { grid-column: span 3; }
  /* pierwsza karta szeroka — wejście do miasta */
  .grid > .panel:first-child { grid-column: span 6; }
  .grid > .panel:first-child::before { height: 300px; }
  .grid > .panel:first-child:hover::before { height: 320px; }
  .grid > .panel:first-child::after { height: 320px; }
  .grid > .panel:first-child h3 { font-size: clamp(26px, 3.4vw, 38px); }
  /* trzy średnie w rzędzie */
  .grid > .panel:nth-child(4),
  .grid > .panel:nth-child(5),
  .grid > .panel:nth-child(6) { grid-column: span 2; }
}

/* karta jako obiekt fizyczny: światło idzie za kursorem, cień rośnie */
.panel {
  position: relative;
  isolation: isolate;
  transition: transform .45s cubic-bezier(.16,1,.3,1),
              border-color .45s ease, box-shadow .45s ease;
}
.panel:hover {
  transform: translateY(-6px);
  box-shadow: 0 30px 70px -30px rgba(0,0,0,.9),
              0 0 0 1px color-mix(in oklab, var(--acc) 35%, transparent);
}
.panel:active { transform: translateY(-2px) scale(.998); }

/* poświata dzielnicy pod kartą */
.panel::before { position: relative; z-index: 1; }
.panel .ck::before {
  content: "";
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--acc);
  box-shadow: 0 0 14px color-mix(in oklab, var(--acc) 80%, transparent);
}

/* wejście kart z rytmem — scroll-driven, nie czasowe */
@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    .grid > .panel {
      animation: karta linear both;
      animation-timeline: view();
      animation-range: entry 2% entry 42%;
    }
    .grid > .panel:nth-child(2n) { animation-range: entry 6% entry 46%; }
    .grid > .panel:nth-child(3n) { animation-range: entry 10% entry 50%; }
    @keyframes karta {
      from { opacity: 0; transform: translateY(48px) scale(.97); }
      to   { opacity: 1; transform: none; }
    }
  }
}

/* --- 6. KRONIKA — oś czasu rysuje się w miarę czytania ------- */
@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    #kronika .rail { position: relative; }
    #kronika .rail::before {
      transform-origin: 50% 0;
      animation: os linear both;
      animation-timeline: view();
      animation-range: cover 0% cover 62%;
    }
    @keyframes os { from { transform: scaleY(0); } to { transform: scaleY(1); } }

    .entry {
      animation: wpis linear both;
      animation-timeline: view();
      animation-range: entry 0% entry 38%;
    }
    @keyframes wpis {
      from { opacity: 0; transform: translateX(22px); }
      to   { opacity: 1; transform: none; }
    }
    /* węzeł na osi zapala się, gdy wpis wchodzi */
    .entry::before {
      animation: wezel linear both;
      animation-timeline: view();
      animation-range: entry 10% entry 44%;
    }
    @keyframes wezel {
      from { transform: scale(.3); box-shadow: 0 0 0 rgba(217,168,92,0); opacity: .3; }
      to   { transform: scale(1); box-shadow: 0 0 18px rgba(217,168,92,.55); opacity: 1; }
    }
  }
}

/* najnowszy wpis wyróżniony — hierarchia, nie jednolita lista */
#kronika .entry:first-of-type {
  border-color: color-mix(in oklab, var(--gold) 34%, var(--line));
  background:
    radial-gradient(600px 200px at 12% 0%, rgba(217,168,92,.07), transparent 70%),
    linear-gradient(180deg, rgba(255,255,255,.025), transparent);
}
#kronika .entry:first-of-type .date::after {
  content: "najnowszy";
  margin-left: 12px; padding: 3px 10px;
  border: 1px solid color-mix(in oklab, var(--gold) 45%, transparent);
  border-radius: 999px; font-size: 10px; letter-spacing: 1.6px;
  color: var(--gold); text-transform: uppercase;
}
html[lang="en"] #kronika .entry:first-of-type .date::after { content: "latest"; }

/* --- 7. TYPOGRAFIA — oddech i łamanie jak w druku ------------ */
h1, h2, h3 { text-wrap: balance; }
p, .lede, .sub, .panel p { text-wrap: pretty; }
h1 { letter-spacing: -.03em; }
.pull {
  position: relative;
  border-left-color: color-mix(in oklab, var(--gold) 70%, transparent);
}
.pull::before {
  content: "";
  position: absolute; left: -1px; top: 0; bottom: 0; width: 2px;
  background: linear-gradient(180deg, var(--gold), transparent);
}
@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    .pull::before {
      transform-origin: 50% 0;
      animation: kreska linear both;
      animation-timeline: view();
      animation-range: entry 10% cover 40%;
    }
    @keyframes kreska { from { transform: scaleY(0); } to { transform: scaleY(1); } }
  }
}

/* --- 8. NAWIGACJA — szkło, które gęstnieje przy przewijaniu -- */
@supports (animation-timeline: scroll()) {
  header.top {
    animation: pasek-gora linear both;
    animation-timeline: scroll(root block);
    animation-range: 0 220px;
  }
  @keyframes pasek-gora {
    from { backdrop-filter: blur(6px); background-color: rgba(7,7,11,.35); border-bottom-color: transparent; }
    to   { backdrop-filter: blur(18px) saturate(140%); background-color: rgba(7,7,11,.86); border-bottom-color: var(--line); }
  }
}
.nav a { position: relative; }
.nav a::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -6px; height: 1px;
  background: currentColor; transform: scaleX(0); transform-origin: 0 50%;
  transition: transform .35s cubic-bezier(.16,1,.3,1);
}
.nav a:hover::after, .nav a.on::after { transform: scaleX(1); }

/* --- 9. CHIPY PYTAŃ — dotyk zamiast płaskiego linku --------- */
.qrow a {
  position: relative; overflow: hidden;
  transition: transform .3s cubic-bezier(.16,1,.3,1), color .3s, border-color .3s, background .3s;
}
.qrow a::before {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(120px 60px at var(--mx, 50%) 50%, color-mix(in oklab, var(--gold) 22%, transparent), transparent 70%);
  opacity: 0; transition: opacity .3s;
}
.qrow a:hover::before { opacity: 1; }

/* --- 10. FORMULARZ I STOPKA --------------------------------- */
input:focus, textarea:focus { border-color: color-mix(in oklab, var(--gold) 70%, transparent); }
button.send { transition: transform .2s cubic-bezier(.16,1,.3,1), box-shadow .3s, filter .3s; }
button.send:hover { filter: brightness(1.06); }

footer { position: relative; }
footer::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 1px;
  background: linear-gradient(90deg, transparent, color-mix(in oklab, var(--gold) 55%, transparent), transparent);
}

/* --- 11. KONTENERY — karta dostosowuje się do własnej szerokości */
.grid { container-type: inline-size; }
@container (max-width: 560px) {
  .panel h3 { font-size: 21px; }
  .panel p { font-size: 14.5px; }
}

/* --- 12. UMIAR — pełny szacunek dla reduced motion ----------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
  .reveal > *, .grid > .panel, .entry { opacity: 1 !important; transform: none !important; filter: none !important; }
}
