/* Dark theme. Raised surfaces are lighter than what they sit on (page < card
   < tile), as in Material and Apple's dark modes; inputs sit below the card.
   Colours used anywhere below are these tokens; reuse them instead of adding
   new ones. Contrast on the tile (WCAG): --fg 12:1, --muted 5.9:1,
   --faint 3.1:1 (icons and other graphics only, not text). */
:root {
  color-scheme: dark;
  --bg: #11141b;
  --card: #1a1e28;
  --tile: #222734;
  --input: #0d1016;
  --fg-strong: #f3f4f6;
  --fg: #e5e7eb;
  --fg-soft: #d1d5db;
  --muted: #9ca3af;
  --faint: #6b7280;
  --line: rgba(255, 255, 255, 0.08);
  --control-border: #3a4152;
  --primary: #818cf8;
  --primary-soft: #a5b4fc;
  --brand-end: #f0abfc;
  --success: #4ade80;
  --danger: #f87171;
  --warning: #fbbf24;
}

/* Users who ask their system for more contrast get stronger lines and text */
@media (prefers-contrast: more) {
  :root {
    --line: rgba(255, 255, 255, 0.22);
    --control-border: #6b7280;
    --muted: #d1d5db;
    --faint: #9ca3af;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}
body {
  margin: 0;
  color: var(--fg);
  /* Light text on dark looks thinner and smaller than dark on light, so the
     base size stays at 14 px and nothing goes below 0.7rem (11 px) */
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 0.875rem;
  line-height: 1.5;
  background: var(--bg);
  min-height: 100vh;
}
a {
  color: var(--primary-soft);
}
h2 {
  margin: 0;
  font: inherit;
}
.page {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 0.9rem 1.25rem 1.25rem;
}

/* Toolbar */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1.2rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--line);
}
.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  margin-left: auto;
}
.control {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.control-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  white-space: nowrap;
}
.form-select {
  font: inherit;
  color: var(--fg);
  background-color: var(--input);
  border: 1px solid var(--control-border);
  border-radius: 0.6rem;
  padding: 0.3rem 0.6rem;
}
.form-select:focus-visible,
.btn-reset:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}
.app-title {
  font-weight: 800;
  letter-spacing: -0.02em;
  font-size: 1.3rem;
  background: linear-gradient(90deg, var(--primary-soft), var(--brand-end));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.app-sub {
  color: var(--muted);
  font-size: 0.82rem;
  margin-left: 0.6rem;
  font-weight: 500;
}
.btn-reset {
  font: inherit;
  font-size: 0.78rem;
  padding: 0.25rem 0.6rem;
  border-radius: 0.5rem;
  cursor: pointer;
  background: var(--tile);
  border: 1px solid var(--control-border);
  color: var(--fg-soft);
}
.btn-reset:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--fg-strong);
}
.btn-reset:disabled {
  color: var(--muted);
  cursor: default;
}
.timing {
  font-size: 0.72rem;
  color: var(--muted);
  min-width: 7rem;
}
.error {
  padding: 0.6rem 0.9rem;
  border-radius: 0.6rem;
  background: color-mix(in srgb, var(--danger) 12%, var(--card));
  border: 1px solid var(--danger);
  color: var(--fg);
}

/* Cards: lighter than the page, so no shadow needed to lift them */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 0.6rem;
}
.card-header {
  border-bottom: 1px solid var(--line);
  font-weight: 700;
  font-size: 0.72rem;
  line-height: 1.2;
  padding: 0.5rem 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.card-body {
  padding: 0.9rem;
}
.games-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.games-header .header-tools {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.games-header .btn-reset {
  text-transform: none;
  letter-spacing: 0;
}
.ratings-note {
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
}

/* What changes */
.summary {
  display: grid;
  grid-template-columns: minmax(0, 19rem) minmax(0, 1fr);
  gap: 0.8rem;
  align-items: start;
}
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}
.stat {
  border-radius: 0.6rem;
  padding: 0.5rem 0.7rem;
  background: var(--tile);
  border: 1px solid var(--line);
}
.stat-value {
  font-size: 1.4rem;
  font-weight: 800;
  line-height: 1.1;
}
.stat-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.stat.picks .stat-value {
  color: var(--primary-soft);
}
.stat.clinched .stat-value {
  color: var(--success);
}
.stat.eliminated .stat-value {
  color: var(--danger);
}
.changes {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.4rem;
}
.change {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.4rem 0.5rem;
  border-radius: 0.5rem;
  background: var(--tile);
  border: 1px solid var(--line);
  border-left: 3px solid var(--faint);
  animation: pop 0.25s ease;
}
.change.clinched {
  border-left-color: var(--success);
  background: color-mix(in srgb, var(--success) 7%, var(--tile));
}
.change.eliminated {
  border-left-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 7%, var(--tile));
}
/* Other changes step back with softer colours, not opacity, so their text
   keeps its contrast */
.change.other .change-team {
  color: var(--fg-soft);
  font-weight: 600;
}
.change-body {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}
.change-team {
  font-weight: 700;
  font-size: 0.85rem;
}
.change-text {
  font-size: 0.75rem;
  color: var(--muted);
}
.change-tag {
  margin-left: auto;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: var(--card);
  color: var(--muted);
}
.change.clinched .change-tag {
  background: color-mix(in srgb, var(--success) 14%, var(--card));
  color: var(--success);
}
.change.eliminated .change-tag {
  background: color-mix(in srgb, var(--danger) 14%, var(--card));
  color: var(--danger);
}
@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(-3px);
  }
  to {
    opacity: 1;
  }
}
.empty {
  color: var(--muted);
  font-size: 0.85rem;
  padding: 1.5rem 0.5rem;
  text-align: center;
}
.summary .empty {
  text-align: left;
  padding: 0.6rem 0.2rem;
}

/* Week tabs */
.week-nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}
.nav-pills {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
  min-width: 0;
}
.nav-link {
  font: inherit;
  font-size: 0.8rem;
  /* Numbers only: the same width for 1 and 18 */
  min-width: 2.2rem;
  padding: 0.25rem 0.4rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  background: none;
  border: 1px solid transparent;
  border-radius: 999px;
  cursor: pointer;
}
.nav-link:hover {
  color: var(--fg);
  background: var(--tile);
}
.nav-link.active {
  background: var(--primary);
  color: var(--bg);
  font-weight: 600;
}
/* The week the season is in, also when another week is shown */
.nav-link.current {
  border-color: var(--primary);
  color: var(--primary-soft);
  font-weight: 600;
}
.nav-link.current.active {
  color: var(--bg);
}
.nav-link:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

/* Games: fill the first column top to bottom, then the second; --rows is
   set per week */
.games {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
  grid-template-rows: repeat(var(--rows), auto);
  grid-auto-flow: column;
}
.game {
  background: var(--tile);
  border: 1px solid var(--line);
  border-radius: 0.7rem;
  padding: 0.45rem 0.55rem 0.5rem;
  transition: border-color 0.15s;
}
.game:hover {
  border-color: var(--control-border);
}
/* A pick that differs from the real result (or an open game picked) */
.game.changed {
  border-color: color-mix(in srgb, var(--primary) 60%, var(--tile));
}
.game-meta {
  font-size: 0.7rem;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.3rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.options {
  display: grid;
  grid-template-columns: 1fr auto 1fr auto;
  gap: 0.3rem;
}
.opt {
  position: relative;
  display: block;
}
/* Hidden but focusable, so the pickers work with the keyboard */
.opt input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}
.opt input:focus-visible + .choice {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}
.choice {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  height: 2.4rem;
  padding: 0 0.5rem;
  border-radius: 0.5rem;
  cursor: pointer;
  background: var(--card);
  border: 1px solid var(--control-border);
  color: var(--fg-soft);
  transition:
    background-color 0.12s ease,
    border-color 0.12s ease;
  user-select: none;
}
.choice:hover {
  border-color: var(--faint);
}
.team-choice {
  justify-content: flex-start;
}
.choice-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}
.choice .abbr {
  font-weight: 700;
  font-size: 0.85rem;
}
.choice .rec {
  font-size: 0.7rem;
  color: var(--muted);
  white-space: nowrap;
}
.choice .prob {
  margin-left: auto;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.choice .prob.fav {
  color: var(--primary-soft);
  font-weight: 800;
}
.opt input:checked + .team-choice .prob {
  color: var(--fg-strong);
}
.tie-choice,
.clear-choice {
  font-size: 0.72rem;
  font-weight: 700;
  min-width: 2.6rem;
  color: var(--muted);
}
.clear-choice {
  min-width: 2rem;
  font-size: 0.9rem;
}
/* --tc is the team's accent (teamAccent()): at least 3:1 on the tile, so the
   border alone marks the pick even for teams whose main colour is black */
.opt input:checked + .team-choice {
  background: color-mix(in srgb, var(--tc) 30%, var(--tile));
  border-color: var(--tc);
  color: var(--fg-strong);
}
.opt input:checked + .team-choice .rec {
  color: var(--fg-soft);
}
.opt input:checked + .tie-choice {
  background: color-mix(in srgb, var(--warning) 16%, var(--tile));
  border-color: var(--warning);
  color: var(--warning);
}
/* "Open" is the default, so its chosen state recedes */
.opt input:checked + .clear-choice {
  background: transparent;
  border-color: var(--line);
  color: var(--faint);
}
.final-tag {
  font-weight: 700;
  color: var(--fg-soft);
}
.choice .score {
  margin-left: auto;
  font-size: 0.95rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
/* Open games have an empty score slot that live scores fill */
.choice .score:empty {
  display: none;
}
/* Pre-game probabilities say little once the game is on */
.game.live .prob {
  display: none;
}
.game.live {
  border-color: color-mix(in srgb, var(--danger) 45%, var(--tile));
}
.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-right: 0.5rem;
  color: var(--danger);
  font-weight: 800;
}
/* Blinks between the red and a red faded into the tile */
.live-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--danger);
  animation: live-blink 1.2s ease-in-out infinite;
}
@keyframes live-blink {
  50% {
    background: color-mix(in srgb, var(--danger) 20%, var(--tile));
  }
}
@media (prefers-reduced-motion: reduce) {
  .live-dot {
    animation: none;
  }
}
.game.live .clock {
  color: var(--fg-soft);
  font-weight: 700;
}
/* The leader's score is underlined in its team colour, apart from the pick
   (border and background) */
.choice .score.lead {
  color: var(--fg-strong);
  text-decoration: underline 3px var(--tc);
  text-underline-offset: 4px;
}
/* A picked tile is already in the team colour */
.opt input:checked + .team-choice .score.lead {
  text-decoration-color: var(--fg-strong);
}
.choice .score.trail {
  color: var(--muted);
}
.logo {
  object-fit: contain;
}
.logo-fallback {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
}

/* Standings */
.conferences {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.5rem;
}
.conf-title {
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin: 0 0 0.3rem 0.2rem;
}
.div-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 0.6rem;
  font-size: 0.8rem;
  color: var(--fg-soft);
  table-layout: fixed;
}
.div-table th,
.div-table td {
  padding: 5px 6px;
  border-bottom: 1px solid var(--line);
  text-align: center;
}
.div-table th {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  border-bottom-color: var(--control-border);
}
.div-table th:first-child,
.div-table td:first-child {
  text-align: left;
  width: 34%;
}
/* W-L-T: wide enough for "10-6-1" on one line */
.div-table th:nth-child(2),
.div-table td:nth-child(2) {
  width: 4.2rem;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.div-table .conf-rank {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.tiebreak {
  text-decoration: underline dotted var(--muted);
  text-underline-offset: 3px;
  cursor: help;
}
.team-cell {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-weight: 600;
}
.status-icon {
  display: inline-flex;
  border-radius: 999px;
  line-height: 0;
}
.status-icon svg {
  width: 1.05em;
  height: 1.05em;
  fill: currentColor;
}
.status-icon.clinched {
  color: var(--success);
}
.status-icon.eliminated {
  color: var(--danger);
}
.status-icon.alive {
  color: var(--faint);
}
.status-icon.undecided {
  color: var(--warning);
}
.status-icon.changed {
  box-shadow:
    0 0 0 2px var(--card),
    0 0 0 3.5px var(--primary-soft);
}
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.9rem;
  font-size: 0.75rem;
  color: var(--muted);
  align-items: center;
}
.legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}
.footer {
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
}

/* Phones (iPhone SE/mini is 375 px wide): one column throughout, so nothing
   overflows and the browser doesn't zoom the whole page out */
@media (max-width: 640px) {
  .page {
    gap: 0.75rem;
    padding: 0.6rem 0.6rem 1rem;
  }
  .toolbar {
    gap: 0.5rem;
  }
  .app-sub {
    display: block;
    margin-left: 0;
  }
  .controls {
    margin-left: 0;
    width: 100%;
    gap: 0.5rem 0.75rem;
  }
  /* Below 16 px iOS Safari zooms in when a select gets focus */
  .form-select {
    font-size: 16px;
  }
  .timing {
    min-width: 0;
  }
  .card-body {
    padding: 0.6rem;
  }
  .games-header {
    flex-wrap: wrap;
    row-gap: 0.4rem;
  }
  .games-header .header-tools {
    margin-left: 0;
    flex-wrap: wrap;
  }
  .summary {
    grid-template-columns: minmax(0, 1fr);
  }
  .changes {
    grid-template-columns: minmax(0, 1fr);
  }
  /* 17 week tabs early in the season would take several rows */
  .nav-pills {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    margin-right: -0.6rem;
    padding-right: 0.6rem;
  }
  .nav-link {
    flex: none;
    padding: 0.4rem 0.8rem;
  }
  .games {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: none;
    grid-auto-flow: row;
  }
  /* Finger-sized targets */
  .choice {
    height: 2.75rem;
    -webkit-tap-highlight-color: transparent;
  }
  .btn-reset {
    padding: 0.4rem 0.7rem;
  }
  .conferences {
    grid-template-columns: minmax(0, 1fr);
    gap: 0.75rem;
  }
  .div-table th,
  .div-table td {
    padding: 5px 3px;
  }
  .div-table th {
    white-space: nowrap;
    letter-spacing: 0.02em;
  }
  /* Logo and abbreviation need less than the 30% they had; W-L-T gets it */
  .div-table th:first-child,
  .div-table td:first-child {
    width: 23%;
  }
}
