:root {
  --bg: #f4f6f8; --card: #ffffff; --ink: #172029; --muted: #5d6a78; --line: #e1e6eb;
  --accent: #0b6bcb; --accent-ink: #ffffff; --accent-soft: #e6f0fb;
  --good: #17803d; --bad: #c62828; --warn: #8a5d00; --you: #fff7d6;
  --radius: 12px; --header-h: 96px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216; --card: #171b21; --ink: #e7eaee; --muted: #9aa5b1; --line: #29313a;
    --accent: #4ea1ff; --accent-ink: #08131f; --accent-soft: #19283a;
    --good: #4cc26a; --bad: #ff6b6b; --warn: #e3b341; --you: #2b2a17;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom);
}
[hidden] { display: none !important; }
h1, h2 { margin: 0; }
h2 { font-size: 1.1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Header with tabs; sticks to the top, clear of the notch. */
.top {
  position: sticky; top: 0; z-index: 20; background: var(--card); border-bottom: 1px solid var(--line);
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
}
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; max-width: 760px; margin: 0 auto; }
.top h1 { font-size: 1.25rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who { display: flex; align-items: center; gap: 8px; font-size: .9rem; color: var(--muted); min-width: 0; }
.who span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tabs { display: flex; gap: 4px; max-width: 760px; margin: 0 auto; }
.tabs a {
  flex: 1; text-align: center; padding: 10px 8px 12px; color: var(--muted); text-decoration: none;
  font-weight: 600; border-bottom: 3px solid transparent; min-height: 44px;
}
.tabs a[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); }

main {
  max-width: 760px; margin: 0 auto;
  padding: 16px max(16px, env(safe-area-inset-right)) 48px max(16px, env(safe-area-inset-left));
}
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card.flush { padding: 0; overflow: hidden; }
.card-head { padding: 14px 16px 10px; }
.pad { padding: 0 16px 14px; margin: 0; }
.stack { display: grid; gap: 12px; }
.section-title { margin: 24px 4px 10px; }
.loading { text-align: center; color: var(--muted); padding: 40px 0; }
.error-card { border-color: var(--bad); color: var(--bad); }

/* Forms. 16px inputs stop iPhone Safari zooming in on focus. */
label { display: block; font-weight: 600; font-size: .9rem; margin: 14px 0 6px; }
input, select, button { font: inherit; font-size: 16px; }
input[type="text"], select {
  width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--ink); appearance: none; -webkit-appearance: none;
}
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat;
  padding-right: 34px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.primary {
  display: block; width: 100%; min-height: 48px; margin-top: 18px; border: 0; border-radius: 10px;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; cursor: pointer;
}
.primary:disabled { opacity: .6; }
.link { background: none; border: 0; color: var(--accent); padding: 8px 4px; font-size: .9rem; cursor: pointer; }
.form-error { color: var(--bad); margin: 12px 0 0; }
#join-form p.muted { margin: 8px 0 4px; }

/* League view */
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.toolbar select { flex: 0 0 auto; width: auto; min-width: 9.5rem; }
.toolbar .small { flex: 1; text-align: right; }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.standings { border-collapse: separate; border-spacing: 0; width: 100%; font-variant-numeric: tabular-nums; }
.standings th, .standings td { padding: 10px 10px; text-align: right; white-space: nowrap; border-top: 1px solid var(--line); }
.standings thead th { border-top: 0; font-size: .75rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
/* Team and Total stay put while the weekly columns scroll sideways. */
.standings .team {
  position: sticky; left: 0; z-index: 1; background: var(--card); text-align: left;
  width: 8.5rem; min-width: 8.5rem; max-width: 8.5rem; overflow: hidden; text-overflow: ellipsis;
}
.standings .total {
  position: sticky; left: 8.5rem; z-index: 1; background: var(--card); box-shadow: 1px 0 0 var(--line);
}
.standings .rank { color: var(--muted); display: inline-block; min-width: 1.6em; }
.standings .total { font-weight: 700; }
.standings .sel { background: var(--accent-soft); }
.standings tr.you td, .standings tr.you .team, .standings tr.you .total { background: var(--you); }
.standings td.none { color: var(--muted); }

.team-card { padding: 0; overflow: hidden; }
.team-card.you { box-shadow: inset 4px 0 0 var(--accent); }
.team-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.team-id { min-width: 0; }
.team-head .name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.team-head .pts { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.no-lineup { padding: 12px 16px; margin: 0; }

details.line { border-bottom: 1px solid var(--line); }
details.line:last-child { border-bottom: 0; }
details.line summary {
  list-style: none; display: flex; gap: 10px; align-items: center; padding: 10px 16px; min-height: 52px; cursor: pointer;
}
details.line summary::-webkit-details-marker { display: none; }
.tag {
  flex: none; width: 3.4rem; text-align: center; font-size: .7rem; font-weight: 700; letter-spacing: .02em;
  padding: 4px 0; border-radius: 6px; background: var(--accent-soft); color: var(--accent);
}
.line-who { flex: 1; min-width: 0; }
.line-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.line-meta { color: var(--muted); font-size: .8rem; }
.line-note { font-size: .78rem; color: var(--warn); }
.line.error .line-note { color: var(--bad); }
.line-pts { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 3.2rem; text-align: right; }
.line:not(.ok) .line-pts { color: var(--muted); }
.breakdown { width: 100%; border-collapse: collapse; font-size: .85rem; margin: 0 0 10px; font-variant-numeric: tabular-nums; }
.breakdown td { padding: 3px 16px 3px 80px; }
.breakdown td + td { padding-left: 8px; text-align: right; width: 4.5rem; }

/* Lineup form */
.slots { display: grid; gap: 10px; margin: 14px 0 6px; }
.slot { display: flex; gap: 10px; align-items: flex-start; }
.slot .tag { margin-top: 12px; }
.combo { position: relative; flex: 1; min-width: 0; }
.combo input { padding-right: 44px; scroll-margin-top: calc(var(--header-h) + 12px); }
.combo.picked input { font-weight: 600; }
.combo.invalid input { border-color: var(--bad); }
.combo.locked input { color: var(--muted); background: var(--card); }
.combo .clear {
  position: absolute; right: 2px; top: 2px; width: 40px; height: 40px; border: 0; border-radius: 8px;
  background: transparent; color: var(--muted); font-size: 1.3rem; line-height: 1; cursor: pointer;
}
.combo .lock-note { font-size: .78rem; color: var(--warn); margin-top: 4px; }
.combo .slot-error { font-size: .78rem; color: var(--bad); margin-top: 4px; }
/* Suggestions sit in the page flow under the box, so the iPhone keyboard never covers them. */
.list {
  margin: 6px 0 0; padding: 4px; list-style: none; background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; max-height: 50vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.list li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px; min-height: 44px; border-radius: 8px; cursor: pointer; }
.list li[aria-selected="true"] { background: var(--accent-soft); }
.list li.disabled { cursor: default; color: var(--muted); }
.list .opt-meta { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.list .empty { color: var(--muted); cursor: default; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 30;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-weight: 600; font-size: .9rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .25); max-width: calc(100% - 32px);
}
