:root {
  --bg: #111318;
  --surface: #1b1e26;
  --surface-2: #262a35;
  --line: #333846;
  --text: #f1f2f5;
  --muted: #9aa1b2;
  --accent: #f5b942;
  --accent-ink: #1a1404;
  --danger: #ff6b6b;
  --ok: #4cd08a;
  --dvd: #d9dce4;
  --bd: #3d8bff;
  --uhd: #f5b942;
  --radius: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
}

h1, h2, h3, p { margin: 0; }
a { color: var(--accent); }

input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 44px;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
label { display: block; font-size: 13px; color: var(--muted); }
label > input, label > select, label > textarea { margin-top: 4px; color: var(--text); font-size: 16px; }
label small { font-weight: normal; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 8px 16px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
  cursor: pointer; text-decoration: none; color: var(--text); white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.link { background: none; border: none; color: var(--muted); text-decoration: underline; }
.btn.small { min-height: 36px; padding: 4px 10px; font-size: 13px; color: var(--text); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }

.icon-btn {
  width: 44px; height: 44px; flex: none;
  background: none; border: none; border-radius: 50%;
  font-size: 20px; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }

.error { color: var(--danger); font-size: 14px; min-height: 0; }
.error:empty { display: none; }
.center { text-align: center; }

/* ---------- Anmeldung ---------- */
#auth { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.auth-card {
  width: 100%; max-width: 360px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 28px 24px; display: grid; gap: 14px; text-align: center;
}
.auth-card img { margin: 0 auto; }
.auth-card h1 { font-size: 24px; }
.auth-card p { color: var(--muted); font-size: 14px; }
.auth-card label { text-align: left; }

/* ---------- Kopfbereich ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding: 8px 16px 10px;
  padding-top: max(8px, env(safe-area-inset-top));
  display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; align-items: center;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; min-width: 0; }
.count { font-weight: 400; font-size: 13px; color: var(--muted); white-space: nowrap; }
.search, .filters { grid-column: 1 / -1; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters select { width: auto; flex: 1 1 130px; min-width: 0; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  min-height: 44px; padding: 6px 14px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px;
  cursor: pointer; font-size: 14px; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }

#actorRow { grid-column: 1 / -1; align-items: center; }
#actorRow .lbl { font-size: 13px; color: var(--muted); }
.chip.small { min-height: 36px; padding: 4px 12px; font-size: 13px; }
.chip .n { color: var(--muted); }
.chip[aria-pressed="true"] .n { color: inherit; }
.names { display: flex; flex-wrap: wrap; gap: 4px 6px; }
.name-btn { background: none; border: none; padding: 2px 0; color: var(--accent); text-decoration: underline; cursor: pointer; text-align: left; }
.name-btn:hover { filter: brightness(1.15); }

@media (min-width: 800px) {
  .top { grid-template-columns: auto minmax(200px, 1fr) auto auto; padding: 10px 24px; }
  .brand { grid-column: 1; grid-row: 1; }
  .search { grid-column: 2; grid-row: 1; }
  .filters { grid-column: 3; grid-row: 1; flex-wrap: nowrap; }
  .filters select { flex: none; }
  #menuBtn { grid-row: 1; grid-column: 4; }
}

/* ---------- Raster ---------- */
main { padding: 16px; }
@media (min-width: 800px) { main { padding: 24px; } }

.grid { display: grid; gap: 14px 12px; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); padding-bottom: 96px; }
@media (min-width: 520px) { .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 20px 16px; } }
@media (min-width: 1100px) { .grid { grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); } }

.card { background: none; border: none; padding: 0; text-align: left; cursor: pointer; min-width: 0; }
.card .name { margin-top: 6px; font-size: 14px; font-weight: 600; line-height: 1.25; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .meta { font-size: 12px; color: var(--muted); }
.card:hover .poster { transform: translateY(-3px); box-shadow: 0 10px 24px #0009; }

.poster {
  position: relative; aspect-ratio: 2 / 3; width: 100%;
  background: linear-gradient(160deg, #2b3040, #1b1e26);
  border-radius: var(--radius); overflow: hidden;
  transition: transform .15s, box-shadow .15s;
}
.poster img { width: 100%; height: 100%; object-fit: cover; display: block; }
.poster .ph { position: absolute; inset: 0; display: grid; place-items: center; padding: 10px; text-align: center;
  font-size: 13px; font-weight: 600; color: var(--muted); overflow-wrap: anywhere; }

.badge {
  display: inline-block; padding: 2px 7px; border-radius: 6px;
  font-size: 11px; font-weight: 700; letter-spacing: .02em; white-space: nowrap;
  background: var(--dvd); color: #15171c;
}
.badge.bd { background: var(--bd); color: #fff; }
.badge.uhd { background: #111; color: var(--uhd); box-shadow: inset 0 0 0 1px var(--uhd); }
.poster .badge { position: absolute; left: 6px; bottom: 6px; box-shadow: 0 2px 6px #0008; }
.poster .badge.uhd { box-shadow: inset 0 0 0 1px var(--uhd), 0 2px 6px #0008; }

.empty { text-align: center; color: var(--muted); padding: 64px 16px; display: grid; gap: 14px; justify-items: center; }
.empty strong { color: var(--text); font-size: 18px; }

.fab {
  position: fixed; right: 20px; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 6;
  width: 60px; height: 60px; border-radius: 50%; border: none;
  background: var(--accent); color: var(--accent-ink); font-size: 30px; line-height: 1; cursor: pointer;
  box-shadow: 0 8px 24px #000a;
}
.fab:hover { filter: brightness(1.08); }

/* ---------- Dialoge ---------- */
dialog {
  border: none; padding: 0; color: var(--text); background: var(--surface);
  width: 100%; max-width: 100%; height: 100dvh; max-height: 100dvh; margin: 0;
}
dialog[open] { display: flex; flex-direction: column; }
dialog::backdrop { background: #000a; }
@media (min-width: 640px) {
  dialog { width: 560px; height: auto; max-height: 90dvh; margin: auto; border-radius: 16px; border: 1px solid var(--line); }
  #detailDlg { width: 720px; }
}
.dlg-head { display: flex; align-items: center; gap: 4px; padding: 8px 8px 8px 16px; border-bottom: 1px solid var(--line); flex: none;
  padding-top: max(8px, env(safe-area-inset-top)); }
.dlg-head h2 { font-size: 18px; flex: 1; min-width: 0; }
.dlg-body { padding: 16px; overflow-y: auto; flex: 1; display: grid; gap: 14px; align-content: start;
  padding-bottom: max(16px, env(safe-area-inset-bottom)); }
.dlg-body section, .dlg-body form, .stack { display: grid; gap: 14px; }
.dlg-body h3 { font-size: 15px; }
.credit { font-size: 12px; color: var(--muted); text-align: center; }

.row, .dlg-body form.row { display: flex; gap: 8px; align-items: end; }
.row > input { flex: 1; min-width: 0; }
.row > label { flex: 1; min-width: 0; }
.or { text-align: center; color: var(--muted); font-size: 13px; }

/* ---------- Scanner ---------- */
.scanner { position: relative; aspect-ratio: 4 / 3; max-height: 46dvh; width: 100%; background: #000; border-radius: var(--radius); overflow: hidden; }
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-line { position: absolute; left: 8%; right: 8%; top: 50%; height: 2px; background: var(--danger); box-shadow: 0 0 10px var(--danger); display: none; }
.scanner.on .scan-line { display: block; }
.scan-off { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 12px; padding: 16px; text-align: center;
  background: var(--surface-2); color: var(--muted); font-size: 14px; }
.scanner.on .scan-off { display: none; }

.spinner { width: 40px; height: 40px; margin: 32px auto 0; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.5s; } .poster { transition: none; } }

/* ---------- Treffer ---------- */
.notice { padding: 12px 14px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); font-size: 14px; display: grid; gap: 10px; }
.notice.warn { border-color: var(--accent); }
.notice.ok { border-color: var(--ok); }
.notice strong { font-size: 16px; }
.notice .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.results { display: grid; gap: 8px; }
.result {
  display: grid; grid-template-columns: 56px 1fr; gap: 12px; align-items: center;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px; text-align: left; cursor: pointer; width: 100%;
}
.result:hover { border-color: var(--accent); }
.result .poster { border-radius: 6px; }
.result .t { font-weight: 600; overflow-wrap: anywhere; }
.result .s { font-size: 13px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 2px; }
.have { color: var(--ok); font-weight: 600; }

/* ---------- Formular ---------- */
.form-top { display: grid; grid-template-columns: 110px 1fr; gap: 14px; align-items: start; }
.cover-edit { display: grid; gap: 8px; justify-items: stretch; }
.cover-edit .btn { width: 100%; white-space: normal; text-align: center; }
.form-fields { display: grid; gap: 12px; min-width: 0; }
.seg { border: none; padding: 0; margin: 0; display: flex; gap: 6px; flex-wrap: wrap; }
.seg legend { font-size: 13px; color: var(--muted); padding: 0; margin-bottom: 4px; }
.seg label { flex: 1; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; min-height: 0; }
.seg span { display: grid; place-items: center; min-height: 44px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface-2); color: var(--text); font-size: 14px; cursor: pointer; white-space: nowrap; }
.seg input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Details ---------- */
.detail { display: grid; gap: 16px; }
@media (min-width: 640px) { .detail { grid-template-columns: 220px 1fr; } }
.detail .poster { max-width: 220px; margin: 0 auto; }
.detail h3 { font-size: 22px; line-height: 1.2; overflow-wrap: anywhere; }
.detail .sub { color: var(--muted); font-size: 14px; }
.detail .info { display: grid; gap: 12px; align-content: start; min-width: 0; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.tag { padding: 2px 9px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); font-size: 12px; }
.detail dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 14px; }
.detail dt { color: var(--muted); }
.detail dd { margin: 0; overflow-wrap: anywhere; }
.detail .plot { font-size: 14px; color: #d5d8e0; }
.detail .actions { display: flex; gap: 8px; flex-wrap: wrap; }

#toast {
  position: fixed; left: 50%; top: auto; right: auto; margin: 0;
  bottom: calc(92px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #000d; border: 1px solid var(--line); color: var(--text); padding: 10px 16px; border-radius: 999px;
  font-size: 14px; z-index: 100; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100vw - 32px); text-align: center;
}
#toast.show { opacity: 1; }
