:root {
  color-scheme: light dark;
  --page: 40rem;
  --bg: #f4f6f8;
  --surface: #fff;
  --surface-2: #f0f2f5;
  --text: #15181d;
  --muted: #5d6674;
  --line: #dde2e8;
  --line-strong: #c3cbd6;
  --accent: #1559c7;
  --accent-soft: #e8f0fe;
  --good: #166534;
  --warn: #9a3412;
  --danger: #b42318;
  --radius: 12px;
  --tap: 44px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1014;
    --surface: #181b21;
    --surface-2: #20242c;
    --text: #e7eaee;
    --muted: #9aa4b2;
    --line: #2b313a;
    --line-strong: #3a424e;
    --accent: #7fb0ff;
    --accent-soft: #1b2740;
    --good: #86efac;
    --warn: #fdba74;
    --danger: #fca5a5;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  padding-bottom: calc(4rem + env(safe-area-inset-bottom));
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow-wrap: break-word;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; }
p { margin: 0 0 0.6rem; }
p:last-child { margin-bottom: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.muted-note { color: var(--muted); font-size: 0.85rem; }
.num, .points { font-variant-numeric: tabular-nums; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- shell ---------- */

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  padding: 0.55rem 0.9rem;
  padding-top: calc(0.55rem + env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 650; text-decoration: none; color: var(--text); }
.logout { display: flex; align-items: center; gap: 0.5rem; margin: 0; min-width: 0; }
.who {
  color: var(--muted); font-size: 0.9rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 9rem;
}
.logout button { min-height: 36px; padding: 0 0.6rem; font-size: 0.85rem; }
.login-link {
  min-height: 36px; padding: 0 0.7rem;
  display: inline-flex; align-items: center;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  text-decoration: none; font-size: 0.9rem;
}

main { max-width: var(--page); margin: 0 auto; padding: 0.75rem 0.75rem 1rem; }

.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 10;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; min-height: 52px;
  display: flex; align-items: center; justify-content: center;
  text-decoration: none; color: var(--muted); font-size: 0.85rem;
}
.tab-active { color: var(--accent); font-weight: 600; box-shadow: inset 0 2px 0 var(--accent); }

/* ---------- primitives ---------- */

button, .btn {
  min-height: var(--tap); padding: 0 0.9rem;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font: inherit; text-decoration: none; cursor: pointer;
}
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--danger); }
button[disabled], .btn[disabled] { opacity: 0.55; cursor: default; }
button.block, .btn.block { width: 100%; }

input[type="text"], input[type="search"], input[type="password"], select {
  min-height: var(--tap); width: 100%;
  padding: 0 0.7rem;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text); font: inherit;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0.85rem; margin: 0 0 0.75rem;
}
.card-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 0.75rem; margin-bottom: 0.55rem;
}
.card-head h2 { margin: 0; font-size: 1.05rem; }
.card-flush { padding: 0; overflow: hidden; }
.card-flush .card-head { padding: 0.85rem 0.85rem 0; }

.flash {
  margin: 0 0 0.75rem; padding: 0.6rem 0.8rem;
  border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: var(--radius); background: var(--surface);
}
.flash-error { border-left-color: var(--danger); color: var(--danger); }

.badge {
  display: inline-block; padding: 0.05rem 0.45rem;
  border: 1px solid var(--line-strong); border-radius: 999px;
  font-size: 0.72rem; line-height: 1.5; color: var(--muted); white-space: nowrap;
}
.badge-open { border-color: var(--accent); color: var(--accent); }
.badge-locked { background: var(--surface-2); }
.badge-hidden { background: var(--surface-2); }
.badge-live { border-color: var(--warn); color: var(--warn); }
.badge-bye { border-color: var(--warn); color: var(--warn); }
.badge-injury { border-color: var(--danger); color: var(--danger); }
.badge-warn { border-color: var(--warn); color: var(--warn); }
.badge-good { border-color: var(--good); color: var(--good); }
.badge-me { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

.points { font-weight: 650; }
.points-empty { color: var(--muted); font-weight: 500; }
.breakdown > summary {
  display: flex; align-items: center; justify-content: flex-end;
  min-height: 34px; padding: 0 0.1rem;
  cursor: pointer; list-style: none;
}
.breakdown > summary::-webkit-details-marker { display: none; }
.breakdown > summary::after {
  content: "▾"; margin-left: 0.3rem; color: var(--muted); font-size: 0.7rem;
}
.breakdown[open] > summary::after { content: "▴"; }
.breakdown-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.breakdown-table td { padding: 0.2rem 0; border-top: 1px solid var(--line); color: var(--muted); }
.breakdown-table td.num { text-align: right; color: var(--text); padding-left: 0.75rem; white-space: nowrap; }
.breakdown-table td:first-child { padding-right: 0.5rem; text-align: left; }
/* An open breakdown takes the slot's full width on its own row instead of squeezing
   the player name into the points column. */
.slot:has(.breakdown[open]) .slot-side { grid-column: 1 / -1; min-width: 0; }
.slot:has(.breakdown[open]) .breakdown-table { margin-top: 0.2rem; }

.empty { padding: 1.1rem 0.5rem; text-align: center; color: var(--muted); }
.empty-title { margin: 0 0 0.35rem; font-weight: 600; color: var(--text); }

.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.row-between { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; }
.stack { display: grid; gap: 0.5rem; }

/* ---------- week navigation ---------- */

.weeknav { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.weeknav .btn, .weeknav .btn-ghost {
  min-width: 3.4rem; min-height: var(--tap);
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius); text-decoration: none;
}
.weeknav .btn-ghost { border: 1px solid transparent; color: var(--muted); }
.weeknav-label { font-weight: 650; }
.weeknav-sub { display: block; font-weight: 400; font-size: 0.78rem; color: var(--muted); text-align: center; }

/* ---------- lineup card ---------- */

.total {
  display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem;
  padding-bottom: 0.6rem; margin-bottom: 0.2rem; border-bottom: 1px solid var(--line);
}
.total-label { color: var(--muted); font-size: 0.9rem; }
.total-points { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.total-asof { margin: 0.25rem 0 0; }

.slots { display: grid; }
.slot {
  display: grid;
  grid-template-columns: 3.1rem minmax(0, 1fr) auto;
  align-items: center; gap: 0.1rem 0.55rem;
  min-height: 56px; padding: 0.5rem 0;
  border-top: 1px solid var(--line);
}
.slots > .slot:first-child { border-top: 0; }
.slot-chip {
  justify-self: start;
  padding: 0.15rem 0.4rem; border-radius: 6px;
  background: var(--surface-2); color: var(--muted);
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.02em;
}
.slot-main { min-width: 0; }
.slot-name { font-weight: 600; }
.slot-sub { display: block; color: var(--muted); font-size: 0.82rem; }
.slot-side { justify-self: end; text-align: right; min-width: 4.4rem; }
.slot-pick {
  grid-column: 2 / span 2;
  display: inline-flex; align-items: center; min-height: var(--tap);
  color: var(--accent); text-decoration: none; font-weight: 600;
}
.slot-badges { display: flex; flex-wrap: wrap; gap: 0.25rem; margin-top: 0.15rem; }
.slot-locked .slot-name { color: var(--muted); }
.slot-link {
  display: block; min-height: var(--tap);
  padding: 0.3rem 0; text-decoration: none; color: inherit;
}
a.slot-link .slot-name { color: var(--accent); }

/* ---------- picker ---------- */

.picker-body { padding: 0 0.85rem; }
.picker-search { display: flex; gap: 0.5rem; margin-bottom: 0.55rem; }
.picker-search button { flex: none; }
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.55rem; }
.chip {
  min-height: 36px; padding: 0 0.7rem;
  display: inline-flex; align-items: center;
  border: 1px solid var(--line-strong); border-radius: 999px;
  text-decoration: none; color: var(--text); font-size: 0.88rem;
}
.chip-active { background: var(--accent); border-color: var(--accent); color: #fff; }
.picker-hint { color: var(--muted); font-size: 0.82rem; margin: 0 0 0.5rem; }

.picks { display: grid; padding: 0 0.85rem; }
.pick { margin: 0; border-top: 1px solid var(--line); }
.picks > .pick:first-child { border-top: 0; }
.pick-row {
  width: 100%; min-height: 58px; padding: 0.5rem 0.1rem;
  display: grid; grid-template-columns: minmax(0, 1fr) auto;
  align-items: center; gap: 0.1rem 0.5rem; text-align: left;
  border: 0; border-radius: 0; background: none;
}
.pick-row[disabled] { opacity: 1; color: var(--muted); }
.pick-ident { min-width: 0; }
.pick-name { font-weight: 600; }
.pick-row[disabled] .pick-name { color: var(--muted); font-weight: 500; }
.pick-sub { display: block; color: var(--muted); font-size: 0.82rem; }
.pick-side { text-align: right; white-space: nowrap; }
.pick-pts { font-variant-numeric: tabular-nums; font-weight: 650; }
.pick-avg { display: block; color: var(--muted); font-size: 0.78rem; }
.pick-reason { display: block; margin-top: 0.1rem; }
.pick-current { background: var(--accent-soft); }

/* ---------- week page ---------- */

.gamebar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem;
  color: var(--muted); font-size: 0.85rem;
}
.user-card { border-left: 3px solid transparent; }
.user-card-me { border-left-color: var(--accent); }
.user-head {
  display: grid; grid-template-columns: 2.2rem minmax(0, 1fr) auto;
  align-items: center; gap: 0.55rem;
  padding-bottom: 0.5rem; border-bottom: 1px solid var(--line);
}
.user-rank { font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.user-name { font-weight: 650; min-width: 0; }
.user-total { text-align: right; font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.hidden-pick { color: var(--muted); }
.dash { color: var(--muted); }

/* ---------- leaderboard ---------- */

table.grid { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
table.grid th, table.grid td { padding: 0.45rem 0.4rem; text-align: left; white-space: nowrap; }
table.grid thead th {
  color: var(--muted); font-size: 0.75rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.03em;
  border-bottom: 1px solid var(--line-strong);
}
table.grid tbody th { border-bottom: 1px solid var(--line); }
table.grid td { border-bottom: 1px solid var(--line); }
table.grid tbody tr:last-child td { border-bottom: 0; }
table.grid td.num, table.grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.grid td.name { white-space: normal; min-width: 7rem; }
table.grid tr.me td { background: var(--accent-soft); }
table.grid th:first-child, table.grid td:first-child { padding-left: 0.85rem; }
/* The grid is wider than a phone and is the one thing allowed to scroll sideways, so
   the week label has to travel with it — otherwise the numbers lose their row.
   Collapsed borders don't follow a sticky cell, hence the box-shadow. */
table.grid th:first-child, table.grid td:first-child {
  position: sticky; left: 0; z-index: 1;
  background: var(--surface); box-shadow: 1px 0 0 var(--line);
}
table.grid th:last-child, table.grid td:last-child { padding-right: 0.85rem; }
.history-week { font-weight: 650; }
.history-week .slot-sub { font-size: 0.72rem; }
.crown { white-space: nowrap; }

/* ---------- forms, key/value blocks, admin lists (auth + admin screens) ---------- */

input[type="number"] {
  min-height: var(--tap); width: 100%;
  padding: 0 0.7rem;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text); font: inherit;
}
input[type="checkbox"] { width: 1.15rem; height: 1.15rem; min-height: 0; margin: 0; }

.field { display: grid; gap: 0.2rem; }
.field-label { color: var(--muted); font-size: 0.85rem; }
.field-inline { display: inline-flex; align-items: center; gap: 0.4rem; }
.field-inline input { width: 4.5rem; }

.form-inline { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; margin: 0; }
.form-inline input[type="text"] { width: 7rem; }
.confirm {
  display: inline-flex; align-items: center; gap: 0.35rem;
  min-height: var(--tap);
  color: var(--muted); font-size: 0.8rem;
}

.kv { display: grid; grid-template-columns: auto 1fr; gap: 0.15rem 0.75rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; }

.admin-list { list-style: none; margin: 0; padding: 0; }
.admin-item { padding: 0.65rem 0; border-top: 1px solid var(--line); }
.admin-item:first-child { border-top: 0; padding-top: 0; }
.admin-name { font-weight: 650; }
.admin-tags { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.admin-actions { display: flex; align-items: center; gap: 0.45rem; flex-wrap: wrap; margin-top: 0.4rem; }
.admin-detail {
  margin: 0.3rem 0 0; color: var(--muted); font-size: 0.8rem;
  overflow-wrap: anywhere;
}