:root {
  color-scheme: light dark;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #16181d;
  --text-dim: #6b7280;
  --border: #e0e2e7;
  --accent: #2563eb;
  --good: #16a34a;
  --warn: #dc2626;
  --radius: 14px;
  --team-colors: #2563eb, #16a34a, #d97706, #db2777, #7c3aed, #0891b2, #dc2626, #4b5563;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101215;
    --surface: #1a1d22;
    --surface-2: #22262c;
    --text: #eef0f3;
    --text-dim: #9aa1ab;
    --border: #2b2f36;
  }
}

* { 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-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px max(16px, env(safe-area-inset-left));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.title-block {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.title-block h1 {
  font-size: 18px;
  margin: 0;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.subtitle {
  font-size: 12px;
  color: var(--text-dim);
}

.tabs {
  display: flex;
  gap: 4px;
  background: var(--surface-2);
  border-radius: 999px;
  padding: 4px;
  margin-left: auto;
}

.tab-btn {
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 15px;
  font-weight: 600;
  padding: 8px 18px;
  border-radius: 999px;
  cursor: pointer;
}

.tab-btn.active {
  background: var(--accent);
  color: white;
}

.status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--good);
  flex: none;
}

.dot.stale { background: var(--warn); }

.refresh-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 14px;
  cursor: pointer;
}

.refresh-btn:active { transform: scale(0.96); }

main {
  flex: 1;
  padding: 16px max(16px, env(safe-area-inset-left));
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}

.error-banner {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 14px;
}
@media (prefers-color-scheme: dark) {
  .error-banner { background: #3f1717; color: #fca5a5; border-color: #7f1d1d; }
}

.view { display: none; }
.view.active { display: block; }

.summary-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.summary-pill {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  color: var(--text-dim);
}
.summary-pill b { color: var(--text); }

.board-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.team-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.team-head {
  padding: 12px 14px;
  color: white;
  font-weight: 700;
  font-size: 15px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.team-head .count {
  font-size: 12px;
  font-weight: 600;
  opacity: 0.85;
  white-space: nowrap;
}

.pick-list {
  list-style: none;
  margin: 0;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.pick-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px;
  border-radius: 8px;
}

.pick-row.filled { background: var(--surface-2); }

.pick-tag {
  font-size: 10px;
  font-weight: 800;
  color: var(--text-dim);
  width: 34px;
  flex: none;
  text-align: center;
  letter-spacing: 0.03em;
}

.pick-name {
  font-size: 14px;
  font-weight: 600;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pick-name.empty {
  color: var(--text-dim);
  font-weight: 400;
  font-style: italic;
}

.pick-pos {
  font-size: 11px;
  color: var(--text-dim);
  background: var(--bg);
  border-radius: 6px;
  padding: 2px 6px;
  flex: none;
  max-width: 40%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crown { flex: none; font-size: 13px; }

.controls-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.search-input {
  flex: 1;
  min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 15px;
  color: var(--text);
}
.search-input:focus { outline: 2px solid var(--accent); }

.filter-chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.filter-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.roster-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.section-heading {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  padding: 14px 4px 2px;
}
.section-heading:first-child { padding-top: 4px; }

.roster-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  align-items: center;
}

.roster-name-row {
  grid-column: 1 / 2;
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
}

.roster-name {
  font-size: 15px;
  font-weight: 700;
}

.section-tag {
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: var(--surface-2);
  border-radius: 6px;
  padding: 3px 7px;
  white-space: nowrap;
  color: var(--text-dim);
}

.section-tag.goalies { color: #2563eb; }
.section-tag.waitlist { color: #d97706; }
.section-tag.dropped { color: #dc2626; }

.section-select {
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

.roster-meta {
  grid-column: 1 / 2;
  font-size: 12px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.roster-stats {
  grid-column: 1 / 2;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.stat-line {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  background: var(--surface-2);
  border-radius: 6px;
  padding: 3px 8px;
  white-space: nowrap;
}

.roster-status {
  grid-row: 1 / -1;
  grid-column: 2 / 3;
  font-size: 12px;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 999px;
  white-space: nowrap;
  text-align: center;
}

.roster-status.available {
  color: var(--text-dim);
  background: var(--surface-2);
}

.roster-status.drafted {
  color: white;
}

.empty-state {
  text-align: center;
  color: var(--text-dim);
  padding: 40px 10px;
  font-size: 14px;
}

@media (max-width: 480px) {
  .title-block h1 { font-size: 16px; }
  .tab-btn { padding: 7px 12px; font-size: 14px; }
}
