/* Inbox – Telegram Mini App. Farben kommen aus Telegrams Theme (--tg-theme-*), Fallbacks für Vorschau. */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #efeff4);
  --flaeche: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #000000);
  --leise: var(--tg-theme-hint-color, #8e8e93);
  --unter: var(--tg-theme-subtitle-text-color, var(--leise));
  --akzent: var(--tg-theme-button-color, #007aff);
  --akzent-text: var(--tg-theme-button-text-color, #ffffff);
  --akzent-schrift: var(--tg-theme-accent-text-color, var(--tg-theme-link-color, #007aff));
  --rot: var(--tg-theme-destructive-text-color, #ff3b30);
  --linie: var(--tg-theme-section-separator-color, rgba(60, 60, 67, 0.18));
  --kopf-bg: var(--tg-theme-header-bg-color, var(--bg));
  --gruen: #2fb45a;
  --schatten: 0 1px 2px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(0, 0, 0, 0.07);
  --radius: 16px;
  --sicher-unten: max(env(safe-area-inset-bottom), var(--tg-safe-area-inset-bottom, 0px));
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not(.tg) {
    --bg: #000000;
    --flaeche: #1c1c1e;
    --text: #ffffff;
    --leise: #8e8e93;
    --akzent: #0a84ff;
    --akzent-schrift: #0a84ff;
    --rot: #ff453a;
    --linie: rgba(84, 84, 88, 0.6);
    --schatten: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  overscroll-behavior: none;
}
::selection { background: color-mix(in srgb, var(--akzent) 28%, transparent); }
:focus-visible { outline: 2px solid var(--akzent); outline-offset: 2px; }
button { font: inherit; color: inherit; }

/* ---------------------------------------------------------------- Kopf */
.kopf { background: var(--kopf-bg); padding: 12px 16px 10px; flex: none; }
.kopf-zeile { display: flex; align-items: baseline; gap: 10px; }
h1 { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; margin: 0; }
.zaehler { color: var(--leise); font-size: 15px; font-variant-numeric: tabular-nums; }
.filter { display: flex; gap: 8px; margin: 10px -16px 0; padding: 0 16px; overflow-x: auto; scrollbar-width: none; }
.filter::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 0; border-radius: 999px; padding: 6px 12px; min-height: 32px;
  background: var(--flaeche); color: var(--text); font-size: 14px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  transition: background-color 160ms ease-out, color 160ms ease-out;
}
.chip .zahl { color: var(--leise); font-variant-numeric: tabular-nums; font-size: 13px; }
.chip[aria-pressed="true"] { background: var(--akzent); color: var(--akzent-text); }
.chip[aria-pressed="true"] .zahl { color: color-mix(in srgb, var(--akzent-text) 75%, transparent); }

/* ---------------------------------------------------------------- Bühne / Stapel */
.buehne { flex: 1; position: relative; padding: 8px 16px 0; min-height: 0; }
.stapel { position: relative; height: 100%; }
.karte {
  position: absolute; inset: 0 0 auto 0; max-height: calc(100% - 18px); min-height: 180px;
  background: var(--flaeche); border-radius: var(--radius); box-shadow: var(--schatten);
  display: flex; flex-direction: column; overflow: hidden;
  transform-origin: 50% 100%;
  transition: transform 260ms cubic-bezier(0.16, 1, 0.3, 1), opacity 200ms ease-out;
  touch-action: pan-y;
  will-change: transform;
}
.karte:not([data-tiefe="0"]) { height: var(--h, auto); }
.karte[data-tiefe="1"] { transform: translateY(9px) scale(0.955); opacity: 0.9; pointer-events: none; }
.karte[data-tiefe="2"] { transform: translateY(18px) scale(0.91); opacity: 0.6; pointer-events: none; }
.karte[data-tiefe="3"] { transform: translateY(18px) scale(0.91); opacity: 0; pointer-events: none; }
.karte.zieht { transition: none; }
.karte.weg-rechts { transform: translateX(120%) rotate(8deg) !important; opacity: 0; }
.karte.weg-links { transform: translateX(-120%) rotate(-8deg) !important; opacity: 0; }
.karte.weg-oben { transform: translateY(-30px) scale(0.98) !important; opacity: 0; }

.stempel {
  position: absolute; top: 18px; z-index: 2; padding: 6px 12px; border-radius: 10px;
  font-weight: 700; font-size: 15px; letter-spacing: 0.02em; opacity: 0; pointer-events: none;
  display: inline-flex; align-items: center; gap: 6px;
}
.stempel svg { width: 18px; height: 18px; }
.stempel.ja { left: 18px; color: #fff; background: var(--gruen); }
.stempel.nein { right: 18px; color: #fff; background: var(--rot); }

.k-kopf { padding: 16px 18px 0; display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--leise); flex: none; }
.k-kopf .firma { color: var(--akzent-schrift); font-weight: 600; }
.k-kopf svg { width: 16px; height: 16px; flex: none; }
.k-kopf .art { display: inline-flex; align-items: center; gap: 5px; }
.k-kopf .frist { margin-left: auto; display: inline-flex; align-items: center; gap: 4px; font-variant-numeric: tabular-nums; }
.k-kopf .frist.knapp { color: var(--rot); }
.k-kopf .nr { font-variant-numeric: tabular-nums; }

.k-inhalt { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 8px 18px 16px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.k-frage { font-size: 19px; font-weight: 600; line-height: 1.3; letter-spacing: -0.01em; margin: 4px 0 12px; text-wrap: pretty; }

.k-meta { margin: 0 0 12px; display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; font-size: 14px; }
.k-meta dt { color: var(--leise); }
.k-meta dd { margin: 0; overflow-wrap: anywhere; }

.k-text {
  white-space: pre-wrap; overflow-wrap: anywhere; font-size: 16px; line-height: 1.45;
  padding: 12px 14px; border-radius: 12px; background: color-mix(in srgb, var(--bg) 70%, var(--flaeche));
  margin: 0 0 12px;
}
.k-text.leer { color: var(--leise); font-style: italic; }
.k-medien { display: grid; gap: 8px; margin: 0 0 12px; }
.k-medien.zwei { grid-template-columns: 1fr 1fr; }
.k-medien img, .k-medien video, .k-medium-platz {
  width: 100%; border-radius: 12px; display: block; background: color-mix(in srgb, var(--leise) 18%, transparent);
  aspect-ratio: 1; object-fit: cover;
}
.k-medien video { aspect-ratio: 9 / 16; max-height: 420px; object-fit: contain; background: #000; }
.k-medium-platz { display: grid; place-items: center; color: var(--leise); font-size: 13px; }

.hinweis {
  display: flex; gap: 8px; align-items: flex-start; font-size: 14px; line-height: 1.35;
  padding: 10px 12px; border-radius: 12px; margin: 0 0 12px;
  background: color-mix(in srgb, var(--akzent) 10%, transparent); color: var(--text);
}
.hinweis svg { width: 18px; height: 18px; flex: none; color: var(--akzent-schrift); margin-top: 1px; }
.hinweis.warn { background: color-mix(in srgb, #ff9500 14%, transparent); }
.hinweis.warn svg { color: #ff9500; }
.k-begruendung { font-size: 14px; color: var(--unter); margin: 0 0 8px; }

.varianten { display: flex; gap: 6px; margin: 0 0 12px; }
.varianten button {
  border: 1px solid var(--linie); background: transparent; border-radius: 999px; padding: 4px 12px; font-size: 13px; cursor: pointer;
}
.varianten button[aria-pressed="true"] { border-color: var(--akzent); color: var(--akzent-schrift); font-weight: 600; }

/* Ändern */
.editor { display: flex; flex-direction: column; gap: 10px; }
.editor textarea {
  width: 100%; min-height: 220px; resize: vertical; font: inherit; font-size: 16px; line-height: 1.45;
  color: var(--text); background: color-mix(in srgb, var(--bg) 70%, var(--flaeche));
  border: 1px solid var(--linie); border-radius: 12px; padding: 12px 14px; caret-color: var(--akzent);
}
.editor textarea:focus { outline: none; border-color: var(--akzent); }
.editor .laenge { font-size: 13px; color: var(--leise); text-align: right; font-variant-numeric: tabular-nums; }
.editor .laenge.zuviel { color: var(--rot); }

/* ---------------------------------------------------------------- Leiste */
.leiste {
  flex: none; display: flex; gap: 10px; padding: 10px 16px calc(10px + var(--sicher-unten));
  background: var(--bg);
}
.leiste.optionen { flex-wrap: wrap; }
.knopf {
  flex: 1; min-height: 50px; border: 0; border-radius: 14px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 17px; font-weight: 600; background: var(--flaeche); color: var(--text);
  transition: transform 120ms ease-out, opacity 160ms ease-out, background-color 160ms ease-out;
}
.knopf svg { width: 20px; height: 20px; }
.knopf:active { transform: scale(0.97); }
.knopf:disabled { opacity: 0.45; cursor: default; transform: none; }
.knopf.ja { background: var(--akzent); color: var(--akzent-text); flex: 1.4; }
.knopf.nein { color: var(--rot); }
.knopf.klein { flex: 0 0 56px; }
.knopf.option { flex: 1 1 calc(50% - 5px); font-size: 15px; min-height: 46px; padding: 0 12px; }
.knopf.laedt { opacity: 0.6; pointer-events: none; }

/* ---------------------------------------------------------------- Rückgängig + Meldung */
.rueckgaengig, .meldung {
  position: fixed; left: 12px; right: 12px; bottom: calc(82px + var(--sicher-unten)); z-index: 5;
  border-radius: 14px; padding: 12px 14px; font-size: 15px;
  background: color-mix(in srgb, var(--text) 88%, var(--bg)); color: var(--bg);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.25);
  animation: hoch 240ms cubic-bezier(0.16, 1, 0.3, 1);
}
.rueckgaengig { display: flex; align-items: center; gap: 10px; overflow: hidden; }
.rueckgaengig[hidden], .meldung[hidden] { display: none; }
.rg-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rg-aktionen { display: flex; gap: 4px; }
.rg-knopf {
  border: 0; background: transparent; color: color-mix(in srgb, var(--akzent) 70%, var(--bg));
  font-weight: 600; font-size: 15px; padding: 6px 8px; border-radius: 8px; cursor: pointer;
}
.rg-uhr { position: absolute; left: 0; bottom: 0; height: 3px; width: 100%; background: var(--akzent); transform-origin: left; }
.rueckgaengig.laeuft .rg-uhr { animation: ablauf var(--dauer, 3s) linear forwards; }
.meldung.fehler { background: var(--rot); color: #fff; }
@keyframes hoch { from { transform: translateY(16px); opacity: 0; } }
@keyframes ablauf { to { transform: scaleX(0); } }

/* ---------------------------------------------------------------- Leer / Fehler / Laden */
.leer-zustand { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px 28px 60px; gap: 8px; }
.leer-zustand svg { width: 56px; height: 56px; color: var(--gruen); margin-bottom: 6px; }
.leer-zustand.fehler svg { color: var(--leise); }
.leer-zustand h2 { font-size: 20px; margin: 0; letter-spacing: -0.01em; }
.leer-zustand p { margin: 0; color: var(--leise); font-size: 15px; max-width: 30ch; }
.leer-zustand .knopf { flex: none; margin-top: 14px; padding: 0 22px; min-height: 44px; font-size: 16px; }

.skelett { position: absolute; inset: 8px 16px 18px; background: var(--flaeche); border-radius: var(--radius); padding: 18px; box-shadow: var(--schatten); }
.sk-zeile, .sk-block { border-radius: 8px; background: color-mix(in srgb, var(--leise) 16%, transparent); margin-bottom: 14px; animation: puls 1.4s ease-in-out infinite; }
.sk-zeile { height: 14px; }
.sk-zeile.kurz { width: 35%; } .sk-zeile.mittel { width: 60%; } .sk-zeile.lang { width: 85%; height: 20px; }
.sk-block { height: 160px; }
@keyframes puls { 50% { opacity: 0.5; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
}
@media (min-width: 560px) {
  .buehne, .kopf, .leiste { width: 100%; max-width: 560px; margin-inline: auto; }
}
.symbole { position: absolute; width: 0; height: 0; overflow: hidden; }
