:root {
  color-scheme: dark;
  --bg: #0d1117;
  --bg-soft: #151b23;
  --card: #161d26;
  --card-2: #1c242f;
  --line: #263140;
  --text: #e6edf3;
  --dim: #94a3b8;
  --dimmer: #64748b;
  --accent: #38bdf8;
  --accent-ink: #04222f;
  --win: #34d399;
  --loss: #f87171;
  --warn: #fbbf24;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --tint-win-bg: #0d2f26;
  --tint-win-border: #14503f;
  --tint-loss-bg: #2f1416;
  --tint-loss-border: #5c2327;
  --tint-warn-bg: #33270a;
  --tint-warn-border: #5e4715;
  --tint-info-bg: #10293a;
  --tint-info-border: #1d4a66;
  --row-hover: #1a222d;
  --row-me: #14202b;
  --input-bg: #0f151d;
  --topbar-grad-1: #121821;
  --topbar-grad-2: #0f141c;
  --out-link: #7dd3fc99;
  --focus-ring: #1d5f80;
  --focus-border: #2f7fa6;
}

/* Light palette: applied when the OS prefers light and no explicit dark
   choice has been made, or when the toggle explicitly sets data-theme="light". */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f7f8fa;
    --bg-soft: #eef1f5;
    --card: #ffffff;
    --card-2: #eef1f5;
    --line: #dbe1e8;
    --text: #1a2028;
    --dim: #56616f;
    --dimmer: #8894a1;
    --accent: #0284c7;
    --accent-ink: #ffffff;
    --win: #16a34a;
    --loss: #dc2626;
    --warn: #b45309;

    --tint-win-bg: #dcfce7;
    --tint-win-border: #86efac;
    --tint-loss-bg: #fee2e2;
    --tint-loss-border: #fca5a5;
    --tint-warn-bg: #fef3c7;
    --tint-warn-border: #fde68a;
    --tint-info-bg: #e0f2fe;
    --tint-info-border: #93c5fd;
    --row-hover: #f1f5f9;
    --row-me: #e0f2fe;
    --input-bg: #ffffff;
    --topbar-grad-1: #ffffff;
    --topbar-grad-2: #f3f4f6;
    --out-link: #0369a1aa;
    --focus-ring: #7dd3fc;
    --focus-border: #38bdf8;
  }
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f7f8fa;
  --bg-soft: #eef1f5;
  --card: #ffffff;
  --card-2: #eef1f5;
  --line: #dbe1e8;
  --text: #1a2028;
  --dim: #56616f;
  --dimmer: #8894a1;
  --accent: #0284c7;
  --accent-ink: #ffffff;
  --win: #16a34a;
  --loss: #dc2626;
  --warn: #b45309;

  --tint-win-bg: #dcfce7;
  --tint-win-border: #86efac;
  --tint-loss-bg: #fee2e2;
  --tint-loss-border: #fca5a5;
  --tint-warn-bg: #fef3c7;
  --tint-warn-border: #fde68a;
  --tint-info-bg: #e0f2fe;
  --tint-info-border: #93c5fd;
  --row-hover: #f1f5f9;
  --row-me: #e0f2fe;
  --input-bg: #ffffff;
  --topbar-grad-1: #ffffff;
  --topbar-grad-2: #f3f4f6;
  --out-link: #0369a1aa;
  --focus-ring: #7dd3fc;
  --focus-border: #38bdf8;
}

* { box-sizing: border-box; }

/* Without this, a horizontal swipe that starts on an inner scroller (.nav, .table-scroll)
   can hand off to the page itself once that scroller hits its edge, panning the whole
   viewport sideways. Containing it here plus overscroll-behavior on those scrollers keeps
   the swipe confined to the control the user is actually touching. */
html { overflow-x: hidden; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { max-width: 1400px; margin: 0 auto; padding: 0 18px; }

/* ---------- top bar ---------- */

.topbar {
  background: linear-gradient(180deg, var(--topbar-grad-1), var(--topbar-grad-2));
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 58px;
  flex-wrap: wrap;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 17px;
  color: var(--text);
}
.brand:hover { text-decoration: none; }
.brand-mark {
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 6px;
  padding: 3px 7px;
  font-size: 13px;
  letter-spacing: 0.5px;
}
/* Always a single swipeable/scrollable row - never wraps, never overflows the page, regardless
   of viewport width or zoom. Edge fade + scroll-snap read as an intentional slider. */
.nav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
  overscroll-behavior-x: contain;
  -webkit-mask-image: linear-gradient(to right, transparent, black 14px, black calc(100% - 14px), transparent);
  mask-image: linear-gradient(to right, transparent, black 14px, black calc(100% - 14px), transparent);
}
.nav::-webkit-scrollbar { display: none; }
.nav a, .linkish {
  padding: 7px 11px;
  border-radius: 7px;
  color: var(--dim);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  scroll-snap-align: start;
}
.nav a:hover, .linkish:hover { background: var(--card-2); color: var(--text); text-decoration: none; }
.nav a.on { background: var(--card-2); color: var(--text); }
.linkish {
  background: none;
  border: 0;
  cursor: pointer;
  font: inherit;
  font-weight: 500;
}
form.inline { display: inline; }

/* ---------- layout pieces ---------- */

main.wrap { padding-top: 22px; padding-bottom: 48px; }

h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: -0.2px; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 8px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--dim); }
p { margin: 0 0 12px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
}
.card.narrow { max-width: 520px; margin-left: auto; margin-right: auto; }
.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.dim { color: var(--dim); }
.dimmer { color: var(--dimmer); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.stack > * + * { margin-top: 10px; }

/* ---------- stats ---------- */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; }
.stat {
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.stat .k { font-size: 12px; text-transform: uppercase; letter-spacing: 0.7px; color: var(--dim); }
.stat .v { font-size: 22px; font-weight: 700; margin-top: 3px; }
.stat .v.sm { font-size: 16px; }

/* ---------- tables ---------- */

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--dim);
  font-weight: 600;
  white-space: nowrap;
}
tbody tr:hover { background: var(--row-hover); }
tr.is-out td { color: var(--dimmer); }
tr.is-out td a { color: var(--out-link); }
tr.me { background: var(--row-me); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- user list (admin players) ---------- */

.user-list > * + * { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.user-row.is-out, .user-row.is-out a { color: var(--dimmer); }
.user-row-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.user-id { flex: 1 1 220px; min-width: 0; }
.user-row-stats { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex: 0 1 auto; }
.mini-stats { display: flex; gap: 14px; flex-wrap: wrap; justify-content: flex-end; }
.mini-stats strong { color: var(--text); }
@media (max-width: 620px) {
  .user-row-stats { align-items: flex-start; width: 100%; }
  .mini-stats { justify-content: flex-start; }
}

/* ---------- badges / pills ---------- */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge-alive { background: var(--tint-win-bg); color: var(--win); border-color: var(--tint-win-border); }
.badge-out { background: var(--tint-loss-bg); color: var(--loss); border-color: var(--tint-loss-border); }
.badge-warn { background: var(--tint-warn-bg); color: var(--warn); border-color: var(--tint-warn-border); }
.badge-info { background: var(--tint-info-bg); color: var(--accent); border-color: var(--tint-info-border); }
.badge-flat { background: var(--card-2); color: var(--dim); border-color: var(--line); }

.pick-cell { font-family: var(--mono); font-weight: 600; font-size: 13px; }
.res-win { color: var(--win); }
.res-loss { color: var(--loss); }
.res-tie { color: var(--warn); }
.res-pending { color: var(--dim); }
.hidden-pick { color: var(--dimmer); letter-spacing: 2px; }

/* ---------- forms ---------- */

label { display: block; font-size: 13px; color: var(--dim); margin-bottom: 5px; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=datetime-local], select, textarea {
  width: 100%;
  padding: 10px 11px;
  background: var(--input-bg);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  font-family: inherit;
  font-size: 16px; /* iOS Safari zooms the page when a focused field is under 16px */
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus-ring); border-color: var(--focus-border); }
textarea { min-height: 110px; resize: vertical; }
.field { margin-bottom: 14px; }
.field-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.field-row > * { flex: 1 1 150px; }
.check { display: flex; align-items: flex-start; gap: 9px; margin-bottom: 12px; }
.check input { width: 16px; height: 16px; margin-top: 2px; flex: none; }
.check label { margin: 0; color: var(--text); font-size: 14px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 0 0 16px; }
legend { padding: 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.7px; color: var(--dim); }

.btn {
  display: inline-block;
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  border-radius: 8px;
  padding: 9px 15px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-ghost { background: var(--card-2); color: var(--text); border: 1px solid var(--line); }
.btn-danger { background: var(--tint-loss-bg); color: var(--loss); border: 1px solid var(--tint-loss-border); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.badge-row { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- flash ---------- */

.flash {
  border-radius: var(--radius);
  padding: 11px 14px;
  margin-bottom: 16px;
  border: 1px solid;
  font-size: 14px;
}
.flash-success { background: var(--tint-win-bg); border-color: var(--tint-win-border); color: var(--win); }
.flash-error { background: var(--tint-loss-bg); border-color: var(--tint-loss-border); color: var(--loss); }
.flash-warn { background: var(--tint-warn-bg); border-color: var(--tint-warn-border); color: var(--warn); }
.errors { margin: 0 0 14px; padding: 11px 14px 11px 30px; background: var(--tint-loss-bg); border: 1px solid var(--tint-loss-border); border-radius: var(--radius); color: var(--loss); }
.errors li { margin: 2px 0; }

/* ---------- games ---------- */

.games { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.game {
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 13px;
}
.game .when { font-size: 12px; color: var(--dim); margin-bottom: 7px; display: flex; justify-content: space-between; gap: 8px; }
.game .team { display: flex; justify-content: space-between; gap: 10px; padding: 2px 0; }
.game .team.w { font-weight: 700; }
.game .team.l { color: var(--dimmer); }
.game .score { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.game .takers { margin-top: 8px; border-top: 1px dashed var(--line); padding-top: 7px; font-size: 12px; color: var(--dim); }

/* ---------- pick options ---------- */

.picker { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.opt { position: relative; }
.opt input { position: absolute; opacity: 0; pointer-events: none; }
.opt label {
  display: block;
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card-2);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
}
.opt label:hover { border-color: var(--tint-info-border); }
.opt input:checked + label { border-color: var(--accent); background: var(--tint-info-bg); box-shadow: 0 0 0 1px var(--accent) inset; }
.opt input:disabled + label { opacity: 0.45; cursor: not-allowed; }
.opt .vs { display: block; font-size: 12px; color: var(--dim); margin-top: 3px; }

/* ---------- week tabs ---------- */

.weektabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.weektabs a {
  padding: 6px 11px;
  border-radius: 7px;
  background: var(--card-2);
  border: 1px solid var(--line);
  color: var(--dim);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.weektabs a.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.weektabs a:hover { text-decoration: none; color: var(--text); }
.weektabs a.on:hover { color: var(--accent-ink); }

/* ---------- misc ---------- */

details.admin-row { margin: 6px 0 0; }
details.admin-row summary { cursor: pointer; color: var(--accent); font-size: 13px; }
details.admin-row > div { margin-top: 9px; padding: 11px; background: var(--bg-soft); border: 1px solid var(--line); border-radius: 8px; }

.foot {
  border-top: 1px solid var(--line);
  padding: 18px 0 30px;
  color: var(--dimmer);
  font-size: 13px;
}
.foot .wrap { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--dim); }

/* ---------- announcements ---------- */

.announce-feed .announce + .announce {
  border-top: 1px solid var(--line);
  margin-top: 16px;
  padding-top: 16px;
}
.announce { position: relative; }
.announce.pinned {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  margin-left: -12px;
}
.announce-title {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 0 0 8px;
  font-size: 17px;
  color: var(--text);
  text-transform: none;
  letter-spacing: 0;
}
.announce p { margin: 0 0 9px; }
.announce p:last-of-type { margin-bottom: 0; }
.announce-meta { font-size: 12px; color: var(--dimmer); margin: 9px 0 0; }

/* ---------- sticky first column ----------
   The standings grid is 20+ columns once the season is under way. Pinning the player
   name means you can scroll the weeks sideways and still know whose row you are on. */

table.sticky-first th:first-child,
table.sticky-first td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--card);
}
table.sticky-first tbody tr:hover td:first-child { background: var(--row-hover); }
table.sticky-first tbody tr.me td:first-child { background: var(--row-me); }
table.sticky-first th:first-child { z-index: 3; }
table.sticky-first th:first-child::after,
table.sticky-first td:first-child::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 1px;
  background: var(--line);
}

/* ---------- mobile ----------
   Roughly half the pool is on a phone, so every control is at least 44px tall and
   nothing but designated scrollers may scroll sideways. */

@media (max-width: 760px) {
  .wrap { padding: 0 14px; padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right)); }
  main.wrap { padding-top: 16px; padding-bottom: 40px; }

  .topbar-inner { flex-direction: column; align-items: stretch; gap: 8px; padding-top: 10px; padding-bottom: 10px; min-height: 0; }
  .brand { font-size: 16px; }
  .nav { gap: 2px; }
  .nav a, .linkish { padding: 10px 12px; min-height: 44px; display: flex; align-items: center; }

  h1 { font-size: 20px; }
  h2 { font-size: 17px; }
  .card { padding: 14px; margin-bottom: 14px; }
  .card-head { gap: 10px; }

  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat .v { font-size: 20px; }

  .grid.two, .grid.three { grid-template-columns: minmax(0, 1fr); }
  .games, .picker { grid-template-columns: minmax(0, 1fr); }

  /* Full-width, thumb-sized tap targets */
  .btn { min-height: 44px; padding: 11px 16px; }
  .btn-sm { min-height: 38px; padding: 8px 12px; }
  .btn-row { gap: 10px; }
  .opt label { padding: 13px 14px; min-height: 52px; }
  details.admin-row summary { min-height: 40px; display: flex; align-items: center; }

  th, td { padding: 8px 7px; font-size: 13px; }
  .table-scroll { margin: 0 -14px; padding: 0 14px; }

  .weektabs { gap: 5px; }
  .weektabs a { min-width: 38px; min-height: 38px; display: flex; align-items: center; justify-content: center; padding: 6px 8px; }

  .field-row { gap: 10px; }
  .field-row > * { flex: 1 1 100%; }
  .legend { gap: 10px; }
  .foot .wrap { flex-direction: column; gap: 6px; }
}

@media (max-width: 420px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .brand-mark { display: none; }
  th, td { padding: 7px 6px; font-size: 12.5px; }
}

/* Respect reduced-motion and coarse pointers */
@media (hover: none) {
  tbody tr:hover { background: none; }
  table.sticky-first tbody tr:hover td:first-child { background: var(--card); }
}

/* ---------- print (Standings only, one page) ---------- */

@media print {
  @page { size: landscape; margin: 0.4in; }

  /* Force the light, print-safe palette regardless of the viewer's dark/light preference -
     without it, dark-theme text (meant to sit on a near-black page) would print near-invisible
     on white paper, since browsers skip background colors in print by default. */
  :root {
    color-scheme: light;
    --bg: #ffffff; --bg-soft: #ffffff; --card: #ffffff; --card-2: #f3f4f6;
    --line: #dbe1e8; --text: #1a2028; --dim: #56616f; --dimmer: #8894a1;
    --win: #16a34a; --loss: #dc2626; --warn: #b45309;
    --tint-win-bg: #dcfce7; --tint-win-border: #86efac;
    --tint-loss-bg: #fee2e2; --tint-loss-border: #fca5a5;
    --tint-warn-bg: #fef3c7; --tint-warn-border: #fde68a;
    --tint-info-bg: #e0f2fe; --tint-info-border: #93c5fd;
    --row-hover: #f1f5f9; --row-me: #e0f2fe;
  }
  html, body { background: #fff; }

  body * { visibility: hidden; }
  .standings-print, .standings-print * { visibility: visible; }
  .standings-print {
    position: absolute; left: 0; top: 0; width: 100%;
    margin: 0; border: 0; box-shadow: none; padding: 0; background: #fff;
  }
  .no-print { display: none !important; }
  .standings-print .table-scroll { overflow: visible; }
  .standings-print table.sticky-first th:first-child,
  .standings-print table.sticky-first td:first-child { position: static; }
  .standings-print table { font-size: 11px; }
  .standings-print th, .standings-print td { padding: 3px 6px; }
  .standings-print * {
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
}
