:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #16181d;
  --muted: #666e7d;
  --border: #dce0e8;
  --accent: #d3151f;
  --accent-soft: #fdecec;
  --green: #1a7f4b;
  --amber: #b0740b;
  --blue: #1f5fbf;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 20, 30, .06), 0 4px 14px rgba(16, 20, 30, .05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1c1f25;
    --surface-2: #23272f;
    --text: #e9ecf1;
    --muted: #99a1b0;
    --border: #313743;
    --accent: #ef4a52;
    --accent-soft: #3a1c1e;
    --green: #46c489;
    --amber: #e0a93b;
    --blue: #6ea3f5;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 14px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }

/* Muss vor den Layoutregeln stehen: display-Angaben wuerden das
   hidden-Attribut sonst aushebeln. */
[hidden] { display: none !important; }

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

h1, h2 { margin: 0; font-weight: 650; }
h2 { font-size: 1.05rem; margin-bottom: .8rem; }

.sr-only {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* --- Kopfbereich --------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 900px; margin: 0 auto;
  padding: .7rem 1rem;
  display: flex; align-items: center; gap: 1rem;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: .6rem; flex: 1 1 auto; }
.ball { font-size: 1.6rem; line-height: 1; }
.topbar h1 { font-size: 1.05rem; letter-spacing: -.01em; }
.league { margin: 0; font-size: .8rem; color: var(--muted); }

.who { display: flex; gap: .4rem; }
.who select, .who input { max-width: 11rem; }

.tabs {
  max-width: 900px; margin: 0 auto;
  padding: 0 .5rem;
  display: flex; gap: .1rem; overflow-x: auto;
}

.tab {
  flex: 0 0 auto;
  background: none; border: none; border-bottom: 2px solid transparent;
  padding: .55rem .8rem; margin: 0;
  font: inherit; font-size: .92rem; color: var(--muted);
  cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* --- Layout -------------------------------------------------------------- */
main { max-width: 900px; margin: 0 auto; padding: 1rem 1rem 5rem; }
.view { display: block; }

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

/* --- Formularelemente ---------------------------------------------------- */
select, input, button { font: inherit; color: inherit; }

select, input[type="text"], input[type="password"], input[type="number"] {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .45rem .55rem;
  width: 100%;
}
select:focus-visible, input:focus-visible, button:focus-visible {
  outline: 2px solid var(--blue); outline-offset: 1px;
}

.primary-btn {
  background: var(--accent); color: #fff;
  border: none; border-radius: 9px;
  padding: .55rem 1.1rem; font-weight: 600; cursor: pointer;
}
.primary-btn:disabled { opacity: .5; cursor: default; }

.ghost-btn {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 9px;
  padding: .45rem .8rem; cursor: pointer; white-space: nowrap;
}
.ghost-btn:hover { background: var(--surface-2); }

.icon-btn {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 9px; width: 2.2rem; height: 2.2rem;
  font-size: 1.2rem; line-height: 1; cursor: pointer;
}
.icon-btn:disabled { opacity: .4; cursor: default; }

.stack { display: grid; gap: .7rem; justify-items: start; }
.stack label { display: grid; gap: .25rem; width: 100%; font-size: .88rem; color: var(--muted); }
.stack label input { color: var(--text); }

.hint { margin: 0; font-size: .82rem; color: var(--muted); }

.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; margin-bottom: .8rem;
}
.card-head h2 { margin: 0; }

.switch {
  display: flex; align-items: flex-start; gap: .55rem;
  margin-top: 1rem; font-size: .86rem; cursor: pointer;
}
.switch input { width: auto; flex: 0 0 auto; margin-top: .15rem; accent-color: var(--accent); }

/* --- Anmeldedialog ------------------------------------------------------- */
dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  box-shadow: 0 10px 40px rgba(0, 0, 0, .3);
  padding: 1.2rem;
  width: min(26rem, calc(100vw - 2rem));
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog form { display: grid; gap: .8rem; }
dialog label { display: grid; gap: .25rem; font-size: .88rem; color: var(--muted); }
dialog label input { color: var(--text); }
.dialog-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .3rem; }

.player-admin { margin-top: 1rem; border-top: 1px solid var(--border); }
.player-row {
  display: grid; grid-template-columns: 1fr auto auto auto;
  gap: .5rem; align-items: center;
  padding: .5rem 0; border-bottom: 1px solid var(--border);
}
.player-row .player-name { font-weight: 550; }
.player-row .ghost-btn { padding: .25rem .6rem; font-size: .82rem; }

.rules-grid { display: grid; gap: .7rem; grid-template-columns: repeat(3, 1fr); align-items: end; }
.rules-grid label { display: grid; gap: .25rem; font-size: .85rem; color: var(--muted); }
.rules-grid button { grid-column: 1 / -1; justify-self: start; }

/* --- Spieltagsnavigation ------------------------------------------------- */
.matchday-nav {
  display: flex; align-items: center; gap: .5rem;
  margin-bottom: 1rem;
}
.matchday-nav select { flex: 1 1 auto; max-width: 14rem; }

/* --- Spiele -------------------------------------------------------------- */
.match-list { display: grid; gap: .6rem; }

.match {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.match-head {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: .5rem;
  padding: .75rem .9rem;
}

.team { display: flex; align-items: center; gap: .5rem; min-width: 0; }
.team.away { flex-direction: row-reverse; text-align: right; }
.team img { width: 26px; height: 26px; object-fit: contain; flex: 0 0 auto; }
.team span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }

.center { display: grid; justify-items: center; gap: .2rem; }

/* Eigene Zeile, damit die Anstosszeit den Vereinsnamen keine Breite wegnimmt. */
.kickoff {
  grid-column: 1 / -1;
  margin-top: .25rem;
  font-size: .74rem; color: var(--muted);
  text-align: center; white-space: nowrap;
}

.result {
  font-variant-numeric: tabular-nums;
  font-weight: 700; font-size: 1.1rem;
  letter-spacing: .02em;
}
.result.pending { color: var(--muted); font-weight: 500; font-size: .95rem; }

.bet-inputs { display: flex; align-items: center; gap: .25rem; }
.bet-inputs input {
  width: 2.6rem; text-align: center; padding: .35rem .2rem;
  font-variant-numeric: tabular-nums;
}
.bet-inputs input:disabled { background: var(--surface-2); color: var(--muted); }
/* Die Pfeilchen der Zahlenfelder stehlen in den schmalen Feldern nur Platz. */
.bet-inputs input { -moz-appearance: textfield; appearance: textfield; }
.bet-inputs input::-webkit-outer-spin-button,
.bet-inputs input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.bet-inputs .colon { color: var(--muted); }

.own-bet { font-size: .78rem; color: var(--muted); }

.bets {
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  padding: .5rem .9rem .6rem;
  display: grid; gap: .25rem;
}
.bet-row {
  display: grid; grid-template-columns: 1fr auto auto;
  gap: .6rem; align-items: center;
  font-size: .86rem;
}
.bet-row .tip { font-variant-numeric: tabular-nums; color: var(--muted); }
.bet-row .pts {
  font-variant-numeric: tabular-nums; font-weight: 650;
  min-width: 2.6rem; text-align: right;
}
.pts.exact { color: var(--green); }
.pts.diff { color: var(--blue); }
.pts.tendency { color: var(--amber); }
.pts.miss { color: var(--muted); font-weight: 500; }

.no-bets { font-size: .82rem; color: var(--muted); }

.locked-note {
  font-size: .78rem; color: var(--muted);
  padding: 0 .9rem .6rem;
}

/* --- Speicherleiste ------------------------------------------------------ */
.save-bar {
  position: sticky; bottom: 0;
  margin-top: 1rem;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: .6rem .9rem;
}
#save-hint { font-size: .84rem; color: var(--muted); }

/* --- Tabelle ------------------------------------------------------------- */
.segmented { display: flex; gap: .4rem; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; }
.seg {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: .35rem .9rem; cursor: pointer; font-size: .88rem;
}
.seg.is-active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.segmented select { max-width: 11rem; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: .5rem .4rem; text-align: right; font-variant-numeric: tabular-nums; }
th { font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
th:nth-child(2), td:nth-child(2) { text-align: left; }
tbody tr { border-top: 1px solid var(--border); }
td.rank { color: var(--muted); width: 2rem; }
td.name { font-weight: 550; }
td.total { font-weight: 700; }
tr.me { background: var(--accent-soft); }

.rules-note { font-size: .8rem; color: var(--muted); text-align: center; }

/* --- Verlauf ------------------------------------------------------------- */
#history-chart svg { width: 100%; height: auto; display: block; }
.legend { display: flex; flex-wrap: wrap; gap: .3rem .9rem; margin-top: .6rem; font-size: .82rem; }
.legend span { display: inline-flex; align-items: center; gap: .35rem; }
.legend i { width: .7rem; height: .7rem; border-radius: 3px; display: inline-block; }

/* --- Hinweise ------------------------------------------------------------ */
.empty { color: var(--muted); text-align: center; padding: 2rem 1rem; }

.toast {
  position: fixed; left: 50%; bottom: 1.2rem; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: .55rem 1rem; border-radius: 999px;
  font-size: .87rem; box-shadow: var(--shadow); z-index: 50;
  max-width: calc(100vw - 2rem);
}
.toast.error { background: var(--accent); color: #fff; }

/* --- Schmale Bildschirme ------------------------------------------------- */
@media (max-width: 560px) {
  .topbar-inner { gap: .6rem; }
  .who { width: 100%; }
  .who select { flex: 1 1 auto; max-width: none; }
  .who input { flex: 0 0 5rem; }
  .team span { font-size: .9rem; }
  .team img { width: 22px; height: 22px; }
  .rules-grid { grid-template-columns: 1fr; }
  main { padding: .8rem .7rem 4rem; }
  th, td { padding: .45rem .25rem; font-size: .88rem; }
}
