:root {
  --bg: #f4f5f3;
  --surface: #ffffff;
  --surface-2: #f0f2ef;
  --ink: #1b2220;
  --ink-2: #4c5753;
  --muted: #7a8581;
  --line: #e2e6e3;
  --head: #1f2a27;
  --head-ink: #ffffff;
  --p1: #00887a;
  --p1-tint: #e3f3f0;
  --p2: #b4532a;
  --p2-tint: #fbebe3;
  --good: #1f7a3a;
  --good-tint: #e4f3e7;
  --warn: #9a6400;
  --radius: 12px;
  --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: #121615;
    --surface: #1a1f1e;
    --surface-2: #222827;
    --ink: #e9eeec;
    --ink-2: #b5bfbb;
    --muted: #87928e;
    --line: #2d3432;
    --head: #0c100f;
    --head-ink: #ffffff;
    --p1: #2a9a8a;
    --p1-tint: #173230;
    --p2: #d06a3e;
    --p2-tint: #3a2419;
    --good: #5cc27a;
    --good-tint: #183022;
    --warn: #e0a640;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.pad { padding: 16px; }
.num { font-variant-numeric: tabular-nums; }

/* header */
.top { background: var(--head); color: var(--head-ink); position: sticky; top: 0; z-index: 10; padding-top: env(safe-area-inset-top); }
.brand { display: flex; align-items: center; gap: 10px; padding: 12px 16px 6px; max-width: 880px; margin: 0 auto; }
.brand .mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; background: #fff; color: var(--head); font-weight: 800; font-size: 16px; }
.brand strong { display: block; letter-spacing: .06em; font-size: 15px; }
.brand small { display: block; opacity: .65; font-size: 12px; }
nav { display: flex; gap: 4px; padding: 4px 12px 0; max-width: 880px; margin: 0 auto; overflow-x: auto; scrollbar-width: none; }
nav a { text-decoration: none; padding: 9px 12px 11px; font-weight: 600; font-size: 14px; opacity: .7; border-bottom: 3px solid transparent; white-space: nowrap; }
nav a.on { opacity: 1; border-bottom-color: #fff; }

main { max-width: 880px; margin: 0 auto; padding: 16px 16px 48px; }
h1 { font-size: 22px; margin: 4px 0 12px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-2); margin: 28px 0 10px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }

/* buttons & forms */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); padding: 9px 14px; border-radius: 10px; font-weight: 600; cursor: pointer; min-height: 40px; }
.btn.primary { background: var(--head); color: #fff; border-color: var(--head); }
@media (prefers-color-scheme: dark) { .btn.primary { background: #e9eeec; color: #121615; border-color: #e9eeec; } }
.btn:disabled { opacity: .5; cursor: default; }
.btn.small { min-height: 32px; padding: 5px 10px; font-size: 13px; }
input[type=email], input[type=text], input[type=number], select {
  border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 9px 10px; min-height: 42px; width: 100%;
}
label.field { display: block; margin: 10px 0; }
label.field span { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 4px; }

/* sign in */
.signin { max-width: 380px; margin: 40px auto; padding: 24px; }
.signin h1 { margin-top: 0; }
.signin .code { letter-spacing: .4em; font-size: 22px; text-align: center; }
.err { color: #b3261e; font-size: 14px; min-height: 1.4em; margin: 6px 0; }
@media (prefers-color-scheme: dark) { .err { color: #ff8a80; } }

/* standings */
.standings { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.team-card { padding: 14px 16px 16px; border-top: 5px solid var(--c); position: relative; overflow: hidden; }
.team-card .tname { font-weight: 700; color: var(--ink); font-size: 15px; display: flex; align-items: center; gap: 8px; }
.team-card .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); flex: none; }
.team-card .who { font-size: 12px; color: var(--muted); }
.team-card .pts { font-size: 44px; font-weight: 800; line-height: 1.05; margin: 8px 0 2px; }
.team-card .pts small { font-size: 14px; font-weight: 600; color: var(--muted); margin-left: 4px; }
.team-card dl { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; margin: 10px 0 0; font-size: 13px; }
.team-card dt { color: var(--ink-2); }
.team-card dd { margin: 0; font-weight: 700; text-align: right; }
.leader-badge { position: absolute; top: 12px; right: 12px; font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 99px; background: var(--c); color: #fff; }
.headline { font-size: 17px; font-weight: 700; margin: 16px 2px 0; }
.headline .muted { font-weight: 400; font-size: 14px; }

table.grid { width: 100%; border-collapse: collapse; font-size: 14px; }
table.grid th { text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-2); padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
table.grid td { padding: 9px 12px; border-bottom: 1px solid var(--line); }
table.grid tr:last-child td { border-bottom: 0; }
table.grid .r { text-align: right; }
table.grid .c { text-align: center; }
table.grid tr.link { cursor: pointer; }
table.grid tr.link:hover td { background: var(--surface-2); }
.wrap { overflow-x: auto; border-radius: var(--radius); }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 99px; }
.chip.t1 { background: var(--p1-tint); color: var(--p1); }
.chip.t2 { background: var(--p2-tint); color: var(--p2); }
.chip.tie { background: var(--surface-2); color: var(--ink-2); }
@media (prefers-color-scheme: dark) { .chip.t1 { color: #7fd6c8; } .chip.t2 { color: #f0a47f; } }

/* matchweek switcher */
.mw-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.mw-bar h1 { margin: 0; text-align: center; flex: 1; }
.mw-bar h1 small { display: block; font-size: 13px; font-weight: 500; color: var(--muted); }
.mw-bar .btn { width: 44px; padding: 0; font-size: 22px; text-decoration: none; }

/* fixture cards */
.day { font-size: 13px; font-weight: 700; color: var(--ink-2); margin: 18px 2px 8px; }
.fx { padding: 12px 14px; margin-bottom: 10px; }
.fx-head { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 8px; gap: 8px; }
.fx-head .state { font-weight: 700; }
.fx-head .state.live { color: #c62828; }
@media (prefers-color-scheme: dark) { .fx-head .state.live { color: #ff8a80; } }
.score-row { display: grid; grid-template-columns: minmax(0,1fr) 58px 10px 58px minmax(0,1fr); align-items: center; gap: 8px; }
.score-row .team { font-weight: 700; font-size: 15px; line-height: 1.2; }
.score-row .team.away { text-align: right; }
.score-row .dash { color: var(--muted); font-weight: 700; }
.score-row select { width: 58px; text-align: center; font-size: 20px; font-weight: 700; padding: 4px; min-height: 46px; text-align-last: center; }
.score-row .big { font-size: 24px; font-weight: 800; text-align: center; }
.score-row .dash { text-align: center; }
.score-row .team { overflow-wrap: anywhere; }
.pick-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.pick-row select { font-size: 14px; min-height: 40px; }
.pick-row input { font-size: 14px; min-height: 40px; margin-top: 6px; }
.pick-row .lbl { font-size: 11px; color: var(--muted); margin-bottom: 3px; text-transform: uppercase; letter-spacing: .05em; }
.saved { font-size: 12px; color: var(--good); font-weight: 600; }
.saved.err { color: #b3261e; }
.locked-note { font-size: 12px; color: var(--muted); }

.scorers { font-size: 12px; color: var(--ink-2); display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 6px; }
.scorers .a { text-align: right; }
.preds { display: grid; gap: 6px; margin-top: 10px; }
.pred { display: grid; grid-template-columns: 4px 1fr auto; gap: 10px; align-items: center; padding: 7px 10px 7px 0; background: var(--surface-2); border-radius: 8px; overflow: hidden; }
.pred .bar { align-self: stretch; background: var(--c); }
.pred .who { font-size: 12px; font-weight: 700; }
.pred .what { font-size: 13px; }
.pred .what b { font-size: 14px; }
.pred .hit { color: var(--good); font-weight: 700; }
.pred .miss { color: var(--muted); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--muted) 50%, transparent); }
.pred .pts { font-weight: 800; font-size: 18px; min-width: 32px; text-align: right; }
.pred .pts small { font-size: 11px; font-weight: 600; color: var(--muted); display: block; line-height: 1; }
.week-total { display: flex; gap: 10px; flex-wrap: wrap; margin: 4px 0 8px; }

/* stats */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.tile { padding: 14px 16px; }
.tile .k { font-size: 12px; color: var(--ink-2); font-weight: 600; }
.tile .vs { display: flex; justify-content: space-between; align-items: baseline; margin-top: 6px; gap: 8px; }
.tile .v { font-size: 26px; font-weight: 800; }
.tile .v.t1 { color: var(--p1); } .tile .v.t2 { color: var(--p2); }
.tile .sub { font-size: 12px; color: var(--muted); }
.chart { padding: 14px 12px 8px; position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .legend { display: flex; gap: 14px; font-size: 13px; margin: 0 4px 8px; flex-wrap: wrap; }
.chart .legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart .legend i { width: 12px; height: 3px; border-radius: 2px; background: var(--c); display: inline-block; }
.chart .legend i.sq { height: 12px; width: 12px; border-radius: 3px; }
.tip { position: absolute; pointer-events: none; background: var(--head); color: #fff; font-size: 12px; padding: 6px 8px; border-radius: 8px; white-space: nowrap; opacity: 0; transition: opacity .1s; z-index: 5; }
@media (prefers-color-scheme: dark) { .tip { background: #e9eeec; color: #121615; } }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; padding: 7px 14px; border-bottom: 1px solid var(--line); font-size: 14px; gap: 8px; }
.list li:last-child { border-bottom: 0; }
.list .h { justify-content: flex-start; font-weight: 700; padding: 11px 14px 8px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 8px; }

/* admin */
.admin-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.goal-row { display: grid; grid-template-columns: 1fr 64px 36px; gap: 6px; margin-top: 6px; }
.editor { border-top: 1px dashed var(--line); margin-top: 12px; padding-top: 12px; }

#toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); background: var(--head); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; transition: .2s; pointer-events: none; z-index: 20; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%); }

@media (max-width: 560px) {
  main { padding: 12px 12px 40px; }
  .standings { gap: 8px; }
  .team-card { padding: 12px; }
  .team-card .pts { font-size: 36px; }
  .team-card .tname { font-size: 13px; }
  .leader-badge { display: none; }
  .two { grid-template-columns: 1fr; }
  .admin-grid { grid-template-columns: 1fr; }
  table.grid th, table.grid td { padding: 8px 6px; }
  table.grid th { font-size: 11px; }
  .score-row .team { font-size: 14px; }
  .tiles { grid-template-columns: 1fr 1fr; gap: 8px; }
  .tile { padding: 12px; }
  .tile .v { font-size: 22px; }
}

input:disabled { background: var(--surface-2); color: var(--muted); cursor: not-allowed; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; padding: 7px 14px; font-weight: 600; font-size: 13px; cursor: pointer; color: var(--ink-2); }
.seg button.on { background: var(--head); color: #fff; }
@media (prefers-color-scheme: dark) { .seg button.on { background: #e9eeec; color: #121615; } }
.wk { width: 100%; border-collapse: collapse; font-size: 13px; }
.wk th { font-size: 11px; font-weight: 700; text-align: left; padding: 9px 8px; background: var(--surface-2); border-bottom: 1px solid var(--line); color: var(--ink-2); }
.wk th.u { border-top: 4px solid var(--c); }
.wk td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.wk tr:last-child td { border-bottom: 0; }
.wk .m b { display: block; font-size: 13px; white-space: nowrap; }
.wk .m small { color: var(--muted); font-size: 11px; }
.wk .p { min-width: 0; }
.wk .p .sc { font-weight: 800; font-size: 15px; }
.wk .p .pk { display: block; font-size: 11px; color: var(--ink-2); line-height: 1.3; }
.wk .p .pk .hit { color: var(--good); font-weight: 700; }
.wk .p .pts { float: right; font-weight: 800; font-size: 14px; }
.wk .p .pts.zero { color: var(--muted); font-weight: 600; }
.wk .p.hide { color: var(--muted); font-size: 12px; }
.wk tfoot td { font-weight: 800; background: var(--surface-2); }
