:root {
  --bg: #000000;
  --bg-card: #121212;
  --bg-card-alt: #1c1c1c;
  --border: #2e2e2e;
  --text: #f5f5f5;
  --text-muted: #9a9a9a;
  --accent: #ffffff;
  --red: #f87171;
  --red-bg: #2a1414;
  --orange: #fbbf24;
  --orange-bg: #2a2210;
  --blue: #93c5fd;
  --blue-bg: #16191f;
  --green: #6ee7b7;
  --green-bg: #10201a;
  --yellow: #eab308;
  --yellow-bg: #262010;
  --grey: #a3a3a3;
  --grey-bg: #1a1a1a;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  padding-bottom: env(safe-area-inset-bottom);
  padding-top: env(safe-area-inset-top);
}

.app-header {
  padding: 20px 16px 14px;
  background: linear-gradient(180deg, #000000 0%, #161616 100%);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

/* The header bar is always a fixed black gradient regardless of theme, so its
   text stays a fixed light color rather than following --text/--text-muted. */
.app-header h1 {
  margin: 0 0 2px;
  font-size: 1.35rem;
  color: #ffffff;
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.header-row h1 {
  flex-shrink: 0;
}

.header-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  max-width: 60%;
  padding: 4px 0;
  background: none;
  border: none;
  color: #b0b0b0;
  font-size: 0.8rem;
  cursor: pointer;
}

.header-summary {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-toggle .chevron {
  flex-shrink: 0;
  font-size: 0.7rem;
  transition: transform 0.2s ease;
}

.app-header.collapsed .header-toggle .chevron {
  transform: rotate(-90deg);
}

.app-header.collapsed .tagline,
.app-header.collapsed .header-details {
  display: none;
}

.tagline {
  margin: 0 0 14px;
  color: #b0b0b0;
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.load-form {
  display: flex;
  gap: 8px;
}

#username-input {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 16px; /* prevents iOS zoom on focus */
}

#username-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

#load-btn, .link-btn {
  padding: 12px 16px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: #000000;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  white-space: nowrap;
}

#load-btn:disabled {
  opacity: 0.6;
}

.status-line {
  margin-top: 10px;
  font-size: 0.85rem;
  color: #b0b0b0;
}

.status-line.error {
  color: #fca5a5;
}

@media (max-width: 480px) {
  .tagline {
    font-size: 3vw;
  }
}

.tab-nav {
  display: flex;
  gap: 8px;
  padding: 12px 16px 0;
  max-width: 1600px;
  margin: 0 auto;
}

.tab-btn {
  flex: 1;
  padding: 10px;
  border-radius: 10px 10px 0 0;
  border: 1px solid var(--border);
  border-bottom: none;
  background: var(--bg-card);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
}

.tab-btn.active {
  background: var(--bg-card-alt);
  color: var(--text);
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

main {
  padding: 16px;
  max-width: 1600px;
  margin: 0 auto;
}

.empty-state {
  color: var(--text-muted);
  text-align: center;
  padding: 40px 12px;
  font-size: 0.95rem;
}

.empty-state .hint {
  font-size: 0.8rem;
  margin-top: 10px;
  opacity: 0.8;
}

.season-banner {
  background: var(--blue-bg);
  border: 1px solid var(--blue);
  color: var(--blue);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  margin-bottom: 16px;
}

.leagues-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  align-items: start;
  gap: 12px;
}

.leagues-dots {
  display: none;
  justify-content: center;
  gap: 6px;
  margin-bottom: 12px;
}

.leagues-dots .dot {
  width: 7px;
  height: 7px;
  padding: 0;
  border: none;
  border-radius: 999px;
  background: var(--border);
  cursor: pointer;
  transition: width 0.2s ease, background 0.2s ease;
}

.leagues-dots .dot.active {
  width: 18px;
  background: var(--accent);
}

@media (max-width: 700px) {
  .leagues-dots {
    display: flex;
  }

  .leagues-container {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 14px;
  }

  .leagues-container::-webkit-scrollbar {
    display: none;
  }

  .league-card {
    flex: 0 0 100%;
    max-width: 100%;
    scroll-snap-align: start;
    scroll-snap-stop: always;
  }
}

.league-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  min-width: 0;
  container-type: inline-size;
}

/* As the grid packs more leagues into one row, each card's own width
   shrinks — these scale its type/spacing down so cramped columns stay
   readable instead of wrapping or overflowing. */
@container (max-width: 260px) {
  .league-card-header {
    padding: 10px 12px;
    gap: 8px;
    flex-wrap: wrap;
  }

  .league-title h2 {
    font-size: 0.86rem;
  }

  .league-title .sub {
    font-size: 0.7rem;
  }

  .record-pill {
    font-size: 0.68rem;
    padding: 2px 7px;
  }

  .alerts {
    padding: 8px 12px 2px;
    gap: 6px;
  }

  .alert {
    padding: 8px 10px;
    gap: 8px;
    font-size: 0.76rem;
  }

  .alert .sub-list {
    font-size: 0.72rem;
  }

  .no-alerts {
    padding: 8px 12px;
    font-size: 0.78rem;
  }

  .roster-section {
    padding: 2px 12px 12px;
  }

  .roster-section h3 {
    font-size: 0.68rem;
    margin: 10px 0 4px;
  }

  .player-row {
    padding: 6px 0;
    gap: 8px;
    font-size: 0.78rem;
  }

  .slot-tag {
    width: 32px;
    font-size: 0.62rem;
  }

  .decision-group h3 {
    margin: 10px 12px 0;
    font-size: 0.66rem;
  }
}

.decision-points-card {
  border-color: var(--accent);
}

.decision-group + .decision-group {
  margin-top: 4px;
}

.decision-group h3 {
  margin: 14px 16px 0;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.decision-group:first-child h3 {
  margin-top: 10px;
}

.league-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--bg-card-alt);
}

.league-title {
  flex: 1;
  min-width: 0;
}

.league-title h2 {
  margin: 0;
  font-size: 1rem;
}

.league-title .sub {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.record-pill {
  font-size: 0.78rem;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.alerts {
  padding: 10px 16px 4px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.alert {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.85rem;
  line-height: 1.35;
}

.alert.sev-high { background: var(--red-bg); border: 1px solid var(--red); }
.alert.sev-mid { background: var(--orange-bg); border: 1px solid var(--orange); }
.alert.sev-low { background: var(--yellow-bg); border: 1px solid var(--yellow); }
.alert.sev-grey { background: var(--grey-bg); border: 1px solid var(--grey); }

.alert b { display: block; margin-bottom: 2px; }

.alert .sub-list {
  margin-top: 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.alert .sub-list span.cand {
  display: inline-block;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 7px;
  margin: 2px 4px 0 0;
}

.no-alerts {
  padding: 10px 16px;
  color: var(--green);
  font-size: 0.85rem;
}

.roster-section {
  padding: 4px 16px 16px;
}

.roster-section h3 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 14px 0 6px;
}

.player-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.87rem;
}

.player-row:last-child { border-bottom: none; }

.slot-tag {
  width: 40px;
  flex-shrink: 0;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-muted);
  padding-top: 2px;
}

.player-info {
  flex: 1;
  min-width: 0;
}

.player-name-line {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-badges-line {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 4px;
}

.player-badges-line:empty {
  display: none;
}

.player-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.badge {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 6px;
  flex-shrink: 0;
}

.badge.bye { background: var(--red-bg); color: var(--red); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-orange { background: var(--orange-bg); color: var(--orange); }
.badge-yellow { background: var(--yellow-bg); color: var(--yellow); }

.badge.game {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-weight: 600;
}

/* Non-Sunday games (Thu/Fri/Sat/Mon) get a grey badge so they stand out as
   worth double-checking against the early lock. */
.badge.game.grey {
  background: var(--grey-bg);
  border-color: var(--grey);
  color: var(--grey);
}

.badge.unknown {
  background: var(--bg);
  border: 1px dashed var(--border);
  color: var(--text-muted);
  font-weight: 500;
}

.viewing-container {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  align-items: start;
  gap: 10px;
}

@media (max-width: 700px) {
  .viewing-container { grid-template-columns: 1fr; }
}

.game-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  min-width: 0;
}

.game-card-header {
  padding: 6px 10px;
  background: var(--bg-card-alt);
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
}

.game-teams {
  font-weight: 700;
  font-size: 0.82rem;
}

.game-meta {
  font-size: 0.68rem;
  color: var(--text-muted);
}

/* Two columns — your players left, opponent players right — kept side by
   side even on mobile. Cells are appended in leagueName-sorted pairs, so
   grid auto-placement lines up each league's mine/theirs cell in the same
   row: a head-to-head layout with no extra alignment logic needed. */
.game-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.col-heading {
  margin: 0;
  padding: 4px 6px 2px;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
}

.col-heading.mine {
  border-right: 1px solid var(--border);
}

.game-cell {
  min-width: 0;
  padding: 4px 6px;
  line-height: 1.3;
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
}

.game-cell.mine {
  border-right: 1px solid var(--border);
}

.game-cell.empty {
  color: var(--text-muted);
  font-size: 0.72rem;
}

.game-cell.empty .player-meta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Line 1 of a viewing cell: league name (truncates) + score chip on the
   right, so each cell stays at two lines even on narrow phones. */
.cell-top {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.cell-top .league-tag {
  flex: 1 1 auto;
  min-width: 0;
}

.league-tag {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.viewing-player-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.game-cell .league-chip {
  flex: 0 0 auto;
  font-size: 0.62rem;
  padding: 0 4px;
  border-radius: 4px;
}

.league-chip {
  font-size: 0.68rem;
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  white-space: nowrap;
}

.league-chip.lead { border-color: var(--green); color: var(--green); }
.league-chip.trail { border-color: var(--red); color: var(--red); }

.league-totals {
  grid-column: 1 / -1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-top: 4px;
}

.league-totals h3 {
  margin: 0 0 8px;
  font-size: 0.82rem;
}

.league-total-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 0;
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
  flex-wrap: wrap;
}

.league-total-row:first-of-type {
  border-top: none;
}

.league-total-name {
  font-weight: 600;
  flex: 1;
  min-width: 0;
}

.league-total-score {
  color: var(--text-muted);
  white-space: nowrap;
}

.league-total-score.mine b,
.league-total-score.theirs b {
  color: var(--text);
  font-weight: 600;
}

.app-footer {
  text-align: center;
  padding: 24px 16px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.link-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-weight: 500;
  padding: 8px 14px;
}

.muted {
  color: var(--text-muted);
  font-size: 0.75rem;
}
