*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #030712;
  --text: #f8fafc;
  --muted: #94a3b8;
  --border: rgba(255, 255, 255, 0.08);
  --gold: #f59e0b;
  --blue: #3b82f6;
  --positive: #34d399;
  --negative: #fb7185;
}

body {
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.starfield {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  background: linear-gradient(180deg, #020617 0%, #0f172a 35%, #0c1222 70%, #030712 100%);
}

.starfield::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 70% 45% at 15% 10%, rgba(56, 189, 248, 0.07), transparent 55%),
    radial-gradient(ellipse 60% 40% at 85% 20%, rgba(167, 139, 250, 0.06), transparent 50%);
}

.star {
  position: absolute;
  border-radius: 50%;
  background: #fff;
  animation: twinkle ease-in-out infinite;
}

@keyframes twinkle {
  0%, 100% { opacity: 0.25; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.15); }
}

.layout {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 90rem;
  margin: 0 auto;
  padding: 0.75rem;
  min-height: 100vh;
}

@media (min-width: 640px) {
  .layout {
    flex-direction: row;
    padding: 1rem;
    gap: 1.25rem;
  }
}

.sidebar {
  flex-shrink: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

@media (min-width: 640px) {
  .sidebar { width: 14rem; }
}

.banner {
  width: 100%;
  aspect-ratio: 16 / 5;
  border-radius: 0.5rem;
  background: url("/logos/team-sprites.png") center 100% / 100% 200% no-repeat;
}

.subtitle {
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.section-label {
  font-size: 0.625rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #64748b;
  margin-bottom: 0.5rem;
}

.period-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

@media (min-width: 640px) {
  .period-list { flex-direction: column; }
}

.period-btn {
  position: relative;
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  cursor: pointer;
  text-align: left;
}

.period-btn:hover { background: rgba(255,255,255,0.05); color: #e2e8f0; }
.period-btn.active { background: rgba(255,255,255,0.12); color: #fff; }
.period-btn.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 2px;
  height: 1.25rem;
  background: var(--gold);
  border-radius: 1px;
  display: none;
}

@media (min-width: 640px) {
  .period-btn.active::before { display: block; }
  .period-btn { padding-left: 1rem; }
}

.member-group-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.team-logo {
  flex-shrink: 0;
  border-radius: 0.25rem;
  background: url("/logos/team-sprites.png") 0 0 / 200% 200% no-repeat;
}

.team-logo.team-2 {
  background-position: 100% 0;
}

.member-group-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: #e2e8f0;
}

.select-all-btn {
  font-size: 0.625rem;
  color: #64748b;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

.select-all-btn:hover { color: #cbd5e1; }

.member-list { list-style: none; display: flex; flex-direction: column; gap: 0.25rem; }

.member-item label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  border-radius: 0.5rem;
  cursor: pointer;
  border: 1px solid transparent;
}

.member-item label.checked {
  border-color: var(--border);
  background: rgba(255,255,255,0.05);
}

.member-item label.unchecked { opacity: 0.5; }

.member-name {
  flex: 1;
  font-size: 0.75rem;
  color: #cbd5e1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.member-pnl {
  font-size: 0.625rem;
  font-family: ui-monospace, monospace;
  color: #64748b;
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.ranking-panel {
  flex-shrink: 0;
  width: 100%;
}

@media (min-width: 640px) {
  .ranking-panel { width: 14rem; }
}

.card {
  background: rgba(2, 6, 23, 0.6);
  border: 1px solid var(--border);
  border-radius: 1rem;
  backdrop-filter: blur(8px);
  overflow: hidden;
}

.scoreboard {
  background: linear-gradient(180deg, rgba(15,23,42,0.85), rgba(2,6,23,0.92));
}

.scoreboard-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
  padding: 1.25rem 1.5rem;
}

.team-score { display: flex; flex-direction: column; }
.team-score.right { align-items: flex-end; text-align: right; }

.team-score-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.team-score.right .team-score-header { flex-direction: row-reverse; }

.team-name { font-size: 0.875rem; font-weight: 600; color: #e2e8f0; }

.lead-badge {
  font-size: 0.625rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--gold);
}

.pnl-box {
  border-radius: 0.5rem;
  border: 1px solid;
  background: rgba(15, 23, 42, 0.6);
  padding: 0.75rem 1rem;
}

.pnl-box.gold { border-color: rgba(245, 158, 11, 0.3); }
.pnl-box.blue { border-color: rgba(59, 130, 246, 0.3); }

.vs-label {
  font-size: 0.625rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: #64748b;
}

.leader-bar {
  border-top: 1px solid rgba(255,255,255,0.05);
  background: rgba(0,0,0,0.2);
  padding: 0.75rem;
  text-align: center;
  font-size: 0.875rem;
  color: #fef3c7;
}

.teams-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 1024px) {
  .teams-grid { grid-template-columns: 1fr 1fr; }
}

.team-panel.gold { border-color: rgba(245, 158, 11, 0.25); }
.team-panel.blue { border-color: rgba(59, 130, 246, 0.25); }
.team-panel.leading.gold { box-shadow: 0 0 50px -12px rgba(245, 158, 11, 0.25); }
.team-panel.leading.blue { box-shadow: 0 0 50px -12px rgba(59, 130, 246, 0.25); }

.panel-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.panel-header.gold { background: linear-gradient(135deg, rgba(245,158,11,0.1), transparent); }
.panel-header.blue { background: linear-gradient(135deg, rgba(59,130,246,0.1), transparent); }

.panel-title-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.panel-stats {
  margin-top: 0.75rem;
  display: flex;
  gap: 1rem;
  font-size: 0.75rem;
  color: #64748b;
}

.member-rows { padding: 1rem; display: flex; flex-direction: column; gap: 0.5rem; }

.member-row {
  position: relative;
  overflow: hidden;
  border-radius: 0.5rem;
  border: 1px solid rgba(255,255,255,0.05);
  background: rgba(15, 23, 42, 0.5);
}

.member-row-inner {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 0.75rem;
}

.member-bar {
  position: absolute;
  inset: 0 auto 0 0;
  opacity: 0.15;
}

.member-bar.gold { background: linear-gradient(90deg, #f59e0b, transparent); }
.member-bar.blue { background: linear-gradient(90deg, #3b82f6, transparent); }

.rank-badge {
  width: 1.75rem;
  height: 1.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.25rem;
  font-size: 0.625rem;
  font-weight: 700;
  flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.05);
  color: #94a3b8;
}

.rank-badge.top.gold { background: rgba(245,158,11,0.15); color: #fcd34d; border-color: rgba(245,158,11,0.25); }
.rank-badge.top.blue { background: rgba(59,130,246,0.15); color: #93c5fd; border-color: rgba(59,130,246,0.25); }

.pnl {
  font-family: ui-monospace, monospace;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.pnl.sm { font-size: 0.875rem; }
.pnl.lg { font-size: 1.25rem; }
.pnl.hero { font-size: clamp(1.5rem, 4vw, 2.5rem); }
.pnl.positive { color: var(--positive); }
.pnl.negative { color: var(--negative); }
.pnl.neutral { color: #d4d4d8; }

.chart-card { padding: 1rem; }

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  margin-bottom: 1rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
}

.legend-line { width: 1.25rem; height: 2px; border-radius: 1px; }
.legend-line.gold { background: var(--gold); }
.legend-line.blue { background: var(--blue); }

.ranking-list {
  list-style: none;
  max-height: calc(100vh - 8rem);
  overflow-y: auto;
  padding: 0.5rem;
}

.ranking-item {
  border-radius: 0.5rem;
  padding: 0.625rem 0.75rem;
  margin-bottom: 0.25rem;
  border: 1px solid transparent;
}

.ranking-item.top { border-color: var(--border); background: rgba(255,255,255,0.05); }

.ranking-row {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
}

.rank-num {
  width: 1.75rem;
  height: 1.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.375rem;
  font-size: 0.625rem;
  font-weight: 700;
  flex-shrink: 0;
  background: rgba(255,255,255,0.05);
  color: #94a3b8;
}

.rank-num.r1 { background: rgba(251,191,36,0.15); color: #fcd34d; }
.rank-num.r2 { background: rgba(148,163,184,0.15); color: #cbd5e1; }
.rank-num.r3 { background: rgba(251,146,60,0.1); color: #fdba74; }

.error-box {
  border: 1px solid rgba(251, 113, 133, 0.3);
  background: rgba(251, 113, 133, 0.1);
  color: #fecdd3;
  padding: 0.75rem 1rem;
  border-radius: 0.75rem;
  font-size: 0.875rem;
}

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5rem 0;
}

.spinner {
  width: 2rem;
  height: 2rem;
  border: 2px solid #334155;
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.empty { text-align: center; color: #64748b; font-size: 0.875rem; padding: 2rem; }

.center-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.body-row {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  flex: 1;
}

@media (min-width: 640px) {
  .body-row { flex-direction: row; }
}
