:root {
  color-scheme: light dark;
  --border: #d0d0d8;
  --tied: #b45309;
  --muted: #6b7280;
  --withdrawn: #9ca3af;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  max-width: 760px;
  margin: 2rem auto;
  padding: 0 1rem;
  line-height: 1.4;
}

header {
  margin-bottom: 1.5rem;
}

h1 {
  margin-bottom: 0.25rem;
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

.header-controls {
  margin-top: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.view-toggle {
  display: flex;
  gap: 0.5rem;
}

.view-toggle[hidden] {
  display: none;
}

.view-toggle button,
.tournament-value-toggle {
  font: inherit;
  padding: 0.3rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.view-toggle button[aria-pressed="true"],
.tournament-value-toggle[aria-pressed="true"] {
  background: #1f2937;
  color: #f9fafb;
  border-color: transparent;
}

.tournament-value {
  margin-bottom: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.tournament-value[hidden] {
  display: none;
}

.tv-bar {
  position: relative;
}

.tv-track {
  height: 1.4rem;
  background: #e5e7eb;
  border-radius: 999px;
  overflow: hidden;
}

.tv-fill {
  height: 100%;
  width: 0;
  background: #9ca3af;
  transition: width 0.3s ease;
}

.tv-fill.met {
  background: #16a34a;
}

.tv-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.5rem;
  font-size: 0.72rem;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

/* Two-layer label so text stays legible regardless of fill width: a dark base label reads
   over the light-gray track, and a white copy is clip-path'd to exactly the filled fraction
   (driven by --tv-fill-pct, the same percentage the fill width uses) so it only paints over
   the colored fill. */
.tv-label--under {
  color: #1f2937;
  text-shadow: none;
}

.tv-label--over {
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.55);
  clip-path: inset(0 calc(100% - var(--tv-fill-pct, 0%)) 0 0);
}

.tv-text {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.tv-text-line {
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
}

.tv-text-icon {
  width: 1.1em;
  text-align: center;
  flex-shrink: 0;
}

.tv-text-icon.met {
  color: #16a34a;
  font-weight: 700;
}

.division {
  margin-bottom: 2rem;
}

.division h2 {
  border-bottom: 2px solid var(--border);
  padding-bottom: 0.25rem;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  text-align: left;
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--border);
}

th {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #6b7280;
}

td.rank, th.rank {
  width: 3rem;
}

td.points, th.points {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.tied {
  color: var(--tied);
  font-weight: 600;
}

.withdrawn td {
  color: var(--withdrawn);
}

/* Cutline (finalists/contenders boundary) and byeline (tiebreaker-decided cut) separators. */
.line-row td {
  padding: 0.15rem 0.5rem;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: none;
}

.cutline-row td {
  font-size: 0.875rem;
  padding-top: 0.4rem;
  color: #b91c1c;
  /* Paint the separator with a gradient background (not a border) so it shares the byeline's
     rendering path — same behavior under `border-collapse: collapse` if any quirk crops up. */
  border-top: none;
  background-image: linear-gradient(#b91c1c, #b91c1c);
  background-repeat: no-repeat;
  background-position: top;
  background-size: 100% 6px;
}

.byeline-row td {
  font-size: 0.875rem;
  padding-top: 0.4rem;
  color: #b45309;
  /* A CSS `dashed` border renders inconsistently under `border-collapse: collapse`
     (dashes get squeezed to fit each cell edge, so the middle can look solid).
     Paint the dashes with a gradient instead for a uniform dash/gap at any width. */
  border-top: none;
  background-image: repeating-linear-gradient(
    to right,
    #b45309 0,
    #b45309 6px,
    transparent 6px,
    transparent 12px
  );
  background-repeat: no-repeat;
  background-position: top;
  background-size: 100% 6px;
}

/* A higher division's cutline redrawn through this division's top tied block. Distinct violet (vs.
   the division's own red cutline) to signal it belongs to a different, more exclusive division — the
   players above it are still contending upward via a real tiebreaker game. Solid line like a cutline. */
.higher-cutline-row td {
  font-size: 0.875rem;
  padding-top: 0.4rem;
  color: #7c3aed;
  border-top: none;
  background-image: linear-gradient(#7c3aed, #7c3aed);
  background-repeat: no-repeat;
  background-position: top;
  background-size: 100% 6px;
}

/* Scenario icon + expand caret, sitting to the left of a tied player's points. */
.tie-marker {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  margin-right: 0.4rem;
  vertical-align: middle;
}

.tiebreak {
  font-size: 0.85em;
  line-height: 1;
}

/* Scenario-specific colors: green = resolved into seeds, red = a real game is needed, gray = inert tie. */
.tiebreak-seeded {
  color: #15803d;
}

.tiebreak-playoffGame {
  color: #b91c1c;
}

.tiebreak-belowCutline {
  color: #6b7280;
}

/* Rows of a tied group are tappable to reveal the automatic-tiebreaker breakdown below them. */
.tiebreak-row {
  cursor: pointer;
}

.tiebreak-row:hover,
.tiebreak-row.tie-active {
  background: rgba(180, 83, 9, 0.09);
}

.tie-caret {
  display: inline-block;
  color: #9ca3af;
  font-weight: 700;
  transition: transform 0.15s ease;
}

.tiebreak-row[aria-expanded="true"] .tie-caret {
  transform: rotate(90deg);
}

/* The expandable detail panel: one row per tied player with their best-game scores. */
.tie-detail-row td {
  background: rgba(180, 83, 9, 0.06);
  padding: 0.5rem 0.75rem 0.6rem;
  border-bottom: 1px solid var(--border);
}

.tie-detail-heading {
  font-weight: 600;
  color: #b45309;
  font-size: 0.85rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}

/* Scenario label as its own pill next to the heading (avoids an em-dash join), colored per scenario. */
.tie-detail-tag {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  background: rgba(107, 114, 128, 0.15);
  color: #6b7280;
}

.tie-detail-tag-seeded {
  background: rgba(21, 128, 61, 0.15);
  color: #15803d;
}

.tie-detail-tag-playoffGame {
  background: rgba(185, 28, 28, 0.15);
  color: #b91c1c;
}

.tie-detail-tag-belowCutline {
  background: rgba(107, 114, 128, 0.15);
  color: #6b7280;
}

.tie-detail-caption {
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 0.15rem;
}

.tie-detail-list {
  margin-top: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.tie-detail-player {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.6rem;
}

.tie-detail-player.withdrawn .tie-detail-name {
  color: var(--withdrawn);
}

.tie-detail-name {
  font-weight: 600;
  min-width: 6.5rem;
}

.tie-detail-games {
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
}

.tie-game:not(:last-child)::after {
  content: ", ";
  color: var(--muted);
}

.tie-game.decider {
  font-weight: 700;
  color: #b45309;
}

.tie-detail-nodata {
  color: var(--muted);
  font-style: italic;
}

.withdrawn-note {
  font-size: 0.75rem;
  color: var(--withdrawn);
  font-style: italic;
}

details.alternates,
details.bubble-watch,
details.ineligible-restricted {
  margin-top: 0.75rem;
}

details.alternates summary,
details.bubble-watch summary,
details.ineligible-restricted summary {
  cursor: pointer;
  color: #6b7280;
  font-size: 0.9rem;
  font-weight: 500;
}

details.bubble-watch table,
details.ineligible-restricted table {
  margin-top: 0.5rem;
  font-size: 0.9rem;
}

th.higher-div,
td.higher-div,
th.restricted-to,
td.restricted-to {
  width: 6rem;
  text-align: center;
}

.error {
  color: #b91c1c;
}

.manual-refresh {
  font: inherit;
  margin-top: 0.5rem;
  padding: 0.3rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.manual-refresh[hidden] {
  display: none;
}

.manual-refresh:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}
