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

/* Visible keyboard focus (mouse clicks don't trigger :focus-visible) */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
:focus:not(:focus-visible) { outline: none; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3148;
  --accent: #4f8ef7;
  --text: #e8eaf0;
  --muted: #7a7f99;
  --win: #4caf79;
  --loss: #e05c5c;
  --save: #4f8ef7;
  --live: #3fb950;
  --warn: #e0a23a;
  --scrim: rgba(0,0,0,0.75);
  --radius: 10px;
}

/* Light theme — follows the OS / browser setting */
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --surface2: #eceef2;
    --border: #d7dbe3;
    --accent: #2563eb;
    --text: #1a1d27;
    --muted: #5b6275;
    --win: #1f8a4c;
    --loss: #c43b3b;
    --save: #2563eb;
    --live: #1a7f37;
    --warn: #a96a14;
    --scrim: rgba(15,17,23,0.45);
  }
}

body {
  background: var(--bg);
  color: var(--text);
  color-scheme: light dark;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}

.app {
  max-width: 1080px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}

header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 20px;
  letter-spacing: -0.3px;
}

/* ── Calendar (weekly strip) ── */
.calendar-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 10px;
  margin: 0 auto 20px;
  max-width: 460px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.week-arrow {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 0.15s;
  flex-shrink: 0;
}
.week-arrow:hover { background: var(--surface2); }

.week-main { flex: 1; min-width: 0; }

.week-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  padding: 0 2px;
}
#week-label { font-weight: 600; font-size: 0.82rem; }

.today-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--accent);
  font-size: 0.68rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.today-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

.week-strip {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
}

.day-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 4px 0;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  user-select: none;
}
.day-cell:hover { background: var(--surface2); }
.dc-dow {
  font-size: 0.6rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.dc-num { font-size: 0.92rem; font-weight: 600; }
.day-cell.today .dc-num { color: var(--accent); }
.day-cell.today { outline: 1.5px solid var(--accent); }
.day-cell.selected { background: var(--accent); }
.day-cell.selected .dc-dow,
.day-cell.selected .dc-num { color: #fff; }
.day-cell.selected { outline: none; }

/* ── Date heading ── */
.date-heading {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 10px;
}

/* ── Games ── */
.games-panel {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
  align-items: stretch;
}
/* Status/loading/empty messages span the whole grid */
.games-panel > .loading,
.games-panel > .empty,
.games-panel > .error { grid-column: 1 / -1; }

.loading, .empty, .error {
  text-align: center;
  color: var(--muted);
  padding: 40px 0;
  font-size: 0.95rem;
}
.error { color: var(--loss); }

.game-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  display: flex;
  flex-direction: column;
}
.game-card:hover {
  border-color: var(--accent);
  background: var(--surface2);
}

.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.card-top-left {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  flex: 1;
  min-width: 0;
}
.dh-chip {
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--muted);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 1px 7px;
}
.game-inning {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--live);
  letter-spacing: 0.3px;
  font-variant-numeric: tabular-nums;
}
.game-time {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.game-status {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  border-radius: 20px;
  padding: 2px 8px;
}
.status-final   { background: var(--surface2); color: var(--muted); }
.status-live    { background: rgba(63,185,80,0.18); color: var(--live); }
.status-preview { background: var(--surface2); color: var(--muted); }
.status-delayed { background: rgba(224,162,58,0.18); color: var(--warn); }
.status-off     { background: var(--surface2); color: var(--warn); }

.score-table { width: 100%; border-collapse: collapse; }
.score-table td { padding: 1px 0; font-size: 0.9rem; }
.score-table .team-name {
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 0;
}
.score-table colgroup .col-stat { width: 30px; }
.score-table .stat {
  text-align: center;
  font-variant-numeric: tabular-nums;
  min-width: 30px;
  padding-left: 6px;
  padding-right: 6px;
}
.score-table .stat.hdr {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  padding-bottom: 4px;
}
.team-rec {
  color: var(--muted);
  font-size: 0.75rem;
  margin-left: 6px;
  font-variant-numeric: tabular-nums;
}
.fav-star {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0 5px 0 0;
  font-size: 0.95rem;
  line-height: 1;
  color: var(--muted);
}
.team-logo {
  width: 18px;
  height: 18px;
  object-fit: contain;
  vertical-align: -4px;
  margin-right: 6px;
}
.ls-team-col .team-logo { width: 16px; height: 16px; }
.fav-star.on { color: var(--warn); }
.fav-star:hover { color: var(--warn); }
.game-card.has-fav { border-color: var(--warn); }
.game-card.has-fav:hover { border-color: var(--accent); }
.team-link {
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  border-bottom: 1px dotted transparent;
}
.team-link:hover { color: var(--accent); border-bottom-color: var(--accent); }

.score-table tbody .stat { color: var(--muted); }
.score-table tbody .stat.runs { color: var(--text); }
.score-table .winner .team-name,
.score-table .winner .stat.runs { font-weight: 700; color: var(--text); }

.pitchers {
  display: flex;
  gap: 12px;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
  font-size: 0.76rem;
  flex-wrap: wrap;
}
.pitcher-entry { display: flex; gap: 5px; align-items: baseline; }
.pitcher-role { font-weight: 800; font-size: 0.72rem; letter-spacing: 0.3px; }
.role-w { color: var(--win); }
.role-l { color: var(--loss); }
.role-s { color: var(--save); }
.role-current { color: var(--live); }
.role-sp { color: var(--muted); }

.live-detail {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  font-size: 0.76rem;
  color: var(--muted);
}
.bases { flex-shrink: 0; }
.live-count { font-variant-numeric: tabular-nums; }
.last-play {
  margin-top: 4px;
  font-size: 0.74rem;
  color: var(--muted);
  font-style: italic;
}

/* Top performers */
.tp-list { display: flex; flex-direction: column; gap: 6px; }
.tp-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  flex-wrap: wrap;
}
.tp-name { font-weight: 600; font-size: 0.9rem; }
.tp-line { color: var(--muted); font-size: 0.82rem; font-variant-numeric: tabular-nums; }
.pitcher-name { color: var(--muted); }

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--scrim);
  z-index: 100;
  padding: 20px 12px;
  overflow: hidden;
  align-items: flex-start;
  justify-content: center;
}
.modal-overlay.open { display: flex; }

.modal-dialog {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 100%;
  max-width: min(1180px, 96vw);
  min-height: 200px;
  max-height: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

/* Header stays pinned while only the box score body scrolls beneath it, so the
   prev/next arrows are always reachable without scrolling back to the top. */
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  border-radius: 14px 14px 0 0;
  flex-shrink: 0;
  z-index: 1;
}

.modal-title { font-weight: 700; font-size: 1rem; }

.modal-actions { display: flex; align-items: center; gap: 8px; }
.modal-nav {
  background: var(--surface2);
  border: none;
  color: var(--muted);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  padding: 10px 16px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-nav:hover:not(:disabled) { color: var(--text); background: var(--surface2); }
.modal-nav:disabled { opacity: 0.35; cursor: default; }
/* Push the close button clear of the nav arrows */
.modal-actions .modal-close { margin-left: 12px; padding: 6px 10px; }

.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
  border-radius: 6px;
}
.modal-close:hover { color: var(--text); background: var(--surface2); }

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

/* ── Box Score sections ── */
.bs-section-title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
  margin-bottom: 10px;
}

/* Line score */
.ls-scroll { overflow-x: auto; }
.ls-table {
  border-collapse: collapse;
  font-size: 0.85rem;
  white-space: nowrap;
  width: 100%;
}
.ls-table th, .ls-table td { padding: 5px 0; }
.ls-team-col { text-align: left; padding-right: 12px; font-weight: 600; min-width: 80px; }
.ls-cell { text-align: center; min-width: 28px; font-variant-numeric: tabular-nums; color: var(--muted); }
.ls-table thead .ls-cell { color: var(--muted); font-size: 0.75rem; font-weight: 600; }
.ls-divider { border-left: 1px solid var(--border); padding-left: 10px; }
.ls-total { color: var(--text); font-weight: 700; }

/* Batting / pitching tables */
.bs-scroll { overflow-x: auto; }
.bs-table {
  border-collapse: collapse;
  font-size: 0.8rem;
  white-space: nowrap;
  width: 100%;
}
.bs-table th, .bs-table td { padding: 4px 3px; }
.bs-table thead th {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  border-bottom: 1px solid var(--border);
}
.bs-table tbody tr:hover { background: var(--surface2); }
.bs-name-hdr { text-align: left; width: 100%; }
.bs-name { text-align: left; white-space: nowrap; }
.bs-stat { text-align: center; font-variant-numeric: tabular-nums; color: var(--muted); width: 26px; padding-left: 2px; padding-right: 2px; }
.bs-stat.rate { width: 44px; text-align: right; padding-right: 8px; }
.bs-stat.pcount { width: 46px; }
.bs-pos {
  display: inline-block;
  font-size: 0.68rem;
  color: var(--muted);
  min-width: 22px;
  margin-right: 4px;
}
.bs-totals td { border-top: 1px solid var(--border); font-weight: 700; color: var(--text); }
.bs-totals .bs-stat { color: var(--text); }

/* Two-column batting/pitching: side by side on wide screens, stacked on mobile */
.bs-twocol {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
}
@media (min-width: 720px) {
  .bs-twocol { grid-template-columns: 1fr 1fr; }
}
.bs-team { min-width: 0; }

/* Batting order number + position + substitutes */
.bs-order {
  display: inline-block;
  min-width: 14px;
  color: var(--muted);
  font-size: 0.72rem;
  margin-right: 2px;
}
.bs-pos { color: var(--muted); font-size: 0.72rem; }
.bs-name.bs-sub { padding-left: 18px; }
.bs-stat.dim { color: var(--muted); }

/* Notes (BATTING / FIELDING / footnotes / Game Info) */
.bs-notes {
  margin-top: 8px;
  font-size: 0.76rem;
  line-height: 1.5;
  color: var(--muted);
}
.note-title {
  font-weight: 700;
  font-size: 0.7rem;
  letter-spacing: 0.6px;
  color: var(--text);
  margin-bottom: 2px;
}
.note-line { margin-bottom: 1px; }
.note-line b { color: var(--text); font-weight: 600; }

.p-dec { color: var(--accent); font-weight: 700; font-size: 0.78rem; }

/* Clickable player names */
.player-link {
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
  border-bottom: 1px dotted transparent;
}
.player-link:hover { border-bottom-color: var(--accent); }

/* Player season stats modal */
.player-dialog { max-width: min(660px, 96vw); }
.player-overlay { z-index: 200; }

.player-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 8px;
}
.player-photo {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface2);
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.player-head-text { min-width: 0; }
.player-phys {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 4px;
}
.player-bio {
  font-size: 0.9rem;
  color: var(--text);
  font-weight: 600;
  margin-bottom: 4px;
}
.ps-table .ps-split { text-align: left; white-space: nowrap; }
.player-season-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
  margin-bottom: 4px;
}
.player-stat-block { margin-bottom: 4px; }
.ps-title {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text);
  margin: 10px 0 8px;
}
.ps-scroll { overflow-x: auto; }
.ps-table {
  border-collapse: collapse;
  width: 100%;
  white-space: nowrap;
}
.ps-table th, .ps-table td {
  padding: 5px 4px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.ps-table thead th {
  font-size: 0.64rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  border-bottom: 1px solid var(--border);
}
.ps-table tbody td {
  font-size: 0.88rem;
  font-weight: 700;
}
.player-ext-link {
  display: inline-block;
  margin-top: 16px;
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
}
.player-ext-link:hover { text-decoration: underline; }
