:root {
  color-scheme: light;
  --page: #edf2f9;
  --surface: #ffffff;
  --surface-2: #e8eef7;
  --ink: #0a1628;
  --ink-2: #44506a;
  --muted: #6d7a92;
  --grid: #dde4ef;
  --axis: #b7c3d6;
  --border: rgba(10, 40, 100, 0.10);
  --head-1: #062a66;
  --head-2: #0b4aa6;
  --on-head: #ffffff;
  --on-head-2: rgba(255, 255, 255, 0.75);
  --accent: #0b5cc4;
  --accent-ink: #ffffff;
  --accent-btn: #0b5cc4;
  --gold: #f5c542;
  --good: #006300;
  --bad: #b3261e;
  --p1: #2a78d6;
  --p2: #eb6834;
  --p3: #1baf7a;
  --wm-opacity: .08;
  --shadow: 0 1px 2px rgba(6, 42, 102, .06), 0 6px 18px rgba(6, 42, 102, .07);
  --radius: 16px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #07101f;
    --surface: #0f1b2e;
    --surface-2: #17263d;
    --ink: #ffffff;
    --ink-2: #c2cde0;
    --muted: #8595ae;
    --grid: #1d2d46;
    --axis: #2c4062;
    --border: rgba(160, 190, 255, 0.12);
    --head-1: #061a3d;
    --head-2: #0b2f6b;
    --accent: #4d94ff;
    --accent-ink: #ffffff;
    --accent-btn: #2f74e0;
    --good: #3ccf6e;
    --bad: #ff7b72;
    --p1: #3987e5;
    --p2: #d95926;
    --p3: #199e70;
    --wm-opacity: .10;
    --shadow: none;  }
}
:root[data-theme="dark"] {
    color-scheme: dark;
    --page: #07101f;
    --surface: #0f1b2e;
    --surface-2: #17263d;
    --ink: #ffffff;
    --ink-2: #c2cde0;
    --muted: #8595ae;
    --grid: #1d2d46;
    --axis: #2c4062;
    --border: rgba(160, 190, 255, 0.12);
    --head-1: #061a3d;
    --head-2: #0b2f6b;
    --accent: #4d94ff;
    --accent-ink: #ffffff;
    --accent-btn: #2f74e0;
    --good: #3ccf6e;
    --bad: #ff7b72;
    --p1: #3987e5;
    --p2: #d95926;
    --p3: #199e70;
    --wm-opacity: .10;
    --shadow: none;}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.45;
  min-height: 100vh;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; line-height: 1.2; }

/* ---------- Header ---------- */
.top {
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, .055) 0 22px, transparent 22px 44px),
    linear-gradient(160deg, var(--head-1) 0%, var(--head-2) 100%);
  color: var(--on-head);
  padding-top: env(safe-area-inset-top);
  position: sticky;
  top: 0;
  z-index: 10;
}
.top-inner, .tabs, main { max-width: 760px; margin: 0 auto; }
.top-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 6px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-ball { width: 34px; height: 34px; flex: none; }
.brand h1 { font-size: 19px; font-weight: 700; letter-spacing: -.01em; }
.sub { margin: 1px 0 0; font-size: 13px; color: var(--on-head-2); }
.icon-btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid rgba(255, 255, 255, .25);
  background: rgba(255, 255, 255, .08);
  color: var(--on-head);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 600;
}
.icon-btn svg { width: 16px; height: 16px; }
.tabs { display: flex; gap: 4px; padding: 6px 12px 0; }
.tabs a {
  color: var(--on-head-2);
  text-decoration: none;
  font-weight: 600;
  font-size: 15px;
  padding: 10px 12px 12px;
  border-bottom: 3px solid transparent;
}
.tabs a[aria-selected="true"] { color: var(--on-head); border-bottom-color: #fff; }

main { padding: 16px; }
.loading, .empty { color: var(--muted); text-align: center; padding: 40px 0; }

/* ---------- Cards ---------- */
.section { margin-bottom: 22px; }
.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 0 2px 10px;
}
.section-head h2 { font-size: 17px; font-weight: 700; }
.section-head .hint { font-size: 13px; color: var(--muted); }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* Ranking */
.ranking { display: grid; gap: 10px; }
.crest { width: 18px; height: 18px; object-fit: contain; flex: none; display: inline-block; vertical-align: -4px; }
.crest.md { width: 28px; height: 28px; }
.crest.lg { width: 38px; height: 38px; }

/* PIN-Sperre: ohne Anmeldung nur das Formular */
body.locked .tabs, body.locked .fab, body.locked #lockBtn { display: none; }
.gate { max-width: 360px; margin: 32px auto; padding: 28px 22px 22px; text-align: center; }
.gate-lock { width: 40px; height: 40px; color: var(--accent); margin-bottom: 8px; }
.gate h2 { font-size: 20px; margin-bottom: 8px; }
.gate .pin-input { margin-bottom: 12px; }
.gate .btn { width: 100%; }
.swatch { width: 14px; height: 3px; border-radius: 2px; display: inline-block; flex: none; }
.rank-text { min-width: 0; }
.rank-club { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-top: 1px; }
.rank {
  display: grid;
  grid-template-columns: 36px 38px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
}
.rank-pos {
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 800; font-size: 16px;
  background: var(--surface-2); color: var(--ink-2);
}
.rank.first .rank-pos { background: var(--gold); color: #3b2a00; }
.rank-name { font-weight: 700; font-size: 17px; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.rank-meta { font-size: 13px; color: var(--ink-2); margin-top: 2px; }
.rank-bal { text-align: right; }
.rank-bal .amt { font-size: 24px; font-weight: 800; letter-spacing: -.02em; }
.rank-bal .lbl { font-size: 12px; color: var(--muted); }
.pos { color: var(--good); }
.neg { color: var(--bad); }
.zero { color: var(--ink-2); }

/* Settlement */
.settle { padding: 4px 0; }
.settle-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
}
.settle-row + .settle-row { border-top: 1px solid var(--grid); }
.flow { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-weight: 600; }
.flow .arrow { color: var(--muted); font-weight: 400; }
.flow .even { color: var(--muted); font-weight: 500; }
.settle-amt { font-weight: 800; font-size: 17px; }
.settle-detail { font-size: 12.5px; color: var(--muted); font-weight: 400; margin-top: 2px; }
details.more { border-top: 1px solid var(--grid); }
details.more summary {
  list-style: none; cursor: pointer;
  padding: 12px 16px; font-size: 14px; font-weight: 600; color: var(--accent);
}
details.more summary::-webkit-details-marker { display: none; }
details.more summary::after { content: " ▾"; }
details.more[open] summary::after { content: " ▴"; }
table.gross { width: 100%; border-collapse: collapse; font-size: 14px; }
table.gross th, table.gross td { padding: 8px 16px; text-align: left; }
table.gross th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
table.gross td.num, table.gross th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.gross tr + tr td { border-top: 1px solid var(--grid); }

/* Chart */
.chart-card { padding: 14px 8px 8px; position: relative; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; padding: 0 10px 8px; font-size: 13px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
svg.chart { display: block; width: 100%; height: auto; overflow: visible; touch-action: pan-y; }
svg.chart text { font-size: 11px; fill: var(--muted); font-variant-numeric: tabular-nums; }
svg.chart .grid { stroke: var(--grid); stroke-width: 1; }
svg.chart .zero-line { stroke: var(--axis); stroke-width: 1; }
svg.chart .series { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
svg.chart .end-label { font-size: 12px; font-weight: 700; fill: var(--ink); }
svg.chart .cross { stroke: var(--axis); stroke-width: 1; }
.tip {
  position: fixed; z-index: 50; pointer-events: none;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .18);
  padding: 8px 10px; font-size: 13px; min-width: 150px;
}
.tip b { display: block; margin-bottom: 4px; }
.tip .r { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.tip .r span:first-child { display: inline-flex; align-items: center; gap: 6px; }
.tip .r span:last-child { font-variant-numeric: tabular-nums; font-weight: 600; }

/* Stats by type */
.types { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.type { padding: 12px 14px; }
.type h3 { font-size: 15px; }
.type .cnt { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.type-row { display: flex; align-items: center; justify-content: space-between; font-size: 14px; padding: 2px 0; }
.type-row span:first-child { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); }
.type-row b { font-variant-numeric: tabular-nums; }

/* ---------- Challenge list ---------- */
.filters { display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px 14px; padding: 0 16px 2px; scrollbar-width: none; }
.chip {
  flex: none;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-2);
}
.chip[aria-pressed="true"] { background: var(--accent-btn); color: var(--accent-ink); border-color: var(--accent-btn); }
.list { display: grid; gap: 8px; }
.day-head { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 12px 4px 2px; }
.item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.item-title { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.item-no { font-size: 12px; color: var(--muted); font-weight: 600; }
.item-players { display: flex; flex-wrap: wrap; gap: 6px; grid-column: 1 / -1; }
.pl {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 13px; padding: 3px 9px 3px 7px; border-radius: 999px;
  background: var(--surface-2); color: var(--ink-2);
}
.pl.win { background: color-mix(in srgb, #f5c542 28%, var(--surface)); color: var(--ink); font-weight: 700; }
.pl.out { opacity: .45; text-decoration: line-through; }
.item-win { font-size: 14px; font-weight: 700; text-align: right; }
.item-win small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; }

/* ---------- FAB ---------- */
.fab {
  position: fixed;
  right: max(16px, calc(50vw - 380px + 16px));
  bottom: calc(18px + env(safe-area-inset-bottom));
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--accent-btn); color: var(--accent-ink);
  border: 0; border-radius: 999px;
  padding: 14px 20px 14px 16px;
  font-weight: 700; font-size: 16px;
  box-shadow: 0 6px 20px rgba(11, 92, 196, .40);
  z-index: 20;
}
.fab svg { width: 22px; height: 22px; }

/* ---------- Sheet (dialog) ---------- */
.sheet {
  border: 0; padding: 0;
  width: min(560px, 100%);
  max-height: 92vh;
  margin: auto auto 0;
  border-radius: 20px 20px 0 0;
  background: var(--surface); color: var(--ink);
}
@media (min-width: 640px) { .sheet { margin: auto; border-radius: 20px; } }
.sheet::backdrop { background: rgba(0, 0, 0, .45); }
.sheet form { padding: 18px 18px calc(18px + env(safe-area-inset-bottom)); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.sheet-head h2 { font-size: 20px; }
.x { border: 0; background: var(--surface-2); width: 34px; height: 34px; border-radius: 50%; font-size: 20px; line-height: 1; }
.field { margin-bottom: 16px; }
.field > label, .field > .lbl { display: block; font-size: 13px; font-weight: 700; color: var(--ink-2); margin-bottom: 6px; }
.input {
  width: 100%; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface-2);
  font-size: 16px;
}
.input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.row2 { display: grid; grid-template-columns: 1fr 110px; gap: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chips .chip { padding: 6px 12px; font-size: 13.5px; }
.toggles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.toggle {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 12px 6px; border-radius: 14px;
  border: 2px solid var(--border); background: var(--surface-2);
  font-weight: 700; font-size: 15px;
}
.toggle .dot { width: 12px; height: 12px; }
.toggle small { font-weight: 500; font-size: 12px; color: var(--muted); }
.toggle[aria-pressed="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }
.toggle[aria-pressed="true"] small { color: var(--accent); }
.toggle.win[aria-pressed="true"] { border-color: #d9a400; background: color-mix(in srgb, #f5c542 26%, var(--surface)); }
.toggle.win[aria-pressed="true"] small { color: var(--ink-2); }
.toggle:disabled { opacity: .35; cursor: not-allowed; }
.preview { font-size: 14px; color: var(--ink-2); background: var(--surface-2); border-radius: 12px; padding: 10px 12px; margin-bottom: 16px; }
.err { color: var(--bad); font-size: 14px; font-weight: 600; min-height: 1.2em; margin: -4px 0 10px; }
.actions { display: flex; gap: 10px; }
.btn {
  flex: 1; padding: 14px; border-radius: 14px; border: 0;
  font-weight: 700; font-size: 16px;
  background: var(--accent-btn); color: var(--accent-ink);
}
.btn:disabled { opacity: .5; }
.btn.ghost { background: var(--surface-2); color: var(--ink); flex: none; padding: 14px 18px; }
.btn.danger { background: transparent; color: var(--bad); border: 1px solid color-mix(in srgb, var(--bad) 40%, transparent); flex: none; padding: 14px 16px; }
.pin-input { text-align: center; font-size: 28px; letter-spacing: .4em; font-variant-numeric: tabular-nums; }
.muted-text { color: var(--muted); font-size: 14px; margin: 0 0 14px; }
.link-btn { border: 0; background: none; color: var(--accent); font-weight: 600; padding: 0; font-size: 14px; }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--surface);
  padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 60;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Vereins-Look ---------- */
.top::after {
  /* weiße Trikotkante unter dem Header */
  content: ""; display: block; height: 4px;
  background: repeating-linear-gradient(90deg, #fff 0 18px, rgba(255, 255, 255, .35) 18px 36px);
}
.brand-crests { display: none; align-items: center; flex: none; }
.brand-crests img {
  width: 34px; height: 34px; object-fit: contain;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .35));
}
.brand-crests img + img { margin-left: -6px; }
body:not(.locked) .brand-crests { display: flex; }
body:not(.locked) .brand-ball { display: none; }
.section-head h2 { text-transform: uppercase; letter-spacing: .04em; font-size: 15px; font-weight: 800; }
.section-head h2::before {
  content: ""; display: inline-block; width: 4px; height: 14px; border-radius: 2px;
  background: var(--accent); margin-right: 8px; vertical-align: -1px;
}
.rank { position: relative; overflow: hidden; isolation: isolate; }
.rank-wm {
  position: absolute; z-index: -1; pointer-events: none;
  right: 64px; top: 50%; width: 120px; height: 120px; object-fit: contain;
  transform: translateY(-50%) rotate(-12deg);
  opacity: var(--wm-opacity);
}
.rank.first { border-color: color-mix(in srgb, var(--gold) 55%, var(--border)); }
.leader {
  display: inline-block; margin-left: 6px; vertical-align: 1px;
  font-size: 9.5px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase;
  color: #3b2a00; background: var(--gold); border-radius: 6px; padding: 2px 6px;
}

.brand { min-width: 0; }
.brand > div:last-child { min-width: 0; }
.brand h1, .sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 480px) {
  .brand { gap: 10px; }
  .brand-crests img { width: 26px; height: 26px; }
  .brand-crests img + img { margin-left: -8px; }
  .brand h1 { font-size: 17px; }
  #lockBtn { font-size: 0; gap: 0; padding: 8px; }
  #lockBtn svg { width: 18px; height: 18px; }
  .rank-wm { right: 40px; width: 100px; height: 100px; }
  .leader { display: table; margin: 3px 0 1px; }
}
@media (max-width: 380px) {
  .rank { grid-template-columns: 30px 32px 1fr auto; gap: 8px; padding: 12px; }
  .crest.lg { width: 32px; height: 32px; }
  .rank-bal .amt { font-size: 21px; }
}
@media (forced-colors: active) {
  .dot, .swatch, .crest { forced-color-adjust: none; }
}
