:root {
  --bg-primary: #0a0a0a;
  --bg-secondary: #141414;
  --bg-card: #1a1a1a;
  --border: #2a2a2a;
  --text-primary: #ffffff;
  --text-secondary: #a0a0a0;
  --text-muted: #666666;
  --accent: #3b82f6;
  --success: #22c55e;
  --warning: #f59e0b;
  --orange: #f97316;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
}

.container {
  max-width: 600px;
  margin: 0 auto;
  padding: 16px;
}

/* Loading */
.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  gap: 16px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Error */
.error-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  gap: 12px;
  text-align: center;
}

.error-container h2 {
  color: #ef4444;
}

/* Hidden utility */
.hidden {
  display: none !important;
}

/* Header */
.header {
  text-align: center;
  margin-bottom: 24px;
}

.header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 0.875rem;
}

/* Section Title */
.section-title {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.trophy {
  font-size: 1.25rem;
}

/* Score Section */
.score-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  margin-bottom: 24px;
}

.score-display {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.team-score {
  flex: 1;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.team-name {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.team-name.winner {
  color: var(--success);
}

.score {
  font-family: 'JetBrains Mono', monospace;
  font-size: 3rem;
  font-weight: 700;
}

.score.winner {
  color: var(--success);
}

.winner-badge-container {
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 8px;
}

.winner-badge {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--success);
  background: rgba(34, 197, 94, 0.1);
  padding: 4px 12px;
  border-radius: 20px;
}

.score-divider {
  font-size: 2rem;
  color: var(--text-muted);
  padding: 0 16px;
}

/* Tabs */
.tabs {
  display: flex;
  background: var(--bg-secondary);
  border-radius: 8px;
  padding: 4px;
  margin-bottom: 24px;
  gap: 4px;
}

.tab {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  padding: 10px 16px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.tab:hover {
  color: var(--text-primary);
}

.tab.active {
  background: var(--bg-card);
  color: var(--text-primary);
}

/* Players List */
.players-section {
  margin-bottom: 24px;
}

.players-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.player-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.player-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  cursor: pointer;
}

.player-header:hover {
  background: var(--bg-secondary);
}

.player-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.player-rank {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  font-weight: 600;
  background: var(--bg-secondary);
  color: var(--text-secondary);
}

.player-rank.gold { background: #eab308; color: white; }
.player-rank.silver { background: #9ca3af; color: white; }
.player-rank.bronze { background: #d97706; color: white; }

.player-name {
  font-weight: 600;
  font-size: 1rem;
}

.player-points {
  display: flex;
  align-items: center;
  gap: 8px;
}

.points-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
}

.points-label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.expand-icon {
  color: var(--text-muted);
  font-size: 1rem;
  transition: transform 0.2s;
}

.player-card.expanded .expand-icon {
  transform: rotate(180deg);
}

.player-details {
  display: none;
  padding: 0 16px 16px;
  border-top: 1px solid var(--border);
}

.player-card.expanded .player-details {
  display: block;
}

.stats-section-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  margin: 16px 0 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stats-row {
  display: flex;
  justify-content: space-around;
  gap: 8px;
}

.stat-box {
  background: var(--bg-secondary);
  border-radius: 8px;
  padding: 12px;
  text-align: center;
  min-width: 70px;
}

.stat-label {
  font-size: 0.625rem;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 4px;
}

.stat-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1rem;
  font-weight: 600;
}

.stat-percent {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  color: var(--accent);
}

.mini-stat-box {
  background: var(--bg-secondary);
  border-radius: 8px;
  padding: 12px 16px;
  text-align: center;
  min-width: 50px;
}

/* Team Totals */
.team-totals-section {
  margin-bottom: 24px;
}

.team-totals {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.team-total-card {
  background: var(--bg-secondary);
  border-radius: 12px;
  padding: 16px;
}

.team-total-card.winner {
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.3);
}

.team-total-name {
  font-weight: 600;
  font-size: 1.125rem;
  text-align: center;
  margin-bottom: 16px;
}

.team-total-name.winner {
  color: var(--success);
}

.team-stats-grid {
  display: flex;
  justify-content: space-around;
  margin-bottom: 12px;
}

.team-stat {
  text-align: center;
}

.team-stat-label {
  font-size: 0.625rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.team-stat-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.875rem;
  font-weight: 600;
}

.team-stat-percent {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  color: var(--accent);
}

.team-other-stats {
  display: flex;
  justify-content: space-around;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* Footer */
.footer {
  text-align: center;
  padding: 24px 0;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.footer strong {
  color: var(--accent);
}

/* Chart Section */
.chart-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  margin-bottom: 24px;
}

.chart-container {
  width: 100%;
  height: 200px;
  margin-bottom: 16px;
}

.chart-container canvas {
  width: 100% !important;
  height: 100% !important;
}

.chart-legend {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-bottom: 12px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.legend-color {
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

.legend-color.team-a {
  background: var(--accent);
}

.legend-color.team-b {
  background: var(--orange);
}

.chart-summary {
  text-align: center;
  font-size: 0.875rem;
  color: var(--text-secondary);
  padding: 12px;
  background: var(--bg-secondary);
  border-radius: 8px;
}

.chart-summary strong {
  color: var(--text-primary);
}

/* Player Timeline */
.player-timeline {
  margin-top: 16px;
}

.timeline-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.timeline-container {
  position: relative;
  height: 60px;
  background: var(--bg-primary);
  border-radius: 8px;
  overflow: hidden;
}

.timeline-track {
  position: absolute;
  top: 50%;
  left: 16px;
  right: 16px;
  height: 2px;
  background: var(--border);
  transform: translateY(-50%);
}

.timeline-point {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.timeline-dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.625rem;
  font-weight: 700;
  color: white;
}

.timeline-dot.pts-1 { background: #22c55e; }
.timeline-dot.pts-2 { background: var(--accent); }
.timeline-dot.pts-3 { background: #f97316; }

.timeline-time {
  position: absolute;
  top: 28px;
  font-size: 0.625rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.timeline-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* Responsive */
@media (max-width: 400px) {
  .score {
    font-size: 2.5rem;
  }
  
  .tab {
    font-size: 0.75rem;
    padding: 8px 12px;
  }
}

/* View Profile Button */
.view-profile-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
  padding: 12px 16px;
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.3);
  border-radius: 8px;
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.875rem;
  transition: all 0.2s ease;
}

.view-profile-btn:hover {
  background: rgba(59, 130, 246, 0.2);
  border-color: var(--accent);
}

.profile-icon {
  font-size: 1rem;
}

/* Player Profile Page */
.player-profile {
  padding-bottom: 32px;
}

.profile-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 16px;
  margin-bottom: 24px;
}

.profile-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: rgba(59, 130, 246, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
}

.avatar-icon {
  font-size: 2.5rem;
}

.profile-name {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.profile-number {
  font-size: 1.125rem;
  color: var(--text-secondary);
  font-weight: 500;
}

/* Career Stats */
.career-stats {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 24px;
}

.career-stats .section-title {
  margin-bottom: 16px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 12px;
}

.stats-grid:last-child {
  margin-bottom: 0;
}

.career-stat-box {
  text-align: center;
  padding: 12px 8px;
  background: var(--bg-secondary);
  border-radius: 8px;
}

.career-stat-value {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent);
  font-family: 'SF Mono', 'Fira Code', monospace;
}

.career-stat-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* Game History */
.game-history {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}

.game-history .section-title {
  margin-bottom: 16px;
}

.no-games {
  text-align: center;
  color: var(--text-secondary);
  padding: 32px 16px;
}

.game-history-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 12px;
}

.game-history-card:last-child {
  margin-bottom: 0;
}

.game-history-card.win {
  border-left: 3px solid var(--success);
}

.game-history-card.loss {
  border-left: 3px solid #ef4444;
}

.game-history-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.game-result {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.75rem;
}

.game-result.win {
  background: rgba(34, 197, 94, 0.2);
  color: var(--success);
}

.game-result.loss {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
}

.game-teams {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}

.team-name {
  font-weight: 600;
}

.vs {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.opponent-name {
  color: var(--text-secondary);
}

.game-score {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-weight: 700;
  font-size: 1rem;
}

.game-history-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.game-stat {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.game-stat strong {
  color: var(--text-primary);
  font-family: 'SF Mono', 'Fira Code', monospace;
}

.game-date {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.view-game-link {
  display: block;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  color: var(--accent);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
}

.view-game-link:hover {
  text-decoration: underline;
}

/* Responsive adjustments for player profile */
@media (max-width: 400px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .game-history-header {
    flex-wrap: wrap;
  }
  
  .game-score {
    margin-left: auto;
  }
}

/* ============================================================
   Timeline Player
   ============================================================ */

.timeline-player {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
  padding: 10px 12px;
  background: var(--bg-secondary);
  border-radius: 10px;
}

.play-pause-btn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 0.875rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.1s;
  user-select: none;
}

.play-pause-btn:hover {
  background: #2563eb;
}

.play-pause-btn:active {
  transform: scale(0.93);
}

.timeline-slider-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
}

#timeline-range {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  outline: none;
  cursor: pointer;
  margin: 0;
  padding: 0;
}

#timeline-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  margin-top: -5px; /* centres 14px thumb on 4px track: (14-4)/2 = 5 */
  box-shadow: 0 0 0 2px rgba(59,130,246,0.3);
  transition: box-shadow 0.15s;
}

#timeline-range::-webkit-slider-thumb:hover {
  box-shadow: 0 0 0 4px rgba(59,130,246,0.4);
}

#timeline-range::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
}

#timeline-range::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: var(--border);
}

#timeline-range::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: var(--border);
}

.timeline-time-display {
  flex-shrink: 0;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 72px;
  text-align: right;
}

/* Timeline live score */
.timeline-score {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 12px;
  padding: 10px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.timeline-score-team {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  gap: 2px;
}

.timeline-score-name {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}

.timeline-score-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.1;
}

.timeline-score-value.team-a { color: var(--accent); }
.timeline-score-value.team-b { color: var(--orange); }

.timeline-score-divider {
  font-size: 1.25rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* ============================================================
   Event Feed
   ============================================================ */

.event-feed {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 12px;
  max-height: 320px;
  overflow-y: auto;
  position: relative;
  padding-right: 2px;
  padding-top: 6px
}

.event-feed.paused {
  cursor: pointer;
}

.event-feed-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 44px;
  color: var(--text-muted);
  font-size: 0.8125rem;
  font-style: italic;
}

.event-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 12px;
  background: var(--bg-card);
  border-radius: 8px;
  border-left: 3px solid var(--border);
  font-size: 0.8125rem;
  color: var(--text-secondary);
  transition: opacity 0.2s;
}

.event-row.newest {
  background: #252525;
  color: var(--text-primary);
  font-weight: 600;
}

/* Selected row in paused mode */
.event-row.selected {
  background: #252525;
  color: var(--text-primary);
  border-left-width: 5px;
  transform: translateX(-3px);
  box-shadow: -3px 4px 14px -2px currentColor;
  z-index: 2;
  position: relative;
  margin-bottom: 6px;
}

/* Pop animation on click */
@keyframes feedRowPop {
  0%   { transform: translateX(-3px) scale(1); }
  35%  { transform: translateX(-5px) scale(1.045); }
  70%  { transform: translateX(-3px) scale(0.985); }
  100% { transform: translateX(-3px) scale(1); }
}

.event-row.selected.pop {
  animation: feedRowPop 0.55s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.event-text--selected {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text-primary);
}

.event-pts {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.6875rem;
  color: var(--text-muted);
  white-space: nowrap;
  margin-left: auto;
  flex-shrink: 0;
}

.event-row.selected .event-pts {
  font-weight: 700;
  color: var(--text-primary);
}

/* Crucial-moment highlight variants */
.event-row.highlight-tie        { background: rgba(244,163,0,0.10); }
.event-row.highlight-comeback   { background: rgba(168,85,247,0.10); }
.event-row.highlight-leadChange { background: rgba(132,204,22,0.10); }
.event-row.highlight-bigRun     { background: rgba(229,57,34,0.10); }
.event-row.highlight-runStopper { background: rgba(16,185,129,0.10); }

/* Hot / Cold streak texture backgrounds */
.event-row.hot-streak,
.event-row.cold-streak {
  position: relative;
}

.event-row.hot-streak {
  border-left-color: #f97316 !important;
  box-shadow: inset 0 0 0 1px rgba(249,115,22,0.25);
}

.event-row.cold-streak {
  border-left-color: #38bdf8 !important;
  box-shadow: inset 0 0 0 1px rgba(56,189,248,0.25);
}

.event-row.hot-streak::before,
.event-row.cold-streak::before {
  content: '';
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  opacity: 0.15;
  z-index: 0;
  pointer-events: none;
  border-radius: 8px;
}

.event-row.hot-streak::before  { background-image: url('assets/firetexture.jpg'); }
.event-row.cold-streak::before { background-image: url('assets/icetexture.jpg'); }

/* Ensure row content sits above the texture overlay */
.event-row.hot-streak > *,
.event-row.cold-streak > * {
  position: relative;
  z-index: 1;
}

.event-row-main {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.event-badge-row {
  padding-left: 42px; /* align under the event text (time + dot widths) */
  overflow: hidden;
}

.event-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 0.6875rem;
  font-weight: 700;
  line-height: 1.4;
  white-space: normal;
  word-break: break-word;
  max-width: 100%;
}

.event-badge--tie        { background: rgba(244,163,0,0.25);    color: #F4A300; }
.event-badge--comeback   { background: rgba(168,85,247,0.25);   color: #a855f7; }
.event-badge--leadChange { background: rgba(132,204,22,0.25);   color: #84cc16; }
.event-badge--bigRun     { background: rgba(229,57,34,0.25);    color: #E53922; }
.event-badge--runStopper { background: rgba(16,185,129,0.25);   color: #10b981; }
.event-badge--hot        { background: rgba(249,115,22,0.22);   color: #fb923c; letter-spacing: 0.02em; }
.event-badge--cold       { background: rgba(56,189,248,0.20);   color: #7dd3fc; letter-spacing: 0.02em; }

.event-text--highlight {
  font-weight: 600;
  color: var(--text-primary);
}

.event-time {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.6875rem;
  color: var(--text-muted);
  min-width: 34px;
  flex-shrink: 0;
  padding-top: 1px;
}

.event-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 4px;
}

.event-text {
  flex: 1;
  white-space: normal;
  word-break: break-word;
  line-height: 1.4;
}
