@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;900&display=swap');

:root, [data-theme="dark"] {
  --bg-page: #0a0a0f;
  --bg-card: #12121a;
  --bg-sidebar: #0f0f17;
  --bg-sidebar-hover: #1a1a26;
  --bg-header: #0f0f17;
  --border: #1e1e2a;
  --royal: #2b5eac;
  --royal-light: #3a75d4;
  --royal-muted: rgba(43, 94, 172, 0.15);
  --royal-subtle: rgba(43, 94, 172, 0.08);
  --accent: #f5d623;
  --accent-hover: #ffe44a;
  --accent-muted: rgba(245, 214, 35, 0.15);
  --accent-subtle: rgba(245, 214, 35, 0.08);
  --gold: #f5d623;
  --gold-glow: rgba(245, 214, 35, 0.12);
  --text-primary: #f0f0f5;
  --text-secondary: #9498a8;
  --text-muted: #5c6078;
  --text-inverse: #0a0a0f;
  --grid-color: rgba(255, 255, 255, 0.03);
  --sidebar-width: 220px;
  --header-height: 52px;
  --font: 'Inter', system-ui, sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--bg-page);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.grid-bg {
  background-image: linear-gradient(var(--grid-color) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-color) 1px, transparent 1px);
  background-size: 24px 24px;
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
}

/* Top Nav */
.topnav {
  height: var(--header-height);
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
}
.topnav-left, .topnav-center, .topnav-right { display: flex; align-items: center; gap: 8px; }
.brand { font-weight: 900; font-size: 17px; letter-spacing: -0.5px; }
.accent { color: var(--royal-light); }
.topnav-link {
  padding: 5px 14px; border-radius: 20px; font-size: 13px; font-weight: 500;
  color: var(--text-secondary); text-decoration: none; transition: all 0.15s;
}
.topnav-link:hover { background: var(--bg-sidebar-hover); color: var(--text-primary); }
.topnav-link.active { background: var(--royal-muted); color: var(--royal-light); }
.league-badge {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--gold); background: var(--royal-muted); padding: 4px 12px; border-radius: 20px;
  border: 1px solid rgba(43, 94, 172, 0.3);
}

/* App Shell */
.app {
  display: flex; min-height: 100vh; padding-top: var(--header-height);
  position: relative; z-index: 1;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width); background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: fixed; top: var(--header-height); left: 0; bottom: 0; z-index: 10;
  overflow: hidden;
}
.sidebar-nav { flex: 1; overflow-y: auto; padding: 8px; }
.nav-section { margin-bottom: 16px; }
.nav-section-label {
  font-size: 10px; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.08em; padding: 8px 8px 4px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: 6px;
  color: var(--text-secondary); text-decoration: none; font-size: 13px; font-weight: 500;
  cursor: pointer; transition: all 0.15s; border-left: 3px solid transparent;
}
.nav-item:hover { background: var(--bg-sidebar-hover); color: var(--text-primary); }
.nav-item.active { background: var(--royal-subtle); color: var(--royal-light); border-left-color: var(--royal-light); }
.event-icon { font-size: 16px; }
.sidebar-footer {
  padding: 12px 16px; border-top: 1px solid var(--border);
  font-size: 11px; color: var(--text-muted);
}

/* Main */
.main {
  flex: 1; margin-left: var(--sidebar-width);
  display: flex; flex-direction: column; min-height: 100vh;
}
.content { flex: 1; padding: 24px; }

/* Hero Banner */
.hero-banner {
  background: linear-gradient(135deg, #1a1520 0%, #0f0f17 50%, #1a1a10 100%);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 32px; margin-bottom: 20px;
  display: flex; justify-content: space-between; align-items: center;
  position: relative; overflow: hidden;
}
.hero-banner::before {
  content: ''; position: absolute; top: -50px; right: -50px;
  width: 200px; height: 200px; border-radius: 50%;
  background: rgba(43, 94, 172, 0.15); filter: blur(60px);
}
.hero-text h1 {
  font-size: 32px; font-weight: 900; letter-spacing: -1px;
  background: linear-gradient(135deg, var(--royal-light) 0%, var(--royal-light) 15%, var(--gold) 55%, #ffe920 85%, #ffed4a 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.hero-text p { color: var(--text-secondary); font-size: 15px; margin-top: 4px; }
.countdown { font-size: 56px; font-weight: 900; color: var(--gold); line-height: 1; }
.countdown-label { font-size: 12px; color: var(--text-muted); text-align: center; margin-top: 4px; }

/* Cards */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; margin-bottom: 20px; }
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 10px; padding: 24px; margin-bottom: 16px;
}
.card-title { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.card-subtitle { font-size: 12px; color: var(--text-muted); margin-bottom: 16px; }

.stat-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 10px; padding: 20px;
}
.stat-card.gold-glow { border-color: rgba(43, 94, 172, 0.3); box-shadow: 0 0 30px rgba(43, 94, 172, 0.12); }
.stat-label { font-size: 12px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-size: 36px; font-weight: 900; color: var(--text-primary); margin: 4px 0; }
.stat-sub { font-size: 12px; color: var(--text-secondary); margin-bottom: 10px; }
.progress-bar { height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--gold), #ffbe4a); border-radius: 2px; }

/* Race Timeline */
.race-timeline { display: flex; flex-direction: column; gap: 8px; }
.race-entry { display: flex; align-items: center; gap: 12px; }
.race-date { width: 60px; font-size: 12px; color: var(--text-muted); font-weight: 600; }
.race-bar-wrap { flex: 1; }
.race-bar {
  height: 28px; border-radius: 4px; display: flex; align-items: center; padding: 0 12px;
  font-size: 12px; font-weight: 700; color: var(--text-primary);
  background: linear-gradient(90deg, #2a2a3a, #3a3a4a);
  transition: width 0.6s ease;
}
.race-bar.pr { background: linear-gradient(90deg, var(--royal), var(--royal-light)); color: var(--gold); font-weight: 900; }
.race-bar.goal {
  background: linear-gradient(90deg, var(--royal), var(--gold));
  color: #1a1a10; animation: pulse-gold 2s infinite;
}
.race-place { width: 70px; text-align: right; font-size: 13px; font-weight: 700; color: var(--text-secondary); }
.race-entry.highlight .race-place { color: var(--gold); }
.race-entry.target .race-place { color: #ff6b35; font-weight: 900; }
@keyframes pulse-gold {
  0%, 100% { box-shadow: 0 0 10px rgba(43, 94, 172, 0.15); }
  50% { box-shadow: 0 0 25px rgba(245, 214, 35, 0.3); }
}

/* Splits */
.splits-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.split {
  background: var(--bg-sidebar); border: 1px solid var(--border);
  border-radius: 8px; padding: 16px;
}
.split-lap { font-size: 11px; color: var(--text-muted); font-weight: 700; text-transform: uppercase; }
.split-target { font-size: 28px; font-weight: 900; color: var(--gold); margin: 4px 0; }
.split-note { font-size: 12px; color: var(--text-secondary); line-height: 1.4; }

/* Rivals */
.rivals-grid { display: flex; flex-direction: column; gap: 8px; }
.rival {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 16px; border-radius: 8px; background: var(--bg-sidebar);
  border: 1px solid var(--border);
}
.rival:first-child { border-color: rgba(43, 94, 172, 0.4); box-shadow: 0 0 15px rgba(43, 94, 172, 0.15); }
.rival-rank {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent-muted); color: var(--gold);
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 13px;
}
.rival:first-child .rival-rank { background: var(--royal); color: var(--gold); }
.rival-info { flex: 1; }
.rival-name { font-weight: 700; font-size: 14px; }
.rival-time { font-size: 12px; color: var(--text-muted); }
.rival-trend { font-size: 12px; font-weight: 600; }
.rival-trend.up { color: #4ade80; }
.rival-trend.flat { color: var(--text-muted); }
.rival-trend.down { color: #f87171; }

/* Views */
.view { display: block; }
.view.hidden { display: none; }

/* Clickable cards */
.clickable { cursor: pointer; transition: transform 0.15s, box-shadow 0.15s; }
.clickable:hover { transform: translateY(-2px); box-shadow: 0 0 40px rgba(43, 94, 172, 0.2); }

/* Rank Hero Box */
.rank-hero {
  background: linear-gradient(135deg, rgba(43, 94, 172, 0.12) 0%, var(--bg-card) 60%);
  border: 2px solid rgba(43, 94, 172, 0.3);
  border-radius: 12px;
  padding: 24px 32px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 24px;
  box-shadow: 0 0 40px rgba(43, 94, 172, 0.1);
}
.rank-number {
  font-size: 72px;
  font-weight: 900;
  color: var(--gold);
  line-height: 1;
  text-shadow: 0 0 30px rgba(245, 214, 35, 0.3);
}
.rank-detail { flex: 1; }
.rank-event {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.rank-time {
  font-size: 28px;
  font-weight: 900;
  color: var(--text-primary);
  margin-top: 2px;
}

@media (max-width: 768px) {
  .rank-hero { padding: 16px 20px; gap: 16px; }
  .rank-number { font-size: 48px; }
  .rank-time { font-size: 20px; }
}

/* Results Table */
.results-table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.results-table th {
  text-align: left; font-size: 11px; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.05em;
  padding: 8px 10px; border-bottom: 1px solid var(--border);
}
.results-table td {
  padding: 10px; border-bottom: 1px solid rgba(255,255,255,0.04);
  font-size: 13px; color: var(--text-secondary);
}
.results-table tr:hover { background: rgba(245, 166, 35, 0.04); }
.results-table td:nth-child(3) { font-weight: 700; color: var(--text-primary); }
.pr-row { background: rgba(245, 166, 35, 0.06); }
.pr-row td { color: var(--text-primary); }
.gold-text { color: var(--gold); }

/* Videos */
.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}
.video-card {
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.video-embed {
  position: relative;
  padding-bottom: 56.25%; /* 16:9 */
  height: 0;
}
.video-embed iframe {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  border-radius: 8px 8px 0 0;
}
.video-label {
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 700;
  color: var(--gold);
}

@media (max-width: 768px) {
  .video-grid { grid-template-columns: 1fr; }
}

/* Hero Photo */
.hero-photo {
  position: relative;
  flex-shrink: 0;
}
.hero-img {
  width: 120px;
  height: 120px;
  object-fit: cover;
  object-position: center top;
  border-radius: 10px;
  border: 2px solid rgba(43, 94, 172, 0.3);
  box-shadow: 0 0 30px rgba(43, 94, 172, 0.2);
  mask-image: linear-gradient(to right, transparent 0%, black 15%, black 85%, transparent 100%);
  -webkit-mask-image: linear-gradient(to right, transparent 0%, black 15%, black 85%, transparent 100%);
}

/* Feature Photo Card */
.photo-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 16px;
  position: relative;
}
.feature-photo {
  width: 100%;
  max-height: 320px;
  object-fit: cover;
  object-position: center 30%;
  display: block;
  mask-image: linear-gradient(to bottom, black 60%, transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom, black 60%, transparent 100%);
}
.photo-caption {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 16px 24px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  background: linear-gradient(to top, var(--bg-card) 0%, transparent 100%);
}

/* Motivational */
.motivational {
  text-align: center; padding: 32px; margin-top: 8px;
  font-size: 16px; font-style: italic; color: var(--text-secondary);
  line-height: 1.6;
}
.motive-sub { font-size: 13px; color: var(--text-muted); font-style: normal; display: block; margin-top: 8px; }

/* ── Mobile / Phone ── */
@media (max-width: 768px) {
  /* Hide sidebar on mobile — content takes full width */
  .sidebar { display: none; }
  .main { margin-left: 0; }

  /* Top nav stacks */
  .topnav {
    height: auto; flex-wrap: wrap; padding: 10px 16px; gap: 8px;
  }
  .topnav-left, .topnav-center, .topnav-right {
    width: 100%; justify-content: center;
  }
  .topnav-center { order: 3; }
  .topnav-right { order: 2; }
  .league-badge { font-size: 10px; }

  /* App shell */
  .app { padding-top: 110px; }
  .content { padding: 12px; }

  /* Hero banner stacks vertically */
  .hero-banner {
    flex-direction: column; text-align: center; padding: 24px 16px; gap: 16px;
  }
  .hero-text h1 { font-size: 24px; }
  .hero-text p { font-size: 13px; }
  .hero-photo { order: -1; }
  .hero-img { width: 100%; height: 160px; border-radius: 8px; }
  .hero-stat { display: flex; align-items: center; gap: 12px; }
  .countdown { font-size: 36px; }
  .countdown-label { text-align: left; }

  /* Card grid — single column */
  .card-grid { grid-template-columns: 1fr; gap: 12px; }

  /* Stat cards */
  .stat-value { font-size: 28px; }

  /* Race timeline — tighter */
  .race-entry { gap: 8px; }
  .race-date { width: 48px; font-size: 11px; }
  .race-bar { height: 24px; font-size: 11px; padding: 0 8px; }
  .race-place { width: 55px; font-size: 11px; }

  /* Splits — single column */
  .splits-grid { grid-template-columns: 1fr; }
  .split-target { font-size: 22px; }

  /* Rivals */
  .rival { padding: 10px 12px; gap: 10px; }
  .rival-name { font-size: 13px; }

  /* Photos */
  .feature-photo { max-height: 220px; }

  /* Motivational */
  .motivational { padding: 20px 12px; font-size: 14px; }

  /* Cards */
  .card { padding: 16px; margin-bottom: 12px; }
  .card-title { font-size: 15px; }
}

/* Small phones */
@media (max-width: 400px) {
  .brand { font-size: 14px; }
  .topnav-link { padding: 4px 10px; font-size: 12px; }
  .hero-text h1 { font-size: 20px; }
  .stat-value { font-size: 24px; }
  .countdown { font-size: 28px; }
}
