:root {
  color-scheme: light;
  --bg: #f5f7f6;
  --panel: #ffffff;
  --ink: #1d2524;
  --muted: #66736f;
  --line: #d9e1de;
  --accent: #0d7f61;
  --accent-strong: #075f49;
  --warn: #9b5d25;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, textarea, select { font: inherit; }

button {
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  min-height: 36px;
  padding: 0 12px;
  cursor: pointer;
}

button:hover { background: var(--accent-strong); }
button.secondary { background: #e8eeeb; color: var(--ink); }
button.warning { background: var(--warn); }
button.danger { background: #9f2e2e; }
button.danger:hover { background: #782222; }

input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--ink);
  min-height: 36px;
  padding: 8px 10px;
}

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

.topbar {
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: #13211e;
  color: white;
}

.topbar h1 { margin: 0; font-size: 22px; letter-spacing: 0; }
.topbar p { margin: 2px 0 0; color: #c6d4d0; }

.iconButton { width: 40px; padding: 0; }

.topActions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.authBar {
  min-width: 0;
}

.loginForm,
.authStatus {
  display: flex;
  gap: 8px;
  align-items: center;
}

.loginForm input {
  width: 150px;
  min-height: 34px;
  border-color: rgba(255, 255, 255, 0.24);
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

.loginForm input::placeholder {
  color: #c6d4d0;
}

.loginForm button,
.authStatus button {
  min-height: 34px;
}

.authStatus span {
  color: #dbe6e3;
  white-space: nowrap;
}

.authLoading span {
  color: #c6d4d0;
}

.publicMode .adminOnly {
  display: none !important;
}

/* Hide private navigation and panels before JS finishes, and after logout. */
.publicMode .tab:not([data-tab="ranking"]):not([data-tab="allMatches"]):not([data-tab="comparison"]),
.publicMode .tabPanel:not([data-panel="ranking"]):not([data-panel="allMatches"]):not([data-panel="comparison"]),
.tab[hidden], .tabPanel[hidden] {
  display: none !important;
}

.appBooting .tabs,
.appBooting .content {
  visibility: hidden;
}

.tabs {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding: 10px 24px 0;
  background: #edf2ef;
  border-bottom: 1px solid var(--line);
}

.tab {
  min-width: 124px;
  border: 1px solid transparent;
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  background: transparent;
  color: #33413d;
}

.tab.active {
  background: var(--bg);
  border-color: var(--line);
  color: var(--ink);
  font-weight: 650;
}

@media (max-width: 760px) {
  .topbar {
    height: auto;
    min-height: 72px;
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    padding: 14px 18px;
  }

  .topActions {
    width: 100%;
  }

  .authBar {
    flex: 1;
  }

  .loginForm {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
    display: grid;
    width: 100%;
  }

  .loginForm input {
    width: 100%;
  }
}

.statsPanel {
  display: grid;
  gap: 16px;
}

.statsHeader {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 320px);
  gap: 16px;
  align-items: end;
}

.statsHeader h2 {
  margin-bottom: 2px;
}

.statsFilters {
  display: grid;
  grid-template-columns: minmax(150px, 190px) minmax(180px, 1fr) minmax(160px, 210px) minmax(220px, 1.2fr);
  gap: 12px;
  align-items: end;
}

.statsPlayerField {
  min-width: 0;
}

.statsSection {
  display: grid;
  gap: 12px;
}

.statsSectionHeader {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: end;
}

.statsSectionHeader h3 {
  margin: 0;
}

.statsSummaryGrid {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 10px;
}

.statsSummaryGrid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  padding: 10px 12px;
}

.statsSummaryGrid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.statsSummaryGrid strong {
  display: block;
  margin-top: 2px;
  font-size: 18px;
}

.eloChartScroll,
.statsTableScroll {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.eloChart {
  display: block;
  overflow: visible;
}

.eloTick line {
  stroke: #dfe6e3;
  stroke-width: 1;
}

.eloTick text,
.dateLabel {
  fill: var(--muted);
  font-size: 11px;
  paint-order: stroke;
  stroke: #fbfcfb;
  stroke-width: 3px;
}

.eloCandle .wick {
  stroke-width: 2;
}

.eloCandle .body {
  stroke-width: 1.5;
  rx: 2;
}

.eloCandle.up .wick,
.eloCandle.up .body {
  stroke: var(--accent-strong);
}

.eloCandle.up .body {
  fill: #cdece2;
}

.eloCandle.down .wick,
.eloCandle.down .body {
  stroke: #9f2e2e;
}

.eloCandle.down .body {
  fill: #f2d1d1;
}

.radarPanel {
  display: grid;
  grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
  gap: 14px;
  align-items: center;
}

.radarChartWrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  padding: 10px;
}

.radarChart {
  width: 100%;
  max-width: 460px;
  display: block;
  margin: 0 auto;
  overflow: visible;
}

.radarRing {
  fill: none;
  stroke: #dfe6e3;
  stroke-width: 1;
}

.radarAxis {
  stroke: #cbd8d2;
  stroke-width: 1;
}

.radarArea {
  fill: rgba(13, 127, 97, 0.22);
  stroke: var(--accent-strong);
  stroke-width: 2;
}

.radarArea.comparisonFirst {
  fill: rgba(13, 127, 97, 0.18);
  stroke: var(--accent-strong);
}

.radarArea.comparisonSecond {
  fill: rgba(159, 46, 46, 0.14);
  stroke: #9f2e2e;
}

.radarPoint {
  fill: var(--accent-strong);
}

.radarLabel {
  fill: var(--ink);
  font-size: 12px;
  font-weight: 650;
  paint-order: stroke;
  stroke: #fbfcfb;
  stroke-width: 3px;
}

.radarTable {
  min-width: 620px;
}

.comparisonGrid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(300px, 0.75fr);
  gap: 14px;
}

.comparisonChartPanel {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.comparisonChartPanel h3 {
  margin: 0;
}

.comparisonLine {
  fill: none;
  stroke-width: 2.5;
}

.comparisonLine.first {
  stroke: var(--accent-strong);
  fill: none;
}

.comparisonPoint.first {
  stroke: var(--accent-strong);
  fill: var(--accent-strong);
}

.comparisonLine.second {
  stroke: #9f2e2e;
  fill: none;
}

.comparisonPoint.second {
  stroke: #9f2e2e;
  fill: #9f2e2e;
}

.chartLegend {
  display: flex;
  gap: 16px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}

.chartLegend span::before {
  content: "";
  display: inline-block;
  width: 24px;
  height: 3px;
  margin-right: 7px;
  vertical-align: middle;
  border-radius: 999px;
}

.legendFirst::before {
  background: var(--accent-strong);
}

.legendSecond::before {
  background: #9f2e2e;
}

.allMatchesTable {
  min-width: 1180px;
}

.statsTable {
  width: 100%;
  min-width: 840px;
  border-collapse: collapse;
}

.statsTable th,
.statsTable td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

.statsTable th {
  color: var(--muted);
  font-weight: 650;
}

.rankingTable tr.selectedRankRow {
  background: #eef8f4;
}

.changeUp {
  color: #2e7d32;
  font-weight: 700;
}

.changeDown {
  color: #c62828;
  font-weight: 700;
}

.playerMatchHistory {
  display: grid;
  gap: 10px;
}

.playerMatchHistory h3 {
  margin: 2px 0 0;
}

.playerTournamentGroup {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  overflow: hidden;
}

.playerTournamentGroup summary {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 12px;
  cursor: pointer;
  color: var(--ink);
}

.playerTournamentGroup summary span {
  color: var(--muted);
  font-size: 13px;
}

.playerTournamentGroup .statsTableScroll {
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
}

.playerMatchesTable {
  min-width: 760px;
}

.content {
  max-width: 1480px;
  margin: 0 auto;
  padding: 18px 24px 28px;
}

.tabPanel { display: none; }
.tabPanel.active { display: block; }

.sectionGrid {
  display: grid;
  grid-template-columns: minmax(280px, 420px) minmax(420px, 1fr);
  gap: 16px;
}

.surface, .graphNode {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.surface { padding: 16px; }

h2 { margin: 0 0 10px; font-size: 16px; }

.stack { display: grid; gap: 10px; }

.field {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

.field input, .field textarea { color: var(--ink); font-size: 14px; }

.list { display: grid; gap: 8px; }

.listItem {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fcfdfd;
}

.listItem strong { display: block; }
.muted { color: var(--muted); }

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  background: #e8eeeb;
  color: #36433f;
  padding: 0 9px;
  font-size: 12px;
}

.validationBox {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  padding: 10px;
}

.validationBox ul {
  margin: 0;
  padding-left: 18px;
}

.validationBox li {
  margin: 4px 0;
}

.validationBox .error {
  color: #9f2e2e;
}

.validationBox .warning {
  color: #8a5a15;
}

.validationOk {
  color: var(--accent-strong);
}

.graphShell {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 16px;
  min-height: calc(100vh - 190px);
}

.graphTools {
  align-self: start;
  position: sticky;
  top: 70px;
  display: grid;
  gap: 10px;
}

.graphToolRow {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(72px, auto);
  gap: 8px;
  align-items: center;
}

.zoomControls {
  display: grid;
  grid-template-columns: 36px minmax(54px, 1fr) 36px;
  align-items: center;
  gap: 4px;
}

.zoomControls button {
  min-height: 36px;
  padding: 0;
}

#zoomLabel {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}

.starterGraphPanel {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: #fbfcfb;
}

.starterGraphPanel h3 {
  margin: 0;
  font-size: 14px;
}

.starterGraphGrid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.starterGraphPolicy,
.starterGraphGrid label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}

.starterGraphPolicy select,
.starterGraphGrid input {
  min-width: 0;
}

.graphBoardWrap {
  height: calc(100vh - 190px);
  min-height: 560px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(#edf2ef 1px, transparent 1px),
    linear-gradient(90deg, #edf2ef 1px, transparent 1px),
    #fbfcfb;
  background-size: 32px 32px;
  overscroll-behavior: contain;
  cursor: grab;
  touch-action: none;
}

.graphBoardWrap.panning,
.graphBoardWrap.panning * {
  cursor: grabbing !important;
  user-select: none;
}

.graphBoardViewport {
  position: relative;
  width: 1900px;
  height: 1200px;
}

.graphBoard {
  position: absolute;
  left: 0;
  top: 0;
  width: 1900px;
  height: 1200px;
  transform-origin: 0 0;
}

.graphEdges {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.graphEdge {
  fill: none;
  stroke: #24745f;
  stroke-width: 2;
}

.graphEdgeDraft {
  fill: none;
  stroke: var(--warn);
  stroke-dasharray: 6 5;
  stroke-width: 2;
}

.graphNode {
  position: absolute;
  width: 290px;
  box-shadow: 0 8px 24px rgba(19, 33, 30, 0.08);
  user-select: none;
  overflow: hidden;
}

.graphNodeHeader {
  cursor: grab;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #f4f8f6;
}

.nodeNameInput {
  min-height: 34px;
  padding: 6px 8px;
  border-color: transparent;
  background: transparent;
  color: var(--ink);
  font-weight: 700;
}

.nodeEditor {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
}

.nodeEditor label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 11px;
}

.nodeEditor input, .nodeEditor textarea {
  min-height: 30px;
  padding: 5px 7px;
  font-size: 12px;
}

.miniCheck {
  grid-template-columns: auto 1fr;
  align-items: center;
}

.miniCheck input {
  width: auto;
  min-height: auto;
}

.nodeWide { grid-column: 1 / -1; }
.hidden { display: none !important; }

.graphNodeBody {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 10px;
}

.ports { display: grid; gap: 6px; }

.port {
  position: relative;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfb;
  padding: 5px 8px;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.port.input {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 2px 4px 2px 14px;
  cursor: pointer;
}
.port.output { padding-right: 16px; text-align: right; cursor: crosshair; }
.port.finalOnly { color: var(--muted); text-align: center; }
.port.startSlot { color: var(--muted); text-align: center; }

.slotSourceLabel {
  min-width: 0;
  overflow-wrap: anywhere;
}

.slotSourceChevron {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 10px;
}

.slotSourcePicker {
  position: absolute;
  z-index: 30;
  width: 260px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  box-shadow: 0 10px 24px rgba(19, 33, 30, 0.16);
  padding: 4px;
}

.slotSourceSelect {
  width: 100%;
  min-height: 180px;
  border: 0;
  border-radius: 4px;
  background: white;
  color: var(--ink);
  font-size: 12px;
}

.port::before, .port::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  transform: translateY(-50%);
  background: var(--accent);
}

.port.input::before { left: -6px; }
.port.input::after { display: none; }
.port.output::after { right: -6px; }
.port.output::before { display: none; }
.port.finalOnly::before, .port.finalOnly::after { display: none; }
.port.startSlot::before, .port.startSlot::after { display: none; }

.nodeMeta {
  padding: 0 10px 10px;
  color: var(--muted);
  font-size: 12px;
}

.nodeTeams {
  padding: 0 10px 10px;
  color: var(--ink);
  font-size: 12px;
}

.nodeTeams span { margin: 3px 4px 0 0; }

.runView {
  display: grid;
  gap: 24px;
  margin-top: 16px;
}

.runLayoutToolbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.segmentedControl {
  display: inline-grid;
  grid-template-columns: repeat(2, 38px);
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #edf2ef;
  padding: 3px;
}

.segmentedControl button {
  min-height: 30px;
  padding: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--ink);
}

.segmentedControl button.active {
  background: var(--accent);
  color: #fff;
}

.runStage {
  display: grid;
  gap: 12px;
}

.runStage > h2 {
  margin: 0;
  font-size: 18px;
}

.runStageGrid {
  display: grid;
  gap: 16px;
}

.runStageGridOne {
  grid-template-columns: minmax(0, 1fr);
}

.runStageGridTwo {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.stagePlannerLayout {
  display: grid;
  grid-template-columns: 220px minmax(420px, 1fr) minmax(280px, 360px);
  gap: 16px;
  align-items: start;
}

.stageActions {
  position: sticky;
  top: 92px;
  display: grid;
  gap: 10px;
}

.stageActionHint {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.stageBoardSurface,
.finalOrderSurface {
  display: grid;
  gap: 12px;
}

.stageBoard {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(220px, 260px);
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.stageColumn {
  display: grid;
  gap: 8px;
  align-content: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfa;
  padding: 10px;
}

.stageColumn.dragOver,
.finalOrderList.dragOver {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.stageColumn h3 {
  margin: 0;
  font-size: 14px;
}

.stageCards,
.finalOrderList {
  display: grid;
  gap: 8px;
}

.stageCard,
.finalOrderCard {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 10px;
  cursor: grab;
}

.stageCard:active,
.finalOrderCard:active {
  cursor: grabbing;
}

.stageCard.dragging,
.finalOrderCard.dragging {
  opacity: 0.45;
}

.stageCardTop {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.stageDragHandle {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 1px;
  cursor: grab;
  user-select: none;
}

.stageCard small {
  color: var(--muted);
}

.stageCardInputs {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fbfa;
  padding: 7px;
}

.stageCardInputs > span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.stageCardInputs div {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: 6px;
  align-items: center;
  font-size: 12px;
}

.stageCardInputs b {
  color: var(--muted);
  font-weight: 700;
  text-align: right;
}

.stageCardInputs em {
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  font-style: normal;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stageEmpty {
  margin: 0;
  border: 1px dashed var(--line);
  border-radius: 6px;
  color: var(--muted);
  padding: 12px;
  text-align: center;
}

.stageCard label,
.finalOrderCard label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}

.stagePlannerInput {
  min-height: 32px;
  padding: 6px 8px;
  cursor: text;
}

.finalOrderCard {
  grid-template-columns: 28px 1fr auto;
  align-items: center;
}

.finalOrderCard span {
  color: var(--muted);
  text-align: right;
}

.finalOrderCard label {
  grid-column: 2 / -1;
}

.basketGroup {
  display: grid;
  gap: 12px;
}

.basketGroup h2 {
  margin: 0;
  font-size: 18px;
}

.basketSlots {
  display: grid;
  gap: 8px;
}

.basketSlot {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 8px;
  align-items: center;
}

.basketSlot span {
  color: var(--muted);
  text-align: right;
}

.managementPanel {
  display: grid;
  gap: 14px;
}

.addRow {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.managementList {
  display: grid;
  gap: 8px;
}

.managementRow {
  display: grid;
  grid-template-columns: 64px minmax(180px, 1fr);
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfb;
  padding: 8px;
}

.managementRow span {
  color: var(--muted);
  font-size: 12px;
}

.buttonManagementRow {
  grid-template-columns: minmax(180px, 1fr) auto;
}

.playerManagementRow {
  grid-template-columns: minmax(180px, 1fr) minmax(150px, 220px);
}

.playerManagementRow label {
  display: grid;
  grid-template-columns: 76px minmax(140px, 1fr);
  gap: 8px;
  align-items: center;
}

.buttonManagementRow label {
  display: grid;
  grid-template-columns: 64px minmax(160px, 1fr);
  gap: 8px;
  align-items: center;
}

.playerAddRow {
  grid-template-columns: minmax(180px, 1fr) minmax(150px, 220px) auto;
}

.seasonLayout {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(420px, 2fr);
  gap: 14px;
  margin-bottom: 14px;
}

.seasonAddRow {
  grid-template-columns: minmax(160px, 1fr) minmax(140px, 180px) auto;
}

.tournamentCreateGrid {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) 150px minmax(180px, 1.5fr) minmax(130px, 1fr) minmax(130px, 1fr) auto;
  gap: 8px;
  align-items: end;
}

.seasonList {
  display: grid;
  gap: 14px;
}

.seasonCard {
  display: grid;
  gap: 12px;
}

.seasonHeader {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 170px;
  gap: 8px;
}

.seasonHeader label,
.tournamentRow label {
  display: grid;
  gap: 4px;
}

.seasonHeader span,
.tournamentRow span {
  color: var(--muted);
  font-size: 12px;
}

.tournamentList {
  display: grid;
  gap: 8px;
}

.tournamentRow {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 92px;
  gap: 10px;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfb;
  padding: 10px;
}

.tournamentRow.active {
  border-color: var(--accent);
  background: #eff8f4;
}

.tournamentRowMain {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 145px minmax(130px, 180px) minmax(130px, 180px);
  gap: 8px;
}

.tournamentBoardHero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 380px);
  gap: 16px;
  align-items: end;
  margin-bottom: 16px;
}

.tournamentBoardHero h2 {
  margin: 0;
  font-size: 24px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.tournamentBoardLayout {
  display: grid;
  gap: 18px;
}

.boardStage {
  display: grid;
  gap: 10px;
}

.boardStageHeader {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.boardStageHeader h2 {
  margin: 0;
  font-size: 20px;
}

.boardStageHeader span {
  color: var(--muted);
}

.boardStageGrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 14px;
}

.tournamentBoardGroup {
  display: grid;
  gap: 12px;
  align-content: start;
}

.boardGroupHeader {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.boardGroupHeader h3 {
  margin: 0;
  font-size: 18px;
}

.boardGroupHeader p {
  margin: 2px 0 0;
  color: var(--muted);
}

.boardStatus {
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.boardStatus.done {
  background: #dcefe7;
  color: var(--accent-strong);
}

.boardStatus.live {
  background: #fff4d8;
  color: #8a5a15;
}

.boardStatus.waiting {
  background: #edf2ef;
  color: var(--muted);
}

.boardEntrants {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 7px;
}

.boardEntrants div,
.boardTransition,
.boardFinalPlace {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfb;
  padding: 7px 8px;
}

.boardEntrants span,
.boardTransition span,
.boardFinalPlace span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.boardEntrants strong,
.boardEntrants small,
.boardTransition strong,
.boardTransition small,
.boardFinalPlace strong,
.boardFinalPlace small {
  display: block;
}

.boardEntrants small,
.boardTransition small,
.boardFinalPlace small {
  color: var(--muted);
  font-size: 12px;
}

.boardEntrants em,
.boardTransition em,
.boardFinalPlace em {
  color: #8a5a15;
  font-style: normal;
}

.boardTableScroll {
  overflow-x: auto;
}

.boardStandingsTable {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.boardStandingsTable th,
.boardStandingsTable td {
  border-bottom: 1px solid var(--line);
  padding: 6px 5px;
  text-align: right;
}

.boardStandingsTable th:nth-child(2),
.boardStandingsTable td:nth-child(2) {
  text-align: left;
}

.boardStandingsTable th {
  color: var(--muted);
  font-weight: 650;
}

.boardTransitions {
  display: grid;
  gap: 6px;
}

.boardTransitions h4 {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.boardTransition {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) minmax(130px, 0.9fr);
  gap: 8px;
  align-items: center;
}

.boardMatches {
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.boardMatches summary {
  cursor: pointer;
  color: var(--muted);
  font-weight: 650;
}

.boardMatchList {
  display: grid;
  gap: 5px;
  margin-top: 8px;
}

.boardMatch {
  display: grid;
  grid-template-columns: 56px minmax(90px, 1fr) auto minmax(90px, 1fr);
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfb;
  padding: 6px 8px;
}

.boardMatch span {
  color: var(--muted);
  font-size: 12px;
}

.boardMatch b {
  white-space: nowrap;
}

.tournamentBoardFinals {
  display: grid;
  gap: 10px;
}

.boardFinalGrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 8px;
}

.boardFinalPlace span {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: var(--accent);
  color: white;
}

.tournamentBracketPanel {
  display: grid;
  gap: 10px;
}

.tournamentBracketScroll {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f5f7f8;
}

.tournamentBracketCanvas {
  position: relative;
  min-width: 100%;
}

.tournamentBracketEdges {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
  z-index: 1;
}

.tournamentBracketStageSeparator {
  position: absolute;
  width: 1px;
  border-left: 1px solid #d7dfdc;
  pointer-events: none;
  z-index: 0;
}

.tournamentBracketBucketLabel {
  position: absolute;
  display: flex;
  align-items: center;
  min-height: 22px;
  color: #74827f;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0;
  z-index: 2;
}

.tournamentBracketBucketLabel::after {
  content: "";
  flex: 1;
  height: 1px;
  margin-left: 8px;
  background: #dce4e1;
}

.bracketEdgePath {
  fill: none;
  stroke: #9dacaa;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.88;
}

.bracketCard {
  position: absolute;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  box-shadow: 0 5px 14px rgba(18, 32, 29, 0.07);
  padding: 7px 8px;
}

.bracketCard.done {
  border-color: #d5e2dd;
}

.bracketCard.live {
  border-color: #dfc983;
}

.bracketCard.waiting {
  opacity: 0.76;
}

.bracketCard header {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.bracketCard header strong {
  min-width: 0;
  overflow: hidden;
  color: #172320;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bracketCard header span {
  color: #7a8784;
  font-size: 11px;
  white-space: nowrap;
}

.bracketPlayers {
  display: grid;
  gap: 5px;
}

.bracketPlayer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 28px;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfb;
  padding: 5px 7px;
  min-height: 30px;
}

.bracketPlayer span {
  overflow-wrap: anywhere;
}

.bracketPlayer em {
  color: #8a5a15;
  font-style: normal;
}

.bracketPlayer strong {
  text-align: right;
}

.bracketScore {
  justify-self: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.tournamentBracketStageLabel {
  position: absolute;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  color: #74827f;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0;
  z-index: 2;
}

.tournamentBracketStageLabel strong {
  color: var(--ink);
  font-size: 12px;
}

.tournamentBracketStageLabel span {
  display: inline-grid;
  place-items: center;
  min-width: 21px;
  height: 21px;
  border-radius: 999px;
  background: #e7ecea;
  color: var(--muted);
  font-weight: 700;
}

.tournamentBracketPanel .bracketCard {
  gap: 4px;
  border-radius: 6px;
  box-shadow: 0 5px 14px rgba(18, 32, 29, 0.07);
  padding: 7px 8px;
  z-index: 3;
}

.bracketEdgePath.advance {
  stroke: #276f90;
}

.bracketEdgePath.drop {
  stroke: #a17a55;
  opacity: 0.78;
}

.bracketMatchRows {
  display: grid;
  gap: 3px;
}

.bracketTeam {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 25px 24px;
  gap: 4px;
  align-items: center;
  border: 0;
  border-radius: 4px;
  background: #f7f9f8;
  padding: 3px 5px;
  min-height: 21px;
  font-size: 12px;
}

.bracketTeamName {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bracketResult {
  text-align: right;
  font-size: 13px;
}

.bracketPenalty {
  color: var(--muted);
  font-size: 10px;
  text-align: right;
}

.bracketPenalty:not(:empty)::before {
  content: "k. ";
}

.runGroup {
  display: grid;
  gap: 12px;
}

.runGroup h3 {
  margin: 0;
  font-size: 16px;
}

.runGroupHeader {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.runColumns {
  display: grid;
  grid-template-columns: minmax(280px, 420px) 1fr;
  gap: 16px;
}

.runColumns h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

.slotList,
.matchList {
  display: grid;
  gap: 8px;
}

.slotRow,
.matchRow {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(180px, 1fr);
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfb;
  padding: 8px;
}

.matchRow {
  grid-template-columns: 80px 1fr auto;
}

.slotRow {
  grid-template-columns: 42px 1fr;
}

.slotRow small {
  grid-column: 2;
  color: var(--muted);
}

.slotRow em,
.standingsTable em,
.scoreSide em,
.h2hRowHead em,
.combinedGroupTable em,
.twoPersonResult em,
.finalPlacesTable em {
  color: #8a5a15;
  font-style: normal;
  font-weight: 600;
}

.scoreMatchRow {
  display: grid;
  grid-template-columns: 34px auto minmax(92px, 1fr) 52px auto 52px minmax(92px, 1fr) auto minmax(130px, 180px) auto auto;
  gap: 6px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfb;
  padding: 8px;
}

.scoreMatchRow.locked {
  background: #f4f8f6;
}

.scoreMatchRow.dragging {
  opacity: 0.55;
}

.matchDragHandle {
  min-height: 30px;
  width: 34px;
  padding: 0;
  color: var(--muted);
  cursor: grab;
}

.matchDragHandle:active {
  cursor: grabbing;
}

.scoreOrder {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.scoreName {
  overflow-wrap: anywhere;
}

.scoreColon {
  color: var(--muted);
  font-weight: 700;
  text-align: center;
}

.scoreSide input {
  min-height: 36px;
  text-align: center;
}

.scoreMatchRow > .scoreInput {
  min-height: 34px;
  padding: 6px 8px;
  text-align: center;
}

.penaltyToggle,
.walkoverToggle {
  display: inline-grid;
  grid-template-columns: auto auto;
  gap: 5px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.penaltyToggle input,
.walkoverToggle input {
  width: auto;
  min-height: auto;
}

.walkoverWinnerInput {
  min-height: 34px;
  padding: 6px 8px;
}

.walkoverNotice {
  grid-column: 1 / -1;
  color: var(--muted);
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.penaltyScores {
  display: grid;
  grid-template-columns: 42px auto 42px;
  gap: 4px;
  align-items: center;
}

.penaltyScores input {
  min-height: 34px;
  padding: 6px;
  text-align: center;
}

.penaltyScores span {
  color: var(--muted);
  font-weight: 700;
}

.scorerInputs {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(92px, 160px) 1fr;
  gap: 8px;
  align-items: start;
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.scorerSideLabel {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.scorerGoalGrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
}

.scorerGoal {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 11px;
}

.scorerGoal input {
  min-height: 32px;
  padding: 6px 8px;
  font-size: 12px;
}

.scorersPanel {
  overflow-x: auto;
}

.scorersTable {
  width: 100%;
  border-collapse: collapse;
}

.scorersTable th,
.scorersTable td {
  border-bottom: 1px solid var(--line);
  padding: 8px 6px;
  text-align: left;
}

.scorersTable th:first-child,
.scorersTable td:first-child {
  width: 64px;
  text-align: right;
}

.scorersTable th:last-child,
.scorersTable td:last-child {
  width: 90px;
  text-align: right;
}

.stageNotice {
  margin: 0;
  color: #8a5a15;
  font-size: 13px;
}

.standingsTable {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.standingsTable th,
.standingsTable td {
  border-bottom: 1px solid var(--line);
  padding: 6px 4px;
  text-align: right;
}

.standingsTable th:nth-child(2),
.standingsTable td:nth-child(2) {
  text-align: left;
}

.standingsTable th {
  color: var(--muted);
  font-weight: 600;
}

.combinedGroupScroll {
  overflow-x: auto;
}

.combinedGroupTable {
  width: 100%;
  min-width: max-content;
  border-collapse: collapse;
  font-size: 12px;
}

.combinedGroupTable th,
.combinedGroupTable td {
  border-bottom: 1px solid var(--line);
  padding: 6px 5px;
  text-align: right;
}

.combinedGroupTable th {
  color: var(--muted);
  font-weight: 600;
}

.combinedGroupTable th:nth-child(2),
.combinedGroupTable td:nth-child(2) {
  min-width: 132px;
  text-align: left;
}

.directHeader {
  position: relative;
  width: 42px;
  min-width: 42px;
  height: 86px;
  padding: 0;
  vertical-align: bottom;
  background: #f4f8f6;
}

.directHeader span {
  position: absolute;
  left: 8px;
  bottom: 8px;
  width: 100px;
  line-height: 1.1;
  text-align: left;
  white-space: nowrap;
  transform: rotate(-60deg);
  transform-origin: left bottom;
}

.directCell {
  width: 42px;
  min-width: 42px;
  text-align: center !important;
  font-weight: 700;
  background: #fff;
}

.directCell span {
  display: block;
}

.directSelf,
.directEmpty {
  background: #fbfcfb;
}

.twoPersonResult {
  display: grid;
  gap: 8px;
}

.twoPersonLine {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) auto minmax(120px, 1fr);
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfb;
  padding: 10px 12px;
}

.twoPersonName {
  font-weight: 700;
  overflow-wrap: anywhere;
}

.twoPersonName.away {
  text-align: right;
}

.twoPersonScore {
  min-width: 54px;
  text-align: center;
}

.finalPlaces {
  overflow-x: auto;
}

.finalPlacesTable {
  width: 100%;
  border-collapse: collapse;
}

.finalPlacesTable th,
.finalPlacesTable td {
  border-bottom: 1px solid var(--line);
  padding: 8px 6px;
  text-align: left;
}

.finalPlacesTable th:first-child,
.finalPlacesTable td:first-child {
  width: 84px;
  text-align: right;
}

.headToHead {
  display: grid;
  gap: 8px;
}

.headToHeadTitle {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.headToHeadScroll {
  overflow-x: auto;
  padding-top: 8px;
}

.headToHeadGrid {
  --h2h-size: 2;
  display: grid;
  grid-template-columns: minmax(120px, 180px) repeat(var(--h2h-size), minmax(58px, 72px));
  min-width: max-content;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  overflow: hidden;
}

.h2hCorner,
.h2hColumnHead,
.h2hRowHead,
.h2hCell {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.h2hCorner,
.h2hColumnHead,
.h2hRowHead {
  background: #f4f8f6;
}

.h2hCorner,
.h2hColumnHead {
  height: 128px;
}

.h2hColumnHead {
  position: relative;
}

.h2hColumnHead span {
  position: absolute;
  left: 10px;
  bottom: 10px;
  width: 130px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.1;
  white-space: nowrap;
  transform: rotate(-60deg);
  transform-origin: left bottom;
}

.h2hRowHead {
  min-height: 40px;
  padding: 7px 8px;
  font-size: 12px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.h2hCell {
  min-height: 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 5px;
  font-size: 12px;
  font-weight: 700;
}

.h2hSelf,
.h2hEmpty {
  background: #fbfcfb;
}

@media (max-width: 980px) {
  .content { padding: 14px; }
  .tabs { padding-left: 14px; padding-right: 14px; }
  .sectionGrid, .graphShell, .runColumns, .stagePlannerLayout, .seasonLayout, .tournamentCreateGrid, .statsHeader, .statsFilters, .radarPanel, .comparisonGrid, .tournamentBoardHero { grid-template-columns: 1fr; }
  .runStageGridTwo { grid-template-columns: minmax(0, 1fr); }
  .graphTools { position: static; }
  .graphBoardWrap {
    height: calc(100vh - 150px);
    min-height: 520px;
  }
  .stageActions { position: static; }
  .twoPersonName.away { text-align: left; }
  .statsSectionHeader,
  .playerTournamentGroup summary {
    display: grid;
    justify-content: stretch;
  }
}

@media (max-width: 720px) {
  .addRow,
  .managementRow,
  .buttonManagementRow,
  .buttonManagementRow label,
  .playerManagementRow,
  .playerManagementRow label,
  .playerAddRow,
  .seasonAddRow,
  .seasonHeader,
  .tournamentRow,
  .tournamentRowMain {
    grid-template-columns: 1fr;
  }

  .scoreMatchRow {
    grid-template-columns: 34px auto minmax(72px, 1fr) 44px auto 44px minmax(72px, 1fr);
  }

  .penaltyToggle,
  .penaltyScores,
  .walkoverToggle,
  .walkoverWinnerInput,
  .scorerInputs {
    grid-column: 1 / -1;
  }

  .scorerInputs {
    grid-template-columns: 1fr;
  }
}
