/* Colours used throughout the app. GBC is navy, MK is red. */
:root {
  --gbc: #1F3A68;
  --mk: #B3202A;
  --gold: #C9A227;
  --bg: #F4F4F1;
  --card: #FFFFFF;
  --text: #1C1C1C;
  --muted: #5E5E5A;
  --line: #E2E1DC;
  --tile: #EFEEE9;
  --chart-line: #1F3A68;
  --other: #A9A8A1;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141414;
    --card: #1F1F1F;
    --text: #F0F0EE;
    --muted: #A9A9A4;
    --line: #333330;
    --tile: #2A2A28;
    --chart-line: #8FB0E6;
    --other: #7C7C76;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 18px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
}
a { color: inherit; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  min-height: 56px;
  padding: env(safe-area-inset-top) 16px 0;
  background: var(--gbc); color: #fff;
}
.topbar .back {
  text-decoration: none; font-size: 18px;
  padding: 12px 4px; margin-left: -4px;
}
.topbar .back[hidden] { display: none; }
/* Logo + name: always takes you Home. With a Back button showing, it moves to the right as just the logo. */
.topbar .home { display: flex; align-items: center; gap: 10px; text-decoration: none; padding: 6px 0; }
.topbar .home img { width: 38px; height: 38px; border-radius: 8px; object-fit: cover; background: #fff; }
.topbar .home .title { font-weight: 600; font-size: 19px; }
.topbar .back:not([hidden]) + .home { margin-left: auto; }
.topbar .back:not([hidden]) + .home .title { display: none; }

/* Home screen */
.home-hero { text-align: center; margin: 4px 0 16px; }
.home-hero img { width: 150px; height: auto; border-radius: 16px; }
.home-hero h1 { margin-top: 10px; }
.feature { display: flex; align-items: center; gap: 14px; text-decoration: none; }
.feature .avatar { width: 72px; height: 72px; font-size: 24px; border: 3px solid var(--gold); }
.feature .label { font-size: 15px; color: var(--muted); }
.feature .big { font-size: 22px; font-weight: 600; line-height: 1.2; }
.links { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.links a {
  background: var(--card); border-radius: 14px; padding: 18px 10px; text-align: center;
  text-decoration: none; font-size: 17px; font-weight: 600;
}
.links .icon { display: block; font-size: 28px; margin-bottom: 4px; }
.card.draft { border: 2px dashed var(--gold); }
.card.draft p { margin: 6px 0 12px; }
.card.draft .button { margin-bottom: 0; }
a.card { display: block; text-decoration: none; }
a.card.feature { display: flex; }
.split span.badge { color: #fff; font-weight: 600; } /* beats the coloured-text rules for .split .GBC / .MK */

main { max-width: 560px; margin: 0 auto; padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); }

/* Bottom menu */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; max-width: 200px; min-height: 60px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; font-size: 14px; font-weight: 500; color: var(--muted);
}
.tabbar .icon { font-size: 22px; line-height: 1; filter: grayscale(1); opacity: 0.6; }
.tabbar a.active { color: var(--gbc); }
.tabbar a.active .icon { filter: none; opacity: 1; }
@media (prefers-color-scheme: dark) { .tabbar a.active { color: var(--chart-line); } }

/* Buttons */
.button {
  display: block; width: 100%; text-align: center; text-decoration: none;
  font-size: 18px; font-weight: 500; padding: 14px; border-radius: 12px;
  background: var(--card); border: 1.5px solid var(--gbc); color: var(--gbc); margin-bottom: 16px;
}
@media (prefers-color-scheme: dark) { .button { border-color: var(--chart-line); color: var(--chart-line); } }

/* Head-to-head */
.h2h-pick { display: flex; align-items: stretch; gap: 10px; margin-bottom: 16px; }
.h2h-pick .vs { align-self: center; font-weight: 600; color: var(--muted); }
.slot {
  flex: 1; min-width: 0; text-decoration: none; text-align: center;
  background: var(--card); border-radius: 14px; padding: 14px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.slot .avatar { width: 64px; height: 64px; font-size: 22px; }
.slot .avatar.empty { border: 2px dashed var(--line); background: transparent; font-size: 28px; }
.slot .name { font-size: 17px; font-weight: 600; line-height: 1.2; }
.slot .change { font-size: 14px; color: var(--muted); }
.split { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.split .big { font-size: 32px; font-weight: 600; line-height: 1.1; }
.split .mid { flex: 1; text-align: center; font-size: 15px; color: var(--muted); }
.bar { display: flex; height: 10px; border-radius: 5px; overflow: hidden; margin: 8px 0 6px; background: var(--tile); }
/* Head-to-head bar: each player's usual team colour, or light grey (see barColours in app.js) */
.bar .GBC { background: var(--gbc); }
.bar .MK { background: var(--mk); }
.bar .other { background: var(--other); }
.bar .level { background: var(--line); }
.split .GBC { color: var(--gbc); font-weight: 600; }
.split .MK { color: var(--mk); font-weight: 600; }
.split .other { color: var(--muted); font-weight: 600; }
@media (prefers-color-scheme: dark) { .split .GBC { color: var(--chart-line); } .split .MK { color: #EF9A9A; } }
.rows.fixed { table-layout: fixed; }
.rows.fixed tr > :first-child { width: 46%; }
.rows td.ahead { font-weight: 700; }
.rows td.ahead::after { content: " ✓"; color: var(--gold); }
.match { padding: 10px 0; border-top: 1px solid var(--line); }
.match:first-child { border-top: none; }
.match .what { font-size: 15px; color: var(--muted); }
.result { font-weight: 600; }
.result.W { color: #2E7D32; }
.result.L { color: var(--mk); }
@media (prefers-color-scheme: dark) { .result.W { color: #81C784; } .result.L { color: #EF9A9A; } }
/* Team pages */
.segmented { display: flex; background: var(--card); border-radius: 12px; padding: 4px; margin-bottom: 16px; gap: 4px; }
.segmented a, .segmented button {
  flex: 1; text-align: center; text-decoration: none; font: inherit; font-size: 17px; font-weight: 600;
  padding: 10px; border: none; border-radius: 9px; background: transparent; color: var(--muted); cursor: pointer;
}
.segmented .on.GBC { background: var(--gbc); color: #fff; }
.segmented .on.MK { background: var(--mk); color: #fff; }
.segmented.small a, .segmented.small button { font-size: 15px; padding: 8px; }
.segmented.small { background: var(--tile); margin: 0 0 8px; }
.segmented.small .on { background: var(--card); color: var(--text); }
.team-head { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.team-head img { width: 76px; height: 76px; border-radius: 14px; object-fit: cover; background: var(--card); }
.team-head .full { font-size: 15px; color: var(--muted); }
.series-num { font-size: 32px; font-weight: 700; }
.series-num.GBC { color: var(--gbc); }
.series-num.MK { color: var(--mk); }
@media (prefers-color-scheme: dark) { .series-num.GBC { color: var(--chart-line); } .series-num.MK { color: #EF9A9A; } }
.year-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.year-row:first-child { border-top: none; }
.year-row .yr { width: 52px; font-weight: 600; }
.year-row .score { flex: 1; }
.year-row .note { display: block; font-size: 14px; color: var(--muted); }
.contrib { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line); text-decoration: none; }
.contrib:first-child { border-top: none; }
.contrib .rank { width: 18px; color: var(--muted); font-weight: 600; }
.contrib .avatar { width: 40px; height: 40px; font-size: 15px; border: none; }
.contrib .who { flex: 1; min-width: 0; }
.contrib .who b { display: block; font-weight: 500; }
.contrib .rec { font-size: 14px; color: var(--muted); }
.contrib .val { font-weight: 700; font-size: 18px; white-space: nowrap; }
.squad { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px 8px; }
.squad a { text-decoration: none; text-align: center; font-size: 14px; line-height: 1.2; }
.squad .avatar { width: 60px; height: 60px; margin: 0 auto 4px; font-size: 18px; border: none; }

/* Honours */
.honour { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.honour:first-of-type { border-top: none; }
.honour .yr { width: 48px; flex: none; font-weight: 600; }
.honour .avatar { width: 44px; height: 44px; font-size: 15px; border: none; }
.honour .who { flex: 1; min-width: 0; }
.honour .who a { font-weight: 500; text-decoration: none; }
.honour .sub { display: block; font-size: 14px; color: var(--muted); }
.honour .sub a { font-weight: 400; }
.honour .score { font-weight: 600; white-space: nowrap; }
.record { padding: 12px 0; border-top: 1px solid var(--line); }
.record:first-of-type { border-top: none; }
.record .label { font-size: 15px; color: var(--muted); }
.record .value { font-size: 24px; font-weight: 700; line-height: 1.25; }
.record .holders { font-size: 16px; }
.record .holders a { text-decoration: none; font-weight: 500; }
.record .holders .muted { font-size: 14px; }

.facts { margin: 0; padding: 0; list-style: none; }
.facts li { padding: 8px 0; border-top: 1px solid var(--line); }
.facts li:first-child { border-top: none; }
.loading, .empty { color: var(--muted); text-align: center; padding: 32px 0; }

/* Cards and headings */
.card { background: var(--card); border-radius: 14px; padding: 16px; margin-bottom: 16px; }
h1 { font-size: 26px; line-height: 1.2; margin: 0; }
h2 { font-size: 21px; margin: 0 0 12px; }
h3 { font-size: 16px; font-weight: 600; color: var(--muted); margin: 18px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 15px; }

/* Team badges */
.badge {
  display: inline-block; color: #fff; font-size: 14px; font-weight: 600;
  padding: 2px 8px; border-radius: 6px; white-space: nowrap; vertical-align: 2px;
}
.badge.GBC { background: var(--gbc); }
.badge.MK { background: var(--mk); }
.badge.unknown { background: var(--tile); color: var(--muted); }

/* Player photos / initials */
.avatar {
  flex: none; width: 48px; height: 48px; border-radius: 50%;
  object-fit: cover; background: var(--tile); color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 17px;
}
.avatar.big { width: 88px; height: 88px; font-size: 28px; }
.avatar.GBC { border: 3px solid var(--gbc); }
.avatar.MK { border: 3px solid var(--mk); }

/* Player list */
.search {
  width: 100%; font-size: 18px; padding: 14px 16px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); color: var(--text); margin-bottom: 8px;
}
.list-heading { font-size: 15px; font-weight: 600; color: var(--muted); margin: 20px 4px 6px; }
.player-list { list-style: none; margin: 0; padding: 0; background: var(--card); border-radius: 14px; overflow: hidden; }
.player-list a {
  display: flex; align-items: center; gap: 14px;
  min-height: 72px; padding: 10px 16px;
  text-decoration: none; border-bottom: 1px solid var(--line);
}
.player-list li:last-child a { border-bottom: none; }
.player-list .who { flex: 1; min-width: 0; }
.player-list .name { display: block; font-size: 19px; font-weight: 500; }
.player-list .sub { display: block; }
.player-list .sub { font-size: 15px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Profile header */
.profile-head { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
.profile-head .nick { font-size: 17px; color: var(--muted); margin-top: 2px; }
.profile-head .badge { margin-top: 8px; }

/* Number tiles */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tiles.three { grid-template-columns: 1fr 1fr 1fr; }
.tile { background: var(--tile); border-radius: 10px; padding: 10px 12px; }
.tile .num { display: block; font-size: 28px; font-weight: 600; line-height: 1.2; }
.tile .lbl { font-size: 15px; color: var(--muted); }

/* Chart */
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis { font-size: 12px; fill: var(--muted); }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--chart-line); stroke-width: 2.5; }
.chart .pt { fill: var(--chart-line); }
.chart .pt.win { fill: var(--gold); stroke: var(--chart-line); stroke-width: 1.5; }
.chart .pt.sel { stroke: var(--text); stroke-width: 3; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart-caption { min-height: 26px; font-size: 16px; margin-top: 4px; }

/* Simple tables (year by year, records by format) */
.rows { width: 100%; border-collapse: collapse; font-size: 17px; }
.rows th { text-align: left; font-size: 14px; font-weight: 600; color: var(--muted); padding: 6px 4px; }
.rows td { padding: 9px 4px; border-top: 1px solid var(--line); }
.rows .r { text-align: right; }
details summary { cursor: pointer; padding: 10px 0 4px; font-size: 17px; color: var(--gbc); font-weight: 500; }
@media (prefers-color-scheme: dark) { details summary { color: var(--chart-line); } }

/* Team-by-year strip */
.strip { display: flex; flex-wrap: wrap; gap: 6px; }
.strip .badge { font-size: 13px; padding: 3px 7px; }

/* Honours: Cups / Awards switch, Boston Sand Wedge, awards */
.segmented .on.plain { background: var(--gbc); color: #fff; }
@media (prefers-color-scheme: dark) { .segmented .on.plain { background: var(--chart-line); color: #141414; } }
.stack { display: flex; flex: none; }
.stack .avatar { width: 40px; height: 40px; font-size: 14px; border: 2px solid var(--card); }
.stack .avatar + .avatar { margin-left: -14px; }
.honour .stack .avatar { width: 40px; height: 40px; border: 2px solid var(--card); }
.award .desc { margin: -8px 0 6px; }
.award .rows td.yr { width: 60px; font-weight: 600; }
.award .rows td a, .trophy { text-decoration: none; }
.award .rows td a { font-weight: 500; }
.award p a { text-decoration: none; font-weight: 500; }

/* Trophy cabinet on a profile */
.trophy { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.trophy .count { width: 44px; flex: none; font-size: 20px; font-weight: 700; color: var(--gold); }
.trophy .what { flex: 1; min-width: 0; }
.trophy .what b { display: block; font-weight: 500; }
.trophy .sub { font-size: 14px; color: var(--muted); }
.award { scroll-margin-top: 72px; }

/* Rule book */
.rules-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.rules-head a { color: var(--gbc); font-weight: 500; }
@media (prefers-color-scheme: dark) { .rules-head a { color: var(--chart-line); } }
.rule-page { display: block; width: 100%; height: auto; margin: 0 0 12px; border-radius: 6px; background: #fff; }

/* Password screen */
body.locked .tabbar { display: none; }
.gate { text-align: center; padding-top: 24px; max-width: 360px; margin: 0 auto; }
.gate img { width: 140px; height: auto; border-radius: 16px; }
.gate h1 { margin: 10px 0 4px; }
.gate .search { margin: 16px 0 4px; text-align: center; }
.gate .error { min-height: 22px; margin: 4px 0 8px; font-size: 15px; color: var(--mk); }
.button.primary { background: var(--gbc); color: #fff; font: inherit; font-weight: 600; cursor: pointer; }
@media (prefers-color-scheme: dark) { .gate .error { color: #EF9A9A; } .button.primary { background: var(--chart-line); color: #141414; } }
