:root {
  --navy: #031f73; --navy2: #00144e; --crimson: #981e32; --crimson2: #6e0718; --sky: #b8cfff; --sky2: #ecf1fd;
  --bg: #f7f7f7; --bg2: #ffffff; --card: #ffffff; --card2: #f1f4fb; --line: #d1d5db;
  --text: #1f2937; --muted: #6b7280; --green: #1f7a3a; --green2: #2f9e56; --greenbg: #e8f5ec; --gold: #9a6b00; --gold2: #d9a400; --goldbg: #fff6dc; --amber: #b45309;
  --red: #c2410c; --redbg: #fff1eb; --amberbg: #fff7ed; --blue: #031f73; --heading: #031f73; --radius: 12px; --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
:root[data-theme="dark"], :root.dark-auto {
  --bg: #0f141d; --bg2: #141a25; --card: #171e2b; --card2: #1f2837; --line: #2b3546;
  --text: #e6eaf2; --muted: #9aa4b8; --sky: #4b6fb8; --sky2: #1b2a47; --green: #4cc47a; --green2: #2f9e56; --greenbg: #14301f;
  --gold: #e6b84a; --gold2: #b88a1f; --goldbg: #2e2510; --amber: #f0a04b; --amberbg: #33240f; --red: #f0784f; --redbg: #3a1f16;
  --heading: #c7d6ff; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font: 15px/1.5 Poppins, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--heading); }
[hidden] { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 12px; } .mono { font-family: var(--mono); }
.gold { color: var(--gold); } .green { color: var(--green); } .red { color: var(--red); } .blue { color: var(--blue); }
.right { text-align: right; } .center { text-align: center; } .nowrap { white-space: nowrap; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 18px; background: #fff; border-bottom: 4px solid var(--crimson); position: sticky; top: 0; z-index: 5; box-shadow: 0 1px 6px rgba(3,31,115,.08); }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { display: block; flex: none; line-height: 0; padding-right: 14px; border-right: none; }
.logo img { height: 44px; width: auto; display: block; }
.hdr-title { font-weight: 700; font-size: 18px; white-space: nowrap; color: var(--navy); letter-spacing: .2px; }
.hdr-sub { color: var(--muted); font-size: 12px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
select, .btn { background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font: inherit; font-size: 14px; cursor: pointer; }
select:focus, .btn:focus { outline: 2px solid var(--navy); outline-offset: 1px; }
.btn.active { border-color: var(--navy); background: var(--navy); color: #fff; }
.btn.primary { background: var(--crimson); border-color: var(--crimson); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--crimson2); }

.tabs { display: flex; gap: 2px; padding: 8px 12px 0; overflow-x: auto; border-bottom: 1px solid var(--line); background: var(--navy); scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { flex: none; background: none; border: none; color: var(--sky); padding: 10px 14px; font-size: 14px; font-weight: 600; cursor: pointer; border-bottom: 3px solid transparent; border-radius: 6px 6px 0 0; font-family: inherit; }
.tabs button:hover { color: #fff; background: var(--navy2); }
.tabs button.active { color: #fff; border-bottom-color: var(--crimson); }
.tabs .commish-tab { margin-left: auto; color: #fff; opacity: .85; }

main { padding: 16px 18px 48px; max-width: 1400px; margin: 0 auto; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; min-width: 0; box-shadow: 0 1px 3px rgba(3,31,115,.06); }
.card h2 { color: var(--heading); }
.card h2 { margin: 0 0 6px; font-size: 16px; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.card h2 .muted { font-weight: 400; font-size: 12px; }
.card.wide { grid-column: 1 / -1; }
.tablewrap { overflow-x: auto; max-width: 100%; }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; overflow-wrap: normal; word-break: normal; }
td.num, td.mono, td.nowrap { white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .3px; white-space: nowrap; position: sticky; top: 0; background: var(--card); }
td.num, th.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
tr.hl td { background: var(--goldbg); }
tr.me td { background: var(--redbg); }
tr.cut td { border-bottom: 2px dashed var(--gold2); }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--card2); }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; border: 1px solid var(--sky); background: var(--sky2); color: var(--navy); white-space: nowrap; font-weight: 600; }
.pill.gold { border-color: var(--gold2); background: var(--goldbg); color: var(--gold); }
.pill.green { border-color: var(--green2); background: var(--greenbg); color: var(--green); }
.pill.red { border-color: var(--red); background: var(--redbg); color: var(--red); }
.pill.amber { border-color: var(--amber); background: var(--amberbg); color: var(--amber); }
.pill.blue { border-color: var(--blue); color: var(--blue); }
/* results: navy bold = win, grey = loss, amber = tie. gold = top score or prize. red-orange = injury or problem. */
.W { color: var(--green); font-weight: 700; } .L { color: var(--muted); } .T { color: var(--amber); font-weight: 600; }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .big { font-size: 26px; font-weight: 700; color: var(--heading); }
.stat .big.gold { color: var(--gold); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.owner { color: var(--muted); font-size: 11.5px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.nm { font-weight: 600; }
td .nm { font-weight: 600; }
.mteam .owner { display: inline; margin-left: 6px; }
.mteam .owner::before { content: '('; } .mteam .owner::after { content: ')'; }
.teamlogo { width: 22px; height: 22px; border-radius: 50%; vertical-align: middle; margin-right: 6px; background: #fff; object-fit: cover; }
.week-nav { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 4px 0 12px; }
.week-nav button { padding: 4px 10px; }
.subtabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0 12px; }
.roster-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
.roster-grid .card { overflow: hidden; }
.roster-grid .card h2 { white-space: normal; line-height: 1.3; }
.roster-grid table { font-size: 12.5px; table-layout: fixed; width: 100%; }
.roster-grid td, .roster-grid th { padding: 3px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.roster-grid th:nth-child(1), .roster-grid td:nth-child(1) { width: 44px; }
.roster-grid th:nth-child(3), .roster-grid td:nth-child(3) { width: 58px; color: var(--muted); font-size: 11.5px; }
.roster-grid th:nth-child(4), .roster-grid td:nth-child(4), .roster-grid th:nth-child(5), .roster-grid td:nth-child(5) { width: 54px; }
.roster-grid .inj { display: inline; }
.bench td { color: var(--muted); }
.ir td { color: var(--muted); font-style: italic; }
.inj { color: var(--red); font-size: 11px; margin-left: 4px; }
.bar { height: 6px; background: var(--bg2); border-radius: 3px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--navy); }
.note { color: var(--muted); font-size: 12px; margin-top: 8px; }
.err { color: var(--red); padding: 12px; }
.loading { padding: 32px; text-align: center; color: var(--muted); }
footer { padding: 24px 18px; color: var(--muted); font-size: 12px; text-align: center; border-top: 1px solid var(--line); background: var(--card); }
.scoregrid td.num { padding: 4px 6px; font-size: 12.5px; }
.scoregrid td.num.top { color: var(--gold); background: var(--goldbg); font-weight: 700; }
.scoregrid td.num.win { color: var(--green); font-weight: 600; }
.scoregrid td.num.loss { color: var(--muted); }
details summary { cursor: pointer; color: var(--muted); font-size: 13px; margin: 4px 0; }
@media (max-width: 640px) { main { padding: 12px 10px 40px; } .card { padding: 12px; } .hdr-title { font-size: 16px; } }

/* commissioner + bracket */
.cm-login { max-width: 420px; margin: 24px auto; }
.cm-login input { width: 100%; padding: 10px 12px; font: inherit; border: 1px solid var(--line); border-radius: 8px; margin: 8px 0 12px; background: var(--card); color: var(--text); }
.cm-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 4px 0 12px; }
.cm-bar .spacer { flex: 1; }
.cm-text { width: 100%; min-height: 220px; font: 12.5px/1.4 var(--mono); border: 1px solid var(--line); border-radius: 8px; padding: 10px; background: var(--card); color: var(--text); }
.cm-stats td:first-child { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .3px; white-space: nowrap; }
.fail { color: var(--crimson); font-weight: 600; }
.rounds { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; align-items: start; }
.game { border: 1px solid var(--line); border-radius: 10px; margin: 6px 0; overflow: hidden; background: #fff; }
.game .side { display: flex; justify-content: space-between; gap: 6px; padding: 5px 8px; font-size: 13px; }
.game .side + .side { border-top: 1px solid var(--line); }
.game .side.won { background: var(--sky2); font-weight: 600; }
.game .side .seed { color: var(--muted); font-size: 11px; margin-right: 4px; }
.game .how { font-size: 11px; color: var(--muted); padding: 2px 8px 5px; }
.bye { color: var(--muted); font-size: 12px; margin: 4px 0; }
.champ { text-align: center; padding: 16px; }
.champ .big { font-size: 28px; }

/* bracket layout */
.bwrap { overflow-x: auto; padding-bottom: 8px; }
.bracket { position: relative; display: flex; gap: 34px; align-items: stretch; min-width: max-content; padding: 4px 6px; }
.blines { position: absolute; inset: 0; pointer-events: none; z-index: 0; }
.bround { position: relative; z-index: 1; display: flex; flex-direction: column; width: 262px; }
.bhead { font-weight: 700; color: var(--heading); font-size: 13px; text-align: center; padding-bottom: 6px; }
.bhead small { display: block; color: var(--muted); font-weight: 500; font-size: 11px; }
.bgames { flex: 1; display: flex; flex-direction: column; justify-content: space-around; gap: 10px; }
.bmatch { background: var(--card); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; box-shadow: 0 1px 3px rgba(3,31,115,.06); }
.bside { display: grid; grid-template-columns: 26px 18px 1fr auto; align-items: center; gap: 6px; padding: 5px 8px; font-size: 12.5px; min-height: 36px; }
.bside + .bside { border-top: 1px solid var(--line); }
.bside.won { background: var(--greenbg); font-weight: 600; }
.bside.won .bname { color: var(--green); }
.bside.lost { color: var(--muted); }
.bside.lost .blogo { filter: grayscale(1); opacity: .6; }
.bside.empty { color: var(--muted); }
.blogo { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; background: #fff; border: 1px solid var(--line); }
.blogo.none { display: inline-block; background: var(--card2); }
.bseed { font-size: 11px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.bname { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.15; }
.bname small { display: block; color: var(--muted); font-weight: 500; font-size: 10.5px; }
.bpts { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 12px; }
.bhow { font-size: 11px; color: var(--muted); padding: 3px 8px 5px; border-top: 1px dashed var(--line); }
.bchamp .bgames { justify-content: center; }
.bwinner { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; padding: 14px; border: 2px solid var(--crimson); border-radius: 12px; background: var(--card); }
.bwinner .blogo { width: 64px; height: 64px; }
.bwinner .bname { font-weight: 700; font-size: 15px; color: var(--heading); white-space: normal; }

/* matchup tables: team | pts | at | team | pts */
.matchtbl { table-layout: fixed; width: 100%; }
.matchtbl td { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 5px 6px; }
.matchtbl td:nth-child(2), .matchtbl td:nth-child(5) { width: 58px; text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.matchtbl td:nth-child(3) { width: 28px; text-align: center; }
.matchtbl td:nth-child(6) { width: 74px; }

/* stacked matchups: name wraps, points right */
.matchups { display: flex; flex-direction: column; gap: 6px; }
.matchup { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--card); }
.mline { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 5px 9px; font-size: 13px; line-height: 1.3; }
.mline + .mline { border-top: 1px solid var(--line); }
.mline.W { background: var(--greenbg); }
.mline.W .mteam { font-weight: 600; color: var(--green); }
.mline.L .mteam { color: var(--muted); }
.mline.T { background: var(--amberbg); }
.mline.T .mteam { color: var(--amber); font-weight: 600; }
.mteam { min-width: 0; overflow-wrap: anywhere; }
.mteam small { font-weight: 400; }
.mpts { flex: none; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.mtag { padding: 2px 9px 5px; }

/* legend */
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; justify-content: center; margin-bottom: 8px; font-size: 12px; color: var(--muted); }
.legend.inline { justify-content: flex-start; margin: 0 0 10px; padding: 6px 10px; background: var(--card2); border-radius: 8px; }
.legend b { color: var(--text); font-weight: 600; }
.legend .sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 5px; border: 1px solid var(--line); }

/* overview: league standings, one tidy mini table per league, same columns everywhere */
.standings-grid { display: grid; gap: 12px 18px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.standings-grid .mini h3 { margin: 4px 0 4px; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.minitbl { table-layout: fixed; width: 100%; font-size: 13px; }
.minitbl th { position: static; }
.minitbl th:nth-child(1), .minitbl td:nth-child(1) { width: 28px; }
.minitbl th:nth-child(3), .minitbl td:nth-child(3) { width: 48px; }
.minitbl th:nth-child(4), .minitbl td:nth-child(4) { width: 62px; }
.minitbl td { padding: 4px 6px; vertical-align: middle; }
.minitbl td.tname { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.minitbl td.tname .owner { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.builder { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 6px 14px; }
.brow { display: flex; align-items: center; gap: 6px; }
.brow .bseedn { width: 24px; text-align: right; font-weight: 700; color: var(--heading); font-variant-numeric: tabular-nums; }
.brow select { flex: 1; min-width: 0; font-size: 13px; }
.brow .btn { padding: 4px 7px; font-size: 11px; }

/* turf header: the field runs from the logo to the right edge; yard lines are 10 per width and hash marks 50 per width,
   so they stretch with the screen instead of repeating at a fixed pixel size. */
.topbar { position: sticky; overflow: hidden; --logo-w: 190px; }
.topbar .turf { position: absolute; top: 0; bottom: 0; left: 0; right: 0; z-index: 0;
  background:
    repeating-linear-gradient(90deg, transparent 0 calc(2% - 1px), rgba(255,255,255,.35) calc(2% - 1px) 2%) 5% top / 100% 6px no-repeat,
    repeating-linear-gradient(90deg, transparent 0 calc(2% - 1px), rgba(255,255,255,.35) calc(2% - 1px) 2%) 5% bottom / 100% 6px no-repeat,
    repeating-linear-gradient(90deg, transparent 0 calc(5% - 1.5px), rgba(255,255,255,.55) calc(5% - 1.5px) 5%, transparent 5% calc(15% - 1.5px), rgba(255,255,255,.55) calc(15% - 1.5px) 15%) 0 0 / 100% 100%,
    repeating-linear-gradient(90deg, #2c7a3c 0 10%, #338845 10% 20%);
}
.topbar .turf::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, rgba(0,0,0,.10), rgba(0,0,0,0) 35%, rgba(0,0,0,.12)); }
.topbar .brand, .topbar .topbar-right { position: relative; z-index: 1; }
.topbar .logo { background: transparent; padding: 0 14px 0 0; border-right: 1px solid rgba(3,31,115,.18); margin-right: 12px; }
.hdr-text { padding: 2px 0; }
.hdr-title { color: var(--navy); text-shadow: none; font-size: 19px; letter-spacing: .3px; }
.hdr-sub { color: #3b4658; text-shadow: none; }
.topbar-right label { color: var(--navy); text-shadow: none; }
.topbar-right select { background: rgba(255,255,255,.95); }
@media (max-width: 640px) { .topbar { --logo-w: 150px; } .topbar .logo img { height: 36px; } }


.bbye { border-style: dashed; background: var(--card2); }
.bbye .bside { grid-template-columns: 26px 18px 1fr auto; }
.bbye .bside.won { background: transparent; }
.bbye .bhow { border-top: none; padding-top: 0; }

/* brand blended straight into the turf: no plate, a soft light behind the mark, white title */
.topbar { padding: 12px 24px; border-bottom: 3px solid var(--crimson); }
.topbar .brand { position: relative; padding: 6px 14px; gap: 14px; background: none; border-radius: 0; }
.topbar .brand > * { position: relative; z-index: 1; }
.topbar .logo { padding: 0 14px 0 0; border-right: none; margin-right: 0; position: relative; filter: drop-shadow(0 0 14px rgba(255,255,255,.6)) drop-shadow(0 0 5px rgba(255,255,255,.48)) drop-shadow(0 0 2px rgba(255,255,255,.4)); }
.topbar .logo img { height: 40px; }
.hdr-title { color: #fff; font-weight: 600; font-size: 19px; letter-spacing: .1px; line-height: 1.15; text-shadow: 0 1px 3px rgba(0,0,0,.55); }
.hdr-sub { font-size: 11.5px; color: #eef5ef; margin-top: 2px; text-shadow: 0 1px 2px rgba(0,0,0,.55); }
.topbar .topbar-right { gap: 8px; }
.topbar-right label { color: #f3f7f4; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; text-shadow: 0 1px 2px rgba(0,0,0,.45); }
.topbar-right select { background: rgba(255,255,255,.92); border: 1px solid rgba(255,255,255,.7); border-radius: 999px; padding: 6px 12px; font-size: 13px; box-shadow: 0 3px 10px rgba(0,0,0,.18); color: var(--navy); font-weight: 600; }
@media (max-width: 640px) { .topbar { padding: 10px 12px; } .topbar .brand { padding: 4px 10px 4px 8px; } .hdr-sub { display: none; } }

/* dark mode: tabs bar and turf stay, everything else follows the tokens */
:root[data-theme="dark"] .tabs, :root.dark-auto .tabs { background: #0b1533; }
:root[data-theme="dark"] .card, :root.dark-auto .card { box-shadow: 0 1px 3px rgba(0,0,0,.4); }
:root[data-theme="dark"] .pill, :root.dark-auto .pill { color: #c7d6ff; }
:root[data-theme="dark"] .teamlogo, :root.dark-auto .teamlogo, :root[data-theme="dark"] .blogo, :root.dark-auto .blogo { background: #fff; }
:root[data-theme="dark"] select, :root.dark-auto select, :root[data-theme="dark"] .btn, :root.dark-auto .btn { background: var(--card2); color: var(--text); border-color: var(--line); }
:root[data-theme="dark"] .btn.active, :root.dark-auto .btn.active { background: var(--sky); color: #fff; border-color: var(--sky); }
:root[data-theme="dark"] .topbar-right select, :root.dark-auto .topbar-right select { background: rgba(23,30,43,.92); color: #e6eaf2; border-color: rgba(255,255,255,.2); }
:root[data-theme="dark"] .legend .sw, :root.dark-auto .legend .sw { filter: brightness(.85); }
:root[data-theme="dark"] .ku-tile, :root.dark-auto .ku-tile { background: var(--card2); }
.theme-btn { background: rgba(255,255,255,.92); border: 1px solid rgba(255,255,255,.7); border-radius: 999px; width: 34px; height: 34px; display: grid; place-items: center; cursor: pointer; font-size: 16px; box-shadow: 0 3px 10px rgba(0,0,0,.18); padding: 0; }
:root[data-theme="dark"] .theme-btn, :root.dark-auto .theme-btn { background: rgba(23,30,43,.92); color: #ffd166; border-color: rgba(255,255,255,.2); }
