:root {
  --bg: #08090d;
  --surface: rgba(255, 255, 255, 0.045);
  --surface-2: rgba(255, 255, 255, 0.075);
  --line: rgba(255, 255, 255, 0.09);
  --text: #eceef5;
  --muted: #8b90a3;
  --accent: #8b7bff;
  --accent-glow: rgba(139, 123, 255, 0.35);
  --ok: #4ade80;
  --warn: #fbbf24;
  --err: #f87171;
  --r: 16px;
  --r-lg: 22px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background:
    radial-gradient(900px 500px at 20% -10%, rgba(139, 123, 255, 0.10), transparent 70%),
    var(--bg);
  color: var(--text);
  font-family: Outfit, system-ui, sans-serif;
  min-height: 100vh;
}

h1, h2 { margin: 0 0 6px; font-weight: 800; letter-spacing: -0.02em; }
.muted { color: var(--muted); margin: 0; font-size: 14px; }
.error { color: var(--err); min-height: 20px; font-size: 14px; margin: 4px 0 0; }

input, button {
  font: inherit;
  color: inherit;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 11px 14px;
  outline: none;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }

button {
  cursor: pointer;
  background: linear-gradient(180deg, var(--accent), #6c5ce0);
  border: none;
  font-weight: 600;
  box-shadow: 0 6px 20px -8px var(--accent-glow);
}
button:hover { filter: brightness(1.08); }
button:disabled { opacity: 0.5; cursor: default; filter: none; }

button.ghost {
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: none;
  font-weight: 500;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  backdrop-filter: blur(12px);
}

/* --- Anmeldung --- */
.gate { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.gate-card { display: grid; gap: 12px; padding: 32px; width: min(380px, 100%); }
.gate-card input, .gate-card button { width: 100%; }

/* --- Kopf --- */
header {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: rgba(8, 9, 13, 0.85);
  backdrop-filter: blur(14px);
  z-index: 5;
}
.brand { font-weight: 800; letter-spacing: -0.02em; font-size: 19px; }
nav { display: flex; gap: 6px; }
.tab {
  background: transparent;
  box-shadow: none;
  color: var(--muted);
  font-weight: 500;
  padding: 8px 14px;
}
.tab.active { background: var(--surface-2); color: var(--text); }
.jf { margin-left: auto; color: var(--muted); text-decoration: none; font-size: 14px; }
.jf:hover { color: var(--text); }

main { padding: 26px 24px 60px; max-width: 1180px; margin: 0 auto; }

/* --- Suche --- */
.searchbar { display: flex; gap: 10px; margin-bottom: 24px; }
.searchbar input { flex: 1; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 18px;
}

.poster {
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow: hidden;
  cursor: pointer;
  background: var(--surface);
  transition: transform 0.2s var(--ease), border-color 0.2s var(--ease);
}
.poster:hover { transform: translateY(-4px); border-color: var(--accent); }
.poster img { width: 100%; aspect-ratio: 2/3; object-fit: cover; display: block; background: #14161f; }
.poster .meta { padding: 10px 12px; }
/* Titel auf zwei Zeilen begrenzen, sonst werden die Kacheln unterschiedlich hoch */
.poster .t {
  font-weight: 600;
  font-size: 14px;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.6em;
}
.poster .y { color: var(--muted); font-size: 12px; margin-top: 3px; }
.badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  margin-left: 6px;
}

/* --- Listen --- */
.list { display: grid; gap: 8px; }
.row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 16px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
}
.row .name { flex: 1; min-width: 0; font-size: 14px; word-break: break-word; }
.row .tags { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.tag {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}
.tag.q { color: var(--accent); }
.tag.de { color: var(--ok); }
.tag.seed { color: var(--warn); }
.tag.warn { color: var(--err); }
.row button { padding: 8px 14px; font-size: 14px; white-space: nowrap; }

.bar { height: 4px; border-radius: 999px; background: var(--surface-2); overflow: hidden; width: 110px; }
.bar span { display: block; height: 100%; background: var(--accent); }

/* --- Auswahl-Fenster --- */
.sheet {
  position: fixed;
  inset: 0;
  background: rgba(3, 4, 8, 0.72);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 20;
}
.sheet-inner { width: min(860px, 100%); max-height: 86vh; overflow: auto; padding: 24px; }
.sheet-head { display: flex; gap: 16px; align-items: flex-start; margin-bottom: 16px; }
.sheet-head > div { flex: 1; }

.episode-pick { display: flex; gap: 14px; align-items: end; margin-bottom: 16px; flex-wrap: wrap; }
.episode-pick label { display: grid; gap: 5px; font-size: 13px; color: var(--muted); }
.episode-pick input { width: 90px; }

.filters { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.chip {
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: none;
  color: var(--muted);
  font-size: 13px;
  padding: 7px 13px;
  font-weight: 500;
}
.chip.active { color: var(--text); border-color: var(--accent); }
.chip.toggle { display: flex; align-items: center; gap: 7px; cursor: pointer; }

.empty { color: var(--muted); text-align: center; padding: 46px 0; font-size: 14px; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #171a24;
  border: 1px solid var(--line);
  padding: 13px 20px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 40;
  box-shadow: 0 18px 40px -18px #000;
}
.toast.ok { border-color: rgba(74, 222, 128, 0.5); }
.toast.err { border-color: rgba(248, 113, 113, 0.5); }

@media (max-width: 620px) {
  header { padding: 12px 14px; gap: 8px; }
  .brand { font-size: 17px; }
  .tab { padding: 8px 11px; font-size: 14px; }
  .jf { font-size: 13px; }
  main { padding: 16px 14px 46px; }

  .searchbar input { min-width: 0; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); gap: 12px; }

  /* Zeile = zwei Spalten: links Text + Marken, rechts der Knopf.
     Vorher brach alles um und jede Quelle wurde ~170 px hoch. */
  .row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 6px 10px;
    padding: 11px 12px;
  }
  .row .name {
    font-size: 13px;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .row .tags { grid-column: 1; gap: 5px; }
  .row .tag { font-size: 10px; padding: 2px 7px; }
  .row button {
    grid-column: 2;
    grid-row: 1 / span 2;
    align-self: center;
    padding: 10px 13px;
    min-height: 42px;
  }
  .bar { width: 70px; }

  /* Auswahl-Fenster als Blatt von unten - nutzt die Hoehe richtig aus */
  .sheet { padding: 0; place-items: end stretch; }
  .sheet-inner {
    width: 100%;
    max-height: 92vh;
    max-height: 92dvh;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    padding: 16px 14px calc(18px + env(safe-area-inset-bottom));
  }
  .sheet-head {
    position: sticky;
    top: -16px;
    background: #0f1118;
    margin: -16px -14px 12px;
    padding: 16px 14px 12px;
    z-index: 2;
  }
  .sheet-head h2 { font-size: 19px; }

  /* Filterleiste seitlich scrollen statt in drei Reihen umbrechen */
  .filters {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  .filters::-webkit-scrollbar { display: none; }
  .chip { flex: 0 0 auto; }

  .episode-pick input { width: 76px; }
}
