/* leaderboard.css - The leaderboard page body (everything between the date bar and
   the footer). Loads after theme.css, styles.css and book-popup.css; the header, nav,
   date bar, footer and book pop-up keep their own styles. Season colors come from
   --primary-dark, which seasonal-config.js sets; the tints below derive from it. */

:root {
  --ink: #2c3e50;
  --muted: #555;
  --line: #d5dbe1;
  --line-soft: #e6eaee;
  /* Plain fallbacks first for browsers without color-mix(). */
  --tint: #eef2f6;
  --tint: color-mix(in srgb, var(--primary-dark) 10%, #fff);
  --primary-deep: #24406a;
  --primary-deep: color-mix(in srgb, var(--primary-dark) 78%, #000);
  --lb-hover: rgba(0, 0, 0, 0.04);
  --lb-hover: color-mix(in srgb, var(--primary-dark) 6%, transparent);
  --focus: var(--primary-dark);
}

main.lb { color: var(--ink); line-height: 1.5; }
/* :where() keeps these at plain-link strength so .btn colors win. */
:where(main.lb) a { color: var(--primary-dark); }
:where(main.lb) a:hover { color: var(--primary-deep); }
main.lb :focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---------- Layout ---------- */

.layout { display: flex; flex-direction: column; gap: 20px; padding-top: 24px; padding-bottom: 40px; }

@media (max-width: 899px) {
  .layout { gap: 16px; padding-top: 16px; }
}

/* ---------- Panels ---------- */

.panel { border: 1px solid var(--line); border-radius: 4px; overflow: hidden; background: #fff; }
.panel-head {
  background: var(--primary-dark); color: #fff;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 10px 15px; min-height: 46px;
}
.panel-head h2 { margin: 0; font-size: 17px; }
.empty { margin: 0; padding: 16px 15px; color: var(--muted); }
.board-note { margin: 0; padding: 28px 15px; text-align: center; font-size: 17px; }

/* ---------- Join card ---------- */

.join-card {
  border: 2px solid var(--primary-dark); border-radius: 6px; background: var(--tint);
  padding: 18px 20px; display: flex; flex-direction: column; gap: 12px;
}
.join-card h2 { margin: 0; font-size: 20px; }
.join-card p { margin: 0; color: var(--muted); }
.join-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px;
  padding: 0 18px; border-radius: 4px; font-weight: 600; text-decoration: none;
}
.btn-primary { background: var(--primary-dark); color: #fff; }
.btn-primary:hover { background: var(--primary-deep); color: #fff; }
.btn-outline { border: 2px solid var(--primary-dark); color: var(--primary-dark); }

/* ---------- Stats ---------- */

.stats-list { margin: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.stat-row {
  display: flex; flex-direction: column-reverse; align-items: center; justify-content: flex-end;
  border: 1px solid var(--line); border-radius: 4px; padding: 14px 8px; text-align: center;
}
.stat-row dt { font-size: 13px; font-weight: 600; color: var(--muted); }
.stat-row dd { margin: 0; font-size: 30px; font-weight: 700; color: var(--primary-dark); line-height: 1.2; }

@media (max-width: 899px) {
  .stats-list { gap: 8px; }
  .stat-row { padding: 10px 4px; }
  .stat-row dt { font-size: 11px; }
  .stat-row dd { font-size: 22px; }
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ---------- Covers ---------- */

.cover {
  display: block; width: 100%; aspect-ratio: 2 / 3; object-fit: cover;
  border-radius: 3px; background: #dfe5ea; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

/* ---------- Shelf ---------- */

.shelf-tabs { display: flex; flex-wrap: wrap; gap: 4px; }
.tab-short { display: none; }
.shelf-tab {
  min-height: 34px; padding: 4px 14px; border-radius: 17px; border: 1px solid #fff;
  background: transparent; color: #fff; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
}
.shelf-tab[aria-pressed="true"] { background: #fff; color: var(--primary-dark); }
.shelf-body { display: flex; align-items: center; gap: 8px; padding: 16px 15px; }
.shelf-grid {
  flex: 1; min-width: 0; display: flex; gap: 14px; overflow-x: auto; scroll-behavior: smooth;
  scroll-snap-type: x proximity; scrollbar-width: none; padding: 2px;
}
.shelf-grid::-webkit-scrollbar { display: none; }
.shelf-grid .empty { padding: 0; }
.shelf-item {
  /* Eight across at desktop width. */
  flex: 0 0 calc((100% - 7 * 14px) / 8); scroll-snap-align: start;
  display: flex; flex-direction: column; gap: 6px; padding: 0; border: none; background: none;
  font: inherit; color: inherit; text-align: left; cursor: pointer; min-width: 0;
}
.shelf-title {
  font-size: 12px; font-weight: 700; color: var(--primary-dark); line-height: 1.2;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.shelf-cap {
  font-size: 11px; color: var(--muted); line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}

@media (max-width: 899px) {
  /* Short tab labels keep the tabs on the heading line at phone width. */
  .tab-long { display: none; }
  .tab-short { display: inline; }
  .shelf-tab { padding: 4px 12px; }
  .shelf-body { padding: 14px 12px; }
  .shelf-grid { gap: 12px; }
  .shelf-item { flex: 0 0 96px; }
}

/* ---------- Prize levels ---------- */

/* A trophy after the name for readers who finished every category; the count line adds "· N more to next prize!". */
.trophies { margin-left: 6px; letter-spacing: 1px; white-space: nowrap; }
.nudge { white-space: nowrap; }
.nudge--done { color: var(--primary-dark); font-weight: 600; }

.prize-key {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px;
  padding: 9px 15px; border-bottom: 1px solid var(--line); background: #f7f9fa;
  font-size: 13px; font-weight: 600; color: var(--muted);
}
.prize-key > span:first-child { margin-right: 8px; }
@media (max-width: 899px) {
  /* Smaller so the key stays on one line on 360px phones (Winter's "5 and 10" key). */
  .prize-key { font-size: 12px; padding: 9px 12px; gap: 6px 12px; }
  .prize-key > span:first-child { margin-right: 0; }
}

.board-rows { list-style: none; margin: 0; padding: 0; }

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

.row { border-bottom: 1px solid var(--line-soft); scroll-margin-top: 12px; }
.row:last-child { border-bottom: none; }

/* Desktop: a heading line with the carousel always open below it.
   Mobile: a collapsed toggle row; its ::after stretches over the whole
   header so tapping anywhere expands it. */
.row-head-desk { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; padding: 12px 15px 2px; }
.row-grid { display: none; }
.row:focus { outline: none; }
.row:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; }

.row-toggle {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; min-width: 0; width: 100%;
  padding: 0; background: none; border: none; font: inherit; color: inherit; text-align: left; cursor: pointer;
}
.row-toggle::after { content: ""; position: absolute; inset: 0; }
.row-toggle:focus-visible { outline: none; }
.row-toggle:focus-visible::after { outline: 3px solid var(--focus); outline-offset: -3px; }
.row-who { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; }
.row-name { font-size: 16px; font-weight: 600; overflow-wrap: anywhere; line-height: 1.3; }
.row-count { font-size: 13px; color: var(--muted); }
.row-count:empty { display: none; }

.stack { display: none; align-items: center; padding-left: 10px; flex-shrink: 0; }
.stack .cover { width: 28px; height: 42px; margin-left: -10px; border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); }

.chev-wrap { display: flex; color: var(--primary-dark); pointer-events: none; }
.chev { transition: transform 0.15s ease; }
.row.is-open .chev { transform: rotate(180deg); }

.row-books { display: flex; align-items: center; gap: 8px; padding: 4px 15px 16px; }
/* Row covers match the Community Shelf: eight across on desktop, 96px on mobile. */
.row-books[hidden] { display: none; }
.books-scroller {
  flex: 1; display: flex; gap: 14px; overflow-x: auto; scroll-behavior: smooth;
  scroll-snap-type: x proximity; padding: 4px 2px 6px;
}
.book {
  flex: 0 0 calc((100% - 7 * 14px) / 8); min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 0; border: none; background: none; font: inherit; color: inherit; cursor: pointer;
  scroll-snap-align: start;
}
.book .cover { width: 100%; }
.book-cat {
  font-size: 11px; line-height: 1.25; color: var(--muted); text-align: center;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.scroll-btn {
  width: 40px; height: 40px; flex-shrink: 0; border: none; border-radius: 50%;
  background: var(--primary-dark); color: #fff; display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.scroll-btn:disabled { opacity: 0.3; cursor: default; }
/* No arrows when everything already fits. */
.carousel.no-overflow > .scroll-btn { display: none; }
.books-scroller { scrollbar-width: none; }
.books-scroller::-webkit-scrollbar { display: none; }

@media (max-width: 899px) {
  .row-head-desk { display: none; }
  .row-grid {
    position: relative; display: grid; grid-template-columns: minmax(0, 1fr) 20px;
    align-items: center; gap: 8px; min-height: 60px; padding: 8px 10px;
  }
  .row-grid:hover { background: var(--lb-hover); }
  .stack { display: flex; }
  .row-name { font-size: 15px; }
  /* Tighter stack and gaps so "15 categories · 10 more to next prize!" fits one line at 360px. */
  .stack { padding-left: 17px; }
  .stack .cover { width: 26px; height: 39px; margin-left: -17px; }
  .row-toggle { gap: 6px; }
  .row-books { padding: 2px 12px 14px; }
  .scroll-btn { display: none; }
  .books-scroller { gap: 12px; }
  .book { flex-basis: 96px; }
}

/* Name line (name + trophy) */
.row-line { display: flex; align-items: center; gap: 8px; min-width: 0; }
