:root {
  --bg: #0f1220;
  --panel: #1a1f36;
  --panel2: #232a4d;
  --text: #e8ebf7;
  --muted: #9aa3c4;
  --accent: #6ea8fe;
  --good: #3fb950;
  --bad: #f85149;
  --warn: #d29922;
  --border: #2c335c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

header {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  min-height: 57px;
  padding: 0 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

header .brand { font-weight: 700; font-size: 18px; display: flex; align-items: center; }
/* brand is not a navigation target: keep its light-blue look but make it
   unclickable with no link cursor */
header .brand a { pointer-events: none; cursor: default; text-decoration: none; color: var(--accent); }
header .who { color: var(--muted); font-size: 14px; display: flex; align-items: center; }
header .who b { color: var(--text); }
header .who a { color: inherit; text-decoration: none; }
header .who a:hover b { text-decoration: underline; }
header .mainnav { display: flex; gap: 0; flex: 1; margin: 0 24px; flex-wrap: wrap; align-items: stretch; }
header .mainnav a {
  color: var(--muted); font-size: 14px; font-weight: 600;
  display: flex; align-items: center;
  padding: 0 16px; transition: background 0.12s;
}
/* nav links never get the global underline-on-hover */
header .mainnav a:hover { text-decoration: none; }
header .mainnav a.active { color: var(--text); }
/* highlight the whole full-height box on hover; the mouse is always inside a
   clickable box (no gaps) */
header .mainnav a:hover { background: var(--panel2); }
/* the "|" divider is the box's own right edge, so each box ends exactly at the
   divider line */
header .mainnav a:not(:last-child) {
  border-right: 1px solid var(--border);
}
/* row-break markers: invisible/no-op on desktop (nav stays one inline row) */
header .mainnav .nav-break { display: none; }
/* desktop: push "Môj účet" to the far right of the nav (gap before it), so it
   sits just left of the "Prihlásený ako…" block */
header .mainnav .nav-account { order: 100; margin-left: auto; border-right: none; }

/* mobile: brand on its own row, nav items fill the full screen width */
@media (max-width: 640px) {
  header {
    flex-direction: column;
    align-items: stretch;
    min-height: 0;
    gap: 8px;
    padding: 14px 0;          /* no side padding so the nav can span edge-to-edge */
  }
  header .brand { padding: 0 16px; }   /* keep the brand indented */
  header .who { padding: 0 16px; }
  header .mainnav { margin: 0; width: 100%; flex-direction: row; flex-wrap: wrap; gap: 0; align-items: stretch; }
  /* items on a line grow to fill the whole row width (no left/right gaps); rows
     stack with no vertical gaps either. Thin borders separate boxes. */
  header .mainnav a {
    flex: 1 1 auto; width: auto; justify-content: center;
    padding: 12px 12px; border-radius: 0;
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    background: var(--panel2);
  }
  /* first item of each row has no left border, last has no right border — but
     since rows wrap dynamically we just drop the outermost edges via the header
     having no side padding, so boxes meet the screen edges cleanly */
  header .mainnav a.active { background: var(--accent); color: #0b1020; }
  /* on mobile, Môj účet stays in its normal row-1 slot (undo desktop right-push) */
  header .mainnav .nav-account { order: 0; margin-left: 0; border-right: 1px solid var(--border); }
  /* force a new row after each group: a full-width, zero-height flex item makes
     everything after it wrap to the next line. Guarantees the requested rows
     (core / series / signup+betting) regardless of label lengths. */
  header .mainnav .nav-break {
    display: block; flex-basis: 100%; width: 100%; height: 0; margin: 0; padding: 0;
  }
}

main { max-width: 900px; margin: 0 auto; padding: 24px; }

h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 17px; margin: 24px 0 10px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  margin-bottom: 16px;
}

.row { display: flex; gap: 12px; align-items: center; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }

input[type="text"], input[type="password"], input[type="number"], select, textarea {
  width: 100%;
  padding: 9px 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel2);
  color: var(--text);
  font-size: 14px;
}
input:focus, select:focus, textarea:focus { outline: 1px solid var(--accent); }

textarea { min-height: 90px; resize: vertical; }

button, .btn {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  background: var(--accent);
  color: #0b1020;
}
button:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-ghost { background: var(--panel2); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--bad); color: #fff; }
.btn-warn { background: var(--warn); color: #0b1020; }

.field { margin-bottom: 14px; }

.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.pill.open { background: rgba(63,185,80,.18); color: var(--good); }
.pill.nabor { background: rgba(139,148,158,.20); color: var(--muted); }
.pill.locked { background: rgba(210,153,34,.18); color: var(--warn); }

/* floating admin controls (shutdown + network toggle), stacked top-right */
#floatCtrls {
  position: fixed; top: 64px; right: 12px; z-index: 1000;
  display: flex; flex-direction: column; gap: 8px; align-items: stretch;
}
#floatCtrls button {
  width: 180px; text-align: center;
  box-shadow: 0 2px 8px rgba(0,0,0,.35);
}
#floatCtrls form { display: block; }
.pill.resulted { background: rgba(110,168,254,.18); color: var(--accent); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 14px; }
th { color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: none; }

/* Player profile: final placements + stats side by side, wrapping on narrow */
.profile-tables { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.profile-tables-col { flex: 1 1 320px; min-width: 0; }
.profile-tables-col h2 { margin-top: 0; }
table.tight th, table.tight td { padding: 5px 8px; font-size: 13px; }
.stats-table th, .stats-table td { padding: 5px 8px; font-size: 13px; }
.stats-table th[title] { cursor: help; }

.error { color: var(--bad); font-size: 13px; margin-top: 8px; }
.ok { color: var(--good); }
.notice { background: var(--panel2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 14px; font-size: 14px; }

/* Betting board */
.bet-player {
  display: grid;
  grid-template-columns: 28px 1fr 130px 120px;
  gap: 12px;
  align-items: center;
  padding: 10px;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 8px;
}
.bet-player .idx { color: var(--muted); text-align: center; }
.bet-player .pname { font-weight: 600; }
.bet-player input[type="number"] { width: 100%; }

.summary {
  position: sticky;
  bottom: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-top: 10px;
  display: flex;
  gap: 24px;
  align-items: center;
  flex-wrap: wrap;
}
.summary .stat b { font-size: 18px; }
.check-ok { color: var(--good); }
.check-bad { color: var(--bad); }

.leaderboard-rank { font-weight: 700; color: var(--accent); }

.drag-handle { cursor: grab; color: var(--muted); }
.bet-player.dragging { opacity: 0.5; }
.bet-player.drag-over { outline: 2px dashed var(--accent); }

/* avatars */
.avatar {
  width: 40px; height: 40px; border-radius: 50%;
  object-fit: cover; background: var(--panel2);
  border: 1px solid var(--border); flex: none;
}
.avatar.sm { width: 28px; height: 28px; }
.avatar.lg { width: 64px; height: 64px; }
/* framed avatars render as a background so zoom changes the crop, not the box
   size, and zooming out can reveal the whole photo */
.avatar.avatar-bg { background-repeat: no-repeat; background-position: center;
  background-size: cover; display: inline-block; }

/* admin avatar cropper (drag-to-frame the mini icon) */
.avatar-frame-trigger { cursor: pointer; }
.cropper-modal {
  position: fixed; inset: 0; z-index: 1100;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.8); padding: 20px;
}
.cropper-modal[hidden] { display: none; }
.cropper-dialog {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px; max-width: 92vw; display: flex; flex-direction: column; gap: 10px;
}
/* the stage is a SQUARE window and the image fills it with the same
   background-size/position model as the mini avatar (.avatar-bg). The circular
   hole fills the whole square (touches all four edges) exactly like the mini
   icon's circle fills its square box — so the crop shown here == the mini photo.
   Bigger on desktop; on mobile it shrinks to fit and stays centered. */
.cropper-stage {
  position: relative; width: 420px; height: 420px; max-width: 82vw; max-height: 82vw;
  margin: 0 auto;
  overflow: hidden; border-radius: 8px; background: #000; touch-action: none;
  user-select: none;
}
.cropper-img {
  position: absolute; inset: 0;
  background-repeat: no-repeat; background-position: center; background-size: cover;
}
/* darken everything outside the circle; the circle spans the full square,
   edge-to-edge (diameter = stage width), matching the round mini avatar.
   closest-side sizes the gradient radius to HALF the box (touches all 4 edges);
   the transparent→opaque stop sits at that radius. */
.cropper-hole {
  position: absolute; inset: 0; pointer-events: none; border-radius: 8px;
  background: rgba(0,0,0,.72);
  -webkit-mask: radial-gradient(circle closest-side at center, transparent 99.5%, #000 100%);
          mask: radial-gradient(circle closest-side at center, transparent 99.5%, #000 100%);
}
.cropper-buttons { display: flex; align-items: center; gap: 8px; }
@media (max-width: 640px) {
  .cropper-dialog { width: 92vw; }
  .cropper-stage { width: 82vw; height: 82vw; }
}

/* roster grid */
.roster-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}
.roster-card {
  background: var(--panel2); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px; display: flex; gap: 10px; align-items: center;
}
.roster-card > .grow { min-width: 0; }
.roster-card input[type="text"] { max-width: 100%; }
.roster-card .rname { font-weight: 600; flex: 1; min-width: 0; overflow-wrap: anywhere; }

/* the logged-in player's own card: subtle accent tint, not a full invert */
.roster-card.card-mine {
  background: rgba(110,168,254,.12);
  border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}
/* waiting for admin approval: subtle tint + red frame + note */
.roster-card.card-pending {
  background: rgba(248,81,73,.10);
  border: 2px solid var(--bad);
  box-shadow: none;
}
.pending-note {
  display: inline-block; margin-top: 2px; font-size: 12px; font-weight: 700;
  color: var(--bad);
}

/* series page: editions on the left, all-time ranking on the right */
.series-layout { display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap; }
.series-editions { flex: 1 1 300px; min-width: 0; }
.series-ranking { flex: 2 1 460px; min-width: 280px; }
.series-ranking h2 { margin-top: 0; }
.ranking-table { width: 100%; border-collapse: collapse; }
.ranking-table th, .ranking-table td {
  padding: 6px 8px; text-align: left; border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.ranking-table th { color: var(--muted); font-weight: 600; }
.ranking-table td:first-child { color: var(--muted); width: 44px; }
.link-badge {
  display: inline-block; margin-top: 2px; font-size: 12px; font-weight: 600;
  color: var(--accent); overflow-wrap: anywhere;
}
.link-none { color: var(--muted); font-size: 12px; font-style: italic; }
.link-requests { margin-bottom: 20px; }
.link-req-row {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  background: var(--panel2); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 12px; margin-bottom: 8px;
}
.link-req-row .grow { flex: 1; min-width: 160px; overflow-wrap: anywhere; }

/* series edition cards */
.edition-winner {
  display: flex; align-items: center; gap: 6px; margin-top: 8px;
  font-weight: 600;
}
.edition-winner span { overflow-wrap: anywhere; }
.walkon { margin-top: 4px; font-size: 14px; }
.walkon a { color: var(--accent); }
.edition-link {
  display: block; text-decoration: none; color: inherit;
  transition: border-color .12s, transform .12s;
}
.edition-link:hover {
  border-color: var(--accent); transform: translateY(-1px);
}

/* home-page announcement */
.announcement {
  background: var(--panel2); border: 1px solid var(--border);
  border-left: 4px solid var(--accent); border-radius: 10px;
  padding: 14px 16px; margin-bottom: 16px; line-height: 1.5;
  overflow-wrap: anywhere;
}

/* roster picker (tournament creation) */
.pick-list { display: flex; flex-direction: column; gap: 6px; max-height: 340px; overflow: auto; }
.pick-item {
  display: flex; gap: 10px; align-items: center;
  background: var(--panel2); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; cursor: pointer;
}
.pick-item.selected { outline: 2px solid var(--accent); }
.pick-item .order-badge {
  min-width: 24px; height: 24px; border-radius: 50%; display: inline-flex;
  align-items: center; justify-content: center; font-size: 12px; font-weight: 700;
  background: var(--accent); color: #0b1020;
}
.pick-item .order-badge.empty { background: transparent; color: var(--muted); border: 1px dashed var(--border); }

/* history editor */
.hist-table { margin-bottom: 18px; }
.hist-table input[type="text"] { padding: 6px 8px; }
.editable-td input { width: 100%; padding: 6px 8px; }
.mini-btn { padding: 4px 10px; font-size: 12px; }
.match-row { display: flex; gap: 8px; margin-bottom: 6px; align-items: center; flex-wrap: wrap; }
.match-row input { padding: 6px 8px; flex: 1 1 120px; min-width: 90px; }
.match-row select { padding: 6px 8px; flex: 0 1 150px; }
.match-row > button { flex: 0 0 auto; }

/* Unified clickable player chip, used everywhere a player name appears. */
.player-link {
  display: inline-flex; align-items: center; gap: 8px; color: var(--text);
  padding: 6px 10px; border-radius: 8px; transition: background 0.12s, color 0.12s;
}
a.player-link:hover { background: var(--panel2); color: var(--accent); text-decoration: none; }

/* A table cell that holds a player chip: the chip fills the whole cell so the
   entire cell is clickable. */
.player-cell { padding: 0; }
.player-cell .player-link { display: flex; width: 100%; box-sizing: border-box; }

/* results page: avatar + name, vertically centred to line up with the
   result dropdown / number input in the next cell */
.player-cell-mid { vertical-align: middle; }
.player-cell-mid { display: table-cell; }
.player-cell-mid img { vertical-align: middle; margin-right: 8px; }
.player-cell-mid span { vertical-align: middle; }

/* match rows: [ Player A -> ][ Score ][ <- Player B ] */
.match-table { width: 100%; }
.match-table th.match-pa, .match-table td.match-pa { text-align: right; width: 42%; }
.match-table th.match-pb, .match-table td.match-pb { text-align: left; width: 42%; }
.match-table th.match-score, .match-table td.match-score {
  text-align: center; width: 16%; font-weight: 700; white-space: nowrap;
}
/* Player A faces the score: avatar on the right, content pushed right.
   NOTE: with row-reverse the main axis is flipped, so flex-start packs to the
   RIGHT (visually). Use flex-start here, flex-start (normal) for player B. */
.match-table td.match-pa .player-link { flex-direction: row-reverse; }
.match-table td.match-pa, .match-table td.match-pb { padding: 0; }
.match-table td.match-pa .player-link,
.match-table td.match-pb .player-link {
  display: flex; width: 100%; box-sizing: border-box; padding: 8px 12px;
}
.match-table td.match-pa .player-link { justify-content: flex-start; }
.match-table td.match-pb .player-link { justify-content: flex-start; }
/* Winning player in a match row: bold name + green background (50% opacity). */
.match-table td.match-winner { background: rgba(63, 185, 80, 0.5); }
.match-table td.match-winner .player-link { font-weight: 700; color: var(--text); }
.match-table td.match-winner .player-link:hover { color: var(--text); }

/* result cell on the player profile: coloured by outcome, whole cell clickable */
.result-cell { padding: 0; }
.result-cell .cell-link {
  display: block; padding: 8px 12px; color: var(--text); transition: filter 0.12s;
}
.result-cell .cell-link:hover { text-decoration: none; filter: brightness(1.25); }
.res-win  { background: rgba(63,185,80,.22); }
.res-draw { background: rgba(210,153,34,.22); }
.res-loss { background: rgba(248,81,73,.20); }
.cell-link { color: var(--text); }
.cell-link:hover { text-decoration: none; color: var(--accent); }

.year-list { display: flex; gap: 10px; flex-wrap: wrap; }
.admin-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.pos-cell { color: var(--muted); font-weight: 700; text-align: center; min-width: 32px; white-space: nowrap; }

/* Konečné poradie: keep the # column tight, let Hráč take the rest. */
.fin-table th:first-child, .fin-table td:first-child { width: 1%; white-space: nowrap; padding-right: 14px; }
.fin-table th:last-child, .fin-table td:last-child { width: 100%; }

/* free-text notes for a group / playoff stage */
.note-text { margin: 6px 0 0; color: var(--muted); font-style: italic; white-space: pre-wrap; }

/* Trackmania: per-track medal backgrounds (50% opacity) on the fastest 3 */
.tm-gold   { background: rgba(255, 200, 40, 0.5); font-weight: 700; }
.tm-silver { background: rgba(180, 190, 200, 0.5); font-weight: 700; }
.tm-bronze { background: rgba(200, 130, 70, 0.5); font-weight: 700; }
.tm-edit input { padding: 5px 7px; }
.tm-edit td, .tm-edit th { padding: 5px 8px; }
.tm-pos { color: var(--muted); font-size: 12px; font-weight: 400; }
.row-tools { display: flex; flex-direction: column; gap: 2px; }
.row-tools button { line-height: 1; padding: 2px 6px; }
.stage-section { border-left: 3px solid var(--accent); }

/* Collapsible section (e.g. Vytvoriť turnaj) */
.collapsible > summary {
  cursor: pointer; list-style: none; display: flex; align-items: center; gap: 8px;
  user-select: none; padding: 4px 6px; margin: -4px -6px; border-radius: 8px;
  transition: background 0.12s;
}
.collapsible > summary:hover { background: var(--panel2); }
.collapsible > summary::-webkit-details-marker { display: none; }
.collapsible > summary::before {
  content: "▸"; color: var(--accent); font-size: 14px; transition: transform 0.12s;
}
.collapsible[open] > summary::before { transform: rotate(90deg); }
.collapsible > summary:hover h2 { color: var(--accent); }
.collapsible > form { margin-top: 14px; }

/* results editor: draggable player chips into ordered list / group slots */
.res-chip {
  display: inline-flex; align-items: center; gap: 8px; cursor: grab;
  background: var(--panel2); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; margin: 4px;
}
.res-chip.dragging { opacity: 0.4; }
.res-row { display: flex; align-items: center; gap: 10px; padding: 2px 0; }
.res-row.drop-hint { outline: 2px dashed var(--accent); border-radius: 8px; }
.res-list { display: flex; flex-direction: column; gap: 2px; }
.res-slot { }
.res-dropzone {
  min-height: 44px; border: 1px dashed var(--border); border-radius: 8px;
  padding: 4px; display: flex; flex-wrap: wrap; align-items: center;
}
.res-dropzone.drop-hint { border-color: var(--accent); background: rgba(110,168,254,.08); }
.res-band-header {
  font-weight: 700; color: var(--accent); margin: 10px 0 2px;
  border-bottom: 1px solid var(--border); padding-bottom: 2px;
}

.net-banner { border-radius: 10px; padding: 12px 14px; margin-bottom: 16px; font-size: 14px; }
.net-banner code { background: rgba(0,0,0,.35); padding: 2px 6px; border-radius: 5px; }
.net-banner.net-off { background: rgba(210,153,34,.15); border: 1px solid var(--warn); }
.net-banner.net-on { background: rgba(63,185,80,.15); border: 1px solid var(--good); }
.copy-row { display: flex; gap: 8px; align-items: center; margin: 8px 0; flex-wrap: wrap; }
.copy-row code { font-size: 14px; }

/* click-to-enlarge avatar lightbox */
.lightbox {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .8); cursor: zoom-out; padding: 24px;
}
.lightbox img {
  max-width: 90vw; max-height: 90vh;
  border-radius: 12px; box-shadow: 0 8px 40px rgba(0, 0, 0, .6);
}
