:root {
  --bg: #0e1116;
  --panel: #161b23;
  --panel-2: #1d2430;
  --line: #262d3a;
  --ink: #e6edf6;
  --dim: #8b97a8;
  --faint: #5b6675;
  --win: #3fb950;
  --lose: #f85149;
  --live: #f0a020;
  --accent: #58a6ff;
  --sleeper: #8b5cf6;
  --espn: #d50a0a;
}

* { box-sizing: border-box; }

/* An explicit display: wins over the UA sheet's [hidden] rule, so state it. */
[hidden] { display: none !important; }

body {
  margin: 0;
  /* Stop iOS rubber-band scroll revealing white behind the dark page. */
  overscroll-behavior-y: none;
  -webkit-tap-highlight-color: transparent;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* Standalone (home-screen) mode draws under the notch and home indicator, so
   pad by the safe-area insets rather than guessing at fixed numbers. */
.wrap {
  max-width: 1100px; margin: 0 auto;
  padding: calc(20px + env(safe-area-inset-top)) calc(18px + env(safe-area-inset-right))
           calc(64px + env(safe-area-inset-bottom)) calc(18px + env(safe-area-inset-left));
}

header {
  display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap;
  padding-bottom: 14px; margin-bottom: 20px; border-bottom: 1px solid var(--line);
}
h1 { font-size: 19px; margin: 0; letter-spacing: -0.01em; }
h1 span { color: var(--faint); font-weight: 400; }
.spacer { flex: 1; }
.meta { color: var(--dim); font-size: 13px; font-variant-numeric: tabular-nums; }
button.refresh {
  background: var(--panel-2); color: var(--ink); border: 1px solid var(--line);
  border-radius: 7px; padding: 6px 12px; font-size: 13px; cursor: pointer;
}
button.refresh:hover { border-color: var(--faint); }
button.refresh:disabled { opacity: .5; cursor: default; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  margin-bottom: 14px; overflow: hidden;
}
.card-head {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 16px; border-bottom: 1px solid var(--line); background: var(--panel-2);
  min-width: 0;
}
.badge {
  font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  padding: 3px 7px; border-radius: 5px; color: #fff;
}
.badge.sleeper { background: var(--sleeper); }
.badge.espn { background: var(--espn); }
.league-name {
  font-weight: 600; font-size: 14px; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.record {
  color: var(--faint); font-size: 12px; font-variant-numeric: tabular-nums;
  white-space: nowrap; flex-shrink: 0;
}

.score-row {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  gap: 12px; padding: 16px;
}
.team { min-width: 0; }
.team.right { text-align: right; }
.team-name {
  font-weight: 600; font-size: 14px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.manager { color: var(--faint); font-size: 12px; }
.score {
  font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em; line-height: 1.1;
}
.score.ahead { color: var(--win); }
.score.behind { color: var(--lose); }
.vs { color: var(--faint); font-size: 12px; font-weight: 600; }
.left-note { color: var(--dim); font-size: 12px; margin-top: 3px; font-variant-numeric: tabular-nums; }
.left-note b { color: var(--live); font-weight: 600; }

/* Per-matchup red-zone chips under the score. Hidden entirely when both idle. */
.rz-strip {
  display: flex; gap: 8px; padding: 0 16px 12px;
}
.rz-chip {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); background: var(--panel-2);
  border-radius: 999px; padding: 6px 10px;
  color: var(--faint); font-size: 12px;
}
.rz-chip.idle { opacity: .5; }
.rz-chip.active {
  opacity: 1; color: #ff8a80;
  border-color: rgba(248,81,73,.55);
  background: rgba(248,81,73,.14);
}
.rz-chip.just_scored {
  opacity: 1; color: var(--win);
  border-color: rgba(63,185,80,.55);
  background: rgba(63,185,80,.16);
  animation: rzflash 1.8s ease-out 1;
}
@keyframes rzflash {
  0%   { box-shadow: 0 0 0 0 rgba(63,185,80,.5); filter: brightness(1.35); }
  100% { box-shadow: 0 0 0 10px rgba(63,185,80,0); filter: brightness(1); }
}
@media (prefers-reduced-motion: reduce) { .rz-chip.just_scored { animation: none; } }
.rz-chip-label {
  flex-shrink: 0; font-size: 10px; font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase;
}
.rz-chip-caption {
  min-width: 0; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.toggle {
  width: 100%; background: none; border: none; border-top: 1px solid var(--line);
  color: var(--dim); padding: 8px; font-size: 12.5px; cursor: pointer; font-family: inherit;
}
.toggle:hover { color: var(--ink); background: var(--panel-2); }

.rosters { display: grid; grid-template-columns: 1fr 1fr; gap: 0; border-top: 1px solid var(--line); }
.rosters > div:first-child { border-right: 1px solid var(--line); }
.roster-head {
  font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--faint); padding: 9px 14px 5px;
}
table { width: 100%; border-collapse: collapse; font-size: 13px; }
td { padding: 4px 8px; vertical-align: middle; }
td.slot { color: var(--faint); font-size: 10.5px; width: 42px; font-weight: 600; letter-spacing: .04em; }
td.who { min-width: 0; }
td.pts { text-align: right; font-variant-numeric: tabular-nums; width: 52px; font-weight: 600; }
.pname { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 190px; }
.pmeta { color: var(--faint); font-size: 11px; white-space: nowrap; }
tr.bench td { opacity: .55; }
tr.bench td.slot { color: var(--faint); }

.dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; margin-right: 5px; vertical-align: 1px; }
.dot.pre { background: var(--faint); }
.dot.in { background: var(--live); box-shadow: 0 0 0 2px rgba(240,160,32,.2); }
.dot.post { background: transparent; border: 1px solid var(--faint); }
.dot.none { background: transparent; }

/* --- red zone ------------------------------------------------------------ */
.rz {
  background: linear-gradient(180deg, rgba(248,81,73,.09), rgba(248,81,73,.03));
  border: 1px solid rgba(248,81,73,.32);
  border-radius: 12px; margin-bottom: 18px; overflow: hidden;
}
.rz-head {
  display: flex; align-items: center; gap: 9px;
  padding: 10px 16px; border-bottom: 1px solid rgba(248,81,73,.2);
}
.rz-head h2 {
  font-size: 12px; margin: 0; letter-spacing: .09em; text-transform: uppercase;
  color: #ff8a80; font-weight: 700;
}
.rz-pulse {
  width: 8px; height: 8px; border-radius: 50%; background: var(--lose);
  animation: rzpulse 1.6s ease-in-out infinite; flex-shrink: 0;
}
@keyframes rzpulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(248,81,73,.55); }
  70%      { opacity: .75; box-shadow: 0 0 0 7px rgba(248,81,73,0); }
}
@media (prefers-reduced-motion: reduce) { .rz-pulse { animation: none; } }

.rz-league { padding: 9px 16px 11px; border-top: 1px solid rgba(248,81,73,.13); }
.rz-league:first-of-type { border-top: none; }
.rz-league-name {
  font-size: 11px; color: var(--dim); letter-spacing: .05em;
  text-transform: uppercase; margin-bottom: 6px;
  display: flex; align-items: center; gap: 7px;
}
.rz-row {
  display: flex; align-items: center; gap: 9px; padding: 4px 0;
  font-size: 13.5px;
}
.rz-who { min-width: 0; flex: 1; }
.rz-side {
  font-size: 9.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  padding: 2px 5px; border-radius: 4px; flex-shrink: 0; min-width: 44px; text-align: center;
}
.rz-side.mine   { background: rgba(63,185,80,.17);  color: var(--win); }
.rz-side.theirs { background: rgba(248,81,73,.15);  color: #ff8a80; }
.rz-name {
  font-weight: 600; line-height: 1.25;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.rz-meta {
  color: var(--faint); font-size: 11.5px; line-height: 1.25;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.rz-def { color: var(--live); font-size: 10.5px; font-weight: 600; }
.rz-pts { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 600; flex-shrink: 0; }

.notice {
  background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--live);
  border-radius: 8px; padding: 12px 16px; margin-bottom: 14px;
  color: var(--dim); font-size: 13px;
}
.notice.setup { border-left-color: var(--accent); }
.notice code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; color: var(--ink); font-size: 12px; }
.notice pre { background: var(--panel-2); padding: 10px 12px; border-radius: 6px; overflow-x: auto; color: var(--ink); font-size: 12px; line-height: 1.5; }
.notice h3 { margin: 0 0 8px; font-size: 14px; color: var(--ink); }
.notice ol { margin: 8px 0 0; padding-left: 18px; }
.notice li { margin-bottom: 6px; }

@media (max-width: 700px) {
  .wrap {
    padding: calc(14px + env(safe-area-inset-top)) calc(11px + env(safe-area-inset-right))
             calc(50px + env(safe-area-inset-bottom)) calc(11px + env(safe-area-inset-left));
  }
  .rosters { grid-template-columns: 1fr; }
  .rosters > div:first-child { border-right: none; border-bottom: 1px solid var(--line); }
  .score { font-size: 25px; }
  .pname { max-width: 42vw; }
}
