/* ------------------------------------------------------------------
   Tournament stats — one stylesheet, no build step, no dependencies.
   Tables are the product, so most of the care goes into them.
   ------------------------------------------------------------------ */

:root {
  --bg:        #f4efe6;
  --surface:   #fffdf9;
  --ink:       #23211e;
  --ink-soft:  #4a453c;
  --muted:     #6b645b;
  --line:      #e2dcd2;
  --line-soft: #ece5d8;
  --accent:    #c9a35a;
  --accent-in: #231f19;
  --accent-bg: #f3e9d3;
  --bar-bg:    #2c2a27;
  --bar-fg:    #fdfaf4;
  --gold:      #b08422;
  --silver:    #8f887c;
  --bronze:    #a2673d;
  --win:       #14624a;
  --loss:      #a33a3a;
  --radius:    14px;
  --shadow:    0 1px 2px rgba(35,33,30,.05), 0 6px 20px -12px rgba(35,33,30,.16);
}

/* Dark values apply from the OS/browser preference by default, but a page
   can override that -- either direction -- via data-theme, set by the
   toggle button in the masthead (see static/theme.js). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:        #1c1a18;
    --surface:   #2a2724;
    --ink:       #f0ebe3;
    --ink-soft:  #cfc7ba;
    --muted:     #a79f93;
    --line:      #3a3733;
    --line-soft: #322f2b;
    --accent:    #d8b473;
    --accent-in: #1c1a18;
    --accent-bg: #3a3227;
    --bar-bg:    #e8dfcd;
    --bar-fg:    #201d1a;
    --gold:      #d8ab45;
    --silver:    #a8a196;
    --bronze:    #c58353;
    --win:       #45c496;
    --loss:      #e0706c;
    --shadow:    0 1px 2px rgba(0,0,0,.4), 0 8px 24px -14px rgba(0,0,0,.7);
  }
}
:root[data-theme="dark"] {
  --bg:        #1c1a18;
  --surface:   #2a2724;
  --ink:       #f0ebe3;
  --ink-soft:  #cfc7ba;
  --muted:     #a79f93;
  --line:      #3a3733;
  --line-soft: #322f2b;
  --accent:    #d8b473;
  --accent-in: #1c1a18;
  --accent-bg: #3a3227;
  --bar-bg:    #e8dfcd;
  --bar-fg:    #201d1a;
  --gold:      #d8ab45;
  --silver:    #a8a196;
  --bronze:    #c58353;
  --win:       #45c496;
  --loss:      #e0706c;
  --shadow:    0 1px 2px rgba(0,0,0,.4), 0 8px 24px -14px rgba(0,0,0,.7);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 15.5px/1.55 "Inter", ui-sans-serif, system-ui, -apple-system,
        "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-feature-settings: "cv05" 1;
  -webkit-font-smoothing: antialiased;
}

.wrap { width: min(1180px, 100% - 2.5rem); margin-inline: auto; }

a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }

/* --- masthead ----------------------------------------------------- */

.masthead {
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: saturate(140%) blur(8px);
  position: sticky; top: 0; z-index: 30;
}
.masthead-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1.5rem; min-height: 62px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: .65rem; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: block; width: 38px; height: 38px; object-fit: contain;
}
.brand-name { display: block; font-weight: 620; letter-spacing: -.012em; }
.brand-sub  { display: block; font-size: .74rem; color: var(--muted); }

.nav { display: flex; gap: .25rem; flex-wrap: wrap; }
.nav a {
  padding: .38rem .7rem; border-radius: 8px; font-size: .875rem;
  font-weight: 500; color: var(--ink-soft);
}
.nav a:hover { background: var(--line-soft); text-decoration: none; }
.nav a.on { background: var(--accent); color: var(--accent-in); }

.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2.05rem; height: 2.05rem; margin-left: .25rem;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--ink); font-size: 1rem;
  cursor: pointer; transition: background-color .12s ease, border-color .12s ease;
}
.theme-toggle:hover { background: var(--line-soft); border-color: var(--accent); }

/* --- headings ------------------------------------------------------ */

h1 {
  font-size: 1.75rem; font-weight: 800; letter-spacing: -.022em;
  margin: 2rem 0 .9rem; padding-bottom: .55rem; position: relative;
}
h1::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2px;
  background: linear-gradient(90deg, var(--accent), transparent);
  transform-origin: left; animation: rule-in .7s ease-out .05s both;
}

@keyframes rule-in {
  from { opacity: 0; transform: scaleX(0); }
  to   { opacity: 1; transform: scaleX(1); }
}

/* --- entrance animation ---------------------------------------------
   Cards and list-like rows fade/slide in on load, staggered so the page
   settles in a beat rather than all at once. Row-level stagger is capped
   at 15 -- past that, rows past the cap just appear, so a 50-row batting
   table doesn't trickle in one line at a time. */

@keyframes fade-up {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.card, .tile, .medal, .bracket-game, .gamerow, .board li {
  animation: fade-up .4s ease-out both;
}
/* transform on <tr> is fragile cross-browser -- opacity only. */
tbody tr { animation: fade-in .3s ease-out both; }

.card:nth-of-type(1), .tile:nth-of-type(1), .medal:nth-of-type(1), .bracket-game:nth-of-type(1) { animation-delay: .03s; }
.card:nth-of-type(2), .tile:nth-of-type(2), .medal:nth-of-type(2), .bracket-game:nth-of-type(2) { animation-delay: .08s; }
.card:nth-of-type(3), .tile:nth-of-type(3), .medal:nth-of-type(3), .bracket-game:nth-of-type(3) { animation-delay: .13s; }
.card:nth-of-type(4), .tile:nth-of-type(4), .medal:nth-of-type(4), .bracket-game:nth-of-type(4) { animation-delay: .18s; }
.card:nth-of-type(5), .tile:nth-of-type(5), .medal:nth-of-type(5), .bracket-game:nth-of-type(5) { animation-delay: .23s; }
.card:nth-of-type(n+6), .tile:nth-of-type(n+6), .medal:nth-of-type(n+6), .bracket-game:nth-of-type(n+6) { animation-delay: .28s; }

.gamerow:nth-child(1),  .board li:nth-child(1),  tbody tr:nth-child(1)  { animation-delay: .050s; }
.gamerow:nth-child(2),  .board li:nth-child(2),  tbody tr:nth-child(2)  { animation-delay: .075s; }
.gamerow:nth-child(3),  .board li:nth-child(3),  tbody tr:nth-child(3)  { animation-delay: .100s; }
.gamerow:nth-child(4),  .board li:nth-child(4),  tbody tr:nth-child(4)  { animation-delay: .125s; }
.gamerow:nth-child(5),  .board li:nth-child(5),  tbody tr:nth-child(5)  { animation-delay: .150s; }
.gamerow:nth-child(6),  .board li:nth-child(6),  tbody tr:nth-child(6)  { animation-delay: .175s; }
.gamerow:nth-child(7),  .board li:nth-child(7),  tbody tr:nth-child(7)  { animation-delay: .200s; }
.gamerow:nth-child(8),  .board li:nth-child(8),  tbody tr:nth-child(8)  { animation-delay: .225s; }
.gamerow:nth-child(9),  .board li:nth-child(9),  tbody tr:nth-child(9)  { animation-delay: .250s; }
.gamerow:nth-child(10), .board li:nth-child(10), tbody tr:nth-child(10) { animation-delay: .275s; }
.gamerow:nth-child(11), .board li:nth-child(11), tbody tr:nth-child(11) { animation-delay: .300s; }
.gamerow:nth-child(12), .board li:nth-child(12), tbody tr:nth-child(12) { animation-delay: .325s; }
.gamerow:nth-child(13), .board li:nth-child(13), tbody tr:nth-child(13) { animation-delay: .350s; }
.gamerow:nth-child(14), .board li:nth-child(14), tbody tr:nth-child(14) { animation-delay: .375s; }
.gamerow:nth-child(15), .board li:nth-child(15), tbody tr:nth-child(15) { animation-delay: .400s; }
.gamerow:nth-child(n+16), .board li:nth-child(n+16), tbody tr:nth-child(n+16) { animation: none; }

@media (prefers-reduced-motion: reduce) {
  h1::after,
  .card, .tile, .medal, .bracket-game, .gamerow, .board li, tbody tr {
    animation: none;
  }
}
h2 { font-size: 1.08rem; font-weight: 620; letter-spacing: -.012em; margin: 0; }
h3 { font-size: .95rem; font-weight: 600; margin: 0; }

.lede { color: var(--muted); margin: 0 0 1.75rem; font-size: .95rem; }
.dim  { color: var(--muted); }

.eyebrow {
  font-size: .7rem; font-weight: 640; letter-spacing: .085em;
  text-transform: uppercase; color: var(--muted);
}

/* --- cards & grid --------------------------------------------------- */

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  margin-bottom: 1.5rem; overflow: hidden;
}
.card-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 1rem; padding: .95rem 1.15rem; border-bottom: 1px solid var(--line-soft);
  flex-wrap: wrap;
}
.card-body { padding: 1.15rem; }

.grid { display: grid; gap: 1.5rem; }
@media (min-width: 900px) {
  .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* --- tables --------------------------------------------------------- */

.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table { border-collapse: collapse; width: 100%; font-size: .875rem; }

/* Fixed column widths so stacked group tables (Group A, Group B, ...) line
   up with each other -- otherwise each table auto-sizes its Team column off
   its own longest name, and every column after it drifts between tables. */
table.standings { table-layout: fixed; }
table.standings th:not(:first-child),
table.standings td:not(:first-child) { width: 7.5%; }

th, td { padding: .52rem .6rem; white-space: nowrap; }
th:first-child, td:first-child { padding-left: 1.15rem; }
th:last-child,  td:last-child  { padding-right: 1.15rem; }

/* Not sticky: .tablewrap is an overflow-x container, so a sticky thead would
   position against that box instead of the viewport and cover the first rows.
   Tables here are short, and the masthead is sticky already. */
thead th {
  background: var(--bar-bg);
  font-size: .7rem; font-weight: 620; letter-spacing: .08em;
  text-transform: uppercase; color: var(--bar-fg);
  text-align: right; border-bottom: 1px solid var(--line);
}
thead th:first-child { text-align: left; }

tbody td {
  text-align: right;
  border-bottom: 1px solid var(--line-soft);
  font-variant-numeric: tabular-nums lining-nums;
}
tbody td:first-child { text-align: left; font-variant-numeric: normal; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--line-soft); }

tfoot td {
  text-align: right; font-weight: 600; padding-top: .6rem;
  border-top: 1px solid var(--line);
  font-variant-numeric: tabular-nums lining-nums;
  color: var(--ink-soft);
}
tfoot td:first-child { text-align: left; }

.num  { font-variant-numeric: tabular-nums lining-nums; text-align: right; }
.key  { font-weight: 560; }
.sub  { color: var(--muted); font-size: .8rem; }

th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]:hover { background: color-mix(in srgb, var(--bar-fg) 12%, var(--bar-bg)); }
th[aria-sort]::after { content: "↓"; margin-left: .3em; opacity: .55; }
th[aria-sort="ascending"]::after { content: "↑"; }

/* --- standings ------------------------------------------------------ */

.rank {
  display: inline-grid; place-items: center; width: 21px; height: 21px;
  border-radius: 6px; background: var(--line-soft); color: var(--muted);
  font-size: .74rem; font-weight: 640; margin-right: .55rem;
}
tr.pos-1 .rank { background: var(--accent); color: var(--accent-in); }

.pct { font-weight: 600; }
.diff-pos { color: var(--win); }
.diff-neg { color: var(--loss); }

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

/* The name column is the only fixed-layout cell not allowed to overflow
   its own width -- W/L/T/PCT/... are all short and never wrap, but a long
   team name plus tiebreak note has to wrap in place instead of spilling
   across the fixed-width columns to its right. */
table.standings td.key {
  white-space: normal;
  overflow-wrap: anywhere;
}

/* --- games ---------------------------------------------------------- */

.gamelist { display: grid; gap: .5rem; }

.gamerow {
  display: grid; grid-template-columns: 62px 1fr auto;
  align-items: center; gap: .9rem;
  padding: .7rem 1.15rem; border-bottom: 1px solid var(--line-soft);
}
.gamerow:last-child { border-bottom: 0; }
.gamerow:hover { background: var(--line-soft); }
.gamecode {
  font-size: .7rem; font-weight: 640; letter-spacing: .04em;
  color: var(--muted); font-variant-numeric: tabular-nums;
}
.matchup { display: grid; gap: .12rem; }
.side { display: flex; align-items: baseline; gap: .5rem; }
.side .score {
  font-variant-numeric: tabular-nums; font-weight: 640; min-width: 1.4rem;
}
.side.won { font-weight: 600; }
.side.lost { color: var(--muted); }
.gametime { font-size: .78rem; color: var(--muted); text-align: right; }

/* Schedule page rows: a stretched box-score link underneath, with the
   iScorecast button lifted above it so both stay clickable. */
.schedrow { position: relative; grid-template-columns: 62px 1fr auto auto; }
.schedrow .rowlink { position: absolute; inset: 0; }
.schedrow.upcoming:hover { background: none; }
.schedrow.upcoming .score { color: var(--muted); font-weight: 400; }
.upcoming-tag {
  display: inline-block; margin-top: .2rem; font-size: .66rem; font-weight: 600;
  letter-spacing: .05em; text-transform: uppercase; color: var(--accent);
}

.castbtn {
  position: relative; z-index: 1;
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .38rem .7rem .38rem .55rem; border-radius: 999px;
  font-size: .76rem; font-weight: 620; line-height: 1;
  background: var(--accent); color: var(--accent-in);
  border: 1px solid var(--accent);
  transition: transform .12s ease, box-shadow .12s ease;
}
a.castbtn:hover {
  text-decoration: none; transform: translateY(-1px);
  box-shadow: 0 4px 12px -6px var(--accent);
}
a.castbtn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.castbtn .cast-icon { width: 1.05rem; height: 1.05rem; flex: none; }
a.castbtn .cast-icon circle { animation: cast-pulse 1.8s ease-in-out infinite; }
@keyframes cast-pulse { 50% { opacity: .35; } }
.castbtn.disabled {
  background: transparent; color: var(--muted); border-color: var(--line);
  opacity: .55; cursor: not-allowed;
}
@media (prefers-reduced-motion: reduce) {
  a.castbtn .cast-icon circle { animation: none; }
}
@media (max-width: 520px) {
  .castbtn { padding: .42rem; }
  .castbtn .cast-label { display: none; }
}

/* --- linescore ------------------------------------------------------ */

.linescore th, .linescore td { text-align: center; padding-inline: .55rem; }
.linescore th:first-child, .linescore td:first-child { text-align: left; }
.linescore .rhe { font-weight: 660; }
.linescore .sep { border-left: 1px solid var(--line); }

/* --- bracket -------------------------------------------------------- */

.rounds { display: grid; gap: 1.15rem; }
@media (min-width: 760px) { .rounds { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); } }

.bracket-game {
  border: 1px solid var(--line); border-radius: 10px; padding: .7rem .85rem;
  background: var(--surface); display: grid; gap: .3rem;
}
.bracket-game .label { font-size: .7rem; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.bracket-game.pending { border-style: dashed; opacity: .72; }

.medals { display: flex; gap: .6rem; flex-wrap: wrap; }
.medal {
  display: flex; align-items: center; gap: .5rem; padding: .55rem .85rem;
  border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
}
.medal .place { font-size: .68rem; letter-spacing: .08em; text-transform: uppercase; font-weight: 640; }
.medal.gold   .place { color: var(--gold); }
.medal.silver .place { color: var(--silver); }
.medal.bronze .place { color: var(--bronze); }

/* --- stat tiles ----------------------------------------------------- */

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(112px, 1fr)); gap: .75rem; }
.tile {
  border: 1px solid var(--line); border-radius: 11px; padding: .7rem .85rem;
  background: var(--surface);
}
.tile .k { font-size: .68rem; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.tile .v {
  font-size: 1.3rem; font-weight: 640; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums lining-nums;
}

/* --- leaders -------------------------------------------------------- */

.board ol { list-style: none; margin: 0; padding: 0; counter-reset: r; }
.board li {
  display: grid; grid-template-columns: 1.4rem 1fr auto; gap: .6rem;
  align-items: baseline; padding: .4rem 0;
  border-bottom: 1px solid var(--line-soft);
}
.board li:last-child { border-bottom: 0; }
.board li::before {
  counter-increment: r; content: counter(r);
  font-size: .74rem; color: var(--muted); font-variant-numeric: tabular-nums;
}
.board li:first-child { font-weight: 600; }
.board .v { font-variant-numeric: tabular-nums; font-weight: 620; }
.board .t { display: block; font-size: .74rem; color: var(--muted); }
.board-note { font-size: .72rem; color: var(--muted); margin: .55rem 0 0; }

.pill {
  display: inline-block; padding: .1rem .45rem; border-radius: 999px;
  background: var(--line-soft); color: var(--muted);
  font-size: .68rem; font-weight: 600; letter-spacing: .03em;
}

.foot {
  margin: 3.5rem 0 2.5rem; padding-top: 1.25rem;
  border-top: 1px solid var(--line); font-size: .8rem; color: var(--ink-soft);
}
.foot p { margin: .2rem 0; }

.actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: 1rem; }
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .42rem .8rem; border-radius: 8px; border: 1px solid var(--line);
  font-size: .82rem; font-weight: 540; background: var(--surface);
}
.btn:hover { border-color: var(--accent); background: var(--line-soft); text-decoration: none; }

@media (max-width: 640px) {
  .wrap { width: min(1180px, 100% - 1.5rem); }

  h1 { font-size: 1.45rem; }
  th:first-child, td:first-child { padding-left: .8rem; }
  th:last-child,  td:last-child  { padding-right: .8rem; }
  .gamerow { padding-inline: .8rem; }
}
