:root {
  --bg-0: #0a0a0e;
  --bg-1: #12121a;
  --bg-2: #1a1a24;
  --surface: rgba(255, 255, 255, 0.045);
  --surface-hover: rgba(255, 255, 255, 0.075);
  --border: rgba(255, 255, 255, 0.07);
  --text: #f4f4f5;
  --muted: #9ca3af;
  --accent: #a78bfa;
  --accent-2: #8b5cf6;
  --accent-ink: #ffffff;
  --good: #4ade80;
  --good-soft: rgba(74, 222, 128, 0.12);
  --warn: #fb923c;
  --warn-soft: rgba(251, 146, 60, 0.12);
  --bad: #f87171;
  --bad-soft: rgba(248, 113, 113, 0.12);
  --radius-sm: 12px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-xl: 32px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  --shadow-sm: 0 4px 16px rgba(0, 0, 0, 0.25);
  --font-display: 'Manrope', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  background: var(--bg-0);
  color: var(--text);
  font-family: var(--font-display);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
}

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

/* Layout */
.shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 260px;
  background: linear-gradient(180deg, var(--bg-1) 0%, var(--bg-0) 100%);
  border-right: 1px solid var(--border);
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  gap: 32px;
  z-index: 100;
  transform: translateX(0);
  transition: transform 0.25s ease;
}

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 99;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

body.menu-open .sidebar-overlay {
  opacity: 1;
  pointer-events: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 8px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 800;
  font-size: 18px;
  box-shadow: 0 4px 16px rgba(139, 92, 246, 0.35);
}

.brand-name {
  font-weight: 800;
  font-size: 20px;
  letter-spacing: -0.02em;
}

.brand-tag {
  font-size: 11px;
  color: var(--muted);
  margin-top: -2px;
}

nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
  transition: all 0.15s ease;
}

.nav-item svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  opacity: 0.8;
}

.nav-item:hover {
  background: var(--surface);
  color: var(--text);
}

.nav-item.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--accent-ink);
  box-shadow: 0 4px 20px rgba(139, 92, 246, 0.3);
}

.nav-item.active svg { opacity: 1; }

.logout {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
}

.logout:hover { color: var(--bad); background: var(--bad-soft); }

/* Header mobile */
.topbar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 90;
  background: rgba(10, 10, 14, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 14px 18px;
  align-items: center;
  justify-content: space-between;
}

.burger {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--text);
}

main {
  flex: 1;
  margin-left: 260px;
  padding: 36px 40px;
  max-width: 1200px;
}

/* Page */
.page-head { margin-bottom: 32px; }
.page-head h1 {
  margin: 0 0 6px;
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -0.03em;
}
.page-head p {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow);
}

.card-title {
  margin: 0 0 18px;
  font-size: 17px;
  font-weight: 700;
}

/* Stats grid */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, background 0.15s ease;
}

.stat-tile:hover {
  background: var(--surface-hover);
  transform: translateY(-2px);
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 32px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
}

.stat-label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

/* Leaderboard */
.leader-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 18px;
}

.leader-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  position: relative;
  overflow: hidden;
}

.leader-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
}

.leader-card.top-1 { border-color: rgba(251, 191, 36, 0.35); }
.leader-card.top-2 { border-color: rgba(192, 192, 192, 0.35); }
.leader-card.top-3 { border-color: rgba(251, 146, 60, 0.35); }

.leader-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--accent);
  opacity: 0.6;
}

.leader-card.top-1::before { background: #fbbf24; opacity: 1; }
.leader-card.top-2::before { background: #c0c0c0; opacity: 1; }
.leader-card.top-3::before { background: #fb923c; opacity: 1; }

.leader-header {
  display: flex;
  align-items: center;
  gap: 14px;
}

.leader-avatar {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 20px;
  color: #fff;
  flex-shrink: 0;
}

.leader-info { flex: 1; min-width: 0; }
.leader-name {
  font-weight: 700;
  font-size: 17px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.leader-badge {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.leader-days {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 700;
  color: var(--good);
  line-height: 1;
}

.leader-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.leader-rank {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}

.link-arrow {
  color: var(--accent);
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.link-arrow:hover { text-decoration: underline; }

/* Profile */
.profile-header {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 28px;
}

.profile-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid;
  place-items: center;
  font-size: 32px;
  font-weight: 800;
  color: #fff;
  box-shadow: 0 8px 24px rgba(139, 92, 246, 0.35);
}

.profile-title h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 800;
}

.profile-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 14px;
}

.status-pill {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 4px 10px;
  border-radius: 999px;
}

.status-active { background: var(--good-soft); color: var(--good); }
.status-break { background: var(--warn-soft); color: var(--warn); }

.profile-card {
  display: flex;
  justify-content: center;
  padding: 28px;
}

.profile-card img {
  max-width: 100%;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
}

.profile-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 14px;
  margin: 24px 0;
}

.profile-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
  text-align: center;
}

.profile-stat .value {
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 700;
  color: var(--accent);
}

.profile-stat .label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 6px;
}

.calendar-section img {
  width: 100%;
  max-width: 640px;
  border-radius: var(--radius-md);
  display: block;
  margin: 0 auto;
}

/* Races */
.race-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 18px;
}

.race-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: var(--shadow-sm);
}

.race-vs {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.race-user {
  flex: 1;
  text-align: center;
}

.race-user .name {
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 4px;
}

.race-user .id {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
}

.race-divider {
  font-weight: 800;
  color: var(--accent);
  font-size: 13px;
}

.race-status {
  align-self: flex-start;
}

.race-date {
  font-size: 13px;
  color: var(--muted);
  margin-top: auto;
}

/* Login */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 20% 20%, rgba(139, 92, 246, 0.12) 0%, transparent 40%),
    radial-gradient(circle at 80% 80%, rgba(74, 222, 128, 0.08) 0%, transparent 40%),
    var(--bg-0);
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 36px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.login-card .brand {
  justify-content: center;
  margin-bottom: 8px;
}

.login-card h1 {
  margin: 0;
  text-align: center;
  font-size: 22px;
}

.login-card .muted {
  text-align: center;
  font-size: 14px;
}

.login-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}

.login-card input {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  color: var(--text);
  font-family: var(--font-display);
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.login-card input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(167, 139, 250, 0.15);
}

.login-card button {
  margin-top: 4px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--accent-ink);
  border: none;
  border-radius: var(--radius-md);
  padding: 13px;
  font-weight: 700;
  cursor: pointer;
  font-size: 15px;
  box-shadow: 0 4px 20px rgba(139, 92, 246, 0.3);
  transition: filter 0.15s ease, transform 0.15s ease;
}

.login-card button:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.error {
  color: var(--bad);
  font-size: 13px;
  margin: 0;
  text-align: center;
}

/* Focus */
a:focus-visible,
button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* Mobile */
@media (max-width: 768px) {
  .topbar { display: flex; }

  .sidebar {
    transform: translateX(-100%);
    width: 280px;
  }

  body.menu-open .sidebar {
    transform: translateX(0);
  }

  main {
    margin-left: 0;
    padding: 22px;
    max-width: 100%;
  }

  .page-head h1 { font-size: 26px; }

  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  .stat-tile { padding: 16px; }
  .stat-value { font-size: 24px; }
  .stat-label { font-size: 10.5px; }

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

  .profile-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .profile-card { padding: 16px; }

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