/*
 * chess-days-players.css — the championship roster on /chess-days/
 * (#players, rendered by _includes/partials/chess-players.njk). Compact
 * cards in a 5 × 2 grid (2 × 5 on phones), each opening the bio <dialog>
 * (assets/js/chess-days-players.js). Linked inline from the page body.
 * Reuses the site design tokens (--heading-color, --accent-color,
 * --surface-color, --heading-font).
 */

/* --- Sort toggle (unhidden by the JS) ----------------------------------- */
.cd-players-sort {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin: 0 0 18px;
  font-size: 13px;
}
.cd-players-sort[hidden] { display: none; }
.cd-players-sort-label {
  color: color-mix(in srgb, var(--default-color), transparent 40%);
}
.cd-players-sort-btn {
  padding: 5px 14px;
  border: 1px solid color-mix(in srgb, var(--heading-color), transparent 80%);
  border-radius: 999px;
  background: var(--surface-color);
  color: var(--heading-color);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}
.cd-players-sort-btn:hover {
  border-color: color-mix(in srgb, var(--accent-color), transparent 40%);
}
.cd-players-sort-btn:focus-visible {
  outline: 2px solid var(--accent-color);
  outline-offset: 2px;
}
.cd-players-sort-btn[aria-pressed="true"] {
  background: var(--accent-color);
  border-color: var(--accent-color);
  color: var(--contrast-color, #fff);
}

/* --- Grid ----------------------------------------------------------------- */
.cd-players-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  align-items: stretch;
  gap: 18px;
}
@media (max-width: 991.98px) {
  .cd-players-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
  }
}

/* --- Card ----------------------------------------------------------------- */
.cd-player {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-width: 0;
  background: var(--surface-color);
  border: 1px solid color-mix(in srgb, var(--heading-color), transparent 86%);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 2px 14px rgba(15, 23, 42, 0.05);
  scroll-margin-top: calc(var(--header-height, 120px) + 14px);
  cursor: pointer;
  transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
}
.cd-player:hover,
.cd-player:focus-visible {
  transform: translateY(-3px);
  border-color: color-mix(in srgb, var(--accent-color), transparent 50%);
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.12);
  outline: none;
}
.cd-player:target {
  animation: cd-player-flash 2.2s ease;
}
@keyframes cd-player-flash {
  0%, 15% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent-color), transparent 70%); }
  100% { box-shadow: 0 2px 14px rgba(15, 23, 42, 0.05); }
}
@media (prefers-reduced-motion: reduce) {
  .cd-player, .cd-player:hover { transition: none; transform: none; }
  .cd-player:target { animation: none; outline: 2px solid var(--accent-color); }
}

/* --- Head: portrait (or placeholder) + title badge ------------------------ */
.cd-player-head {
  position: relative;
  aspect-ratio: 4 / 4.4;
  max-width: 100%;
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--heading-color), transparent 88%), color-mix(in srgb, var(--accent-color), transparent 84%));
}
.cd-player-photo {
  position: absolute;
  inset: 0;
}
.cd-player-photo img,
.cd-modal-photo img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
}
.cd-player-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 52px;
  color: color-mix(in srgb, var(--heading-color), transparent 65%);
  background-image:
    linear-gradient(45deg, rgba(0, 0, 0, 0.05) 25%, transparent 25%, transparent 75%, rgba(0, 0, 0, 0.05) 75%),
    linear-gradient(45deg, rgba(0, 0, 0, 0.05) 25%, transparent 25%, transparent 75%, rgba(0, 0, 0, 0.05) 75%);
  background-size: 36px 36px;
  background-position: 0 0, 18px 18px;
}
/* Title badge (GM/IM/FM) in the photo's top-right corner — the only thing
   over the portrait; untitled players simply have no badge. */
.cd-player-title {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 13px;
  padding: 2px 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

/* --- Body ----------------------------------------------------------------- */
.cd-player-body {
  padding: 12px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 0;
}
/* Draw number: the same labelled kicker the dialog carries (.cd-modal-kicker),
   sized for the card. Uppercasing is left to CSS so the data file keeps the
   label in sentence case for the dialog. */
.cd-player-draw {
  margin: 0 0 1px;
  font-family: var(--heading-font);
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--default-color), transparent 45%);
}
.cd-player-name {
  margin: 0;
  font-size: 15px;
  line-height: 1.25;
  font-weight: 700;
  color: var(--heading-color);
  overflow-wrap: anywhere;
}
/* Club row: logo + name. The two-line clamp lives on the text span, not the
   row, so the logo stays vertically centred beside a wrapped name. */
.cd-player-club {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  font-size: 12px;
  line-height: 1.35;
  color: color-mix(in srgb, var(--default-color), transparent 30%);
}
.cd-player-club-text {
  min-width: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
/* Club logos come in every shape (tall crests, square badges, a wide
   wordmark), so each keeps its own aspect ratio inside a fixed-height slot
   with a width cap, rather than being forced into a square that would shrink
   the wide ones to nothing. */
.cd-club-logo {
  flex: 0 0 auto;
  height: 24px;
  width: auto;
  max-width: 64px;
  object-fit: contain;
}
.cd-modal-meta .cd-club-logo {
  height: 30px;
  max-width: 96px;
  margin-right: 8px;
  vertical-align: middle;
}
.cd-player-rating {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--heading-color);
  margin-bottom: 6px;
}
/* The rating list's month: muted, so the number still leads. */
.cd-player-rating-date {
  font-weight: 400;
  color: color-mix(in srgb, var(--default-color), transparent 40%);
}
/* The CTA — always visible, filled on hover/focus of the card. */
.cd-player-more {
  margin-top: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  align-self: stretch;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--accent-color), transparent 55%);
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-color);
  text-decoration: none;
  transition: background 0.2s ease, color 0.2s ease;
}
.cd-player:hover .cd-player-more,
.cd-player:focus-visible .cd-player-more,
.cd-player-more:hover,
.cd-player-more:focus-visible {
  background: var(--accent-color);
  color: var(--contrast-color, #fff);
  border-color: var(--accent-color);
}

/* Title legend under the grid — deliberately the same quiet, centred line as
   .cd-crosstable-legend under the standings table. */
.cd-players-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 18px;
  margin: 14px 0 0;
  text-align: center;
  font-size: 12px;
  color: color-mix(in srgb, var(--default-color), transparent 40%);
}
/* One entry per title, kept whole when the legend wraps. The abbreviation
   reuses the card badge (colours below); the expansion is written out beside
   it, so no help cursor. */
.cd-players-legend-item {
  white-space: nowrap;
}
/* The ratings note wraps on phones (unlike the short title items) and takes
   a line of its own below them. */
.cd-players-legend-note {
  flex-basis: 100%;
}
.cd-players-legend-badge {
  cursor: default;
  margin-right: 3px;
  font-size: 11px;
}

/* --- Title badge (shared with the live tables) ----------------------------
   It is an <abbr> whose title spells the abbreviation out (site.chess.titles,
   mirrored in chess-days-live.js), so drop the UA's dotted underline and say
   with the cursor that hovering explains something. */
.cd-title {
  display: inline-block;
  cursor: help;
  padding: 1px 7px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1.5;
  color: #fff;
  background: #64748b;
  vertical-align: middle;
}
/* Bootstrap's reboot underlines abbr[title] — outrank it by the attribute,
   not the element, so the badge stays a solid chip. */
.cd-title[title] {
  text-decoration: none;
}
.cd-title--gm { background: #b45309; }
.cd-title--im { background: #1d4ed8; }
.cd-title--fm { background: #047857; }
.cd-title--cm { background: #6d28d9; }

/* --- Bio dialog ----------------------------------------------------------- */
.cd-modal {
  width: min(720px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 0;
  border-radius: 18px;
  background: var(--surface-color);
  color: var(--default-color);
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.35);
  overflow: hidden;
}
.cd-modal::backdrop {
  background: rgba(8, 12, 28, 0.62);
  backdrop-filter: blur(2px);
}
.cd-modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 0;
  background: rgba(255, 255, 255, 0.92);
  color: #1f2937;
  font-size: 18px;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}
.cd-modal-close:hover,
.cd-modal-close:focus-visible {
  background: var(--accent-color);
  color: #fff;
  outline: none;
}
.cd-modal-body {
  display: grid;
  grid-template-columns: 260px 1fr;
  max-height: calc(100vh - 32px);
}
.cd-modal-photo {
  position: relative;
  min-height: 300px;
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--heading-color), transparent 88%), color-mix(in srgb, var(--accent-color), transparent 84%));
}
.cd-modal-photo .cd-player-placeholder {
  font-size: 88px;
}
/* The portraits are transparent cut-outs, so the placeholder (chequer
   pattern + knight) would show through around the player. Hide it whenever a
   photo is actually present: a missing card photo removes its own <img>
   (onerror), and the dialog's <img> is [hidden] when there is none — in both
   cases the placeholder comes back. The head's gradient stays as the ground. */
.cd-player-photo:has(img) .cd-player-placeholder,
.cd-modal-photo:has(img:not([hidden])) .cd-player-placeholder {
  display: none;
}
.cd-modal-photo .cd-player-title {
  top: 14px;
  right: 14px;
  font-size: 15px;
  padding: 3px 10px;
}
.cd-modal-text {
  padding: 26px 28px 28px;
  overflow-y: auto;
}
.cd-modal-kicker {
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--default-color), transparent 45%);
}
.cd-modal-name {
  margin: 0 0 6px;
  font-size: 24px;
  line-height: 1.2;
  font-weight: 700;
  color: var(--heading-color);
  padding-right: 36px;
}
.cd-modal-meta {
  margin: 0 0 14px;
  font-size: 14px;
  color: color-mix(in srgb, var(--default-color), transparent 30%);
}
.cd-modal-meta strong {
  color: var(--heading-color);
  font-variant-numeric: tabular-nums;
}
.cd-modal-bio {
  margin: 0;
  font-size: 15px;
  line-height: 1.6;
}
@media (max-width: 767.98px) {
  .cd-modal-body {
    grid-template-columns: 1fr;
  }
  .cd-modal-photo {
    min-height: 0;
    aspect-ratio: 16 / 10;
  }
  /* A wide strip would crop a portrait-shaped cover fit to forehead-and-eyes;
     the cut-outs show whole instead, standing on the strip's bottom edge with
     a little headroom (the gradient fills the sides). */
  .cd-modal-photo img {
    top: 14px;
    height: calc(100% - 14px);
    object-fit: contain;
    object-position: center bottom;
  }
  /* Stacked, the photo spans the dialog's top, where the close button sits
     (top right) — the title badge moves to the photo's other corner. */
  .cd-modal-photo .cd-player-title {
    right: auto;
    left: 14px;
  }
  .cd-modal-text {
    padding: 18px 18px 22px;
  }
  .cd-modal-name {
    font-size: 20px;
  }
}
@media (max-width: 575.98px) {
  .cd-player-body { padding: 10px; }
  .cd-player-name { font-size: 14px; }
  .cd-player-placeholder { font-size: 40px; }
  .cd-player-title { top: 8px; right: 8px; font-size: 12px; }
  .cd-player-more { font-size: 12px; padding: 5px 8px; }
}
