/* =============================================================================
 *  Psychoedukative Impulse — Stylesheet
 *  ---------------------------------------------------------------------------
 *  Verbindlich: styleguide.html (Maryna Herz · Psychologische Begleitung)
 *  Akzentfarbe: Blau (#5F7D8C) — wie vom Nutzer vorgegeben
 *
 *  Design-Prinzipien aus dem Styleguide, die hier konkret umgesetzt sind:
 *    – Sand (#E9E3D8) als Kartenhintergrund, KEINE Schatten
 *    – Cormorant Garamond für Überschriften, Inter für Fließtext und UI
 *    – Container max. 960px Content-Breite
 *    – 8px-Spacing-Skala
 *    – Reduktion statt Reiz: dezente Übergänge, keine Bewegung um der Bewegung willen
 *    – prefers-reduced-motion vollständig respektiert (Flip → Accordion)
 *
 *  Diese Datei nutzt eigene CSS-Variablen mit Fallback auf die globalen
 *  Variablen des Child Themes (style.css :root). Falls jene Variablen aus
 *  irgendeinem Grund nicht greifen, funktioniert das Modul trotzdem.
 * ============================================================================= */

.herz-impulse {
  /* Lokale Aliase mit Fallback auf globale Tokens des Child Themes */
  --hi-bg:           var(--color-bg,           #F4F2EE);
  --hi-sand:         var(--color-sand,         #E9E3D8);
  --hi-border:       var(--color-border,       #CFC9BE);
  --hi-text-muted:   var(--color-text-muted,   #5E5A55);
  --hi-text:         var(--color-text,         #3F3C38);
  --hi-accent:       var(--color-accent-blue,  #5F7D8C);
  --hi-accent-hover: var(--color-accent-blue-hover, #4E6976);
  --hi-accent-focus: var(--color-accent-blue-focus, #8FA6B1);

  --hi-font-serif:   var(--font-serif, "Cormorant Garamond", Georgia, serif);
  --hi-font-sans:    var(--font-sans,  "Inter", system-ui, sans-serif);

  --hi-radius-card:  12px;
  --hi-radius-pill:  999px;
  --hi-radius-input: 6px;

  --hi-shadow-focus: 0 0 0 2px var(--hi-bg), 0 0 0 4px var(--hi-accent-focus);

  /* Container-Breite: editorial, nicht überdimensioniert */
  max-width: 960px;
  margin: 0 auto;
  padding: 0 1.25rem;

  color: var(--hi-text);
  font-family: var(--hi-font-sans);
  font-size: 18px;
  line-height: 1.65;
}

/* -------------------------------------------------------------------------- */
/*  Intro                                                                     */
/* -------------------------------------------------------------------------- */

.herz-impulse__intro {
  text-align: left;
  margin-bottom: 2.5rem;
}

.herz-impulse__eyebrow {
  display: inline-block;
  font-family: var(--hi-font-sans);
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--hi-accent);
  margin-bottom: 0.75rem;
}

.herz-impulse__title {
  font-family: var(--hi-font-serif);
  font-size: 28px;
  font-weight: 300;
  line-height: 1.3;
  letter-spacing: -0.01em;
  color: var(--hi-text);
  margin: 0 0 1rem 0;
}

.herz-impulse__lede {
  font-size: 18px;
  line-height: 1.65;
  color: var(--hi-text-muted);
  max-width: 65ch;
  margin: 0;
}

/* -------------------------------------------------------------------------- */
/*  Toolbar (Suche)                                                           */
/* -------------------------------------------------------------------------- */

.herz-impulse__toolbar {
  margin-bottom: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.herz-impulse__search {
  width: 100%;
  max-width: 420px;
  padding: 0.75rem 1rem;
  font-family: var(--hi-font-sans);
  font-size: 16px;
  color: var(--hi-text);
  background: var(--hi-bg);
  border: 1px solid var(--hi-border);
  border-radius: var(--hi-radius-input);
  transition: border-color 0.2s ease;
  -webkit-appearance: none;
  appearance: none;
}

.herz-impulse__search:focus {
  outline: none;
  border-color: var(--hi-accent);
  box-shadow: var(--hi-shadow-focus);
}

.herz-impulse__search::placeholder {
  color: var(--hi-text-muted);
  opacity: 0.75;
}

.herz-impulse__status {
  margin: 0;
  font-size: 14px;
  color: var(--hi-text-muted);
  min-height: 1.25em;
}

/* Screen-Reader-only Helper */
.herz-impulse .screen-reader-text {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* -------------------------------------------------------------------------- */
/*  A–Z Letterbar                                                             */
/* -------------------------------------------------------------------------- */

.herz-impulse__letterbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.5rem;
  padding: 1rem 0;
  margin-bottom: 2.5rem;
  border-top: 1px solid var(--hi-border);
  border-bottom: 1px solid var(--hi-border);
}

.herz-impulse__letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  min-height: 32px;
  padding: 0.25rem 0.5rem;
  font-family: var(--hi-font-sans);
  font-size: 14px;
  font-weight: 400;
  color: var(--hi-accent);
  text-decoration: none;
  border-radius: var(--hi-radius-input);
  transition: background 0.2s ease, color 0.2s ease;
}

.herz-impulse__letter:hover,
.herz-impulse__letter:focus-visible {
  background: var(--hi-sand);
  color: var(--hi-accent-hover);
  outline: none;
}

.herz-impulse__letter:focus-visible {
  box-shadow: var(--hi-shadow-focus);
}

.herz-impulse__letter.is-empty {
  color: var(--hi-border);
  cursor: default;
}

/* -------------------------------------------------------------------------- */
/*  Buchstaben-Gruppen                                                        */
/* -------------------------------------------------------------------------- */

.herz-impulse__letter-group {
  margin-bottom: 3rem;
  scroll-margin-top: 100px; /* Sticky-Header beim Sprung berücksichtigen */
}

.herz-impulse__letter-group:last-child {
  margin-bottom: 0;
}

.herz-impulse__letter-heading {
  font-family: var(--hi-font-serif);
  font-size: 32px;
  font-weight: 300;
  line-height: 1;
  color: var(--hi-accent);
  margin: 0 0 1.5rem 0;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--hi-border);
  letter-spacing: 0.02em;
}

/* -------------------------------------------------------------------------- */
/*  Karten-Grid                                                               */
/* -------------------------------------------------------------------------- */

.herz-impulse__grid {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 1.5rem;
  grid-template-columns: 1fr;            /* Mobile: 1 Spalte */
}

@media (min-width: 640px) {
  .herz-impulse__grid {
    grid-template-columns: repeat(2, 1fr); /* Tablet: 2 Spalten */
  }
}

@media (min-width: 1024px) {
  .herz-impulse__grid {
    grid-template-columns: repeat(3, 1fr); /* Desktop: 3 Spalten */
  }
}

.herz-impulse__item {
  margin: 0;
  padding: 0;
  list-style: none;
  /* Perspective auf den Wrapper, damit die 3D-Drehung sauber wirkt */
  perspective: 1200px;
}

/* -------------------------------------------------------------------------- */
/*  Karte                                                                     */
/* -------------------------------------------------------------------------- */

.herz-card {
  position: relative;
  height: 100%;
  /* Feste Mindesthöhe stabilisiert das Grid, falls Texte unterschiedlich lang sind */
  min-height: 320px;
}

.herz-card__inner {
  /* Button als Karten-Wrapper → automatisch fokussierbar, tastaturzugänglich */
  all: unset; /* Reset des Button-Styling */
  display: block;
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 320px;
  cursor: pointer;
  text-align: left;
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: var(--hi-radius-card);
}

.herz-card__inner:focus-visible {
  outline: none;
  box-shadow: var(--hi-shadow-focus);
}

/* Flip-Trigger: Hover auf Desktop + .is-flipped (JS toggelt das auf Tap/Tastatur) */
@media (hover: hover) and (pointer: fine) {
  .herz-card:hover .herz-card__inner:not(.is-disabled) {
    transform: rotateY(180deg);
  }
}

.herz-card__inner.is-flipped {
  transform: rotateY(180deg);
}

/* -------------------------------------------------------------------------- */
/*  Karten-Seiten (Vorder- und Rückseite)                                     */
/* -------------------------------------------------------------------------- */

.herz-card__face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: 1.75rem 1.5rem;
  background: var(--hi-sand);
  border: 1px solid var(--hi-border);
  border-radius: var(--hi-radius-card);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  /* KEINE Schatten — gemäß Styleguide */
  overflow: hidden;
}

.herz-card__face--front {
  z-index: 2;
}

.herz-card__face--back {
  transform: rotateY(180deg);
  background: var(--hi-bg);
  border-color: var(--hi-accent);
  /* Rückseite scrollbar, falls Text mal länger ist */
  overflow-y: auto;
  /* Sanftes Anzeigen des Scroll-Indikators nur wenn nötig */
  scrollbar-width: thin;
  scrollbar-color: var(--hi-border) transparent;
}

.herz-card__face--back::-webkit-scrollbar { width: 6px; }
.herz-card__face--back::-webkit-scrollbar-track { background: transparent; }
.herz-card__face--back::-webkit-scrollbar-thumb {
  background: var(--hi-border);
  border-radius: 3px;
}

/* -------------------------------------------------------------------------- */
/*  Vorderseiten-Inhalt                                                       */
/* -------------------------------------------------------------------------- */

.herz-card__eyebrow {
  font-family: var(--hi-font-sans);
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--hi-accent);
  margin-bottom: 0.75rem;
}

.herz-card__title {
  font-family: var(--hi-font-serif);
  font-size: 22px;
  font-weight: 400;
  line-height: 1.25;
  color: var(--hi-text);
  margin: 0 0 0.75rem 0;
  /* Letter-spacing wie Styleguide für ruhige Wirkung */
  letter-spacing: -0.005em;
}

.herz-card__teaser {
  font-size: 16px;
  line-height: 1.6;
  color: var(--hi-text-muted);
  margin: 0;
  /* Teaser darf nicht zu lang werden, aber wir clipen sanft */
  flex-grow: 1;
}

.herz-card__hint {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  margin-top: 1.25rem;
  font-family: var(--hi-font-sans);
  font-size: 14px;
  font-weight: 400;
  color: var(--hi-accent);
  letter-spacing: 0.02em;
}

.herz-card__hint--back {
  color: var(--hi-text-muted);
}

/* -------------------------------------------------------------------------- */
/*  Rückseiten-Inhalt                                                         */
/* -------------------------------------------------------------------------- */

.herz-card__source {
  display: block;
  font-family: var(--hi-font-sans);
  font-size: 12px;
  letter-spacing: 0.05em;
  color: var(--hi-text-muted);
  margin-bottom: 0.75rem;
}

.herz-card__source em {
  font-style: italic;
  color: var(--hi-text);
}

.herz-card__body {
  font-size: 15px;
  line-height: 1.6;
  color: var(--hi-text);
  margin: 0 0 1rem 0;
}

.herz-card__example {
  font-size: 14px;
  line-height: 1.55;
  color: var(--hi-text-muted);
  margin: 0;
  padding-left: 0.75rem;
  border-left: 2px solid var(--hi-border);
}

.herz-card__example em {
  font-style: italic;
}

.herz-card__example-label {
  display: inline-block;
  font-family: var(--hi-font-sans);
  font-weight: 600;
  font-style: normal;
  color: var(--hi-text);
  margin-right: 0.25em;
}

/* -------------------------------------------------------------------------- */
/*  Leerzustand bei Suche                                                     */
/* -------------------------------------------------------------------------- */

.herz-impulse__empty {
  font-family: var(--hi-font-serif);
  font-style: italic;
  font-size: 18px;
  color: var(--hi-text-muted);
  text-align: center;
  padding: 3rem 1rem;
  margin: 0;
}

/* Buchstaben-Gruppe, in der KEIN Treffer mehr sichtbar ist, wird ausgeblendet
   (Klasse wird vom JS gesetzt) */
.herz-impulse__letter-group.is-empty {
  display: none;
}

.herz-impulse__item.is-hidden {
  display: none;
}

/* -------------------------------------------------------------------------- */
/*  Touch-Geräte: kein 3D-Flip, sondern Accordion                             */
/* -------------------------------------------------------------------------- */
/*  Auf Touch-Geräten ist das Scrollen INNERHALB einer mit rotateY(180deg)
    transformierten Karte (Kombination aus 3D-Transform und
    backface-visibility:hidden) unzuverlässig — insbesondere iOS Safari kann
    Touch-Gesten nicht sauber an einen Overflow-Container innerhalb eines
    transformierten Elements delegieren, sodass längere Rückseitentexte
    abgeschnitten wirken.
    Lösung: Auf Geräten ohne präzisen Hover-Zeiger wird der Flip ausgeschaltet,
    die Rückseite klappt unterhalb der Vorderseite auf, die Karte wächst mit
    ihrem Inhalt. Die Seitenscroll-Bewegung erledigt der Browser nativ.
    Desktop-Verhalten (Hover-Flip) bleibt unverändert. */

@media (hover: none), (pointer: coarse) {
  .herz-card,
  .herz-card__inner {
    min-height: 0;
    height: auto;
  }

  .herz-card__inner {
    transform: none !important;
    transition: none;
  }

  .herz-card__face {
    position: static;
    transform: none !important;
    backface-visibility: visible;
    -webkit-backface-visibility: visible;
    /* Wichtig: overflow von hidden auf visible, sonst clipt die Karte
       die ausgeklappte Rückseite */
    overflow: visible;
  }

  .herz-card__face--front {
    border-radius: var(--hi-radius-card) var(--hi-radius-card) 0 0;
  }

  .herz-card__face--back {
    display: none;
    border-top: none;
    border-radius: 0 0 var(--hi-radius-card) var(--hi-radius-card);
    margin-top: -1px; /* Doppelter Rand entfällt */
    /* Internes Scrollen nicht mehr nötig, da Karte natürlich wächst */
    overflow-y: visible;
  }

  /* JS toggelt .is-flipped auf .herz-card__inner — wir nutzen das, um die
     Rückseite anzuzeigen. Der Flip-Transform selbst wird oben neutralisiert. */
  .herz-card__inner.is-flipped .herz-card__face--front {
    border-bottom: none;
    border-radius: var(--hi-radius-card) var(--hi-radius-card) 0 0;
  }

  .herz-card__inner.is-flipped .herz-card__face--back {
    display: flex;
  }
}

/* -------------------------------------------------------------------------- */
/*  Accessibility: reduced motion                                             */
/* -------------------------------------------------------------------------- */
/*  Wer Bewegung reduziert haben möchte, bekommt KEINEN Flip — stattdessen
    wird die Rückseite unterhalb der Vorderseite als ruhige Aufklapp-Variante
    angezeigt. Das JS setzt dafür `data-reduced-motion="1"` an .herz-impulse. */

.herz-impulse[data-reduced-motion="1"] .herz-card,
.herz-impulse[data-reduced-motion="1"] .herz-card__inner {
  min-height: 0;
  height: auto;
}

.herz-impulse[data-reduced-motion="1"] .herz-card__inner {
  transform: none !important;
  transition: none;
}

.herz-impulse[data-reduced-motion="1"] .herz-card__face {
  position: static;
  transform: none !important;
  backface-visibility: visible;
  -webkit-backface-visibility: visible;
}

.herz-impulse[data-reduced-motion="1"] .herz-card__face--back {
  display: none;
  border-top: none;
  border-radius: 0 0 var(--hi-radius-card) var(--hi-radius-card);
  margin-top: -1px; /* Doppelter Rand entfällt */
}

.herz-impulse[data-reduced-motion="1"] .herz-card__face--front {
  border-radius: var(--hi-radius-card) var(--hi-radius-card) 0 0;
}

.herz-impulse[data-reduced-motion="1"] .herz-card.is-open .herz-card__face--front {
  border-radius: var(--hi-radius-card) var(--hi-radius-card) 0 0;
  border-bottom: none;
}

.herz-impulse[data-reduced-motion="1"] .herz-card.is-open .herz-card__face--back {
  display: flex;
}

/* Fallback für Browser, die `data-reduced-motion`-Attribut nicht über JS bekommen:
   prefers-reduced-motion auch in CSS respektieren */
@media (prefers-reduced-motion: reduce) {
  .herz-card__inner {
    transition: none;
  }
  .herz-card:hover .herz-card__inner {
    transform: none;
  }
  .herz-card__inner.is-flipped {
    transform: none;
  }
}

/* -------------------------------------------------------------------------- */
/*  Print                                                                      */
/* -------------------------------------------------------------------------- */
/*  Druckansicht zeigt alle Inhalte (Vorder- + Rückseite) untereinander
    in ruhiger Typografie — ohne Flip-Mechanik. */

@media print {
  .herz-impulse__toolbar,
  .herz-impulse__letterbar {
    display: none;
  }
  .herz-card,
  .herz-card__inner {
    height: auto;
    min-height: 0;
    transform: none !important;
  }
  .herz-card__face {
    position: static;
    transform: none !important;
    backface-visibility: visible;
    border: 1px solid #999;
    background: #fff;
    page-break-inside: avoid;
    margin-bottom: 0.5rem;
  }
}