/* Herrn Lanos Wollknäuel: Brett, Wolle, Stifte, Schriften und Aquarell-Grund,
   dazu die Rollen, die es in den Tokens nicht gibt (Faden, Schnittbogen). */

/* Lilita One (Titel, Knöpfe, Zahlen) und Barlow (Text), selbst gehostet, OFL. */
@font-face {
  font-family: "Lilita One";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/lilita-one-latin.woff2") format("woff2");
}
@font-face {
  font-family: "Barlow";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/barlow-400-latin.woff2") format("woff2");
}
@font-face {
  font-family: "Barlow";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/barlow-700-latin.woff2") format("woff2");
}

:root {
  /* Gemessen an der Ergebnis-Karte: Rand, Titel, Herr Lano über der Folie, Punkte, Fuß. */
  --fan-reserve: 16.25rem;
  --result-overlap: 2.25rem;
  /* Wolle und Schnittbogen: Fadenfarbe bleibt Cyan, auch im Universum Puerto Patida. */
  --yarn: #039eec;
  --yarn-twist: #5cc3f5;
  --yarn-deep: #036b9e;
  --yarn-tint: #e2f4fd;
  --yarn-shade: color-mix(in srgb, var(--yarn) 70%, var(--yarn-deep));
  --paper-line: color-mix(in srgb, var(--yarn-deep) 9%, transparent);
  --cut-line: color-mix(in srgb, var(--color-ink) 20%, transparent);
  /* Rot als Text auf Creme (Rot selbst ist nur Fläche) */
  --wrong-text: var(--pp-red-deep);
}

/* Aquarell-Grund: ein festes Element mit dem Bild (kein background-attachment: fixed, das iOS ignoriert und
   Browser beim Scrollen neu malen). Das Bild rastert der Browser einmal, danach schiebt er nur die Ebene. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  /* Feste Bildbreite statt cover: Die Größe hängt nicht an der Fensterhöhe, die sich am iPhone beim Scrollen ändert.
     Unten läuft der Grund wie ein Fleck ins Papier aus. Etwas nach oben, damit die Wortmarke auf Tupfern steht. */
  background: url("img/grund.svg") center -90px / 1350px auto no-repeat;
}

@media (min-width: 1000px) {
  body::before {
    background-size: 1200px auto;
    background-position: center -80px;
  }
}

/* ---------- Startmenü: Knäuel am Logo ---------- */

/* Wie Baumi hinter den Büschen: eine kleine Szene am Titel. Herr Lano hält im Porträt ein Knäuel;
   ein zweites rollt neben ihm los, unter der Wortmarke entlang, und legt den Faden als Unterstrich
   ab. Dann rollt es sich wieder auf und zurück. Das Knäuel dreht sich um seine Mitte und schrumpft
   zum Boden hin, so bleibt der Faden an ihm; Faden und Knäuel laufen im selben Takt. Beide tragen
   dieselbe Kontur in Tinte. Die Bahn beginnt im Porträt und reicht über die Wortmarke hinaus. Nur
   transform und clip-path bewegen sich; im Spiel ist #start verborgen und die Szene steht. */
/* Das Porträt sitzt links und rückt neben den Zurück-Pfeil, nicht darunter; rechts bleibt
   Platz für das Knäuel am Ende seiner Bahn (schmale Handys verkleinern dafür die Wortmarke). */
.start-head {
  padding: 0 var(--space-3) 0 var(--tap-min);
}
.start-head .start-logo {
  position: relative;
}
.logo-yarn {
  --ball: 1.7rem;
  position: absolute;
  left: calc(var(--ball) * -1);
  right: calc(var(--ball) * -0.5);
  /* Über der Serienkette (mindestens 6 px): Ohne Top-3-Karte rückt sie direkt unter das Logo. */
  bottom: calc(var(--ball) * -0.45 + 0.5rem);
  height: var(--ball);
  pointer-events: none;
}
.logo-thread {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: calc(var(--ball) / 3);
  overflow: visible;
  animation: logo-thread 16s ease-in-out infinite;
}
.logo-thread path {
  fill: none;
  stroke: var(--yarn);
  stroke-width: 2.5;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}
.logo-thread .logo-outline {
  stroke: var(--color-ink);
  stroke-width: 5.2;
}
/* Die Laufbahn ist so breit wie der Faden; das Knäuel sitzt mit seiner Mitte an ihrem rechten Ende. */
.logo-run {
  position: absolute;
  inset: 0;
  animation: logo-run 16s ease-in-out infinite;
}
.logo-ball {
  position: absolute;
  right: calc(var(--ball) / -2);
  bottom: 0;
  width: var(--ball);
  height: var(--ball);
  transform-origin: 50% 100%;
  animation: logo-shrink 16s ease-in-out infinite;
}
.logo-ball svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
  animation: logo-roll 16s ease-in-out infinite;
}
.logo-ball circle {
  fill: var(--yarn);
  stroke: var(--color-ink);
  stroke-width: 1.5;
}
.logo-ball path {
  fill: none;
  stroke: var(--yarn-twist);
  stroke-width: 1.6;
  stroke-linecap: round;
}
/* Ruhe am Porträt, hinrollen, kurz liegen, zurückrollen und aufwickeln. */
@keyframes logo-run {
  from,
  12% {
    transform: translateX(-100%);
  }
  42%,
  58% {
    transform: translateX(0);
  }
  88%,
  to {
    transform: translateX(-100%);
  }
}
@keyframes logo-thread {
  from,
  12% {
    clip-path: inset(-0.5rem 100% -0.5rem -0.5rem);
  }
  42%,
  58% {
    clip-path: inset(-0.5rem -0.5rem -0.5rem -0.5rem);
  }
  88%,
  to {
    clip-path: inset(-0.5rem 100% -0.5rem -0.5rem);
  }
}
@keyframes logo-roll {
  from,
  12% {
    transform: rotate(0deg);
  }
  42%,
  58% {
    transform: rotate(900deg);
  }
  88%,
  to {
    transform: rotate(0deg);
  }
}
@keyframes logo-shrink {
  from,
  12% {
    transform: scale(1);
  }
  42%,
  58% {
    transform: scale(0.7);
  }
  88%,
  to {
    transform: scale(1);
  }
}
html[data-reduced-motion] .logo-yarn {
  display: none;
}

/* ---------- Spielansicht ---------- */

.bar h2 {
  flex: 1;
  margin: 0;
  text-align: center;
  font-size: var(--text-l);
  font-family: var(--font-display);
  font-weight: 400;
  color: var(--color-on-bg);
}

/* Infos-Karte über dem Brett: flache Zeile mit Uhr und Zählern. */
.infos {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-s);
  font-weight: 700;
  color: var(--color-ink-soft);
}
.timer {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: var(--text-l);
  font-variant-numeric: tabular-nums;
  color: var(--color-ink);
}

.board-card {
  padding: var(--space-2);
}

.board {
  display: block;
  width: 100%;
  height: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.paper {
  pointer-events: none;
}
.paper-line {
  fill: none;
  stroke: var(--paper-line);
  stroke-width: 1;
}
.fabric-ground {
  fill: var(--yarn-tint);
}
.fabric-stripe {
  fill: var(--yarn-twist);
  opacity: 0.35;
}

/* Das fertige Stoffteil erscheint, während das Knäuel abrollt. */
.fill {
  fill: url(#fabric);
  opacity: 0;
  transition: opacity 900ms var(--ease-out) 600ms;
}
.fill.is-inside {
  opacity: 1;
}
html[data-reduced-motion] .fill {
  transition: none;
}

/* Offene Kante: gestrichelte Schnittlinie. Gelegt: Wolle aus drei verdrehten Strängen, ohne Kontur. */
.edge {
  stroke: var(--cut-line);
  stroke-width: 1.2;
  stroke-dasharray: 3 4;
  stroke-linecap: round;
}
.edge.is-line {
  stroke: transparent;
}
.wools,
.unroll {
  filter: url(#fuzz);
}
.wool {
  visibility: hidden;
}
.wool.is-line {
  visibility: visible;
}
.is-solved .wool {
  visibility: hidden;
}
.wool path,
.unroll path {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.strand-0 {
  stroke: var(--yarn);
  stroke-width: 4.4;
}
.strand-1 {
  stroke: color-mix(in srgb, var(--yarn) 80%, var(--yarn-twist));
  stroke-width: 3.9;
}
.strand-2 {
  stroke: var(--yarn-shade);
  stroke-width: 3.4;
}

/* Nach dem Lösen: ein Faden, der hinter dem Knäuel sichtbar wird (--t setzt board.js). */
.unroll {
  visibility: hidden;
}
.is-solved .unroll {
  visibility: visible;
}
.unroll path {
  stroke-dasharray: calc(var(--t, 0) * var(--length, 0) * 1px) calc(var(--length, 0) * 1px);
}

.ball {
  pointer-events: none;
}
.ball-body {
  fill: var(--yarn);
}
.ball-strand {
  fill: none;
  stroke: var(--yarn-twist);
  stroke-width: 1.6;
  stroke-linecap: round;
}

/* Tipp: gelbe Fläche unter dem Faden, ein Fehler in Magenta; Form und Text dazu. */
.hint-cell {
  fill: var(--color-hint);
  opacity: 0.55;
}
.hint-vertex {
  fill: none;
  stroke: var(--color-hint);
  stroke-width: 5;
}
.hint-edge {
  stroke: var(--color-hint);
  stroke-width: 14;
  stroke-linecap: round;
  opacity: 0.85;
}
.hint-wrong .hint-edge {
  stroke: var(--color-wrong);
  opacity: 0.5;
}
.hint {
  margin: 0;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-m);
  background: var(--color-hint);
  color: var(--color-on-accent);
  font-weight: 700;
}
.hint[hidden] {
  display: none;
}

.cross {
  stroke: var(--color-wrong);
  stroke-width: 2;
  stroke-linecap: round;
  visibility: hidden;
}
.cross.is-shown {
  visibility: visible;
}
.is-solved .cross {
  visibility: hidden;
}

.dot {
  fill: var(--color-ink);
  transition: r var(--duration-fast) var(--ease-out);
}
.dot.is-bad {
  fill: var(--color-wrong);
  r: 7px;
}

.clue-text {
  font-size: 22px;
  font-family: var(--font-display);
  font-weight: 400;
  fill: var(--color-ink);
  text-anchor: middle;
  dominant-baseline: central;
}
/* Erfüllt: gefüllter Kreis. Zu viele: Ring. Nie nur über die Farbe. */
.clue-badge {
  fill: transparent;
  stroke: transparent;
  stroke-width: 2.5;
}
.clue.is-done .clue-badge {
  fill: var(--yarn-tint);
}
.clue.is-done .clue-text {
  fill: var(--yarn-deep);
}
.clue.is-over .clue-badge {
  stroke: var(--color-wrong);
}
.clue.is-over .clue-text {
  fill: var(--wrong-text);
}
.is-solved .clue .clue-badge {
  fill: transparent;
  stroke: transparent;
}
.is-solved .clue .clue-text {
  fill: var(--color-ink);
}

/* Stift: Zaun oder Kreuz. Gewählt ist, was gefüllt ist (dazu aria-pressed, nicht nur Farbe). */
.tools {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-1);
  margin: 0;
  padding: var(--space-1);
  border: 0;
  background: var(--color-surface);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-raised);
}
.tool {
  font: inherit;
  font-family: var(--font-display);
  font-weight: 400;
  min-height: var(--tap-min);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--color-ink-soft);
  cursor: pointer;
}
.tool svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke-linecap: round;
}
.tool-line {
  stroke: var(--yarn);
  stroke-width: 4;
}
.tool-cross {
  stroke: var(--color-wrong);
  stroke-width: 2.5;
}
.tool[aria-pressed="true"] {
  background: var(--color-primary);
  color: var(--color-ink);
}
.tool:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
}

.report-links {
  display: flex;
  gap: var(--space-5);
}
.share-hint {
  margin: 0;
  font-size: var(--text-s);
  font-weight: 700;
  color: var(--color-on-bg);
}
.share-hint:empty {
  display: none;
}
.report {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
}
.report-text {
  width: 100%;
  min-height: 10rem;
  padding: var(--space-3);
  border: 0;
  border-radius: var(--radius-m);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-ink);
  background: var(--color-surface);
}
.report-text[hidden] {
  display: none;
}

.result-open {
  align-self: stretch;
}
.result {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-2);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}
/* Wie die Stufenknöpfe auf dem Startbildschirm, zwei je Reihe; ein
   einzelner letzter Knopf nimmt die ganze Breite. */
.actions .btn {
  flex: 1 1 40%;
  padding: 0.6rem 0.3rem;
  border-radius: var(--radius-m);
}
