/* Motywy kolorystyczne: jasny (domyślny) i ciemny — wybierane przełącznikiem w nagłówku. */
:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1d2228;
  --muted: #5b6470;
  /* Tabele: tło nagłówka, podświetlenie wiersza, cieniowanie kolumn w rankingach */
  --th-bg: #eef1f4;
  --row-hover: rgba(31, 111, 67, .06);
  --col-pts: rgba(31, 111, 67, .09);
  --col-rec: rgba(43, 95, 184, .05);
  --col-t-even: rgba(20, 30, 40, .055);
  --col-t-odd: transparent;
  --line: #e2e5ea;
  /* Pola formularzy: wyraźniejsza ramka i cień (czytelne na jasnych monitorach) */
  --input-border: #a3acb7;
  --input-border-hover: #7d8794;
  --input-shadow: 0 1px 2px rgba(16, 24, 40, .10), inset 0 1px 2px rgba(16, 24, 40, .05);
  --focus-ring: rgba(31, 111, 67, .22);
  --accent: #1f6f43;
  --accent-soft: #e3f2e9;
  --on-accent: #ffffff;
  --danger: #c62828;
  --warn-bg: #fff6dd;
  --warn: #8a6100;
  --err-bg: #fdeaea;
  --ok-bg: #e3f2e9;
  --info-bg: #e3ecfa;
  --info: #2b5fb8;
  --rank-bg: #f3e8ff;
  --rank: #7a3ec2;
  --ready: #fff;
  --ready-border: #1f6f43;
  --done-bg: #f7f8fa;
  --board: #2b5fb8;
  --header-bg: #1f2a24;
  --header-text: #dfe7e2;
  --header-accent: #b9d8c5;
  --foot-bg: #000;
  --foot-text: #c4c8cd;
  --toast-bg: #1f2a24;
  --shadow: rgba(0, 0, 0, .15);
  --radius: 8px;
  /* Kolumny zawodników w tabeli rekordów legów (A — niebieski, B — pomarańczowy) */
  --pa-col: rgba(37, 99, 235, .072);
  --pb-col: rgba(234, 88, 12, .072);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --pa-col: rgba(96, 140, 255, .12);
  --pb-col: rgba(255, 140, 70, .12);
  --bg: #15181c;
  --card: #1e2227;
  --text: #e6e8eb;
  --muted: #a7afba;
  --th-bg: #262b31;
  --row-hover: rgba(76, 182, 123, .08);
  --col-pts: rgba(76, 182, 123, .12);
  --col-rec: rgba(141, 180, 242, .07);
  --col-t-even: rgba(255, 255, 255, .05);
  --col-t-odd: transparent;
  --line: #30353c;
  --input-border: #56606b;
  --input-border-hover: #7a8590;
  --input-shadow: 0 1px 2px rgba(0, 0, 0, .35), inset 0 1px 2px rgba(0, 0, 0, .25);
  --focus-ring: rgba(76, 182, 123, .28);
  --accent: #4cb67b;
  --accent-soft: #1d3a2a;
  --on-accent: #0d1a12;
  --danger: #ef6b6b;
  --warn-bg: #3a3017;
  --warn: #f0c75e;
  --err-bg: #3d1f1f;
  --ok-bg: #1d3a2a;
  --info-bg: #1c2a40;
  --info: #8db4f2;
  --rank-bg: #2e2140;
  --rank: #c9a2f5;
  --ready: #23282e;
  --ready-border: #4cb67b;
  --done-bg: #191c20;
  --board: #7aa7f0;
  --header-bg: #0e1311;
  --toast-bg: #2c3a32;
  --shadow: rgba(0, 0, 0, .5);
  color-scheme: dark;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 "Segoe UI", system-ui, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
h1 { margin: 2px 0 6px; font-size: 26px; letter-spacing: -.01em; }
h2 { margin: 0 0 14px; font-size: 18px; letter-spacing: -.005em; }
h2 small { color: var(--muted); font-weight: 400; font-size: 13px; margin-left: 6px; }
.num { font-variant-numeric: tabular-nums; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }

.top { display: flex; align-items: center; gap: 24px; padding: 10px 20px; background: var(--header-bg); color: #fff; position: sticky; top: 0; z-index: 10; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 18px; }
.brand span { font-weight: 400; opacity: .7; }
#nav { display: flex; gap: 4px; flex-wrap: wrap; }
#nav a { color: var(--header-text); text-decoration: none; padding: 6px 12px; border-radius: 6px; }
#nav a.active, #nav a:hover { background: rgba(255, 255, 255, .14); color: #fff; }
.dot { display: inline-block; background: #f0a500; color: #000; border-radius: 9px; padding: 0 6px; font-size: 11px; font-weight: 700; }

.top-right { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.theme-switch { display: inline-flex; border: 1px solid rgba(255, 255, 255, .25); border-radius: 7px; overflow: hidden; }
.theme-switch button { font: inherit; font-size: 12px; background: transparent; color: var(--header-text); border: none; padding: 4px 10px; cursor: pointer; }
.theme-switch button + button { border-left: 1px solid rgba(255, 255, 255, .25); }
.theme-switch button:hover { background: rgba(255, 255, 255, .1); }
.theme-switch button.active { background: rgba(255, 255, 255, .22); color: #fff; font-weight: 600; }
#sync-indicator { font-size: 12px; color: var(--header-accent); }
/* Wersja dev: wybór instancji (pubu) w nagłówku */
#instance-switch:empty { display: none; }
/* (label ma domyślnie układ w kolumnie — tu obok siebie, oba elementy tej samej wysokości) */
label.inst-switch { display: inline-flex; flex-direction: row; align-items: center; gap: 6px; }
.inst-dev, .inst-switch select { box-sizing: border-box; height: 26px; }
.inst-dev { display: inline-flex; align-items: center; font-size: 11px; font-weight: 800; letter-spacing: .06em; background: #f0a500; color: #000; border-radius: 6px; padding: 0 8px; }
.inst-switch select { font: inherit; font-size: 12px; background: rgba(255, 255, 255, .12); color: #fff; border: 1px solid rgba(255, 255, 255, .3); border-radius: 6px; padding: 0 6px; }
.inst-switch select option { color: #000; }
.inst-table tr.inst-current td { background: var(--accent-soft, rgba(46, 125, 50, .08)); }
.inst-form { margin-top: 12px; }
.inst-links { margin: 6px 0 8px; padding-left: 1.2em; line-height: 1.9; }
.banner { max-width: 1400px; margin: 12px auto 0; padding: 10px 16px; border-radius: 8px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
#sync-banner:empty { display: none; }
#sync-banner { padding: 0 20px; }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.error { background: var(--err-bg); color: var(--danger); }

body { min-height: 100vh; display: flex; flex-direction: column; }
main { max-width: 1400px; width: 100%; margin: 0 auto; padding: 16px 20px 40px; flex: 1; }
/* Stopka przyklejona do dołu okna — widoczna także przy przewijaniu długich stron (np. drabinka 128). */
.foot { position: sticky; bottom: 0; z-index: 10; text-align: center; font-size: 12px; color: var(--foot-text); background: var(--foot-bg); padding: 7px 20px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.card-head h2 { margin: 0; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }

.row-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
input, select { font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--input-border); border-radius: 6px; padding: 7px 9px; min-width: 0;
  box-shadow: var(--input-shadow); transition: border-color .15s, box-shadow .15s; }
input:hover:not(:disabled), select:hover:not(:disabled) { border-color: var(--input-border-hover); }
/* Aktywne pole: zielona ramka + jasna poświata */
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring), var(--input-shadow); }
input:disabled, select:disabled { opacity: .6; box-shadow: none; }
input[type="checkbox"], input[type="radio"] { box-shadow: none; }
input.num { width: 64px; }
input.search { width: 280px; max-width: 100%; }
label.chk { flex-direction: row; align-items: center; gap: 6px; color: var(--text); font-size: 14px; }
label.chk.big { font-size: 15px; }
label.chk select { padding: 2px 4px; }

.btn { display: inline-flex; align-items: center; gap: 6px; font: inherit; border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 6px; padding: 7px 14px; cursor: pointer; text-decoration: none; }
.btn:hover:not([disabled]) { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover:not([disabled]) { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 3px 9px; font-size: 12px; }
.btn.big { padding: 10px 26px; font-size: 16px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
label.btn { flex-direction: row; color: var(--text); font-size: 14px; }

.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 12.5px; color: var(--muted); font-weight: 600; background: var(--th-bg); border-bottom: 1px solid var(--line); padding: 8px 10px; white-space: nowrap; }
.tbl thead th:first-child { border-top-left-radius: 6px; }
.tbl thead th:last-child { border-top-right-radius: 6px; }
.tbl td { border-bottom: 1px solid var(--line); padding: 9px 10px; vertical-align: middle; }
.tbl.compact td { padding: 6px 10px; }
.tbl tbody tr:hover > td { background-color: var(--row-hover); }
.tbl th.center, .tbl td.center { text-align: center; }
.tbl th.right, .tbl td.right { text-align: right; }

/* Lista turniejów: te same kolumny i szerokości we wszystkich trzech tabelach */
/* min. szerokość: na wąskim oknie tabela przewija się w poziomie zamiast ściskać kolumnę z nazwą */
.tbl.tlist { table-layout: fixed; min-width: 920px; }
.tlist col.c-date { width: 104px; }
.tlist col.c-series { width: 16%; }
.tlist col.c-num { width: 84px; }
.tlist col.c-state { width: 200px; }
.tlist col.c-act { width: 140px; }
.t-link { font-weight: 700; font-size: 15.5px; text-decoration: none; }
.t-link:hover { text-decoration: underline; }
.t-badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
.t-badges:empty { display: none; }
.t-badges .badge { margin-left: 0; }
.progress { display: inline-block; width: 64px; height: 6px; border-radius: 3px; background: var(--line); vertical-align: middle; overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--accent); }

/* Sezony */
.season-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; background: var(--card); border: 1px solid var(--line);
  border-left: 4px solid var(--accent); border-radius: var(--radius); padding: 10px 16px; margin-bottom: 12px; max-width: 640px; }
.season-table { max-width: 640px; margin-top: 8px; }
.season-bar div { display: flex; flex-direction: column; }
.season-bar b { font-size: 22px; font-weight: 800; letter-spacing: -.01em; }
input.season-in { width: 96px; }
.season-group { border: 1px solid var(--line); border-radius: 6px; margin-bottom: 10px; }
.season-group summary { cursor: pointer; padding: 10px 14px; background: var(--th-bg); border-radius: 6px; }
.season-group[open] summary { border-bottom: 1px solid var(--line); border-radius: 6px 6px 0 0; }
.season-group .tbl { margin: 0; }
.rank-title { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

.t-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: -4px; }
.t-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

/* Karta zawodnika */
a.p-link { color: inherit; text-decoration: none; border-bottom: 1px dotted var(--muted); }
a.p-link:hover { color: var(--accent); border-bottom-color: var(--accent); }
.stats-filter { margin-top: 12px; }
.t-head-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.stat-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin: 14px 0 16px; }
.stat-tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; display: flex; flex-direction: column; }
.stat-tile span { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.stat-tile b { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.3; }
.stat-tile small { font-size: 12px; color: var(--muted); }
.stat-tile small b { font-size: inherit; font-weight: 700; line-height: inherit; color: var(--text); }
.stat-tile small span.sl-dist { font-size: inherit; text-transform: none; letter-spacing: 0; }
.res { display: inline-block; min-width: 46px; padding: 1px 8px; border-radius: 10px; font-weight: 700; }
.res-w { background: var(--ok-bg); color: var(--accent); }
.res-l { background: var(--err-bg); color: var(--danger); }

/* Rankingi: cieniowanie grup kolumn (punkty, rekordy, kolejne turnieje naprzemiennie) */
.tbl.rank col.c-rank { width: 70px; }
.tbl.rank col.c-pts { background: var(--col-pts); }
.tbl.rank col.c-rec { background: var(--col-rec); }
.tbl.rank col.c-t-even { background: var(--col-t-even); }
.tbl.rank col.c-t-odd { background: var(--col-t-odd); }
.tbl.rank td:nth-child(4), .tbl.rank th:nth-child(4) { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
.tbl.rank td:nth-child(6), .tbl.rank th:nth-child(6), .tbl.rank td:nth-child(10), .tbl.rank th:nth-child(10) { border-left: 1px solid var(--line); }
.tbl.rank td:nth-child(2), .tbl.rank td:nth-child(3) { white-space: nowrap; }
.tbl.rank td.pts-total { font-weight: 800; font-size: 15.5px; color: var(--accent); }
.tbl.rank thead th { vertical-align: bottom; }
.tbl td.win { font-weight: 700; }
.tbl td.score { font-weight: 700; font-size: 15px; }
.tbl tr.st-waiting { opacity: .6; }
.tbl tr.st-bye, .tbl tr.st-skipped { opacity: .5; }
.tbl tr.podium.p1 td { background: rgba(240, 190, 30, .16); }
.tbl tr.podium.p2 td { background: rgba(160, 170, 180, .16); }
.tbl tr.podium.p3 td { background: rgba(200, 120, 60, .13); }
.tbl input { padding: 4px 7px; }

.badge { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 10px; background: var(--line); color: var(--text); margin-left: 4px; font-weight: 600; }
.badge.planned { background: var(--info-bg); color: var(--info); }
.badge.inProgress { background: var(--warn-bg); color: var(--warn); }
.badge.finished, .badge.free { background: var(--ok-bg); color: var(--accent); }
.badge.busy { background: var(--info-bg); color: var(--info); }
.badge.broken { background: var(--err-bg); color: var(--danger); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.mult { background: var(--warn-bg); color: var(--warn); }
.mult-mark { color: var(--warn); }
.badge.cat { background: var(--info-bg); color: var(--info); }
.badge.ranked { background: var(--rank-bg); color: var(--rank); }
.row-form label.chk { padding-bottom: 8px; }
.row-form label.players-active { padding-bottom: 0; align-self: center; flex-direction: row; align-items: center; gap: 6px; font-size: 13px; white-space: nowrap; }
/* Przycisk w formularzu (np. Dodaj, Utwórz turniej) tej samej wysokości co pola obok. */
.row-form > .btn:not(.sm) { height: 34px; box-sizing: border-box; padding-top: 0; padding-bottom: 0; font-size: 14px; }
.badge.seed { background: var(--accent-soft); color: var(--accent); }

.msg { padding: 8px 12px; border-radius: 6px; margin: 8px 0; }
.msg.error { background: var(--err-bg); color: var(--danger); }
.msg.warn { background: var(--warn-bg); color: var(--warn); }
.msg.ok { background: var(--ok-bg); color: var(--accent); }

.t-head { margin-bottom: 8px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 8px 14px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.counter { font-size: 15px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chip { font: inherit; border: 1px solid var(--line); background: var(--card); color: var(--text); padding: 4px 12px; border-radius: 16px; cursor: pointer; }
.chip span { color: var(--muted); margin-left: 3px; }
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.chip.active span { color: var(--on-accent); opacity: .8; }

/* Rankingi */
.table-scroll { overflow: auto; }
.table-scroll.tall { max-height: 65vh; border: 1px solid var(--line); border-radius: 6px; }
.tbl.rank th.tcol { min-width: 90px; font-weight: 600; white-space: normal; }
.tbl.rank th.tcol span { display: block; font-weight: 400; max-width: 130px; margin: 0 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tbl.pts th, .tbl.pts td { padding: 2px 3px; border-bottom: 1px solid var(--line); }
.tbl.pts thead th { position: sticky; top: 0; background: var(--card); z-index: 2; }
.tbl.pts tbody th { position: sticky; left: 0; background: var(--card); z-index: 1; text-align: right; padding-right: 8px; color: var(--muted); }
.tbl.pts-linear { width: auto; min-width: 360px; }
.tbl.pts-linear td:first-child { padding-right: 40px; }
input.pt { width: 64px; text-align: right; padding: 3px 5px; font-size: 13px; }
select.gender-sel { padding: 3px 6px; font-size: 13px; }
.gender-list { max-height: 55vh; overflow: auto; border: 1px solid var(--line); border-radius: 6px; }
.gender-list thead th { position: sticky; top: 0; background: var(--card); }
.gender-list tr.unsure td { background: var(--warn-bg); }
.series-pick { display: flex; flex-direction: column; gap: 8px; }

/* Przycisk "Ekran dla widzów" w nagłówku turnieju */
.t-head { display: flex; flex-direction: row-reverse; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }

/* ===== Ekran dla widzów (osobne okno na telewizor) ===== */
body.screen-mode { height: 100vh; overflow: hidden; }
body.screen-mode .top, body.screen-mode .foot, body.screen-mode #sync-banner { display: none; }
body.screen-mode main { max-width: none; padding: 1.2vh 1.2vw; height: 100vh; display: flex; flex-direction: column; gap: 1.2vh; }
body.scr-idle, body.scr-idle * { cursor: none !important; }
.scr-head { display: flex; justify-content: space-between; align-items: baseline; gap: 2vw; }
.scr-title { font-size: clamp(20px, 2.4vw, 48px); font-weight: 700; }
.scr-title span { font-size: .5em; font-weight: 400; color: var(--muted); margin-left: .8em; }
.scr-clock { font-size: clamp(18px, 2vw, 40px); font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.scr-toolbar { position: fixed; right: 1.2vw; bottom: 1.2vh; z-index: 20; display: flex; gap: 4px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 4px; box-shadow: 0 4px 16px var(--shadow); transition: opacity .3s; }
.scr-toolbar button { font: inherit; font-size: 13px; border: none; background: transparent; color: var(--text); padding: 6px 12px; border-radius: 6px; cursor: pointer; }
.scr-toolbar button:hover { background: var(--accent-soft); }
.scr-toolbar button.active { background: var(--accent); color: var(--on-accent); font-weight: 600; }
body.scr-idle .scr-toolbar { opacity: 0; pointer-events: none; }
/* Wspólny ekran (turnieje w trakcie): rodzaj turnieju i pozycja w automatycznej zmianie widoków */
.scr-cat { font-size: .55em; padding: .15em .6em; border-radius: 1em; vertical-align: middle; margin-left: .4em; color: #fff; }
.scr-cat-K { background: #c2185b; }
.scr-cat-M { background: #1565c0; }
.scr-rot { margin-left: auto; font-size: clamp(12px, 1.1vw, 22px); color: var(--muted); font-variant-numeric: tabular-nums; }
.scr-tb-info { font-size: 13px; color: var(--muted); padding: 6px 10px; align-self: center; }
.row-form.screen-all { align-items: center; }
.head-left { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
/* Przyciski przy nagłówku (Automaty, Wpisowe) — ta sama wysokość i wyrównanie, licznik nie powiększa przycisku */
.head-left .btn { box-sizing: border-box; height: 28px; padding: 0 10px; line-height: 1; display: inline-flex; align-items: center; gap: 6px; }
.head-left .btn > span { display: inline-flex; align-items: center; line-height: 1; }
.head-left .btn .btn-ico { font-size: 14px; height: 14px; }
.head-left .btn .badge { padding: 3px 6px; }
/* Planowany czas rozpoczęcia przy nazwie turnieju zaplanowanego */
.t-start { font-size: 13px; font-weight: 600; color: var(--accent); background: var(--accent-soft); padding: 1px 8px; border-radius: 10px; white-space: nowrap; margin-left: 6px; vertical-align: middle; }
h1 .t-start { font-size: 14px; }
input.time-in { width: 100px; }
/* Strzałka w menu przy „Turnieje” w widoku turnieju — powrót do listy */
.nav-up { vertical-align: -2px; margin-right: 6px; }
/* Ręczny wybór widoku wspólnego ekranu (lista turniejów, „W trakcie”) */
.screen-manual { margin: 4px 0 12px; padding: 8px 12px; background: var(--th-bg); border-radius: 8px; display: flex; flex-direction: column; gap: 6px; }
.screen-manual-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.screen-manual-label { font-size: 13px; font-weight: 600; min-width: 220px; }
.screen-manual .chip { font-size: 12.5px; padding: 2px 10px; }
.row-form.screen-all label.chk { padding-bottom: 0; flex-direction: row; align-items: center; gap: 6px; font-size: 13px; }
.scr-body { flex: 1; min-height: 0; display: grid; gap: 1.2vw; }
.scr-body.layout-split { grid-template-columns: 3fr 2fr; }
.scr-panel { background: var(--card); border: 1px solid var(--line); border-radius: 10px; min-height: 0; overflow: hidden; }
.scr-bracket { padding: 1vh 1vw; }
/* Ranking na żywo na ekranie dla widzów — duże litery, czytelne z daleka */
.scr-ranking { padding: 1.5vh 1.5vw; container-type: inline-size; }
.scr-rank-inner { font-size: clamp(14px, 2.1cqw, 34px); }
.scr-rank-inner h3 { font-size: 1em; margin: 0 0 .5em; color: var(--accent); text-transform: uppercase; letter-spacing: .04em; }
.scr-rank-inner h3 span { text-transform: none; letter-spacing: 0; color: var(--muted); font-weight: 400; font-size: .75em; margin-left: .6em; }
.scr-rank { width: 100%; border-collapse: collapse; }
.scr-rank th { font-size: .6em; text-transform: uppercase; color: var(--muted); text-align: right; padding: .3em .5em; border-bottom: 2px solid var(--line); }
.scr-rank td { text-align: right; padding: .28em .5em; border-bottom: 1px solid var(--line); }
.scr-rank .l { text-align: left; }
.scr-rank td:first-child, .scr-rank th:first-child { width: 3.5em; }
.scr-rank tr.lr-playing td { background: var(--accent-soft); }
.scr-rank small, .scr-rank .small { font-size: .65em; }
.scr-rank .badge { font-size: .6em; }
.scr-fit { transform-origin: 0 0; display: flex; flex-direction: column; }
.scr-row { margin-bottom: 18px; flex: 1; display: flex; flex-direction: column; }
.scr-row .bracket { flex: 1; }
/* Kolumny rund rozciągają się na całą szerokość panelu (min. 190 px przed powiększeniem). */
.scr-bracket .bracket { min-width: 0; }
.scr-row-label { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 4px; font-weight: 700; }
.scr-bracket .round { width: auto; flex: 1 1 190px; min-width: 190px; }
.scr-bracket .round-head { font-size: 12px; }
/* Rozmiar czcionki względem szerokości panelu (cqw), więc tablica meczów skaluje się i w podziale, i na całym ekranie. */
.scr-matches-panel { container-type: inline-size; }
.scr-matches { padding: 1.5vh 1.2vw; font-size: clamp(13px, 3.2cqw, 34px); }
.scr-matches h3 { font-size: 1em; margin: .8em 0 .3em; color: var(--accent); text-transform: uppercase; letter-spacing: .04em; }
.scr-matches h3:first-child { margin-top: 0; }
.scr-m { display: grid; grid-template-columns: 6.2em 1fr auto 1fr 9em; align-items: center; gap: .6em; padding: .3em .5em; border-bottom: 1px solid var(--line); }
.scr-m.live { background: var(--accent-soft); border-radius: 6px; border-bottom-color: transparent; margin-bottom: 3px; }
.scr-m.next { color: var(--text); }
.scr-m.done { color: var(--muted); font-size: .85em; }
.scr-m.top { font-size: 1.15em; font-weight: 600; }
.scr-board { font-weight: 700; color: var(--board); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scr-m.next .scr-board, .scr-m.done .scr-board { color: var(--muted); font-weight: 400; }
.scr-pl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scr-pl.win { font-weight: 700; color: var(--accent); }
/* Zawodnik, który odpadł z turnieju — nazwisko na czerwono. */
.scr-pl.out { color: #d40000; }
:root[data-theme="dark"] .scr-pl.out { color: #ff2a1f; }
.scr-sc { font-weight: 800; min-width: 3em; text-align: center; font-variant-numeric: tabular-nums; }
.scr-rd { font-size: .6em; color: var(--muted); text-align: right; }
.scr-none { color: var(--muted); margin: .2em .5em; }
.scr-champion { font-size: 2em; font-weight: 800; margin: .3em 0 .6em; }
.scr-m:has(.scr-no) { grid-template-columns: 3em 1fr; }
.scr-no { font-weight: 700; }
@container (max-width: 1000px) {
  .scr-m { grid-template-columns: 5.4em 1fr auto 1fr; gap: .45em; }
  .scr-rd { display: none; }
}
.scr-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: clamp(28px, 5vw, 96px); font-weight: 700; color: var(--muted); }
.scr-empty small { font-size: .35em; font-weight: 400; margin-top: .5em; }
/* Lista zapisanych przed losowaniem (jedna albo dwie kolumny: kobiety / mężczyźni) */
.scr-entries { padding: 1.5vh 1.5vw; container-type: inline-size; }
.scr-entries-note { text-align: center; color: var(--muted); font-weight: 600; font-size: clamp(12px, 1.3cqw, 26px); margin-bottom: .8em; }
.scr-entries-grid { display: grid; gap: 2.5cqw; font-size: clamp(14px, 1.5cqw, 30px); }
.scr-entries-grid.cols-2 { grid-template-columns: 1fr 1fr; }
.scr-entries-grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.scr-entries-col h3 { font-size: 1em; margin: 0 0 .5em; color: var(--accent); text-transform: uppercase; letter-spacing: .04em; }
.scr-entries-col h3 .scr-cat { font-size: .8em; margin-left: 0; text-transform: none; letter-spacing: 0; }
.scr-entries-col h3 span { text-transform: none; letter-spacing: 0; color: var(--muted); font-weight: 400; font-size: .75em; margin-left: .6em; }
.scr-entries-list { margin: 0; padding-left: 2.4em; }
.scr-entries-list li { padding: .18em 0; border-bottom: 1px solid var(--line); break-inside: avoid; font-weight: 600; }
.scr-entries-list li::marker { color: var(--muted); font-weight: 400; font-size: .8em; }

/* Pola wyszukiwania z przyciskiem „×” (widoczny tylko, gdy coś jest wpisane) */
.search-wrap { position: relative; display: inline-flex; align-items: center; }
.ac .search-wrap { display: flex; }
.search-wrap input, .ac .search-wrap input { padding-right: 36px; width: 100%; }
.clear-btn { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 24px; height: 24px; border: none; border-radius: 50%;
  background: var(--line); color: var(--text); cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0; }
.clear-btn svg { display: block; }
.clear-btn:hover { background: var(--danger); color: #fff; }
.search-wrap input:placeholder-shown + .clear-btn { display: none; }

/* Autouzupełnianie */
.ac { position: relative; max-width: 560px; }
.ac input { width: 100%; font-size: 15px; padding: 10px 12px; }
.ac-list { position: absolute; left: 0; right: 0; top: 100%; z-index: 5; list-style: none; margin: 2px 0 0; padding: 4px 0; background: var(--card); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 6px 20px var(--shadow); max-height: 360px; overflow: auto; }
.ac-list li { padding: 6px 12px; cursor: pointer; }
.ac-list li.hl, .ac-list li:hover { background: var(--accent-soft); }
.ac-list li.new { border-top: 1px solid var(--line); }

/* Drabinka */
.bracket-scroll { overflow-x: auto; padding-bottom: 6px; }
.bracket { display: flex; gap: 18px; align-items: stretch; min-width: min-content; }
.round { display: flex; flex-direction: column; width: 210px; flex: 0 0 210px; }
.round-head { font-weight: 600; font-size: 13px; padding: 4px 2px 8px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.round-head small { display: block; color: var(--muted); font-weight: 400; font-size: 11px; }
.round-body { flex: 1; display: flex; flex-direction: column; justify-content: space-around; gap: 6px; }
.m { border: 1px solid var(--line); border-radius: 6px; background: var(--done-bg); font-size: 12.5px; overflow: hidden; }
.m[data-action] { cursor: pointer; }
.m[data-action]:hover { border-color: var(--accent); box-shadow: 0 1px 6px rgba(0, 0, 0, .1); }
.m.s-ready { background: var(--ready); border-color: var(--ready-border); border-left-width: 4px; }
.m.s-ready.on-board { border-color: var(--board); }
.m.s-waiting, .m.s-bye, .m.s-skipped { opacity: .55; }
.m-head { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--muted); padding: 2px 6px; border-bottom: 1px solid var(--line); }
.m-board { color: var(--board); font-weight: 600; }
/* Publikacja na stronie www */
.pub-url { flex: 2 1 320px; }
.pub-key { flex: 1 1 260px; }
.pub-key input { font-family: Consolas, monospace; }
/* Pole z podpisem + przyciski + stan: przyciski i stan na wysokości pola (nie podpisu), wszystko tej samej wysokości */
.pub-row { margin-top: 8px; align-items: flex-end; }
.pub-row > span { min-height: 34px; display: inline-flex; align-items: center; gap: 6px; }
.pub-row label input { height: 34px; box-sizing: border-box; }
.pub-err { color: var(--danger); font-weight: 600; }
code.pub-code { user-select: all; background: var(--th-bg); padding: 2px 6px; border-radius: 4px; font-size: 12px; }
/* Strona www (tylko do odczytu) */
.web-live { font-size: 12px; color: var(--muted); }
/* Opłacone wpisowe (lista zapisów) */
.note10 { vertical-align: middle; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .25)); }
.paid-cell { width: 80px; }
.paid-note { margin-left: 6px; }
input.paid-chk { width: 18px; height: 18px; vertical-align: middle; margin: 0; cursor: pointer; accent-color: #1f6f43; }
/* Ranking na żywo */
.lr-up { color: #1a8d3c; font-weight: 700; }
.lr-down { color: var(--danger); font-weight: 700; }
:root[data-theme="dark"] .lr-up { color: #4ccb72; }
.live-rank tr.lr-playing td { background: var(--accent-soft); }
/* Zegar meczu (zakładka Mecze) */
.m-timer { display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 12px; font-variant-numeric: tabular-nums; }
.m-dur { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.m-head-r { display: inline-flex; gap: 6px; align-items: center; }
.m-rec { color: #d4a017; font-size: 12px; line-height: 1; cursor: help; }
.m-row { display: flex; justify-content: space-between; gap: 6px; padding: 3px 6px; }
.m-row + .m-row { border-top: 1px dashed var(--line); }
.m-row .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-row .sc { font-weight: 700; min-width: 12px; text-align: right; }
.m-row.win { font-weight: 700; color: var(--accent); }
.m-note { padding: 6px; color: var(--muted); font-style: italic; }

/* Okno dialogowe */
dialog { border: none; border-radius: 10px; padding: 0; width: min(600px, calc(100vw - 32px)); background: var(--card); color: var(--text); box-shadow: 0 10px 40px rgba(0, 0, 0, .3); }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
.dlg-body { padding: 20px; display: flex; flex-direction: column; gap: 10px; }
.dlg-body h2 { margin-bottom: 4px; }
.dlg-player { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.dlg-name { font-size: 16px; font-weight: 600; }
.dlg-name small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.legs { display: flex; gap: 4px; flex-wrap: wrap; }
.leg { font: inherit; font-size: 16px; font-weight: 600; width: 40px; height: 40px; border-radius: 6px; border: 1px solid var(--line); background: var(--card); color: var(--text); cursor: pointer; }
.leg.sel { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
/* Rekordy w oknie wyniku: 180 / 171 / HF / SL */
.dlg-recs { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; padding: 6px 8px; margin-top: -4px; background: var(--done-bg); border: 1px solid var(--line); border-radius: 6px; }
.rec-grp { display: inline-flex; flex-direction: row; align-items: center; gap: 3px; font-size: 13px; color: var(--text); }
.rec-l { font-weight: 700; font-size: 12px; color: var(--muted); margin-right: 3px; }
.rec-btn { font: inherit; font-size: 13px; font-weight: 600; width: 28px; height: 28px; border-radius: 5px; border: 1px solid var(--line); background: var(--card); color: var(--text); cursor: pointer; }
.rec-btn.sel { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
input.rec-in { width: 70px; padding: 4px 6px; }
.rec-btn:disabled { opacity: .3; cursor: not-allowed; }
/* Rekordy rozpisane na legi (widok rozszerzony okna wyniku) */
dialog.wide { width: min(900px, calc(100vw - 32px)); }
.rec-toggle { align-self: flex-start; }
.leg-recs { display: flex; flex-direction: column; gap: 8px; }
.leg-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 6px; }
.leg-table { width: 100%; min-width: 690px; border-collapse: collapse; table-layout: fixed; font-size: 13px; }
.leg-table col.c-no { width: 44px; }
.leg-table col.c-max { width: 112px; }
.leg-table col.c-fin { width: 96px; }
.leg-table th, .leg-table td { padding: 5px 6px; text-align: center; white-space: nowrap; }
.leg-table thead th { background: var(--th-bg); font-weight: 700; overflow: hidden; text-overflow: ellipsis; }
.leg-table thead tr:first-child th { font-size: 13px; color: var(--text); padding-top: 8px; }
.leg-table thead tr.sub th { font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--line); }
.leg-table .leg-group-head td { text-align: left; background: var(--accent-soft); padding: 6px 10px; border-top: 1px solid var(--line); }
.leg-table .leg-row td { border-top: 1px solid var(--line); }
.leg-table .leg-row.has td { background: var(--done-bg); }
/* Kolumny każdego zawodnika zabarwione od nagłówka do dołu — od razu widać, czyje są rekordy. */
.leg-table td.ca, .leg-table .leg-row.has td.ca { background: var(--pa-col); }
.leg-table td.cb, .leg-table .leg-row.has td.cb { background: var(--pb-col); }
/* Nagłówek zawodnika w dokładnie tym samym kolorze co jego kolumny (ten sam odcień na tle karty, nie na szarym). */
.leg-table thead th.ca { background: linear-gradient(var(--pa-col), var(--pa-col)), var(--card); }
.leg-table thead th.cb { background: linear-gradient(var(--pb-col), var(--pb-col)), var(--card); }
/* Nagłówki 180 / 171 / HF / SL — pogrubione i wyraźne. */
.leg-table thead tr.sub th { color: var(--text); font-size: 13px; font-weight: 800; }
.leg-table .leg-no { font-weight: 700; color: var(--muted); }
.leg-table .rec-btn { width: 30px; height: 30px; margin: 0 1px; }
.leg-table input.rec-in { width: 100%; text-align: center; font-weight: 700; font-size: 14px; }
/* HF bez strzałek góra/dół (zajmowały miejsce z prawej i przesuwały tekst w lewo). */
.leg-table input.rec-in[data-key="hf"] { -moz-appearance: textfield; appearance: textfield; }
.leg-table input.rec-in[data-key="hf"]::-webkit-inner-spin-button, .leg-table input.rec-in[data-key="hf"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
/* SL ze strzałkami — lewy margines równy ich szerokości, żeby tekst był na środku. */
.leg-table input.rec-in[data-key="sl"] { padding-left: 21px; }
/* Podpowiedzi (100–170, 9–18) wyraźnie jaśniejsze od wpisanych wartości. */
input.rec-in::placeholder { color: var(--muted); opacity: .45; font-weight: 400; font-size: 12px; }
.leg-table .leg-err td { padding-top: 0; text-align: left; white-space: normal; }
.leg-table .leg-err .msg { margin: 0; }
.legacy-recs { display: block; }
.legacy-recs .btn { margin-left: 6px; }
.msg.small { font-size: 12px; padding: 5px 10px; margin: 0; }
/* Najlepsze rekordy (klasyfikacja, rankingi, ekran dla widzów) */
.rec-leads { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.rec-lead { display: flex; flex-direction: column; background: var(--accent-soft); border-radius: 8px; padding: 8px 14px; min-width: 150px; }
.rec-lead span { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.rec-lead b { font-size: 14px; }
.rec-lead em { font-style: normal; font-size: 20px; font-weight: 800; color: var(--accent); }
.tbl .rec-col { width: 48px; font-variant-numeric: tabular-nums; }
.scr-matches .rec-leads { gap: .4em; }
.scr-matches .rec-lead { padding: .3em .6em; min-width: 0; }
.scr-matches .rec-lead span { font-size: .55em; }
.scr-matches .rec-lead b { font-size: .75em; }
.scr-matches .rec-lead em { font-size: .9em; }
.vs { text-align: center; color: var(--muted); font-size: 12px; }
.dlg-board { flex-direction: row; align-items: center; gap: 8px; font-size: 14px; color: var(--text); }
.dlg-actions { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.spacer { flex: 1; }

.toast { position: fixed; bottom: 48px; left: 50%; transform: translateX(-50%) translateY(80px); background: var(--toast-bg); color: #fff; padding: 10px 18px; border-radius: 8px; opacity: 0; transition: .25s; z-index: 100; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); }
.toast.ok { background: #1f6f43; }
.toast.warn { background: #b26a00; }

/* Na węższych ekranach nagłówek zawija się w kilka wierszy — wtedy nie przyklejamy go, żeby nie zasłaniał treści. */
@media (max-width: 1000px) {
  .top { position: static; gap: 10px 20px; }
}
@media (max-width: 640px) {
  main { padding: 12px 16px 40px; }
  .tbl { font-size: 13px; display: block; overflow-x: auto; } /* szeroka tabela przewija się w swojej ramce, a nie cała strona */
  .row-form > * { flex: 1 1 100%; }
}
@media print {
  /* Wydruk zawsze w jasnych kolorach, niezależnie od wybranego motywu. */
  :root, :root[data-theme] { --bg: #fff; --card: #fff; --text: #000; --muted: #444; --line: #bbb; --done-bg: #fff; --ready: #fff; --th-bg: #eee;
    --col-pts: rgba(0, 0, 0, .07); --col-rec: rgba(0, 0, 0, .04); --col-t-even: rgba(0, 0, 0, .03); --accent: #1f6f43; color-scheme: light; }
  .top, .tabs, .btn, .t-head a, .msg, .foot, #sync-banner { display: none !important; }
  .table-scroll { overflow: visible; max-height: none; }
  .card-head .chips { display: none !important; }
  body { background: #fff; }
  .card { border: none; padding: 0; }
  /* Statystyki zawodnika */
  @page { margin: 12mm; }
  main:has(.stats-filter) { zoom: .82; } /* statystyki zawodnika: mniejsza czcionka, układ bez zmian */
  .stats-filter { display: none !important; }
  .print-only { display: block !important; margin-top: 4px; }
  .stat-tiles, .stat-tile, .tbl tr { break-inside: avoid; }
  .card { margin-bottom: 14px; }
  a { color: inherit; text-decoration: none; }
}
.print-only { display: none; }
