/* Match History component family
 * ==============================
 * The shared Match History table used by Global Match History, the major-god
 * recent-match list, the tournament series game list, and the player-profile
 * history table (rendered client-side by static/js/player_stats.js against
 * these same class names).
 *
 * Everything here is namespaced under .mh-* on purpose. The legacy
 * .leaderboards-table / .recent-games-* / .player-stats-* class names are kept
 * on the markup for unrelated consumers and existing JS hooks, but no rule in
 * this file styles them -- .leaderboards-table alone is used by ten unrelated
 * templates and must not be restyled from here.
 *
 * Load order matters: this file must come after leaderboards.css so the
 * component layer wins for .mh-* elements without needing !important.
 */

.mh-table-wrap {
  --mh-hairline: rgba(219, 188, 118, 0.12);
  --mh-rule: rgba(219, 174, 84, 0.62);
  --mh-head-bg: linear-gradient(180deg, rgba(224, 180, 91, 0.1), transparent), #101b27;
  --mh-head-text: #e8c87f;
  --mh-text: rgba(246, 238, 219, 0.96);
  --mh-text-muted: rgba(235, 222, 193, 0.68);
  --mh-text-soft: rgba(235, 222, 193, 0.52);
  --mh-win: rgba(124, 211, 143, 0.52);
  --mh-loss: rgba(239, 147, 125, 0.52);

  /* Type floor: names and metadata stay at or above 12px even though the
     design specimen renders them smaller. */
  --mh-name-size: 0.8rem;
  --mh-rating-size: 0.75rem;
  --mh-god-size: 1.9rem;

  position: relative;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
}

.mh-table-wrap:focus-visible {
  outline: 2px solid var(--mh-head-text);
  outline-offset: 2px;
}

/* A side that runs deeper than three players steps avatar and type down once
   so a 6v6 row does not blow out the table row height. */
.mh-matchup--compact {
  --mh-name-size: 0.75rem;
  --mh-rating-size: 0.72rem;
  --mh-god-size: 1.4rem;
}

.mh-table {
  width: 100%;
  min-width: 60rem;
  table-layout: fixed;
  border-collapse: collapse;
}

/* The table also carries the legacy .leaderboards-table classes for unrelated
   consumers and JS hooks. Those rules are (class, element) specific, so the
   component's own cell rules are scoped under .mh-table to win without
   !important -- and the legacy zebra striping is switched off, since the
   approved design separates rows with a hairline only. */
.mh-table.leaderboards-table > tbody > tr:nth-child(even) {
  background: none;
}

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

/* Scoped through the wrapper so this beats .leaderboards-page
   .leaderboards-table th, which would otherwise drop the header to 0.7rem --
   below the readable floor for a column label. */
.mh-table-wrap .mh-table > thead > tr > th {
  padding: 0.68rem 0.72rem;
  border-bottom: 2px solid var(--mh-rule);
  background: var(--mh-head-bg);
  color: var(--mh-head-text);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.075em;
  text-transform: uppercase;
  text-align: left;
  white-space: nowrap;
}

.mh-table-wrap .mh-table > thead > tr > th.mh-th-length {
  text-align: center;
}

/* The numbered tournament variant keeps a quieter header band. */
.mh-table-wrap .mh-table--numbered > thead > tr > th {
  background: rgba(232, 196, 111, 0.07);
  border-bottom: 1px solid rgba(232, 196, 111, 0.16);
  color: rgba(235, 222, 193, 0.72);
}

/* ---- column widths ---- */

/* Under a fixed table-layout the browser distributes any slack across every
   column proportionally rather than handing it to an `auto` one, so Matchup
   carries an explicit generous width and keeps the lion's share at any table
   size. These sum to roughly the table's min-width. */
.mh-col-info { width: 9rem; }
.mh-col-game { width: 4.5rem; }
.mh-col-length { width: 5.25rem; }
.mh-col-map { width: 12rem; }
.mh-col-matchup { width: 28rem; }
.mh-col-actions { width: 5rem; }

/* ---- rows ---- */

.mh-row > .mh-cell {
  padding: 0.95rem 0.8rem;
  border-bottom: 1px solid var(--mh-hairline);
  vertical-align: middle;
  background: none;
}

.mh-table > tbody > tr:last-child > .mh-cell {
  border-bottom: none;
}

.mh-row {
  cursor: pointer;
  transition: background-color 0.16s ease;
}

.mh-row:hover {
  background: rgba(232, 196, 111, 0.05);
}

.mh-row:focus-visible {
  outline: 2px solid var(--mh-head-text);
  outline-offset: -2px;
}

/* ---- info cell ---- */

.mh-info {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}

.mh-info-date {
  color: var(--mh-text);
  font-size: 0.85rem;
  font-weight: 700;
}

.mh-info-time {
  color: var(--mh-text-muted);
  font-size: 0.78rem;
}

.mh-info-id {
  color: var(--mh-text-soft);
  font-size: 0.75rem;
}

.mh-game-number {
  color: var(--mh-head-text);
  font-family: var(--font-title, Cinzel, Georgia, serif);
  font-size: 1rem;
  font-weight: 400;
}

/* ---- length ---- */

.mh-table .mh-cell--length {
  color: rgba(240, 231, 214, 0.9);
  font-family: var(--font-title, Cinzel, Georgia, serif);
  font-size: 0.92rem;
  letter-spacing: 0.02em;
  text-align: center;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ---- map ---- */

.mh-map {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  min-width: 0;
}

.mh-map-art {
  flex: 0 0 auto;
  display: block;
}

.mh-map-art img {
  display: block;
  width: 3rem;
  height: 3rem;
  object-fit: cover;
  border-radius: 0.4rem;
  border: 1px solid rgba(231, 197, 126, 0.22);
}

.mh-map-copy {
  min-width: 0;
}

.mh-map-name {
  display: block;
  color: var(--mh-text);
  font-size: 0.86rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mh-map-meta {
  display: block;
  color: var(--mh-text-muted);
  font-size: 0.76rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- matchup: two teams, mirrored columns ---- */

/* A centred flex row rather than fixed grid tracks: the two sides hug their
   content when there is room -- so the result pills sit beside their team
   instead of being pushed to the cell edges -- and shrink when there is not,
   which lets a long name ellipsise its own end. Grid tracks sized to content
   instead overflowed the fixed-width cell and clipped the front of the name. */
.mh-matchup--versus {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  width: 100%;
}

.mh-matchup--versus > .mh-matchup-result,
.mh-matchup--versus > .mh-matchup-vs {
  flex: 0 0 auto;
}

.mh-matchup--versus > .mh-matchup-side {
  flex: 0 1 auto;
}

.mh-matchup-result {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.18rem;
}

.mh-matchup-result--left { align-items: flex-start; }
.mh-matchup-result--right { align-items: flex-end; }

.mh-matchup-side {
  display: grid;
  gap: 0.3rem;
  min-width: 0;
}

.mh-matchup-side--left {
  justify-items: end;
}

.mh-matchup-side--right {
  justify-items: start;
}

.mh-matchup-side > * {
  max-width: 100%;
  min-width: 0;
}

.mh-matchup-vs {
  width: 1.7rem;
  height: 1.7rem;
  object-fit: contain;
  justify-self: center;
  filter: drop-shadow(0 0.3rem 0.4rem rgba(0, 0, 0, 0.38));
}

/* ---- matchup: three or more teams, wrapping blocks, no VS mark ---- */

.mh-matchup--multi {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.9rem;
  align-items: flex-start;
}

.mh-team-block {
  display: grid;
  gap: 0.3rem;
  min-width: 0;
  padding-left: 0.9rem;
  border-left: 1px solid var(--mh-hairline);
}

.mh-team-block:first-child {
  padding-left: 0;
  border-left: none;
}

.mh-team-block-head {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.mh-team-label {
  color: rgba(240, 231, 214, 0.72);
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
}

.mh-team-roster {
  display: grid;
  gap: 0.3rem;
  justify-items: start;
  min-width: 0;
}

.mh-team-more {
  display: inline-grid;
  place-items: center;
  min-width: 1.9rem;
  height: 1.6rem;
  padding: 0 0.35rem;
  border: 1px solid rgba(230, 195, 123, 0.3);
  border-radius: 0.8rem;
  color: var(--mh-head-text);
  font-size: 0.72rem;
  font-weight: 900;
}

/* ---- matchup: inline fallback ---- */

.mh-matchup--inline {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.75rem;
}

.mh-missing {
  color: var(--mh-text-soft);
  font-size: 0.78rem;
  font-style: italic;
}

/* ---- player token ---- */

.mh-token {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
  max-width: 100%;
  color: var(--mh-text);
  font-size: var(--mh-name-size);
  font-weight: 800;
}

/* Mirrored: on the left side the god icon sits inward, next to the VS mark. */
.mh-token--left {
  flex-direction: row-reverse;
}

.mh-token.is-empty {
  min-height: var(--mh-god-size);
}

.mh-token-god {
  flex: 0 0 auto;
  width: var(--mh-god-size);
  height: var(--mh-god-size);
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid rgba(230, 195, 123, 0.24);
  box-shadow: 0 0.35rem 0.8rem rgba(0, 0, 0, 0.22);
}

.mh-token.is-win .mh-token-god { border-color: var(--mh-win); }
.mh-token.is-loss .mh-token-god { border-color: var(--mh-loss); }

.mh-token-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.2;
}

/* The left side's token block hugs the VS mark, but the name itself stays
   start-aligned: right-aligned overflowing text clips its beginning instead of
   ellipsising its end, which hides the part of the name that identifies it. */
.mh-matchup-side--left .mh-token-info {
  align-items: flex-end;
}

.mh-matchup-side--left .mh-token-rating {
  text-align: right;
}

.mh-token-name {
  display: block;
  max-width: 100%;
  overflow: hidden;
  /* Always start-aligned: the side container is right-aligned, and inheriting
     that here would clip the front of a long name instead of ellipsising its
     end -- hiding exactly the characters that identify the player. */
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: inherit;
  font-size: var(--mh-name-size);
}

a.mh-token-name:hover,
a.mh-token-name:focus-visible {
  color: var(--mh-head-text);
}

.mh-token-rating {
  color: rgba(238, 227, 203, 0.62);
  font-size: var(--mh-rating-size);
  font-weight: 700;
  letter-spacing: 0.02em;
}

/* ---- result pill ---- */

.mh-result-pill {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  border-radius: 0.25rem;
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

.mh-result-pill.is-win {
  background: rgba(124, 211, 143, 0.16);
  color: #8fe3a4;
}

.mh-result-pill.is-loss {
  background: rgba(239, 147, 125, 0.14);
  color: #f0a58f;
}

/* ---- actions ----
 * Analysis and replay availability are independent; these are two separate
 * treatments, never one state. Analysis is the stronger gold action, replay
 * the subdued outlined one. No blue primary action here by design.
 */

.mh-actions {
  display: flex;
  gap: 0.45rem;
  align-items: center;
}

.mh-action {
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 1px solid rgba(230, 195, 123, 0.24);
  border-radius: 50%;
  background: rgba(8, 20, 34, 0.78);
  transition: border-color 0.16s ease, transform 0.16s ease;
}

.mh-action img {
  width: 1.05rem;
  height: 1.05rem;
  object-fit: contain;
}

/* Analysis: the stronger gold/bronze action. */
.mh-action--analysis {
  background: linear-gradient(180deg, rgba(245, 204, 120, 0.22), rgba(92, 63, 23, 0.7));
  border-color: rgba(235, 199, 119, 0.42);
}

/* Replay: the darker, subdued outlined action. */
.mh-action--replay {
  background: rgba(8, 20, 34, 0.78);
  border-color: rgba(230, 195, 123, 0.24);
}

a.mh-action:hover,
a.mh-action:focus-visible {
  border-color: rgba(235, 199, 119, 0.7);
  transform: translateY(-1px);
}

a.mh-action:focus-visible {
  outline: 2px solid var(--mh-head-text);
  outline-offset: 2px;
}

.mh-action--empty {
  border-style: dashed;
  border-color: rgba(230, 195, 123, 0.14);
  background: rgba(8, 20, 34, 0.4);
  cursor: default;
}

/* ---- empty state ---- */

.mh-table .mh-empty {
  padding: 2.2rem 1rem;
  text-align: center;
}

.mh-empty strong {
  display: block;
  color: var(--mh-text);
  font-size: 1rem;
}

.mh-empty p {
  margin: 0.4rem 0 0;
  color: var(--mh-text-muted);
  font-size: 0.85rem;
}

/* ---- player-profile variant ----
 * Rendered client-side by static/js/player_stats.js against the same class
 * names; Result and Rating are player-centric columns the global table has no
 * data for.
 */

.mh-col-result { width: 5.5rem; }
.mh-col-rating { width: 6.5rem; }

.mh-table .mh-cell--result,
.mh-table .mh-cell--rating {
  white-space: nowrap;
}

.mh-table .mh-cell--rating {
  color: rgba(240, 231, 214, 0.9);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

.mh-official-detail {
  display: block;
  margin-top: 0.2rem;
  color: var(--mh-text-soft);
  font-size: 0.72rem;
}

/* ---- responsive ----
 * Desktop is the primary experience. Below it the table keeps its shape and
 * scrolls inside its own region rather than compressing names into
 * unreadability; the wrapper is focusable so the scroll region is reachable
 * from the keyboard.
 */

@media (max-width: 900px) {
  .mh-table-wrap {
    --mh-god-size: 1.5rem;
  }

  .mh-table {
    min-width: 52rem;
  }

  .mh-map-art img {
    width: 2.5rem;
    height: 2.5rem;
  }
}

@media (max-width: 600px) {
  .mh-table {
    min-width: 46rem;
  }

  .mh-row > .mh-cell {
    padding: 0.75rem 0.6rem;
  }

  .mh-matchup--versus {
    gap: 0.35rem;
  }

  .mh-matchup-vs {
    width: 1.3rem;
    height: 1.3rem;
  }
}
