/* The home page's Agent Cup (public/js/cup.js): an exhibition-preview bracket with simulated results. Mobile first: a
   round switcher and a grid of match cards; from 1180 px the two-sided bracket (R16 | QF | SF | Final | SF | QF | R16)
   with connector lines drawn by the slots. Logical properties throughout, so Arabic mirrors the bracket. */
.home-cup { position: relative; margin: 0 0 20px; padding: 18px 16px 16px; border: 1px solid var(--line); border-radius: var(--radius); background: radial-gradient(120% 90% at 50% 0%, rgba(230, 180, 94, 0.13), rgba(230, 180, 94, 0) 60%), var(--bg-2); }
.home-cup[hidden] { display: none; }
.home-cup-head { display: grid; gap: 6px; justify-items: center; text-align: center; margin: 0 0 14px; }
.home-cup-badge { display: inline-block; margin: 0; padding: 4px 10px; border: 1px dashed var(--accent-2); border-radius: 999px; font-size: 0.72rem; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent-2); }
.page-home main .home-cup h2 { margin: 0; font-size: clamp(1.6rem, 5.4vw, 2.5rem); line-height: 1.1; letter-spacing: -0.01em; }
.home-cup-lead { margin: 0; max-width: 60ch; color: #ddd3c3; line-height: 1.45; }
.home-cup-board { min-height: 220px; }
.home-cup-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin: 16px 0 0; }
.home-cup-actions .btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; }
.home-cup-note { margin: 12px auto 0; max-width: 72ch; text-align: center; font-size: 0.8rem; line-height: 1.45; }

/* ------------------------------------------------------------ a match card */
.cup-match { position: relative; display: grid; gap: 2px; padding: 6px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg-3); }
.cup-match.is-live { border-color: var(--pg-live); box-shadow: 0 0 0 1px rgba(76, 217, 123, 0.35), 0 0 18px rgba(76, 217, 123, 0.18); }
.cup-match.is-next { border-style: dashed; border-color: var(--accent-2); }
.cup-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; min-height: 18px; padding: 0 4px 2px; font-size: 0.66rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.cup-status { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.cup-status.live { color: var(--pg-live); }
.cup-status.next { color: var(--accent-2); }
.cup-status.done { color: var(--pg-soon); }
.cup-clock { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: 0; }
.cup-team { display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; align-items: center; gap: 8px; width: 100%; min-height: 32px; margin: 0; padding: 3px 6px 3px 4px; border: 0; border-radius: 7px; background: transparent; color: var(--text); font: inherit; font-size: 0.9rem; text-align: start; cursor: pointer; transition: background-color 0.15s, opacity 0.15s; }
.cup-team.is-tbd { cursor: default; }
.cup-team:hover, .cup-team:focus-visible { background: rgba(241, 235, 225, 0.07); }
.cup-team:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.cup-mark { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 6px; background: hsl(var(--h, 30) 62% 46%); color: #fff; font-size: 0.72rem; font-weight: 800; line-height: 1; }
.cup-mark.mono { background: #ece6dc; color: #121212; }
.cup-team.is-tbd .cup-mark { background: transparent; border: 1px dashed var(--line); }
.cup-name { display: flex; align-items: baseline; gap: 6px; min-width: 0; overflow: hidden; white-space: nowrap; }
.cup-agent { overflow: hidden; text-overflow: ellipsis; font-weight: 700; }
.cup-maker { overflow: hidden; text-overflow: ellipsis; font-size: 0.74rem; color: var(--muted); }
.cup-cc { flex: 0 0 auto; padding: 0 4px; border: 1px solid var(--line); border-radius: 4px; font-size: 0.62rem; font-weight: 700; letter-spacing: 0.04em; color: var(--muted); }
.cup-tbd { font-style: italic; color: var(--muted); font-weight: 500; }
.cup-score { min-width: 3ch; font-family: var(--mono); font-size: 0.86rem; font-variant-numeric: tabular-nums; text-align: end; color: var(--muted); }
.cup-team.is-win .cup-agent, .cup-team.is-win .cup-score { color: var(--accent); }
.cup-team.is-win .cup-score::before { content: "▸ "; font-size: 0.7em; }
.cup-team.is-out { opacity: 0.55; }
.cup-match.is-live .cup-score { color: var(--text); }
.cup-score.bump { animation: cup-bump 0.6s ease-out; }
@keyframes cup-bump { 0% { color: var(--pg-live); transform: scale(1.18); } 100% { transform: none; } }
.cup-status.live .pg-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--pg-live); animation: cup-pulse 1.4s ease-in-out infinite; }
@keyframes cup-pulse { 50% { opacity: 0.25; } }

/* tracing one agent's road through the bracket (hover, focus, or a click that pins it) */
.home-cup.is-tracing .cup-team[data-agent]:not(.is-hl) { opacity: 0.32; }
.home-cup.is-tracing .cup-team.is-hl { opacity: 1; background: rgba(230, 180, 94, 0.16); }

.cup-trophy { display: block; width: 58px; height: 58px; margin: 0 auto 8px; filter: drop-shadow(0 4px 14px rgba(230, 180, 94, 0.45)); }
.cup-trophy .body { fill: var(--accent); stroke: #8a6526; stroke-width: 1.5; stroke-linejoin: round; }
.cup-trophy .handles { fill: none; stroke: var(--accent); stroke-width: 3; stroke-linecap: round; }
.cup-who { margin: 8px 0 0; text-align: center; font-size: 0.82rem; font-weight: 700; color: var(--accent-2); }

/* ------------------------------------------------------------ narrow: the round switcher */
.cup-bracket { display: none; }
.cup-tabs { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin: 0 0 12px; }
.cup-tab { min-height: 40px; padding: 0 14px; border: 1px solid var(--line); border-radius: 999px; background: transparent; color: var(--text); font: inherit; font-size: 0.86rem; font-weight: 700; cursor: pointer; }
.cup-tab[aria-pressed="true"] { border-color: var(--accent); background: var(--accent); color: #1b140b; }
.cup-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.cup-list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.cup-final-note { padding: 10px 0 0; }
@media (min-width: 620px) {
  .cup-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cup-list.round-final { grid-template-columns: minmax(0, 360px); justify-content: center; }
}

/* ------------------------------------------------------------ wide: the two-sided bracket */
@media (min-width: 1180px) {
  .home-cup { padding: 24px 20px 18px; }
  .home-cup-board { min-height: 380px; }
  .cup-rounds { display: none; }
  .cup-bracket { --gap: 14px; display: grid; grid-template-columns: minmax(0, 1.12fr) minmax(0, 1.06fr) repeat(3, minmax(0, 0.94fr)) minmax(0, 1.06fr) minmax(0, 1.12fr); column-gap: var(--gap); }
  .cup-col { display: flex; flex-direction: column; min-width: 0; }
  .cup-round { margin: 0 0 6px; text-align: center; font-size: 0.68rem; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
  .cup-col.is-final .cup-round { color: var(--accent-2); }
  .cup-slots { display: flex; flex: 1 1 auto; flex-direction: column; }
  .cup-slot { position: relative; display: flex; flex: 1 1 0; flex-direction: column; justify-content: center; padding: 5px 0; }
  .cup-slot .cup-match { width: 100%; padding: 5px 4px; }
  .cup-team { min-height: 28px; gap: 5px; padding: 3px 4px 3px 2px; font-size: 0.82rem; grid-template-columns: 18px minmax(0, 1fr) auto; }
  .cup-mark { width: 18px; height: 18px; font-size: 0.66rem; border-radius: 5px; }
  .cup-maker, .cup-cc, .cup-unit, .cup-status.done { display: none; }
  .cup-score { min-width: 0; font-size: 0.74rem; }
  .cup-team.is-win .cup-score::before { content: none; }
  /* connectors: a stub out of each match on the side facing the final, a vertical joint per pair, a stub into the next */
  .cup-col.is-left .cup-slot::after, .cup-col.is-right .cup-slot::after { content: ""; position: absolute; top: 50%; width: calc(var(--gap) / 2); border-top: 1px solid var(--line); }
  .cup-col.is-left .cup-slot::after { inset-inline-end: calc(var(--gap) / -2); }
  .cup-col.is-right .cup-slot::after { inset-inline-start: calc(var(--gap) / -2); }
  .cup-col.is-left:not(.round-sf) .cup-slot::before, .cup-col.is-right:not(.round-sf) .cup-slot::before { content: ""; position: absolute; width: 0; }
  .cup-col.is-left:not(.round-sf) .cup-slot::before { inset-inline-end: calc(var(--gap) / -2); border-inline-end: 1px solid var(--line); }
  .cup-col.is-right:not(.round-sf) .cup-slot::before { inset-inline-start: calc(var(--gap) / -2); border-inline-start: 1px solid var(--line); }
  .cup-col:not(.round-sf) .cup-slot:nth-child(odd)::before { top: 50%; bottom: 0; }
  .cup-col:not(.round-sf) .cup-slot:nth-child(even)::before { top: 0; bottom: 50%; }
  .cup-col.is-left:not(.round-r16) .cup-match::before, .cup-col.is-right:not(.round-r16) .cup-match::before,
  .cup-col.is-final .cup-match::before, .cup-col.is-final .cup-match::after { content: ""; position: absolute; top: 50%; width: calc(var(--gap) / 2); border-top: 1px solid var(--line); }
  .cup-col.is-left .cup-match::before, .cup-col.is-final .cup-match::before { inset-inline-start: calc(var(--gap) / -2 - 1px); }
  .cup-col.is-right .cup-match::before, .cup-col.is-final .cup-match::after { inset-inline-end: calc(var(--gap) / -2 - 1px); }
  /* the trophy and the question sit above and below the final, so the final stays on the semi-finals' line */
  .cup-col.is-final .cup-trophy { position: absolute; inset-inline: 0; bottom: calc(50% + 52px); width: 64px; height: 64px; }
  .cup-col.is-final .cup-who { position: absolute; inset-inline: 0; top: calc(50% + 52px); margin: 0; }
  .cup-col.is-final .cup-match { border-color: var(--accent); background: linear-gradient(180deg, rgba(230, 180, 94, 0.12), rgba(230, 180, 94, 0.02)), var(--bg-3); }
}
@media (prefers-reduced-motion: reduce) {
  .cup-status.live .pg-dot, .cup-score.bump { animation: none; }
}
