/* Mali, das Pixel-Maskottchen (bunny.js) */

/* Platz am Seitenende: So kann man alles über Mali hinaus hochscrollen und er
   verdeckt am Ende keine Buttons (er sitzt ja fest unten am Bildschirm). */
body {
  padding-bottom: 90px;
}

.mali {
  position: fixed;
  bottom: 14px;
  z-index: 40;
  width: 64px;
  height: 64px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.mali:focus-visible {
  outline: 3px solid #f6a5b9;
  outline-offset: 4px;
  border-radius: 8px;
}

/* Weicher Schatten unter Mali */
.mali::after {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: -3px;
  height: 6px;
  border-radius: 50%;
  background: rgba(28, 27, 26, 0.15);
}

.mali-body {
  width: 100%;
  height: 100%;
  transform-origin: 50% 100%;
}

/* 16×16 Pixel groß gezogen – "pixelated" verhindert Weichzeichnen */
.mali-sprite {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  transition: transform 0.2s;
}

.mali.facing-left .mali-sprite {
  transform: rotate(-6deg);
}

.mali.hopping:not(.facing-left) .mali-sprite {
  transform: rotate(6deg);
}

/* Hoppeln: hoch und runter, beim Landen etwas platt */
.mali.hopping .mali-body {
  animation: mali-hop 0.36s ease-in-out infinite;
}

@keyframes mali-hop {
  0%, 100% { transform: translateY(0) scale(1.08, 0.92); }
  50% { transform: translateY(-14px) scale(0.95, 1.05); }
}

/* Freudensprung */
.mali.jumping .mali-body {
  animation: mali-jump 0.6s ease-out;
}

@keyframes mali-jump {
  0% { transform: translateY(0) scale(1.1, 0.9); }
  40% { transform: translateY(-26px) scale(0.92, 1.1); }
  70% { transform: translateY(0) scale(1.1, 0.9); }
  100% { transform: translateY(0) scale(1, 1); }
}

/* Tanzen */
.mali.dancing .mali-body {
  animation: mali-dance 0.6s ease-in-out infinite;
}

@keyframes mali-dance {
  0%, 100% { transform: rotate(-10deg) translateX(-3px); }
  50% { transform: rotate(10deg) translateX(3px); }
}

/* Herz, z, ♪ – schweben hoch und verschwinden */
.mali-fx {
  position: absolute;
  top: -10px;
  font: 700 18px/1 "Courier New", monospace;
  color: #6b5656;
  pointer-events: none;
  animation: mali-float 1.4s ease-out forwards;
}

.mali-fx canvas {
  width: 21px;
  height: 18px;
  image-rendering: pixelated;
}

@keyframes mali-float {
  0% { transform: translateY(0); opacity: 0; }
  15% { opacity: 1; }
  100% { transform: translateY(-38px); opacity: 0; }
}

/* --- Sprechblase im Pixel-Look ---------------------------------------------------------- */

.mali-bubble {
  position: fixed;
  z-index: 41;
  width: min(300px, calc(100vw - 16px));
  padding: 14px 16px 12px;
  background: #fff;
  color: #2d2326;
  border: 3px solid #2d2326;
  box-shadow: 4px 4px 0 #f6a5b9;   /* harter, versetzter Schatten = Pixel-Look */
  font-size: 0.95rem;
  line-height: 1.4;
}

/* Spitze unten, zeigt auf Mali (Position kommt aus bunny.js: --tail-x) */
.mali-bubble::after {
  content: "";
  position: absolute;
  bottom: -11px;
  left: calc(var(--tail-x, 50%) - 8px);
  width: 14px;
  height: 14px;
  background: #fff;
  border-right: 3px solid #2d2326;
  border-bottom: 3px solid #2d2326;
  transform: rotate(45deg);
}

.mali-bubble p {
  margin: 0 0 8px;
}

.mali-title {
  font: 700 1rem/1.3 "Courier New", monospace;
  color: #c0436b;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.mali-terms {
  font-size: 0.8rem;
  color: #7a6a6a;
}

.mali-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.mali-buttons button,
.mali-return {
  padding: 6px 12px;
  border: 2px solid #2d2326;
  background: #fff;
  color: #2d2326;
  font: 700 0.8rem/1 "Courier New", monospace;
  cursor: pointer;
  box-shadow: 2px 2px 0 #2d2326;
}

.mali-buttons button.primary {
  background: #ffc7d1;
}

.mali-buttons button:active,
.mali-return:active {
  transform: translate(2px, 2px);
  box-shadow: none;
}

.mali-close {
  position: absolute;
  top: 2px;
  right: 6px;
  border: none;
  background: none;
  font-size: 1.2rem;
  line-height: 1;
  color: #7a6a6a;
  cursor: pointer;
}

/* Kleiner Knopf zum Zurückholen */
.mali-return {
  position: fixed;
  left: 12px;
  bottom: 14px;
  z-index: 40;
  font-size: 1rem;
}

/* --- Handy -------------------------------------------------------------------------------- */

/* Am Handy sitzt Mali fest rechts unten auf einem runden Kissen (bunny.js hoppelt dort nicht
   herum) – so verdeckt er keine Buttons und schwebt nicht mitten über der Seite. */
@media (max-width: 640px) {
  .mali {
    width: 46px;
    height: 46px;
    bottom: calc(14px + env(safe-area-inset-bottom));
    transition: bottom 0.3s;
  }

  /* Kissen hinter Mali statt Schatten in der Luft */
  .mali::before {
    content: "";
    position: absolute;
    inset: -7px -7px -5px;
    z-index: -1;
    border-radius: 50%;
    background: rgba(255, 250, 252, 0.94);
    border: 1px solid #f3dbe3;
    box-shadow: 0 6px 18px rgba(45, 35, 38, 0.14);
  }

  .mali::after {
    display: none;
  }

  .mali-return {
    bottom: calc(14px + env(safe-area-inset-bottom));
  }

  /* Startseite: nur über die "Mit Pinterest verbinden"-Leiste, wenn sie gerade zu sehen ist */
  body.landing:has(.mobile-connect:not(.hidden)) .mali,
  body.landing:has(.mobile-connect:not(.hidden)) .mali-return {
    bottom: calc(86px + env(safe-area-inset-bottom));
  }

  body.landing {
    padding-bottom: 160px;   /* Leiste + Mali */
  }
}

/* --- Begrüßung beim allerersten Besuch (bunny.js: welcome) ------------------------------- */

/* Scrollen sperren, solange die Begrüßung läuft */
html.splash-open {
  overflow: hidden;
}

/* Kleiner Mali wartet unsichtbar, bis der große an seinen Platz geflogen ist */
.mali.waiting {
  opacity: 0;
  pointer-events: none;
}

.mali-splash {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

/* Rosa Hintergrund als eigene Ebene – so kann er ausblenden, während Mali sichtbar bleibt */
.mali-splash::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 42%, #ffffff 0%, #fde4ec 55%, #f7c8d8 100%);
  transition: opacity 0.7s ease;
}

.splash-stage {
  position: relative;
  max-width: 640px;
  padding: 0 20px;
  text-align: center;
}

/* Großer Pixel-Mali: hüpft von unten herein und wippt dann sanft */
.splash-sprite {
  width: min(42vw, 176px);
  height: min(42vw, 176px);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  animation:
    splash-in 0.8s cubic-bezier(0.3, 1.4, 0.5, 1) both,
    splash-bob 1.8s ease-in-out 0.8s infinite;
}

@keyframes splash-in {
  0% { transform: translateY(70vh) scale(0.6); }
  60% { transform: translateY(-18px) scale(1.06, 0.94); }
  100% { transform: none; }
}

@keyframes splash-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.splash-name {
  margin: 14px 0 6px;
  font: 700 1rem/1 "Courier New", monospace;
  letter-spacing: 0.35em;
  color: var(--accent, #c93a69);
}

.splash-text {
  min-height: 3.9em;          /* Platz für drei Zeilen – nichts springt beim Tippen */
  margin: 0;
  font-family: var(--serif, Georgia, serif);
  font-size: clamp(1.35rem, 3.6vw, 2rem);
  line-height: 1.3;
  color: var(--text, #3a2a30);
}

.splash-heart {
  position: absolute;
  top: 0;
  width: 28px;
  height: 24px;
  image-rendering: pixelated;
  animation: mali-float 1.6s ease-out both;
}

.splash-skip {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 28px;
  margin: 0;
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted, #7a606a);
}

/* Abgang: Hintergrund und Texte blenden aus, Mali fliegt (bunny.js) */
.mali-splash.leaving::before,
.mali-splash.leaving .splash-name,
.mali-splash.leaving .splash-text,
.mali-splash.leaving .splash-skip {
  opacity: 0;
  transition: opacity 0.6s ease;
}

.mali-splash.leaving .splash-sprite {
  animation: none;            /* Wippen stoppen, damit der Flug sauber startet */
}

/* Nur für Screenreader sichtbar */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  .splash-sprite {
    animation: none;
  }
}

/* --- Vibe-Karte zum Teilen (vibecard.js) --- */
.vibecard-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(58, 42, 48, 0.55);
  backdrop-filter: blur(4px);
}

.vibecard-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  max-height: 100%;
}

.vibecard-image {
  /* Story-Format 9:16 – passt immer auf den Bildschirm */
  height: min(72vh, calc((100vw - 32px) * 16 / 9));
  aspect-ratio: 9 / 16;
  border-radius: 18px;
  box-shadow: 0 18px 50px rgba(58, 42, 48, 0.35);
}

.vibecard-actions {
  display: flex;
  gap: 10px;
}

/* --- Mali arbeitet: Analyse-Ansicht (analysis.js) --- */
.analysis {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 900;
  width: min(380px, calc(100vw - 32px));
  padding: 22px 22px 18px;
  border-radius: 24px;
  background: #fff;
  box-shadow: 0 18px 50px rgba(58, 42, 48, 0.22);
  border: 1px solid #f3dbe3;
  animation: analysis-in 0.35s ease-out;
}

@keyframes analysis-in {
  from { opacity: 0; transform: translateY(16px); }
}

.analysis-minimize {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: #fbe3ea;
  color: #a52a57;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}

.analysis-title {
  margin: 0 36px 14px 0;
  font-family: var(--serif);
  font-size: 1.35rem;
}

.analysis-stage {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  min-height: 96px;
}

.analysis-sprite {
  width: 80px;
  height: 80px;
  flex: none;
  image-rendering: pixelated;
}

/* Sprechblase mit Spitze nach links zu Mali */
.analysis-bubble {
  position: relative;
  flex: 1;
  margin: 0 0 18px;
  padding: 12px 14px;
  border-radius: 16px;
  background: #fff4f7;
  border: 1px solid #f3dbe3;
  font-size: 0.95rem;
  line-height: 1.4;
}

.analysis-bubble::before {
  content: "";
  position: absolute;
  left: -8px;
  bottom: 14px;
  width: 14px;
  height: 14px;
  background: #fff4f7;
  border-left: 1px solid #f3dbe3;
  border-bottom: 1px solid #f3dbe3;
  transform: rotate(45deg);
}

.analysis-bubble.pop {
  animation: analysis-pop 0.3s ease-out;
}

@keyframes analysis-pop {
  from { opacity: 0; transform: translateY(4px); }
}

.analysis-bar {
  height: 10px;
  margin-top: 12px;
  border-radius: 999px;
  background: #fbe3ea;
  overflow: hidden;
}

.analysis-bar span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #f08fac, var(--accent));
  transition: width 0.6s ease;
}

.analysis-count {
  min-height: 1.2em;
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: right;
}

.analysis-steps {
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.92rem;
  color: var(--muted);
}

.analysis-steps li {
  padding: 3px 0 3px 26px;
  position: relative;
}

.analysis-steps li::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 50%;
  width: 10px;
  height: 10px;
  margin-top: -5px;
  border-radius: 50%;
  border: 2px solid #f3c6d3;
}

.analysis-steps li.active {
  color: var(--text);
  font-weight: 600;
}

.analysis-steps li.active::before {
  border-color: var(--accent);
  animation: analysis-pulse 1s ease-in-out infinite;
}

.analysis-steps li.done {
  color: var(--text);
}

.analysis-steps li.done::before {
  content: "✓";
  width: auto;
  height: auto;
  margin-top: -0.65em;
  border: none;
  color: var(--accent);
  font-weight: 700;
}

@keyframes analysis-pulse {
  50% { transform: scale(1.35); }
}

.analysis-found {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.analysis-found:empty,
.analysis-actions:empty {
  display: none;
}

.analysis-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

/* Verkleinert: kleiner Knopf unten links */
.analysis-pill {
  position: fixed;
  left: 16px;
  bottom: 16px;
  z-index: 900;
  padding: 10px 16px;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(201, 58, 105, 0.35);
  cursor: pointer;
}

/* Solange die Ansicht offen ist, sitzt Mali dort – der kleine Mali unten macht Pause */
body.analysis-open .mali,
body.analysis-open .mali-bubble,
body.photo-open .mali,
body.photo-open .mali-bubble {
  visibility: hidden;
}

@media (max-width: 600px) {
  .analysis {
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    border-radius: 24px 24px 0 0;
    padding-bottom: calc(18px + env(safe-area-inset-bottom));
  }
}

@media (prefers-reduced-motion: reduce) {
  .analysis,
  .analysis-bubble.pop,
  .analysis-steps li.active::before {
    animation: none;
  }
}
