:root {
  --bg: #fbf8f0;
  --bg-glow: #fffdf8;
  --ink: #1a2634;
  --muted: #6e7480;
  --line: rgba(26, 38, 52, 0.14);
  --rule: #1a2634;
  --red: #b5232b;
  --serif: 'Besley', 'Clarendon', Georgia, serif;
  --mono: 'Sometype Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);

  /* playoff status */
  --z: #14532d;  /* best record in league */
  --y: #2f8a4c;  /* division */
  --w: #c7891a;  /* wild card */
  --x: #2f6db3;  /* playoff berth */
  --e: #a9a59b;  /* eliminated */
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--mono);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ---------- views ---------- */
.view {
  position: fixed;
  inset: 0;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.7s var(--ease), visibility 0s linear 0.7s;
}
.view.is-active {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.7s var(--ease) 0.05s, visibility 0s;
}

/* ---------- front page ---------- */
#home {
  background: radial-gradient(58% 60% at 50% 46%, var(--bg-glow) 0%, var(--bg) 72%);
}
#stage {
  position: absolute;
  inset: 0;
  outline: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.75s cubic-bezier(0.6, 0, 0.2, 1), opacity 0.6s ease 0.1s;
}
#stage canvas { display: block; }
#stage.is-launching { opacity: 0; }
#stage:focus-visible { box-shadow: inset 0 0 0 2px rgba(181, 35, 43, 0.35); }

body:not(.is-ready) #stage { opacity: 0; }
body.is-ready #stage:not(.is-launching) { animation: ballIn 1.1s var(--ease) backwards; }
@keyframes ballIn {
  from { opacity: 0; transform: translateY(14px) scale(0.96); }
  to   { opacity: 1; transform: none; }
}

/* ---------- standings page ---------- */
#standings {
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--bg);
}
#standings.is-active .bar,
#standings.is-active .content > * { animation: rise 0.8s var(--ease) both; }
#standings.is-active .content > :nth-child(1) { animation-delay: 0.10s; }
#standings.is-active .content > :nth-child(2) { animation-delay: 0.16s; }
#standings.is-active .content > :nth-child(3) { animation-delay: 0.24s; }
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}

/* top bar: wordmark, then the tabs */
.bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 20px 56px;
  padding: 22px 56px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.mark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex: none;
  color: var(--ink);
  text-decoration: none;
  font-family: var(--serif);
  font-weight: 800;
  font-size: 20px;
  letter-spacing: 0.01em;
  text-transform: uppercase;
}
.mark svg { transition: transform 0.6s var(--ease); }
.mark:hover svg { transform: rotate(-200deg); }
.mark:focus-visible { outline: 2px solid var(--ink); outline-offset: 4px; }

.switch { display: flex; flex-wrap: wrap; gap: 4px 28px; }
.switch button {
  border: 0;
  background: none;
  padding: 4px 0;
  cursor: pointer;
  font-family: var(--serif);
  font-weight: 500;
  font-size: 19px;
  text-transform: uppercase;
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: transparent;
  text-decoration-thickness: 1.5px;
  text-underline-offset: 5px;
  white-space: nowrap;
  transition: text-decoration-color 0.25s ease, opacity 0.25s ease;
  opacity: 0.55;
}
.switch button:hover { opacity: 1; }
.switch button.is-on { opacity: 1; text-decoration-color: currentColor; }
.switch button:focus-visible { outline: 2px solid var(--ink); outline-offset: 4px; }

.content {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 64px 56px 88px;
}

.eyebrow {
  margin: 0 0 18px;
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

h1 {
  margin: 0 0 56px;
  font-family: var(--serif);
  font-weight: 800;
  font-size: clamp(44px, 12vw, 104px);
  line-height: 0.95;
  letter-spacing: -0.01em;
  text-transform: uppercase;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
h1.is-swapping { opacity: 0; transform: translateY(6px); }
h1.is-long { font-size: clamp(36px, 9.5vw, 104px); }

/* ---------- tables ---------- */
.divisions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 48px 40px;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.divisions.is-swapping { opacity: 0; transform: translateY(8px); }
.divisions[hidden] { display: none; }

.card {
  animation: rise 0.7s var(--ease) both;
  animation-delay: calc(var(--i) * 70ms);
}
.card-wide { grid-column: 1 / -1; max-width: calc((100% - 40px) * 2 / 3 + 0px); }

.card-head {
  padding-bottom: 12px;
  border-bottom: 2px solid var(--rule);
}
.card-head h2 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 700;
  font-size: 26px;
  line-height: 1;
  text-transform: uppercase;
}

.row {
  position: relative;
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr) 28px 30px 44px 40px 40px;
  align-items: center;
  column-gap: 6px;
  height: 48px;
  padding: 0 10px 0 14px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  border-bottom: 1px solid var(--line);
}
.table-wildcard .row { grid-template-columns: 22px minmax(0, 1fr) 40px 40px 56px 56px 56px 48px; }
.row-head {
  height: 36px;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.row-head span:not(.team-col):not(.rank) { text-align: right; }

/* status bar on the left edge of each row */
.row::before {
  content: '';
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 4px;
  background: var(--s, transparent);
}
.row.is-z { --s: var(--z); }
.row.is-y { --s: var(--y); }
.row.is-w { --s: var(--w); }
.row.is-x { --s: var(--x); }
.row.is-e { --s: var(--e); }
.row.is-z, .row.is-y, .row.is-w, .row.is-x {
  background: color-mix(in srgb, var(--s) 7%, transparent);
}
.row.is-e .team, .row.is-e .num { color: var(--muted); }
.row.is-e .logo { filter: grayscale(1); opacity: 0.7; }

/* the wild-card cut line: teams above it are in */
.row.is-cut { border-bottom: 2px dashed var(--ink); }

.rank { color: var(--muted); font-size: 12px; }
.team {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  font-weight: 500;
  white-space: nowrap;
}
.logo { flex: none; width: 22px; height: 22px; object-fit: contain; }
.nick { overflow: hidden; text-overflow: ellipsis; }
.num { text-align: right; }
.soft { color: var(--muted); }

.tag {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 17px;
  height: 17px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
  color: #fff;
  background: var(--s, var(--ink));
  cursor: help;
}

/* ---------- postseason ---------- */
.bracket {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(0, 1.2fr);
  grid-template-rows: auto repeat(4, minmax(118px, auto));
  gap: 14px 44px;
}
.round-head {
  margin: 0 0 6px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--rule);
  font-family: var(--serif);
  font-weight: 700;
  font-size: 20px;
  line-height: 1;
  text-transform: uppercase;
}

.series {
  position: relative;
  align-self: center;
  animation: rise 0.7s var(--ease) both;
}
.series-meta {
  margin: 0;
  padding: 0 0 8px;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.st {
  display: grid;
  grid-template-columns: 22px 14px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  height: 42px;
  padding: 0 10px;
  border-top: 1px solid var(--line);
  font-size: 14px;
}
.st:last-of-type { border-bottom: 1px solid var(--line); }
.st .seed { font-size: 11px; color: var(--muted); text-align: right; }
.st .nick { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.st .w { font-variant-numeric: tabular-nums; }
.st.is-win { font-weight: 700; background: color-mix(in srgb, var(--ink) 5%, transparent); }
.st.is-out { color: var(--muted); }
.st.is-out .logo { filter: grayscale(1); opacity: 0.6; }

.series.is-ws { padding: 16px; border: 2px solid var(--rule); }
.series.is-ws .st { grid-template-columns: 22px 18px minmax(0, 1fr) auto; height: 48px; font-size: 15px; }
.champ {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 18px 0 0;
  font-family: var(--serif);
  font-weight: 800;
  font-size: 28px;
  line-height: 1;
  text-transform: uppercase;
}
.champ .logo { width: 44px; height: 44px; }
.champ small {
  display: block;
  margin-bottom: 6px;
  font-family: var(--mono);
  font-weight: 400;
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.series.is-tbd {
  display: grid;
  place-items: center;
  min-height: 84px;
  border: 1px dashed var(--line);
}
.series.is-tbd .series-meta { padding: 0; }

.section-head {
  grid-column: 1 / -1;
  margin: 24px 0 -16px;
  font-family: var(--serif);
  font-weight: 800;
  font-size: clamp(30px, 4vw, 44px);
  line-height: 1;
  text-transform: uppercase;
}
.card-sub {
  margin: 10px 0 0;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.table-games .row { grid-template-columns: 26px 54px minmax(0, 1fr) 24px 16px minmax(0, 1fr) 24px; padding: 0 8px; }
.table-games .row::before { display: none; }
.table-games .date { font-size: 12px; }
.table-games .at { text-align: center; color: var(--muted); font-size: 12px; }
.table-games .team { color: var(--muted); }
.table-games .is-win { color: var(--ink); font-weight: 700; }

/* ---------- highlights ---------- */
.hl-nav {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: -16px;
  padding-bottom: 16px;
  border-bottom: 2px solid var(--rule);
}
.hl-nav .btn { min-width: 120px; padding: 10px 16px; font-size: 13px; white-space: nowrap; }
.hl-nav .btn:disabled { visibility: hidden; }
.hl-date {
  margin: 0;
  font-family: var(--serif);
  font-weight: 700;
  font-size: 22px;
  text-align: center;
  text-transform: uppercase;
}

.hl-card {
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--line);
  padding-bottom: 20px;
  animation: rise 0.7s var(--ease) both;
  animation-delay: calc(var(--i) * 60ms);
}
/* a day with a single game (most postseason days) gets one wide feature */
.hl-card.is-feature {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: 40px;
  align-items: start;
}
.hl-card.is-feature .hl-media { margin-bottom: 0; }
.hl-card.is-feature .hl-head { font-size: clamp(24px, 2.4vw, 34px); }
.hl-card.is-feature .hl-blurb { -webkit-line-clamp: 5; }
.hl-media {
  position: relative;
  display: block;
  aspect-ratio: 16 / 9;
  margin-bottom: 16px;
  overflow: hidden;
  background: color-mix(in srgb, var(--ink) 8%, transparent);
}
.hl-media img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 0.6s var(--ease); }
.hl-media:hover img { transform: scale(1.03); }
.hl-play {
  position: absolute;
  left: 0;
  bottom: 0;
  padding: 8px 12px;
  background: var(--ink);
  color: var(--bg);
  font-size: 12px;
  letter-spacing: 0.04em;
}
.hl-label {
  margin: 0 0 8px;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.hl-score { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.hl-team { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); }
.hl-team b { font-weight: 500; }
.hl-team.is-win { color: var(--ink); }
.hl-team.is-win b { font-weight: 700; }
.hl-score .at { color: var(--muted); font-size: 12px; }
.hl-head {
  margin: 14px 0 8px;
  font-family: var(--serif);
  font-weight: 700;
  font-size: 21px;
  line-height: 1.15;
}
.hl-head a { color: inherit; text-decoration: none; }
.hl-head a:hover { text-decoration: underline; text-decoration-thickness: 1.5px; text-underline-offset: 4px; }
.hl-blurb {
  margin: 0;
  font-size: 13px;
  line-height: 1.6;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.hl-clips { list-style: none; margin: 14px 0 0; padding: 0; }
.hl-clips a {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-top: 1px solid var(--line);
  color: var(--ink);
  text-decoration: none;
  font-size: 13px;
}
.hl-clips a::before { content: '▶'; flex: none; font-size: 9px; line-height: 2; color: var(--muted); }
.hl-clips a span { flex: 1; }
.hl-clips a:hover span { text-decoration: underline; text-underline-offset: 3px; }
.hl-clips time { flex: none; color: var(--muted); }

/* ---------- home run derby ---------- */
.derby-stage {
  position: relative;
  height: min(72vh, 680px);
  min-height: 420px;
  overflow: hidden;
  border: 2px solid var(--rule);
  background: var(--bg);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  cursor: crosshair;
  animation: rise 0.7s var(--ease) both;
}
.derby-stage canvas { display: block; width: 100%; height: 100%; }
.derby-hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  gap: 28px;
  padding: 14px 18px;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.derby-hud span:last-child { margin-left: auto; }
.derby-hud b { font-weight: 700; }
.derby-pitch, .derby-hint {
  position: absolute;
  bottom: 14px;
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.derby-pitch { left: 18px; }
.derby-hint { right: 18px; color: var(--muted); }
.derby-call {
  position: absolute;
  left: 50%;
  top: 18%;
  transform: translate(-50%, 8px);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.3s var(--ease);
}
.derby-call.is-on { opacity: 1; transform: translate(-50%, 0); }
.derby-call strong {
  display: block;
  font-family: var(--serif);
  font-weight: 800;
  font-size: clamp(36px, 6vw, 72px);
  line-height: 1;
  text-transform: uppercase;
  white-space: nowrap;
}
.derby-call.is-good strong { color: var(--red); }
.derby-call span {
  display: block;
  margin-top: 10px;
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.derby-overlay {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(440px, calc(100% - 32px));
  padding: 28px;
  background: var(--bg);
  border: 2px solid var(--rule);
  text-align: center;
}
.derby-overlay[hidden] { display: none; }
.derby-overlay h2 {
  margin: 0 0 12px;
  font-family: var(--serif);
  font-weight: 800;
  font-size: 36px;
  line-height: 1;
  text-transform: uppercase;
}
.derby-overlay p { margin: 0 0 22px; font-size: 14px; line-height: 1.6; }

/* ---------- legend + states ---------- */
.legend {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 12px 28px;
  margin: -8px 0 0;
  padding: 20px 0 0;
  list-style: none;
  border-top: 1px solid var(--line);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.legend li { display: flex; align-items: center; gap: 10px; }
.legend .is-z { --s: var(--z); }
.legend .is-y { --s: var(--y); }
.legend .is-w { --s: var(--w); }
.legend .is-x { --s: var(--x); }
.legend .is-e { --s: var(--e); }
.legend .tag { cursor: default; }

.state {
  grid-column: 1 / -1;
  margin: 0;
  padding: 48px 0;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.state p { margin: 0 0 18px; }
.btn {
  border: 1.5px solid var(--ink);
  border-radius: 0;
  background: none;
  padding: 12px 22px;
  font: inherit;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
  text-transform: uppercase;
  transition: background 0.2s ease, color 0.2s ease;
}
.btn:hover { background: var(--ink); color: var(--bg); }

.credit {
  margin-top: 64px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------- responsive ---------- */
@media (max-width: 1280px) {
  .divisions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card-wide { max-width: none; }
}
@media (max-width: 900px) {
  .bar { flex-direction: column; align-items: flex-start; gap: 10px; padding: 16px 24px; }
  .switch { gap: 4px 18px; }
  .bracket { display: flex; flex-direction: column; gap: 12px; }
  .series { align-self: stretch; }
  .round-head:not(:first-child) { margin-top: 28px; }
  .switch button { font-size: 16px; }
  .content { padding: 44px 24px 64px; }
  .divisions { grid-template-columns: minmax(0, 1fr); gap: 40px; }
  .hl-card.is-feature { grid-template-columns: minmax(0, 1fr); gap: 16px; }
}
@media (max-width: 560px) {
  .bar { padding: 14px 16px; }
  .mark { font-size: 17px; }
  .switch button { font-size: 15px; }
  .content { padding: 32px 16px 56px; }
  h1 { margin-bottom: 36px; }
  .row,
  .table-wildcard .row { grid-template-columns: 18px minmax(0, 1fr) 28px 28px 44px 38px; padding: 0 4px 0 10px; font-size: 13px; column-gap: 4px; }
  .opt { display: none; }
  .hl-nav .btn { min-width: 0; padding: 10px 12px; }
  .hl-date { font-size: 16px; }
  .derby-hud { gap: 14px; padding: 12px; font-size: 11px; }
  .derby-hint { display: none; }
  .table-games .row { grid-template-columns: 26px 50px minmax(0, 1fr) 22px 14px minmax(0, 1fr) 22px; padding: 0 4px; }
  .champ { font-size: 24px; }
  .logo { width: 20px; height: 20px; }
}

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