/* ─────────────────────────────────────────────────────────────
   ARA – Aphasie Kommunikation · Eigenständige WebApp
   Responsive Stylesheet (Mobile → Tablet → Desktop)
   Farbwelt 1:1 aus der App (src/theme/colors.ts)
   ───────────────────────────────────────────────────────────── */
:root {
  --bg: #f7f8f9;
  --bg2: #ffffff;
  --ink: #0f1012;
  --muted: #6b7280;
  --rule: #e5e7eb;
  --accent: #435693;
  --accent2: #ffd042;
  --accent-light: #eef0f7;
  --secondary: #881212;

  /* Fluid-Größen */
  --pad: clamp(16px, 4vw, 28px);
  --radius-card: clamp(12px, 2.5vw, 18px);
  --radius-btn: 11px;
  --fs-lead: clamp(13px, 3.4vw, 15px);
  --fs-body: clamp(15px, 4vw, 18px);
  --fs-title: clamp(20px, 5.2vw, 30px);
  --fs-btn: clamp(17px, 4.6vw, 24px);
  --stage-max: 660px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  margin: 0;
  overflow-x: hidden; /* Sicherheitsnetz: verhindert horizontales Scrollen/Bouncen auf Mobilgeräten (v. a. iOS Safari) */
  font-family: "Noto Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: #e9ecf2; /* außen leicht abgedunkelt, damit die App-Fläche auf Desktop klar erkennbar bleibt */
}

/* ── App-Fläche: zentrierte, geräteunabhängige Spalte ────────── */
#app {
  max-width: var(--stage-max);
  margin: 0 auto;
  min-height: 100dvh;
  background: var(--bg);
}
@media (min-width: 640px) {
  #app {
    border-inline: 1px solid var(--rule);
    box-shadow: 0 0 24px rgba(15, 16, 18, 0.06);
  }
}

/* ── View = voller Bildschirm mit internem Scrollbereich ─────── */
.view {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  height: 100dvh;
  overflow: hidden;
}
.view-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 var(--pad);
}
.view-scroll > .inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  min-width: 0;      /* darf auf Mobilgeräten nie breiter als der Viewport werden */
  max-width: 100%;
  padding-bottom: 30px;
}
.no-scroll { overflow: hidden; }

/* ── Bilder / Logos ──────────────────────────────────────────── */
.logo { width: clamp(66px, 19vw, 92px); height: auto; display: block; }
.logo-intro { width: clamp(66px, 19vw, 96px); height: auto; }

/* ── Footer-Bereich (fester Boden) ───────────────────────────── */
.view-bottom {
  flex-shrink: 0;
  padding: 0 var(--pad);
  background: var(--bg);
}
.view-bottom.center { display: flex; flex-direction: column; align-items: center; padding-inline: 0; }

/* ── Willkommen ──────────────────────────────────────────────── */
.w-header {
  position: relative;
  display: flex;
  justify-content: center;
  padding-top: clamp(44px, 9vh, 84px);
  padding-inline: var(--pad);
  z-index: 5;
}
.w-header::after { /* Ausfade-Verlauf unter dem Logo */
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -40px;
  height: 40px;
  background: linear-gradient(to bottom, var(--bg), rgba(247, 248, 249, 0));
  pointer-events: none;
}

.w-card {
  width: 100%;
  background: var(--bg2);
  border-radius: var(--radius-card);
  margin-top: clamp(28px, 7vh, 52px);
  padding: clamp(22px, 6vw, 44px) clamp(18px, 5vw, 32px) clamp(14px, 4vw, 19px);
  box-shadow: 0 1px 3px rgba(15, 16, 18, 0.05);
}
.w-title { margin: 0; font-size: clamp(22px, 7vw, 36px); font-weight: 700; line-height: 1.14; color: rgba(0, 0, 0, 0.8); }
.w-body1 { margin: 14px 0 0; font-size: clamp(15px, 4.6vw, 22px); line-height: 1.32; color: rgba(0, 0, 0, 0.8); }
.w-body2 { margin: 12px 0 0; font-size: clamp(13px, 4vw, 18px); line-height: 1.38; color: rgba(0, 0, 0, 0.8); }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 13px;
  margin-top: 20px;
  min-height: 40px;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
  font: inherit;
  text-align: left;
  width: 100%;
}
.radio {
  flex-shrink: 0;
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 3px solid var(--accent);
  display: flex; align-items: center; justify-content: center;
  background: transparent;
}
.radio.checked { background: var(--accent); }
.radio.checked::after { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--bg2); }
.checkbox-label { font-size: clamp(13px, 4vw, 18px); color: rgba(0, 0, 0, 0.8); }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: block;
  width: 100%;
  border: 0;
  border-radius: var(--radius-btn);
  font-family: inherit;
  font-size: var(--fs-btn);
  font-weight: 400;
  padding: clamp(12px, 4vw, 19px) 20px;
  cursor: pointer;
  text-align: center;
  transition: opacity 0.15s ease, transform 0.05s ease;
}
.btn:active { transform: scale(0.99); }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 2px 6px rgba(15, 16, 18, 0.15); }
.btn-primary:disabled { background: rgba(67, 86, 147, 0.5); box-shadow: none; cursor: default; }
.btn-outline { background: transparent; color: var(--accent); border: 3px solid var(--accent); }
.btn-secondary { background: var(--secondary); color: #fff; }
.btn-light { background: var(--bg2); color: var(--accent); border: 2px solid var(--accent); }

.w-footer { padding-bottom: clamp(20px, 6vh, 40px); padding-top: 6px; }
.w-footer .btn + .btn { margin-top: 25px; }

/* ── W0 Sprachauswahl ────────────────────────────────────────── */
/* Eigene Liste (nicht .voice-selector), weil hier fünf Einträge mit
   Flagge + Label + Radio stehen und enger gestapelt werden müssen. */
.lang-list {
  display: flex;
  flex-direction: column;
  /* align-self übersteuert `align-items: center` des .inner-Containers –
     ohne das schrumpft die Liste auf Inhaltsbreite und die Radios
     werden rechts abgeschnitten. */
  align-self: stretch;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  /* Der Footer (.view-bottom) liegt AUSSERHALB des Scrollbereichs. Auf
     niedrigen Viewports ist die Liste scrollbar; etwas Luft nach unten
     verhindert, dass die letzte Zeile (Español) optisch am Button klebt.
     Bewusst klein gehalten – der Footer selbst hat schon eigenes
     Padding, zu viel Reserve würde den Scrollweg unnötig verlängern. */
  padding-bottom: clamp(16px, 3vh, 28px);
}
.lang-row {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 64px;
  background: var(--bg2);
  border: 2px solid transparent;
  border-radius: 10px;
  padding: clamp(10px, 3vw, 16px) 22px;
  margin-top: clamp(8px, 1.8vh, 14px);
  font: inherit;
  font-size: clamp(16px, 4.6vw, 21px);
  color: #000;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(15, 16, 18, 0.1);
}
.lang-row.selected {
  border-color: var(--accent);
  background: var(--accent-light, #eef0f7);
}
.lang-row .lang-flag {
  width: 34px;
  height: 34px;
  border-radius: 4px;
  object-fit: cover;
  flex-shrink: 0;
  margin-right: 16px;
}
.lang-row .lang-label { flex: 1; }

/* ── W2 Stimmen-Auswahl ──────────────────────────────────────── */
.voice-selector {
  display: flex;
  align-items: center;
  width: 100%;
  background: var(--bg2);
  border: 2px solid transparent;
  border-radius: 10px;
  padding: clamp(16px, 4.4vw, 21px) 27px;
  margin-top: clamp(13px, 3.5vh, 25px);
  font: inherit;
  font-size: clamp(15px, 4.4vw, 20px);
  color: #000;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(15, 16, 18, 0.1);
}
.voice-selector.selected { border-color: var(--accent); }
.voice-selector .grow { flex: 1; }
.vdot { width: 12px; height: 12px; border-radius: 50%; background: rgba(0, 0, 0, 0.13); flex-shrink: 0; margin-left: 8px; }
.voice-selector.selected .vdot { background: var(--accent); }

/* ── Lightbox (W3) ───────────────────────────────────────────── */
.lightbox {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  z-index: 50;
}
.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: #081234;
  opacity: 0.75;
  border: 0;
  width: 100%;
  cursor: pointer;
}
.lightbox-card {
  position: relative;
  margin: clamp(120px, 20vh, 205px) auto 0;
  width: min(92%, 460px);
  max-height: 70vh;
  overflow-y: auto;
  background: rgba(255, 255, 255, 0.97);
  border-radius: 11px;
  padding: clamp(22px, 5vw, 43px) clamp(16px, 4vw, 24px) 19px;
}
.lightbox-title { font-size: clamp(15px, 4.4vw, 21px); font-weight: 600; line-height: 1.33; color: rgba(0, 0, 0, 0.8); margin: 0; }
.lightbox-body { margin: 18px 0 28px; font-size: clamp(13px, 3.8vw, 17px); line-height: 1.4; color: rgba(0, 0, 0, 0.8); font-weight: 300; }

/* ── Intro / Kategorie: Sprachkarte ──────────────────────────── */
.flag-row {
  display: flex;
  justify-content: center;
  gap: clamp(8px, 2.4vw, 10px);
  margin: clamp(20px, 6vh, 32px) 0 clamp(18px, 4.6vw, 28px);
}
.flag-btn {
  width: clamp(44px, 11vw, 56px);
  height: clamp(44px, 11vw, 56px);
  border-radius: 50%;
  border: 2px solid var(--rule);
  background: var(--bg2);
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.flag-btn img { width: 100%; height: 100%; object-fit: cover; }
.flag-btn.active { border-color: var(--accent2); background: var(--accent2); box-shadow: 0 0 0 1px var(--accent2); }
.flag-btn:focus-visible, .btn:focus-visible, .voice-selector:focus-visible,
.play-btn:focus-visible, .thumb-btn:focus-visible, .tile:focus-visible,
.lang-btn:focus-visible, .lang-option:focus-visible, .home-btn:focus-visible,
.lang-row:focus-visible {
  outline: 3px solid var(--accent2);
  outline-offset: 2px;
}

/* Sprach-/Antwort-Karte */
.speech-card {
  width: 100%;
  background: var(--bg2);
  border-radius: 16px;
  border: 1px solid var(--rule);
  padding: 20px;
  box-shadow: 0 1px 4px rgba(15, 16, 18, 0.08);
}
.speech-card.row {
  display: flex;
  align-items: center;
  gap: 14px;
}
.speech-card .grow { flex: 1; min-width: 0; }
.speech-text { font-size: var(--fs-body); line-height: 1.42; color: var(--ink); margin: 0; }
.speech-text strong { font-weight: 700; }
.intro-page-1 .speech-card { margin-bottom: clamp(16px, 5vw, 32px); }
.flag-page-title { font-size: var(--fs-body); }

/* Screen 2 (Danke): vertikale Karte */
.v-card { flex-direction: column; align-items: stretch; gap: 0; }
.speech-header-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 26px;
}
.thanks-title-v2 { flex: 1; margin: 0; font-size: clamp(18px, 5vw, 25px); font-weight: 700; line-height: 1.2; color: var(--accent); }
.thanks-title { margin: 0; font-size: clamp(16px, 4.6vw, 21px); font-weight: 700; color: var(--accent); }
.thanks-body { font-size: clamp(14px, 4.2vw, 18px); line-height: 1.4; color: var(--ink); margin: 0 0 16px; }
.thanks-prelude { font-size: clamp(14px, 4.2vw, 18px); font-weight: 700; line-height: 1.4; color: var(--ink); margin: 0 0 8px; }
.steps-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.steps-list li { font-size: clamp(14px, 4.2vw, 18px); line-height: 1.4; color: var(--ink); }

/* Play-Button (play.png = gelber Kreis mit Dreieck) */
.play-btn {
  width: clamp(64px, 17vw, 88px);
  height: clamp(64px, 17vw, 88px);
  border: 0;
  background: transparent;
  padding: 0;
  flex-shrink: 0;
  border-radius: 50%;
  cursor: pointer;
}
.play-btn img { width: 100%; height: 100%; display: block; }
.play-btn.busy { opacity: 0.5; }
.play-btn.hidden { display: none; }

/* Daumen-Buttons */
.thumb-row { display: flex; gap: clamp(16px, 6vw, 28px); justify-content: center; margin-top: clamp(16px, 5vw, 32px); margin-bottom: 10px; }
.thumb-btn {
  width: clamp(112px, 32vw, 140px);
  height: clamp(112px, 32vw, 140px);
  border: 0;
  border-radius: 16px;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow: 0 3px 8px rgba(15, 16, 18, 0.2);
}
.thumb-btn img { width: 58%; height: 58%; }

/* Zurück/Weiter (Screen 2) */
.action-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin-top: 32px; }
.btn-inline {
  font-family: inherit;
  font-size: clamp(14px, 4.2vw, 20px);
  font-weight: 700;
  padding: 14px 24px;
  border-radius: 12px;
  min-height: 48px;
  cursor: pointer;
}
.btn-back { background: var(--bg2); color: var(--accent); border: 2px solid var(--accent); }
.btn-continue { background: var(--accent); color: #fff; border: 0; }

/* Home-Button + powered-by */
.home-wrap { display: flex; flex-direction: column; align-items: center; padding-top: 12px; }
.home-btn {
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
  border-radius: 50%;
  width: clamp(60px, 16vw, 72px);
  height: clamp(60px, 16vw, 72px);
  margin-bottom: 18px;
}
.home-btn img { width: 100%; height: 100%; display: block; }
.powered { display: flex; align-items: center; justify-content: center; gap: 4px; padding: 8px 0 16px; color: var(--muted); font-size: clamp(11px, 3vw, 13px); }
.powered img { height: 16px; width: auto; }
.fade-before-bottom {
  position: relative;
}
.fade-before-bottom::before {
  content: "";
  position: absolute;
  left: 0; right: 0; top: -40px;
  height: 40px;
  background: linear-gradient(to top, var(--bg), rgba(247, 248, 249, 0));
  pointer-events: none;
}

/* ── Home: Header + Sprachauswahl + Kachel-Grid ──────────────── */
.home-view { padding-top: clamp(28px, 7vh, 50px); }
.intro-scroll { padding-top: clamp(24px, 6vh, 50px); }
.home-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; max-width: 100%; }
.lang-wrap { position: relative; }
.lang-btn {
  font-family: inherit;
  font-weight: 700;
  font-size: clamp(13px, 3.8vw, 16px);
  color: var(--accent);
  background: transparent;
  border: 2px solid var(--accent);
  border-radius: 8px;
  min-width: clamp(48px, 12vw, 60px);
  min-height: 44px;
  padding: 8px 14px;
  cursor: pointer;
}
.lang-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 40;
  background: var(--bg2);
  border: 1px solid var(--rule);
  border-radius: 10px;
  box-shadow: 0 2px 6px rgba(15, 16, 18, 0.15);
  padding: 6px 0;
  min-width: 190px;
}
.lang-option {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  font: inherit;
  font-size: clamp(14px, 4vw, 16px);
  color: var(--ink);
  padding: 12px 22px;
  cursor: pointer;
}
.lang-option.active { background: var(--accent-light); }

.tile-grid {
  display: grid;
  /* minmax(0,1fr): Spalten dürfen unter die Inhalts-Mindestbreite schrumpfen.
     Verhindert horizontalen Überlauf in Safari/WebKit, wenn Kachel-Icons
     (Original bis ~200 px) breiter sind als die Kachel auf schmalen Displays. */
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(10px, 3vw, 16px);
  width: 100%;
  min-width: 0;
  max-width: 100%;
  align-content: start;
}
.tile {
  aspect-ratio: 1 / 1;
  min-width: 0; /* intrinsische Mindestbreite des Inhalts erlauben zu schrumpfen */
  border: 0;
  border-radius: 16px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14%;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(15, 16, 18, 0.12);
}
.tile.tile-help { background: var(--secondary); }
.tile img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain; /* Icon bleibt unverzerrt, auch bei nicht-quadratischen Quellbildern */
  min-width: 0;
  min-height: 0;
  pointer-events: none;
}

/* ── Kategorie-Screen ────────────────────────────────────────── */
.cat-view { padding-top: clamp(24px, 6vh, 50px); }
.cat-header { display: flex; flex-direction: column; align-items: center; width: 100%; }
.cat-lead {
  max-width: 340px;
  text-align: center;
  font-size: var(--fs-lead);
  font-weight: 700;
  line-height: 1.4;
  color: rgba(0, 0, 0, 0.65);
  margin: clamp(14px, 4vh, 22px) 0 clamp(10px, 3vh, 16px);
}
.cat-card-wrap { flex: 1; display: flex; flex-direction: column; justify-content: center; width: 100%; min-height: 0; }
.cat-card {
  background: var(--bg2);
  border: 1px solid var(--rule);
  border-radius: 16px;
  padding: clamp(16px, 4vw, 24px);
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: 0 2px 8px rgba(15, 16, 18, 0.1);
}
.cat-card img.cat-icon { width: clamp(44px, 12vw, 60px); height: clamp(44px, 12vw, 60px); flex-shrink: 0; }
.cat-card .cat-text { flex: 1; margin: 0; font-size: clamp(14px, 4.4vw, 18px); line-height: 1.45; color: var(--ink); }
.no-audio-hint { text-align: center; font-size: 14px; color: var(--muted); margin-top: 12px; }

/* ── Accessibilität: prefers-reduced-motion ──────────────────── */
@media (prefers-reduced-motion: no-preference) {
  .view { animation: view-in 0.25s ease; }
  @keyframes view-in { from { opacity: 0.4; } to { opacity: 1; } }
}

/* ── Höhe-Schutz für kleine Screens ──────────────────────────── */
@media (max-height: 560px) {
  .w-header { padding-top: 24px; }
  .w-card { margin-top: 16px; }
}

/* ── Mobil ≤ 576 px: Kachel-Grid garantiert im Viewport ─────── */
/* Das 2-Spalten-Grid nutzt auf schmalen Screens explizit
   minmax(0,1fr)-Spalten und schrumpfende Icons, damit die Kacheln
   bei iPhones/kleinen Android-Geräten nie über den rechten Rand
   hinauslaufen. Die Icons bleiben dank object-fit:contain unverzerrt. */
@media (max-width: 576px) {
  .view-scroll,
  .view-scroll > .inner,
  .home-header,
  .tile-grid {
    max-width: 100%;
  }

  .tile-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: clamp(8px, 2.5vw, 10px);
  }

  .tile {
    min-width: 0;
    padding: 12%;
    border-radius: 14px;
  }

  .tile img {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
  }
}
