/* Ladder page. Builds on /shared/page.css (tokens, header, footer) and /shared/prizes.css. */

:root {
  --surface: color-mix(in srgb, var(--page-text) 6%, transparent);
  --line: color-mix(in srgb, var(--page-text) 16%, transparent);
  --gold: #E9B44C;
  --gold-text: #1d1a16;
}

/* Everything on this page reads best in a narrow column; it stays left-aligned with header and footer. */
.ladder > header,
#ladder-root,
.ladder > .state { max-width: 640px; }

.ladder .back { margin-top: -10px; }

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

.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--line);
}

.tab {
  flex: 1 1 0;
  min-width: 0;
  min-height: 44px;
  padding: 6px 4px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--page-text);
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.2;
  cursor: pointer;
}

.tab[aria-selected="true"] {
  background: var(--page-text);
  color: var(--page-bg);
}

@media (hover: hover) {
  .tab[aria-selected="false"]:hover { background: color-mix(in srgb, var(--page-text) 10%, transparent); }
}

.tab:focus-visible {
  outline: 3px solid var(--page-text);
  outline-offset: 2px;
}

.period {
  min-height: 1.45em;
  margin: 12px 0 16px;
  color: var(--page-muted);
  font-size: 14px;
}

/* ---------- Prizes ---------- */

.ladder .prizes-block { margin-bottom: 20px; }

/* ---------- You card ---------- */

.you-card {
  margin: 0 0 16px;
  padding: 12px 14px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--gold) 22%, transparent);
  box-shadow: inset 0 0 0 2px var(--gold);
}

.you-card p { margin: 0; font-weight: 800; }

/* ---------- Rows ---------- */

.rows {
  list-style: none;
  margin: 0;
  padding: 0;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--line);
  overflow: hidden;
}

.row + .row,
.row + .gap,
.gap + .row { border-top: 1px solid var(--line); }

.row { position: relative; }

/* The row is a grid of plain content on top of a transparent button that fills it, so the whole row opens the
   scores per game while the nickname can still be a link (a link may not sit inside a button). */
.row-main { position: relative; }

.row-line {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 28px 28px minmax(0, 1fr) auto 12px;
  align-items: center;
  column-gap: 10px;
  min-height: 56px;
  padding: 10px 12px;
  pointer-events: none;
}

.row-line a { pointer-events: auto; }

.row-toggle {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

@media (hover: hover) {
  .row-toggle:hover { background: color-mix(in srgb, var(--page-text) 6%, transparent); }
}

.row-toggle:focus-visible {
  outline: 3px solid var(--page-text);
  outline-offset: -3px;
}

.rank {
  justify-self: center;
  min-width: 24px;
  padding: 2px 0;
  border-radius: 12px;
  text-align: center;
  font-weight: 800;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  color: var(--page-muted);
}

/* Fallback when shared/avatar-node.js is not available: initials on a circle in the hue of the nickname. */
.avatar {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-weight: 800;
  font-size: 11px;
  line-height: 1;
  letter-spacing: 0.02em;
  background: hsl(var(--av-h) 55% 82%);
  color: hsl(var(--av-h) 65% 20%);
}

/* The real avatar (an inline svg from shared/avatars.js, level ring included). */
.av-img { display: inline-flex; flex: none; border-radius: 50%; line-height: 0; }
.av-img svg { display: block; width: 100%; height: 100%; }

@media (prefers-color-scheme: dark) {
  .avatar {
    background: hsl(var(--av-h) 35% 28%);
    color: hsl(var(--av-h) 70% 88%);
  }
}

.who {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.nick-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 6px;
  min-width: 0;
}

.nick {
  max-width: 100%;
  font-weight: 800;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The nickname of a public profile: underlined, with a 44px-high tap area that does not move the layout. */
.nick-link {
  padding: 12px 0;
  margin: -12px 0;
  color: inherit;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--page-text) 40%, transparent);
  text-underline-offset: 3px;
}

@media (hover: hover) {
  .nick-link:hover { text-decoration-color: currentColor; }
}

.nick-link:focus-visible {
  outline: 3px solid var(--page-text);
  outline-offset: 0;
  border-radius: 4px;
}

/* The level of a player (Metaal ... Diamant): the colour of the level as tint and edge, the name always in text. */
.level-badge {
  flex: none;
  padding: 0 8px;
  border-radius: 999px;
  border: 2px solid var(--lv, var(--line));
  background: color-mix(in srgb, var(--lv, transparent) 26%, transparent);
  color: var(--page-text);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.45;
}

.you-tag {
  flex: none;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--gold);
  color: var(--gold-text);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.6;
}

.game {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  color: var(--page-muted);
  font-size: 13px;
  line-height: 1.3;
}

.game-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--page-muted);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--page-text) 35%, transparent);
}

.result {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
  text-align: right;
}

.score {
  font-weight: 800;
  font-size: 17px;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.date {
  color: var(--page-muted);
  font-size: 12px;
  line-height: 1.3;
}

.chevron {
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--page-muted);
  border-bottom: 2px solid var(--page-muted);
  transform: rotate(45deg);
  transition: transform 120ms ease;
}

.row.is-open .chevron { transform: rotate(-135deg); }

/* Rank 1: a gold number badge, a gold edge and a bigger score. No emoji. */
.row.is-first { box-shadow: inset 4px 0 0 var(--gold); background: color-mix(in srgb, var(--gold) 10%, transparent); }
.row.is-first .rank { background: var(--gold); color: var(--gold-text); }
.row.is-first .score { font-size: 19px; }

/* The row of the visitor. */
.row.is-you { background: color-mix(in srgb, var(--gold) 20%, transparent); box-shadow: inset 0 0 0 2px var(--gold); }
.row.is-first.is-you { box-shadow: inset 0 0 0 2px var(--gold), inset 6px 0 0 var(--gold); }

.bests { padding: 0 12px 12px 88px; }
.bests-title { margin: 0 0 4px; color: var(--page-muted); font-size: 12px; font-weight: 800; }
.bests-list { list-style: none; margin: 0; padding: 0; font-size: 14px; font-variant-numeric: tabular-nums; }
.bests-list li { padding: 2px 0; }

.gap {
  padding: 4px 0;
  text-align: center;
  color: var(--page-muted);
  font-weight: 800;
  letter-spacing: 0.2em;
}

/* ---------- Loading, empty, error ---------- */

.state {
  padding: 24px 16px;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--line);
  text-align: center;
}

.state p { margin: 0 0 12px; }
.state p:last-child { margin-bottom: 0; }

.state-link {
  display: inline-block;
  padding: 10px 0;
  color: var(--page-text);
  font-weight: 800;
  text-underline-offset: 3px;
}

.retry {
  min-height: 44px;
  padding: 0 20px;
  border: 0;
  border-radius: 10px;
  background: var(--page-text);
  color: var(--page-bg);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.retry:focus-visible,
.state-link:focus-visible {
  outline: 3px solid var(--page-text);
  outline-offset: 3px;
}

@media (max-width: 400px) {
  .tab { font-size: 13px; }
  .row-line { grid-template-columns: 24px 28px minmax(0, 1fr) auto 10px; column-gap: 8px; padding: 10px 10px; }
  .bests { padding-left: 78px; }
}

@media (prefers-reduced-motion: reduce) {
  .chevron { transition: none; }
}
