:root {
  --bg: #F4F5F1;
  --surface: #FFFFFF;
  --surface-2: #F4F5F1;
  --ink: #15212B;
  --muted: #56626C;
  --line: #DDE1DA;
  --line-soft: #EEF0EC;
  --accent: #1E6B52;
  --accent-ink: #FFFFFF;
  --star: #A15C07;
  --hint-bg: #FBF7EE;
  --hint-ink: #4A3A1E;
  --danger: #B42318;
  --bar: #15212B;
  --bar-muted: #B9C3CB;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F171E;
    --surface: #17222B;
    --surface-2: #1F2C36;
    --ink: #E8ECEF;
    --muted: #A3AEB7;
    --line: #2B3A45;
    --line-soft: #24323C;
    --accent: #3FA27F;
    --accent-ink: #0B1712;
    --star: #E9A23B;
    --hint-bg: #2A2416;
    --hint-ink: #EBD9B4;
    --danger: #F97066;
    --bar: #0B1218;
    --bar-muted: #93A1AC;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}
h1, h2, h3 { line-height: 1.2; letter-spacing: -0.01em; }
button, input { font: inherit; color: inherit; }
a { color: var(--accent); }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.muted-light { color: var(--bar-muted); font-size: 13px; }

/* Kopfzeile */
.topbar { background: var(--bar); color: #fff; padding-top: env(safe-area-inset-top); position: sticky; top: 0; z-index: 5; }
.topbar__inner { max-width: 1240px; margin: 0 auto; padding: 14px 16px; display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 12px; color: #fff; text-decoration: none; min-width: 0; }
.brand > span { display: flex; flex-direction: column; min-width: 0; }
.brand__name { font-weight: 700; font-size: 20px; }
.brand__meta { font-size: 13px; color: var(--bar-muted); }
.topbar__actions { display: flex; align-items: center; gap: 12px; }

/* Buttons */
.btn { min-height: 44px; padding: 0 18px; border-radius: 10px; border: 1px solid transparent; display: inline-flex; align-items: center; gap: 8px; font-weight: 600; cursor: pointer; }
.btn--primary { background: var(--accent); color: var(--accent-ink); }
.btn--outline { background: var(--surface); border-color: var(--ink); color: var(--ink); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn.is-busy svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .btn.is-busy svg { animation: none; } }
.link-btn { background: none; border: 0; color: var(--accent); font-weight: 600; min-height: 44px; padding: 0 4px; cursor: pointer; }
.icon-btn { width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; }
.icon-btn--danger { color: var(--danger); }

/* Layout */
.layout { max-width: 1240px; margin: 0 auto; padding: 24px 16px calc(48px + env(safe-area-inset-bottom)); display: flex; flex-wrap: wrap; gap: 24px; align-items: flex-start; }
.sidebar { flex: 1 1 340px; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.detail { flex: 999 1 560px; min-width: 0; display: flex; flex-direction: column; gap: 20px; }
.section-head { display: flex; justify-content: space-between; align-items: center; }
.section-head h2 { margin: 0; font-size: 20px; }

/* Spielerkarten */
.player-list { display: flex; flex-direction: column; gap: 12px; }
.player { display: flex; gap: 8px; align-items: stretch; }
.player__card { flex: 1; min-width: 0; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; cursor: pointer; }
.player__card[aria-current="true"] { border: 2px solid var(--accent); padding: 13px 15px; }
.player__top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.player__name { font-weight: 600; font-size: 16px; }
.player__id { font-size: 13px; color: var(--muted); }
.player__error { font-size: 13px; color: var(--danger); margin-top: 6px; }
.chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin-top: 12px; }
.chip { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; display: flex; flex-direction: column; }
.chip__code { font-size: 12px; font-weight: 700; color: var(--accent); letter-spacing: .04em; }
.chip__points { font-size: 18px; font-weight: 650; font-variant-numeric: tabular-nums; }
.chip__rank { font-size: 12px; color: var(--muted); }
.player__tools { display: flex; flex-direction: column; gap: 6px; }

/* Hinzufügen */
.add-form { display: flex; flex-direction: column; gap: 8px; padding: 16px; border: 1px dashed var(--line); border-radius: var(--radius); background: var(--surface); }
.add-form label { font-weight: 600; }
.add-form__row { display: flex; gap: 8px; }
.add-form input, dialog input { flex: 1; min-width: 0; min-height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.candidates { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.candidates button { width: 100%; min-height: 44px; display: flex; justify-content: space-between; gap: 8px; align-items: center; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); cursor: pointer; text-align: left; }

/* Detail */
.detail__head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 12px; }
.detail__head h1 { margin: 2px 0 0; font-size: 30px; }
.back-btn { display: none; }
.legend { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.star { width: 14px; height: 14px; fill: var(--star); stroke: none; }
.disc { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.disc__head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.disc__title { display: flex; align-items: center; gap: 12px; }
.disc__title h3 { margin: 0; font-size: 17px; }
.badge { font-weight: 700; font-size: 14px; color: var(--bg); background: var(--ink); border-radius: 8px; padding: 5px 9px; }
.stats { display: flex; gap: 24px; }
.stat { text-align: right; }
.stat__label { font-size: 12px; color: var(--muted); }
.stat__value { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat__value--accent { color: var(--accent); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 8px; }
td { padding: 10px 8px; border-top: 1px solid var(--line-soft); vertical-align: top; }
th:first-child, td:first-child { padding-left: 20px; width: 34px; }
th:last-child, td:last-child { padding-right: 20px; }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
tr.is-dropped td { color: var(--muted); }
td .event { font-size: 12px; color: var(--muted); }
td a { color: inherit; text-decoration-color: var(--line); text-underline-offset: 3px; }
td a:hover { color: var(--accent); }
.disc__foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 16px; padding: 12px 20px; background: var(--hint-bg); color: var(--hint-ink); font-size: 13px; }
.empty { background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); padding: 24px; color: var(--muted); }

.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: 10px; max-width: calc(100% - 32px); z-index: 10; }
dialog { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--ink); max-width: min(420px, calc(100% - 32px)); padding: 20px; }
dialog::backdrop { background: rgb(0 0 0 / .4); }
dialog h2 { margin: 0 0 8px; font-size: 20px; }
dialog form { display: flex; flex-direction: column; gap: 10px; }
.dialog__actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

/* Kategorie-Etikett je Ergebnis */
.cat { display: inline-block; margin-right: 6px; padding: 0 6px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink); font-weight: 600; font-size: 11px; line-height: 18px; white-space: nowrap; }

/* Punkte-Rechner */
.calc { border-top: 1px solid var(--line); }
.calc summary { cursor: pointer; padding: 12px 20px; min-height: 44px; display: flex; align-items: center; font-weight: 600; color: var(--accent); list-style: none; }
.calc summary::-webkit-details-marker { display: none; }
.calc summary::before { content: '›'; display: inline-block; width: 16px; transition: transform .15s; }
.calc[open] summary::before { transform: rotate(90deg); }
.calc__controls { display: flex; flex-wrap: wrap; gap: 10px 16px; padding: 0 20px 12px; }
.calc__controls label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.calc__cat { flex: 1 1 220px; }
.calc select { min-height: 44px; padding: 0 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); font: inherit; font-size: 15px; max-width: 100%; }
.calc table td:first-child, .calc table th:first-child { width: auto; }
.gain { color: var(--accent); }
.calc__note { margin: 0; padding: 10px 20px 14px; font-size: 12px; color: var(--muted); }

/* Smartphone: Liste und Detail als getrennte Ansichten */
@media (max-width: 760px) {
  .topbar__inner { padding: 10px 16px; flex-wrap: nowrap; }
  .brand__changed { display: none; }
  .brand img { width: 30px; height: 30px; }
  .brand__name { font-size: 18px; }
  .topbar #updatedAt { display: none; }
  .btn--primary span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .btn--primary { padding: 0 12px; }
  .layout { padding-top: 16px; }
  .layout.show-detail .sidebar { display: none; }
  .layout:not(.show-detail) .detail { display: none; }
  .back-btn { display: inline-flex; align-self: flex-start; margin-left: -4px; }
  .detail__head h1 { font-size: 26px; }
  .disc__head { padding: 14px 16px; }
  th:first-child, td:first-child { padding-left: 14px; }
  th:last-child, td:last-child { padding-right: 14px; }
  .disc__foot { padding: 12px 16px; }
  .calc summary { padding: 12px 16px; }
  .calc__controls { padding: 0 16px 12px; }
  .calc__note { padding: 10px 16px 14px; }
}
