:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #15201a;
  --muted: #5f6b65;
  --line: #e2e7e4;
  --brand: #0b7a3b;
  --brand-ink: #ffffff;
  --brand-soft: #e3f3ea;
  --accent: #f2b705;
  --danger: #c62828;
  --live: #d32f2f;
  --exact: #0b7a3b;
  --outcome: #2e6fd8;
  --miss: #8a948f;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1412;
    --card: #18201c;
    --text: #e8eeea;
    --muted: #9aa7a0;
    --line: #2a342f;
    --brand: #2fb26a;
    --brand-ink: #06210f;
    --brand-soft: #173325;
    --outcome: #6aa1ff;
    --exact: #2fb26a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; line-height: 1.2; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 .5rem; }
p { margin: .4rem 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.row { display: flex; gap: .5rem; align-items: center; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: .75rem; }

/* ---- layout ---- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--brand); color: var(--brand-ink);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: 720px; margin: 0 auto; padding: .7rem 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.brand { color: var(--brand-ink); font-weight: 700; font-size: 1.1rem; }
.brand:hover { text-decoration: none; }
#nav a { color: var(--brand-ink); opacity: .9; font-size: .95rem; margin-left: 1rem; }
.container { max-width: 720px; margin: 0 auto; padding: 16px 16px 80px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem; box-shadow: var(--shadow);
}
.card + .card { margin-top: .75rem; }
a.card { display: block; color: inherit; }
a.card:hover { text-decoration: none; border-color: var(--brand); }

/* ---- forms ---- */
label { display: block; font-weight: 600; margin-bottom: .3rem; }
input[type=text], input[type=email], input[type=search] {
  width: 100%; padding: .75rem .85rem; font-size: 1rem;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--text);
}
input:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: transparent; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .75rem 1.1rem; font-size: 1rem; font-weight: 600;
  border-radius: 10px; border: 1px solid transparent; cursor: pointer;
  background: var(--brand); color: var(--brand-ink);
}
.btn:hover { text-decoration: none; filter: brightness(1.05); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.secondary { background: var(--card); color: var(--text); border-color: var(--line); }
.btn.ghost { background: transparent; color: var(--brand); padding: .5rem .6rem; }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--line); }
.btn.block { width: 100%; }
.btn.small { padding: .45rem .75rem; font-size: .9rem; }
.error { color: var(--danger); font-size: .9rem; min-height: 1.2em; }

/* ---- segmented tabs ---- */
.tabs {
  display: flex; gap: .25rem; background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: .25rem; margin: 1rem 0;
  position: sticky; top: calc(52px + env(safe-area-inset-top)); z-index: 5;
}
.tabs button {
  flex: 1; padding: .55rem .25rem; border: 0; border-radius: 9px; cursor: pointer;
  background: transparent; color: var(--muted); font-weight: 600; font-size: .95rem;
}
.tabs button[aria-selected=true] { background: var(--brand); color: var(--brand-ink); }

/* ---- chips ---- */
.chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.chip {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .5rem .8rem; border-radius: 999px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); cursor: pointer; font-size: .95rem;
}
.chip[aria-pressed=true] { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); font-weight: 600; }
.tag {
  display: inline-block; padding: .1rem .45rem; border-radius: 6px; font-size: .75rem; font-weight: 600;
  background: var(--brand-soft); color: var(--brand);
}
.tag.live { background: var(--live); color: #fff; }
.tag.warn { background: #fff3cd; color: #7a5a00; }

/* ---- league list ---- */
.league-card .name { font-weight: 700; font-size: 1.1rem; }
.stat { text-align: center; min-width: 3.5rem; }
.stat b { display: block; font-size: 1.35rem; line-height: 1.1; }
.stat span { font-size: .75rem; color: var(--muted); }

/* ---- matches ---- */
.day { margin: 1.25rem 0 .4rem; font-weight: 700; color: var(--muted); font-size: .9rem; text-transform: uppercase; letter-spacing: .03em; }
.match { padding: .8rem 1rem; }
.match + .match { margin-top: .5rem; }
.match-meta { display: flex; justify-content: space-between; gap: .5rem; font-size: .8rem; color: var(--muted); margin-bottom: .45rem; }
.match-meta > span:last-child { white-space: nowrap; }
.match-body { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: .6rem; }
.team { font-weight: 600; overflow-wrap: anywhere; }
.team.home { text-align: right; }
.score-inputs { display: flex; align-items: center; gap: .3rem; }
.score-inputs input {
  width: 2.8rem; height: 2.8rem; text-align: center; font-size: 1.25rem; font-weight: 700;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text);
  -moz-appearance: textfield;
}
.score-inputs input::-webkit-outer-spin-button, .score-inputs input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.score-inputs .sep { color: var(--muted); font-weight: 700; }
.final { font-size: 1.35rem; font-weight: 800; letter-spacing: .05em; white-space: nowrap; text-align: center; min-width: 4.5rem; }
.match-foot { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-top: .5rem; font-size: .85rem; color: var(--muted); }
.saved { color: var(--brand); font-weight: 600; }
.pts { display: inline-block; min-width: 2.4rem; text-align: center; padding: .15rem .45rem; border-radius: 999px; font-weight: 700; font-size: .8rem; color: #fff; background: var(--miss); }
.pts.p3 { background: var(--exact); }
.pts.p1 { background: var(--outcome); }
details.others { margin-top: .5rem; font-size: .9rem; }
details.others summary { cursor: pointer; color: var(--brand); font-weight: 600; }
.others ul { list-style: none; padding: 0; margin: .4rem 0 0; }
.others li { display: flex; justify-content: space-between; padding: .3rem 0; border-top: 1px solid var(--line); }

/* ---- table ---- */
table.board { width: 100%; border-collapse: collapse; }
.board th, .board td { padding: .6rem .4rem; text-align: right; border-bottom: 1px solid var(--line); }
.board th { font-size: .75rem; color: var(--muted); font-weight: 600; text-transform: uppercase; }
.board th:nth-child(2), .board td:nth-child(2) { text-align: left; width: 100%; }
.board th:first-child, .board td:first-child { text-align: center; width: 2rem; }
.board tr.me td { background: var(--brand-soft); font-weight: 700; }
.board td.pts-col { font-weight: 800; font-size: 1.05rem; }
.medal { font-size: 1.1rem; }
select {
  padding: .55rem .7rem; font-size: .95rem; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); max-width: 100%;
}

/* ---- invite ---- */
.invite-box { display: flex; gap: .5rem; align-items: center; background: var(--brand-soft); border-radius: 12px; padding: .75rem; }
.invite-box code { font-size: 1.1rem; font-weight: 700; letter-spacing: .12em; color: var(--brand); }
.hero { text-align: center; padding: 1.5rem .5rem; }
.hero .ball { font-size: 3rem; }
.hero h1 { font-size: 1.75rem; }
.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); }

/* ---- toast ---- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #1d2621; color: #fff; padding: .7rem 1.1rem; border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,.25); max-width: calc(100% - 32px); z-index: 50; font-size: .95rem;
}
.toast.err { background: var(--danger); }

.picker-list { max-height: 55vh; overflow: auto; border: 1px solid var(--line); border-radius: 12px; }
.pick { display: flex; gap: .75rem; align-items: center; padding: .65rem .8rem; border-bottom: 1px solid var(--line); cursor: pointer; }
.pick:last-child { border-bottom: 0; }
.pick input { width: 1.2rem; height: 1.2rem; accent-color: var(--brand); flex: none; }
.pick .when { font-size: .8rem; color: var(--muted); }
.sticky-bottom {
  position: sticky; bottom: 0; padding: .75rem 0 calc(.75rem + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.spinner { text-align: center; padding: 2rem; color: var(--muted); }
ul.rules { padding-left: 1.2rem; }
ul.rules li { margin: .35rem 0; }

/* ---- v2 components ---- */
.narrow { max-width: 440px; margin: 1rem auto; }
.stack-sm > * + * { margin-top: .4rem; }
.card.flat { box-shadow: none; background: var(--bg); }
h3 { font-size: 1rem; margin: 1.25rem 0 .4rem; }
.card > h3:first-child { margin-top: 0; }

.avatar {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  border-radius: 50%; object-fit: cover; color: #fff; font-weight: 700; line-height: 1;
  background: var(--line);
}
.nav-me { display: inline-flex; align-items: center; gap: .4rem; }
.nav-me .avatar { border: 2px solid rgba(255,255,255,.7); }
.who { color: inherit; gap: .5rem; min-width: 0; }
.who span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a.who:hover { text-decoration: none; }
.avatar-stack { display: inline-flex; align-items: center; }
.avatar-stack .avatar { border: 2px solid var(--bg); margin-left: -8px; }
.avatar-stack .avatar:first-child { margin-left: 0; }
.avatar-stack .more { margin-left: 4px; font-size: .8rem; color: var(--muted); }

.badge {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  min-width: 2.1rem; height: 1.45rem; padding: 0 .3rem; border-radius: 6px;
  color: #fff; font-size: .68rem; font-weight: 800; letter-spacing: .03em;
}

/* stepper score entry */
.pick-row { display: flex; align-items: center; gap: .6rem; padding: .3rem 0; }
.pick-row .team { font-weight: 600; overflow-wrap: anywhere; }
.stepper { display: inline-flex; align-items: center; gap: .25rem; flex: none; }
.stepper .num { min-width: 2.2rem; text-align: center; font-size: 1.35rem; font-weight: 800; }
.step {
  width: 2.5rem; height: 2.5rem; border-radius: 50%; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font-size: 1.3rem; font-weight: 700; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; touch-action: manipulation;
}
.step:active { background: var(--brand-soft); border-color: var(--brand); }
.soon { color: var(--live); font-weight: 700; }

/* wizard */
.progress { height: 4px; background: var(--line); border-radius: 4px; margin: .4rem 0 .5rem; overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--brand); transition: width .2s; }
.presets { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.preset {
  text-align: left; padding: .75rem; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); cursor: pointer; display: flex; flex-direction: column; gap: .2rem;
}
.preset[aria-pressed=true] { border-color: var(--brand); background: var(--brand-soft); box-shadow: 0 0 0 1px var(--brand) inset; }
.rule-line { display: flex; align-items: center; gap: .75rem; padding: .55rem 0; border-bottom: 1px solid var(--line); }
.rule-line:last-child { border-bottom: 0; }
.rule-line.dim .rule-name { color: var(--muted); }
.rule-name { font-weight: 600; }
.chip.static { cursor: default; font-size: .8rem; padding: .25rem .6rem; background: var(--brand-soft); border-color: transparent; color: var(--brand); font-weight: 600; }

/* league */
.league-head { display: flex; gap: .75rem; align-items: flex-start; justify-content: space-between; }
.summary { margin-top: 1rem; }
.summary-main { display: flex; align-items: center; gap: .5rem; font-weight: 700; font-size: 1.05rem; margin: .2rem 0; }
.medal-big { font-size: 1.6rem; }
.champ select { width: 100%; }
.tie-teams { display: grid; grid-template-columns: 1fr auto 1fr; gap: .5rem; align-items: center; margin: .3rem 0 .5rem; }
.tie-teams .vs { color: var(--muted); font-size: .85rem; }
.team-pick {
  display: flex; align-items: center; justify-content: center; gap: .4rem; padding: .7rem .5rem;
  border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--text);
  font-weight: 600; cursor: pointer; min-height: 3rem;
}
.team-pick[aria-pressed=true] { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); box-shadow: 0 0 0 1px var(--brand) inset; }
.team-pick:disabled { cursor: default; opacity: .85; }
.member-list { list-style: none; margin: 0; padding: 0; }
.member-list li { display: flex; justify-content: space-between; align-items: center; padding: .45rem 0; border-bottom: 1px solid var(--line); }
.member-list li:last-child { border-bottom: 0; }

/* table */
.board tbody tr { cursor: pointer; }
.board td:nth-child(2) { max-width: 0; }
.move { display: block; font-size: .65rem; font-weight: 700; line-height: 1; min-height: .65rem; }
.move.up { color: var(--exact); }
.move.down { color: var(--danger); }

/* player page */
.player-head { display: flex; gap: 1rem; align-items: center; }
.player-head h1 { margin-bottom: .2rem; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: .5rem; margin-top: .75rem; }
.stats .card + .card { margin-top: 0; }
.stat-box { text-align: center; padding: .75rem; }
.stat-box b { display: block; font-size: 1.5rem; }
.stat-box span { font-size: .8rem; color: var(--muted); }
.form-bars { display: flex; justify-content: space-around; align-items: flex-end; gap: .5rem; padding-top: 1rem; }
.bar { display: flex; flex-direction: column; align-items: center; gap: .25rem; flex: 1; }
.bar-fill { width: 70%; max-width: 40px; background: var(--brand); border-radius: 6px 6px 2px 2px; }
.bar-val { font-weight: 700; font-size: .9rem; }
.bar-label { font-size: .75rem; color: var(--muted); }

.photo-picker { gap: 1rem; }
.code-input { font-size: 1.6rem !important; letter-spacing: .4em; text-align: center; font-weight: 700; }

@media (max-width: 380px) {
  .presets { grid-template-columns: 1fr; }
  .tabs button { font-size: .85rem; }
}
.team-cell { display: flex; align-items: center; gap: .4rem; min-width: 0; }
.team-cell.home { justify-content: flex-end; text-align: right; }
.team-cell .team { font-weight: 600; overflow-wrap: anywhere; }
.tie .match-meta > span:last-child { white-space: normal; text-align: right; }

/* ---- home v3 ---- */
.banner {
  display: flex; align-items: center; gap: .75rem; margin: 1rem 0 .25rem;
  padding: .9rem 1rem; border-radius: var(--radius); color: inherit;
}
a.banner:hover { text-decoration: none; filter: brightness(1.03); }
.banner.todo { background: var(--accent); color: #2b2100; box-shadow: var(--shadow); }
.banner.done { background: var(--brand-soft); color: var(--text); }
.banner-icon { font-size: 1.6rem; }
.banner-go { font-weight: 700; white-space: nowrap; }
.card.list { padding: 0; overflow: hidden; }
.league-row {
  display: flex; align-items: center; gap: .75rem; padding: .8rem 1rem;
  border-bottom: 1px solid var(--line); color: inherit;
}
.league-row:last-child { border-bottom: 0; }
a.league-row:hover { text-decoration: none; background: var(--bg); }
.league-row .name { font-weight: 700; }
.league-row .tag { margin-top: .3rem; }
.league-row .chips { margin-top: .35rem; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.league-row .grow { min-width: 0; }
.search { margin-bottom: .6rem; }
.card.list > p { padding: 1rem; margin: 0; }
.card.list .spinner { padding: 1.5rem; }
.vis-chip { background: var(--bg) !important; color: var(--muted) !important; border: 1px solid var(--line) !important; }
.switch-row { display: flex; align-items: flex-start; gap: .6rem; font-weight: 400; cursor: pointer; }
.switch-row input { width: 1.3rem; height: 1.3rem; accent-color: var(--brand); flex: none; margin-top: .1rem; }

/* ---- admin ---- */
.table-wrap { overflow-x: auto; }
.admin-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.admin-table th, .admin-table td { text-align: left; padding: .4rem .5rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
.admin-table th { color: var(--muted); font-weight: 600; font-size: .75rem; text-transform: uppercase; }
.admin-chart { display: flex; align-items: flex-end; gap: 3px; height: 140px; }
.admin-chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; min-width: 0; }
.admin-chart .stack { display: flex; flex-direction: column-reverse; width: 80%; }
.admin-chart .real, .key.real { background: var(--brand); }
.admin-chart .bots, .key.bots { background: var(--line); }
.admin-chart .v, .admin-chart .lbl, .admin-chart .sgn { font-size: .65rem; color: var(--muted); line-height: 1.3; }
.admin-chart .sgn { color: var(--brand); font-weight: 700; min-height: .85rem; }
.key { display: inline-block; width: .7rem; height: .7rem; border-radius: 2px; vertical-align: middle; }
.list-controls { margin-bottom: .6rem; gap: .5rem; }
.list-controls select { flex: 1; min-width: 0; }
.league-row .tag { margin-left: .2rem; vertical-align: middle; }
.brand { white-space: nowrap; }
#nav { display: flex; align-items: center; flex-wrap: nowrap; }
@media (max-width: 420px) {
  .topbar-inner { gap: .5rem; }
  #nav a { margin-left: .65rem; font-size: .88rem; }
  .nav-me span { display: none; }
}

/* big "My leagues" button on the home screen: looks and feels like a button */
.my-leagues-btn {
  display: flex; align-items: center; gap: .8rem; margin: .9rem 0 .2rem;
  padding: .95rem 1rem; border-radius: 16px; color: #fff; cursor: pointer;
  background: linear-gradient(180deg, #14a052 0%, #0b7a3b 100%);
  box-shadow: 0 4px 0 #075a2b, 0 8px 18px rgba(11, 122, 59, .28);
  transition: transform .08s ease, box-shadow .08s ease, filter .15s;
  -webkit-tap-highlight-color: transparent; user-select: none;
}
.my-leagues-btn:hover { text-decoration: none; filter: brightness(1.05); }
.my-leagues-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #075a2b, 0 3px 8px rgba(11, 122, 59, .25); }
.my-leagues-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.my-leagues-btn .icon { font-size: 1.7rem; filter: drop-shadow(0 1px 1px rgba(0,0,0,.2)); }
.my-leagues-btn b { font-size: 1.12rem; }
.my-leagues-btn .sub { font-size: .85rem; opacity: .9; margin-top: .1rem; }
.my-leagues-btn .peeks { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .35rem; }
.my-leagues-btn .peek {
  font-size: .76rem; padding: .15rem .5rem; border-radius: 999px; background: rgba(255,255,255,.2);
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.my-leagues-btn .peek b { font-size: .76rem; }
.my-leagues-btn .cta {
  flex: none; background: #fff; color: #0b7a3b; font-weight: 800; font-size: .92rem;
  padding: .6rem .9rem; border-radius: 999px; white-space: nowrap;
  box-shadow: 0 2px 0 rgba(0,0,0,.15);
}
/* No leagues yet: same button, inviting rather than loud */
.my-leagues-btn.empty {
  background: linear-gradient(180deg, #ffffff 0%, #f1f7f3 100%); color: var(--text);
  box-shadow: 0 4px 0 #cfe3d6, 0 8px 18px rgba(0,0,0,.06); border: 1.5px solid #bfdcc9;
}
.my-leagues-btn.empty:active { box-shadow: 0 1px 0 #cfe3d6; }
.my-leagues-btn.empty .cta { background: var(--brand); color: #fff; }
@media (prefers-color-scheme: dark) {
  .my-leagues-btn.empty { background: var(--card); border-color: var(--line); box-shadow: 0 4px 0 #0c120f; }
}
.my-leagues-btn .grow { text-align: left; min-width: 0; }
.my-leagues-btn .peek { max-width: 11rem; }
