/* Leaderboards panel (leaderboards.js). Uses the page tokens (--card, --navy,
   --blue, --border, --bg), so the Thanksgiving remap in seasonal.css dresses
   it automatically and the normal yearbook keeps OFM blue. One lifted layer
   (the dialog); each game is a flat tinted field inside it (no border of its
   own, no shadows inside the dialog). No side stripes, no plates behind
   numbers. Desktop: three equal cards with one shape (toggle, five rows,
   footer action). Narrow screens: the same cards stacked, sized to content. */
html.lb-open body { overflow: hidden; }

.lb-dialog {
  position: fixed; inset: 0; z-index: 10060;
  display: grid; place-items: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  background: rgba(13, 31, 53, 0.42);
  animation: lb-fade 0.18s ease-out both;
}
html.sx-thanksgiving .lb-dialog { background: rgba(43, 25, 14, 0.46); }
.lb-card {
  position: relative; width: min(1120px, 100%); max-height: calc(100dvh - 32px); overflow: auto;
  overscroll-behavior: contain;
  padding: 24px; border-radius: 20px;
  background: var(--card, #fff); border: 1px solid var(--border, #DBE7F4); box-shadow: var(--shadow-lg);
  font-family: var(--font-body); color: var(--text, #374151);
  animation: lb-rise 0.24s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
.lb-card:focus { outline: none; }

.lb-head { display: flex; align-items: center; gap: 14px; margin: 0 0 20px; padding-right: 52px; }
.lb-medal {
  flex: none; display: grid; place-items: center; width: 48px; height: 48px; border-radius: 50%;
  color: var(--blue, #1E72BE); background: color-mix(in srgb, var(--blue, #1E72BE) 10%, var(--card, #fff));
  border: 1px solid var(--blue, #1E72BE); box-shadow: 0 0 0 4px var(--sx-tg-halo, rgba(30, 114, 190, 0.14));
}
.lb-medal svg { width: 26px; height: 26px; }
.lb-titles { min-width: 0; }
.lb-head h2 {
  margin: 0; font: 800 clamp(1.4rem, 1.15rem + 1vw, 1.75rem)/1.1 var(--font-display, var(--font-body));
  letter-spacing: -0.02em; color: var(--navy, #0D1F35);
}
.lb-lede { margin: 4px 0 0; font-size: 0.875rem; line-height: 1.4; color: var(--muted, #5B6B7F); text-wrap: pretty; }
.lb-x {
  position: absolute; top: 14px; right: 14px; z-index: 2; width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer; color: var(--navy, #0D1F35);
  background: var(--card, #fff); border: 1px solid transparent;
}
.lb-x:hover { border-color: var(--border-strong, #B8D4EE); }

.lb-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; align-items: stretch; }
.lb-game {
  display: flex; flex-direction: column; min-width: 0;
  padding: 16px; border-radius: 16px; background: var(--bg, #F4F8FC);
}
.lb-game-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 0 0 12px; }
.lb-game h3 { margin: 0; font: 800 1.1rem/1.2 var(--font-display, var(--font-body)); letter-spacing: -0.01em; color: var(--navy, #0D1F35); white-space: nowrap; }
.lb-status { margin: 0; font-size: 0.75rem; font-weight: 600; color: var(--muted, #5B6B7F); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Two-way toggle: same vocabulary as the game's own segmented control
   (gold tint, accent hairline) so "which view am I in" reads at a glance. */
.lb-seg { display: flex; gap: 4px; padding: 3px; margin: 0 0 8px; border-radius: 999px; background: var(--card, #fff); box-shadow: inset 0 0 0 1px var(--border, #DBE7F4); }
.lb-seg-btn {
  flex: 1; min-height: 38px; padding: 0 12px; border-radius: 999px; border: 0; cursor: pointer;
  background: transparent; font: 700 0.8125rem/1 var(--font-body); color: var(--muted, #5B6B7F);
}
.lb-seg-btn:hover { color: var(--navy, #0D1F35); }
@media (pointer: coarse) { .lb-seg-btn { min-height: 44px; } }
.lb-seg-btn[aria-pressed="true"] {
  background: var(--sx-tg-gold-tint, color-mix(in srgb, var(--blue, #1E72BE) 12%, var(--card, #fff)));
  color: var(--navy, #0D1F35); box-shadow: inset 0 0 0 1px var(--blue, #1E72BE);
}

/* Five rows tall on every card; a longer seasonal board scrolls inside it. */
.lb-body { --lb-row: 52px; display: flex; flex-direction: column; min-height: calc(5 * var(--lb-row)); }
.lb-list { list-style: none; margin: 0; padding: 0; }
.lb-list.is-scroll {
  max-height: calc(5 * var(--lb-row)); overflow: auto; overscroll-behavior: contain;
  /* Fade the last row while more players sit below (alpha mask, no color plate). */
  -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 32px), transparent);
  mask-image: linear-gradient(to bottom, #000 calc(100% - 32px), transparent);
}
/* Scrolled away from the top: fade the top edge too, so rows above are hinted. */
.lb-list.is-scroll:not(.at-start) {
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 32px, #000 calc(100% - 32px), transparent);
  mask-image: linear-gradient(to bottom, transparent, #000 32px, #000 calc(100% - 32px), transparent);
}
.lb-list.is-scroll.at-end:not(.at-start) {
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 32px);
  mask-image: linear-gradient(to bottom, transparent, #000 32px);
}
.lb-list.is-scroll.at-start.at-end { -webkit-mask-image: none; mask-image: none; }
.lb-row {
  display: grid; grid-template-columns: 26px minmax(0, 1fr) auto; align-items: center; gap: 8px;
  box-sizing: border-box; height: var(--lb-row); padding: 0 6px; border-bottom: 1px solid var(--border, #DBE7F4);
}
.lb-row:last-child { border-bottom: 0; }
.lb-you { flex: none; white-space: pre; font-weight: 800; color: var(--blue, #1E72BE); }
.lb-rule { margin: 8px 6px 12px; font-size: 0.75rem; font-weight: 600; color: var(--muted, #5B6B7F); }
.lb-rank {
  display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  font: 800 0.8125rem/1 var(--font-body); font-variant-numeric: tabular-nums; color: var(--muted, #5B6B7F);
}
.lb-row.is-first .lb-rank { color: var(--card, #fff); background: var(--blue, #1E72BE); box-shadow: 0 0 0 3px var(--sx-tg-halo, rgba(30, 114, 190, 0.2)); }
.lb-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
/* One friendly line in the room a short board leaves (never placeholder rows). */
.lb-invite {
  flex: 1; display: grid; place-items: center; margin: 0; padding: 12px 8px;
  font-size: 0.875rem; font-weight: 600; line-height: 1.4; text-align: center; text-wrap: balance; color: var(--muted, #5B6B7F);
}
.lb-list + .lb-invite { border-top: 1px solid var(--border, #DBE7F4); }

.lb-who { display: flex; align-items: center; gap: 10px; min-width: 0; min-height: 44px; color: inherit; text-decoration: none; border-radius: 10px; }
a.lb-who:hover .lb-name { text-decoration: underline; text-underline-offset: 3px; }
.lb-face {
  position: relative; flex: none; display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; overflow: hidden;
  background: color-mix(in srgb, var(--blue, #1E72BE) 10%, var(--card, #fff));
  font: 800 0.6875rem/1 var(--font-body); color: var(--navy, #0D1F35);
}
.lb-face.is-initials { background: var(--navy, #0D1F35); color: var(--card, #fff); }
.lb-face img { width: 100%; height: 100%; object-fit: cover; object-position: center 18%; }
.lb-who-text { display: flex; flex-direction: column; min-width: 0; }
.lb-name { display: flex; min-width: 0; overflow: hidden; font-weight: 700; font-size: 0.875rem; line-height: 1.25; color: var(--navy, #0D1F35); white-space: nowrap; }
.lb-name-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.lb-sub { font-size: 0.75rem; line-height: 1.3; color: var(--muted, #5B6B7F); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-faces { display: flex; flex: none; }
.lb-team-sub { display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.lb-faces .lb-face { width: 20px; height: 20px; font-size: 0.5625rem; box-shadow: 0 0 0 2px var(--bg, #F4F8FC); }
.lb-faces .lb-face + .lb-face { margin-left: -5px; }

.lb-score { display: flex; flex-direction: column; align-items: flex-end; font-variant-numeric: tabular-nums; }
.lb-score b { font: 800 1.05rem/1.1 var(--font-body); color: var(--navy, #0D1F35); }
.lb-score small { font-size: 0.6875rem; font-weight: 600; color: var(--muted, #5B6B7F); white-space: nowrap; }
.lb-row.is-first .lb-score b { font-size: 1.25rem; color: var(--blue, #1E72BE); }

.lb-note { margin: 12px 4px; font-size: 0.875rem; line-height: 1.45; color: var(--text, #374151); }
.lb-link-btn {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 4px;
  font: 700 0.875rem/1.2 var(--font-body); color: var(--blue-deep, #155A9C);
  background: none; border: 0; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px;
}
.lb-link-btn:hover { text-decoration-thickness: 2px; }
/* Footer action, same slot on every card. */
.lb-actions { display: flex; justify-content: center; margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border, #DBE7F4); }
.lb-play {
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 1.25rem; border-radius: 999px; cursor: pointer;
  font: 700 0.875rem/1 var(--font-body); color: var(--blue-deep, #155A9C);
  background: var(--card, #fff); border: 1px solid var(--sx-tg-ctrl, var(--border-strong, #B8D4EE));
}
.lb-play:hover { border-color: var(--blue, #1E72BE); box-shadow: 0 0 0 3px var(--sx-tg-halo, rgba(30, 114, 190, 0.16)); }

.lb-x:focus-visible, .lb-seg-btn:focus-visible, .lb-play:focus-visible, .lb-link-btn:focus-visible, .lb-more:focus-visible, a.lb-who:focus-visible, .lb-list:focus-visible {
  outline: 2px solid var(--sx-tg-focus, var(--blue, #1E72BE)); outline-offset: 2px;
}

/* Tablets and phones: one game per row, natural height (no reserved rows;
   the invite line shows only on an empty board). */
@media (max-width: 1023px) {
  .lb-grid { grid-template-columns: 1fr; gap: 12px; }
  .lb-body { min-height: 0; }
  .lb-list.is-scroll { max-height: none; overflow: visible; }
  .lb-invite:not(.is-empty) { display: none; }
  .lb-invite.is-empty { padding: 16px 8px; }
  .lb-actions { margin-top: 8px; }
}
@media (min-width: 600px) and (max-width: 1023px) { .lb-card { width: min(640px, 100%); } }
@media (max-width: 480px) {
  .lb-dialog { padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom)); }
  .lb-card { padding: 0 14px 18px; border-radius: 18px; max-height: calc(100dvh - 16px); }
  /* The title row stays put while the sheet scrolls, so Close is always in reach. */
  .lb-head { position: sticky; top: 0; z-index: 1; gap: 10px; margin: 0 -14px 12px; padding: 16px 60px 12px 14px; background: var(--card, #fff); border-bottom: 1px solid var(--border, #DBE7F4); }
  .lb-x { top: 50%; right: 8px; transform: translateY(-50%); }
  .lb-medal { width: 40px; height: 40px; }
  .lb-medal svg { width: 22px; height: 22px; }
  .lb-game { padding: 12px; }
}

@keyframes lb-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes lb-rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .lb-dialog, .lb-card { animation: none; } }
@media print { .lb-dialog { display: none; } }
