:root {
  --bg: #0f1419;
  --bg2: #161c24;
  --bg3: #1f2832;
  --border: #2a3340;
  --text: #e7ebef;
  --muted: #9ba3af;
  --accent: #22c55e;
  --accent-dim: #166534;
  --danger: #ef4444;
  --warn: #f59e0b;
  --gold: #fbbf24;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--accent); text-decoration: none; }
button {
  font-family: inherit;
  font-size: 16px;
  border: none;
  cursor: pointer;
  background: var(--bg3);
  color: var(--text);
  padding: 12px 16px;
  border-radius: 10px;
  min-height: 44px;
}
button.primary { background: var(--accent); color: #04140a; font-weight: 700; }
button.primary:disabled { background: var(--accent-dim); color: #d1fae5; }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
button.danger { background: var(--danger); color: white; }
button.small { padding: 6px 12px; font-size: 13px; min-height: 32px; border-radius: 8px; }

input, select {
  font-family: inherit; font-size: 16px;
  background: var(--bg3); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; min-height: 44px; width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

header.app-header {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg2); border-bottom: 1px solid var(--border);
  padding: calc(10px + env(safe-area-inset-top, 0px)) calc(14px + env(safe-area-inset-right, 0px)) 10px calc(14px + env(safe-area-inset-left, 0px));
  display: flex; align-items: center; gap: 10px;
}
.app-header .who { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.app-header .who #hd-pseudo { font-weight: 600; font-size: 15px; line-height: 1.1; max-width: 35vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-header .points { color: var(--accent); font-weight: 700; font-size: 13px; line-height: 1.1; }
.app-header .spacer { flex: 1; }
.app-header button { padding: 8px 10px; min-height: 36px; font-size: 18px; min-width: 40px; }
.app-header a { text-decoration: none; }

nav.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--bg2); border-top: 1px solid var(--border);
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 8px calc(4px + env(safe-area-inset-right, 0px)) calc(8px + env(safe-area-inset-bottom, 0px)) calc(4px + env(safe-area-inset-left, 0px));
  z-index: 10;
}
nav.tabbar button {
  background: transparent; color: var(--muted);
  font-size: 12px; padding: 6px 4px; border-radius: 8px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 52px;
}
nav.tabbar button .icon { font-size: 20px; line-height: 1; }
nav.tabbar button.active { color: var(--accent); }

main { padding: 12px 14px 12px; }

.section-title {
  font-size: 14px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.05em;
  margin: 18px 0 8px;
}
.section-title.today { color: var(--accent); }

.match-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 10px;
}
.match-card .meta {
  font-size: 12px; color: var(--muted);
  display: flex; align-items: center; gap: 8px; margin-bottom: 8px;
  flex-wrap: wrap;
}
.match-card .badge {
  padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600;
  background: var(--bg3); color: var(--muted);
}
.match-card .badge.live { background: #7f1d1d; color: #fecaca; }
.match-card .badge.done { background: var(--accent-dim); color: #d1fae5; }
.match-card .badge.locked { background: #1e3a8a; color: #c7d2fe; }
.match-card .teams {
  display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: center;
}
.team { display: flex; align-items: center; gap: 8px; font-weight: 600; min-width: 0; }
.team.right { justify-content: flex-end; }
.team .flag { font-size: 22px; line-height: 1; }
.team .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vs { color: var(--muted); font-size: 14px; padding: 0 6px; }
.score { font-size: 22px; font-weight: 800; padding: 0 8px; }
.score .extra { font-size: 11px; color: var(--muted); display: block; text-align: center; }

.pick-row {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; margin-top: 10px;
}
.pick-row.two-cols { grid-template-columns: 1fr 1fr; }
.pick-row button {
  padding: 10px 6px; font-size: 14px; font-weight: 600;
  background: var(--bg3); color: var(--text); border-radius: 10px;
}
.pick-row button.selected { background: var(--accent); color: #04140a; }

.score-inputs { display: grid; grid-template-columns: 1fr auto 1fr; gap: 6px; margin-top: 8px; align-items: center; }
.score-inputs input { text-align: center; padding: 10px 6px; }
.score-inputs .dash { color: var(--muted); }

.match-actions { display: flex; gap: 8px; margin-top: 10px; }

.my-prono {
  font-size: 13px; color: var(--muted); margin-top: 8px;
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}
.points-badge {
  background: var(--accent); color: #04140a;
  font-weight: 700; padding: 2px 10px; border-radius: 999px; font-size: 13px;
}
.points-badge.zero { background: var(--bg3); color: var(--muted); }
.points-badge.exact { background: var(--gold); color: #312107; }

.filter-row {
  display: flex; gap: 6px; margin-bottom: 12px; overflow-x: auto;
  padding-bottom: 4px;
}
.filter-row button { white-space: nowrap; font-size: 13px; padding: 8px 12px; min-height: 36px; }
.filter-row button.active { background: var(--accent); color: #04140a; }

table.standings { width: 100%; border-collapse: collapse; font-size: 13px; }
table.standings th, table.standings td { padding: 8px 4px; text-align: center; border-bottom: 1px solid var(--border); }
table.standings th { color: var(--muted); font-weight: 500; font-size: 11px; text-transform: uppercase; }
table.standings td.team-cell { text-align: left; }
table.standings tr:last-child td { border-bottom: none; }
table.standings .pos { color: var(--muted); width: 22px; }
table.standings .qual { color: var(--accent); }

.group-card { background: var(--bg2); border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; margin-bottom: 12px; }
.group-card h3 { margin: 0 0 8px; font-size: 16px; }

table.leaderboard { width: 100%; border-collapse: collapse; }
table.leaderboard th, table.leaderboard td { padding: 12px 8px; border-bottom: 1px solid var(--border); text-align: left; }
table.leaderboard th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; }
table.leaderboard td.pts { color: var(--accent); font-weight: 700; font-size: 18px; }
table.leaderboard td.rank { color: var(--muted); width: 30px; text-align: center; font-weight: 600; }
table.leaderboard tr.me { background: rgba(34,197,94,0.08); }
table.leaderboard .num { text-align: right; }

.bracket-stage { margin-bottom: 20px; }
.bracket-stage h3 { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin: 0 0 8px; }

dialog.modal {
  border: 1px solid var(--border);
  background: var(--bg2); color: var(--text);
  border-radius: 14px;
  padding: 0;
  width: 92vw; max-width: 480px;
  max-height: 86vh;
}
dialog.modal::backdrop { background: rgba(0,0,0,0.6); }
dialog.modal .modal-head { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
dialog.modal .modal-head h2 { margin: 0; font-size: 17px; flex: 1; }
dialog.modal .modal-body { padding: 16px; overflow-y: auto; max-height: calc(86vh - 60px); }

.rules-grid { display: grid; gap: 10px; }
.rules-grid .rule { background: var(--bg3); border-radius: 10px; padding: 10px 12px; display: flex; align-items: center; gap: 12px; }
.rules-grid .rule .pts { color: var(--accent); font-weight: 700; font-size: 18px; min-width: 40px; text-align: center; }

.errmsg { color: var(--danger); font-size: 14px; margin-top: 8px; }
.notice { background: var(--bg3); border-radius: 10px; padding: 12px; color: var(--muted); font-size: 14px; margin-bottom: 10px; }
.empty { color: var(--muted); text-align: center; padding: 40px 20px; }
.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%);
  background: var(--accent); color: #04140a; font-weight: 700;
  padding: 10px 18px; border-radius: 999px; z-index: 100;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
  opacity: 0; transition: opacity 200ms ease;
  pointer-events: none;
}
.toast.show { opacity: 1; }

/* Login / register */
.auth-screen { max-width: 380px; margin: 6vh auto; padding: 0 16px; }
.auth-screen h1 { font-size: 28px; text-align: center; margin-bottom: 6px; }
.auth-screen .sub { color: var(--muted); text-align: center; margin-bottom: 24px; font-size: 14px; }
.auth-card { background: var(--bg2); border: 1px solid var(--border); border-radius: 16px; padding: 18px; }
.auth-card .field { margin-bottom: 14px; }
.auth-card label { font-size: 13px; color: var(--muted); display: block; margin-bottom: 6px; }
.switch-mode { text-align: center; margin-top: 12px; font-size: 14px; color: var(--muted); }
.switch-mode a { cursor: pointer; }
