:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #eef1f6;
  --text: #111827;
  --muted: #6b7280;
  --border: #dde2ea;
  --accent: #1d4ed8;
  --accent-soft: #dbe5ff;
  --mine: #0f7b3f;
  --mine-soft: #dcf5e6;
  --warn: #b45309;
  --warn-soft: #fdf0dc;
  --danger: #b91c1c;
  --clock: #dc2626;
  --shadow: 0 8px 28px rgba(15, 23, 42, 0.18);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #1f2630;
    --text: #e6edf3;
    --muted: #8b949e;
    --border: #2b3340;
    --accent: #6ea0ff;
    --accent-soft: #1b2a4a;
    --mine: #4ade80;
    --mine-soft: #12301f;
    --warn: #f5b25a;
    --warn-soft: #33260f;
    --danger: #f87171;
    --clock: #f87171;
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

button, input { font: inherit; color: inherit; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.pad { padding: 16px; }
.spacer { flex: 1; }
.error { color: var(--danger); font-weight: 600; }

/* ---------- Login ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 24px; display: grid; gap: 10px; box-shadow: var(--shadow);
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0; }
.login-card label { font-weight: 600; font-size: 14px; margin-top: 6px; }

input:not([type]), input[type="text"], input[type="password"], input[type="search"], input[type="number"] {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); outline: none;
}
input:focus { border-color: var(--accent); }

.btn {
  padding: 10px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); cursor: pointer; font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.mine { background: var(--mine); border-color: var(--mine); color: #fff; }
.btn.taken { background: var(--text); border-color: var(--text); color: var(--bg); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10; background: var(--surface);
  border-bottom: 1px solid var(--border); padding: 8px 16px 0;
}
.topbar-row { display: flex; align-items: center; gap: 10px; }
.brand { font-size: 18px; margin: 0; }
.sync { font-size: 10px; color: var(--mine); transition: color 0.2s; }
.sync.busy { color: var(--warn); }
.sync.err { color: var(--danger); }
.icon-btn {
  background: none; border: 1px solid var(--border); border-radius: 8px; width: 34px; height: 34px;
  display: grid; place-items: center; cursor: pointer; text-decoration: none; color: var(--text); font-size: 17px;
}
.controls { margin-top: 8px; }
.controls input[type="search"] { flex: 1; min-width: 0; }
.toggle { display: flex; align-items: center; gap: 6px; white-space: nowrap; font-size: 14px; }

.banner {
  margin-top: 8px; padding: 8px 12px; border-radius: 10px; background: var(--accent-soft);
  font-size: 14px; display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center;
}
.banner strong { font-size: 15px; }
.banner.clock { background: var(--clock); color: #fff; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.82; } }

.tabs { display: flex; gap: 2px; overflow-x: auto; margin: 8px -16px 0; padding: 0 16px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  background: none; border: none; border-bottom: 3px solid transparent; padding: 8px 10px;
  cursor: pointer; white-space: nowrap; color: var(--muted); font-weight: 600;
}
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- Views ---------- */
.view { padding: 12px 16px 80px; max-width: 1100px; margin: 0 auto; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin: 16px 0 6px; }
.section-title:first-child { margin-top: 4px; }

.cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 720px) { .cards { grid-template-columns: 1fr; } }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; }
.card h3 { margin: 0 0 6px; font-size: 14px; display: flex; justify-content: space-between; }
.card ol { margin: 0; padding: 0; list-style: none; }
.card li { display: flex; justify-content: space-between; gap: 8px; padding: 5px 0; border-top: 1px solid var(--border); cursor: pointer; }
.card li:first-child { border-top: none; }

.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 8px; text-align: right; white-space: nowrap; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; }
th.sortable { cursor: pointer; text-decoration: underline dotted; }
td.l, th.l { text-align: left; }
td.name { white-space: normal; font-weight: 600; min-width: 120px; }
td.name .sub { display: block; font-weight: 400; font-size: 12px; color: var(--muted); }
tbody tr { border-top: 1px solid var(--border); cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
tr.taken td { opacity: 0.45; }
tr.taken td.name { text-decoration: line-through; }
tr.mine { background: var(--mine-soft); }
tr.mine:hover { background: var(--mine-soft); }
tr.dim td { opacity: 0.5; }
.b { font-weight: 700; }
.neg { color: var(--muted); }

.badge {
  display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 999px;
  margin-left: 4px; vertical-align: 1px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.badge.need { background: var(--mine-soft); color: var(--mine); border-color: transparent; }
.badge.bench { background: var(--surface-2); }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.mine { background: var(--mine); color: #fff; border-color: transparent; }
.badge.taken { background: var(--text); color: var(--bg); border-color: transparent; }
.pos-F { color: var(--accent); }
.pos-D { color: var(--warn); }
.pos-G { color: var(--mine); }

@media (max-width: 560px) {
  .hide-sm { display: none; }
  th, td { padding: 7px 5px; }
  body { font-size: 14px; }
}

.more { display: block; margin: 12px auto 0; }

/* ---------- My team ---------- */
.roster { display: grid; gap: 6px; }
.slot {
  display: grid; grid-template-columns: 52px 1fr auto; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px;
}
.slot.empty { border-style: dashed; color: var(--muted); background: transparent; }
.slot .tag { font-weight: 700; font-size: 12px; color: var(--muted); }
.slot .who { font-weight: 600; cursor: pointer; }
.needs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.stat-row { display: flex; flex-wrap: wrap; gap: 8px 18px; margin: 4px 0 8px; font-size: 14px; }

/* ---------- Recent ---------- */
.recent li { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
.recent li .when { font-size: 12px; color: var(--muted); }

/* ---------- Dialogs ---------- */
.sheet {
  border: none; border-radius: 16px; padding: 18px; width: min(460px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
.sheet::backdrop { background: rgba(0, 0, 0, 0.45); }
.sheet h2 { margin: 0 0 4px; font-size: 20px; }
.sheet form { display: grid; gap: 12px; }
.sheet form label { display: grid; gap: 4px; font-weight: 600; font-size: 14px; }
.sheet form label.toggle { display: flex; }
.sheet-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.sheet-actions .btn { flex: 1; min-width: 90px; }
.detail { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.detail div { background: var(--surface-2); border-radius: 8px; padding: 6px 8px; }
.detail span { display: block; font-size: 11px; color: var(--muted); }
.detail b { font-variant-numeric: tabular-nums; }
.note { margin-top: 10px; font-size: 14px; }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 50;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  box-shadow: var(--shadow); font-weight: 600; max-width: calc(100vw - 32px);
}
.toast button { background: none; border: none; color: inherit; text-decoration: underline; cursor: pointer; font-weight: 700; margin-left: 10px; }
.text-btn { font-size: 13px; color: var(--muted); text-decoration: none; padding: 6px 4px; }
.espn-btn { white-space: nowrap; border: 1px solid var(--border); border-radius: 8px; height: 34px; padding: 0 8px; background: none; cursor: pointer; font-weight: 600; color: var(--accent); }
.espn-btn.busy { opacity: 0.55; pointer-events: none; }
.espn-status { font-size: 12px; color: var(--muted); margin-top: 4px; padding: 0 2px; }
.espn-status.err { color: var(--danger); font-weight: 600; }
.dlg-sub { margin: 6px 0 -4px; font-size: 15px; }
.unmatched { margin-bottom: 12px; border-color: var(--warn); }
.unmatched li { cursor: default; }

/* ---------- Paste + rosters ---------- */
textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font: 13px/1.35 ui-monospace, SFMono-Regular, Menlo, monospace; resize: vertical;
}
.paste-result { max-height: 40vh; overflow-y: auto; margin-top: 10px; font-size: 14px; }
.paste-result p { margin: 4px 0; }
.paste-list { list-style: none; margin: 8px 0 0; padding: 0; }
.paste-list li { display: grid; grid-template-columns: 38px 1fr auto; gap: 8px; align-items: center; padding: 5px 0; border-top: 1px solid var(--border); }
.paste-list li.same { opacity: 0.55; }
.team-pick { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 12px; }
.chip {
  border: 1px solid var(--border); background: var(--surface-2); border-radius: 999px; padding: 5px 10px;
  font-size: 13px; font-weight: 600; cursor: pointer;
}
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
tr.sel td { background: var(--accent-soft); }
.badge.slp { background: #fde68a; color: #7c4a03; border-color: transparent; }
@media (prefers-color-scheme: dark) { .badge.slp { background: #4a3a0c; color: #fcd34d; } }
.slp-card { border-color: #f5c542; margin-bottom: 4px; }

/* ---------- Pool switcher ---------- */
.pool-switch { display: flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 2px; }
.pool-switch a {
  padding: 5px 10px; border-radius: 8px; text-decoration: none; color: var(--muted);
  font-weight: 700; font-size: 14px; white-space: nowrap;
}
.pool-switch a.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }

/* ---------- NFL ---------- */
select {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font: inherit;
}
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.two-col label { display: grid; gap: 4px; font-weight: 600; font-size: 14px; }
#import .two-col { margin: 6px 0 4px; }
code { font-size: 12px; background: var(--surface-2); padding: 1px 4px; border-radius: 4px; }
.nfl-cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 720px) { .nfl-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 420px) { .nfl-cards { grid-template-columns: 1fr; } }
.cards.two { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 10px; }
@media (max-width: 720px) { .cards.two { grid-template-columns: 1fr; } }
.card h3 span:first-child { font-weight: 700; }

.board-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.board { border-collapse: collapse; font-size: 12px; min-width: 760px; }
.board th, .board td { border: 1px solid var(--border); padding: 5px 6px; text-align: left; vertical-align: top; white-space: normal; }
.board thead th { position: static; font-size: 11px; max-width: 110px; }
.board td { min-width: 92px; cursor: pointer; }
.board td b { display: block; font-size: 12px; line-height: 1.2; }
.board td span { display: block; }
.board .me { background: var(--mine-soft); }
.board .clock-cell { outline: 2px solid var(--clock); outline-offset: -2px; }
.board .g-QB { box-shadow: inset 3px 0 0 #8b5cf6; }
.board .g-RB { box-shadow: inset 3px 0 0 #10b981; }
.board .g-WRTE { box-shadow: inset 3px 0 0 #3b82f6; }
.board .g-PK, .board .g-Def, .board .g-Coach { box-shadow: inset 3px 0 0 #9ca3af; }
.text-btn { white-space: nowrap; }
@media (max-width: 420px) { .topbar-row { gap: 6px; } .pool-switch a { padding: 5px 7px; } }
