/*
 * Bewegung – bewusst dezent und rein per CSS.
 *
 * 1. Einblenden beim Scrollen: scroll-driven animations (animation-timeline: view()).
 *    Fallback: Browser ohne Unterstützung zeigen die Inhalte sofort und ohne Animation an.
 *    Es gibt keinen Zustand, in dem Inhalte unsichtbar bleiben.
 * 2. Leichtes Parallax nur für Bildflächen (.parallax).
 * 3. Bei prefers-reduced-motion: reduce wird jede Bewegung abgeschaltet.
 */

@media (prefers-reduced-motion: no-preference) {
  @supports (animation-timeline: view()) {
    .reveal {
      animation: reveal-up linear both;
      animation-timeline: view();
      animation-range: entry 0% entry 70%;
    }

    /* Elemente in Rastern leicht gestaffelt */
    .reveal-stagger > * {
      animation: reveal-up linear both;
      animation-timeline: view();
      animation-range: entry 0% entry 70%;
    }

    .reveal-stagger > :nth-child(2) { animation-range: entry 8% entry 78%; }
    .reveal-stagger > :nth-child(3) { animation-range: entry 16% entry 86%; }

    /* Parallax: Bild ist etwas größer als sein Rahmen und wandert beim Scrollen langsam */
    .parallax {
      overflow: hidden;
    }

    .parallax > img {
      scale: 1.12;
      animation: parallax-shift linear both;
      animation-timeline: view();
      animation-range: cover 0% cover 100%;
    }
  }

  /* Kleine Hover-Bewegungen für Karten und Buttons */
  .card {
    transition: transform 0.25s ease, box-shadow 0.25s ease;
  }

  .card:hover {
    transform: translateY(-3px);
    box-shadow: 0 0.5rem 2rem rgb(105 85 60 / 0.12);
  }

  .button:hover {
    transform: translateY(-1px);
  }

  html {
    scroll-behavior: smooth;
  }
}

/* ---------- Startseite: Hero zoomt beim Laden der Seite aus dem Hintergrund nach vorn (einmalig) ---------- */

@media (prefers-reduced-motion: no-preference) {
  /* 3D-Bühne: Elemente starten „weit hinten“ (negative Z-Achse) und kommen nach vorn */
  .hero--full .hero__grid,
  .hero--full .hero__text {
    perspective: 1000px;
  }

  .hero--full::before {
    animation: zoom-from-depth-soft 1.6s cubic-bezier(0.16, 1, 0.3, 1) both;
  }

  .hero--full::after {
    animation: zoom-from-depth-ring 1.8s cubic-bezier(0.16, 1, 0.3, 1) 0.1s both;
  }

  .hero--full .hero__media {
    animation: zoom-from-depth 1.4s cubic-bezier(0.16, 1, 0.3, 1) 0.15s both;
  }

  .hero--full .hero__text > * {
    animation: zoom-from-depth-text 1.1s cubic-bezier(0.16, 1, 0.3, 1) both;
  }

  .hero--full .hero__text > :nth-child(1) { animation-delay: 0.35s; }
  .hero--full .hero__text > :nth-child(2) { animation-delay: 0.45s; }
  .hero--full .hero__text > :nth-child(4) { animation-delay: 0.6s; }
  .hero--full .hero__text > :nth-child(5) { animation-delay: 0.72s; }
  .hero--full .hero__text > :nth-child(6) { animation-delay: 0.85s; }

  /* Die Linie unter der Überschrift zeichnet sich nach dem Titel ein */
  .hero--full .hero__text > .rule {
    animation: draw-line 0.8s cubic-bezier(0.65, 0, 0.35, 1) 0.85s both;
  }

  .hero--full .hero__scroll {
    animation: fade-in 0.8s ease-out 1.3s both;
  }
}

@keyframes zoom-from-depth {
  from {
    opacity: 0;
    translate: 0 0 -600px;
    filter: blur(14px);
  }

  to {
    opacity: 1;
    translate: 0 0 0;
    filter: blur(0);
  }
}

@keyframes zoom-from-depth-text {
  from {
    opacity: 0;
    translate: 0 1rem -320px;
    filter: blur(8px);
  }

  to {
    opacity: 1;
    translate: 0 0 0;
    filter: blur(0);
  }
}

@keyframes zoom-from-depth-soft {
  from { opacity: 0; scale: 0.3; }
  to { opacity: 0.7; scale: 1; }
}

@keyframes zoom-from-depth-ring {
  from { opacity: 0; scale: 0.2; }
  to { opacity: 0.45; scale: 1; }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ---------- Startseite: verspielte, aber ruhige Details ---------- */

@media (prefers-reduced-motion: no-preference) {
  @supports (animation-timeline: view()) {
    /* Leistungen „fliegen“ beim Scrollen herein: links, von unten, rechts – gestaffelt */
    .fly-in > * {
      animation: fly-in-up cubic-bezier(0.22, 1, 0.36, 1) both;
      animation-timeline: view();
      animation-range: entry 5% cover 38%;
    }

    .fly-in > :nth-child(3n + 1) {
      animation-name: fly-in-left;
    }

    .fly-in > :nth-child(3n + 2) {
      animation-range: entry 15% cover 42%;
    }

    .fly-in > :nth-child(3n) {
      animation-name: fly-in-right;
      animation-range: entry 25% cover 46%;
    }

    /* Salbei-Linien unter Überschriften zeichnen sich ein */
    .rule {
      animation: draw-line ease-out both;
      animation-timeline: view();
      animation-range: entry 20% cover 30%;
    }
  }

  /* Lesefortschritt: dünne Linie unter der Kopfzeile wächst mit dem Scrollen */
  @supports (animation-timeline: scroll()) {
    .site-header::after {
      animation: grow-x linear both;
      animation-timeline: scroll(root block);
    }
  }

  /* Organische Bildform „atmet“ langsam – wie die runde Form im Logo */
  .hero__frame {
    animation: blob-morph 18s ease-in-out infinite alternate;
  }

  .hero__media::before {
    animation: blob-morph-alt 22s ease-in-out infinite alternate;
  }

  /* Scroll-Hinweis: ein Punkt wandert ruhig die Linie hinab */
  .hero__scroll-line::after {
    animation: scroll-dot 2.6s cubic-bezier(0.65, 0, 0.35, 1) infinite;
  }
}

@keyframes fly-in-up {
  from {
    opacity: 0;
    translate: 0 4rem;
    scale: 0.94;
    filter: blur(6px);
  }

  to {
    opacity: 1;
    translate: 0 0;
    scale: 1;
    filter: blur(0);
  }
}

@keyframes fly-in-left {
  from {
    opacity: 0;
    translate: -5rem 2.5rem;
    rotate: -3deg;
    filter: blur(6px);
  }

  to {
    opacity: 1;
    translate: 0 0;
    rotate: 0deg;
    filter: blur(0);
  }
}

@keyframes fly-in-right {
  from {
    opacity: 0;
    translate: 5rem 2.5rem;
    rotate: 3deg;
    filter: blur(6px);
  }

  to {
    opacity: 1;
    translate: 0 0;
    rotate: 0deg;
    filter: blur(0);
  }
}

@keyframes draw-line {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

@keyframes grow-x {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

@keyframes blob-morph {
  0% { border-radius: 48% 52% 44% 56% / 38% 42% 58% 62%; }
  50% { border-radius: 56% 44% 50% 50% / 46% 36% 64% 54%; }
  100% { border-radius: 44% 56% 58% 42% / 40% 52% 48% 60%; }
}

@keyframes blob-morph-alt {
  0% { border-radius: 56% 44% 52% 48% / 48% 58% 42% 52%; }
  100% { border-radius: 46% 54% 40% 60% / 56% 44% 56% 44%; }
}

@keyframes scroll-dot {
  0% { translate: 0 -0.5rem; opacity: 0; }
  25% { opacity: 1; }
  75% { opacity: 1; }
  100% { translate: 0 2.75rem; opacity: 0; }
}

@keyframes reveal-up {
  from {
    opacity: 0;
    translate: 0 1.75rem;
  }

  to {
    opacity: 1;
    translate: 0 0;
  }
}

@keyframes parallax-shift {
  from { translate: 0 -5%; }
  to { translate: 0 5%; }
}

/* Absicherung: Bei reduzierter Bewegung wirklich alles aus – auch Übergänge aus anderen Dateien. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }

  .parallax > img {
    scale: 1 !important;
    translate: none !important;
  }

  .card:hover,
  .button:hover {
    transform: none !important;
  }
}

/* Druck: alles sichtbar, keine Bewegung */
@media print {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }

  .site-header,
  .nav-toggle,
  .skip-link {
    position: static;
  }
}

/* ---------- Logo: die Figur zeichnet sich beim Laden der Startseite ---------- */

@media (prefers-reduced-motion: no-preference) {
  /* Kein vector-effect: non-scaling-stroke – sonst rechnet der Browser das Strichmuster in Pixeln
     statt relativ zur Pfadlänge (pathLength="1"), und das „Zeichnen“ wäre unsichtbar. */
  .logo-figure {
    stroke: var(--brand-sage);
    stroke-width: 3;
    stroke-dasharray: 1;
    animation:
      logo-draw 1.8s cubic-bezier(0.65, 0, 0.35, 1) 0.2s both,
      logo-fill 0.7s ease-out 1.7s both;
  }

  /* Großes Logo im Hero: zeichnet sich, nachdem der Hero herangezoomt ist – hier gut sichtbar */
  .hero__placeholder .logo-figure {
    stroke-width: 2.5;
    animation:
      logo-draw 1.8s cubic-bezier(0.65, 0, 0.35, 1) 0.9s both,
      logo-fill 0.8s ease-out 2.5s both;
  }
}

@keyframes logo-draw {
  from { stroke-dashoffset: 1; }
  to { stroke-dashoffset: 0; }
}

@keyframes logo-fill {
  from { fill-opacity: 0; stroke-opacity: 1; }
  to { fill-opacity: 1; stroke-opacity: 0; }
}

/* ---------- Bewegungslinie: zeichnet sich beim Scrollen durch die Startseite ---------- */
/* Ohne Unterstützung oder bei reduzierter Bewegung: Linie steht ruhig und vollständig da. */

@media (prefers-reduced-motion: no-preference) {
  @supports (animation-timeline: view()) {
    .flow {
      view-timeline-name: --flow;
    }

    /* Die Linie wird von oben nach unten freigelegt (Maske), statt über ein Strichmuster:
       mit vector-effect: non-scaling-stroke funktioniert stroke-dashoffset nicht relativ zur Länge. */
    .flow__line {
      animation: flow-reveal linear both;
      animation-timeline: --flow;
      animation-range: cover 0% cover 100%;
    }
  }
}

@keyframes flow-reveal {
  from { clip-path: inset(0 0 100% 0); }
  to { clip-path: inset(0 0 0 0); }
}

/* ---------- Live-Status: ruhiger Pulsring, solange erreichbar ---------- */

@media (prefers-reduced-motion: no-preference) {
  .open-status.is-open .open-status__dot::after {
    animation: status-pulse 2.4s ease-out infinite;
  }
}

@keyframes status-pulse {
  0% { opacity: 0.6; scale: 0.6; }
  80%, 100% { opacity: 0; scale: 1.6; }
}

/* ---------- Fließende Seitenwechsel (native View Transitions des Browsers) ---------- */
/* Kopfzeile bleibt stehen, der Inhalt blendet weich über; Titel von News/Stellen wandern
   von der Karte an ihre Position auf der Detailseite (view-transition-name im Markup). */

@media (prefers-reduced-motion: no-preference) {
  @view-transition {
    navigation: auto;
  }

  .site-header {
    view-transition-name: site-header;
  }

  ::view-transition-old(root) {
    animation: vt-out 0.2s ease-in both;
  }

  ::view-transition-new(root) {
    animation: vt-in 0.4s cubic-bezier(0.16, 1, 0.3, 1) 0.05s both;
  }

  ::view-transition-group(*) {
    animation-duration: 0.5s;
    animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
  }
}

@keyframes vt-out {
  to { opacity: 0; }
}

@keyframes vt-in {
  from { opacity: 0; translate: 0 14px; }
}
