:root {
  --bg: #0f1512;
  --surface: #171e1a;
  --surface-2: #1f2822;
  --border: #2b362f;
  --text: #ecf1ee;
  --muted: #93a39a;
  --green: #1f9a5b;
  --green-soft: rgba(31, 154, 91, .16);
  --red: #d2453d;
  --red-soft: rgba(210, 69, 61, .16);
  --gold: #e3b341;
  --gold-soft: rgba(227, 179, 65, .16);
  --radius: 14px;
  --shadow: 0 8px 30px rgba(0, 0, 0, .35);
  --nav-h: 64px;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f5f3;
    --surface: #ffffff;
    --surface-2: #f0f3f1;
    --border: #dde3df;
    --text: #18201b;
    --muted: #5f6e66;
    --green: #17834c;
    --green-soft: rgba(23, 131, 76, .12);
    --red: #c0372f;
    --red-soft: rgba(192, 55, 47, .1);
    --gold: #a77a0c;
    --gold-soft: rgba(227, 179, 65, .2);
    --shadow: 0 8px 30px rgba(0, 0, 0, .12);
    color-scheme: light;
  }
}

* { 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, sans-serif;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- Topbar & Navigation ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; gap: 10px; align-items: center; text-decoration: none; min-width: 0; }
.brand span { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand strong { font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand small { color: var(--muted); font-size: .78rem; }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  text-decoration: none; color: var(--muted); font-size: .74rem; font-weight: 600;
}
.nav svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.nav a.active { color: var(--green); }

@media (min-width: 760px) {
  body { padding-bottom: 32px; }
  .nav {
    position: static; display: flex; gap: 4px; height: auto; padding: 0;
    background: none; border: 0;
  }
  .nav a { flex-direction: row; gap: 7px; font-size: .92rem; padding: 8px 14px; border-radius: 999px; }
  .nav a:hover { background: var(--surface-2); color: var(--text); }
  .nav a.active { background: var(--green-soft); }
  .nav svg { width: 18px; height: 18px; }
}

/* ---------- Layout ---------- */
.container { max-width: 980px; margin: 0 auto; padding: 16px; }
.loading { padding: 60px 0; text-align: center; color: var(--muted); }
h1 { font-size: 1.45rem; margin: 6px 0 4px; }
h2 { font-size: 1.12rem; margin: 22px 0 10px; }
.sub { color: var(--muted); margin: 0 0 16px; font-size: .92rem; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mode-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: .8rem; font-weight: 600; color: var(--muted);
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 4px 10px; border-radius: 999px;
}
.page-head { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: end; justify-content: space-between; margin-bottom: 14px; }

/* ---------- Buttons & Formulare ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 8px 16px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2);
  font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.danger { background: var(--red-soft); border-color: transparent; color: var(--red); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 34px; padding: 4px 12px; font-size: .88rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.block { width: 100%; }

label.field { display: block; }
label.field > span { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
input[type=text], input[type=password], input[type=date], select, textarea {
  width: 100%; min-height: 44px; padding: 9px 12px;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2);
}
textarea { min-height: 130px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--green); outline-offset: 1px; }
.grid-2 { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 600px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip-radio input { position: absolute; opacity: 0; pointer-events: none; }
.chip-radio span {
  display: inline-block; padding: 8px 14px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2); font-weight: 600; font-size: .9rem;
}
.chip-radio input:checked + span { background: var(--green-soft); border-color: var(--green); color: var(--green); }
.chip-radio input:focus-visible + span { outline: 2px solid var(--green); }

/* ---------- Tabelle ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); }
table.league { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.league th, table.league td { padding: 10px 8px; text-align: center; white-space: nowrap; }
table.league th { font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); border-bottom: 1px solid var(--border); background: var(--surface-2); }
table.league td { border-bottom: 1px solid var(--border); }
table.league tr:last-child td { border-bottom: 0; }
table.league .name { text-align: left; width: 100%; font-weight: 600; }
table.league .name a { text-decoration: none; }
table.league .name a:hover { text-decoration: underline; }
table.league tbody tr { cursor: pointer; }
table.league tbody tr:hover { background: var(--surface-2); }
.rank { font-weight: 700; width: 34px; }
.rank-badge { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; font-size: .85rem; }
tr.top1 .rank-badge { background: var(--gold-soft); color: var(--gold); }
tr.top2 .rank-badge, tr.top3 .rank-badge { background: var(--green-soft); color: var(--green); }
.pts { font-weight: 800; font-size: 1.02rem; }
.pos { color: var(--green); }
.neg { color: var(--red); }
.form { display: inline-flex; gap: 3px; }
.form i { width: 18px; height: 18px; border-radius: 5px; font-style: normal; font-size: .68rem; font-weight: 800; display: grid; place-items: center; color: #fff; }
.form i.S { background: var(--green); }
.form i.N { background: var(--red); }
.hide-sm { display: none; }
@media (min-width: 600px) { .hide-sm { display: table-cell; } }
.legend { font-size: .8rem; color: var(--muted); margin-top: 10px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
@media (min-width: 600px) { .stats { grid-template-columns: repeat(6, 1fr); } }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px; text-align: center; }
.stat b { display: block; font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.stat span { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* ---------- Spieltage ---------- */
.md-picker { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; }
.md-scroll { display: flex; gap: 6px; overflow-x: auto; padding: 4px 2px; scrollbar-width: thin; flex: 1; scroll-behavior: smooth; }
.md-chip {
  flex: 0 0 auto; min-width: 42px; height: 42px; padding: 0 10px; border-radius: 10px;
  display: grid; place-items: center; font-weight: 700; text-decoration: none;
  background: var(--surface); border: 1px solid var(--border); position: relative;
}
.md-chip.done { color: var(--muted); }
.md-chip.active { background: var(--green); border-color: var(--green); color: #fff; }
.md-chip.current:not(.active)::after { content: ""; position: absolute; top: 5px; right: 5px; width: 7px; height: 7px; border-radius: 50%; background: var(--gold); }
.md-arrow { flex: 0 0 auto; width: 42px; height: 42px; padding: 0; }

.md-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.md-head h1 { margin: 0; }
.progress { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 6px 0 16px; }
.progress > div { height: 100%; background: var(--green); border-radius: 99px; transition: width .3s; }

.matches { display: grid; gap: 10px; }
@media (min-width: 760px) { .matches { grid-template-columns: 1fr 1fr; } }
.match { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.match-top { display: flex; justify-content: space-between; align-items: center; font-size: .78rem; color: var(--muted); margin-bottom: 8px; font-weight: 600; }
.match-body { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; }
.player { font-weight: 700; overflow-wrap: anywhere; }
.player.p2 { text-align: right; }
.player small { display: block; font-weight: 500; color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; }
.player.winner { color: var(--green); }
.player.loser { color: var(--muted); }
.score { font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: .02em; min-width: 72px; text-align: center; }
.score.empty { font-size: .95rem; font-weight: 700; color: var(--muted); }
.match-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.match-actions .btn { flex: 1; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: .72rem; font-weight: 700; }
.badge.open { background: var(--surface-2); color: var(--muted); }
.badge.reported { background: var(--gold-soft); color: var(--gold); }
.badge.forfeit { background: var(--red-soft); color: var(--red); }
.badge.confirmed { background: var(--green-soft); color: var(--green); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .55);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .15s ease;
}
.modal {
  width: 100%; max-width: 520px; max-height: 92vh; overflow-y: auto;
  background: var(--surface); border-radius: 18px 18px 0 0; padding: 18px 16px;
  padding-bottom: calc(18px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow); animation: up .2s ease;
}
@media (min-width: 600px) {
  .modal-backdrop { align-items: center; }
  .modal { border-radius: 18px; padding: 22px; }
}
.confirm-layer { z-index: 70; }
.confirm-layer .modal { max-width: 420px; }
.modal h3 { margin: 0 0 4px; font-size: 1.15rem; }
.modal .close { float: right; border: 0; background: none; font-size: 1.6rem; line-height: 1; cursor: pointer; color: var(--muted); padding: 0 4px; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }

.vs-head { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: center; text-align: center; font-weight: 700; margin: 14px 0 10px; }
.vs-head .vs { color: var(--muted); font-size: .8rem; }
.result-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.result-grid .lbl { grid-column: 1 / -1; font-size: .78rem; font-weight: 700; color: var(--muted); margin-top: 4px; }
.res-btn {
  height: 54px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2);
  font-size: 1.25rem; font-weight: 800; cursor: pointer; font-variant-numeric: tabular-nums;
}
.res-btn.sel { background: var(--green); border-color: var(--green); color: #fff; }
.summary { margin: 14px 0; padding: 12px; border-radius: 12px; background: var(--green-soft); color: var(--green); font-weight: 700; text-align: center; }
.warn { padding: 10px 12px; border-radius: 10px; background: var(--gold-soft); color: var(--gold); font-size: .86rem; font-weight: 600; }

/* ---------- Feedback / Admin ---------- */
.fb-item { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.fb-item.neu { border-left: 4px solid var(--gold); }
.fb-item.erledigt { opacity: .65; }
.fb-msg { white-space: pre-wrap; overflow-wrap: anywhere; margin: 8px 0; }
.tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 16px; padding-bottom: 2px; }
.tabs a { flex: 0 0 auto; padding: 8px 14px; border-radius: 999px; text-decoration: none; font-weight: 600; font-size: .9rem; background: var(--surface); border: 1px solid var(--border); }
.tabs a.active { background: var(--green); border-color: var(--green); color: #fff; }
.count { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 99px; background: var(--gold); color: #000; font-size: .72rem; margin-left: 4px; }
.admin-md { margin-bottom: 14px; }
.admin-md summary { cursor: pointer; font-weight: 700; padding: 4px 0; list-style: none; display: flex; align-items: center; gap: 8px; }
.admin-md summary::-webkit-details-marker { display: none; }
.admin-md summary::before { content: "▸"; color: var(--muted); transition: transform .15s; }
.admin-md[open] summary::before { transform: rotate(90deg); }
.admin-list { display: grid; gap: 6px; margin-top: 10px; }
.admin-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); font-size: .92rem; }
.player-edit { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.empty-state { text-align: center; padding: 40px 16px; color: var(--muted); }

/* ---------- Playoffs ---------- */
tr.zone-po td:first-child { box-shadow: inset 4px 0 0 var(--green); }
tr.zone-pi td:first-child { box-shadow: inset 4px 0 0 var(--gold); }
.zone-key { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: -1px; }
.zone-key.po { background: var(--green); }
.zone-key.pi { background: var(--gold); }

.md-chip.po-chip { padding: 0 14px; white-space: nowrap; }
.md-chip.po-chip:not(.active) { border-color: var(--gold); color: var(--gold); }
.md-chip.po-chip.active { background: var(--gold); border-color: var(--gold); color: #1b1400; }

.po-champ {
  display: flex; align-items: center; gap: 14px; margin-bottom: 18px; padding: 16px 18px;
  border-radius: var(--radius); background: var(--gold-soft); border: 1px solid var(--gold); font-size: 2rem;
}
.po-champ small { display: block; font-size: .78rem; color: var(--gold); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.po-champ strong { font-size: 1.4rem; }

.seed-grid { display: grid; gap: 6px; grid-template-columns: 1fr; }
@media (min-width: 600px) { .seed-grid { grid-template-columns: 1fr 1fr; } }
.seed-row { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); }
.seed-row.out { opacity: .6; }
.seed-row .po-name { flex: 1; font-weight: 600; }
.seed-edit { display: grid; gap: 10px; grid-template-columns: 1fr; }
@media (min-width: 600px) { .seed-edit { grid-template-columns: 1fr 1fr; } }

.po-seed {
  display: inline-grid; place-items: center; min-width: 24px; height: 24px; border-radius: 6px;
  background: var(--surface-2); color: var(--muted); font-size: .78rem; font-weight: 800; font-variant-numeric: tabular-nums;
}
.po-match { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; }
.po-match.final { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold-soft); }
.po-head { display: flex; justify-content: space-between; align-items: center; gap: 6px; font-size: .76rem; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.po-row { display: flex; align-items: center; gap: 8px; padding: 5px 0; }
.po-row + .po-row { border-top: 1px dashed var(--border); }
.po-row .po-name { flex: 1; font-weight: 600; overflow-wrap: anywhere; }
.po-row .po-legs { font-size: 1.1rem; font-variant-numeric: tabular-nums; min-width: 18px; text-align: right; }
.po-row.win .po-name, .po-row.win .po-legs { color: var(--green); }
.po-row.win .po-seed { background: var(--green-soft); color: var(--green); }
.po-row.lose { opacity: .55; }
.po-notes { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; font-size: .74rem; color: var(--muted); }
.po-actions { display: flex; gap: 6px; margin-top: 8px; }
.po-actions .btn.primary { flex: 1; }

.po-playin { display: grid; gap: 10px; grid-template-columns: 1fr; }
@media (min-width: 760px) { .po-playin { grid-template-columns: repeat(3, 1fr); } }

.bracket { display: grid; gap: 12px; grid-template-columns: 1fr; }
.br-col { display: flex; flex-direction: column; gap: 8px; }
.br-games { display: flex; flex-direction: column; gap: 10px; flex: 1; }
.br-title { font-size: .78rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-top: 6px; }
.po-seed:empty { visibility: hidden; }
@media (min-width: 760px) {
  .bracket { grid-template-columns: repeat(3, 1fr); gap: 18px; }
  .br-games { justify-content: space-around; }
  .br-title { text-align: center; margin: 0; }
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 20px + env(safe-area-inset-bottom)); z-index: 60;
  transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600;
  transition: all .2s; max-width: calc(100% - 32px); text-align: center; box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--red); color: #fff; }
@media (min-width: 760px) { .toast { bottom: 24px; } }
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--green); margin-right: 5px; animation: pulse 2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
