/**
 * Header Styles
 *
 * Covers the sticky game header, team matchup/scores, live dot,
 * MLB live scoreboard strip (R/H/E + bases diamond), and the
 * sport info board (NHL/NBA/NFL stat strip).
 */

/* === Sticky Game Header === */
.game-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  /* Respect iOS notch / Dynamic Island at the top */
  padding: calc(8px + env(safe-area-inset-top, 0px)) calc(12px + env(safe-area-inset-right, 0px)) 6px calc(12px + env(safe-area-inset-left, 0px));
  position: sticky;
  top: 0;
  z-index: 100;
}

/* === Compact single-row header === */
.header-compact {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.back-btn-compact {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.2rem;
  min-width: 36px;
  min-height: 44px;
  padding: 0;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.back-btn-compact:active {
  opacity: 0.5;
}

.team-compact {
  flex-direction: row;
  gap: 4px;
  min-width: auto;
}

.team-compact .team-logo {
  width: 28px;
  height: 28px;
}

.team-compact .team-abbrev {
  font-size: 0.9rem;
}

.header-coins {
  font-size: 0.95rem;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.header-coins .pts-value {
  color: var(--gold);
}

.header-coins.bump { animation: pointsBump 0.4s var(--spring); }

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ai-status-badge {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 3px 8px;
  border-radius: 20px;
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.25), rgba(79, 195, 247, 0.15));
  color: #c084fc;
  border: 1px solid rgba(168, 85, 247, 0.4);
  text-transform: uppercase;
  display: none !important;
}

.back-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.85rem;
  /* Minimum 44px touch target height per Apple HIG */
  min-height: 44px;
  padding: 4px 14px;
  border-radius: 20px;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  transition: transform 0.2s var(--spring-soft), border-color 0.15s ease, color 0.15s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  display: inline-flex;
  align-items: center;
}

.back-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.back-btn:active {
  transform: scale(0.92);
  transition-duration: 0.06s;
}

/* === Team Matchup === */
.game-matchup {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 6px;
}

/* When inside the compact header, the matchup is inline */
.header-compact .score-center {
  text-align: center;
  flex-shrink: 0;
}

.team {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 72px;
}

.team-abbrev {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.team-logo {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: contain;
}

/* MLB logos come from the team-cap-on-light CDN (designed for white backgrounds)
   and are near-invisible on the dark UI — wrap them in a white circle. */
.team-logo[data-sport="mlb"] {
  background: rgba(255, 255, 255, 0.92);
  padding: 5px;
  box-sizing: border-box;
}

.score-center { text-align: center; }

.score-big {
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  transition: transform 0.3s var(--spring);
}

/* Score just changed — brief scale bump */
.score-big.score-changed {
  animation: digitChange 0.4s var(--spring) both;
}

.game-period {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-top: 2px;
}

.live-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  background: var(--red);
  border-radius: 50%;
  margin-right: 4px;
  animation: pulse 1.5s ease-in-out infinite;
}

/* === MLB Live Scoreboard Strip === */
/*
 * Compact R/H/E scoreboard shown inside the sticky header for MLB games only.
 * Layout: [▲ inning + outs dots] [R H E two-row mini-table]
 * Hidden by default; made visible via .visible class set by renderMLBScoreboard().
 */
.mlb-scoreboard {
  display: none;
  align-items: center;
  gap: 14px;
  padding: 6px calc(16px + env(safe-area-inset-right, 0px)) 2px calc(16px + env(safe-area-inset-left, 0px));
  border-top: 1px solid var(--border);
  margin-top: 6px;
}

.mlb-scoreboard.visible {
  display: flex;
}

/* Left column: half-inning arrow + inning number + outs dots */
.mlb-situation {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.mlb-half {
  font-size: 0.75rem;
  color: var(--accent);
  line-height: 1;
}

.mlb-inning {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  min-width: 18px;
  text-align: center;
}

.mlb-outs-row {
  display: flex;
  gap: 4px;
  align-items: center;
  margin-left: 2px;
}

/* Each out indicator dot (empty = no out, filled = out recorded) */
.mlb-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 1.5px solid var(--text-dim);
  background: transparent;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.mlb-dot.filled {
  background: #f97316;
  border-color: #f97316;
}

/* Right column: R / H / E mini-table */
.mlb-rhe-table {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.72rem;
}

.mlb-rhe-header,
.mlb-rhe-row {
  display: grid;
  grid-template-columns: 34px repeat(3, 26px);
  column-gap: 2px;
}

.mlb-rhe-header {
  color: var(--text-dim);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 1px;
}

.mlb-rhe-header span,
.mlb-rhe-row span {
  text-align: right;
}

.mlb-rhe-header span:first-child,
.mlb-rhe-row span:first-child {
  text-align: left;
}

.mlb-rhe-row {
  color: var(--text);
  font-weight: 600;
  line-height: 1.55;
}

/* Team abbreviation cell */
.mlb-abbr {
  color: var(--text-dim);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* Highlight the currently batting team */
.mlb-rhe-row.batting .mlb-abbr {
  color: var(--accent);
}

.mlb-rhe-row.batting {
  color: var(--text);
}

/* === MLB Bases Diamond === */
/*
 * Four rotated squares arranged in a 2×2 grid that, when the grid itself
 * is rotated 45°, form the classic baseball diamond layout:
 *   2nd (top) — 1st (right) — home (bottom) — 3rd (left)
 */
.mlb-bases-diamond {
  display: grid;
  grid-template-columns: 13px 13px;
  grid-template-rows: 13px 13px;
  gap: 2px;
  transform: rotate(45deg);
  margin-left: 8px;
  flex-shrink: 0;
}

/* Order in DOM: 2nd, 3rd, 1st, home — maps to grid positions to form diamond */
.mlb-base-sq {
  width: 13px;
  height: 13px;
  border: 1.5px solid var(--text-dim);
  background: transparent;
  border-radius: 1px;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.mlb-base-sq.occupied {
  background: var(--gold);
  border-color: var(--gold);
}

/* Home plate is always grey — batter's box, not a runnable base */
.mlb-base-sq.mlb-base-home {
  border-color: var(--border);
  background: var(--border);
}

/* === Sport Info Board (NHL / NBA / NFL) === */
/*
 * Compact stat strip inside the sticky header for sport-specific live metrics.
 * Mirrors the MLB scoreboard strip style: dark background, thin top border,
 * horizontally scrollable on small screens.
 * Hidden by default; JS adds .visible when the correct sport is active.
 */
.sport-info-board {
  display: none;
  align-items: center;
  gap: 0;
  padding: 6px calc(16px + env(safe-area-inset-right, 0px)) 4px calc(16px + env(safe-area-inset-left, 0px));
  border-top: 1px solid var(--border);
  margin-top: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none; /* Firefox */
}

.sport-info-board::-webkit-scrollbar { display: none; }

.sport-info-board.visible {
  display: flex;
}

/* Individual stat cell: label on top, away·home values below */
.sib-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
  min-width: 52px;
}

.sib-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-dim);
  line-height: 1;
}

.sib-values {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Middle separator dot between away and home values */
.sib-sep {
  font-size: 0.6rem;
  color: var(--text-dim);
  line-height: 1;
}

/* Thin vertical rule between stat cells */
.sib-divider {
  width: 1px;
  height: 28px;
  background: var(--border);
  flex-shrink: 0;
  margin: 0 8px;
}

/* NFL: situation cell (down & distance) is wider and uses a single-value layout */
.nfl-situation-stat {
  min-width: 72px;
  align-items: flex-start;
}

.nfl-sit-val {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.3;
  white-space: nowrap;
}

/* Fade gradient on right edge to hint at horizontal scroll */
.sport-info-board::after {
  content: '';
  position: sticky;
  right: 0;
  flex-shrink: 0;
  width: 24px;
  min-height: 100%;
  background: linear-gradient(to right, transparent, var(--surface));
  pointer-events: none;
  margin-left: -24px;
}

/* === Responsive: Header === */

/* ── Small phones (≤ 390px) ── */
@media (max-width: 390px) {
  .game-matchup { gap: 10px; }
  .score-big    { font-size: 1.5rem; }
  .team-logo    { width: 32px; height: 32px; }
  .team-abbrev  { font-size: 0.95rem; }
  .team         { min-width: 56px; }
  .header-compact { gap: 6px; }
  .team-compact .team-logo { width: 24px; height: 24px; }
  .team-compact .team-abbrev { font-size: 0.8rem; }
  .header-coins { font-size: 0.85rem; }
}

/* ── Landscape on small phones (height ≤ 430px) ── */
@media (max-height: 430px) and (orientation: landscape) {
  .game-header {
    padding-top: calc(6px + env(safe-area-inset-top, 0px));
    padding-bottom: 6px;
  }
  .game-matchup { margin-top: 4px; }
  .team-logo    { width: 28px; height: 28px; }
  .score-big    { font-size: 1.3rem; }
}
