:root {
  color-scheme: dark;
  --bg: #070b16;
  --surface: rgba(255, 255, 255, 0.045);
  --surface-hover: rgba(255, 255, 255, 0.07);
  --border: rgba(255, 255, 255, 0.09);
  --text: #e9edf6;
  --text-dim: #8b93a7;
  --orange: #ff8c1a;
  --orange-soft: rgba(255, 140, 26, 0.15);
  --blue: #3b82f6;
  --blue-soft: rgba(59, 130, 246, 0.15);
  --green: #34d399;
  --green-soft: rgba(52, 211, 153, 0.15);
  --red: #f87171;
  --red-soft: rgba(248, 113, 113, 0.15);
  --gold: #ffd24a;
  --silver: #c8cfdd;
  --bronze: #e08a5a;
  --radius: 16px;
}

* { box-sizing: border-box; }

::selection { background: var(--orange); color: #0a0e1a; }

::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #232a3d; border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: #2f3750; }

body {
  margin: 0;
  font-family: "Inter", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 3rem 1.5rem 5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
}

body::before,
body::after {
  content: "";
  position: fixed;
  border-radius: 50%;
  filter: blur(130px);
  z-index: -1;
  pointer-events: none;
}
body::before {
  width: 480px;
  height: 480px;
  top: -160px;
  left: -140px;
  background: radial-gradient(circle, rgba(255, 140, 26, 0.5), transparent 65%);
  animation: floatA 16s ease-in-out infinite alternate;
}
body::after {
  width: 560px;
  height: 560px;
  bottom: -200px;
  right: -160px;
  background: radial-gradient(circle, rgba(59, 130, 246, 0.5), transparent 65%);
  animation: floatB 20s ease-in-out infinite alternate;
}

@keyframes floatA { to { transform: translate(70px, 50px) scale(1.2); } }
@keyframes floatB { to { transform: translate(-60px, -40px) scale(1.15); } }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.5); }
  70% { box-shadow: 0 0 0 7px rgba(52, 211, 153, 0); }
}

h1, h2, .stat .value { font-family: "Space Grotesk", "Inter", sans-serif; }

.hero {
  text-align: center;
  margin-bottom: 2rem;
  animation: fadeUp 0.5s ease both;
}
.hero-small { margin-bottom: 1.5rem; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 1.1rem;
}
.badge .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 2s infinite;
}

h1 {
  font-size: clamp(2.4rem, 7vw, 3.6rem);
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.02em;
  background: linear-gradient(100deg, #ffb25e 0%, var(--orange) 35%, var(--blue) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
h1:has(+ .subtitle) { margin-bottom: 0.4rem; }

.subtitle {
  color: var(--text-dim);
  margin: 0;
  font-size: 0.95rem;
  letter-spacing: 0.01em;
}

.back {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--text-dim);
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 1rem;
  transition: color 0.2s;
}
.back:hover { color: var(--orange); text-decoration: none; }

a {
  color: var(--blue);
  text-decoration: none;
}
a:hover { color: var(--orange); }

h2 { color: var(--text); }

.bar {
  display: flex;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  width: min(760px, 100%);
  margin-bottom: 1.75rem;
  animation: fadeUp 0.5s ease 0.08s both;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-dim);
  font-size: 0.85rem;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
}
.status .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--blue);
  box-shadow: 0 0 8px var(--blue);
}

#refresh {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: linear-gradient(100deg, var(--orange), var(--blue));
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 0.6rem 1.2rem;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  font-family: inherit;
  transition: transform 0.2s, box-shadow 0.2s, filter 0.2s;
  box-shadow: 0 4px 20px rgba(255, 140, 26, 0.25);
}
#refresh:hover { transform: translateY(-2px); filter: brightness(1.1); box-shadow: 0 6px 28px rgba(59, 130, 246, 0.35); }
#refresh:active { transform: translateY(0); }
#refresh:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.card {
  background: var(--surface);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.4rem;
  margin-bottom: 1.1rem;
  width: min(760px, 100%);
  animation: fadeUp 0.45s ease both;
  transition: transform 0.22s ease, border-color 0.22s ease, box-shadow 0.22s ease, background 0.22s;
}
.card:nth-child(2) { animation-delay: 0.05s; }
.card:nth-child(3) { animation-delay: 0.1s; }
.card:nth-child(4) { animation-delay: 0.15s; }
.card:nth-child(5) { animation-delay: 0.2s; }
.card.clickable { cursor: pointer; }
.card.clickable:hover {
  transform: translateY(-3px);
  border-color: rgba(255, 140, 26, 0.55);
  background: var(--surface-hover);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45), 0 0 24px rgba(255, 140, 26, 0.08);
}

.race-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.35rem;
}
.race-top h2 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.9rem;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-dim);
}
.chip svg { width: 13px; height: 13px; flex: 0 0 auto; }
.chip-orange { border-color: rgba(255, 140, 26, 0.4); color: #ffb25e; background: var(--orange-soft); }
.chip-blue { border-color: rgba(59, 130, 246, 0.4); color: #7db0ff; background: var(--blue-soft); }
.chip-green { border-color: rgba(52, 211, 153, 0.4); color: #6fe7b4; background: var(--green-soft); }
.chip-red { border-color: rgba(248, 113, 113, 0.4); color: #fca5a5; background: var(--red-soft); }

.meta {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin: 0.4rem 0 0.9rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
th, td {
  text-align: left;
  padding: 0.55rem 0.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.right { text-align: right; }
th {
  color: var(--text-dim);
  font-weight: 500;
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.15s; }
tbody tr:hover { background: rgba(255, 255, 255, 0.03); }

.mono {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--text);
}

.winner { color: var(--orange); font-weight: 600; }

.player {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}
.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.02em;
  flex: 0 0 auto;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
}
.pname { line-height: 1.15; }
.pname .pid {
  display: block;
  color: var(--text-dim);
  font-size: 0.72rem;
  font-weight: 400;
}

.rank {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
}
.rank.gold {
  background: linear-gradient(135deg, #ffd24a, #f5a623);
  color: #4a3200;
  border: none;
  box-shadow: 0 0 14px rgba(255, 210, 74, 0.45);
}
.rank.silver {
  background: linear-gradient(135deg, #dde3ee, #9aa5b8);
  color: #2b3345;
  border: none;
  box-shadow: 0 0 12px rgba(200, 207, 221, 0.35);
}
.rank.bronze {
  background: linear-gradient(135deg, #e8a06c, #b96a35);
  color: #3d1e07;
  border: none;
  box-shadow: 0 0 12px rgba(224, 138, 90, 0.35);
}

.empty {
  color: var(--text-dim);
  text-align: center;
  padding: 2.5rem;
  font-size: 0.9rem;
}

.race-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 1.1rem;
  width: 100%;
}

#content {
  width: 90%;
  max-width: 1800px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
#content > .card { width: 100%; }

#stats, #results {
  width: 90%;
  max-width: 1800px;
}
.race-grid .card {
  width: 100%;
  height: 100%;
  margin-bottom: 0;
  min-width: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.race-grid .card table { margin-top: auto; font-size: 0.8rem; table-layout: fixed; }
.race-grid .card th, .race-grid .card td { padding: 0.45rem 0.35rem; }
.race-grid .empty { grid-column: 1 / -1; }

.stats {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 0.8rem;
  margin-bottom: 1.4rem;
  width: min(760px, 100%);
  animation: fadeUp 0.45s ease both;
}
.stat {
  flex: 1 1 140px;
  background: var(--surface);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.9rem 1rem;
  text-align: center;
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
}
.stat:hover {
  transform: translateY(-2px);
  border-color: rgba(255, 140, 26, 0.45);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.4);
}
.stat .stat-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  margin-bottom: 0.5rem;
}
.stat .stat-icon svg { width: 18px; height: 18px; }
.stat .stat-icon.o { background: var(--orange-soft); color: var(--orange); }
.stat .stat-icon.b { background: var(--blue-soft); color: var(--blue); }
.stat .value {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}
.stat .label {
  color: var(--text-dim);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  margin-top: 0.15rem;
}

.player-id { color: var(--text-dim); font-size: 0.75rem; }

@media (max-width: 640px) {
  body { padding: 2.2rem 1rem 4rem; }
  .card { padding: 1rem; }
  .bar { flex-direction: column; align-items: stretch; }
  #refresh { justify-content: center; }
  table { font-size: 0.8rem; }
  .stat { flex: 1 1 120px; }
}
