:root {
  --bg-primary: #191A1C;
  --bg-secondary: #111111;
  --bg-tertiary: #1a1a1a;
  --bg-elevated: #222222;
  --border-color: #2a2a2a;
  --border-hover: #444444;
  --text-primary: #f0f0f0;
  --text-secondary: #a0a0a0;
  --text-muted: #666666;
  --accent-primary: #d50f3b;
  --accent-primary-hover: #b10d31;

  --red-100: #FFEBEF;
  --red-400: #FF5C7F;
  --red-450: #FF335F;
  --red-500: #FF1B4E;
  --red-550: #FF0A3F;
  --red-600: #EB0033;
  --red-700: #BD0029;
  --red-900: #5C0014;

  --yellow-100: #FFFAE6;
  --yellow-300: #FFE270;
  --yellow-400: #FFD324;
  --yellow-500: #FFCC00;
  --yellow-600: #D6AB00;
  --yellow-700: #B38F00;

  --gray-50:  #F8F8F9;
  --gray-100: #F2F2F3;
  --gray-200: #DFE0E2;
  --gray-300: #C9CBCF;
  --gray-400: #A9ACB2;
  --gray-500: #8A8D92;
  --gray-600: #6E747C;
  --gray-700: #595D64;
  --gray-750: #28292B;
  --gray-800: #1B1C1E;
  --gray-850: #17181A;
  --gray-900: #111213;
  --gray-950: #0F1011;

  /* Rank tier colors */
  --tier-platinum: #C9CBCF;
  --tier-gold: #FFD324;
  --tier-silver: #C9CBCF;
  --tier-bronze: #CD7F32;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.6);
  --radius-xs: 2px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --transition: all 0.2s ease;

  --font-sm: 0.875rem;
  --font-md: 1rem;
  --font-lg: 1.25rem;
  --font-xl: 2rem;
  --font-2xl: 3rem;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Bai Jamjuree', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--gray-950);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
}

.content-wrapper {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
}

.content-wrapper--hero {
  padding-top: 100px; /* clears the fixed navbar (~80px tall) */
  padding-bottom: 20px;
}

/* ===== NAVBAR ===== */
.navbar-wrap {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
}

.navbar {
  width: 100%;
  transition: var(--transition);
  padding: 16px 0;
  background: transparent;
}

.navbar--scrolled {
  background: rgba(15, 16, 17, 0.92);
  border-bottom: 1px solid var(--gray-750);
  backdrop-filter: blur(8px);
}

.navbar__inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 32px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
}

.navbar__left { justify-self: start; display: flex; align-items: center; }
.navbar__center { justify-self: center; display: flex; align-items: center; }
.navbar__right { justify-self: end; display: flex; align-items: center; gap: 8px; }

.navbar__brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}

.navbar__logo {
  height: 30px;
  width: auto;
}

/* Matches .login-card__tagline on the login screen. */
.navbar__tagline {
  font-family: 'Bai Jamjuree', sans-serif;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--text-secondary);
  user-select: none;
}

.navbar__links {
  list-style: none;
  display: flex;
  gap: 32px;
  margin: 0;
  padding: 0;
}

.navbar__link {
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  transition: var(--transition);
}

.navbar__link:hover { color: var(--yellow-500); }
.navbar__link.is-active { color: var(--yellow-500); }

/* ===== HERO ===== */
.page-hero {
  background: radial-gradient(ellipse at top, rgba(213, 15, 59, 0.08) 0%, transparent 60%), var(--gray-950);
  border-bottom: 1px solid var(--gray-800);
}

/* Compact page header: title and subtitle share one baseline row. */
.page-heading {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 2px 14px;
}

.page-title {
  font-size: var(--font-xl);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.page-subtitle {
  color: var(--text-secondary);
  font-size: var(--font-sm);
  font-family: 'Inter', sans-serif;
}

/* ===== MAIN ===== */
.page-main {
  padding: 24px 0 80px;
}

/* ===== ALERT ===== */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 24px;
  font-family: 'Inter', sans-serif;
  font-size: var(--font-sm);
}

.alert--error {
  background: rgba(255, 27, 78, 0.1);
  border: 1px solid var(--red-600);
  color: var(--text-primary);
}

.alert--info {
  background: rgba(255, 204, 0, 0.08);
  border: 1px solid var(--yellow-700);
  color: var(--text-primary);
}

/* ===== STATS BAR ===== */
.stats-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 32px;
  flex-wrap: wrap;
}

.stat-card {
  flex: 1;
  min-width: 140px;
  background: var(--gray-900);
  border: 1px solid var(--gray-750);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-card__label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  font-weight: 600;
}

.stat-card__value {
  font-size: 24px;
  font-weight: 700;
  font-family: 'Inter', sans-serif;
}

.stat-card--platinum .stat-card__value { color: var(--tier-platinum); }
.stat-card--gold .stat-card__value { color: var(--tier-gold); }
.stat-card--silver .stat-card__value { color: var(--tier-silver); }
.stat-card--bronze .stat-card__value { color: var(--tier-bronze); }

.stats-block .stats-bar {
  margin-bottom: 10px;
}

.stats-note {
  margin: 0 0 32px;
  font-size: 12px;
  color: var(--text-muted);
}

/* ===== SEARCH BAR ===== */
.search-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.search-bar__input {
  flex: 1;
  min-width: 220px;
  background: var(--gray-850);
  border: 1px solid var(--gray-700);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  transition: var(--transition);
}

.search-bar__input::placeholder {
  color: var(--text-muted);
}

.search-bar__input:hover,
.search-bar__input:focus {
  border-color: var(--border-hover);
  outline: none;
}

.search-bar__select {
  background: var(--gray-850);
  border: 1px solid var(--gray-700);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  cursor: pointer;
  transition: var(--transition);
}

.search-bar__select:hover,
.search-bar__select:focus {
  border-color: var(--border-hover);
  outline: none;
}

.search-bar__hint {
  margin: -14px 0 24px;
  font-size: 12px;
  color: var(--text-muted);
}

/* ===== TABS ===== */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--gray-750);
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  margin-bottom: -1px;
  border-bottom: 2px solid transparent;
  font-family: 'Bai Jamjuree', sans-serif;
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--text-secondary);
  text-decoration: none;
  transition: var(--transition);
}

.tab:hover {
  color: var(--text-primary);
}

.tab.is-active {
  color: var(--text-primary);
  border-bottom-color: var(--accent-primary);
}

.tab__count {
  padding: 1px 8px;
  background: var(--gray-850);
  border: 1px solid var(--gray-750);
  border-radius: 999px;
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  color: var(--text-secondary);
}

.tab.is-active .tab__count {
  border-color: var(--red-600);
  color: var(--text-primary);
}

/* ===== FILTER BAR ===== */
.filter-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.filter-bar__meta {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.pill {
  background: var(--gray-850);
  border: 1px solid var(--gray-750);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  color: var(--text-secondary);
  font-family: 'Inter', sans-serif;
}

.pill--accent {
  border-color: var(--red-600);
  color: var(--text-primary);
}

.pill--muted {
  color: var(--text-muted);
}

/* ===== RANK TABLE ===== */
.table-container {
  background: var(--gray-900);
  border: 1px solid var(--gray-750);
  border-radius: var(--radius-md);
  overflow: hidden;
  overflow-x: auto;
}

.rank-table {
  width: 100%;
  border-collapse: collapse;
  font-family: 'Inter', sans-serif;
  font-size: var(--font-sm);
  min-width: 900px;
}

.rank-table thead {
  background: var(--gray-850);
  border-bottom: 1px solid var(--gray-750);
}

.rank-table th {
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  white-space: nowrap;
}

.rank-table tbody tr {
  border-bottom: 1px solid var(--gray-800);
  transition: var(--transition);
}

.rank-table tbody tr:last-child { border-bottom: none; }
.rank-table tbody tr:hover { background: var(--gray-850); }

.rank-table td {
  padding: 12px 16px;
  color: var(--text-secondary);
  vertical-align: middle;
}

.rank-table__col-rank {
  font-weight: 700;
  color: var(--text-primary) !important;
  font-variant-numeric: tabular-nums;
}

.rank-table__col-name {
  color: var(--text-primary) !important;
  font-weight: 600;
}

.rank-table__col-nat {
  white-space: nowrap;
}

.rank-table__col-last {
  white-space: nowrap;
}

.flag {
  height: 14px;
  width: auto;
  border-radius: 2px;
  vertical-align: middle;
  margin-right: 6px;
}

.nat-code {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

/* ===== TEAM CELL ===== */
.team {
  display: flex;
  align-items: center;
  gap: 8px;
}

.team-logo {
  width: 20px;
  height: 20px;
  object-fit: contain;
  border-radius: var(--radius-xs);
  background: var(--gray-800);
  flex-shrink: 0;
}

.team-name {
  color: var(--text-primary);
  font-weight: 600;
}

.rank-table__col-tag {
  white-space: nowrap;
}

.tag-code {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

/* ===== RANK ADJUSTMENT ===== */
.rank-table__col-adjust {
  white-space: nowrap;
}

.adjust {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.adjust--up { color: #4caf50; }
.adjust--down { color: var(--red-400); }
.adjust--flat { color: var(--text-muted); }

/* ===== TIER BADGES ===== */
.tier-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-xs);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.tier-badge--platinum { background: rgba(201, 203, 207, 0.15); color: var(--tier-platinum); }
.tier-badge--gold { background: rgba(255, 211, 36, 0.15); color: var(--tier-gold); }
.tier-badge--silver { background: rgba(201, 203, 207, 0.12); color: var(--tier-silver); }
.tier-badge--bronze { background: rgba(205, 127, 50, 0.15); color: var(--tier-bronze); }

/* ===== RATING (DR / SR) ===== */
.rank-table__col-rating {
  white-space: nowrap;
}

.rating {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rating .tier-badge {
  min-width: 74px;
  text-align: center;
}

.progress {
  display: inline-block;
  width: 56px;
  height: 6px;
  background: var(--gray-800);
  border-radius: 999px;
  overflow: hidden;
  flex-shrink: 0;
}

.progress__bar {
  display: block;
  height: 100%;
  background: var(--red-600);
  border-radius: 999px;
}

.rating__pct {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--text-secondary);
  min-width: 34px;
  text-align: right;
}

/* ===== LAST RACE ===== */
.last-race__title {
  display: block;
  color: var(--text-primary);
  font-weight: 500;
  white-space: nowrap;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.last-race__date {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ===== PAGINATION ===== */
.pagination {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 24px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-family: 'Bai Jamjuree', sans-serif;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  transition: var(--transition);
  border: none;
  cursor: pointer;
}

.btn--ghost {
  background: transparent;
  border: 1px solid var(--gray-700);
  color: var(--text-secondary);
}

.btn--ghost:hover {
  border-color: var(--border-hover);
  color: var(--text-primary);
}

.btn--primary {
  background: var(--red-600);
  color: #fff;
  border: 1px solid var(--red-600);
}

.btn--primary:hover {
  background: var(--red-700);
  border-color: var(--red-700);
}

.btn--ghost.is-disabled {
  opacity: 0.4;
  pointer-events: none;
}

/* ===== NO DATA ===== */
.no-data {
  padding: 64px 24px;
  text-align: center;
  color: var(--text-muted);
  background: var(--gray-900);
  border: 1px solid var(--gray-750);
  border-radius: var(--radius-md);
}

.no-data code {
  color: var(--text-secondary);
  font-family: 'Inter', sans-serif;
}

/* Roster entries that are not in the cached rankings. */
.rank-row--missing {
  opacity: 0.55;
}

/* ===== FORM FIELD ===== */
.form-field {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-field__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.form-field__label {
  font-family: 'Bai Jamjuree', sans-serif;
  font-size: 12px;
  line-height: 16px;
  font-weight: 400;
  letter-spacing: 0.25px;
  text-transform: uppercase;
  color: var(--gray-400);
}

.form-field__control {
  width: 100%;
  font-family: 'Bai Jamjuree', sans-serif;
  font-size: 14px;
  line-height: 20px;
  font-weight: 400;
  color: #fff;
  background: rgba(17, 18, 19, 0.64);
  border: 1px solid var(--gray-850);
  border-radius: var(--radius-xs);
  padding: 12px 16px;
  outline: none;
  transition: border-color 0.15s ease;
}

.form-field__control::placeholder { color: var(--gray-700); }
.form-field__control:hover,
.form-field__control:focus { border-color: var(--red-500); }
.form-field:has(.form-field__control:hover) .form-field__label { color: #fff; }

/* ===== CHECKBOX ===== */
.checkbox {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-family: 'Inter', sans-serif;
  font-size: var(--font-sm);
  line-height: 1.45;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

.checkbox input[type="checkbox"] {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  margin-top: 2px;
  accent-color: var(--red-500);
  cursor: pointer;
}

/* ===== BUTTON ===== */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-xs);
  font-family: 'Bai Jamjuree', sans-serif;
  font-size: 12px;
  line-height: 20px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.25px;
  text-decoration: none;
  cursor: pointer;
  transition: var(--transition);
}

.button--primary {
  background: var(--red-500);
  border-color: var(--red-500);
  color: #fff;
}

.button--primary:hover {
  background: var(--red-450);
  border-color: var(--red-450);
  color: #fff;
}

.button--primary:active {
  background: var(--red-550);
  border-color: var(--red-550);
  color: #fff;
}

.button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(255, 27, 78, 0.45);
}

/* ===== LOGIN PAGE ===== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 40px;
  background: var(--gray-850);
  border: 1px solid var(--gray-800);
  border-radius: var(--radius-sm);
}

.login-card__brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.login-card__logo {
  display: block;
  height: 24px;
  width: auto;
}

.login-card__tagline {
  font-family: 'Bai Jamjuree', sans-serif;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.login-card__error {
  font-size: 14px;
  line-height: 20px;
  color: var(--red-500);
  background: rgba(220, 0, 50, 0.08);
  border: 1px solid var(--red-500);
  border-radius: var(--radius-xs);
  padding: 12px 16px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.login-form .button {
  width: 100%;
}

/* ===== LOGOUT (navbar) ===== */
.navbar__logout {
  font-family: 'Bai Jamjuree', sans-serif;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--text-secondary);
  border: 1px solid var(--gray-700);
  border-radius: var(--radius-xs);
  padding: 6px 12px;
  transition: var(--transition);
}

.navbar__logout:hover {
  color: #fff;
  border-color: var(--red-500);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
  .navbar__inner { grid-template-columns: 1fr auto; }
  .navbar__center { display: none; }
  .navbar__logo { height: 22px; }
  .navbar__tagline { font-size: 9px; }
  .content-wrapper--hero { padding-top: 88px; padding-bottom: 16px; }
  .page-title { font-size: var(--font-lg); }
  .stats-bar { flex-direction: column; }
  .stat-card { min-width: 100%; }
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-bar__meta { justify-content: flex-start; }
  .login-card { padding: 28px 20px; }
}
