:root {
  --bg: #f4f1fa;
  --bg-2: #ebe5f7;
  --card: #ffffff;
  --text: #1d1730;
  --muted: #6b6383;
  --line: #e1dbef;
  --accent: #7c3aed;
  --accent-2: #f59e0b;
  --accent-text: #ffffff;
  --win: #16a34a;
  --win-bg: #dcfce7;
  --fail: #dc2626;
  --fail-bg: #fee2e2;
  --shadow: 0 1px 2px rgb(29 23 48 / 6%), 0 4px 16px rgb(29 23 48 / 6%);
  --radius: 16px;
  --tabbar-h: 64px;
  color-scheme: light;
}

/* Dunkel: automatisch nach Systemeinstellung (außer "Hell" gewählt) oder fest per data-theme="dark".
   Beide Blöcke müssen gleich bleiben. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #120d20;
    --bg-2: #1b1430;
    --card: #1e1733;
    --text: #f1edfb;
    --muted: #a49cbd;
    --line: #2f2648;
    --accent: #a78bfa;
    --accent-2: #fbbf24;
    --accent-text: #160f28;
    --win: #4ade80;
    --win-bg: #12301f;
    --fail: #f87171;
    --fail-bg: #3a1618;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 16px rgb(0 0 0 / 25%);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #120d20;
  --bg-2: #1b1430;
  --card: #1e1733;
  --text: #f1edfb;
  --muted: #a49cbd;
  --line: #2f2648;
  --accent: #a78bfa;
  --accent-2: #fbbf24;
  --accent-text: #160f28;
  --win: #4ade80;
  --win-bg: #12301f;
  --fail: #f87171;
  --fail-bg: #3a1618;
  --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 16px rgb(0 0 0 / 25%);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

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, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
}

body.no-scroll { overflow: hidden; }

button, input, textarea, select { font: inherit; color: inherit; }

button { cursor: pointer; }

button:disabled { cursor: default; opacity: .6; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

[hidden] { display: none !important; }

.boot, .loading { padding: 32px 16px; text-align: center; color: var(--muted); }

/* ------------------------------------------------------------ Grundgerüst */

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 20px; letter-spacing: -.02em; }

.logo { font-size: 24px; }

.topbar-right { display: flex; align-items: center; gap: 6px; min-width: 0; }

.me-chip {
  display: flex; align-items: center; gap: 8px; max-width: 180px; min-width: 0;
  padding: 4px 12px 4px 4px; border-radius: 999px;
  background: var(--card); border: 1px solid var(--line);
}

.me-chip span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.content {
  max-width: 640px; margin: 0 auto;
  padding: 16px 16px calc(var(--tabbar-h) + 32px + env(safe-area-inset-bottom));
}

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card);
  border-top: 1px solid var(--line);
}

.tab {
  flex: 1; max-width: 128px; height: var(--tabbar-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 12px; font-weight: 600;
}

.tab { position: relative; }

.tab-badge {
  position: absolute; top: 6px; left: calc(50% + 6px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--fail); color: #fff; font-size: 11px; font-weight: 800; line-height: 18px; text-align: center;
}

.tab-icon { font-size: 22px; line-height: 1; filter: grayscale(1); opacity: .7; transition: transform .15s; }

.tab.active { color: var(--accent); }

.tab.active .tab-icon { filter: none; opacity: 1; transform: translateY(-2px) scale(1.1); }

.page-title { margin: 4px 0 12px; font-size: 26px; letter-spacing: -.02em; overflow-wrap: anywhere; }

.lead { margin: -4px 0 16px; color: var(--muted); }

.hint { color: var(--muted); font-size: 14px; margin: 10px 0; }

/* ------------------------------------------------------------ Bausteine */

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px;
}

.empty { text-align: center; padding: 32px 16px; }

.empty-icon { font-size: 40px; }

.boot-error { max-width: 420px; margin: 64px auto; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 18px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); font-weight: 600;
}

.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

.btn.danger { color: var(--fail); border-color: color-mix(in srgb, var(--fail) 40%, var(--line)); }

.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; }

.btn.wide { width: 100%; margin: 4px 0 12px; }

.icon-btn {
  min-width: 40px; min-height: 40px; border: 0; background: transparent; border-radius: 10px; font-size: 18px;
}

.icon-btn:hover { background: var(--bg-2); }

.linkish { border: 0; background: none; padding: 0; font-weight: 700; text-align: left; }

.linkish:hover { text-decoration: underline; }

.avatar {
  --hue: 260;
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 50%;
  background: hsl(var(--hue) 65% 52%); color: #fff;
  font-weight: 700; font-size: 14px; letter-spacing: -.02em;
}

.me-chip .avatar { width: 30px; height: 30px; font-size: 12px; }

.avatar.big { width: 64px; height: 64px; font-size: 24px; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }

.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: none; padding: 7px 14px; border-radius: 999px; font-size: 14px; font-weight: 600;
  border: 1px solid var(--line); background: var(--card); color: var(--muted);
}

.chip.on { background: var(--text); border-color: var(--text); color: var(--bg); }

.seg { display: flex; gap: 4px; padding: 4px; margin-bottom: 16px; border-radius: 12px; background: var(--bg-2); }

.seg button {
  flex: 1; min-height: 40px; border: 0; border-radius: 9px; background: transparent;
  font-weight: 700; color: var(--muted);
}

.seg button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

.seg button.on.win { color: var(--win); }

.seg button.on.fail { color: var(--fail); }

.field { display: block; margin-bottom: 14px; min-width: 0; }

.field > span:first-child { display: block; margin-bottom: 6px; font-size: 14px; font-weight: 600; color: var(--muted); }

.field input, .field textarea, select {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--bg);
}

.field textarea { resize: vertical; min-height: 96px; }

.field input:focus, .field textarea:focus, select:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }

.form-error {
  margin: 0 0 12px; padding: 10px 12px; border-radius: 10px;
  background: var(--fail-bg); color: var(--fail); font-weight: 600; font-size: 14px;
}

.image-drop {
  width: 100%; min-height: 110px; border-radius: 12px; border: 2px dashed var(--line); background: var(--bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; color: var(--muted); font-weight: 600;
}

.image-drop:hover { border-color: var(--accent); color: var(--accent); }

.image-drop-icon { font-size: 30px; }

.image-preview img { display: block; width: 100%; max-height: 360px; object-fit: cover; border-radius: 12px; background: var(--bg-2); }

.image-actions { display: flex; gap: 8px; margin-top: 8px; }

/* ------------------------------------------------------------ Login */

.auth { max-width: 420px; margin: 0 auto; padding: calc(8px + env(safe-area-inset-top)) 16px 32px; }

.auth-top { display: flex; justify-content: flex-end; gap: 4px; min-height: 40px; margin-bottom: 8px; }

.lang-btn { font-size: 13px; font-weight: 800; letter-spacing: .04em; color: var(--muted); }

.pending-note { margin-top: -4px; }

.card-title { margin: 0 0 12px; font-size: 16px; }

.card .seg:last-child { margin-bottom: 0; }

.hero { text-align: center; margin-bottom: 20px; }

.hero-logo {
  width: 84px; height: 84px; margin: 0 auto 8px; border-radius: 24px; font-size: 48px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: var(--shadow);
}

.hero h1 { margin: 0; font-size: 34px; letter-spacing: -.03em; }

.hero p { margin: 6px 0 0; color: var(--muted); }

.legal-link { text-align: center; font-size: 13px; }

.legal-link a { color: var(--muted); }

/* ------------------------------------------------------------ Datenschutz (datenschutz.html) */

.legal {
  max-width: 640px; margin: 0 auto; line-height: 1.55; overflow-wrap: anywhere;
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(32px + env(safe-area-inset-bottom));
}

.legal-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 40px; }

.legal-top .linkish { color: var(--muted); font-size: 14px; }

.legal h2 { font-size: 18px; margin: 24px 0 8px; }

.legal .card h2 { margin-top: 0; }

.legal ul { padding-left: 20px; }

.legal li { margin-bottom: 6px; }

.legal a { color: var(--accent); }

/* ------------------------------------------------------------ Ranking */

.awards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 4px 0 14px; }

@media (min-width: 560px) { .awards { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

.award {
  padding: 12px; border-radius: var(--radius); text-align: center; min-width: 0;
  background: linear-gradient(160deg, color-mix(in srgb, var(--accent) 16%, var(--card)), var(--card));
  border: 1px solid var(--line);
}

.award-icon { font-size: 26px; }

.award-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }

.award-who { font-weight: 800; overflow-wrap: anywhere; }

.award-value { font-size: 13px; color: var(--muted); }

.ranklist { list-style: none; margin: 0; padding: 0; }

.rank-row {
  width: 100%; display: flex; align-items: center; gap: 10px; text-align: left;
  padding: 12px; margin-bottom: 8px; border-radius: var(--radius);
  background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow);
}

.rank-row:hover { border-color: var(--accent); }

.rank-row.mine { border-color: color-mix(in srgb, var(--accent) 60%, var(--line)); background: color-mix(in srgb, var(--accent) 7%, var(--card)); }

.rank-row.dim { opacity: .6; }

.place { flex: none; width: 30px; text-align: center; font-weight: 800; font-size: 18px; color: var(--muted); }

.rank-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }

.rank-name { display: flex; align-items: center; gap: 6px; font-weight: 700; min-width: 0; overflow: hidden; white-space: nowrap; }

.you { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 6px; background: var(--accent); color: var(--accent-text); }

.streak { font-size: 13px; font-weight: 700; color: var(--accent-2); }

.pill { flex: none; font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 6px; white-space: nowrap; }

.new-badge { background: var(--accent-2); color: #1d1730; letter-spacing: .03em; }

.verified-badge { background: var(--win-bg); color: var(--win); }

.admin-badge { background: var(--accent); color: var(--accent-text); }

.hidden-badge { background: var(--bg-2); color: var(--muted); }

.admin-public { flex: none; font-size: 14px; }

.larp-who-row { display: flex; align-items: center; gap: 6px; min-width: 0; }

.admin-user.is-new { border-left: 4px solid var(--accent-2); }

.admin-user.is-deleted { border-left: 4px solid var(--muted); background: var(--bg-2); }

.deleted-badge { background: var(--muted); color: var(--card); }

.admin-name { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; font-weight: 700; }

.admin-stats, .admin-votes { margin: 8px 0 0; font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }

.admin-votes b { color: var(--text); }

.admin-votes .pill { margin-left: 4px; }

.admin-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.admin-actions:empty { display: none; }

.admin-warning {
  margin: 8px 0 0; padding: 6px 10px; border-radius: 8px; font-size: 14px; font-weight: 600;
  background: color-mix(in srgb, var(--accent-2) 18%, var(--card)); color: var(--text);
}

.more-votes { font-weight: 600; color: var(--accent); font-size: 14px; }

.admin-search, .picker-input {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--card);
}

.admin-search { margin-bottom: 12px; }

.admin-search:focus, .picker-input:focus {
  border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}

/* Personensuche */
.picker { position: relative; }

.field .picker-input { background: var(--bg); }

.picker-list {
  position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px);
  margin: 0; padding: 4px; list-style: none; max-height: 320px; overflow-y: auto;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
}

.picker-option { padding: 10px 12px; border-radius: 8px; cursor: pointer; }

.picker-option:hover { background: var(--bg-2); }

.picker-option.on { font-weight: 700; color: var(--accent); }

.picker-more { padding: 8px 12px; font-size: 13px; color: var(--muted); }

.feed-filters .picker { flex: 1 1 180px; max-width: 260px; margin-bottom: 10px; }

.feed-filters .picker-input { min-height: 36px; padding: 6px 10px; }

/* Ranking: Lücke zur eigenen Zeile + Umschalter */
.rank-gap { text-align: center; color: var(--muted); font-weight: 800; letter-spacing: .2em; margin: -2px 0 6px; }

.rank-toggle { margin-top: 0; }

.rank-stats { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.ratebar { display: block; height: 6px; border-radius: 3px; background: var(--fail-bg); overflow: hidden; }

.ratebar-win { display: block; height: 100%; background: var(--win); border-radius: 3px; }

.rank-big { flex: none; font-size: 20px; font-weight: 800; min-width: 44px; text-align: right; }

/* ------------------------------------------------------------ Feed */

.feed-filters { display: flex; flex-wrap: wrap; gap: 0 10px; align-items: flex-start; }

.feed-filters .chips { flex: 1 1 auto; }

.feed-filters select { width: auto; max-width: 100%; min-height: 36px; padding: 6px 10px; margin-bottom: 10px; background: var(--card); }

.larp { border-left: 4px solid var(--win); position: relative; }

.larp.unseen { box-shadow: 0 0 0 2px var(--accent), var(--shadow); }

.unseen-badge { position: absolute; top: -9px; left: 16px; background: var(--accent); color: var(--accent-text); }

.larp.is-fail { border-left-color: var(--fail); }

.larp-head { display: flex; align-items: center; gap: 10px; }

.larp-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.larp-who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }

.larp-date { font-size: 13px; color: var(--muted); }

.badge { flex: none; font-size: 12px; font-weight: 700; padding: 4px 8px; border-radius: 8px; }

.badge.win { background: var(--win-bg); color: var(--win); }

.badge.fail { background: var(--fail-bg); color: var(--fail); }

.larp-title { margin: 12px 0 4px; font-size: 18px; overflow-wrap: anywhere; }

.pending {
  display: inline-block; margin: 0 0 8px; padding: 3px 8px; border-radius: 8px;
  font-size: 12px; font-weight: 600; color: var(--muted); background: var(--bg-2);
}

.larp-story { margin: 0 0 8px; white-space: pre-wrap; overflow-wrap: anywhere; }

.larp-image { display: block; width: 100%; padding: 0; margin: 8px 0; border: 0; border-radius: 12px; overflow: hidden; background: var(--bg-2); }

.larp-image img { display: block; width: 100%; max-height: 420px; object-fit: cover; }

.larp-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; flex-wrap: wrap; }

.reactions { display: flex; gap: 6px; flex-wrap: wrap; }

.react {
  min-height: 36px; padding: 4px 10px; border-radius: 999px; font-size: 16px;
  border: 1px solid var(--line); background: var(--bg); display: inline-flex; align-items: center; gap: 4px;
}

.react.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 15%, var(--card)); }

.react .count { font-size: 13px; font-weight: 700; }

.larp-actions { display: flex; gap: 2px; margin-left: auto; }

/* Geglückte Larps: Votes + Aktionen oben, Reaktionen in eigener Zeile darunter */
.larp-foot .vote + .reactions { order: 3; flex-basis: 100%; }

.vote {
  display: inline-flex; align-items: center; border-radius: 999px;
  border: 1px solid var(--line); background: var(--bg); overflow: hidden;
}

.vote-btn {
  min-height: 36px; padding: 4px 10px; border: 0; background: transparent; font-size: 16px;
  display: inline-flex; align-items: center; gap: 4px;
}

.vote-btn .count { font-size: 13px; font-weight: 700; }

.vote-btn:disabled { opacity: .55; }

.vote-btn.up.on { background: var(--win-bg); color: var(--win); }

.vote-btn.down.on { background: var(--fail-bg); color: var(--fail); }

.vote-score {
  min-width: 34px; padding: 0 4px; text-align: center; font-weight: 800; font-size: 14px;
  border-left: 1px solid var(--line); border-right: 1px solid var(--line); line-height: 36px; color: var(--muted);
}

.vote-score.pos { color: var(--win); }

.vote-score.neg { color: var(--fail); }

/* ------------------------------------------------------------ Profil */

.profile-head { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }

.profile-head .page-title { margin: 0; }

.profile-head .hint { margin: 2px 0 0; }

.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }

.tile { padding: 12px 6px; border-radius: 14px; text-align: center; background: var(--card); border: 1px solid var(--line); }

.tile-value { font-size: 22px; font-weight: 800; }

.tile-label { font-size: 12px; color: var(--muted); font-weight: 600; }

details.card { padding: 0; }

details.card summary { padding: 14px 16px; font-weight: 700; cursor: pointer; list-style-position: inside; }

details.card > :not(summary) { margin-left: 16px; margin-right: 16px; }

details.card > form { padding-bottom: 16px; }

.rules { padding-left: 18px; padding-bottom: 12px; }

.rules li { margin-bottom: 6px; }

.danger-zone summary { color: var(--fail); }

/* ------------------------------------------------------------ Overlays */

.overlay {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center;
  background: rgb(10 6 20 / 55%);
}

.modal {
  width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  background: var(--card); border-radius: 20px 20px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
}

@media (min-width: 600px) {
  .overlay { align-items: center; }
  .modal { border-radius: 20px; }
}

.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }

.modal-head h2 { margin: 0; font-size: 20px; }

.lightbox {
  position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center;
  background: rgb(0 0 0 / 90%); cursor: zoom-out; padding: 16px;
}

.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px; }

.toasts {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom)); z-index: 70;
  transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center;
  width: max-content; max-width: calc(100vw - 32px); pointer-events: none;
}

.toast {
  padding: 10px 16px; border-radius: 12px; background: var(--text); color: var(--bg);
  font-weight: 600; font-size: 14px; box-shadow: var(--shadow); transition: opacity .3s, transform .3s;
}

.toast.out { opacity: 0; transform: translateY(8px); }
