/* Layout: a sidebar (games list / clubs grid) beside a full-height map.
   On phones the map sits on top and the sidebar scrolls underneath. */

:root {
  --bg: #f3f5f1;
  --panel: #ffffff;
  --ink: #17211b;
  --muted: #5d6b62;
  --line: #dbe2dc;
  --pitch: #1f7a4a;
  --pin: #c8102e;
  --display: "Barlow Condensed", "Arial Narrow", sans-serif;
  --body: "Source Sans 3", system-ui, sans-serif;

  /* Numbers tab. Results run home win -> draw -> away win, so they get two opposite
     hues with a neutral middle. Both modes were checked for colour-blind separation
     and 3:1 contrast against the panel; green/red failed, which is why home is blue. */
  --result-home: #2a78d6;
  --result-draw: #5d6b62;
  --result-away: #c8102e;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101612;
    --panel: #18211b;
    --ink: #e6ede8;
    --muted: #9aa89f;
    --line: #2a362e;
    --pitch: #3fb27a;
    --pin: #ff4d63;
    --result-home: #3987e5;
    --result-draw: #9aa89f;
    --result-away: #d94f63;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  display: grid;
  grid-template-columns: 340px 1fr;
  grid-template-rows: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 var(--body);
}

#map { height: 100%; }

/* ---------- Sidebar header ---------- */

.sidebar {
  overflow-y: auto;
  padding: 20px 16px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.sidebar h1 {
  margin: 0 0 6px;
  color: var(--pitch);
  font: 700 30px/1 var(--display);
  letter-spacing: .01em;
  text-transform: uppercase;
}

.subtitle {
  margin: 0 0 16px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.stats { display: flex; gap: 18px; margin: 0 0 18px; }
.stats div { font: 700 26px/1 var(--display); }
.stats span {
  display: block;
  color: var(--muted);
  font: 600 11px/1.4 var(--body);
  letter-spacing: .08em;
  text-transform: uppercase;
}

/* ---------- Tabs ---------- */

.tabs {
  display: flex;
  gap: 4px;
  margin: 0 0 14px;
  border-bottom: 1px solid var(--line);
}

.tabs button {
  all: unset;
  cursor: pointer;
  flex: 1;
  margin-bottom: -1px;
  padding: 8px 4px;
  border-bottom: 3px solid transparent;
  text-align: center;
  color: var(--muted);
  font: 700 15px/1 var(--display);
  letter-spacing: .06em;
  text-transform: uppercase;
}

.tabs button[aria-selected="true"] { color: var(--pitch); border-color: var(--pitch); }
.tabs button:focus-visible { outline: 2px solid var(--pitch); outline-offset: 2px; }

/* ---------- Games tab ---------- */

.month {
  display: flex;
  justify-content: space-between;
  margin: 16px 0 6px;
  color: var(--muted);
  font: 600 12px/1 var(--body);
  letter-spacing: .1em;
  text-transform: uppercase;
}

.month span {
  font-weight: 500;
  letter-spacing: .05em;
}

.game {
  all: unset;
  cursor: pointer;
  display: grid;
  grid-template-columns: 52px 1fr auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 6px;
  border-bottom: 1px solid var(--line);
  border-radius: 6px;
}

.game:hover,
.game:focus-visible {
  background: color-mix(in srgb, var(--pitch) 12%, transparent);
  outline: none;
}

.game-date {
  align-self: start;
  color: var(--muted);
  font: 600 13px/1.3 var(--display);
  font-variant-numeric: tabular-nums;
  text-transform: uppercase;
}

.game-title { font-weight: 600; }
.game-ground { color: var(--muted); font-size: 13px; }

/* Photo thumbnail on a game row or in a popup; the number shows when there's more than one */
.thumb {
  position: relative;
  display: inline-block;
  cursor: zoom-in;
  width: 56px;
  height: 42px;
  border-radius: 4px;
  overflow: hidden;
  background: var(--line);
}

.thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.thumb:hover,
.thumb:focus-visible { outline: 2px solid var(--pitch); outline-offset: 1px; }

.thumb span {
  position: absolute;
  right: 2px;
  bottom: 2px;
  padding: 1px 4px;
  border-radius: 3px;
  background: rgba(0, 0, 0, .65);
  color: #fff;
  font: 700 11px/1.2 var(--display);
}

.leaflet-popup-content .thumb { display: block; width: 120px; height: 90px; margin: 4px 0 2px; }

/* ---------- Clubs tab ---------- */

/* Search sticks to the top of the sidebar so it stays in reach down a long grid */
.club-search {
  position: sticky;
  top: -20px; /* the sidebar's top padding, so it sits flush when stuck */
  z-index: 1;
  display: block;
  width: 100%;
  margin: 0 0 12px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font: 400 15px/1.2 var(--body);
  box-shadow: 0 -20px 0 var(--panel); /* covers cards scrolling up behind the gap above it */
}
.club-search::placeholder { color: var(--muted); }
.club-search:focus-visible { outline: 2px solid var(--pitch); outline-offset: -1px; border-color: transparent; }

.club[hidden] { display: none; }
.club-none { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

.club-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 10px;
}

.club {
  all: unset;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: center;
}

.club:hover,
.club:focus-visible,
.club.selected {
  background: color-mix(in srgb, var(--pitch) 12%, transparent);
  outline: none;
}

.club img,
.badge { width: 56px; height: 56px; object-fit: contain; }

/* Placeholder for clubs without a crest: initials on a colour picked from the name */
.badge {
  display: grid;
  place-items: center;
  border: 2px dashed color-mix(in srgb, var(--ink) 25%, transparent);
  border-radius: 50%;
  background: var(--badge-colour);
  color: #fff;
  font: 700 20px/1 var(--display);
}

.club-name { font: 600 13px/1.2 var(--body); }
.club-count {
  color: var(--muted);
  font: 700 12px/1 var(--display);
  letter-spacing: .06em;
  text-transform: uppercase;
}

.club-record {
  font: 700 12px/1 var(--display);
  letter-spacing: .06em;
}
.club-record .w { color: var(--pitch); }
.club-record .d { color: var(--muted); }
.club-record .l { color: #e0735f; }

/* Expanded list of a club's games, inserted after the selected club's row */
.club-games {
  grid-column: 1 / -1;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--bg);
  font-size: 13px;
}

.club-games ul { margin: 4px 0 0; padding-left: 16px; }
.club-games li { cursor: pointer; }
.club-games li:hover { color: var(--pitch); }

.hint { margin: 12px 0 0; color: var(--muted); font-size: 12px; }

/* ---------- Grounds tab ---------- */

.ground {
  all: unset;
  cursor: pointer;
  display: grid;
  grid-template-columns: 46px 1fr auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 6px;
  border-bottom: 1px solid var(--line);
  border-radius: 6px;
}

.ground:hover,
.ground:focus-visible {
  background: color-mix(in srgb, var(--pitch) 12%, transparent);
  outline: none;
}

.ground-date {
  color: var(--muted);
  font: 600 13px/1.15 var(--display);
  font-variant-numeric: tabular-nums;
  text-transform: uppercase;
}

.ground-name { font-weight: 600; overflow-wrap: anywhere; }

.ground-count {
  color: var(--muted);
  font: 700 12px/1 var(--display);
  letter-spacing: .06em;
  text-transform: uppercase;
}

/* ---------- Numbers tab ---------- */

.section {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin: 20px 0 8px;
  color: var(--muted);
  font: 600 12px/1 var(--body);
  letter-spacing: .1em;
  text-transform: uppercase;
}

.section span {
  font-weight: 400;
  letter-spacing: .04em;
  text-transform: none;
}

.bars,
.split,
.records { margin: 0; padding: 0; list-style: none; }

/* A name, a bar of its share of the biggest value, and the count */
.bars li,
.split li {
  display: grid;
  grid-template-columns: 1fr 56px 18px;
  align-items: center;
  gap: 8px;
  padding: 3px 2px;
  border-radius: 4px;
  font-size: 13px;
}

.split li { grid-template-columns: 10px 1fr 18px; }

.bars li[data-ground] { cursor: pointer; }
.bars li[data-ground]:hover,
.bars li[data-ground]:focus-visible,
.records li:hover,
.records li:focus-visible {
  background: color-mix(in srgb, var(--pitch) 12%, transparent);
  outline: none;
}

.bar-label { overflow-wrap: anywhere; }

.bar-value {
  color: var(--muted);
  font: 700 13px/1 var(--display);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.bar-track {
  height: 10px;
  border-radius: 2px;
  background: var(--bg);
}

.bar-fill {
  display: block;
  height: 100%;
  border-radius: 0 4px 4px 0;
  background: var(--pitch);
}

/* Who won: a swatch per row carries the identity, so the bar below needs no legend */
.swatch { width: 10px; height: 10px; border-radius: 50%; }

.split-bar { display: flex; gap: 2px; height: 8px; margin: 6px 0 0; }
.split-bar span { border-radius: 2px; }
.split-bar span:first-child { border-top-left-radius: 999px; border-bottom-left-radius: 999px; }
.split-bar span:last-child { border-top-right-radius: 999px; border-bottom-right-radius: 999px; }

[data-result="home"] { background: var(--result-home); }
[data-result="draw"] { background: var(--result-draw); }
[data-result="away"] { background: var(--result-away); }

/* Games by month: twelve columns on a hairline baseline, empty months left empty */
.columns {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 2px;
  align-items: end;
  border-bottom: 1px solid var(--line);
}

.column { display: grid; justify-items: center; gap: 3px; }

.column-value {
  min-height: 11px;
  color: var(--muted);
  font: 700 11px/1 var(--display);
  font-variant-numeric: tabular-nums;
}

.column-track { display: flex; align-items: flex-end; width: 14px; height: 54px; }

.column-fill {
  width: 100%;
  border-radius: 4px 4px 0 0;
  background: var(--pitch);
}

.column-label {
  margin-bottom: 3px;
  color: var(--muted);
  font: 600 10px/1 var(--body);
}

.records li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 8px;
  cursor: pointer;
  padding: 5px 2px;
  border-radius: 4px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.record-label {
  grid-column: 1 / -1;
  color: var(--muted);
  font: 600 11px/1 var(--body);
  letter-spacing: .07em;
  text-transform: uppercase;
}

.record-game { font-weight: 600; }
.record-note { color: var(--muted); font-size: 12px; }

/* ---------- Map pins, popups and the "show all" control ---------- */

.pin {
  display: grid;
  place-items: center;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--pin);
  color: #fff;
  font: 700 13px/1 var(--display);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .4);
}

.pin.highlighted { background: var(--pitch); }

/* Crest pin: the club I've most often seen host at this ground. The white disc is what makes
   crests of any colour read against both the street and the dark tiles. */
.pin.crest {
  position: relative;
  /* Flex, not the grid .pin uses: a percentage height on the crest only resolves against a
     definite container height here, and without it a tall crest keeps its own aspect and spills. */
  display: flex;
  align-items: center;
  justify-content: center;
  /* object-fit fits a crest to its square, but the pin is a circle, so artwork near the corners
     of that square hangs out of the disc. How much padding that needs was measured rather than
     guessed: across the crests actually used, the furthest opaque pixel sits at 1.34x the
     artwork's half-width (Stella Maris; most are nearer 1.1), not the 1.41x a crest filling its
     whole square would reach. The border counts as disc here, being white too, so 4px leaves a
     24px crest whose furthest point lands 16px out with the disc edge at 18px. */
  padding: 4px;
  background: #fff;
  /* A hairline under the white border, so the disc still has an edge on pale street tiles */
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .22), 0 1px 5px rgba(0, 0, 0, .4);
}

/* width/height, not max-*: Leaflet forces `max-width/max-height: none !important` on every img in
   the marker pane, so a max-* cap is ignored and the crest renders at its full 128px. */
.pin.crest img { width: 100%; height: 100%; object-fit: contain; display: block; }

/* Same placeholder as the Clubs tab, for a home club with no crest file */
.pin.crest .initials {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--badge-colour);
  color: #fff;
  font: 700 11px/1 var(--display);
}

/* Filtered to one club: a green ring round the disc, since the crest fills the pin itself */
.pin.crest.highlighted {
  background: #fff;
  border-color: var(--pitch);
  box-shadow: 0 0 0 1px var(--pitch), 0 1px 5px rgba(0, 0, 0, .4);
}

/* Games played here, once there's been more than one */
.pin .count {
  position: absolute;
  top: -5px;
  right: -5px;
  display: grid;
  place-items: center;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--pitch);
  color: #fff;
  font: 700 11px/1 var(--display);
  box-shadow: 0 0 0 2px #fff;
}

.leaflet-popup-content { font: 14px/1.4 var(--body); }
.leaflet-popup-content b {
  color: #1f7a4a;
  font: 700 17px/1.2 var(--display);
  text-transform: uppercase;
}
.leaflet-popup-content ul { margin: 6px 0 0; padding-left: 16px; }
.leaflet-popup-content small { color: #5d6b62; font-size: 12px; }

.show-all {
  cursor: pointer;
  padding: 8px 12px;
  border: 0;
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  font: 700 14px/1 var(--display);
  letter-spacing: .05em;
  text-transform: uppercase;
  box-shadow: 0 1px 5px rgba(0, 0, 0, .35);
}

.show-all b { color: var(--pitch); }

/* ---------- Photo viewer ---------- */

#lightbox {
  width: 100vw;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 16px;
  border: 0;
  background: rgba(0, 0, 0, .92);
  color: #fff;
}

#lightbox[open] {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

#lightbox::backdrop { background: transparent; }

#lightbox img {
  max-width: 100%;
  max-height: calc(100dvh - 80px);
  object-fit: contain;
  border-radius: 4px;
}

#lightbox p { margin: 0; font-size: 14px; text-align: center; }

#lightbox button {
  position: absolute;
  cursor: pointer;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, .15);
  color: #fff;
  font: 400 28px/1 var(--body);
}

#lightbox button:hover,
#lightbox button:focus-visible { background: rgba(255, 255, 255, .3); outline: none; }

.lightbox-prev { left: 12px; top: 50%; translate: 0 -50%; }
.lightbox-next { right: 12px; top: 50%; translate: 0 -50%; }
.lightbox-close { right: 12px; top: 12px; font-size: 20px !important; }
#lightbox.single .lightbox-prev,
#lightbox.single .lightbox-next { display: none; }

/* ---------- Phones ---------- */

@media (max-width: 760px) {
  body { grid-template-columns: 1fr; grid-template-rows: 55vh auto; height: auto; }
  #map { order: -1; height: 55vh; }
  .sidebar { overflow: visible; border-right: 0; }
  /* The page scrolls here, not the sidebar, so stick to the top of the screen instead */
  .club-search { top: 0; box-shadow: 0 -8px 0 var(--panel); }
}
