:root {
  --nav: #0b2d52;
  --nav-deep: #082440;
  --page: #f5f8fc;
  --ink: #17324d;
  --soft: #eaf1f8;
  --line: #dbe7f2;
  --muted: #708399;
  --panel-shadow: 0 .45rem 1.5rem rgba(15, 47, 82, .09);
}

html {
  min-height: 100%;
}

body {
  background:
    radial-gradient(circle at 92% 4%, rgba(48, 116, 181, .08), transparent 24rem),
    var(--page);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main {
  flex: 1 0 auto;
  width: 100%;
}

.app-navbar {
  background: linear-gradient(110deg, var(--nav-deep), var(--nav));
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.navbar-brand {
  letter-spacing: .01em;
}

.navbar .nav-link {
  border-radius: .55rem;
  padding-inline: .75rem !important;
  transition: color .16s ease, background-color .16s ease;
}

.navbar .nav-link:hover,
.navbar .nav-link:focus-visible {
  background: rgba(255, 255, 255, .08);
  color: #fff;
}

.app-card {
  border: 1px solid rgba(213, 226, 239, .72);
  border-radius: 1rem;
  box-shadow: var(--panel-shadow);
}

.hero-panel {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  background: linear-gradient(135deg, #fff, #eaf3ff);
  border: 1px solid #deebf8;
  border-radius: 1.25rem;
  padding: 2.7rem 1rem;
  box-shadow: 0 .55rem 1.75rem rgba(15, 47, 82, .07);
}

.hero-panel::after {
  content: "";
  position: absolute;
  z-index: -1;
  width: 210px;
  height: 210px;
  right: -58px;
  bottom: -76px;
  border-radius: 1.4rem;
  opacity: .18;
  transform: rotate(12deg);
  background-color: #d7e8f8;
  background-image:
    linear-gradient(45deg, rgba(11, 45, 82, .22) 25%, transparent 25%, transparent 75%, rgba(11, 45, 82, .22) 75%),
    linear-gradient(45deg, rgba(11, 45, 82, .22) 25%, transparent 25%, transparent 75%, rgba(11, 45, 82, .22) 75%);
  background-position: 0 0, 22px 22px;
  background-size: 44px 44px;
}

.btn {
  border-radius: .68rem;
  font-weight: 550;
  transition: transform .15s ease, box-shadow .15s ease, background-color .15s ease, border-color .15s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  box-shadow: 0 .25rem .65rem rgba(13, 110, 253, .15);
}

.form-control,
.form-select {
  border-radius: .7rem;
  border-color: #cfdeeb;
}

.form-control:focus,
.form-select:focus {
  border-color: #8db9e3;
  box-shadow: 0 0 0 .2rem rgba(13, 110, 253, .11);
}

.modal-content {
  border: 0;
  border-radius: 1.1rem;
  box-shadow: 0 1rem 3rem rgba(13, 37, 62, .2);
}

.modal-header,
.modal-footer {
  border-color: #e5edf5;
}

/*
 * Bootstrap's scrollable modal expects header/body/footer to be direct
 * children of .modal-content. Our forms wrap those elements, so the form
 * itself must participate in the flex layout; otherwise long dialogs are
 * clipped instead of scrollable, especially on phones.
 */
.modal-dialog-scrollable .modal-content,
.modal-dialog-scrollable .modal-content > form {
  max-height: calc(100vh - 1rem);
  max-height: calc(100dvh - 1rem);
}

.modal-dialog-scrollable .modal-content > form {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.modal-dialog-scrollable .modal-content > form > .modal-header,
.modal-dialog-scrollable .modal-content > form > .modal-footer {
  flex: 0 0 auto;
}

.modal-dialog-scrollable .modal-content > form > .modal-body {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 575.98px) {
  .modal-dialog-scrollable {
    height: calc(100vh - 1rem);
    height: calc(100dvh - 1rem);
    min-height: calc(100vh - 1rem);
    min-height: calc(100dvh - 1rem);
  }
}

@media (min-width: 576px) {
  .modal-dialog-scrollable .modal-content,
  .modal-dialog-scrollable .modal-content > form {
    max-height: calc(100vh - 3.5rem);
    max-height: calc(100dvh - 3.5rem);
  }
}

.app-table thead th {
  background: #eef4fa;
  color: #49647d;
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .045em;
  border-bottom: 0;
  white-space: nowrap;
}

.app-table td,
.app-table th {
  padding: .9rem 1rem;
}

.app-table tbody tr {
  transition: background-color .14s ease, box-shadow .14s ease;
}

.app-table tbody tr:hover {
  background: rgba(13, 110, 253, .035);
}

.player-name-cell {
  font-weight: 650;
}

.elo-cell {
  font-weight: 700;
  color: #0b4f88;
  font-variant-numeric: tabular-nums;
}

.rank-chip {
  display: inline-grid;
  place-items: center;
  min-width: 2rem;
  height: 2rem;
  padding: 0 .42rem;
  border-radius: .65rem;
  background: #edf4fb;
  color: #315b82;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

.leaderboard-table tbody tr:nth-child(1) .rank-chip {
  background: #fff4c7;
  color: #7d5c00;
}

.leaderboard-table tbody tr:nth-child(2) .rank-chip {
  background: #edf0f3;
  color: #53606c;
}

.leaderboard-table tbody tr:nth-child(3) .rank-chip {
  background: #f4e1d4;
  color: #7e4c2c;
}

.stat-card {
  height: 100%;
  background: #fff;
  border: 1px solid rgba(219, 231, 242, .9);
  border-radius: .9rem;
  padding: 1rem 1.1rem;
  box-shadow: 0 .25rem 1rem rgba(15, 47, 82, .07);
  transition: transform .15s ease, box-shadow .15s ease;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 .45rem 1.25rem rgba(15, 47, 82, .1);
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: .82rem;
  margin-bottom: .2rem;
}

.stat-card strong {
  font-size: 1.45rem;
  font-variant-numeric: tabular-nums;
}

.chart-wrap {
  height: 330px;
}

.participant-grid ul {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: .55rem;
  list-style: none;
  padding: 0;
  margin: 0;
}

.participant-grid li {
  background: #f7fafd;
  border: 1px solid #e1ebf5;
  border-radius: .75rem;
  padding: .65rem .8rem;
  transition: background-color .15s ease, border-color .15s ease;
}

.participant-grid li:hover {
  background: #f0f6fc;
  border-color: #ccddeb;
}

.participant-grid label {
  display: flex;
  gap: .5rem;
  align-items: center;
}

/* Abzeichen: Startseite und Rangliste */
.badge-info-button {
  position: absolute;
  top: .85rem;
  right: .85rem;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  color: #315b82;
  background: rgba(255, 255, 255, .8);
  border: 1px solid rgba(130, 168, 202, .35);
  box-shadow: 0 .25rem .8rem rgba(15, 47, 82, .08);
  backdrop-filter: blur(5px);
  font-size: .88rem;
}

.badge-info-button:hover,
.badge-info-button:focus-visible {
  color: #173f65;
  background: #fff;
  border-color: rgba(83, 137, 186, .5);
}

.badge-column {
  width: 82px;
  text-align: center;
}

.leaderboard-badge {
  display: inline-block;
  width: 42px;
  height: 42px;
  object-fit: contain;
  vertical-align: middle;
  filter: drop-shadow(0 3px 4px rgba(15, 47, 82, .15));
  transition: transform .15s ease;
}

tr:hover .leaderboard-badge {
  transform: translateY(-1px) scale(1.04);
}

.badge-placeholder {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px dashed #ccd9e5;
  border-radius: 50%;
  color: #9aaabd;
  font-weight: 600;
}

.badge-modal-content {
  overflow: hidden;
}

.badge-modal-kicker,
.badge-panel-kicker {
  color: #517596;
  font-size: .76rem;
  font-weight: 750;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.badge-overview-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .9rem;
}

.badge-overview-card {
  display: flex;
  align-items: center;
  gap: .8rem;
  min-width: 0;
  padding: .85rem;
  border: 1px solid #dce7f1;
  border-radius: .95rem;
  background: linear-gradient(145deg, #fff, #f7fafe);
  box-shadow: 0 .2rem .75rem rgba(15, 47, 82, .055);
}

.badge-overview-card img {
  flex: 0 0 auto;
  width: 64px;
  height: 64px;
  object-fit: contain;
}

.badge-overview-card strong,
.badge-overview-card span {
  display: block;
}

.badge-overview-card strong {
  margin-bottom: .13rem;
  color: #17324d;
}

.badge-overview-card span {
  color: var(--muted);
  font-size: .84rem;
  white-space: nowrap;
}

/* Abzeichen: Spielerprofil */
.badge-progress-panel {
  position: relative;
  overflow: hidden;
  background: linear-gradient(125deg, #ffffff 0%, #f4f8fc 58%, #e8f1fa 100%);
  border: 1px solid #d5e3ef;
  border-radius: 1.15rem;
  padding: 1.35rem 1.5rem;
  box-shadow: 0 .5rem 1.5rem rgba(15, 47, 82, .085);
}

.badge-progress-panel::after {
  content: "♟";
  position: absolute;
  right: 1.1rem;
  bottom: -2.3rem;
  color: rgba(11, 45, 82, .035);
  font-size: 9rem;
  line-height: 1;
  pointer-events: none;
}

.current-badge-display,
.no-badge-display,
.highest-badge-state {
  display: flex;
  align-items: center;
  gap: 1rem;
  position: relative;
  z-index: 1;
}

.current-badge-display img {
  width: 92px;
  height: 92px;
  object-fit: contain;
  flex: 0 0 auto;
  filter: drop-shadow(0 .35rem .45rem rgba(15, 47, 82, .16));
}

.no-badge-icon,
.highest-badge-icon {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: #edf3f9;
  border: 1px dashed #bdcddd;
  color: #6f8498;
  font-size: 2rem;
}

.highest-badge-icon {
  border-style: solid;
  background: #f1eafb;
  border-color: #dac8eb;
  color: #63407d;
}

.badge-progress-count {
  color: #214a70;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.badge-progress-track {
  height: .72rem;
  background: #dce7f1;
  border-radius: 999px;
  overflow: hidden;
  box-shadow: inset 0 1px 2px rgba(15, 47, 82, .08);
}

.badge-progress-track .progress-bar {
  border-radius: inherit;
  background: linear-gradient(90deg, #2f6fa8, #4e93c9);
  transition: width .35s ease;
}

.badge-progress-note {
  color: #506c86;
  font-size: .9rem;
}

/* Einheitliche Fußzeile */
.app-footer {
  flex: 0 0 auto;
  margin-top: 1rem;
  color: #6f8295;
  background: rgba(236, 242, 248, .72);
  border-top: 1px solid #dbe6ef;
  font-size: .8rem;
}

.modal.fade .modal-dialog {
  transform: scale(.98);
  transition: transform .18s ease-out;
}

.modal.show .modal-dialog {
  transform: scale(1);
}

@media (max-width: 767.98px) {
  .badge-overview-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .badge-progress-panel {
    padding: 1.2rem;
  }
}

@media (max-width: 576px) {
  .hero-panel {
    padding: 4rem .8rem 1.75rem;
  }

  .badge-info-button {
    top: .7rem;
    right: .7rem;
  }

  .app-table td,
  .app-table th {
    padding: .7rem .65rem;
  }

  .badge-column {
    width: 58px;
  }

  .leaderboard-badge {
    width: 36px;
    height: 36px;
  }

  .rank-chip {
    min-width: 1.8rem;
    height: 1.8rem;
  }

  .chart-wrap {
    height: 270px;
  }

  .badge-overview-grid {
    grid-template-columns: 1fr;
  }

  .badge-overview-card {
    padding: .75rem .9rem;
  }

  .badge-overview-card img {
    width: 56px;
    height: 56px;
  }

  .current-badge-display img {
    width: 78px;
    height: 78px;
  }

  .badge-progress-count {
    font-size: .92rem;
  }

  .app-footer .container {
    text-align: center;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
  }
}

/* Turniere */
.tournament-filter .badge {
  font-size: .72em;
}

.tournament-list-card {
  overflow: hidden;
  transition: transform .16s ease, box-shadow .16s ease;
}

.tournament-list-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 .65rem 1.65rem rgba(15, 47, 82, .12);
}

.tournament-list-icon-wrap {
  width: 150px;
  min-height: 150px;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: linear-gradient(145deg, #edf4fb, #f8fbfe);
  border-right: 1px solid var(--line);
}

.tournament-list-icon {
  display: block;
  width: 118px;
  height: 118px;
  border-radius: 1rem;
  object-fit: cover;
  box-shadow: 0 .35rem 1rem rgba(15, 47, 82, .14);
}

.tournament-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem 1.15rem;
  color: var(--muted);
  font-size: .9rem;
}

.tournament-mode-option {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .45rem;
  padding: 1rem;
  border: 1px solid #d8e5f0;
  border-radius: 1rem;
  background: #fff;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}

.tournament-mode-option:hover {
  transform: translateY(-1px);
  border-color: #a9c9e6;
}

.tournament-mode-option .form-check-input {
  position: absolute;
  top: .8rem;
  left: .8rem;
}

.tournament-mode-option img {
  width: 92px;
  height: 92px;
  object-fit: cover;
  border-radius: .85rem;
}

.tournament-mode-option span {
  color: var(--muted);
  font-size: .82rem;
}

.tournament-mode-option.active-mode:has(input:checked) {
  border-color: #75aee1;
  box-shadow: 0 0 0 .2rem rgba(13, 110, 253, .08);
}

.tournament-mode-option.disabled-mode {
  opacity: .55;
  cursor: not-allowed;
  filter: grayscale(.35);
}

.ko-bracket-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  padding: .4rem .2rem 1rem;
}

.ko-bracket {
  position: relative;
  display: grid;
  gap: 72px;
  width: max-content;
  min-width: 100%;
  padding: 0 1rem 1rem;
}

.ko-bracket-lines {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: visible;
}

.ko-bracket-line {
  fill: none;
  stroke: #aac2d8;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.ko-bracket-round {
  position: relative;
  z-index: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.ko-bracket-round-title {
  flex: 0 0 auto;
  margin: 0 0 .9rem;
  color: #4c6d8a;
  font-size: .82rem;
  font-weight: 750;
  letter-spacing: .055em;
  text-align: center;
  text-transform: uppercase;
}

.ko-bracket-round-matches {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  gap: 1rem;
}

.ko-match-card {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  min-height: 112px;
  padding: .7rem;
  color: var(--ink);
  background: #fff;
  border: 1px solid #d9e6f1;
  border-radius: .9rem;
  box-shadow: 0 .25rem .75rem rgba(15, 47, 82, .075);
  text-align: left;
}

button.ko-match-card {
  cursor: pointer;
  transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease;
}

button.ko-match-card:hover,
button.ko-match-card:focus-visible {
  transform: translateY(-1px);
  border-color: #8db9e3;
  box-shadow: 0 .4rem 1rem rgba(15, 47, 82, .12);
  outline: 0;
}

.ko-match-card.is-complete {
  border-color: #b9dcc6;
  background: linear-gradient(145deg, #fff, #f5fbf7);
}

.ko-match-card.is-bye {
  border-style: dashed;
  background: #f5f9fc;
}

.ko-match-card.is-pending {
  background: #f8fafc;
  color: #7890a5;
}

.ko-match-card.is-locked {
  box-shadow: 0 .25rem .75rem rgba(15, 47, 82, .05);
}

.ko-match-number {
  display: block;
  margin-bottom: .4rem;
  color: #7890a5;
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.ko-player-row {
  display: flex;
  align-items: center;
  gap: .45rem;
  min-height: 25px;
  padding: .18rem .25rem;
  border-radius: .45rem;
}

.ko-player-row.winner {
  color: #146c43;
  background: #eaf7ef;
  font-weight: 750;
}

.ko-color-marker {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 50%;
  color: #49647d;
  background: #edf3f8;
  font-size: .66rem;
  font-weight: 800;
}

.ko-player-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ko-match-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .5rem;
  margin-top: .45rem;
  padding-top: .4rem;
  border-top: 1px solid #edf2f6;
  color: #5e7891;
  font-size: .74rem;
}

@media (max-width: 767.98px) {
  .tournament-list-icon-wrap {
    width: 112px;
    min-height: 132px;
    padding: .75rem;
  }

  .tournament-list-icon {
    width: 88px;
    height: 88px;
  }
}

@media (max-width: 575.98px) {
  .tournament-list-card .row {
    display: block;
  }

  .tournament-list-icon-wrap {
    width: 100%;
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}

.ko-bracket {
  justify-content: center;
}

/* Schweizer System und Rundenturnier */
.tournament-current-round {
  border-color: #8db9e3;
  box-shadow: 0 0 0 .2rem rgba(13, 110, 253, .07), 0 .45rem 1.2rem rgba(15, 47, 82, .08);
}

.round-robin-day {
  padding: 1rem;
  border: 1px solid #e1eaf2;
  border-radius: .9rem;
  background: #fff;
}

.round-robin-day:last-child {
  margin-bottom: 0 !important;
}

.tournament-mode-option.active-mode:has(input:checked) span {
  color: #245f96;
  font-weight: 650;
}

@media (max-width: 575.98px) {
  .tournament-mode-grid > div {
    flex: 0 0 100%;
    width: 100%;
  }

  .tournament-mode-option {
    display: grid;
    grid-template-columns: auto 72px 1fr;
    grid-template-rows: auto auto;
    column-gap: .8rem;
    text-align: left;
  }

  .tournament-mode-option .form-check-input {
    position: static;
    grid-row: 1 / 3;
    align-self: center;
  }

  .tournament-mode-option img {
    grid-row: 1 / 3;
    width: 72px;
    height: 72px;
  }

  .round-robin-day {
    padding: .75rem;
  }
}

/* Collapsible round-robin matchdays and reliable redirect anchors. */
.round-robin-day { scroll-margin-top: 1.5rem; }
.round-robin-day > summary { cursor: pointer; padding: 0.75rem; }
.round-robin-day > summary:hover { background: rgba(0, 0, 0, 0.035); }
.round-robin-day > .table-responsive { margin-top: 0.5rem; }

.round-robin-day > summary::before { content: "▸"; margin-right: .4rem; font-weight: 700; color: var(--bs-primary); }
.round-robin-day[open] > summary::before { content: "▾"; }
