:root {
  --bg: #f4f5f0;
  --card: #ffffff;
  --ink: #15201a;
  --muted: #66706a;
  --line: #dfe3dc;
  --accent: #0e5a3a;
  --accent-ink: #ffffff;
  --accent-soft: #e3efe8;
  --win: #1d7a46;
  --draw: #b7791f;
  --loss: #b42318;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); line-height: 1.45; }
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 .6rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mt { margin-top: 1rem; }
code { background: #eef0ec; padding: 0 .25rem; border-radius: 4px; }
ul.plain { list-style: none; padding: 0; margin: 0; display: grid; gap: .4rem; }

/* ---------- Top bar & navigation ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .7rem 1.2rem; padding-top: max(.7rem, env(safe-area-inset-top));
  background: var(--accent); color: var(--accent-ink);
}
.brand { display: flex; align-items: center; gap: .6rem; color: inherit; text-decoration: none; font-weight: 700; min-width: 0; }
.brand #brand-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-mark { background: #c8f169; color: var(--accent); border-radius: 6px; padding: .1rem .4rem; font-size: .8rem; letter-spacing: .05em; }
#nav { display: flex; gap: .2rem; flex-wrap: wrap; }
#nav a, #nav button {
  color: var(--accent-ink); text-decoration: none; background: none; border: 0; font: inherit;
  padding: .4rem .7rem; border-radius: 8px; cursor: pointer; opacity: .88; text-align: left;
}
#nav a.active, #nav a:hover, #nav button:hover { background: rgba(255,255,255,.14); opacity: 1; }

#menu-btn {
  display: none; align-items: center; gap: .4rem; flex: none;
  -webkit-appearance: none; appearance: none;
  min-height: 42px; padding: .35rem .75rem; margin: -4px -4px -4px 0;
  background: rgba(255,255,255,.16); border: 1.5px solid rgba(255,255,255,.55); border-radius: 10px;
  color: #fff; font: inherit; font-weight: 600; font-size: .95rem; cursor: pointer;
}
#menu-btn svg { display: block; flex: none; }
#menu-btn .icon-close { display: none; }
#menu-btn.open .icon-open { display: none; }
#menu-btn.open .icon-close { display: block; }
#menu-btn:active { background: rgba(255,255,255,.28); }

@media (max-width: 760px) {
  #menu-btn { display: flex; }
  #nav {
    display: none; position: absolute; top: 100%; left: 0; right: 0;
    flex-direction: column; gap: 0; padding: .4rem .6rem .8rem;
    background: var(--accent); box-shadow: 0 10px 24px rgba(0,0,0,.18);
  }
  #nav.open { display: flex; }
  #nav a, #nav button { padding: .85rem .8rem; font-size: 1.05rem; border-radius: 8px; }
  #nav button { border-top: 1px solid rgba(255,255,255,.15); border-radius: 0; margin-top: .3rem; }
}

/* ---------- WhatsApp ---------- */
.wa-link { display: inline-flex; align-items: center; gap: .4rem; text-decoration: none; font-weight: 600; }
.wa-link svg { flex: none; }
#nav a.nav-wa { background: #25d366; color: #fff; opacity: 1; margin-left: .3rem; }
#nav a.nav-wa:hover { background: #1fb857; }
.btn-wa { justify-content: center; width: 100%; min-height: 46px; padding: .6rem 1rem; border-radius: 8px; background: #25d366; color: #fff; }
.btn-wa:hover { background: #1fb857; }
.wa-box { background: #eafbf0; border: 1px solid #bfeccf; border-radius: 10px; padding: .2rem .9rem .9rem; margin: .8rem 0 .4rem; }
@media (max-width: 760px) {
  #nav a.nav-wa { margin: .4rem 0 0; justify-content: center; }
}

/* ---------- Layout ---------- */
main { max-width: 980px; margin: 0 auto; padding: 1.4rem 1.2rem 4rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; margin-bottom: 1rem; }
.card.flush { padding: 0; }
.narrow { max-width: 420px; margin: 1.5rem auto; }
.row { display: flex; gap: .75rem; flex-wrap: wrap; align-items: end; }
.row > * { flex: 1 1 180px; }
.row > .shrink { flex: 0 0 auto; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: .5rem 1rem; flex-wrap: wrap; }

/* ---------- Forms ---------- */
label { display: block; font-size: .85rem; font-weight: 600; margin: .7rem 0 .25rem; }
label.check, label.inline { display: flex; align-items: center; gap: .5rem; font-weight: 400; font-size: .92rem; }
label.check { min-height: 44px; margin: .2rem 0; cursor: pointer; }
input, select, textarea {
  width: 100%; font: inherit; font-size: 16px; padding: .6rem .7rem; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink);
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
.search { max-width: 240px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .3rem;
  font: inherit; font-weight: 600; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink);
  padding: .6rem 1rem; min-height: 44px; border-radius: 8px; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn.secondary { background: #fff; color: var(--accent); }
.btn.danger { background: #fff; color: var(--loss); border-color: var(--loss); }
.btn.sm { padding: .3rem .6rem; min-height: 36px; font-size: .85rem; }
.btn.full { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.banner { padding: .8rem 1rem; border-radius: 10px; margin-bottom: 1rem; background: var(--accent-soft); }
.banner.warn { background: #fff4e0; }
.banner.bad { background: #fde8e6; }

.deadline { font-weight: 600; }
.countdown { font-variant-numeric: tabular-nums; }
.mobile-only { display: none; }

/* ---------- Prize pot ---------- */
.pot {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: .2rem .7rem;
  background: linear-gradient(135deg, #0e5a3a, #17724b); color: #fff;
  border-radius: var(--radius); padding: .9rem 1.2rem; margin-bottom: 1rem;
}
.pot-label { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; opacity: .85; font-weight: 600; }
.pot b { font-size: 1.7rem; color: #c8f169; font-variant-numeric: tabular-nums; }
.pot-breakdown { max-width: 420px; margin: .5rem 0 .5rem; }
.pot-breakdown td { padding: .35rem 0; }
.pot-breakdown td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.pot-breakdown tr.total td { font-weight: 700; border-top: 2px solid var(--ink); }

/* ---------- Player switcher ---------- */
.switcher { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: 1rem; }
.seg { display: flex; gap: .3rem; flex-wrap: wrap; }
.seg button {
  font: inherit; display: inline-flex; align-items: center; gap: .45rem; min-height: 44px;
  padding: .45rem .9rem; border-radius: 999px; border: 1.5px solid var(--line); background: #fff; cursor: pointer; font-weight: 600;
}
.seg button.active { background: var(--ink); border-color: var(--ink); color: #fff; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #aab; }
.dot.alive { background: #3bb36b; } .dot.rebuy_pending { background: var(--draw); } .dot.eliminated { background: var(--loss); }

/* ---------- Fixture picker ---------- */
.fixtures { display: grid; gap: .55rem; }
.fixture { display: grid; grid-template-columns: 1fr 2.4rem 1fr; gap: .4rem; align-items: stretch; }
.fixture .vs { color: var(--muted); font-size: .85rem; display: flex; align-items: center; justify-content: center; font-weight: 600; }
.ko { font-size: .75rem; color: var(--muted); text-align: center; margin-bottom: .15rem; }
.team-btn {
  font: inherit; text-align: center; padding: .75rem .5rem; min-height: 52px; border-radius: 10px; border: 1.5px solid var(--line);
  background: #fff; cursor: pointer; font-weight: 600; color: var(--ink); line-height: 1.2;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .15rem;
}
.team-btn:hover:not(:disabled) { border-color: var(--accent); }
.team-btn.selected { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 0 0 3px #c8f169 inset; }
.team-btn:disabled { cursor: not-allowed; }
.team-btn:disabled:not(.used) { color: #a7aea9; background: #f3f4f2; }
/* Teams already used this competition: blacked out */
.team-btn.used { background: #111; border-color: #111; color: #6f6f6f; }
.team-btn.used small { font-size: .65rem; text-transform: uppercase; letter-spacing: .08em; color: #9a9a9a; font-weight: 700; }
.team-btn.used.selected { color: #fff; }
.pill.used-pill { background: #111; color: #fff; }
.used-list .pill { margin: .15rem .1rem; }

.tag-random { display: inline-block; font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  padding: .05rem .4rem; border-radius: 4px; background: #ece6ff; color: #5b3fb5; vertical-align: middle; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: .5rem .55rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.actions { white-space: nowrap; text-align: right; }
td.actions .btn { margin: .1rem 0; }
table.grid td, table.grid th { white-space: nowrap; }
.sticky-col { position: sticky; left: 0; background: var(--card); z-index: 1; box-shadow: 1px 0 0 var(--line); }

/* Tables that turn into cards on phones */
@media (max-width: 700px) {
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr { padding: .75rem 0; border-bottom: 1px solid var(--line); }
  table.stack tr:last-child { border-bottom: 0; }
  table.stack td { border: 0; padding: .2rem 0; display: flex; justify-content: space-between; align-items: center; gap: 1rem; text-align: right; }
  table.stack td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: .8rem; text-align: left; flex: none; }
  table.stack td.primary { font-weight: 700; display: block; text-align: left; font-size: 1rem; }
  table.stack td.actions { justify-content: flex-start; flex-wrap: wrap; white-space: normal; padding-top: .5rem; }
  table.stack td select { max-width: 60%; }
}

.pill { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: #eef0ec; }
.pill.alive { background: #e2f3e8; color: var(--win); }
.pill.rebuy_pending { background: #fff1d6; color: var(--draw); }
.pill.eliminated { background: #fde8e6; color: var(--loss); }
.pill.pending { background: #eceef7; color: #3a4a8c; }
.team-pill { margin: .2rem .15rem; padding-right: .2rem; }
.team-pill button { border: 0; background: none; cursor: pointer; color: var(--muted); padding: .1rem .35rem; font-size: .8rem; }
.res-W, .res-P { color: var(--win); font-weight: 700; }
.res-D { color: var(--draw); font-weight: 700; }
.res-L, .res-NP { color: var(--loss); font-weight: 700; }

/* ---------- Chart ---------- */
.bars { display: grid; gap: .45rem; }
.bar-row { display: grid; grid-template-columns: 9rem 1fr 2.2rem; gap: .6rem; align-items: center; font-size: .9rem; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { background: #eef0ec; border-radius: 4px; height: 1.25rem; overflow: hidden; }
.bar-fill { background: var(--accent); height: 100%; border-radius: 4px; }
.bar-row:first-child .bar-fill { background: #2f8f5b; }
.bar-val { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

.tabs { display: flex; gap: .35rem; flex-wrap: wrap; margin-bottom: 1rem; }
.tabs.scroll { flex-wrap: nowrap; overflow-x: auto; padding-bottom: .2rem; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.tabs button { font: inherit; border: 1px solid var(--line); background: #fff; padding: .5rem .9rem; min-height: 40px; border-radius: 999px; cursor: pointer; white-space: nowrap; flex: none; }
.tabs button.active { background: var(--ink); color: #fff; border-color: var(--ink); }

.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: .75rem; margin-bottom: 1rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; min-width: 0; }
.stat b { display: block; font-size: 1.4rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Admin: fixtures ---------- */
.fx-list { display: grid; gap: .6rem; }
.fx-card { border: 1px solid var(--line); border-radius: 10px; padding: .7rem; }
.fx-score { display: grid; grid-template-columns: 1fr 3.4rem auto 3.4rem 1fr; gap: .45rem; align-items: center; }
.fx-score .fx-team { font-weight: 700; }
.fx-score .fx-team:first-child { text-align: right; }
.score { text-align: center; padding: .5rem .2rem; }
.fx-meta { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem 1rem; margin-top: .5rem; font-size: .9rem; }
.fx-meta input[type=datetime-local] { width: auto; padding: .35rem .5rem; }
.fx-btns { margin-left: auto; display: flex; gap: .35rem; }

.hint { background: var(--accent-soft); padding: .55rem .8rem; border-radius: 8px; }
.chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .4rem; }
.chip {
  font: inherit; font-weight: 600; min-height: 46px; padding: .5rem; border-radius: 10px;
  border: 1.5px solid var(--line); background: #fff; cursor: pointer; color: var(--ink);
}
.chip:hover:not(:disabled) { border-color: var(--accent); }
.chip.home { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip.taken { background: #f1f2ef; color: #b3b9b4; cursor: default; }
.staged { margin-top: 1rem; display: grid; gap: .4rem; }
.staged-row { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .5rem .7rem; background: #f6f8f4; border-radius: 8px; flex-wrap: wrap; }
.staged-row > span:last-child { display: flex; gap: .3rem; }
.ko-input { max-width: 260px; }
details summary { cursor: pointer; color: var(--accent); font-weight: 600; min-height: 32px; }

#toast {
  position: fixed; left: 50%; bottom: max(1.2rem, env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(150%);
  background: var(--ink); color: #fff; padding: .7rem 1.1rem; border-radius: 10px; transition: transform .2s, opacity .2s;
  max-width: calc(100vw - 2rem); opacity: 0; visibility: hidden; z-index: 50; text-align: center;
}
#toast.show { transform: translateX(-50%) translateY(0); opacity: 1; visibility: visible; }
#toast.err { background: var(--loss); }

/* ---------- Phones ---------- */
@media (max-width: 560px) {
  main { padding: 1rem .75rem 4rem; }
  .card { padding: 1rem .9rem; }
  h1 { font-size: 1.3rem; }
  .mobile-only { display: inline; }
  .deadline .sep { display: none; }
  .search { max-width: none; }
  .stat-row { grid-template-columns: 1fr 1fr; }
  .stat-row .stat:nth-child(2) { grid-column: 1 / -1; grid-row: 1; }
  .bar-row { grid-template-columns: 6.8rem 1fr 1.8rem; font-size: .85rem; }
  .chips { grid-template-columns: repeat(2, 1fr); }
  .fx-score { grid-template-columns: 1fr 3rem auto 3rem 1fr; font-size: .9rem; }
  .fx-meta label.inline { width: 100%; }
  .fx-meta input[type=datetime-local] { flex: 1; }
  .fx-btns { margin-left: 0; width: 100%; }
  .fx-btns .btn { flex: 1; }
  .full-mobile { width: 100%; }
  .ko-input { max-width: none; }
  .row > .shrink { flex: 1 1 auto; }
  .row > .shrink .btn { width: 100%; }
}