:root {
  --bg-primary: #f5f7fa;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-hover: #eef1f6;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --accent: #475569;
  --accent-light: #64748b;
  --green: #059669;
  --red: #dc2626;
  --yellow: #d97706;
  --blue: #2563eb;
  --border: #e2e8f0;
}

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

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
}

header {
  background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 50%, #cbd5e1 100%);
  padding: 0.75rem 2rem;
  text-align: center;
  border-bottom: 2px solid #94a3b8;
  position: relative;
  overflow: hidden;
}

header::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23475569' fill-opacity='0.06'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

header h1 {
  font-size: 1.9rem;
  font-weight: 800;
  background: linear-gradient(90deg, #1e293b, #334155, #475569);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  position: relative;
}

header p {
  color: var(--text-secondary);
  margin-top: 0.35rem;
  font-size: 0.85rem;
  position: relative;
}

.dashboard {
  max-width: 80%;
  margin: 0 auto;
  padding: 0.75rem 2rem;
  display: grid;
  gap: 0.75rem;
}

.nav-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.chart-dropdown {
  display: none;
}

.nav-tabs {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.season-dropdown {
  position: relative;
}

.season-dropdown-btn {
  padding: 0.4rem 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: 0.5rem;
  border: 1px solid var(--accent);
  background: rgba(71, 85, 105, 0.08);
  color: var(--text-primary);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
}

.season-dropdown-btn:hover {
  background: rgba(71, 85, 105, 0.15);
}

.season-dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 4px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  z-index: 100;
  min-width: 100%;
  overflow: hidden;
}

.season-dropdown-menu.open {
  display: block;
}

.season-dropdown-item {
  padding: 0.45rem 1rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.season-dropdown-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.season-dropdown-item.selected {
  background: rgba(71, 85, 105, 0.12);
  color: var(--accent);
  font-weight: 600;
}

.nav-tab {
  padding: 0.4rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 0.95rem;
  font-weight: 500;
}

.nav-tab:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-tab.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  box-shadow: 0 0 16px rgba(71, 85, 105, 0.25);
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 0.75rem 1rem;
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.card-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
}

.card-subtitle {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.1rem;
}

.controls {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

select, button {
  padding: 0.35rem 0.75rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  color: var(--text-primary);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}

select:hover, button:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
}

.viz-section { display: none; }
.viz-section.active { display: block; }

.tooltip {
  position: fixed;
  background: var(--bg-secondary);
  border: 1px solid var(--accent);
  border-radius: 0.5rem;
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  color: var(--text-primary);
  pointer-events: none;
  z-index: 1000;
  box-shadow: 0 8px 32px rgba(0,0,0,0.12);
  max-width: 280px;
  opacity: 0;
  transition: opacity 0.15s;
}

.tooltip .team-name {
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 0.4rem;
  color: var(--accent-light);
}

.tooltip .stat-row {
  display: flex;
  justify-content: space-between;
  gap: 1.5rem;
  padding: 0.15rem 0;
}

.tooltip .stat-label { color: var(--text-secondary); }
.tooltip .stat-value { font-weight: 600; }

svg text { font-family: 'Segoe UI', system-ui, sans-serif; }

.bar-label { fill: var(--text-secondary); font-size: 12px; }
.axis text { fill: var(--text-secondary); font-size: 11px; }
.axis line, .axis path { stroke: var(--border); }
.grid line { stroke: var(--border); stroke-opacity: 0.3; }
.grid path { stroke: var(--border); }

.legend {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 0.5rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: opacity 0.2s;
}

.legend-item:hover { opacity: 0.8; }

.legend-color {
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

.team-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-bottom: 0.5rem;
  max-width: 60%;
  margin-left: auto;
  margin-right: auto;
  justify-content: center;
}

.team-chip {
  padding: 0.35rem 0.75rem;
  border-radius: 2rem;
  font-size: 0.75rem;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.2s;
  background: var(--bg-secondary);
  color: var(--text-secondary);
}

.team-chip.selected {
  border-color: var(--accent);
  background: rgba(71, 85, 105, 0.12);
  color: var(--text-primary);
}

.team-chip:hover { border-color: var(--accent-light); }


.bump-line-thin {
  fill: none;
  stroke-width: 1.5px;
  transition: stroke 0.3s, stroke-width 0.3s;
}
.bump-line-thin.selected { stroke-width: 3px; }

.bump-line-fat {
  fill: none;
  stroke: gray;
  stroke-width: 15px;
  stroke-opacity: 0;
  cursor: pointer;
}

.bump-team-text {
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: fill 0.3s;
}

.bump-rank-dot {
  cursor: pointer;
  transition: fill 0.3s;
}

.bump-rank-num {
  font-size: 10px;
  font-weight: 700;
  pointer-events: none;
}

.bump-match-dot {
  transition: r 0.15s, stroke-width 0.15s;
  pointer-events: none;
}

.loading {
  text-align: center;
  padding: 3rem;
  color: var(--text-secondary);
  font-size: 1.1rem;
}

/* Tablet */
@media (max-width: 1024px) {
  header { padding: 1.5rem 1rem; }
  header h1 { font-size: 2rem; }
  header p { font-size: 0.95rem; }
  .dashboard { max-width: 100%; padding: 1rem; gap: 1rem; }
  .card { padding: 1rem; }
  .card-title { font-size: 1.1rem; }
  .card-header { flex-direction: column; align-items: flex-start; }
  .controls { width: 100%; }
  .controls select, .controls button { flex: 1; min-width: 0; font-size: 0.8rem; padding: 0.4rem 0.6rem; }
  .nav-tab { padding: 0.6rem 1rem; font-size: 0.85rem; }
  .season-dropdown-btn { font-size: 0.8rem; padding: 0.4rem 0.6rem; }
  .team-selector { max-width: 80%; }
}

/* Mobile */
@media (max-width: 640px) {
  header { padding: 1rem 0.75rem; }
  header h1 { font-size: 1.4rem; }
  header p { font-size: 0.8rem; }
  .dashboard { padding: 0.5rem; gap: 0.75rem; }
  .card { padding: 0.75rem; border-radius: 0.75rem; }
  .card-title { font-size: 1rem; }
  .card-subtitle { font-size: 0.75rem; }
  .nav-tabs { display: none; }
  .chart-dropdown { display: block; font-size: 0.75rem; padding: 0.3rem 0.5rem; border-radius: 0.5rem; border: 1px solid var(--accent); background: rgba(71, 85, 105, 0.08); color: var(--text-primary); font-weight: 600; cursor: pointer; }
  .season-dropdown-btn { font-size: 0.75rem; padding: 0.3rem 0.5rem; }
  .controls { flex-direction: column; }
  .controls select, .controls button { width: 100%; font-size: 0.8rem; }
  .controls .sort-btn { width: auto; font-size: 0.65rem; padding: 0.3rem 0.45rem; }
  .card-header .controls:has(.sort-btn) { flex-direction: row; flex-wrap: nowrap; }
  .team-selector { max-width: 100%; }
  .team-chip { padding: 0.25rem 0.5rem; font-size: 0.65rem; }
  .tooltip { max-width: 220px; font-size: 0.75rem; padding: 0.5rem 0.75rem; }
  .tooltip .team-name { font-size: 0.85rem; }
  .bump-line-thin { stroke-width: 2px; }
  .bump-line-thin.selected { stroke-width: 4px; }
  .bump-line-fat { stroke-width: 20px; }
  .bump-team-text { font-size: 10px; }
  .bump-rank-num { font-size: 8px; }
  .legend { gap: 0.75rem; }
  .legend-item { font-size: 0.75rem; }
}

/* Landscape mobile */
@media (max-height: 500px) and (orientation: landscape) {
  header { padding: 0.5rem 0.75rem; }
  header h1 { font-size: 1.2rem; }
  header p { font-size: 0.7rem; margin-top: 0.1rem; }
  .dashboard { padding: 0.5rem; gap: 0.5rem; }
  .card { padding: 0.5rem; }
  .card-title { font-size: 0.9rem; }
  .card-subtitle { font-size: 0.7rem; }
  .card-header { gap: 0.25rem; }
  .nav-bar { margin-bottom: 0.25rem; }
  .nav-tabs { display: none; }
  .chart-dropdown { display: block; font-size: 0.75rem; padding: 0.3rem 0.5rem; border-radius: 0.5rem; border: 1px solid var(--accent); background: rgba(71, 85, 105, 0.08); color: var(--text-primary); font-weight: 600; cursor: pointer; }
  .season-dropdown-btn { font-size: 0.7rem; padding: 0.25rem 0.4rem; }
  .controls .sort-btn { width: auto; font-size: 0.6rem; padding: 0.2rem 0.4rem; }
  .card-header .controls:has(.sort-btn) { flex-direction: row; flex-wrap: nowrap; }
  .radar-layout { display: flex; flex-direction: row; flex-wrap: wrap; gap: 1.5rem; justify-content: flex-start; align-items: center; }
  .radar-layout .team-selector { flex: 0 0 auto; width: 80px; flex-direction: column; margin: 0; max-width: none; max-height: calc(100vh - 120px); overflow-y: auto; scrollbar-width: none; justify-content: flex-start; align-items: center; border-bottom: none; }
  .radar-layout .team-selector::-webkit-scrollbar { display: none; }
  .radar-layout .team-selector .team-chip { font-size: 0.6rem; padding: 0.2rem 0.4rem; }
  .radar-layout #radar-chart { flex: 1; display: flex; justify-content: center; }
  .radar-layout .legend { flex: 0 0 100%; }
}

/* Disable tap highlight on mobile */
#bump-chart svg, #history-chart svg {
  -webkit-tap-highlight-color: transparent;
}

/* Ensure SVGs and chart containers don't overflow */
#standings-chart, #scatter-chart, #bump-chart, #form-chart, #radar-chart {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

#form-chart {
  display: flex;
  justify-content: center;
}
