:root {
    color-scheme: light;
    --ink: #202124;
    --muted: #62666d;
    --line: #d7dde3;
    --ice: #eaf4fb;
    --blue: #2c7fb8;
    --red: #d62728;
    --green: #2f8f5b;
    --win-bg: #cdecd6;
    --win-ink: #1b5e20;
    --loss-bg: #f7d2d2;
    --loss-ink: #8b1818;
    --split-bg: #e5e9ee;
    --split-ink: #3f4750;
    --diag-bg: #f4f5f6;
    --pending-bg: #fafbfc;
    --pending-ink: #98a1aa;
    --inflight-bg: #fff2c2;
    --inflight-edge: #d6a800;
    --inflight-ink: #6b5400;
  }
  * { box-sizing: border-box; }
  body {
    font-family: system-ui, -apple-system, sans-serif;
    margin: 0;
    color: var(--ink);
    background: #f6f8fa;
  }
  header, main { max-width: 1200px; margin: 0 auto; padding: 1rem; }
  header { padding-top: 1.4rem; }
  h1 { margin: 0 0 0.35rem; font-size: 1.6rem; font-weight: 750; }
  h2 { margin: 0 0 0.6rem; font-size: 1.1rem; }
  .sub { color: var(--muted); margin: 0.25rem 0 0; font-size: 0.92rem; }
  .nav { margin-top: 0.7rem; display: flex; gap: 0.8rem; flex-wrap: wrap; }
  .nav a { color: var(--blue); }
  .section-nav {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
    margin-top: 0.8rem;
  }
  .section-nav a {
    border: 1px solid var(--line);
    border-radius: 5px;
    color: var(--ink);
    background: #fff;
    padding: 0.35rem 0.65rem;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 650;
  }
  .section-nav a.active {
    border-color: var(--blue);
    color: #fff;
    background: var(--blue);
  }
  .meta-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem 1.2rem;
    margin-top: 0.5rem;
    color: var(--muted);
    font-size: 0.9rem;
  }
  .meta-row b { color: var(--ink); }
  .champion { color: var(--green); font-weight: 700; }

  .card {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0.9rem 1rem;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
    margin-top: 1rem;
  }

  .columns {
    display: grid;
    grid-template-columns: minmax(390px, 430px) minmax(0, 1fr);
    gap: 1rem;
    align-items: start;
    margin-top: 1rem;
  }
  .columns > div { min-width: 0; }
  @media (max-width: 1050px) {
    .columns { grid-template-columns: 1fr; }
  }

  .standings-wrap {
    overflow-x: auto;
    max-width: 100%;
  }
  table.standings {
    width: 100%;
    min-width: 470px;
    border-collapse: collapse;
    table-layout: fixed;
    font-size: 0.82rem;
  }
  table.standings th, table.standings td {
    padding: 0.32rem 0.34rem;
    text-align: left;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
  }
  table.standings th { background: #eef1f4; font-weight: 600; }
  table.standings td.num { text-align: right; font-variant-numeric: tabular-nums; }
  table.standings td.rank { color: var(--muted); }
  table.standings td.team {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  table.standings td.margin { font-weight: 600; }
  table.standings .rank-col { width: 1.7rem; }
  table.standings .team-col { width: 7.4rem; }
  table.standings .short-col { width: 2.2rem; }
  table.standings .rate-col { width: 3.1rem; }
  table.standings .ci-col { width: 5.0rem; }
  table.standings .score-col { width: 2.7rem; }
  table.standings .action-col { width: 4.8rem; }
  table.standings td.promote-cell { text-align: right; }
  table.standings td.promote-cell form { margin: 0; }
  button.promote-btn {
    border: 1px solid var(--line);
    border-radius: 5px;
    padding: 0.25rem 0.42rem;
    background: #fff;
    color: var(--text);
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
  }
  button.promote-btn:hover {
    border-color: var(--green);
    color: var(--green);
  }
  .engine {
    display: inline-block;
    padding: 0.04em 0.4em;
    margin-left: 0.3em;
    border-radius: 0.3em;
    font-size: 0.78em;
    font-weight: 600;
  }
  .engine-v1 { background: #e8d4f5; color: #4a2c70; }
  .engine-v2 { background: #d4e8f5; color: #1a4a70; }

  .grid-wrap { overflow-x: auto; }
  table.grid {
    border-collapse: separate;
    border-spacing: 2px;
    font-variant-numeric: tabular-nums;
    font-size: 0.85rem;
  }
  table.grid th {
    text-align: left;
    padding: 0.3rem 0.5rem;
    font-weight: 600;
    background: #eef1f4;
    border-radius: 3px;
    white-space: nowrap;
  }
  table.grid th.corner { background: transparent; }
  table.grid th.col-head {
    text-align: center;
    /* keep names readable at small cell widths */
    min-width: 4.5rem;
  }
  table.grid td.cell {
    width: 4.8rem;
    height: 3.0rem;
    text-align: center;
    border-radius: 3px;
    padding: 0;
    font-size: 0.9rem;
    line-height: 1.1;
  }
  table.grid td.cell .score { font-weight: 700; }
  table.grid td.cell .extra {
    display: block;
    font-size: 0.7rem;
    font-weight: 500;
    opacity: 0.85;
    margin-top: 0.05rem;
  }
  table.grid td.cell.win { background: var(--win-bg); color: var(--win-ink); }
  table.grid td.cell.loss { background: var(--loss-bg); color: var(--loss-ink); }
  table.grid td.cell.split { background: var(--split-bg); color: var(--split-ink); }
  table.grid td.cell.diag { background: var(--diag-bg); }
  table.grid td.cell.pending { background: var(--pending-bg); color: var(--pending-ink); }
  table.grid td.cell.in-flight {
    background: var(--inflight-bg);
    color: var(--inflight-ink);
    box-shadow: inset 0 0 0 2px var(--inflight-edge);
    font-weight: 600;
    animation: pulse 1.8s ease-in-out infinite;
  }
  @keyframes pulse {
    0%, 100% { box-shadow: inset 0 0 0 2px var(--inflight-edge); }
    50% { box-shadow: inset 0 0 0 2px var(--inflight-edge), 0 0 0 2px rgba(214, 168, 0, 0.45); }
  }

  .legend {
    display: flex;
    gap: 0.8rem;
    align-items: center;
    color: var(--muted);
    font-size: 0.85rem;
    margin-top: 0.6rem;
  }
  .legend .swatch {
    display: inline-block;
    width: 1rem; height: 1rem;
    border-radius: 3px;
    vertical-align: middle;
    margin-right: 0.3rem;
  }
  .swatch.win { background: var(--win-bg); }
  .swatch.loss { background: var(--loss-bg); }
  .swatch.split { background: var(--split-bg); }
  .swatch.pending { background: var(--pending-bg); border: 1px solid var(--line); }
  .swatch.in-flight { background: var(--inflight-bg); border: 1px solid var(--inflight-edge); }
  .curlit-wrap { overflow-x: auto; max-width: 100%; }
  table.curlit {
    width: 100%;
    min-width: 680px;
    border-collapse: collapse;
    table-layout: fixed;
    font-size: 0.82rem;
    font-variant-numeric: tabular-nums;
  }
  table.curlit th, table.curlit td {
    padding: 0.34rem 0.42rem;
    border-bottom: 1px solid var(--line);
    text-align: right;
    white-space: nowrap;
  }
  table.curlit th { background: #eef1f4; font-weight: 600; }
  table.curlit th:first-child, table.curlit td:first-child { text-align: left; }
  table.curlit .negative { color: var(--red); font-weight: 700; }
  table.curlit .positive { color: var(--green); font-weight: 700; }
  .curlit-summary {
    margin-top: 0.7rem;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 0.55rem;
  }
  .curlit-finding {
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 0.55rem 0.65rem;
    background: #fafbfc;
  }
  .curlit-finding.bad { border-color: #efb4b4; background: #fff4f4; }
  .curlit-finding.watch { border-color: #e4cf8f; background: #fff9df; }
  .curlit-finding.ok { border-color: #add8be; background: #f0fbf4; }
  .curlit-finding b { display: block; font-size: 0.95rem; }
  .curlit-finding span { display: block; color: var(--muted); font-size: 0.82rem; margin-top: 0.12rem; }
  .team-charts { margin-top: 1.4rem; padding-top: 1.1rem; border-top: 1px solid var(--line); }
  .team-charts:first-child { margin-top: 0; padding-top: 0; border-top: none; }
  .team-charts > h3 { margin: 0 0 0.3rem; font-size: 1.05rem; }
  .team-charts > h3 .sub { font-weight: 400; font-size: 0.82rem; color: var(--muted); }
  .chart-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 0.9rem;
    margin-top: 0.9rem;
  }
  .chart-panel {
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 0.7rem;
    background: #fbfcfd;
  }
  .chart-panel h3 { margin: 0 0 0.55rem; font-size: 0.95rem; }
  .chart-row {
    display: grid;
    grid-template-columns: 2.2rem 1fr 3.4rem;
    gap: 0.55rem;
    align-items: center;
    margin: 0.18rem 0;
    font-size: 0.78rem;
  }
  .chart-bars {
    display: grid;
    gap: 0.12rem;
  }
  .chart-track {
    height: 0.45rem;
    border-radius: 999px;
    background: #e5e9ee;
    overflow: hidden;
  }
  .chart-track.step {
    position: relative;
  }
  .chart-track.step::before {
    content: "";
    position: absolute;
    left: 50%;
    top: 0;
    bottom: 0;
    width: 1px;
    background: #8b949e;
    z-index: 1;
  }
  .chart-fill {
    height: 100%;
    border-radius: 999px;
  }
  .chart-track.step .chart-fill {
    position: absolute;
    top: 0;
  }
  .chart-track.step .chart-fill.pos { left: 50%; }
  .chart-track.step .chart-fill.neg { right: 50%; }
  .chart-fill.league { background: var(--blue); }
  .chart-fill.pro { background: #9aa3ad; }
  .chart-fill.club { background: #d28b26; }
  .chart-value { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
  .chart-legend { display: flex; gap: 0.8rem; flex-wrap: wrap; color: var(--muted); font-size: 0.78rem; }
  .chart-legend i { display: inline-block; width: 0.8rem; height: 0.45rem; border-radius: 999px; margin-right: 0.25rem; }

  .empty {
    color: var(--muted);
    font-style: italic;
    padding: 0.7rem 0;
  }
  .error {
    color: var(--red);
    background: #fdecec;
    border: 1px solid #f3b6b6;
    padding: 0.5rem 0.7rem;
    border-radius: 4px;
  }
  .notice {
    color: var(--green);
    background: #e7f6ed;
    border: 1px solid #b8dfc8;
    padding: 0.5rem 0.7rem;
    border-radius: 4px;
  }
  .team-picker {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 0.45rem 0.75rem;
    margin-top: 0.7rem;
  }
  .team-option {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.45rem;
    align-items: start;
    padding: 0.45rem 0.5rem;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: #fafbfc;
  }
  .team-option input { margin-top: 0.2rem; }
  .team-option strong { display: block; font-size: 0.9rem; }
  .team-option small { display: block; color: var(--muted); font-size: 0.76rem; margin-top: 0.1rem; }
  .start-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem 0.9rem;
    align-items: center;
    margin-top: 0.8rem;
  }
  button.primary {
    border: 0;
    border-radius: 5px;
    padding: 0.45rem 0.75rem;
    color: #fff;
    background: var(--blue);
    font-weight: 700;
    cursor: pointer;
  }
  button.primary:disabled {
    background: #9aa6b2;
    cursor: not-allowed;
  }
  button.danger {
    border: 0;
    border-radius: 5px;
    padding: 0.45rem 0.75rem;
    color: #fff;
    background: var(--red);
    font-weight: 700;
    cursor: pointer;
  }
  button.danger:disabled {
    background: #b9a0a0;
    cursor: not-allowed;
  }
  .activity-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 0.7rem;
  }
  .live-match {
    border: 1px solid var(--line);
    border-left: 4px solid var(--inflight-edge);
    border-radius: 6px;
    padding: 0.65rem 0.7rem;
    background: #fffaf0;
  }
  .live-match .match-title {
    display: flex;
    justify-content: space-between;
    gap: 0.6rem;
    font-size: 0.82rem;
    color: var(--muted);
  }
  .live-match .teams {
    margin-top: 0.25rem;
    font-weight: 700;
  }
  .live-match .score-line {
    margin-top: 0.25rem;
    font-variant-numeric: tabular-nums;
  }
  .live-match .fresh { color: var(--green); font-weight: 700; }
  .live-match .stale { color: var(--red); font-weight: 700; }
  .live-match.failed {
    background: #fff0f0;
    border-left-color: var(--red);
    opacity: 0.85;
  }
  .live-match .failed-badge {
    color: #fff; background: var(--red); border-radius: 3px;
    padding: 0 0.35rem; font-size: 0.72rem; font-weight: 700;
  }
  .live-match .failure-reason {
    color: var(--red); font-size: 0.82rem;
    word-break: break-all;
  }
  .stale-status { color: var(--red); font-weight: 700; }
  .activity-heading {
    margin: 0.9rem 0 0.25rem;
    color: var(--muted);
    font-size: 0.86rem;
    font-weight: 700;
    text-transform: uppercase;
  }
  .recent-list {
    display: grid;
    gap: 0.3rem;
    margin-top: 0.8rem;
    font-size: 0.88rem;
  }
  .recent-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem 0.7rem;
    justify-content: space-between;
    border-top: 1px solid var(--line);
    padding-top: 0.35rem;
  }
