:root {
  --ink: #1d211c;
  --muted: #68706a;
  --paper: #f5f7f0;
  --surface: #fffffb;
  --line: #ccd2c5;
  --pine: #123f33;
  --pine-soft: #dfe9df;
  --river: #126d76;
  --rose: #b3455d;
  --gold: #be8a19;
  --shadow: 0 14px 34px rgba(29, 33, 28, 0.1);
  --chart-card-height: 690px;
  --font-display: "Source Serif 4", Georgia, serif;
  --font-data: "Roboto Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(rgba(18, 63, 51, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(18, 63, 51, 0.035) 1px, transparent 1px),
    var(--paper);
  background-size: 32px 32px;
  font-family: var(--font-data);
}

a {
  color: var(--pine);
  font-weight: 700;
}

button,
input {
  font: inherit;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  color: #f8fbf3;
  background: rgba(18, 63, 51, 0.96);
  border-bottom: 1px solid rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(10px);
}

.header-inner {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(520px, auto);
  gap: 1.25rem;
  align-items: center;
  width: min(100%, 1320px);
  margin: 0 auto;
  padding: 0.85rem 1rem;
}

.brand-block {
  min-width: 0;
}

.eyebrow {
  margin: 0;
  color: #b9caba;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  margin-top: 0.08rem;
  font-family: var(--font-display);
  font-size: 1.72rem;
  font-weight: 750;
  line-height: 1;
}

h2 {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 750;
  line-height: 1.1;
}

h3 {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 750;
}

.controls {
  display: grid;
  grid-template-columns: auto minmax(220px, 320px) auto;
  gap: 0.9rem;
  align-items: end;
  justify-content: end;
}

.gender-control,
.search-control,
.toggle-control {
  display: grid;
  grid-template-rows: 0.75rem 2.45rem;
  gap: 0.32rem;
  align-items: center;
}

.gender-control,
.search-control {
  min-width: 0;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.2rem;
  height: 2.45rem;
  padding: 0.2rem;
  margin: 0;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.14);
}

.control-label,
.search-control label,
.toggle-control > span:first-child {
  display: block;
  margin: 0;
  color: #b9caba;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0;
  line-height: 0.75rem;
  text-transform: uppercase;
}

.segmented label {
  position: relative;
  display: inline-flex;
  min-width: 4.15rem;
  min-height: 0;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  color: #dce8dc;
  cursor: pointer;
}

.segmented input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.segmented span {
  position: relative;
  z-index: 1;
  font-size: 0.78rem;
  font-weight: 700;
}

.segmented label:has(input:checked) {
  color: var(--pine);
  background: #f7fbf1;
}

.segmented label:has(input:focus-visible),
.toggle-control input:focus-visible + .toggle-track {
  outline: 3px solid rgba(190, 138, 25, 0.45);
  outline-offset: 2px;
}

.athlete-input-wrap {
  position: relative;
  min-width: 0;
}

.search-control input {
  width: 100%;
  height: 2.45rem;
  padding: 0 2.55rem 0 0.7rem;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  color: #f8fbf3;
  background: rgba(0, 0, 0, 0.18);
}

.search-control input:focus-visible {
  border-color: rgba(255, 255, 255, 0.42);
  outline: none;
}

.search-control input::placeholder {
  color: #9db4a6;
}

.search-control input::-webkit-calendar-picker-indicator {
  display: none !important;
}

.search-control input::-webkit-list-button {
  display: none !important;
}

.athlete-clear-button {
  position: absolute;
  right: 0.48rem;
  top: 50%;
  display: inline-flex;
  width: 1.55rem;
  height: 1.55rem;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.82);
  border-radius: 999px;
  color: var(--pine);
  background: #fffef6;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1;
  transform: translateY(-50%);
  cursor: pointer;
}

.athlete-clear-button[hidden] {
  display: none;
}

.athlete-clear-button:hover,
.athlete-clear-button:focus-visible {
  border-color: #fff;
  background: #ffffff;
}

.athlete-clear-button:focus-visible {
  outline: none;
}

.toggle-control {
  cursor: pointer;
}

.toggle-control input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle-track {
  position: relative;
  display: block;
  align-self: center;
  width: 3.25rem;
  height: 1.75rem;
  border: 1px solid rgba(255, 255, 255, 0.26);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.2);
}

.toggle-track::after {
  position: absolute;
  top: 0.18rem;
  left: 0.22rem;
  width: 1.24rem;
  height: 1.24rem;
  border-radius: 50%;
  background: #dce8dc;
  content: "";
  transition: transform 140ms ease, background 140ms ease;
}

.toggle-control input:checked + .toggle-track {
  background: rgba(190, 138, 25, 0.65);
}

.toggle-control input:checked + .toggle-track::after {
  transform: translateX(1.45rem);
  background: #fffef6;
}

.page-shell {
  width: min(100%, 1320px);
  margin: 0 auto;
  padding: 1rem;
}

.viz-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 390px);
  gap: 1rem;
  align-items: stretch;
}

.chart-panel,
.detail-panel,
.table-panel,
.snapshot-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 251, 0.96);
  box-shadow: var(--shadow);
}

.chart-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  height: var(--chart-card-height);
  overflow: hidden;
}

.detail-panel {
  height: var(--chart-card-height);
}

.panel-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.95rem 1rem 0;
}

.section-heading p,
.detail-copy {
  margin-top: 0.25rem;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.45;
}

.time-chart {
  width: 100%;
  height: 100%;
  min-height: 0;
}

.detail-panel {
  min-height: 0;
  overflow-y: auto;
  padding: 1rem;
}

.detail-panel h3 {
  margin-bottom: 0.2rem;
}

.detail-title-row {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 0.75rem;
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.75rem 0;
}

.detail-chip {
  display: inline-flex;
  align-items: center;
  min-height: 1.55rem;
  padding: 0.18rem 0.45rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--pine);
  background: var(--pine-soft);
  font-size: 0.72rem;
  font-weight: 700;
}

.detail-chip--gold {
  color: #614100;
  background: #f6e8bd;
}

.detail-list {
  display: grid;
  gap: 0.55rem;
  margin-top: 0.75rem;
}

.note-row {
  padding: 0.65rem 0;
  border-top: 1px solid var(--line);
}

.note-row:first-child {
  border-top: 0;
}

.note-row strong {
  display: block;
  font-family: var(--font-display);
  font-size: 0.95rem;
}

.note-row span {
  display: block;
  margin-top: 0.15rem;
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.45;
}

.snapshot-section {
  margin-top: 1rem;
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.65rem;
}

.leaderboard-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.table-panel {
  overflow: hidden;
}

.leaderboard-grid .table-panel {
  min-height: 25.5rem;
}

.table-panel h3 {
  padding: 0.85rem 0.9rem 0;
}

.table-panel--F {
  border-top: 4px solid var(--rose);
}

.table-panel--M {
  border-top: 4px solid var(--river);
}

.table-panel--F h3 {
  color: var(--rose);
}

.table-panel--M h3 {
  color: var(--river);
}

.table-scroll {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 0.78rem;
}

th,
td {
  padding: 0.62rem 0.6rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
}

tr:last-child td {
  border-bottom: 0;
}

td {
  color: var(--ink);
}

tr[data-athlete-name] {
  cursor: pointer;
}

tr[data-athlete-name]:hover td {
  background: rgba(190, 138, 25, 0.08);
}

.col-rank {
  width: 2.7rem;
}

.col-gender-rank {
  width: 5.8rem;
}

.col-time {
  width: 5.2rem;
}

.col-year {
  width: 4.75rem;
}

.col-place {
  width: 4.75rem;
}

.col-athlete {
  width: auto;
}

.profile-table {
  font-size: 0.74rem;
}

.profile-table th,
.profile-table td {
  padding: 0.44rem 0.32rem;
  white-space: nowrap;
}

.profile-table th {
  font-size: 0.58rem;
}

.profile-table .col-year {
  width: 3.05rem;
}

.profile-table .col-time {
  width: 4.35rem;
}

.profile-table .col-gender-rank {
  width: 3.45rem;
}

.profile-table .col-place {
  width: 3.55rem;
}

td:first-child {
  color: var(--muted);
}

td:nth-child(2),
.col-athlete {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.name-button {
  display: inline-block;
  max-width: 100%;
  padding: 0;
  border: 0;
  color: var(--ink);
  background: transparent;
  font-weight: 700;
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  vertical-align: bottom;
  white-space: nowrap;
  cursor: pointer;
}

.name-button:hover,
.name-button:focus-visible {
  color: var(--gold);
  text-decoration: underline;
  outline: none;
}

.table-row-highlight td {
  background: rgba(190, 138, 25, 0.16);
}

.empty-rank-row td {
  color: transparent;
  pointer-events: none;
}

.table-panel--muted {
  opacity: 0.45;
}

.snapshot-section {
  padding: 1rem;
}

.leaderboard-block--annual {
  margin-top: 1.15rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.snapshot-heading {
  margin-bottom: 0.75rem;
}

.snapshot-year {
  min-width: 5rem;
  color: var(--pine);
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 750;
  text-align: right;
}

.snapshot-slider {
  width: 100%;
  margin: 0 0 0.9rem;
  accent-color: var(--pine);
}

.data-error {
  margin-bottom: 1rem;
  padding: 0.8rem 1rem;
  border: 1px solid rgba(198, 80, 50, 0.4);
  border-left: 5px solid #c65032;
  border-radius: 8px;
  background: rgba(198, 80, 50, 0.08);
  color: #7f2919;
}

footer {
  padding: 1rem 1rem 1.4rem;
  color: var(--muted);
  font-size: 0.72rem;
  text-align: center;
}

@media (max-width: 1020px) {
  .header-inner,
  .viz-layout {
    grid-template-columns: 1fr;
  }

  .controls {
    justify-content: stretch;
  }

  .detail-panel {
    height: auto;
    min-height: 0;
    overflow-y: visible;
  }

  .chart-panel {
    height: auto;
  }

  .time-chart {
    height: 620px;
  }
}

@media (max-width: 720px) {
  .header-inner {
    padding: 0.75rem;
  }

  h1 {
    font-size: 1.42rem;
  }

  .controls {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .segmented {
    grid-template-columns: repeat(3, 1fr);
  }

  .segmented label {
    min-width: 0;
  }

  .toggle-control {
    width: max-content;
  }

  .page-shell {
    padding: 0.65rem;
  }

  .panel-header,
  .section-heading {
    flex-direction: column;
    align-items: stretch;
  }

  .time-chart {
    height: 470px;
  }

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

  .leaderboard-grid table {
    min-width: 0;
  }
}
