:root {
  --bg: #f3f0e8;
  --panel: #ffffff;
  --text: #1f2328;
  --muted: #5b6570;
  --line: #d8dee6;
  --accent: #b94a2f;
  --accent-soft: #f9ece7;
  --shadow: 0 10px 26px rgba(23, 29, 35, 0.08);
  --flat: #1f9d55;
  --flat-soft: #e9f8ef;
  --up: #d64545;
  --up-soft: #fdecec;
  --down: #2f6fd6;
  --down-soft: #eaf1ff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--text);
  font-family: "Segoe UI", "Trebuchet MS", sans-serif;
  background:
    radial-gradient(1400px 700px at 0% -20%, rgba(76, 98, 74, 0.16) 0%, transparent 60%),
    radial-gradient(1200px 620px at 100% -10%, rgba(73, 88, 110, 0.14) 0%, transparent 58%),
    linear-gradient(180deg, #e7e4dd 0%, #f1eee8 46%, #f6f3ee 100%);
}

.app {
  max-width: 1480px;
  margin: 0 auto;
  padding: 16px;
}

.masthead {
  border: 1px solid #4a545f;
  border-radius: 18px;
  padding: 14px 16px 18px;
  box-shadow: 0 16px 42px rgba(17, 22, 29, 0.28);
  background:
    radial-gradient(120% 90% at -10% -30%, rgba(35, 86, 161, 0.38) 0%, transparent 60%),
    radial-gradient(120% 90% at 120% -20%, rgba(32, 170, 158, 0.34) 0%, transparent 58%),
    radial-gradient(95% 90% at 50% 120%, rgba(74, 93, 58, 0.26) 0%, transparent 64%),
    linear-gradient(124deg, #0b234a 0%, #17365f 34%, #195a68 66%, #1b7a70 100%);
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 2px 4px;
}

.brand-wrap { position: relative; }

.brand-menu-button {
  border: 0;
  background: transparent;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: var(--text);
  font: inherit;
  padding: 0;
}

.brand { font-weight: 700; font-size: 20px; }
.brand-menu-caret { color: var(--muted); }
.masthead .brand-menu-button { color: #edf3fa; }
.masthead .brand-menu-caret { color: #b7c4d4; }
.masthead .status { color: #c3cfdd; }

.brand-menu {
  position: absolute;
  left: 0;
  top: calc(100% + 8px);
  min-width: 210px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  z-index: 30;
}

.brand-menu[hidden] { display: none; }

.brand-menu a {
  display: block;
  color: var(--text);
  text-decoration: none;
  padding: 9px 10px;
  border-radius: 8px;
}

.brand-menu a:hover { background: #f4f7fb; }
.status { color: var(--muted); font-size: 15px; }

.hero {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 12px;
  border-radius: 14px;
  padding: 18px;
  background:
    radial-gradient(140% 120% at 0% 0%, rgba(255, 255, 255, 0.08) 0%, transparent 62%),
    linear-gradient(120deg, rgba(9, 29, 63, 0.34) 0%, rgba(17, 67, 94, 0.28) 100%);
  border: 1px solid rgba(173, 212, 244, 0.24);
  backdrop-filter: blur(2px);
}

.hero h1 { margin: 0 0 10px; font-size: 36px; line-height: 1.1; color: #f4f8ff; }
.hero p { margin: 0; color: #d5e3f3; max-width: 64ch; font-size: 17px; line-height: 1.45; }

.hero-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.metric {
  border: 1px solid rgba(188, 220, 246, 0.36);
  border-radius: 12px;
  padding: 14px;
  background: rgba(11, 34, 66, 0.34);
}

.metric-value { display: block; font-size: 34px; font-weight: 700; color: #f3f8ff; }
.metric-label { color: #c8d8ea; font-size: 14px; }

.filters-bar {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  padding: 16px;
}

.filter-group { display: grid; gap: 8px; }
.search-group { min-width: 0; }
.filter-title { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.filter-row { display: flex; gap: 8px; flex-wrap: wrap; }

.search-input {
  width: 100%;
  border: 1px solid #c6ced8;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 16px;
  font: inherit;
  color: var(--text);
  background: #fff;
}

.filter-toggle {
  border: 1px solid #c6ced8;
  background: #fff;
  color: #3b4652;
  border-radius: 999px;
  padding: 9px 15px;
  font-size: 15px;
  cursor: pointer;
}

.filter-toggle.active {
  background: #edf4ff;
  border-color: #8fb8ef;
  color: #174f90;
}

.filter-toggle[data-filter="category"][data-value="flat"] {
  color: #1b7f47;
}
.filter-toggle[data-filter="category"][data-value="up"] {
  color: #b43636;
}
.filter-toggle[data-filter="category"][data-value="down"] {
  color: #275eb5;
}
.filter-toggle[data-filter="category"][data-value="flat"].active {
  background: var(--flat-soft);
  border: 2px solid var(--flat);
  color: #126638;
}
.filter-toggle[data-filter="category"][data-value="up"].active {
  background: var(--up-soft);
  border: 2px solid var(--up);
  color: #8f2323;
}
.filter-toggle[data-filter="category"][data-value="down"].active {
  background: var(--down-soft);
  border: 2px solid var(--down);
  color: #1f4f9b;
}
.filter-toggle[data-filter="category"][data-value="overall"].active {
  background: #fff;
  border: 2px solid #607286;
  color: #2d3f55;
}

.filter-division-toggle {
  position: relative;
  border: 1px solid #cfd5dd;
  border-radius: 999px;
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  width: min(310px, 100%);
  min-height: 56px;
  padding: 4px;
  overflow: hidden;
  background: #fff;
  color: #475569;
  cursor: pointer;
}

.filter-division-thumb {
  position: absolute;
  top: 4px;
  left: 4px;
  width: calc(50% - 4px);
  height: calc(100% - 8px);
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid #f1c8bc;
  transition: transform .2s ease;
}

.filter-division-toggle[aria-pressed="true"] .filter-division-thumb {
  transform: translateX(100%);
}

.filter-division-label {
  position: relative;
  z-index: 1;
  font-size: 15px;
  line-height: 1;
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  white-space: nowrap;
}

.table-shell {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: auto;
  background: var(--panel);
  box-shadow: var(--shadow);
  max-height: calc(100vh - 310px);
}

.rating-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 16px;
  table-layout: fixed;
}

.rating-table th:nth-child(1),
.rating-table td:nth-child(1) { width: 72px; }
.rating-table th:nth-child(3),
.rating-table td:nth-child(3) { width: 86px; }
.rating-table th:nth-child(4),
.rating-table td:nth-child(4),
.rating-table th:nth-child(5),
.rating-table td:nth-child(5),
.rating-table th:nth-child(6),
.rating-table td:nth-child(6),
.rating-table th:nth-child(7),
.rating-table td:nth-child(7),
.rating-table th:nth-child(8),
.rating-table td:nth-child(8) { width: 110px; }

.rating-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  text-align: left;
  padding: 14px 12px;
  border-bottom: 1px solid var(--line);
  background: #fbfdff;
  color: #4f5d6d;
  font-weight: 600;
}

.rating-table thead th:nth-child(5) { color: #1b7f47; background: #f3fbf6; }
.rating-table thead th:nth-child(6) { color: #ad2f2f; background: #fff5f5; }
.rating-table thead th:nth-child(7) { color: #275eb5; background: #f3f7ff; }
.rating-table thead th:nth-child(8) { color: #4f5d6d; background: #fbfdff; }

.rating-table td {
  padding: 13px 12px;
  border-bottom: 1px solid #eef2f6;
  vertical-align: middle;
}

.rating-table tbody tr:hover { background: #fafcff; }
.rating-table tbody tr:last-child td { border-bottom: 0; }

.rank-pill {
  min-width: 46px;
  display: inline-block;
  text-align: center;
  border-radius: 999px;
  border: 1px solid #d6deea;
  padding: 4px 10px;
  color: #3f4f64;
  font-weight: 600;
}

.rank-1, .rank-2, .rank-3 { background: #fff3d8; border-color: #f0d48d; }

.name-cell button {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  color: #153f70;
  font-weight: 700;
  font-size: 16px;
  text-align: left;
  cursor: pointer;
  padding: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-mark {
  display: inline-block;
  background: #fff3d8;
  border: 1px solid #f0d48d;
  border-radius: 999px;
  padding: 0 6px;
  margin: 0 2px;
}

.score-badge {
  display: inline-block;
  text-align: center;
  border-radius: 999px;
  padding: 5px 10px;
  border: 1px solid #d8e1eb;
  background: #f6f9fc;
  color: #2d3f55;
  font-variant-numeric: tabular-nums;
}

.rating-table td:nth-child(5) .score-badge {
  border-color: #b9e6ca;
  background: var(--flat-soft);
  color: #126638;
}
.rating-table td:nth-child(6) .score-badge {
  border-color: #f2b7b7;
  background: var(--up-soft);
  color: #8f2323;
}
.rating-table td:nth-child(7) .score-badge {
  border-color: #bfd4fb;
  background: var(--down-soft);
  color: #1f4f9b;
}
.rating-table td:nth-child(8) .score-badge {
  border-color: #d8e1eb;
  background: #f6f9fc;
  color: #2d3f55;
}

.score-strong {
  border-width: 2px;
  box-shadow: 0 0 0 2px rgba(36, 54, 78, 0.08) inset;
}

.empty-state {
  padding: 24px;
  color: var(--muted);
  font-size: 16px;
}

.about-modal {
  position: fixed;
  inset: 0;
  background: rgba(10, 18, 30, 0.46);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 14px;
  z-index: 60;
}

.about-modal.open { display: flex; }

.participant-card {
  width: min(1320px, 96vw);
  max-height: min(94vh, 1300px);
  overflow: auto;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.participant-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.about-close {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  width: 30px;
  height: 30px;
  cursor: pointer;
}

.participant-body { padding: 16px 18px 20px; font-size: 16px; }
.participant-metrics { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-bottom: 12px; }
.participant-metrics .metric {
  padding: 12px;
  border-width: 2px;
}
.participant-metrics .metric .metric-value {
  font-size: 38px;
  letter-spacing: -0.02em;
}
.participant-metrics .metric .metric-label {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.participant-metrics .metric-overall {
  background: #fff;
  border-color: #607286;
}
.participant-metrics .metric-overall .metric-value,
.participant-metrics .metric-overall .metric-label {
  color: #2d3f55;
}
.participant-metrics .metric-flat {
  background: var(--flat-soft);
  border-color: var(--flat);
}
.participant-metrics .metric-flat .metric-value,
.participant-metrics .metric-flat .metric-label {
  color: #126638;
}
.participant-metrics .metric-up {
  background: var(--up-soft);
  border-color: var(--up);
}
.participant-metrics .metric-up .metric-value,
.participant-metrics .metric-up .metric-label {
  color: #8f2323;
}
.participant-metrics .metric-down {
  background: var(--down-soft);
  border-color: var(--down);
}
.participant-metrics .metric-down .metric-value,
.participant-metrics .metric-down .metric-label {
  color: #1f4f9b;
}

.participant-metrics .metric-endurance {
  background: #f5f3ff;
  border-color: #c4b5fd;
}
.participant-metrics .metric-endurance .metric-value,
.participant-metrics .metric-endurance .metric-label {
  color: #5b21b6;
}
.participant-metrics .metric-info-toggle {
  position: relative;
  text-align: left;
  cursor: pointer;
}
.participant-metrics .metric-info-toggle .metric-hint {
  display: none;
  position: absolute;
  left: 8px;
  right: 8px;
  top: calc(100% + 6px);
  z-index: 12;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid #c4b5fd;
  background: rgba(255, 255, 255, 0.98);
  color: #364a63;
  font-size: 12px;
  line-height: 1.35;
  box-shadow: 0 10px 24px rgba(8, 26, 54, 0.14);
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
}
.participant-metrics .metric-info-toggle.open .metric-hint {
  display: block;
}

.participant-rank-meta {
  margin: 2px 0 12px;
  padding: 10px 12px;
  border: 1px solid #d8e0ec;
  border-radius: 10px;
  background: #f8fbff;
  color: #33475f;
  font-size: 14px;
  line-height: 1.45;
}

.participant-rank-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #556a82;
  margin-bottom: 8px;
}

.participant-rank-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.participant-rank-table th,
.participant-rank-table td {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid #e5ebf3;
}

.participant-rank-table thead th {
  font-size: 12px;
  color: #5e7289;
  font-weight: 700;
}

.participant-rank-table tbody tr:last-child td {
  border-bottom: 0;
}

.rank-cat {
  font-weight: 700;
}

.rank-cat-overall { color: #23354f; }
.rank-cat-flat { color: #126638; }
.rank-cat-up { color: #8f2323; }
.rank-cat-down { color: #1f4f9b; }

.participant-rank-table td:not(:first-child) {
  font-variant-numeric: tabular-nums;
}

.participant-results-wrap {
  margin-top: 10px;
  border: 1px solid #e4e9f1;
  border-radius: 12px;
  overflow: auto;
  max-width: 100%;
}

.participant-results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.participant-results-table th,
.participant-results-table td {
  padding: 9px 10px;
  border-bottom: 1px solid #edf1f6;
  text-align: left;
  vertical-align: middle;
}

.participant-results-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8fbff;
  color: #4d5d72;
  font-weight: 600;
}

.participant-results-table tbody tr:hover {
  background: #fafcff;
}

.participant-results-table tbody tr:last-child td {
  border-bottom: 0;
}

.participant-results-title {
  margin: 12px 0 8px;
  font-size: 15px;
  font-weight: 700;
}

.chip {
  display: inline-block;
  border: 1px solid #d5deea;
  background: #f6f9fc;
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 12px;
  color: #3a4f6b;
}

.chip.chip-top {
  border-color: #efc57f;
  background: #fff5e2;
  color: #8b4f00;
}

.trail-link {
  color: #174f90;
  text-decoration: none;
}

.trail-link:hover {
  text-decoration: underline;
}

@media (max-width: 980px) {
  .hero { grid-template-columns: 1fr; }
  .filters-bar { grid-template-columns: 1fr; }
  .rating-table { font-size: 14px; }
  .participant-metrics { grid-template-columns: 1fr 1fr; }
  .filter-division-toggle { width: 100%; }
}

@media (max-width: 700px) {
  .rating-shell {
    padding: 10px;
    gap: 10px;
  }

  .hero {
    padding: 12px;
    border-radius: 14px;
  }

  .hero h1 {
    font-size: 24px;
  }

  .hero p {
    font-size: 13px;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .metric {
    padding: 8px 10px;
    min-height: 58px;
  }

  .metric .value {
    font-size: 20px;
  }

  .metric .label {
    font-size: 11px;
  }

  .table-shell {
    max-height: 62vh;
  }

  .rating-table {
    table-layout: fixed;
    width: 100%;
    font-size: 12px;
  }

  .rating-table th,
  .rating-table td {
    padding: 6px 6px;
  }

  .rating-table th:nth-child(1),
  .rating-table td:nth-child(1) {
    width: 36px;
    min-width: 36px;
  }

  .rating-table th:nth-child(3),
  .rating-table td:nth-child(3) {
        width: auto;
        min-width: auto;
  }

  .rating-table th:nth-child(4),
  .rating-table td:nth-child(4),
  .rating-table th:nth-child(5),
  .rating-table td:nth-child(5),
  .rating-table th:nth-child(6),
  .rating-table td:nth-child(6),
  .rating-table th:nth-child(7),
  .rating-table td:nth-child(7),
  .rating-table th:nth-child(8),
  .rating-table td:nth-child(8) {
    width: 52px;
    min-width: 52px;
  }

  .name-cell button {
    font-size: 12px;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  .score-badge {
    font-size: 11px;
    padding: 2px 6px;
  }
}

@media (max-width: 720px) {
  .table-shell {
    max-height: calc(100vh - 280px);
    overflow-x: auto;
    overflow-y: auto;
  }
  .rating-table {
    table-layout: auto;
    width: max-content;
    font-size: 12px;
  }
  .rating-table thead th,
  .rating-table td {
    padding: 8px 6px;
  }
  .rating-table th:nth-child(1),
  .rating-table td:nth-child(1) { width: 52px; }
  .rating-table th:nth-child(3),
  .rating-table td:nth-child(3) { width: auto; }
  .rating-table th:nth-child(4),
  .rating-table td:nth-child(4) { display: none; }
  .rating-table th:nth-child(5),
  .rating-table td:nth-child(5),
  .rating-table th:nth-child(6),
  .rating-table td:nth-child(6),
  .rating-table th:nth-child(7),
  .rating-table td:nth-child(7),
  .rating-table th:nth-child(8),
  .rating-table td:nth-child(8) { width: auto; }
  .name-cell button {
    font-size: 13px;
    white-space: normal;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100px;
  }
  .rank-pill {
    min-width: 36px;
    padding: 3px 8px;
    font-size: 11px;
  }
  .score-badge {
    padding: 4px 6px;
    font-size: 11px;
  }
}
