:root {
  --bg: #06080b;
  --panel: rgba(14, 18, 24, 0.78);
  --panel-strong: rgba(20, 26, 34, 0.94);
  --line: rgba(255, 255, 255, 0.12);
  --line-strong: rgba(255, 255, 255, 0.22);
  --text: #f4f7fb;
  --muted: #9ba8b6;
  --soft: #cad4df;
  --red: #ff4655;
  --cyan: #25d8ff;
  --green: #61f3a6;
  --gold: #ffd166;
  --ink: #07090d;
  --max: 1180px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input {
  font: inherit;
}

.backdrop {
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(circle at 16% 18%, rgba(255, 70, 85, 0.28), transparent 28%),
    radial-gradient(circle at 82% 8%, rgba(37, 216, 255, 0.17), transparent 26%),
    linear-gradient(140deg, #07090d 0%, #10141b 52%, #05070a 100%);
}

.grid {
  position: absolute;
  inset: 0;
  opacity: 0.28;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.08) 1px, transparent 1px);
  background-size: 64px 64px;
  mask-image: linear-gradient(to bottom, black, transparent 84%);
}

.scanline {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent, rgba(255, 255, 255, 0.035), transparent);
  animation: scan 7s linear infinite;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  width: min(var(--max), calc(100% - 32px));
  margin: 0 auto;
  padding: 18px 0;
  backdrop-filter: blur(18px);
}

.brand,
.nav {
  display: flex;
  align-items: center;
}

.brand {
  gap: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.brand-text {
  display: inline-flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.brand-title {
  color: var(--text);
  font-weight: 900;
}

.brand-credit {
  color: rgba(244, 247, 251, 0.54);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.14em;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid var(--line-strong);
  background: linear-gradient(135deg, var(--red), #ff8f70);
  color: white;
  font-size: 13px;
  clip-path: polygon(11% 0, 100% 0, 89% 100%, 0 100%);
}

.nav {
  gap: 6px;
  color: var(--soft);
  font-size: 14px;
  font-weight: 700;
}

.nav a {
  padding: 10px 12px;
  border: 1px solid transparent;
}

.nav a:hover {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.05);
}

.section {
  width: min(var(--max), calc(100% - 32px));
  margin: 0 auto;
}

.hero {
  min-height: calc(100svh - 80px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(330px, 460px);
  gap: 48px;
  align-items: center;
  padding: 60px 0 42px;
}

.eyebrow {
  margin: 0 0 14px;
  color: var(--cyan);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

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

h1 {
  max-width: 850px;
  margin-bottom: 24px;
  font-size: clamp(54px, 9vw, 124px);
  line-height: 0.86;
  font-weight: 950;
  text-transform: uppercase;
}

h2 {
  margin-bottom: 18px;
  font-size: clamp(34px, 5vw, 68px);
  line-height: 0.95;
  font-weight: 920;
  text-transform: uppercase;
}

h3 {
  font-size: 24px;
}

.hero-lead {
  max-width: 650px;
  color: var(--soft);
  font-size: clamp(18px, 2vw, 23px);
  line-height: 1.45;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 34px;
}

.primary-action,
.ghost-action {
  display: inline-flex;
  align-items: center;
  min-height: 48px;
  padding: 0 20px;
  font-weight: 900;
  text-transform: uppercase;
  border: 1px solid var(--line-strong);
  clip-path: polygon(0 0, calc(100% - 12px) 0, 100% 12px, 100% 100%, 12px 100%, 0 calc(100% - 12px));
}

.primary-action {
  background: var(--red);
  color: white;
  box-shadow: 0 18px 70px rgba(255, 70, 85, 0.22);
}

.ghost-action {
  background: rgba(255, 255, 255, 0.06);
}

.hero-panel,
.formula-card,
.leaderboard-shell,
.manual-note {
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(18px);
  box-shadow: 0 26px 90px rgba(0, 0, 0, 0.28);
}

.hero-panel {
  min-height: 520px;
  padding: 22px;
  position: relative;
  overflow: hidden;
}

.hero-panel::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(120deg, rgba(255, 70, 85, 0.28), transparent 34%),
    linear-gradient(0deg, rgba(37, 216, 255, 0.16), transparent 45%);
  pointer-events: none;
}

.live-badge {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 10px 12px;
  color: var(--soft);
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.18);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.live-badge span {
  width: 8px;
  height: 8px;
  background: var(--green);
  border-radius: 50%;
  box-shadow: 0 0 24px var(--green);
}

.leader-preview {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 14px;
  margin-top: 72px;
}

.preview-row {
  display: grid;
  grid-template-columns: 44px 38px 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.07);
  transform: translateX(var(--offset));
}

.preview-row strong {
  font-size: 20px;
}

.preview-rank {
  color: var(--gold);
  font-weight: 950;
}

.preview-score {
  color: var(--cyan);
  font-size: 14px;
  font-weight: 900;
}

.preview-row .avatar {
  width: 38px;
  height: 38px;
  font-size: 12px;
}

.stats-band {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  width: min(var(--max), calc(100% - 32px));
  margin: 0 auto;
  border-block: 1px solid var(--line);
}

.stat {
  min-height: 142px;
  padding: 26px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.035);
}

.stat:last-child {
  border-right: 0;
}

.stat span {
  display: block;
  font-size: clamp(38px, 6vw, 70px);
  line-height: 0.9;
  font-weight: 950;
}

.stat p {
  margin: 12px 0 0;
  color: var(--muted);
  font-weight: 800;
  text-transform: uppercase;
}

.manual-note {
  display: grid;
  grid-template-columns: 1.08fr 0.92fr;
  gap: 34px;
  margin-top: 90px;
  padding: 34px;
}

.manual-note p:last-child,
.section-heading p,
.formula-copy p,
.formula-card p {
  color: var(--soft);
  line-height: 1.7;
}

.leaderboard-section,
.formula-grid,
#races {
  padding-top: 112px;
}

.section-heading {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(260px, 0.75fr);
  gap: 42px;
  align-items: end;
  margin-bottom: 28px;
}

.section-heading p:last-child {
  margin-bottom: 8px;
}

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

.segmented {
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
}

.segmented button {
  min-height: 40px;
  padding: 0 14px;
  color: var(--soft);
  border: 0;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
}

.segmented button.active {
  background: var(--text);
  color: var(--ink);
}

.search {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 50px;
  padding: 0 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.search input {
  width: min(34vw, 230px);
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  text-transform: none;
}

.leaderboard-shell {
  overflow: hidden;
}

.table-head,
.leader-row {
  display: grid;
  grid-template-columns: 72px minmax(170px, 1fr) 120px 96px 96px 96px;
  gap: 12px;
  align-items: center;
}

.table-head {
  padding: 15px 18px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.leaderboard {
  display: grid;
}

.leader-row {
  position: relative;
  min-height: 82px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  border-left: 0;
  border-right: 0;
  border-top: 0;
  color: var(--text);
  background: linear-gradient(90deg, rgba(255, 255, 255, calc(var(--heat) * 0.08)), transparent);
  cursor: pointer;
  transition: transform 180ms ease, background 180ms ease;
  text-align: left;
}

.leader-row:last-child {
  border-bottom: 0;
}

.leader-row:hover {
  transform: translateX(6px);
  background-color: rgba(255, 255, 255, 0.055);
}

.rank {
  color: var(--gold);
  font-size: 22px;
  font-weight: 950;
}

.driver {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  min-width: 0;
}

.driver strong {
  display: block;
  font-size: 20px;
  color: var(--text);
  text-shadow: 0 0 18px rgba(37, 216, 255, 0.14);
}

.driver-info > span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.score {
  color: var(--cyan);
  font-size: 22px;
  font-weight: 950;
}

.metric {
  color: var(--soft);
  font-weight: 850;
}

.avatar {
  position: relative;
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.24);
  background:
    linear-gradient(135deg, hsla(var(--hue), 90%, 58%, 0.95), hsla(calc(var(--hue) + 44), 84%, 48%, 0.74)),
    rgba(255, 255, 255, 0.08);
  color: white;
  font-size: 14px;
  font-weight: 950;
  overflow: hidden;
  border-radius: 999px;
  box-shadow: inset 0 0 18px rgba(255, 255, 255, 0.12), 0 10px 30px rgba(0, 0, 0, 0.28);
}

.avatar img {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-fallback {
  position: relative;
  z-index: 1;
}

.driver-info {
  min-width: 0;
}

.formula-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 460px);
  gap: 42px;
  align-items: start;
}

.formula-card {
  padding: 28px;
}

.formula-line {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 0;
  border-top: 1px solid var(--line);
}

.formula-line span {
  color: var(--muted);
  font-weight: 900;
  text-transform: uppercase;
}

.formula-line strong {
  text-align: right;
}

.formula-detail {
  display: grid;
  gap: 10px;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.formula-detail span {
  color: var(--soft);
  font-size: 14px;
  font-weight: 750;
  line-height: 1.45;
}

.race-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding-bottom: 80px;
}

.race-card {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.045);
  padding: 18px;
}

.race-card h3 {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 14px;
  font-size: 18px;
}

.race-card a {
  color: var(--cyan);
  font-size: 13px;
  font-weight: 850;
}

.race-results {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  padding: 8px 10px;
  border: 1px solid var(--line);
  color: var(--soft);
  background: rgba(0, 0, 0, 0.16);
  font-size: 13px;
  font-weight: 800;
}

.player-dialog {
  width: min(620px, calc(100% - 32px));
  border: 1px solid var(--line-strong);
  background: var(--panel-strong);
  color: var(--text);
  padding: 0;
  backdrop-filter: blur(20px);
}

.player-dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
}

.dialog-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-size: 24px;
  cursor: pointer;
}

.dialog-body {
  padding: 30px;
}

.dialog-profile {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 18px;
  align-items: center;
}

.dialog-profile .avatar {
  width: 76px;
  height: 76px;
  font-size: 22px;
}

.dialog-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 22px 0;
}

.dialog-stat {
  padding: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
}

.dialog-stat strong {
  display: block;
  font-size: 22px;
}

.dialog-stat span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.mini-results {
  display: grid;
  gap: 8px;
  max-height: 260px;
  overflow: auto;
}

.mini-result {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  color: var(--soft);
}

.reveal {
  opacity: 0;
  transform: translateY(22px);
  transition: opacity 700ms ease, transform 700ms ease;
}

.reveal.visible {
  opacity: 1;
  transform: translateY(0);
}

.admin-toggle {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: var(--panel-strong);
  color: var(--soft);
  font-size: 20px;
  cursor: pointer;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(12px);
}

.admin-toggle:hover {
  color: var(--cyan);
  border-color: var(--cyan);
}

.admin-dialog {
  width: min(680px, calc(100% - 32px));
  border: 1px solid var(--line-strong);
  background: var(--panel-strong);
  color: var(--text);
  padding: 0;
  backdrop-filter: blur(20px);
  max-height: 88svh;
}

.admin-dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
}

.admin-body {
  max-height: 88svh;
  overflow: auto;
}

.admin-form {
  display: grid;
  gap: 14px;
  margin-bottom: 18px;
}

.admin-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.admin-form input {
  min-height: 46px;
  padding: 0 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  text-transform: none;
}

.admin-form input:focus {
  outline: 0;
  border-color: var(--cyan);
}

.admin-error {
  color: var(--red);
  font-weight: 800;
  font-size: 13px;
}

.admin-tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  margin-bottom: 22px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
}

.admin-tab {
  flex: 1;
  min-height: 40px;
  border: 0;
  background: transparent;
  color: var(--soft);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
  cursor: pointer;
}

.admin-tab.active {
  background: var(--text);
  color: var(--ink);
}

.result-rows {
  display: grid;
  gap: 8px;
}

.result-row {
  display: grid;
  grid-template-columns: 1fr 90px 36px;
  gap: 8px;
  align-items: center;
}

.result-row input {
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
}

.result-remove {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  background: rgba(255, 70, 85, 0.15);
  color: var(--red);
  cursor: pointer;
  font-size: 18px;
}

.admin-list {
  margin-top: 26px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.admin-list h3 {
  font-size: 16px;
  margin-bottom: 12px;
}

.admin-race-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  color: var(--soft);
  font-size: 13px;
}

.admin-race-row a {
  display: block;
  color: var(--cyan);
  font-size: 12px;
  margin-top: 2px;
}

.admin-empty {
  color: var(--muted);
  font-size: 13px;
}

.admin-hint {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  margin-top: 4px;
}

.admin-danger {
  border-color: rgba(255, 70, 85, 0.4);
  color: var(--red);
}

.export-output {
  width: 100%;
  min-height: 220px;
  margin: 14px 0;
  padding: 14px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.3);
  color: var(--soft);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  resize: vertical;
}

@media (max-width: 520px) {
  .admin-toggle {
    right: 16px;
    bottom: 16px;
  }
}

@keyframes scan {
  from {
    transform: translateY(-100%);
  }
  to {
    transform: translateY(100%);
  }
}

@media (max-width: 860px) {
  .topbar {
    align-items: flex-start;
  }

  .nav {
    display: none;
  }

  .hero,
  .manual-note,
  .section-heading,
  .formula-grid {
    grid-template-columns: 1fr;
  }

  .hero {
    padding-top: 32px;
  }

  .hero-panel {
    min-height: 360px;
  }

  .stats-band {
    grid-template-columns: repeat(2, 1fr);
  }

  .stat:nth-child(2) {
    border-right: 0;
  }

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

  .segmented {
    overflow-x: auto;
  }

  .search input {
    width: 100%;
  }

  .table-head {
    display: none;
  }

  .leader-row {
    grid-template-columns: 54px minmax(0, 1fr) 86px;
    grid-template-areas:
      "rank driver score"
      "rank races podium";
  }

  .leader-row .rank {
    grid-area: rank;
  }

  .leader-row .driver {
    grid-area: driver;
  }

  .leader-row .score {
    grid-area: score;
    text-align: right;
  }

  .leader-row .race-count {
    grid-area: races;
  }

  .leader-row .top-three {
    grid-area: podium;
    text-align: right;
  }

  .leader-row .avg-place {
    display: none;
  }

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

  .dialog-stats {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 520px) {
  .stats-band {
    grid-template-columns: 1fr;
  }

  .stat {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .hero-actions a {
    width: 100%;
    justify-content: center;
  }
}
