/* Stempelapp - Einstiegsseite
 *
 * Richtung "Karte im Mittelpunkt": grosse, enge Systemschrift auf warmem
 * Grauweiss wie auf apple.com/wallet, die Stempelkarte als Hauptdarsteller,
 * die sich neigt und wie Folie glaenzt (nach der Holo-Karte von Konstantin
 * Denerz, codepen.io/konstantindenerz/full/XWPpvpg).
 *
 * Die Systemschrift ist auf dem iPhone SF Pro, auf Android Roboto. Sie kostet
 * keinen Ladevorgang, und an der Theke zaehlt jede Sekunde.
 */

:root {
  --grund: #ece8e1;
  --grund-tief: #e2ddd4;
  --text: #1d1b19;
  --leise: #6e675f;
  --akzent: #2e7d5b;
  --fehler: #b3261e;

  /* Farben der Karte. Spaeter je Cafe, bis dahin Kaffee. */
  --karte-1: #7a5236;
  --karte-2: #2a1a10;
  --karte-text: #fbf5ee;

  /* Federkurve, erzeugt wie bei Jake Archibald (linear-easing-generator).
     Schwingt einmal leicht ueber und kommt dann zur Ruhe. */
  --feder: linear(0, 0.006, 0.025 2.8%, 0.101 6.1%, 0.539 18.9%, 0.721 25.3%,
    0.849 31.5%, 0.937 38.1%, 0.968 41.8%, 0.991 45.7%, 1.006 50.1%, 1.015 55%,
    1.017 63.9%, 1.001 85.5%, 1);
  --sanft: cubic-bezier(0.22, 1, 0.36, 1);

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --grund: #141210;
    --grund-tief: #1d1a17;
    --text: #f4efe9;
    --leise: #a39a91;
    --akzent: #6fcf9f;
    --fehler: #f2b8b5;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(120% 60% at 50% 0%, var(--grund) 40%, var(--grund-tief) 100%) fixed,
    var(--grund);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

main {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  /* Platz fuer die Links zu Impressum und Datenschutz darunter. */
  min-height: calc(100dvh - 44px);
  padding: max(20px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
  display: flex;
}

.zustand {
  width: 100%;
  display: flex;
  flex-direction: column;
}

.zustand[hidden] { display: none; }

.zustand.mitte {
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 4px;
}

/* ---------------------------------------------------------------- Laden */

#laden { justify-content: center; align-items: center; }

.lader {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2.5px solid color-mix(in srgb, var(--text) 15%, transparent);
  border-top-color: var(--text);
  animation: drehen 0.8s linear infinite;
}

@keyframes drehen { to { transform: rotate(1turn); } }

/* ---------------------------------------------------------------- Kopf */

.titel {
  margin: 12px 0 0;
  font-size: clamp(40px, 11.5vw, 64px);
  line-height: 0.98;
  font-weight: 700;
  letter-spacing: -0.045em;
}

.titel.klein {
  margin-top: 20px;
  font-size: clamp(34px, 9vw, 48px);
}

.titel .zeile { display: block; }

.titel .zeile:nth-child(2) { color: var(--leise); }

.unterzeile {
  margin: 14px 0 0;
  font-size: 17px;
  line-height: 1.45;
  color: var(--leise);
  letter-spacing: -0.01em;
  max-width: 34ch;
}

.unterzeile strong { color: var(--text); font-weight: 600; }

/* ---------------------------------------------------------------- Buehne */

.buehne {
  position: relative;
  flex: 1;
  min-height: 250px;
  display: grid;
  place-items: center;
  margin: 12px -20px 0;
  perspective: 1100px;
  touch-action: pan-y;
}

.buehne canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* ---------------------------------------------------------------- Karte (leicht) */

.karte {
  --rx: 0deg;
  --ry: 0deg;
  --mx: 50%;
  --my: 50%;
  --glanz: 0;

  position: relative;
  width: min(84vw, 380px);
  aspect-ratio: 1.586;
  border-radius: 22px;
  color: var(--karte-text);
  transform-style: preserve-3d;
  transform: rotateX(var(--rx)) rotateY(var(--ry));
  will-change: transform;
}

.karte.ruht { animation: schweben 6s ease-in-out infinite; }

@keyframes schweben {
  0%, 100% { transform: rotateX(4deg) rotateY(-7deg) translateY(0); }
  50% { transform: rotateX(-3deg) rotateY(6deg) translateY(-6px); }
}

.karte-flaeche {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  overflow: hidden;
  background:
    radial-gradient(140% 90% at 15% 0%, color-mix(in srgb, var(--karte-1) 70%, white) 0%, transparent 55%),
    linear-gradient(155deg, var(--karte-1), var(--karte-2));
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 0.25),
    inset 0 0 0 1px rgb(255 255 255 / 0.08),
    0 1px 1px rgb(0 0 0 / 0.08),
    0 12px 24px -8px rgb(40 20 5 / 0.35),
    0 40px 60px -20px rgb(40 20 5 / 0.45);
}

/* Feines Korn, damit die Flaeche nach Material aussieht statt nach Verlauf. */
.karte-flaeche::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.18;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='k'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23k)'/></svg>");
}

/* Folie: Regenbogenbaender, die mit dem Blickwinkel wandern. */
.karte-folie {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  mix-blend-mode: color-dodge;
  opacity: calc(0.12 + var(--glanz) * 0.35);
  background:
    repeating-linear-gradient(115deg,
      #ff8a8a 0%, #ffd27a 6%, #9dffb0 12%, #7ad8ff 18%, #c39bff 24%, #ff8a8a 30%);
  background-size: 300% 300%;
  background-position: var(--mx) var(--my);
  transition: opacity 0.4s var(--sanft);
}

/* Lichtfleck, der dem Finger folgt. */
.karte-licht {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  opacity: var(--glanz);
  background: radial-gradient(circle at var(--mx) var(--my), rgb(255 255 255 / 0.35), transparent 45%);
  mix-blend-mode: soft-light;
  transition: opacity 0.4s var(--sanft);
}

.karte-inhalt {
  position: absolute;
  inset: 0;
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  transform: translateZ(30px);
}

.karte-kopf {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.karte-name {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 650;
  font-size: 17px;
  letter-spacing: -0.02em;
}

.karte-logo {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 700;
  background: rgb(255 255 255 / 0.16);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.3);
  backdrop-filter: blur(6px);
  overflow: hidden;
}

.karte-logo img { width: 100%; height: 100%; object-fit: cover; }

.karte-art {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  opacity: 0.7;
}

.stempel {
  margin-top: auto;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  width: 62%;
  gap: 9px;
}

.stempelfeld {
  aspect-ratio: 1;
  border-radius: 50%;
  /* Eingepraegt: Schatten innen oben, Licht innen unten. */
  background: rgb(0 0 0 / 0.16);
  box-shadow:
    inset 0 2px 3px rgb(0 0 0 / 0.35),
    inset 0 -1px 0 rgb(255 255 255 / 0.12);
  display: grid;
  place-items: center;
}

.stempelfeld.voll {
  background: var(--karte-text);
  color: var(--karte-2);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.3);
}

.stempelfeld svg { width: 58%; height: 58%; }

/* Das Feld fuer den ersten Stempel pulsiert leise. */
.stempelfeld.naechstes {
  box-shadow:
    inset 0 2px 3px rgb(0 0 0 / 0.35),
    0 0 0 0 rgb(255 255 255 / 0.5);
  animation: pochen 2.4s var(--sanft) infinite;
}

@keyframes pochen {
  0% { box-shadow: inset 0 0 0 2px rgb(255 255 255 / 0.75), inset 0 2px 3px rgb(0 0 0 / 0.35), 0 0 0 0 rgb(255 255 255 / 0.45); }
  70%, 100% { box-shadow: inset 0 0 0 2px rgb(255 255 255 / 0.75), inset 0 2px 3px rgb(0 0 0 / 0.35), 0 0 0 8px rgb(255 255 255 / 0); }
}

.karte-fuss {
  margin-top: 12px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 12.5px;
  letter-spacing: -0.005em;
}

.karte-fuss span:first-child { opacity: 0.75; }
.karte-fuss span:last-child { font-weight: 600; }

/* ---------------------------------------------------------------- Knoepfe */

/* Die offiziellen Badges von Apple und Google. Sie duerfen nicht veraendert
   werden, deshalb traegt der Knopf nur das Bild und bewegt sich als Ganzes. */
.badge {
  appearance: none;
  border: 0;
  background: none;
  padding: 0;
  margin: 0 auto;
  display: block;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.5s var(--feder), opacity 0.3s;
}

.badge { max-width: 100%; }

/* Beide gleich breit. Die Seitenverhaeltnisse von Apple und Google
   unterscheiden sich leicht, gestaucht werden darf keiner. */
.badge img { display: block; width: 190px; height: auto; }

.badge:active { transform: scale(0.96); transition-duration: 0.1s; }

.badge:disabled { opacity: 0.55; cursor: default; }

.badge[hidden] { display: none; }

.badge:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--akzent) 60%, transparent);
  outline-offset: 4px;
  border-radius: 14px;
}

.aktion {
  display: grid;
  gap: 10px;
  margin-top: 8px;
}

.verweis:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--akzent) 60%, transparent);
  outline-offset: 3px;
}

.kleingedruckt {
  margin: 4px 0 0;
  text-align: center;
  font-size: 13px;
  color: var(--leise);
}

.verweis {
  appearance: none;
  border: 0;
  background: none;
  padding: 8px;
  margin-top: 18px;
  color: var(--leise);
  font: inherit;
  font-size: 15px;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.fehler {
  margin: 4px 0 0;
  text-align: center;
  color: var(--fehler);
  font-size: 15px;
}

#captcha:empty { display: none; }

/* ---------------------------------------------------------------- Haken */

.haken {
  width: 76px;
  height: 76px;
  fill: none;
  stroke: var(--akzent);
  stroke-width: 3.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.haken circle { stroke-dasharray: 183; stroke-dashoffset: 183; }
.haken path { stroke-dasharray: 40; stroke-dashoffset: 40; }

#fertig:not([hidden]) .haken circle { animation: zeichnen 0.7s var(--sanft) forwards; }
#fertig:not([hidden]) .haken path { animation: zeichnen 0.45s 0.45s var(--sanft) forwards; }

@keyframes zeichnen { to { stroke-dashoffset: 0; } }

/* ---------------------------------------------------------------- Auftritt */

.auftritt > * {
  opacity: 0;
  transform: translateY(14px);
  animation: auftauchen 0.9s var(--sanft) forwards;
}

.auftritt > *:nth-child(2) { animation-delay: 0.06s; }
.auftritt > *:nth-child(3) { animation-delay: 0.12s; }
.auftritt > *:nth-child(4) { animation-delay: 0.18s; }
.auftritt > *:nth-child(5) { animation-delay: 0.26s; }

@keyframes auftauchen { to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .karte.ruht { animation: none; }
}

@media (min-width: 700px) {
  main { padding-top: 56px; }
}

/* Zurueck in die Ruhe federt die Karte, waehrend sie dem Finger folgt nicht. */
.karte:not(.ruht):not(.folgt) { transition: transform 0.9s var(--feder); }

/* Vorschau ohne Supabase: deutlich sagen, dass hier nichts passiert. */
body.vorschau::after {
  content: "Vorschau. Es wird kein Pass angelegt.";
  position: fixed;
  left: 50%;
  top: max(10px, env(safe-area-inset-top));
  transform: translateX(-50%);
  padding: 6px 12px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--text) 10%, transparent);
  color: var(--leise);
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
}

body.vorschau main { padding-top: max(52px, calc(env(safe-area-inset-top) + 42px)); }

/* ---------------------------------------------------------------- Rechtliches */

.recht-links {
  display: flex;
  justify-content: center;
  gap: 20px;
  font-size: 13px;
}

.recht-links a {
  color: var(--leise);
  text-decoration: none;
}

.recht-links a:hover { text-decoration: underline; text-underline-offset: 3px; }

.seite-fuss { height: 44px; align-items: flex-start; }

main.rechtstext {
  display: block;
  min-height: 0;
  padding-bottom: 48px;
  font-size: 16px;
  line-height: 1.6;
}

.rechtstext h2 {
  margin: 32px 0 6px;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.rechtstext p { margin: 0 0 12px; max-width: 62ch; }

.rechtstext p.leise { color: var(--leise); }

.rechtstext p.klein { font-size: 14px; margin-top: 28px; }

.rechtstext a { color: var(--text); text-underline-offset: 3px; }

.rechtstext .zurueck {
  display: inline-block;
  margin-top: 4px;
  color: var(--leise);
  font-size: 15px;
  text-decoration: none;
}

.rechtstext .zurueck::before { content: "\2039\00a0"; }

.rechtstext .recht-links { justify-content: flex-start; margin-top: 36px; }
