:root {
  --bg:        #edeef7;
  --panel:     #ffffff;
  --panel-2:   #f4f5fc;
  --line:      #e6e7f3;
  --line-strong:#cdd0e3;
  --text:      #1a1d2e;
  --muted:     #6b6f86;
  --accent:    #5b5ef0;   /* Indigo – Primärfarbe */
  --accent-dk: #4a43d9;
  --accent-ink:#362aa6;
  --accent-2:  #a855f7;   /* Violett – Sekundärakzent */
  --gold:      #e0a106;   /* Amber – Punkte */
  --danger:    #ef4444;
  --shadow:    0 1px 2px rgba(22,32,46,.05), 0 8px 24px rgba(22,32,46,.07);
  --shadow-sm: 0 1px 2px rgba(22,32,46,.06);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  background:
    radial-gradient(900px 500px at 88% -8%, rgba(168,85,247,.12), transparent 60%),
    radial-gradient(820px 520px at 0% 0%, rgba(91,94,240,.12), transparent 55%),
    var(--bg);
  background-attachment: fixed;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 26px; background: #fff;
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
  box-shadow: 0 1px 2px rgba(20,30,50,.04);
}
.brand { font-weight: 800; font-size: 1.18rem; text-decoration: none; letter-spacing: .2px;
  display: inline-flex; align-items: center; gap: 9px; }
.brand-ball { font-size: 1.3rem; line-height: 1; filter: drop-shadow(0 1px 1px rgba(22,32,46,.18)); }
.brand-text {
  background: linear-gradient(90deg, var(--accent-dk), var(--accent) 45%, var(--accent-2) 75%, #ec4899);
  -webkit-background-clip: text; background-clip: text; color: transparent; }
.topbar nav { display: flex; align-items: center; gap: 18px; }
.topbar nav a { color: var(--muted); text-decoration: none; font-weight: 500; }
.topbar nav a:hover { color: var(--accent-dk); }
.hello { color: var(--muted); }

main { max-width: 1140px; margin: 26px auto; padding: 0 18px; }

/* ---------- Cards ---------- */
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 20px; margin-bottom: 18px; box-shadow: var(--shadow);
}
.match { transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease; }
.match:hover { transform: translateY(-1px); box-shadow: 0 2px 4px rgba(22,32,46,.06), 0 12px 30px rgba(22,32,46,.10); border-color: #d9dbf3; }
h1 { font-size: 1.55rem; margin: 0; letter-spacing: -.2px; }
h2 { font-size: 1.02rem; margin: 0 0 12px; }
h3.stage { margin: 26px 0 12px; color: var(--accent-dk); font-size: .82rem;
  text-transform: uppercase; letter-spacing: 1px; font-weight: 700; }
.muted { color: var(--muted); }
a { color: var(--accent-2); }

/* ---------- Auth ---------- */
.auth { max-width: 380px; margin: 64px auto; }
.auth label, .match-form label { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; font-size: .85rem; color: var(--muted); font-weight: 600; }
input {
  background: #fff; border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 10px 12px; font-size: 1rem;
}
input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91,94,240,.18); }
.btn {
  background: var(--accent); color: #fff; border: 0; border-radius: 10px;
  padding: 10px 16px; font-weight: 700; cursor: pointer; font-size: .95rem; box-shadow: 0 1px 2px rgba(91,94,240,.3);
}
.btn:hover { background: var(--accent-dk); }
.btn.small { padding: 6px 12px; font-size: .82rem; }
.link-btn { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; padding: 0; }
.link-btn:hover { color: var(--text); }
.link-btn.danger { color: var(--danger); }
.inline { display: inline; }
.error { color: var(--danger); background: #fdecec; border: 1px solid #f7c9c9; padding: 9px 13px; border-radius: 10px; }
.notice { color: var(--accent-ink); background: #ecedff; border: 1px solid #d3d6f7; padding: 9px 13px; border-radius: 10px; }

/* ---------- Dashboard layout ---------- */
.layout { display: grid; grid-template-columns: 300px 1fr; gap: 22px; align-items: start; }
/* wichtig: verhindert, dass der breite Turnierbaum die Spalte (und damit die Seite)
   über die Bildschirmbreite hinaus aufbläht – stattdessen scrollt er intern */
.layout > * { min-width: 0; }
.sidebar { position: sticky; top: 86px; }

.leaderboard ol { list-style: none; margin: 0; padding: 0; }
.leaderboard li { display: flex; align-items: center; gap: 10px; padding: 8px 8px; border-radius: 10px; }
.leaderboard li + li { border-top: 1px solid var(--line); border-radius: 0; }
.leaderboard li.me { background: #eaf1ff; border-radius: 10px; border-top-color: transparent; }
.leaderboard .rank { width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%;
  background: var(--panel-2); color: var(--muted); font-size: .78rem; font-weight: 700; }
.leaderboard li:nth-child(1) .rank { background: #fdf0cf; color: #9a6b00; }
.leaderboard li:nth-child(2) .rank { background: #eceef2; color: #5d6b7d; }
.leaderboard li:nth-child(3) .rank { background: #f7e6d8; color: #9a5a2a; }
.leaderboard .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.leaderboard .pts { font-weight: 800; color: var(--gold); font-variant-numeric: tabular-nums; }

.mypoints .bignum { font-size: 2.8rem; font-weight: 800; color: var(--accent); text-align: center; line-height: 1; padding: 6px 0; }
.rules ul { margin: 0; padding-left: 18px; line-height: 1.75; font-size: .9rem; }
.rules strong { color: var(--accent-dk); }

/* ---------- Content head + toggle ---------- */
.content-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 8px; flex-wrap: wrap; }
.head-actions { display: inline-flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.btn.ghost { background: #fff; color: var(--accent-dk); border: 1px solid var(--line); box-shadow: var(--shadow-sm); text-decoration: none; }
.btn.ghost:hover { background: var(--panel-2); border-color: var(--line-strong); }
.toggle { display: inline-flex; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 4px; box-shadow: var(--shadow); }
.toggle-btn { border: 0; background: none; cursor: pointer; padding: 8px 14px; border-radius: 9px;
  font-weight: 600; font-size: .9rem; color: var(--muted); }
.toggle-btn:hover { color: var(--text); }
.toggle-btn.active { background: var(--accent); color: #fff; box-shadow: 0 1px 2px rgba(91,94,240,.3); }

/* Speicher-Feedback (ohne Neuladen) */
.flash-ok { background: var(--accent-dk) !important; color: #fff !important; }
.flash-err { background: var(--danger) !important; color: #fff !important; }

/* ---------- Listenansicht ---------- */
.match {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px 16px; margin-bottom: 10px; box-shadow: var(--shadow);
}
.match .when { font-size: .8rem; color: var(--muted); margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.chip { background: var(--panel-2); border: 1px solid var(--line); color: var(--accent-dk);
  border-radius: 999px; padding: 2px 10px; font-size: .72rem; font-weight: 700; }
.match .row { display: flex; align-items: center; gap: 10px; }
.team { flex: 1; font-weight: 600; }
.team.home { text-align: right; }
.team.away { text-align: left; }
.goal { width: 56px; text-align: center; padding: 8px; }
.goal:disabled { background: var(--panel-2); color: var(--muted); }
.sep { color: var(--muted); font-weight: 700; }
.result { margin-top: 10px; font-size: .85rem; display: flex; gap: 10px; align-items: center; }
.final strong { color: var(--text); }
.badge { padding: 3px 10px; border-radius: 999px; font-weight: 800; font-size: .76rem; background: var(--panel-2); color: var(--muted); }
.pts-7 { background: #fbe7b0; color: #8a5d00; }
.pts-5, .pts-4 { background: #e3e4ff; color: var(--accent-ink); }
.pts-3 { background: #efe1ff; color: #7e22ce; }
.pts-1 { background: #e9eaf1; color: #545a72; }
.pts-0 { background: #fde2e4; color: #b42330; }

/* ---------- Abschnittstitel ---------- */
.section-title { font-size: 1.05rem; margin: 22px 0 14px; padding-bottom: 8px;
  border-bottom: 2px solid var(--line); position: relative; }
.section-title::after { content: ''; position: absolute; left: 0; bottom: -2px; width: 46px; height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2)); }

/* ---------- Gruppenphase ---------- */
.groups-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; margin-bottom: 8px; }
.group-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  overflow: hidden; box-shadow: var(--shadow-sm); }
.group-head { font-weight: 800; font-size: .82rem; letter-spacing: .4px; padding: 9px 12px; color: #fff;
  background: linear-gradient(90deg, var(--accent-dk), var(--accent)); }
.group-table { width: 100%; border-collapse: collapse; font-size: .82rem; }
.group-table th { font-weight: 600; color: var(--muted); text-align: center; padding: 6px 4px; font-size: .72rem; }
.group-table td { text-align: center; padding: 6px 4px; border-top: 1px solid var(--line); }
.group-table .t-pos { width: 20px; color: var(--muted); }
.group-table .t-team { text-align: left; font-weight: 600; }
.group-table .t-goals { color: var(--muted); font-variant-numeric: tabular-nums; }
.group-table .t-pts { font-weight: 800; color: var(--accent-ink); font-variant-numeric: tabular-nums; }
.group-table tr.qualify { background: #eef0ff; }
.group-table tr.qualify .t-pos { color: var(--accent-dk); font-weight: 800; }
.group-table tbody tr.qualify:nth-child(2) { box-shadow: inset 0 -2px 0 #d6d9fb; }

/* ---------- Turnierbaum (Bracket) ---------- */
.bracket-note { margin: 6px 0 16px; }
.bracket-scroll { overflow-x: auto; padding-bottom: 10px; }
.bracket { display: flex; column-gap: 46px; width: max-content; min-height: 1380px; }
.round { display: flex; flex-direction: column; width: 178px; flex: 0 0 178px; }
.round-head { text-align: center; font-size: .74rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .6px; color: var(--accent-dk); padding-bottom: 10px; }
.round-body { flex: 1; display: flex; flex-direction: column; }
.slot { flex: 1; display: flex; align-items: center; position: relative; min-height: 84px; }

/* Verbindungslinien */
.round:not(.is-last) .slot::after {
  content: ''; position: absolute; left: 100%; top: 50%;
  width: 23px; height: 2px; background: var(--line-strong);
}
.round:not(.is-last) .slot:nth-child(odd)::before {
  content: ''; position: absolute; left: calc(100% + 23px); top: 50%;
  width: 2px; height: 100%; background: var(--line-strong);
}
.round:not(.is-last) .slot:nth-child(even)::before {
  content: ''; position: absolute; left: calc(100% + 23px); top: 0;
  width: 23px; height: 2px; background: var(--line-strong);
}

.bm {
  width: 100%; background: #fff; border: 1px solid var(--line); border-radius: 12px;
  padding: 8px 10px; box-shadow: var(--shadow); position: relative; z-index: 1;
}
.bm.is-done { border-color: #d6dae8; }
.bm-line { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 3px 0; }
.bm-line + .bm-line { border-top: 1px dashed var(--line); }
.bm-team { font-size: .82rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bm-in { width: 38px; padding: 4px; text-align: center; font-size: .85rem; }
.bm-num { width: 26px; text-align: center; font-weight: 800; color: var(--text); font-variant-numeric: tabular-nums; }
.bm-foot { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-top: 7px; }
.bm-result { font-weight: 800; font-size: .8rem; }
.bm-save { background: var(--accent); color: #fff; border: 0; border-radius: 7px; padding: 4px 9px;
  font-size: .74rem; font-weight: 700; cursor: pointer; width: 100%; }
.bm-save:hover { background: var(--accent-dk); }
.bm-lock { font-size: .74rem; color: var(--muted); }

.third { margin-top: 26px; width: 200px; }
.third .round-head { text-align: left; }

/* ---------- Admin ---------- */
.match-form { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; }
.match-form label { margin-bottom: 0; }
table.results { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.results th, table.results td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); }
table.results th { color: var(--muted); font-weight: 600; }
.result-form .goal { width: 46px; }

.foot { text-align: center; color: var(--muted); padding: 34px; font-size: .82rem; }

/* sanfteres, fingerfreundliches Scrollen im Turnierbaum */
.bracket-scroll { -webkit-overflow-scrolling: touch; }

/* ============ Tablet / Handy ============ */
@media (max-width: 820px) {
  main { margin: 16px auto; padding: 0 12px; }

  /* Topbar kompakter */
  .topbar { padding: 11px 14px; }
  .brand { font-size: 1.04rem; }
  .brand-ball { font-size: 1.15rem; }
  .topbar nav { gap: 12px; font-size: .92rem; }

  /* Layout einspaltig; Sidebar kompakt (Leaderboard voll, Punkte+Regeln nebeneinander) */
  .layout { grid-template-columns: 1fr; gap: 16px; }
  .sidebar { position: static; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .sidebar .card { margin-bottom: 0; }
  .leaderboard { grid-column: 1 / -1; }
  .mypoints .bignum { font-size: 2.2rem; }

  /* Kopfzeile + Aktionen stapeln, volle Breite, große Tap-Targets */
  .content-head { flex-direction: column; align-items: stretch; gap: 10px; }
  .head-actions { width: 100%; justify-content: space-between; }
  .toggle { flex: 1; justify-content: center; }
  .toggle-btn { flex: 1; padding: 10px 8px; }
  .btn, .toggle-btn, .btn.ghost { min-height: 42px; }

  /* Eingaben min. 16px -> verhindert Auto-Zoom auf iOS */
  .goal, .bm-in { font-size: 16px; }
  .goal { width: 52px; }

  /* Listenansicht: Paarung in eine Zeile, Button darunter volle Breite */
  .match .row { flex-wrap: wrap; gap: 8px; }
  .team { flex: 1 1 30%; min-width: 0; }
  .match .row .btn.small { flex: 1 1 100%; order: 5; }

  /* Turnierbaum schmaler -> weniger horizontales Scrollen */
  .bracket { min-height: 1180px; }
  .round { width: 150px; flex-basis: 150px; }
  .bm { padding: 7px 8px; }
  .bm-team { font-size: .78rem; }

  /* Gruppen-Kacheln: eine Spalte */
  .groups-grid { grid-template-columns: 1fr; }
}

/* ============ kleine Handys ============ */
@media (max-width: 480px) {
  .sidebar { grid-template-columns: 1fr; }   /* alles untereinander */
  .rules { display: none; }                   /* Regeln stehen auch im Report */
  .topbar nav .hello { display: none; }       /* Begrüßung ausblenden, spart Platz */
  h1 { font-size: 1.35rem; }
  .group-card { font-size: .95rem; }
}
