/* ---------------------------------------------------------------
   Zeichen-Effekt (Test)
   Beim Laden wird der Kopf gezeichnet, beim Scrollen der Rest:
   Konstruktionslinien, Maßlinien von der Mitte aus, Rahmen Seite
   für Seite, Bilder von der Skizze zum fertigen Bild, Zeilen
   abwechselnd von links und rechts.
   Die Scroll-Effekte steuert draw.js. Ohne JavaScript oder bei
   „Bewegung reduzieren“ steht die fertige Seite da.
   Entfernen: <link rel="stylesheet" href="/draw.css"> in index.html löschen.
   --------------------------------------------------------------- */

/* weiche Bewegung für Linien */
:root {
  --calm: cubic-bezier(0.45, 0, 0.25, 1);
}

@property --fr-t { syntax: '<percentage>'; inherits: false; initial-value: 100%; }
@property --fr-r { syntax: '<percentage>'; inherits: false; initial-value: 100%; }
@property --fr-b { syntax: '<percentage>'; inherits: false; initial-value: 100%; }
@property --fr-l { syntax: '<percentage>'; inherits: false; initial-value: 100%; }

/* Konstruktionslinien im Kopf (ohne Animation unsichtbar) */
.guide {
  display: none;
}

/* =================== Beim Laden =================== */

@media (prefers-reduced-motion: no-preference) {
  .intro {
    position: relative;
  }

  .intro h1 span {
    -webkit-text-stroke-color: currentColor;
    animation: ink-fill 1.6s var(--ease) both;
  }

  .intro h1 span + span {
    animation-delay: 0.25s;
  }

  .intro .label {
    animation-delay: 0.1s;
  }

  .lead {
    animation-delay: 0.7s;
  }

  /* Porträt: blendet ein, kurz grau, dann in Farbe */
  .detail .ring {
    animation: fade 0.8s ease 0.1s both;
  }

  .detail .photo {
    animation: photo-in 1.2s ease 0.3s both;
  }

  .detail figcaption .pos {
    animation: stamp 0.9s ease 1.1s both;
  }

  @media (min-width: 860px) {
    .guide {
      display: block;
      position: absolute;
      pointer-events: none;
      background: var(--tusche);
    }

    /* waagerecht durch die Grundlinie des Namens */
    .guide-h {
      left: -64px;
      right: -64px;
      top: 58%;
      height: 0.75px;
      transform-origin: left center;
      animation: guide-x 1.8s var(--ease) both;
    }

    /* senkrecht durch die Mitte des Porträts */
    .guide-v {
      top: -64px;
      bottom: -40px;
      right: 8.5rem;
      width: 0.75px;
      transform-origin: center top;
      animation: guide-y 1.8s var(--ease) 0.3s both;
    }
  }
}

/* =================== Beim Scrollen ===================
   Linien laufen zeitgesteuert, nicht am Scrollrad: draw.js setzt die
   Klasse .in, sobald ein Element unten ins Bild kommt. Erst danach,
   etwas weiter oben, wird der Text getippt. */

@media (prefers-reduced-motion: no-preference) {
  /* läuft, sobald draw.js .in setzt (spezifischer als die Regeln unten) */
  .typing .section-head.in::after,
  .typing .parts .pos.in,
  .typing .plate.in::after,
  .typing .plate.in img,
  .typing .plate.in .pos,
  .typing .spec.in::before,
  .typing .notes.in > div,
  .typing .parts.in tbody tr,
  .typing .tools div.in,
  .typing .rev li.in,
  .typing .rev .idx.in,
  .typing .field.in,
  .typing .dim.in::after,
  .typing .dim.in::before,
  .typing .ticks.in::after,
  .typing .ticks.in span,
  .typing .ticks.in .brk,
  .typing .today.in {
    animation-play-state: running;
  }

  /* --- Abschnittsköpfe: Linie von links --- */
  .typing .section-head {
    position: relative;
    border-bottom-color: transparent;
  }

  .typing .section-head::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: -1.25px;
    height: 1.25px;
    background: var(--ink);
    transform-origin: left center;
    animation: draw-x 1.8s var(--calm) both paused;
  }

  /* --- Stückliste --- */
  .typing .parts .pos {
    animation: stamp 0.9s ease 0.4s both paused;
  }

  /* --- Bildtafeln: Rahmen Seite für Seite, Bild wird scharf und farbig --- */
  .typing .plate {
    border-color: transparent;
  }

  .typing .plate::after {
    content: '';
    position: absolute;
    inset: -1px;
    pointer-events: none;
    background:
      linear-gradient(var(--ink), var(--ink)) left top / var(--fr-t) 1px no-repeat,
      linear-gradient(var(--ink), var(--ink)) right top / 1px var(--fr-r) no-repeat,
      linear-gradient(var(--ink), var(--ink)) right bottom / var(--fr-b) 1px no-repeat,
      linear-gradient(var(--ink), var(--ink)) left bottom / 1px var(--fr-l) no-repeat;
    animation: trace 2.2s var(--calm) both paused;
  }

  /* zweite Tafel: gespiegelt, beginnt oben rechts und läuft gegen den Uhrzeigersinn */
  .typing .piece:nth-child(even) .plate::after {
    background:
      linear-gradient(var(--ink), var(--ink)) right top / var(--fr-t) 1px no-repeat,
      linear-gradient(var(--ink), var(--ink)) left top / 1px var(--fr-r) no-repeat,
      linear-gradient(var(--ink), var(--ink)) left bottom / var(--fr-b) 1px no-repeat,
      linear-gradient(var(--ink), var(--ink)) right bottom / 1px var(--fr-l) no-repeat;
  }

  .typing .plate img {
    animation: develop 1.8s ease 0.6s both paused;
  }

  .typing .plate .pos {
    animation: stamp 0.9s ease 0.5s both paused;
  }

  /* --- Trennlinie zwischen Beschreibung und Datenblatt --- */
  .typing .spec {
    position: relative;
    border-top-color: transparent;
  }

  .typing .spec::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: -0.75px;
    height: 0.75px;
    background: var(--hair);
    transform-origin: left center;
    animation: draw-x 1.6s var(--calm) 0.2s both paused;
  }

  /* --- Notizen im Werdegang und Zeilen der Stückliste: von links aufgedeckt --- */
  .typing .notes > div,
  .typing .parts tbody tr {
    animation: reveal 1.4s var(--calm) both paused;
  }

  .typing .notes > div:nth-child(2) {
    animation-delay: 0.2s;
  }

  .typing .notes > div:nth-child(3) {
    animation-delay: 0.4s;
  }

  .typing .parts tbody tr:nth-child(2) {
    animation-delay: 0.2s;
  }

  /* --- Werkzeug und Ausblick: Linien --- */
  .typing .tools div,
  .typing .rev li {
    border-bottom-color: transparent;
    background: linear-gradient(var(--hair), var(--hair)) left bottom / 100% 0.75px no-repeat;
    animation: line-x 1.6s var(--calm) both paused;
  }

  .typing .rev li:nth-child(even) {
    background-position: right bottom;
  }

  .typing .rev .idx {
    animation: stamp 0.9s ease 0.5s both paused;
  }

  /* --- Schriftfeld: Linien dunkeln nach --- */
  .typing .field {
    animation: ink-in 1.6s ease both paused;
  }

  /* --- Fortschritt: Tuschelinie am linken Blattrand (folgt dem Scrollen) --- */
  @supports (animation-timeline: scroll()) {
    .sheet::after {
      content: '';
      position: absolute;
      left: 2px;
      top: 6px;
      bottom: 6px;
      width: 2px;
      background: var(--tusche);
      transform-origin: center top;
      animation: draw-y linear both;
      animation-timeline: scroll(root);
      pointer-events: none;
    }
  }

  /* Platz unter dem Blatt, damit auch der Footer getippt wird */
  .typing body {
    padding-bottom: 30vh;
  }

  /* hochkant auf dem Handy steht der Kontaktsatz über dem Schriftfeld
     und erreicht die Auslösezone auch ohne Zusatzplatz */
  @media (max-width: 640px) {
    .typing body {
      padding-bottom: 16px;
    }
  }
}

/* --- Maßkette (nur breite Ansicht) --- */
@media (prefers-reduced-motion: no-preference) {
  /* Maßlinie wächst von der Mitte nach außen */
  .typing .dim::after {
    transform-origin: center center;
    animation: draw-x 1.8s var(--calm) both paused;
  }

  /* Begrenzungen fallen danach ein */
  .typing .dim::before {
    animation: fade 0.8s ease 1.2s both paused;
  }

  .typing .ticks {
    border-top-color: transparent;
  }

  .typing .ticks::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: -1px;
    height: 1px;
    background: var(--ink);
    transform-origin: left center;
    animation: draw-x 2s var(--calm) both paused;
  }

  .typing .ticks span {
    animation: fade 1s ease 0.8s both paused;
  }

  .typing .ticks .brk {
    animation: stamp 0.9s ease 1.4s both paused;
  }

  .typing .today {
    transform-origin: center top;
    animation: draw-y 1.6s var(--calm) 1.2s both paused;
  }
}

/* --- Zeichentisch: wandert beim Scrollen langsamer mit als das Blatt,
   so ziehen alle Zeichnungen einmal vorbei, ohne sich zu wiederholen --- */
@supports (animation-timeline: scroll()) {
  @media (prefers-reduced-motion: no-preference) {
    body {
      animation: table-pan linear both;
      animation-timeline: scroll(root);
    }

  }
}

/* Raster und Zeichnungen bewegen sich gemeinsam, wie ein Tisch */
@keyframes table-pan {
  from { background-position: center 0, 0 0, 0 0, 0 0, 0 0; }
  to {
    background-position:
      center calc(100vh - 2700px),
      0 calc(100vh - 2700px),
      0 calc(100vh - 2700px),
      0 calc(100vh - 2700px),
      0 calc(100vh - 2700px);
  }
}

/* =================== Keyframes =================== */

@keyframes ink-fill {
  0% {
    -webkit-text-fill-color: transparent;
    -webkit-text-stroke-width: 1.25px;
    clip-path: inset(-10% 100% -10% 0);
  }
  45% {
    -webkit-text-fill-color: transparent;
    -webkit-text-stroke-width: 1.25px;
    clip-path: inset(-10% 0 -10% 0);
  }
  100% {
    -webkit-text-fill-color: currentColor;
    -webkit-text-stroke-width: 0px;
    clip-path: inset(-10% 0 -10% 0);
  }
}

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

@keyframes photo-in {
  0% { opacity: 0; filter: grayscale(0.7); }
  30% { opacity: 1; filter: grayscale(0.6); }
  100% { opacity: 1; filter: none; }
}

@keyframes guide-x {
  0% {
    transform: scaleX(0);
    opacity: 0.9;
  }
  55% {
    transform: scaleX(1);
    opacity: 0.9;
  }
  100% {
    transform: scaleX(1);
    opacity: 0;
  }
}

@keyframes guide-y {
  0% {
    transform: scaleY(0);
    opacity: 0.9;
  }
  55% {
    transform: scaleY(1);
    opacity: 0.9;
  }
  100% {
    transform: scaleY(1);
    opacity: 0;
  }
}

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

@keyframes draw-y {
  from { transform: scaleY(0); }
  to { transform: scaleY(1); }
}

@keyframes reveal {
  from { clip-path: inset(-0.4em 100% -0.4em -0.4em); opacity: 0.4; }
  to { clip-path: inset(-0.4em -0.4em -0.4em -0.4em); opacity: 1; }
}

@keyframes line-x {
  from { background-size: 0% 0.75px; }
  to { background-size: 100% 0.75px; }
}

@keyframes drop {
  from { opacity: 0; translate: 0 -14px; }
  to { opacity: 1; translate: 0 0; }
}

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

@keyframes stamp {
  from { opacity: 0; scale: 1.12; }
  to { opacity: 1; scale: 1; }
}

@keyframes trace {
  0% { --fr-t: 0%; --fr-r: 0%; --fr-b: 0%; --fr-l: 0%; }
  25% { --fr-t: 100%; --fr-r: 0%; --fr-b: 0%; --fr-l: 0%; }
  50% { --fr-t: 100%; --fr-r: 100%; --fr-b: 0%; --fr-l: 0%; }
  75% { --fr-t: 100%; --fr-r: 100%; --fr-b: 100%; --fr-l: 0%; }
  100% { --fr-t: 100%; --fr-r: 100%; --fr-b: 100%; --fr-l: 100%; }
}

@keyframes develop {
  from {
    filter: grayscale(1) blur(4px);
  }
  to {
    filter: grayscale(0) blur(0);
  }
}

@keyframes ink-in {
  from { background-color: var(--hair); border-color: var(--hair); }
  to { background-color: var(--ink); border-color: var(--ink); }
}

/* Tipp-Effekt (draw.js): Zeichen sind da, aber erst unsichtbar */
.typing [data-type] .ch {
  opacity: 0;
}

.typing [data-type] .ch.on {
  opacity: 1;
}

.typing [data-type] .ch.cur {
  box-shadow: 2px 0 0 var(--tusche);
}
