*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #F5F3FF;
  --surface:   #ffffff;
  --surface2:  #f0f1f5;
  --border:    #dde0e8;
  --text:      #1a1a2e;
  --muted:     #6b6b8a;
  --gold:      #c8960a;
  --line:      #c3c8d6;

  /* competition accents */
  --fa:        #1e2a5a;
  --fa-soft:   #eef1fa;
  --efl:       #0b6b4f;
  --efl-soft:  #eaf5f1;
  --accent:    var(--fa);
  --accent-soft: var(--fa-soft);

  --win:       #14733f;
  /* Sized so the whole pyramid fits a 1280px laptop without sideways
     scrolling; widened on roomier screens. */
  --card-w:    104px;   /* minimum column width at the base of the pyramid */
  --card-max:  124px;
  --card-fs:   .794rem;
  --vgap:      42px;    /* vertical space between rounds = connector height */
  --label-w:   118px;   /* wide enough for the longest label, "Quarter-Final" (~104px text + 10px padding), on one line */
  /* rotated (mobile) bracket */
  --hcol-w:    150px;
  --hgap:      26px;
  --hrow:      62px;
}

/* 16 base columns + the label gutter must still fit, so the minimum only
   grows to what a 1920px window can hold (16 x 110 + 118 = 1878). --label-w
   doesn't need to change here: the label font-size is fixed, not tied to
   --card-fs, so 118px stays enough at any width. */
@media (min-width: 1500px) {
  :root { --card-w: 110px; --card-max: 138px; --card-fs: .844rem; --vgap: 48px; }
}

body[data-comp="efl-cup"] { --accent: var(--efl); --accent-soft: var(--efl-soft); }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 24px 20px 60px;
}

/* ── header / controls ── */
.header { display: flex; align-items: center; gap: 14px; margin-bottom: 6px; }
.header h1 { font-size: 1.594rem; letter-spacing: -.3px; }
.sub { color: var(--muted); font-size: .964rem; margin: 2px 0 20px; }

/* Two tracks: the season/competition rows on the left, the Facts & Trivia card
   filling the right (where the competition blurb paragraph used to sit). Stacks
   to a single column under 760px — see the mobile block near the end of the file. */
.controls {
  display: flex; flex-direction: row; align-items: stretch; gap: 18px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px 16px; margin-bottom: 22px;
}
.controls-main {
  display: flex; flex-direction: column; gap: 14px; justify-content: center;
  flex: 0 1 auto;
}
.control-row { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; }
.control-row label {
  font-size: .794rem; text-transform: uppercase; letter-spacing: .7px;
  color: var(--muted); font-weight: 700; white-space: nowrap;
  min-width: 108px; /* same width on both rows so the FA Cup button lines up under the season dropdown */
}

/* ── competition buttons (replace the old native <select>) ── */
.comp-buttons { display: flex; gap: 8px; }
.comp-btn {
  display: flex; align-items: center; gap: 7px;
  font: inherit; font-size: 1.014rem; padding: 7px 14px;
  border: 1.5px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); cursor: pointer;
  transition: border-color .12s, background-color .12s;
}
.comp-btn:hover { border-color: var(--accent); }
.comp-btn[aria-pressed="true"] {
  border-color: var(--accent); background: var(--accent-soft); font-weight: 700;
}

/* ── competition description tooltip ──
   Holds the blurb the facts card displaced. Shown on hover and keyboard focus,
   and toggled by click (aria-expanded) so it is reachable on touch, where there
   is no hover state at all. */
.comp-info-wrap { position: relative; display: inline-flex; }
.comp-info {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; padding: 0;
  font: inherit; font-size: .834rem; font-weight: 700; font-style: italic;
  line-height: 1; font-family: Georgia, 'Times New Roman', serif;
  border: 1.5px solid var(--border); border-radius: 50%;
  background: var(--surface); color: var(--muted); cursor: pointer;
  transition: border-color .12s, color .12s;
}
.comp-info:hover, .comp-info[aria-expanded="true"] { border-color: var(--accent); color: var(--accent); }
.comp-info:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.comp-tip {
  position: absolute; left: 50%; top: calc(100% + 8px); transform: translateX(-50%);
  z-index: 20; width: max-content; max-width: 280px;
  background: var(--text); color: #ffffff;
  font-size: .834rem; line-height: 1.45; text-align: left;
  padding: 8px 10px; border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0,0,0,.18);
  opacity: 0; visibility: hidden; transition: opacity .12s;
}
.comp-tip::before {
  content: ''; position: absolute; left: 50%; top: -5px; transform: translateX(-50%);
  border-left: 5px solid transparent; border-right: 5px solid transparent;
  border-bottom: 5px solid var(--text);
}
.comp-info:hover + .comp-tip,
.comp-info:focus-visible + .comp-tip,
.comp-info[aria-expanded="true"] + .comp-tip { opacity: 1; visibility: visible; }

/* ── facts & trivia card (one fact at a time; every fact is in the markup) ── */
.facts-card {
  /* fills whatever the season/competition column leaves — the controls bar is
     full-bleed, so a capped card would strand empty space on the right */
  flex: 1 1 420px; min-width: 0;
  display: flex; flex-direction: column;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--accent-soft); padding: 10px 12px;
}
.facts-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.facts-title {
  font-size: .794rem; text-transform: uppercase; letter-spacing: .7px;
  color: var(--accent); font-weight: 700;
}
.facts-nav { display: flex; align-items: center; gap: 6px; }
.facts-count { font-size: .794rem; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 46px; text-align: center; }
.facts-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; padding: 0;
  border: 1.5px solid var(--border); border-radius: 7px;
  background: var(--surface); color: var(--accent); cursor: pointer;
  transition: border-color .12s, opacity .12s;
}
.facts-btn:hover:not(:disabled) { border-color: var(--accent); }
.facts-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.facts-btn:disabled { opacity: .35; cursor: not-allowed; }
/* The shared CHEVRON_ICON points down; rotate it into ‹ and ›. */
.facts-btn .chev { transition: none; }
.facts-prev .chev { transform: rotate(90deg); }
.facts-next .chev { transform: rotate(-90deg); }
/* min-height keeps the controls bar from resizing as you step between a one-line
   fact and a three-line one. */
.facts-list { margin-top: 6px; min-height: 74px; }
.fact-item[hidden] { display: none; }
.fact-head {
  display: flex; align-items: baseline; gap: 7px;
  font-size: .914rem; font-weight: 700; color: var(--text);
}
.fact-icon { flex-shrink: 0; }
.fact-body { margin-top: 3px; font-size: .864rem; line-height: 1.45; color: var(--muted); }
.fact-team { display: inline-block; margin-top: 4px; font-size: .764rem; color: var(--accent); font-weight: 600; }
.facts-more {
  margin-top: 8px; align-self: flex-start;
  font-size: .794rem; font-weight: 600; color: var(--accent); text-decoration: none;
}
.facts-more:hover { text-decoration: underline; }

/* ── season dropdown (violet-themed custom listbox, matches the Points
   Table page's season selector look/behavior) ── */
.season-dropdown { position: relative; }
.season-btn {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  font: inherit; font-size: 1.014rem; padding: 7px 12px; min-width: 118px;
  background: #ffffff; border: 1.5px solid #e5e7eb; border-radius: 8px;
  color: #374151; cursor: pointer;
}
.season-btn:hover { border-color: #a78bfa; }
.season-btn:focus-visible { outline: 2px solid #c4b5fd; outline-offset: 2px; border-color: #a78bfa; }
.season-btn .chev { color: #9ca3af; flex-shrink: 0; transition: transform .15s; }
.season-btn[aria-expanded="true"] .chev { transform: rotate(180deg); }
.season-listbox {
  position: absolute; left: 0; top: calc(100% + 4px); min-width: 100%; z-index: 10;
  max-height: 256px; overflow-y: auto;
  background: #ffffff; border: 1px solid #e5e7eb; border-radius: 10px;
  box-shadow: 0 10px 25px rgba(0,0,0,.12); padding: 4px 0;
}
.season-listbox [role="option"] {
  display: block; width: 100%; text-align: left; white-space: nowrap;
  font: inherit; font-size: 1.014rem; padding: 6px 14px; border: none; background: none;
  cursor: pointer; color: #374151;
}
.season-listbox [role="option"]:hover { background: #f5f3ff; }
.season-listbox [role="option"].selected { background: #f5f3ff; color: #6d28d9; font-weight: 600; }

/* ── club crests ──
   Real crest when the club has a local logo asset; otherwise an empty,
   unlabeled black & white shield outline (SHIELD_ICON) — no initials. */
.crest {
  width: 16px; height: 16px; flex-shrink: 0;
  object-fit: contain;
}
img.crest { border-radius: 50%; }
svg.crest-fallback { color: #8a8fa3; }
.tie-grid .crest, .acc-body .crest { width: 20px; height: 20px; }

/* ── pyramid bracket ──────────────────────────────────────────────
   The final sits at the apex and each round branches downward, matching
   the competition's own bracket graphic. Every round is a grid over the
   same number of columns as the base round, so a tie in round r simply
   spans 2^r columns and lands centred over its two children. ── */
.bracket-wrap { overflow-x: auto; padding-bottom: 10px; }
.bracket { min-width: min-content; margin: 0 auto; }

.pyr-row {
  display: grid;
  grid-template-columns: var(--label-w) repeat(var(--cols), minmax(var(--card-w), 1fr));
  column-gap: 0;
}
.pyr-row + .pyr-row { margin-top: var(--vgap); }

.pyr-label {
  grid-column: 1; align-self: center; padding-right: 10px;
  font-size: .714rem; font-weight: 800; letter-spacing: .8px;
  text-transform: uppercase; color: var(--muted); text-align: right;
  white-space: nowrap;
}

.tie {
  position: relative; display: flex; justify-content: center;
  padding: 0 3px;
}
.tie-card {
  width: 100%; max-width: var(--card-max); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px;
  overflow: hidden; cursor: pointer; transition: border-color .12s, box-shadow .12s;
  font-size: var(--card-fs);
}
/* early-round and mobile lists have room for full names */
.tie-grid .tie-card, .acc-body .tie-card { max-width: none; font-size: .894rem; }
.tie-card:hover { border-color: var(--accent); box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.tie-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.row {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 7px; background: var(--surface);
}
.row + .row { border-top: 1px solid var(--border); }
.row.won { background: var(--accent-soft); font-weight: 700; }
.row .nm { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sc { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 12px; text-align: right; }
.row.won .sc { color: var(--win); }
.note {
  font-size: .674rem; color: var(--muted); padding: 2px 7px;
  background: var(--surface2); border-top: 1px solid var(--border);
  display: flex; gap: 5px; flex-wrap: wrap;
}
.note b { color: var(--accent); font-weight: 700; }

/* ── connectors ──
   Each tie draws an L up to its parent: a vertical riser at its own centre
   and a horizontal arm reaching half its cell width toward the parent.
   The two siblings' arms meet under the parent's downward stub. */
.tie.child-left::before,
.tie.child-right::before {
  content: ''; position: absolute; box-sizing: border-box;
  top: calc(var(--vgap) / -2); height: calc(var(--vgap) / 2);
  width: 50%; border-top: 2px solid var(--line);
}
.tie.child-left::before  { left: 50%;  border-left: 2px solid var(--line); }
.tie.child-right::before { right: 50%; border-right: 2px solid var(--line); }

.tie.has-children::after {
  content: ''; position: absolute; left: calc(50% - 1px);
  top: 100%; height: calc(var(--vgap) / 2); width: 2px; background: var(--line);
}

/* ── apex ── */
.pyr-crown {
  display: grid;
  grid-template-columns: var(--label-w) 1fr;
  margin-bottom: 6px;
}
.pyr-crown .crown-inner {
  grid-column: 2; display: flex; flex-direction: column;
  align-items: center; gap: 2px;
}
.trophy { color: var(--accent); display: flex; }
.champion {
  font-size: .814rem; font-weight: 800; letter-spacing: .6px;
  text-transform: uppercase; color: var(--gold);
  font-family: 'Montserrat', sans-serif;
}
.pyr-row.final-row .tie-card {
  border-color: var(--gold); border-width: 2px;
  max-width: calc(var(--card-max) + 40px);
}

/* ── expanded tie detail ── */
dialog {
  border: none; border-radius: 14px; padding: 0; max-width: 460px; width: calc(100% - 32px);
  box-shadow: 0 18px 50px rgba(0,0,0,.28);
  margin: auto; /* the universal *{margin:0} reset above would otherwise pin a
    modal <dialog> at the top-left instead of letting the UA centre it */
}
dialog::backdrop { background: rgba(15,18,32,.5); }
.dlg-head {
  background: var(--accent); color: #fff; padding: 14px 18px;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.dlg-head .rd { font-size: .794rem; opacity: .85; text-transform: uppercase; letter-spacing: .8px; }
.dlg-close {
  background: rgba(255,255,255,.16); border: none; color: #fff; cursor: pointer;
  width: 28px; height: 28px; border-radius: 50%; font-size: 1.094rem; line-height: 1;
}
.dlg-body { padding: 6px 18px 18px; max-height: 62vh; overflow-y: auto; }
.leg { padding: 12px 0; border-bottom: 1px solid var(--border); }
.leg:last-child { border-bottom: none; }
.leg-top { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.leg-score { font-weight: 800; font-variant-numeric: tabular-nums; display: inline-flex; align-items: center; }
.leg-date { color: var(--muted); font-size: .874rem; }
.tag {
  font-size: .724rem; font-weight: 800; text-transform: uppercase; letter-spacing: .5px;
  padding: 2px 7px; border-radius: 4px; background: var(--surface2);
  color: var(--muted); border: 1px solid var(--border);
}
.tag.pens { background: #fff4e0; color: #8a5a00; border-color: #f0d6a0; }
.goal-list { list-style: none; display: flex; flex-direction: column; gap: 3px; }
.goal-list li { display: flex; gap: 8px; font-size: .934rem; align-items: baseline; }
.goal-list .min {
  min-width: 34px; color: var(--muted); font-variant-numeric: tabular-nums; font-size: .874rem;
}
.goal-list .who { flex: 1; }
.goal-list .tm { color: var(--muted); font-size: .854rem; }
.gtype { font-size: .774rem; color: var(--muted); }
.missing { font-size: .894rem; color: var(--muted); font-style: italic; }
.outcome {
  margin-top: 12px; padding: 9px 12px; border-radius: 8px;
  background: var(--accent-soft); border: 1px solid var(--accent);
  color: var(--accent); font-size: .934rem; font-weight: 600;
}

/* ── early rounds ── */
.section-title {
  margin: 34px 0 4px; font-size: 1.144rem; display: flex; align-items: center; gap: 10px;
}
.section-note { color: var(--muted); font-size: .914rem; margin-bottom: 14px; max-width: 760px; }
.round-block { margin-bottom: 20px; }
.round-block > h3 {
  font-size: .834rem; text-transform: uppercase; letter-spacing: .9px;
  color: var(--muted); margin-bottom: 8px; font-weight: 800;
  text-decoration: underline; text-underline-offset: 3px;
}
.tie-grid {
  display: grid; gap: 8px;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
}

/* ── mobile: the bracket rotated 90° ──────────────────────────────
   A 16-wide pyramid cannot shrink to a phone: you would see a fifth of it
   at a time and the connectors — the whole point of a bracket — would be
   meaningless. Turning it on its side keeps the tree intact: rounds run
   left to right, ties stack down the screen. You swipe sideways through
   five rounds instead of sixteen ties. ── */
.hbracket-wrap { display: none; overflow-x: auto; padding-bottom: 10px; }
.hbracket { display: flex; align-items: stretch; min-width: min-content; }

/* header sits above the grid, not inside it, so it cannot collide with
   the first tie's row */
.hcol {
  display: flex; flex-direction: column;
  margin-right: var(--hgap);
  flex: 0 0 var(--hcol-w);
}
.hcol:last-child { margin-right: 0; }
.hcol-grid {
  display: grid;
  grid-template-rows: repeat(var(--rows), var(--hrow));
  flex: 1;
}

.hcol-head {
  font-size: .674rem; font-weight: 800; letter-spacing: .7px;
  text-transform: uppercase; color: var(--muted);
  padding-bottom: 6px; text-align: center;
}

.htie { position: relative; display: flex; align-items: center; }
.htie .tie-card { max-width: none; width: 100%; font-size: .774rem; }

/* connectors, rotated: the arm runs right from each tie toward its parent */
.htie.child-top::before, .htie.child-bottom::before {
  content: ''; position: absolute; box-sizing: border-box;
  left: 100%; width: calc(var(--hgap) / 2); height: 50%;
  border-right: 2px solid var(--line);
}
.htie.child-top::before    { top: 50%; border-top: 2px solid var(--line); }
.htie.child-bottom::before { top: 0;   border-bottom: 2px solid var(--line); }

.htie.has-parent::after {
  content: ''; position: absolute; right: 100%;
  top: calc(50% - 1px); width: calc(var(--hgap) / 2); height: 2px;
  background: var(--line);
}

.hchampion {
  display: flex; align-items: center; gap: 7px; padding: 0 0 8px;
  font-size: .834rem; font-weight: 800; color: var(--gold);
  text-transform: uppercase; letter-spacing: .5px;
  font-family: 'Montserrat', sans-serif;
}
.hchampion-icon { color: var(--accent); display: inline-flex; }

/* ── collapsible earlier rounds (mobile) ── */
.accordion { display: none; }
.acc-round { border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px; background: var(--surface); overflow: hidden; }
.acc-round > summary {
  padding: 11px 14px; font-weight: 700; cursor: pointer; font-size: 1.014rem;
  display: flex; justify-content: space-between; align-items: center; list-style: none;
}
.acc-round > summary::-webkit-details-marker { display: none; }
.acc-round > summary::after { content: '▾'; color: var(--muted); }
.acc-round[open] > summary { border-bottom: 1px solid var(--border); background: var(--surface2); }
.acc-round[open] > summary::after { content: '▴'; }
.acc-body { padding: 10px; display: flex; flex-direction: column; gap: 8px; }

.status { padding: 40px 0; text-align: center; color: var(--muted); }

@media (max-width: 760px) {
  body { padding: 16px 12px 40px; }
  /* the upright pyramid and the desktop early-round grid give way to the
     rotated bracket and the collapsible list */
  .bracket-wrap, .early-desktop { display: none; }
  .hbracket-wrap { display: block; }
  .accordion { display: block; }
  /* the facts card stacks under the season/competition rows rather than beside them */
  .controls { flex-direction: column; gap: 12px; }
  .facts-card { flex: 1 1 auto; }
  /* tightened so the info icon stays on the competition row instead of wrapping
     onto a line of its own — both labels shrink together, so the FA Cup button
     still lines up under the season dropdown */
  .control-row { gap: 10px; }
  .control-row label { min-width: 88px; }
  .season-btn { min-width: 100px; }
  .comp-btn span { display: inline; }
  /* a right-edge tooltip would overflow a narrow screen — pin it to the left */
  .comp-tip { left: auto; right: 0; transform: none; max-width: min(280px, 78vw); }
  .comp-tip::before { left: auto; right: 8px; transform: none; }
}

/* ── site chrome (generated pages only — not in the standalone prototype) ──
   Thin brand header/footer + breadcrumb/pager nav so cup pages read as part
   of the site rather than a bare embedded app, matching the facts pages'
   header/footer colors (#401898). */
header { background: var(--surface); border-bottom: 1px solid var(--border); padding: 0.75rem 2rem; margin: -24px -20px 24px; }
header a { display: inline-flex; align-items: center; text-decoration: none; color: #401898; font-weight: 700; font-size: 1.194rem; }
footer { text-align: center; padding: 2rem 1.5rem 3rem; font-size: 0.894rem; color: var(--muted); }
footer a { color: #401898; text-decoration: none; }
footer a:hover { text-decoration: underline; }
nav.breadcrumb { font-size: 0.944rem; color: var(--muted); margin-bottom: 14px; }
nav.breadcrumb a { color: var(--muted); text-decoration: none; }
nav.breadcrumb a:hover { text-decoration: underline; }
nav.pager { display: flex; justify-content: space-between; margin-top: 34px; padding-top: 18px; border-top: 1px solid var(--border); font-weight: 600; font-size: 0.974rem; }
nav.pager a { color: var(--accent); text-decoration: none; }
nav.pager a:hover { text-decoration: underline; }
nav.pager span.disabled { color: var(--muted); font-weight: 400; }

@media (max-width: 760px) {
  header { padding: 0.75rem 1rem; margin: -16px -12px 18px; }
}
