:root {
  --bg: #f4f5ef;
  --surface: #fffefa;
  --text: #1f1f1f;
  --muted: #666;
  --accent: #b05a1f;
  --accent-2: #2f4f4f;
  --border: #dfdfd7;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "IBM Plex Sans", "Avenir Next", "Segoe UI", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 10% 0%, #fff9eb, transparent 30%),
    radial-gradient(circle at 90% 20%, #e6f5f2, transparent 25%),
    var(--bg);
}

h2, h3, h4 { margin: 0; }
hr { border: 0; border-top: 1px solid var(--border); margin: 12px 0; }

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar[hidden] { display: none; }

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.topbar-logo {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
}

.topbar-title {
  font-weight: 700;
  font-size: 1rem;
  white-space: nowrap;
  letter-spacing: 0.01em;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-left: auto;
  flex-shrink: 0;
}

.user-name {
  font-size: 0.92rem;
  color: var(--text);
  white-space: nowrap;
}

.logout-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.92rem;
  cursor: pointer;
  padding: 4px 0;
  white-space: nowrap;
}

.logout-btn:hover {
  color: var(--text);
}

.layout {
  max-width: 1240px;
  margin: 24px auto;
  padding: 0 16px 32px;
  display: grid;
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.auth-card {
  max-width: 480px;
  margin: 0 auto;
  text-align: center;
}

.auth-card h2 { margin-bottom: 4px; }

.auth-card .stack { text-align: left; }

.auth-logo {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  object-fit: cover;
  margin-bottom: 8px;
}

body:has(.auth-card:not([hidden])):not(:has(#dashboard:not([hidden]))) {
  background: #1a1f2b;
}

body:has(.auth-card:not([hidden])):not(:has(#dashboard:not([hidden]))) .layout {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding-top: 0;
  padding-bottom: 0;
}

.brand-link {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
}

.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
}

.auth-switch {
  margin-top: 12px;
  font-size: 0.9rem;
  color: var(--muted);
}

.auth-switch a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.auth-switch a:hover {
  text-decoration: underline;
}

.auth-role-fieldset {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 0;
  display: flex;
  gap: 16px;
  align-items: center;
}

.auth-role-fieldset legend {
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0 4px;
}

.auth-role-option {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.92rem;
  cursor: pointer;
}

.auth-role-option input {
  width: auto;
  margin: 0;
}

.stack {
  display: grid;
  gap: 10px;
}

.stack.compact { gap: 8px; }

input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: white;
  font-family: inherit;
}

textarea { resize: vertical; }

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

.row.wrap { flex-wrap: wrap; }

.filters {
  margin: 12px 0 16px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  align-items: end;
}

.btn {
  background: var(--accent);
  color: white;
  border: 0;
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
}

.btn.secondary { background: var(--accent-2); }

.btn.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.chip {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.85rem;
  background: #faf9f2;
}

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

.tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.top-tabs {
  margin-bottom: 0;
  gap: 2px;
}

.tab[hidden] {
  display: none;
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.92rem;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}

.tab:hover {
  color: var(--text);
}

.tab svg {
  flex-shrink: 0;
}

.top-tabs .tab.active {
  background: #eef6f0;
  color: #2d6a4f;
  border-color: #2d6a4f;
}

.top-tabs .tab.active svg {
  stroke: #2d6a4f;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.grid.two {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 12px;
}

#dynasty-filter-grid {
  grid-template-columns: 1.45fr 1fr;
}

.subcard {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  background: #fff;
}

.cards {
  margin-top: 10px;
  display: grid;
  gap: 8px;
}

.winner-card,
.dues-card,
.rule-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  background: linear-gradient(145deg, #fff, #fff8ef);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 34px;
}

.chip.asset {
  background: #eef4ef;
  border-color: #d2ded2;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chip.asset button {
  border: 0;
  background: transparent;
  cursor: pointer;
  padding: 0;
}

.winner-card p,
.dues-card p,
.rule-card p { margin: 4px 0; }

.player-cell {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.team-cell {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.player-headshot,
.player-headshot-fallback {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #f2f3ef;
  flex: 0 0 auto;
}

.player-headshot-pick {
  object-fit: contain;
  padding: 2px;
}

.player-headshot-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.8rem;
}

.team-avatar,
.team-avatar-fallback {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #f2f3ef;
  flex: 0 0 auto;
}

.team-avatar-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.65rem;
}

.nfl-team-logo {
  width: 24px;
  height: 24px;
  object-fit: contain;
  display: inline-block;
}

.nfl-team-fallback {
  color: var(--muted);
  font-size: 0.85rem;
}

.trend-up {
  color: #1f8f3a;
  font-weight: 600;
}

.trend-down {
  color: #b02a2a;
  font-weight: 600;
}

.trend-flat {
  color: var(--muted);
}

.table-wrap { overflow: auto; }
.table-wrap.maxh { max-height: 540px; }

#season-stats-table td,
#season-stats-table th {
  white-space: nowrap;
  font-size: 0.85rem;
  padding: 6px 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  text-align: left;
  padding: 8px;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
  vertical-align: top;
}

th.sortable {
  cursor: pointer;
  user-select: none;
}

th.sorted::after {
  content: ' ▲';
  font-size: 0.72rem;
  color: var(--muted);
}

th.sorted[data-sort-dir='desc']::after {
  content: ' ▼';
}

.codebox {
  margin-top: 10px;
  border: 1px solid var(--border);
  background: #f7f7f2;
  border-radius: 10px;
  padding: 10px;
  font-size: 0.83rem;
  overflow: auto;
  max-height: 280px;
}

.inline-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.92rem;
}

.bylaws-content {
  font-size: 0.92rem;
  line-height: 1.65;
  padding: 4px 0;
}

.bylaws-content h1 { font-size: 1.35rem; margin: 0 0 4px; color: var(--accent); }
.bylaws-content h2 { font-size: 1.1rem; margin: 20px 0 6px; color: var(--accent-2); border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.bylaws-content h3 { font-size: 0.98rem; margin: 14px 0 4px; }
.bylaws-content p { margin: 6px 0; }
.bylaws-content ul, .bylaws-content ol { margin: 4px 0; padding-left: 22px; }
.bylaws-content li { margin: 3px 0; }
.bylaws-content hr { margin: 14px 0; }
.bylaws-content em { color: var(--muted); }
.bylaws-content a[href^="#article-"] { color: var(--accent); text-decoration: none; }
.bylaws-content a[href^="#article-"]:hover { text-decoration: underline; }
.bylaws-content h2[id] { scroll-margin-top: 72px; }
.bylaws-content table { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: 0.88rem; }
.bylaws-content th, .bylaws-content td { border: 1px solid var(--border); padding: 5px 10px; text-align: left; }
.bylaws-content th { background: #f0efe8; font-weight: 600; }
.bylaws-content strong { font-weight: 600; }

.inline-check input { width: auto; }

.inline-edit {
  width: auto;
  min-width: 90px;
  padding: 6px 8px;
  font-size: 0.85rem;
}

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 6px 10px;
  margin-top: 8px;
}

.filter-dropdown summary {
  cursor: pointer;
  font-weight: 600;
  user-select: none;
}

.filter-dropdown .checkbox-grid-wrap {
  margin-top: 8px;
  height: 140px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  background: #fbfbf7;
}

#dynasty-filter-team {
  grid-template-columns: 1fr;
}

#dynasty-filter-team {
  font-size: 0.9rem;
}

#dynasty-team-filter-card .checkbox-grid-wrap {
  height: 240px;
}

.checkbox-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.88rem;
}

.checkbox-item input {
  width: auto;
  margin: 0;
}

@media (max-width: 960px) {
  .grid.two { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
  .top-tabs { order: 2; width: 100%; }
  .top-actions { order: 1; }
}
