/* =====================================================================
 *  tools/leaderboards.css  -  /tools/leaderboards
 *  ---------------------------------------------------------------------
 *  Loads after bico-theme.css and tools.css, so every colour here is a
 *  theme token and both the parchment and the nocturne palettes come out
 *  right without a single override.
 * ===================================================================== */

/* ---------------------------------------------------------------------
 *  Gold that can be READ, not just drawn with.
 *
 *  --gold is #b8892b in vellum, and the winning row is painted with
 *  --gold-wash (#f0e3c4). Gold text on that is 2.48:1 - the same
 *  white-on-gold failure the /geopo spell chips had. The nocturne gold
 *  is already 9.69:1 on its own wash, so only the light theme needs a
 *  different value: #7a5a11 is 5.01:1 on the wash and 5.57:1 on a plain
 *  card, and still reads as gold rather than as brown.
 *
 *  Declared per theme rather than as :root { var(--gold) }, because a
 *  custom property resolves its var() where it is DECLARED - a :root
 *  indirection would freeze the vellum gold and follow the theme no
 *  further.
 * ------------------------------------------------------------------- */
:root              { --lb-gold-ink: #7a5a11; }
body.bico-vellum   { --lb-gold-ink: #7a5a11; }
body.bico-nocturne { --lb-gold-ink: var(--gold); }

/* --text-muted is 3.56:1 on the winning row and 4.10:1 on a plain card
   in vellum, so none of the small print below uses it. --text-secondary
   is 7.9:1 at worst in either theme and still sits a step below the
   name, which is all the hierarchy needed. */

/* ---- controls ------------------------------------------------------- */

.lb-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--gap-md);
  padding: var(--pad-md);
  margin-bottom: var(--gap-md);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.lb-field { display: flex; flex-direction: column; gap: 4px; }

.lb-field__k {
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.lb-input {
  font-family: var(--font-ui);
  font-size: 14px;
  padding: 6px 10px;
  color: var(--text-primary);
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.lb-input:focus-visible { outline: 2px solid var(--lb-gold-ink); outline-offset: 1px; }

/* The dropdown list itself is painted by the OS, which does not inherit
   the page tokens - without these it is black text on black in nocturne. */
.lb-input option { color: var(--text-primary); background: var(--surface-3); }

.lb-meta {
  flex: 1 1 220px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0;
  font-family: var(--font-ui);
  font-size: 12px;
  color: var(--text-secondary);
  text-align: right;
}
.lb-meta__when { color: var(--text-secondary); }

/* ---- section jumps -------------------------------------------------- */

.lb-jump {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap-xs);
  margin-bottom: var(--gap-lg);
}

.lb-jump__link {
  font-family: var(--font-ui);
  font-size: 13px;
  padding: 4px 13px;
  color: var(--text-secondary);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  text-decoration: none;
  transition: border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.lb-jump__link:hover { border-color: var(--lb-gold-ink); color: var(--text-primary); }

/* ---- sections and the card grid ------------------------------------- */

.lb-section { margin-bottom: var(--gap-xl); }
.lb-section:last-child { margin-bottom: var(--gap-md); }

/* scroll-margin so a #sec- jump does not land under the sticky header */
.lb-section { scroll-margin-top: calc(var(--header-h) + 16px); }

.lb-section__title {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.5px;
  margin: 0 0 var(--gap-sm);
  padding-bottom: 6px;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border);
}

.lb-grid {
  display: grid;
  gap: var(--gap-md);
  /* Two up on a desktop, one up on a phone, and the cards stay readable
     in between rather than stretching to half a 1180px shell. */
  grid-template-columns: repeat(auto-fit, minmax(330px, 1fr));
}

.lb-card {
  display: flex;
  flex-direction: column;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.lb-card__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px var(--gap-sm);
  padding: var(--pad-md) var(--pad-md) var(--pad-sm);
  border-bottom: 1px solid var(--border);
}

.lb-card__title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text-primary);
}

.lb-card__col {
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-secondary);
  white-space: nowrap;
}

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

.lb-rows {
  flex: 1;
  list-style: none;
  margin: 0;
  padding: 0;
}

.lb-row {
  display: grid;
  grid-template-columns: 30px 1fr auto auto;
  align-items: center;
  gap: 0 var(--gap-sm);
  padding: 9px var(--pad-md);
  border-bottom: 1px solid var(--border);
}
.lb-row:last-child { border-bottom: 0; }

.lb-row--first { background: var(--gold-wash); }

.lb-rank {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}
.lb-row--first .lb-rank { color: var(--lb-gold-ink); font-size: 21px; }

.lb-row__body { min-width: 0; }

.lb-name {
  display: block;
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  text-decoration: none;
  /* A long domain name must not widen the card past its grid track. */
  overflow-wrap: anywhere;
}
a.lb-name:hover { color: var(--lb-gold-ink); text-decoration: underline; }

.lb-sub {
  display: block;
  font-family: var(--font-prose);
  font-size: 12.5px;
  line-height: 1.35;
  color: var(--text-secondary);
  overflow-wrap: anywhere;
}

.lb-tags {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  margin-top: 2px;
  font-family: var(--font-ui);
  font-size: 11.5px;
  color: var(--text-secondary);
}

.lb-guild { color: var(--text-secondary); text-decoration: none; }
a.lb-guild:hover { color: var(--lb-gold-ink); text-decoration: underline; }

.lb-owner { color: var(--text-secondary); }

/* The separator TRAILS the guild instead of leading the owner.
   Leading it meant that when a long guild name wrapped - "Emissaires de
   la Cite des Sables" does, at 375px - the owner began the next line
   with a lone middle dot, which reads as a bullet. Trailing it, the
   guild line simply ends in a dot, which reads as "continues below".
   The class is set by the renderer only when an owner actually follows,
   so a guild with no owner never gets a dangling dot. */
.lb-guild--sep::after { content: '\00a0\00b7'; }

.lb-chip {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  padding: 1px 6px;
  color: var(--text-secondary);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
}

.lb-val { text-align: right; white-space: nowrap; }

.lb-val__n {
  display: block;
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}
.lb-row--first .lb-val__n { color: var(--lb-gold-ink); font-size: 17px; }

.lb-val__u {
  display: block;
  font-family: var(--font-ui);
  font-size: 10px;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.lb-hist {
  font-size: 13px;
  line-height: 1;
  padding: 5px;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: var(--radius-sm);
}
.lb-hist:hover { color: var(--lb-gold-ink); background: var(--surface-3); }

/* ---- card footer ---------------------------------------------------- */

.lb-card__foot {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px var(--gap-sm);
  padding: var(--pad-sm) var(--pad-md);
  background: var(--surface-1);
  border-top: 1px solid var(--border);
  font-family: var(--font-ui);
  font-size: 11.5px;
  color: var(--text-secondary);
}

.lb-entrants { font-variant-numeric: tabular-nums; }

.lb-why > summary {
  cursor: pointer;
  color: var(--text-secondary);
  text-decoration: underline dotted;
  text-underline-offset: 2px;
}
.lb-why > summary:hover { color: var(--lb-gold-ink); }
.lb-why[open] { flex: 1 1 100%; }
.lb-why > p {
  margin: 6px 0 0;
  font-family: var(--font-prose);
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text-secondary);
}

/* ---- states --------------------------------------------------------- */

.lb-unavail,
.lb-empty {
  margin: 0;
  padding: var(--pad-md);
  font-family: var(--font-prose);
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-secondary);
}
.lb-unavail { color: var(--text-secondary); }
.lb-unavail strong { color: var(--warn); }
.lb-empty { font-style: italic; color: var(--text-secondary); }

.lb-loading,
.lb-error {
  padding: var(--pad-xl) var(--pad-md);
  text-align: center;
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--text-secondary);
}
.lb-error { color: var(--text-secondary); }

.lb-retry {
  font-family: var(--font-ui);
  font-size: 13px;
  padding: 5px 14px;
  color: var(--text-primary);
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  cursor: pointer;
}
.lb-retry:hover { border-color: var(--lb-gold-ink); }

.lb-foot {
  margin: var(--gap-lg) 0 0;
  font-family: var(--font-prose);
  font-size: 13px;
  font-style: italic;
  color: var(--text-secondary);
}

/* ---- narrow --------------------------------------------------------- */

@media (max-width: 560px) {
  .lb-controls { gap: var(--gap-sm); }
  .lb-meta { flex-basis: 100%; text-align: left; }
  .lb-grid { grid-template-columns: 1fr; }
  .lb-row {
    grid-template-columns: 26px 1fr auto;
    row-gap: 2px;
  }
  /* The history arrow moves under the value rather than squeezing the
     name into nothing on a 320px screen. */
  .lb-hist {
    grid-column: 3;
    justify-self: end;
    padding: 2px 5px;
  }
  .lb-val { grid-column: 3; grid-row: 1; }
  .lb-row__body { grid-column: 2; grid-row: 1 / span 2; }
  .lb-rank { grid-row: 1 / span 2; }
}
