/* World Cup Sweepstake — layered on top of Pico CSS.
   Pico owns base typography / forms / buttons / tables; we tune its theme
   variables to our brand and keep the bespoke match/standings components. */

/* --- Brand tuning for Pico (buttons, links, focus rings, radius) --- */
:root {
  --pico-primary: #1d6f42;
  --pico-primary-background: #1d6f42;
  --pico-primary-hover: #18603a;
  --pico-primary-hover-background: #18603a;
  --pico-primary-focus: rgba(29, 111, 66, .3);
  --pico-primary-inverse: #fff;
  --pico-border-radius: 12px;
  --pico-font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --pico-spacing: 1rem;
}
:root[data-theme="dark"] {
  --pico-primary: #2e9d5e;
  --pico-primary-background: #2e9d5e;
  --pico-primary-hover: #38b06c;
  --pico-primary-hover-background: #38b06c;
  --pico-primary-focus: rgba(46, 157, 94, .35);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --pico-primary: #2e9d5e;
    --pico-primary-background: #2e9d5e;
    --pico-primary-hover: #38b06c;
    --pico-primary-hover-background: #38b06c;
    --pico-primary-focus: rgba(46, 157, 94, .35);
  }
}

/* --- Our own design tokens (bespoke components) --- */
:root {
  --bg: #f4f6f8; --card: #fff; --ink: #16202b; --muted: #5c6b7a;
  --line: #e2e8f0; --brand: #1d6f42; --brand-ink: #fff;
  --accent: #c8102e; --ok: #1d6f42; --warn: #b8860b;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16,32,43,.08), 0 1px 2px rgba(16,32,43,.06);
  --shadow-lg: 0 6px 20px rgba(16,32,43,.12);
  --topbar: linear-gradient(180deg, #237a4b, #1d6f42);
}
/* Dark values — applied for an explicit dark theme OR for "system" + OS dark. */
:root[data-theme="dark"] {
  --bg: #0e151c; --card: #161f29; --ink: #e7edf3; --muted: #93a1b0;
  --line: #26313d; --brand: #2e9d5e; --shadow: none; --shadow-lg: none;
  --topbar: linear-gradient(180deg, #1a2b22, #14241c);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #0e151c; --card: #161f29; --ink: #e7edf3; --muted: #93a1b0;
    --line: #26313d; --brand: #2e9d5e; --shadow: none; --shadow-lg: none;
    --topbar: linear-gradient(180deg, #1a2b22, #14241c);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--pico-font-family);
}
a { color: var(--brand); text-decoration: none; transition: color .15s ease; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: .2rem 0 1rem; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; margin: 0 0 .7rem; }
h3 { font-size: 1rem; margin: 0 0 .4rem; }
.muted { color: var(--muted); font-size: .9rem; }
.error { color: var(--accent); font-weight: 600; }

/* --- topbar --- */
.topbar {
  position: sticky; top: 0; z-index: 5; background: var(--topbar); color: var(--brand-ink);
  padding: .6rem 1rem; box-shadow: var(--shadow-lg);
}
/* Full-width brand bar, but content aligned to the same centred column as the page. */
.topbar-inner {
  max-width: 960px; margin: 0 auto; width: 100%;
  display: flex; flex-wrap: wrap; align-items: center; gap: .25rem .75rem;
}
.brand { color: var(--brand-ink); font-weight: 700; font-size: 1.05rem; }
.brand:hover { text-decoration: none; opacity: .92; }
.topbar-right { margin-left: auto; display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; }
.nav { display: flex; flex-wrap: wrap; gap: .25rem; }
.nav a { color: var(--brand-ink); opacity: .85; padding: .4rem .65rem; border-radius: 8px; font-size: .95rem; transition: background .15s ease, opacity .15s ease; }
.nav a:hover { opacity: 1; text-decoration: none; background: rgba(255,255,255,.14); }
.nav a.active { opacity: 1; background: rgba(255,255,255,.22); font-weight: 600; }
.logout-top { color: var(--brand-ink); opacity: .85; padding: .4rem .65rem; border-radius: 8px; font-size: .95rem; transition: background .15s ease, opacity .15s ease; }
.logout-top:hover { opacity: 1; text-decoration: none; background: rgba(255,255,255,.14); }

/* On mobile the primary nav becomes a fixed bottom bar (thumb-friendly). */
@media (max-width: 719px) {
  .nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
    background: var(--topbar); box-shadow: 0 -2px 12px rgba(0,0,0,.22);
    flex-wrap: nowrap; justify-content: space-around; gap: 0; overflow-x: auto;
    padding: .5rem .4rem calc(.5rem + env(safe-area-inset-bottom, 0px));
  }
  .nav a {
    flex: 1 0 auto; text-align: center; white-space: nowrap;
    font-size: .85rem; padding: .5rem .6rem; border-radius: 6px;
  }
  .nav a.logout { opacity: .9; }
  /* Keep page content clear of the fixed bottom bar. */
  body { padding-bottom: calc(4rem + env(safe-area-inset-bottom, 0px)); }
}
.theme-toggle {
  width: auto; margin: 0; padding: .35rem .5rem; line-height: 1; font-size: 1.05rem;
  background: rgba(255,255,255,.12); color: var(--brand-ink); border: 1px solid rgba(255,255,255,.18);
  border-radius: 8px; cursor: pointer; transition: background .15s ease;
}
.theme-toggle:hover { background: rgba(255,255,255,.24); }

.container { max-width: 960px; margin: 0 auto; padding: 1.25rem 1rem; }
.footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 2rem 1rem; }

/* --- cards & grids --- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.15rem; margin-bottom: 1rem; box-shadow: var(--shadow);
}
.card.narrow { max-width: 380px; margin: 2.5rem auto; }
/* One card per row at every width — the standings table needs the space. */
.groups { display: grid; gap: 1rem; }
.groups .card { min-width: 0; margin-bottom: 0; }

/* --- forms (reset Pico's full-width/block behaviour inside inline rows) --- */
form label { display: block; margin: 0 0 .8rem; font-size: .9rem; color: var(--muted); }
.card.narrow input[type=password] { width: 100%; }
.inline { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; margin-bottom: 0; }
.adminfix form, .scoreform, .playerlist form, .assign form { margin-bottom: 0; }
.inline input, .inline select, .inline button,
.scoreform input, .scoreform select, .scoreform button {
  width: auto; margin-bottom: 0;
}
button.danger {
  background: transparent; color: var(--accent);
  border: 1px solid var(--line); font-weight: 500;
}
button.danger:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }

/* --- fixtures --- */
ul.fixtures { list-style: none; margin: 0; padding: 0; }
.fixture {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: .5rem;
  padding: .6rem 0; border-bottom: 1px solid var(--line);
}
.fixture:last-child { border-bottom: 0; }
.side { display: inline-flex; align-items: center; gap: .4rem; min-width: 0; }
.fixture .side:first-child { justify-content: flex-end; text-align: right; }
.side.tbd { color: var(--muted); font-style: italic; }
.flag { font-size: 1.2rem; line-height: 1; flex: none; }
.score { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.score .dash { margin: 0 .25rem; color: var(--muted); }
.score.live { color: var(--accent); }
.livedot { color: var(--accent); margin-left: .25rem; animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.kickoff { color: var(--muted); font-size: .85rem; white-space: nowrap; }
.tag {
  grid-column: 1 / -1; justify-self: center; color: var(--muted);
  font-size: .72rem; text-transform: uppercase; letter-spacing: .04em;
}
.dathdr { font-size: 1rem; color: var(--brand); }

/* --- standings --- */
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
/* Fixed layout so long team names can't widen the table past the card; the
   team column takes whatever the pinned numeric columns leave over. */
.standings { margin: 0; table-layout: fixed; }
.standings th[title] { width: 2.1rem; }
.standings th, .standings td { padding: .45rem .3rem; text-align: center; border: 0; }
.standings th { color: var(--muted); font-weight: 600; border-bottom: 2px solid var(--line); }
.standings td.team, .standings th:nth-child(2) { text-align: left; }
.standings tbody tr { border-bottom: 1px solid var(--line); }
.standings tbody tr:last-child { border-bottom: 0; }
.standings .pos { color: var(--muted); width: 1.4rem; }
.standings .team { display: flex; align-items: center; gap: .4rem; }
/* Safety on very narrow screens: long names ellipsize instead of widening the table. */
.standings .team .tname { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.standings .pts { font-weight: 700; }
.standings tr.qualify td.pos { color: var(--ok); font-weight: 700; }
.standings tr.qualify { background: color-mix(in srgb, var(--ok) 8%, transparent); }
.standings tr.maybe td.pos { color: var(--warn); font-weight: 700; }

/* --- leaderboard --- */
ol.leaderboard { list-style: none; margin: 0; padding: 0; }
.leaderboard > li { padding: .8rem 0; border-bottom: 1px solid var(--line); }
.leaderboard > li:last-child { border-bottom: 0; }
.lb-head { display: flex; align-items: center; gap: .6rem; }
.lb-rank { width: 1.7rem; height: 1.7rem; display: grid; place-items: center;
  background: var(--line); border-radius: 50%; font-weight: 700; font-size: .85rem; }
.leaderboard > li.leader .lb-rank { background: var(--warn); color: #fff; }
.lb-name { font-weight: 600; }
.lb-pts { margin-left: auto; font-weight: 700; }
.lb-teams { list-style: none; margin: .4rem 0 0; padding: 0 0 0 2.3rem; }
.lb-teams li { display: flex; align-items: center; gap: .4rem; font-size: .9rem; padding: .15rem 0; }
.lb-tpts { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.leaderboard.mini li { display: flex; padding: .4rem 0; border-bottom: 1px solid var(--line); }
.leaderboard.mini li:last-child { border-bottom: 0; }
.leaderboard.mini .lb-pts { font-weight: 700; }
ul.scoring { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: .3rem .8rem; }
ul.scoring li { display: flex; justify-content: space-between; border-bottom: 1px dotted var(--line); padding: .25rem 0; }

/* --- admin --- */
.adminfix { display: grid; gap: .5rem; }
.scoreform {
  display: flex; align-items: center; gap: .4rem; flex-wrap: wrap;
  padding: .55rem; border: 1px solid var(--line); border-radius: 10px; background: var(--card);
}
.scoreform .tag { grid-column: auto; justify-self: auto; flex-basis: 100%; text-align: left; }
.scoreform .sf-side { flex: 1 1 6rem; min-width: 0; }
.scoreform input[type=number] { width: 3.4rem; text-align: center; }
.scoreform select { flex: 1 1 8rem; }
.playerlist, .assign { list-style: none; margin: .6rem 0 0; padding: 0; }
.playerlist li { display: flex; justify-content: space-between; align-items: center;
  padding: .45rem 0; border-bottom: 1px solid var(--line); }
.playerlist li:last-child { border-bottom: 0; }
.assign td { padding: .45rem .3rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.assign .team { display: flex; align-items: center; gap: .4rem; }
