/* Layout: single column, phone first; sticky top bar, fixed bottom tab bar. */
:root {
  --bg: #eef0eb;
  --surface: #ffffff;
  --surface-2: #f6f7f3;
  --ink: #121512;
  --muted: #5b655d;
  --line: #d7dbd2;
  --accent: #1b7a45;
  --accent-ink: #ffffff;
  --gold: #e3a90b;
  --danger: #c0392b;
  --danger-soft: #fbe9e6;
  --success-soft: #e3f3e8;
  --warning-soft: #fdf3d8;
  --kit-black: #0e100f;
  --kit-black-ink: #ffffff;
  --kit-white: #ffffff;
  --kit-white-ink: #121512;
  --shadow: 0 1px 2px rgb(18 21 18 / 6%), 0 4px 14px rgb(18 21 18 / 6%);
  --radius: 14px;
  --font-display: 'Saira Condensed', 'Arial Narrow', 'Roboto Condensed', sans-serif;
  --font-body: 'Source Sans 3', -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0f0d;
    --surface: #161a17;
    --surface-2: #1d221e;
    --ink: #ecefe9;
    --muted: #9aa59c;
    --line: #2b322d;
    --accent: #43b46e;
    --accent-ink: #08130c;
    --gold: #f2bf3a;
    --danger: #ef6f5f;
    --danger-soft: #3a1c18;
    --success-soft: #16301f;
    --warning-soft: #3a3016;
    --kit-black: #000000;
    --kit-white: #f3f4f1;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 var(--font-body);
  padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
}
img { max-width: 100%; display: block; }
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--font-display); line-height: 1.1; text-wrap: balance; margin: 0; letter-spacing: 0.01em; }
h1 { font-size: 1.9rem; font-weight: 800; }
h2 { font-size: 1.35rem; font-weight: 700; }
h3 { font-size: 1.1rem; font-weight: 700; }
p { margin: 0; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.label { font-size: 0.75rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
  background: var(--kit-black);
  color: var(--kit-black-ink);
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.brand-mark { display: flex; width: 30px; height: 30px; border-radius: 50%; overflow: hidden; border: 2px solid #fff; }
.brand-mark span { flex: 1; }
.brand-mark span:first-child { background: #000; }
.brand-mark span:last-child { background: #fff; }
.brand-name { font-family: var(--font-display); font-weight: 800; font-size: 1.3rem; letter-spacing: 0.02em; }
.topbar-links { display: flex; gap: 6px; align-items: center; }
.topbar-links a, .topbar-links button {
  color: #fff; text-decoration: none; font-size: 0.85rem; font-weight: 600;
  padding: 6px 10px; border-radius: 999px; background: rgb(255 255 255 / 12%); border: 0; font-family: inherit; cursor: pointer;
}
.badge-count {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 999px; background: var(--danger); color: #fff; font-size: 0.75rem; font-weight: 700; margin-left: 4px;
}

/* ---------- Bottom tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 2px 9px; color: var(--muted); text-decoration: none; font-size: 0.7rem; font-weight: 600;
}
.tabbar a svg { width: 24px; height: 24px; }
.tabbar a[aria-current='page'] { color: var(--accent); }

/* ---------- Page ---------- */
.page { max-width: 720px; margin: 0 auto; padding-inline: 16px; padding-block: 18px 28px; display: grid; gap: 18px; }
.page-head { display: flex; align-items: end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.stack { display: grid; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row-between { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; display: grid; gap: 12px; min-width: 0; }
.card-link { color: inherit; text-decoration: none; }
.card-link:focus-visible, a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }

/* ---------- Flash ---------- */
.flash { border-radius: 12px; padding: 12px 14px; font-weight: 600; }
.flash-success { background: var(--success-soft); }
.flash-error { background: var(--danger-soft); color: var(--danger); }
.flash-info { background: var(--warning-soft); }

/* ---------- Scoreboard ---------- */
.scoreboard { display: grid; grid-template-columns: 1fr auto 1fr; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); }
.scoreboard .side { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 14px; }
.scoreboard .side-black { background: var(--kit-black); color: var(--kit-black-ink); }
.scoreboard .side-white { background: var(--kit-white); color: var(--kit-white-ink); flex-direction: row-reverse; }
.scoreboard .team-label { font-family: var(--font-display); font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.95rem; }
.scoreboard .score { font-family: var(--font-display); font-weight: 800; font-size: 2.2rem; line-height: 1; font-variant-numeric: tabular-nums; }
.scoreboard .vs { display: grid; place-items: center; padding: 0 8px; background: var(--surface-2); color: var(--muted); font-weight: 700; font-size: 0.8rem; }
.scoreboard.big .score { font-size: 3.2rem; }

/* ---------- Pills ---------- */
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px; font-size: 0.78rem; font-weight: 700; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill-complete { background: var(--success-soft); color: var(--accent); }
.pill-pending { background: var(--warning-soft); color: #9a6b00; }
.pill-cancelled { background: var(--danger-soft); color: var(--danger); }
.pill-scheduled { background: var(--surface-2); color: var(--ink); }
.pill-gold { background: var(--warning-soft); color: #8a6100; }
@media (prefers-color-scheme: dark) { .pill-pending, .pill-gold { color: var(--gold); } }
.kit-dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 1.5px solid var(--ink); vertical-align: -1px; }
.kit-dot.black { background: #000; }
.kit-dot.white { background: #fff; }

.form-strip { display: inline-flex; gap: 3px; }
.form-strip span { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 6px; font-size: 0.75rem; font-weight: 800; color: #fff; }
.form-strip .win { background: var(--accent); }
.form-strip .draw { background: #8a948c; }
.form-strip .loss { background: var(--danger); }

/* ---------- Avatars ---------- */
.avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: var(--surface-2); flex: none; border: 2px solid var(--line); }
.avatar.lg { width: 112px; height: 112px; border-width: 3px; }
.avatar.sm { width: 30px; height: 30px; }
.person { display: flex; align-items: center; gap: 10px; min-width: 0; color: inherit; text-decoration: none; }
.person-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Lists ---------- */
.list { display: grid; }
.list > * { padding: 10px 0; border-bottom: 1px solid var(--line); }
.list > *:last-child { border-bottom: 0; }
.lineups { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 520px) { .lineups { grid-template-columns: 1fr; } }
.lineup { border-radius: 12px; overflow: hidden; border: 1px solid var(--line); background: var(--surface); }
.lineup-head { padding: 8px 12px; font-family: var(--font-display); font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; display: flex; justify-content: space-between; }
.lineup-black .lineup-head { background: var(--kit-black); color: var(--kit-black-ink); }
.lineup-white .lineup-head { background: var(--kit-white); color: var(--kit-white-ink); border-bottom: 1px solid var(--line); }
.lineup-body { padding: 4px 12px 10px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin-inline: -16px; padding-inline: 16px; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 6px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 700; }
th a { color: inherit; text-decoration: none; }
th a.active { color: var(--accent); }
td:first-child, th:first-child { text-align: left; }
td.player-cell { position: sticky; left: 0; background: var(--surface); }

/* ---------- Stats tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.tile { background: var(--surface-2); border-radius: 12px; padding: 10px; display: grid; gap: 2px; }
.tile .value { font-family: var(--font-display); font-size: 1.6rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
.tile .caption { font-size: 0.75rem; color: var(--muted); font-weight: 600; }

/* ---------- Forms ---------- */
label { display: grid; gap: 4px; font-weight: 600; font-size: 0.9rem; }
input, select, textarea {
  font: inherit; font-size: 16px; color: var(--ink); background: var(--surface);
  border: 1.5px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; min-width: 0;
}
input[type='checkbox'], input[type='radio'] { width: 22px; height: 22px; accent-color: var(--accent); }
input[type='number'] { text-align: center; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 10px 18px; border-radius: 12px; border: 0; cursor: pointer;
  font: 700 1rem var(--font-body); text-decoration: none;
  background: var(--accent); color: var(--accent-ink);
}
.btn-block { width: 100%; }
.btn-secondary { background: var(--surface-2); color: var(--ink); border: 1.5px solid var(--line); }
.btn-dark { background: var(--kit-black); color: var(--kit-black-ink); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-small { min-height: 36px; padding: 6px 12px; font-size: 0.9rem; border-radius: 10px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Stage editor ---------- */
.stage { display: grid; gap: 8px; padding: 12px; border-radius: 12px; background: var(--surface-2); }
.stage-fields { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.stage-fields label { font-size: 0.7rem; font-weight: 700; color: var(--muted); text-align: center; }
.stage-fields input { padding: 8px 4px; }
@media (max-width: 420px) { .stage-fields { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

/* ---------- Issues ---------- */
.issues { margin: 0; padding-left: 20px; display: grid; gap: 4px; }
.issues li { color: var(--muted); }

/* ---------- Infirmary ---------- */
.ward { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.bed {
  position: relative; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 16px 14px; display: grid; gap: 10px; border-top: 6px solid var(--danger);
}
.bed::after {
  content: '+'; position: absolute; top: 10px; right: 14px; font: 800 1.6rem/1 var(--font-display); color: var(--danger);
}
.progress { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); }
.ambulance-banner { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-radius: var(--radius); background: var(--danger); color: #fff; }
.ambulance-banner svg { width: 54px; height: 54px; flex: none; }

/* ---------- Team picker ---------- */
.pick-list { display: grid; gap: 6px; }
.pick-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; background: var(--surface); border: 1.5px solid var(--line); }
.pick-item.is-disabled { opacity: 0.55; }
.pick-item:has(input:checked) { border-color: var(--accent); background: var(--success-soft); }
.balance { display: grid; grid-template-columns: auto 1fr 1fr; gap: 4px 12px; font-variant-numeric: tabular-nums; }
.balance div:nth-child(3n + 2), .balance div:nth-child(3n) { text-align: right; font-weight: 700; }

.ratings-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.ratings-grid label { font-size: 0.7rem; text-align: center; color: var(--muted); }
.ratings-grid input { padding: 8px 2px; }

.delta-up { color: var(--accent); font-weight: 800; }
.delta-down { color: var(--danger); font-weight: 800; }
.delta-same { color: var(--muted); font-weight: 800; }

/* ---------- Profile ---------- */
.profile-head { display: grid; justify-items: center; gap: 8px; text-align: center; }
.photo-button { position: relative; border: 0; padding: 0; background: none; border-radius: 50%; cursor: pointer; }
.photo-button .camera {
  position: absolute; right: 2px; bottom: 2px; width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); border: 3px solid var(--surface);
}

/* ---------- Help ---------- */
.prose { display: grid; gap: 10px; max-width: 65ch; }
.prose ul, .prose ol { margin: 0; padding-left: 22px; display: grid; gap: 4px; }
details.card summary { cursor: pointer; font-family: var(--font-display); font-weight: 700; font-size: 1.15rem; list-style: none; display: flex; justify-content: space-between; }
details.card summary::after { content: '+'; color: var(--accent); font-weight: 800; }
details.card[open] summary::after { content: '–'; }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; }
.hidden { display: none !important; }

@media (prefers-reduced-motion: no-preference) {
  .btn, .pick-item { transition: background-color 0.15s, border-color 0.15s, transform 0.1s; }
  .btn:active { transform: scale(0.98); }
}
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }
.card.row-between, .card.row { display: flex; }
.card.row-between { flex-wrap: nowrap; }
.card.row-between > :first-child { min-width: 0; }
.streak { display: inline-block; min-width: 30px; padding: 2px 6px; border-radius: 6px; font-weight: 800; font-size: 0.8rem; text-align: center; background: var(--surface-2); color: var(--muted); }
.streak-win { background: var(--accent); color: #fff; }
.streak-loss { background: var(--danger); color: #fff; }
.duel { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }
.duel-right { justify-content: flex-end; text-align: right; }
.duel-vs { font-family: var(--font-display); font-weight: 800; color: var(--muted); text-transform: uppercase; }
.meetings-badge { display: flex; align-items: center; gap: 6px; padding: 10px 14px; border-radius: 12px; background: var(--warning-soft); color: var(--ink); font-weight: 700; text-decoration: none; }
.streak-columns { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.highlight { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; text-decoration: none; color: var(--ink); }
.highlight-hot { background: var(--success-soft); }
.highlight-cold { background: var(--danger-soft); }
.preview-card, .next-match { position: relative; overflow: hidden; padding-top: 22px; }
.preview-card::before, .next-match::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 6px;
  background: linear-gradient(90deg, var(--kit-black) 50%, var(--kit-white) 50%); border-bottom: 1px solid var(--line);
}
.preview-text { font-weight: 600; }
.preview-facts { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.preview-facts li { line-height: 1.35; }
