*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #0a0a0a;
  --surface: #141414;
  --table-header: #1a1a1a;
  --row-even: #111111;
  --row-odd: #0e0e0e;
  --red: #e63946;
  --text: #ffffff;
  --text-secondary: #999999;
  --scaled: #f59e0b;
  --dns: #555555;
  --border: #222222;
  --gold: #ffd700;
  --silver: #c0c0c0;
  --bronze: #cd7f32;
  --row-hover: #1c1c1c;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Nav */
.nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  display: flex;
  align-items: center;
}

.nav-inner {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav-brand {
  font-family: 'Oswald', sans-serif;
  font-weight: 700;
  font-size: 1.5rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.nav-subtitle {
  font-family: 'Oswald', sans-serif;
  font-weight: 400;
  font-size: 0.85rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

/* Hero */
.hero {
  margin-top: 60px;
  padding: 32px 24px;
  text-align: center;
  background: linear-gradient(180deg, #111111 0%, var(--bg) 100%);
}

.hero-title {
  font-family: 'Oswald', sans-serif;
  font-weight: 700;
  font-size: 2rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.hero-subtitle {
  font-family: 'Oswald', sans-serif;
  font-weight: 400;
  font-size: 1rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 8px;
}

/* Tabs */
.tabs-container {
  position: sticky;
  top: 60px;
  z-index: 90;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.tabs {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  gap: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  font-family: 'Oswald', sans-serif;
  font-weight: 600;
  font-size: 0.9rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
  padding: 14px 20px;
  cursor: pointer;
  border: none;
  background: none;
  white-space: nowrap;
  border-bottom: 3px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--text);
  border-bottom-color: var(--red);
}

/* Main */
.main {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 20px 24px;
}

/* Controls */
.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 16px;
}

.search-box input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 0.875rem;
  padding: 10px 16px;
  width: 260px;
  outline: none;
  transition: border-color 0.15s;
}

.search-box input::placeholder {
  color: var(--dns);
}

.search-box input:focus {
  border-color: var(--red);
}

.last-updated {
  font-size: 0.75rem;
  color: var(--dns);
  white-space: nowrap;
}

/* Table */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  font-feature-settings: 'tnum';
}

thead {
  position: sticky;
  top: 0;
  z-index: 10;
}

thead th {
  background: var(--table-header);
  font-family: 'Oswald', sans-serif;
  font-weight: 600;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
  padding: 12px 14px;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  position: relative;
}

thead th:hover {
  color: var(--text);
}

thead th .sort-arrow {
  margin-left: 4px;
  font-size: 0.65rem;
  opacity: 0.5;
}

thead th.sorted .sort-arrow {
  opacity: 1;
  color: var(--red);
}

thead th.col-rank,
thead th.col-athlete {
  position: sticky;
  z-index: 11;
  background: var(--table-header);
}

thead th.col-rank {
  left: 0;
  text-align: center;
  width: 60px;
}

thead th.col-athlete {
  left: 60px;
  min-width: 160px;
}

thead th.col-total {
  background: #1d1d1d;
  color: var(--text);
}

tbody tr {
  transition: background-color 0.1s;
}

tbody tr:nth-child(even) {
  background: var(--row-even);
}

tbody tr:nth-child(odd) {
  background: var(--row-odd);
}

tbody tr:hover {
  background: var(--row-hover);
}

tbody td {
  padding: 10px 14px;
  white-space: nowrap;
  border-bottom: 1px solid #1a1a1a;
}

tbody td.col-wo {
  white-space: normal;
  min-width: 80px;
}

tbody td.col-rank,
tbody td.col-athlete {
  position: sticky;
  z-index: 5;
}

tbody tr:nth-child(even) td.col-rank,
tbody tr:nth-child(even) td.col-athlete {
  background: var(--row-even);
}

tbody tr:nth-child(odd) td.col-rank,
tbody tr:nth-child(odd) td.col-athlete {
  background: var(--row-odd);
}

tbody tr:hover td.col-rank,
tbody tr:hover td.col-athlete {
  background: var(--row-hover);
}

tbody td.col-rank {
  left: 0;
  text-align: center;
  font-weight: 600;
  width: 60px;
}

tbody td.col-athlete {
  left: 60px;
  font-weight: 600;
  min-width: 160px;
}

tbody td.col-total {
  font-weight: 700;
  background: rgba(255, 255, 255, 0.03);
}

tbody td.col-wkts {
  color: var(--text-secondary);
}

.rank-1 { color: var(--gold); }
.rank-2 { color: var(--silver); }
.rank-3 { color: var(--bronze); }

/* Flight indicators */
:root {
  --flight-1: #e63946;
  --flight-2: #d97706;
  --flight-3: #3b82f6;
  --flight-4: #555555;
}

tbody td.col-rank.flight-1 { box-shadow: inset 2px 0 0 var(--flight-1); }
tbody td.col-rank.flight-2 { box-shadow: inset 2px 0 0 var(--flight-2); }
tbody td.col-rank.flight-3 { box-shadow: inset 2px 0 0 var(--flight-3); }
tbody td.col-rank.flight-4 { box-shadow: inset 2px 0 0 var(--flight-4); }

tr.flight-separator td {
  border-top: 2px solid var(--border);
}

.flight-legend {
  display: flex;
  gap: 16px;
  padding: 10px 14px;
  font-size: 0.75rem;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
}

.flight-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.flight-legend-bar {
  display: inline-block;
  width: 3px;
  height: 14px;
  border-radius: 1px;
}

.flight-legend-bar.flight-1 { background: var(--flight-1); }
.flight-legend-bar.flight-2 { background: var(--flight-2); }
.flight-legend-bar.flight-3 { background: var(--flight-3); }
.flight-legend-bar.flight-4 { background: var(--flight-4); }

.cell-dns {
  color: var(--dns);
}

.scaled-tag {
  color: var(--scaled);
  font-weight: 600;
  font-size: 0.8em;
}

.cell-rank {
  display: block;
  font-weight: 600;
}

.cell-result {
  display: block;
  font-size: 0.85em;
  color: var(--text-secondary);
  margin-top: 1px;
}

.cell-pts {
  display: block;
  font-size: 0.85em;
  color: var(--dns);
  margin-top: 1px;
}

/* Loading */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 16px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Skeleton loading */
.skeleton-table {
  width: 100%;
  border-collapse: collapse;
}

.skeleton-table th {
  background: var(--table-header);
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.skeleton-table .skel-bar {
  height: 12px;
  background: var(--border);
  border-radius: 4px;
}

.skeleton-table th .skel-bar {
  width: 60px;
  opacity: 0.6;
}

.skeleton-table td {
  padding: 12px 14px;
  border-bottom: 1px solid #1a1a1a;
}

.skeleton-table tr:nth-child(even) {
  background: var(--row-even);
}

.skeleton-table tr:nth-child(odd) {
  background: var(--row-odd);
}

.skeleton-table td .skel-bar {
  animation: shimmer 1.5s ease-in-out infinite;
}

.skeleton-table td:first-child .skel-bar { width: 24px; }
.skeleton-table td:nth-child(2) .skel-bar { width: 120px; }
.skeleton-table td .skel-bar { width: 70px; }
.skeleton-table td:last-child .skel-bar { width: 36px; }
.skeleton-table td:nth-last-child(2) .skel-bar { width: 48px; }

@keyframes shimmer {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 0.6; }
}

.error-message {
  text-align: center;
  padding: 40px 20px;
  color: var(--red);
  font-size: 0.9rem;
}

/* Footer */
.footer {
  text-align: center;
  padding: 32px 24px;
  color: var(--dns);
  font-size: 0.75rem;
  border-top: 1px solid var(--border);
  margin-top: auto;
}

/* Responsive */
@media (max-width: 768px) {
  .hero-title {
    font-size: 1.4rem;
  }

  .hero-subtitle {
    font-size: 0.85rem;
  }

  .hero {
    padding: 24px 16px;
  }

  .main {
    padding: 16px 12px;
  }

  .controls {
    flex-direction: column;
    align-items: stretch;
  }

  .search-box input {
    width: 100%;
    padding: 12px 16px;
    font-size: 1rem;
  }

  .last-updated {
    text-align: right;
  }

  .tab {
    font-size: 0.85rem;
    padding: 16px 18px;
    min-height: 48px;
  }

  table {
    font-size: 0.8rem;
  }

  thead th,
  tbody td {
    padding: 8px 10px;
  }

  thead th.col-rank,
  tbody td.col-rank {
    display: none;
  }

  thead th.col-athlete,
  tbody td.col-athlete {
    left: 0;
    min-width: 140px;
    max-width: 210px;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  tbody td.col-athlete::before {
    content: attr(data-rank) ". ";
    font-weight: 600;
    color: var(--text-secondary);
  }

  tbody td.col-athlete.rank-1::before { color: var(--gold); }
  tbody td.col-athlete.rank-2::before { color: var(--silver); }
  tbody td.col-athlete.rank-3::before { color: var(--bronze); }

  tbody td.col-athlete.flight-1 { box-shadow: inset 2px 0 0 var(--flight-1); }
  tbody td.col-athlete.flight-2 { box-shadow: inset 2px 0 0 var(--flight-2); }
  tbody td.col-athlete.flight-3 { box-shadow: inset 2px 0 0 var(--flight-3); }
  tbody td.col-athlete.flight-4 { box-shadow: inset 2px 0 0 var(--flight-4); }
}

@media (max-width: 480px) {
  .nav-brand {
    font-size: 1.2rem;
  }

  .nav-subtitle {
    font-size: 0.7rem;
  }

  .hero-title {
    font-size: 1.2rem;
  }

  table {
    font-size: 0.75rem;
  }

  thead th,
  tbody td {
    padding: 6px 8px;
  }
}
