/* =============================================================
   HABIT SECTION
   Bild startet bildschirmfuellend, zoomt beim Scrollen auf die Person
   und schrumpft zur Karte, dann haken sich die Wochentage ab. Die
   Ueberschrift steht von Anfang an auf dem Bild.
   Grundform ohne .habit--live: fertige Karte (ohne JS und bei
   prefers-reduced-motion). Die Klasse setzt das Inline-Skript in der
   Section, damit beim Laden nichts springt.
   ============================================================= */

.habit {
  background: var(--color-surface, #F5F3F2);
}

/* Grundform: fertige Karte */
.habit__frame {
  position: relative;
  width: min(100% - 48px, 1200px);
  aspect-ratio: 16 / 10;
  margin-inline: auto;
  border-radius: var(--radius-card, 28px);
  overflow: hidden;
  background: #2a2019;
}

/* Dunkelt den unteren Bereich ab, damit die weisse Schrift dort lesbar bleibt */
.habit__frame::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, transparent 45%, rgba(20, 12, 8, 0.45) 100%);
  pointer-events: none;
}

.habit__photo {
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  object-fit: cover;
  object-position: 30% 45%;
}

/* ── Ueberschrift und Wochentage ── */
.habit__overlay {
  position: absolute;
  z-index: 1;
  left: 48%;
  right: calc(var(--habit-inset-side, 0px) + 48px);
  /* Mitte der fertigen Karte, die Wochentage sind von Anfang an mitgerechnet */
  top: calc((100% + var(--habit-inset-top, 0px) - var(--habit-inset-bottom, 0px)) / 2);
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Weicher Schleier hinter der Schrift, auf dem Telefon liegt sie auf dem hellen Shirt */
.habit__overlay::before {
  content: '';
  position: absolute;
  z-index: -1;
  inset: -22% -16%;
  background: radial-gradient(closest-side, rgba(20, 12, 8, 0.55), rgba(20, 12, 8, 0.32) 55%, transparent);
  pointer-events: none;
}

.habit__headline {
  color: #ffffff;
  font-size: clamp(1.8rem, 3.5vw, 2.6rem);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.03em;
  text-shadow: 0 1px 14px rgba(0, 0, 0, 0.35);
  text-wrap: balance;
}

.habit__week {
  display: flex;
  gap: 8px;
}

.habit__day {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: clamp(34px, 4.8vw, 68px);
  padding: 14px 0;
  border-radius: 999px;
  color: #ffffff;
  font-size: clamp(0.75rem, 1.35vw, 1.125rem);
  font-weight: 600;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.45);
}

.habit__day--done {
  background: rgba(255, 255, 255, 0.1);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.habit__mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 66%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.28);
}

.habit__day--done .habit__mark {
  background: #ef6c44;
}

.habit__mark svg {
  display: block;
  width: 56%;
  height: 56%;
}

/* ── Scroll-Fassung ── */
.habit--live .habit__stage {
  height: 230vh;
}

.habit--live .habit__pin {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100svh;
}

.habit--live .habit__frame {
  position: absolute;
  inset: 0;
  width: auto;
  aspect-ratio: auto;
  margin: 0;
  border-radius: 0;
  background: none;
  will-change: clip-path;
}

.habit--live .habit__photo {
  position: absolute;
  top: 0;
  left: 0;
  width: auto;
  height: auto;
  transform-origin: 0 0;
  will-change: transform;
}

.habit--live .habit__day {
  opacity: 0;
  will-change: transform, opacity;
}

/* Mobile: Text und Tage in der Mitte der Karte */
@media (max-width: 720px) {
  .habit__frame {
    width: calc(100% - 32px);
    aspect-ratio: 4 / 5;
  }

  .habit__overlay {
    left: calc(var(--habit-inset-side, 0px) + 12px);
    right: calc(var(--habit-inset-side, 0px) + 12px);
    align-items: center;
    gap: 16px;
    text-align: center;
  }

  .habit__week {
    gap: 4px;
  }

  .habit__day {
    width: min(60px, calc((100vw - 32px - 24px - 24px) / 7));
    gap: 6px;
    padding: 9px 0;
    font-size: 0.75rem;
  }

  .habit__mark {
    width: 72%;
  }
}

/* Niedrige Displays: iPhone SE zeigt in Safari nur rund 550 px Hoehe */
@media (max-height: 640px) {
  .habit--live .habit__headline {
    font-size: 1.4rem;
  }

  .habit--live .habit__overlay {
    gap: 10px;
  }

  .habit--live .habit__day {
    padding: 7px 0;
    gap: 4px;
  }
}
