*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Dark theme (default) ────────────────────────────────────────────────── */
:root, [data-theme="dark"] {
  --bg: #0a0e1a;
  --surface: #141929;
  --surface2: #1c2438;
  --border: #2a3450;
  --accent: #f5a623;
  --green: #27c93f;
  --red: #e74c3c;
  --gold: #ffd700;
  --silver: #c0c0c0;
  --bronze: #cd7f32;
  --text: #e8ecf4;
  --muted: #7a8aaa;
  --radius: 10px;
  --ctrl-bg: #1c2438;
  --ctrl-border: #2a3450;
  --ctrl-text: #c8d0e8;
  --header-hover: #222d45;
}

/* ── Light theme ─────────────────────────────────────────────────────────── */
[data-theme="light"] {
  --bg: #eef1f8;
  --surface: #ffffff;
  --surface2: #e4e9f5;
  --border: #c8d2e8;
  --accent: #c47d0a;
  --green: #1b8830;
  --red: #c0392b;
  --gold: #a07800;
  --silver: #707070;
  --bronze: #8a5020;
  --text: #1a2040;
  --muted: #5a6a8a;
  --radius: 10px;
  --ctrl-bg: #e4e9f5;
  --ctrl-border: #c0cade;
  --ctrl-text: #2a3450;
  --header-hover: #d8dff0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 15px;
  min-height: 100vh;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px 0;
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  gap: 8px;
}

.header-top h1 { font-size: 1.05rem; font-weight: 700; color: var(--accent); flex: 1; min-width: 0; }
#refresh-info  { font-size: .72rem; color: var(--muted); white-space: nowrap; }

.header-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.ctrl-btn {
  background: var(--ctrl-bg);
  border: 1px solid var(--ctrl-border);
  color: var(--ctrl-text);
  border-radius: 6px;
  padding: 3px 9px;
  font-size: .75rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s, border-color .12s;
  white-space: nowrap;
}
.ctrl-btn:hover { background: var(--header-hover); border-color: var(--accent); }

#status {
  font-size: .75rem;
  color: var(--muted);
  padding-bottom: 8px;
}

/* ── Tabs ────────────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 2px; }
.tab-btn {
  flex: 1; background: none; border: none; color: var(--muted);
  padding: 10px 4px; font-size: .8rem; cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s;
  white-space: nowrap;
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── Main ────────────────────────────────────────────────────────────────── */
main { padding: 12px; }
.tab-view { display: none; }
.tab-view.active { display: block; }

/* ── Section header ──────────────────────────────────────────────────────── */
.section-header {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--muted);
  margin: 18px 0 8px;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--border);
}

/* ── Pool bar ────────────────────────────────────────────────────────────── */
.pool-bar {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
  font-size: .85rem;
}
.prize-chip { padding: 3px 10px; border-radius: 20px; font-weight: 600; font-size: .78rem; }
.prize-chip.p1 { background: rgba(255,215,0,.15);    color: var(--gold); }
.prize-chip.p2 { background: rgba(192,192,192,.15);  color: var(--silver); }
.prize-chip.p3 { background: rgba(205,127,50,.15);   color: var(--bronze); }
.prize-chip.p4 { background: rgba(231,76,60,.15);    color: #e07070; }

/* ── Tables ──────────────────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  container-type: inline-size;
}

/* Tabela Typów: pełna nazwa gdy kontener ≥ 560px, skrót gdy węższszy */
@container (min-width: 560px) { .tname-short { display: none; } }
@container (max-width: 559px) { .tname-full  { display: none; } }
.main-table { width: 100%; border-collapse: collapse; font-size: .82rem; }
.main-table th {
  background: var(--surface2); color: var(--muted); font-weight: 600;
  padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.main-table td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.main-table tr:last-child td { border-bottom: none; }
.main-table tr.top3 td { background: rgba(245,166,35,.04); }
.main-table tr:hover td { background: var(--surface2); }
.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
.sortable:hover { color: var(--accent); }
.sort-active { color: var(--accent); }

.rank { font-size: 1rem; text-align: center; width: 36px; }
.name { font-weight: 600; }
.pts { font-weight: 700; color: var(--accent); white-space: nowrap; }
.max-pts { font-size: .7rem; color: var(--muted); font-weight: 400; display: inline-block; margin-left: 4px; }
.prize-amount { font-weight: 700; color: var(--gold); }
.prize-cell { white-space: nowrap; }
.breakdown { color: var(--muted); font-size: .75rem; }
.age-badge { margin-left: 3px; }

/* ── Team links / flags ──────────────────────────────────────────────────── */
.team-link {
  cursor: pointer;
  color: var(--text);
  white-space: nowrap;
  transition: color .12s;
}
.team-link:hover { color: var(--accent); text-decoration: underline; }
.team-name { white-space: nowrap; }
.team-unknown { color: var(--muted); }
.flag { margin-right: 4px; font-size: 1em; }
.fifa-code { font-size: .7rem; color: var(--muted); font-weight: 400; margin-left: 3px; }
.slot-label { color: var(--muted); font-size: .78rem; }
.muted { color: var(--muted); }

/* ── Predictions tab ─────────────────────────────────────────────────────── */
.legend { font-size: .75rem; color: var(--muted); margin-bottom: 10px; line-height: 1.8; }
.predictions-table td { white-space: nowrap; }

/* Popularity chart */
.popularity-chart { display: flex; flex-direction: column; gap: 6px; margin-bottom: 6px; }
.pop-row {
  display: flex; align-items: center; gap: 8px;
  font-size: .8rem; cursor: pointer; padding: 4px 6px;
  border-radius: 6px; transition: background .12s;
}
.pop-row:hover { background: var(--surface2); }
.pop-row.elim .pop-team { color: var(--muted); text-decoration: line-through; }
.pop-row.top4 .pop-team { color: var(--accent); font-weight: 600; }
.pop-team { width: 130px; flex-shrink: 0; }
.pop-bar-wrap { flex: 1; height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; min-width: 60px; }
.pop-bar { height: 100%; background: var(--accent); border-radius: 4px; transition: width .4s; }
.pop-row.elim .pop-bar { background: var(--muted); }
.pop-row.top4 .pop-bar { background: var(--gold); }
.pop-count { width: 28px; text-align: right; font-weight: 600; color: var(--text); }
.pop-pct { width: 34px; text-align: right; color: var(--muted); font-size: .72rem; }

/* Prize prediction */
.prize-prediction { display: flex; flex-direction: column; gap: 8px; }
.prize-pred-row {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 14px; font-size: .85rem;
}
.pts-small { color: var(--muted); font-size: .75rem; }

/* ── Tournament – groups ─────────────────────────────────────────────────── */
.groups-grid {
  display: grid;
  /* karty min 220px, rosną proporcjonalnie do wolnego miejsca */
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
  margin-bottom: 6px;
}

.group-card {
  container-type: inline-size;   /* karta jest kontenerem — Container Query */
  container-name: gcard;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

/* ── Container Queries: pełna nazwa ≥ 260px, skrót < 260px ───────────────── */
@container gcard (min-width: 280px) { .gname-short { display: none;   } }
@container gcard (max-width: 279px) { .gname-full  { display: none;   } }

.group-title {
  background: var(--surface2);
  padding: 6px 10px;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--accent);
  border-bottom: 1px solid var(--border);
}
.group-title--btn { cursor: pointer; transition: background .12s; }
.group-title--btn:hover { background: var(--header-hover); }
.group-title-arrow { float: right; color: var(--muted); font-weight: 400; }

.group-table {
  width: 100%; border-collapse: collapse; font-size: .72rem;
  /* table-layout: auto — kolumna nazwy bierze tyle ile potrzebuje */
}
.group-table th {
  color: var(--muted); font-weight: 600; padding: 4px 6px;
  border-bottom: 1px solid var(--border); text-align: center;
}
.group-table th:first-child { text-align: left; }
.group-table td { padding: 5px 6px; border-bottom: 1px solid var(--border); }
.group-table td:not(:first-child) { white-space: nowrap; } /* cyfry nie zawijają */
.group-table tr:last-child td { border-bottom: none; }
.group-table tr.advancing td { background: rgba(39,201,63,.07); }
.group-table tr.advancing td:first-child { border-left: 2px solid var(--green); }
.group-table tr.elim td { opacity: .55; }
.stat { text-align: center; }
.pts-col { font-weight: 700; color: var(--accent); }

/* ── Upcoming matches ────────────────────────────────────────────────────── */
.upcoming-card {
  background: var(--surface2);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 10px;
}
.upcoming-title {
  font-size: .75rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .7px; color: var(--accent); margin-bottom: 10px;
}
.upcoming-match {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.upcoming-match:last-child { border-bottom: none; }
.upcoming-teams {
  display: flex; align-items: center; gap: 8px;
  font-size: .88rem; font-weight: 600; margin-bottom: 4px;
}
.upcoming-vs { color: var(--muted); font-size: .75rem; font-weight: 400; }
.upcoming-info {
  display: flex; flex-wrap: wrap; gap: 6px 14px;
  font-size: .72rem; color: var(--muted);
}
.upcoming-round { color: var(--accent); font-weight: 600; }
.upcoming-time  { color: var(--text); }
.upcoming-local { color: var(--muted); }
.upcoming-ground {}

/* ── Collapsible sections ────────────────────────────────────────────────── */
.collapsible { margin-bottom: 8px; }
.sec-header {
  width: 100%; background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 14px;
  display: flex; justify-content: space-between; align-items: center;
  font-size: .8rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .6px; color: var(--text); cursor: pointer;
  transition: background .12s;
}
.sec-header:hover { background: var(--header-hover); }
.sec-icon { color: var(--muted); font-size: .7rem; margin-left: 6px; }
.sec-body { padding-top: 8px; }
.sec-body.sec-collapsed { display: none; }

/* ── Tournament – top4 ───────────────────────────────────────────────────── */
.top4-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.t4-slot {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; display: flex; flex-direction: column; gap: 4px;
}
.t4-label { font-size: .72rem; color: var(--muted); }
.t4-team  { font-weight: 700; font-size: .9rem; }

/* ── Tournament – knockout ───────────────────────────────────────────────── */
.ko-bracket { display: flex; flex-direction: column; gap: 6px; }
.ko-round-body {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 12px;
}
.match-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  grid-template-rows: auto auto;
  align-items: center;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  gap: 0 8px;
  font-size: .8rem;
}
.match-row:last-child { border-bottom: none; }
.match-row .team { }
.match-row > span:nth-child(3) { text-align: right; }
.match-row .team.elim .team-link { color: var(--muted); }
.match-row .score { font-size: .88rem; min-width: 52px; text-align: center; }
.no-score { color: var(--muted); }
.match-meta {
  grid-column: 1 / -1;
  display: flex; flex-wrap: wrap; gap: 4px 12px;
  font-size: .68rem; color: var(--muted);
  padding-top: 3px;
}
.match-venue-time { color: var(--text); }
.match-local-time { }
.match-ground     { }

/* ── Rules ───────────────────────────────────────────────────────────────── */
.rules-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.rules-card h3 { font-size: .78rem; text-transform: uppercase; letter-spacing: .7px; color: var(--accent); margin-bottom: -8px; }
.rules-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.rules-table th, .rules-table td { padding: 7px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.rules-table th { color: var(--muted); font-weight: 500; width: 65%; }
.rules-table td { font-weight: 600; }
.rules-note { font-size: .78rem; color: var(--muted); }
.participants-list { display: flex; flex-wrap: wrap; gap: 6px; }
.participant-chip { background: var(--surface2); border: 1px solid var(--border); border-radius: 20px; padding: 4px 12px; font-size: .78rem; }

/* ── Squad modal ─────────────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.7);
  align-items: center; justify-content: center;
  padding: 16px;
}
.modal-overlay.open { display: flex; }
.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 100%; max-width: 420px;
  max-height: 80vh;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 1rem; font-weight: 700;
}
.modal-close {
  background: none; border: none; color: var(--muted); font-size: 1.1rem;
  cursor: pointer; padding: 4px 6px; border-radius: 6px;
  transition: color .12s, background .12s;
}
.modal-close:hover { color: var(--text); background: var(--surface2); }
.modal-body { overflow-y: auto; padding: 12px 16px; }
.squad-group { margin-bottom: 14px; }
.squad-pos-label {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .7px;
  color: var(--accent); font-weight: 700; margin-bottom: 6px;
}
.squad-player {
  display: flex; gap: 10px; align-items: baseline;
  padding: 5px 0; border-bottom: 1px solid var(--border); font-size: .82rem;
}
.squad-player:last-child { border-bottom: none; }
.squad-num  { width: 22px; text-align: right; color: var(--muted); font-size: .75rem; }
.squad-name { flex: 1; font-weight: 500; }
.squad-dob  { color: var(--muted); font-size: .72rem; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (min-width: 640px) {
  main { padding: 16px; max-width: 920px; margin: 0 auto; }
  header { padding: 16px 16px 0; }
  .main-table { font-size: .9rem; }
  .top4-grid { grid-template-columns: repeat(4, 1fr); }
  .pop-team { width: 180px; }
}

@media (min-width: 1100px) {
  main { max-width: 1200px; }
}

/* ── Modal wide variant ──────────────────────────────────────────────────── */
.modal-card--wide { max-width: 560px; }

/* ── Group matches modal content ─────────────────────────────────────────── */
.gm-section-label {
  font-size: .68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .8px; color: var(--accent);
  padding: 8px 0 6px; border-bottom: 1px solid var(--border); margin-bottom: 2px;
}

.gm-match {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.gm-match:last-child { border-bottom: none; }

.gm-teams {
  display: flex; align-items: center; gap: 8px;
  font-size: .88rem; margin-bottom: 5px;
}
.gm-team { flex: 1; }
.gm-team--right { text-align: right; }

.gm-score {
  display: flex; flex-direction: column; align-items: center;
  min-width: 60px; flex-shrink: 0;
}
.gm-ft { font-size: 1rem; font-weight: 700; color: var(--accent); }
.gm-ht { font-size: .68rem; color: var(--muted); }
.gm-score--vs { font-size: .8rem; color: var(--muted); }

.gm-scorers {
  display: flex; gap: 8px;
  font-size: .75rem; margin-bottom: 4px;
}
.gm-goals-col { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.gm-goals-col--right { text-align: right; align-items: flex-end; }
.gm-goal { display: flex; align-items: center; gap: 4px; }
.gm-goals-col--right .gm-goal { flex-direction: row-reverse; }
.gm-min { color: var(--muted); font-size: .7rem; }
.gm-no-goals { color: var(--muted); font-size: .75rem; font-style: italic; }

.gm-meta {
  font-size: .7rem; color: var(--muted);
  line-height: 1.6;
}

/* ── Password gate ───────────────────────────────────────────────────────── */
#password-gate {
  position: fixed; inset: 0; z-index: 200;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}

.pw-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 32px;
  width: 100%; max-width: 340px;
  text-align: center;
  display: flex; flex-direction: column; gap: 16px;
}

.pw-logo { font-size: 2.8rem; line-height: 1; }
.pw-title { font-size: 1rem; font-weight: 700; color: var(--accent); }

#pw-form { display: flex; flex-direction: column; gap: 10px; }

.pw-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: .95rem;
  padding: 10px 14px;
  outline: none;
  transition: border-color .15s;
  text-align: center;
  letter-spacing: .1em;
}
.pw-input:focus { border-color: var(--accent); }

.pw-btn {
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: #fff;
  font-size: .9rem;
  font-weight: 700;
  padding: 10px;
  cursor: pointer;
  transition: opacity .15s;
}
.pw-btn:hover { opacity: .85; }

.pw-error {
  font-size: .78rem;
  color: var(--red);
  min-height: 1.2em;
}

@keyframes pw-shake {
  0%,100% { transform: translateX(0); }
  20%,60%  { transform: translateX(-6px); }
  40%,80%  { transform: translateX(6px); }
}
.pw-shake { animation: pw-shake .4s ease; }
