/* ============================================================================
   Grade Champions celebration
   ----------------------------------------------------------------------------
   Student-facing announcement that celebrates the #1 student of every grade.
   Rendered by js/grade_champions.js; the teacher-portal preview reuses the
   same .uk-champions-* classes so the preview is pixel-faithful.
   Palette follows the site tokens (ink navy, gold, warm paper).
   ============================================================================ */

.uk-champions-overlay {
  --ch-ink: #16233b;
  --ch-ink-soft: #4a5670;
  --ch-paper: #fbfaf7;
  --ch-line: #e3dccd;
  --ch-gold: #c49a45;
  --ch-gold-deep: #8a6a22;
  --ch-gold-soft: rgba(196, 154, 69, 0.14);
  --ch-font-display: "Playfair Display", Georgia, serif;
  --ch-font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;

  position: fixed;
  inset: 0;
  z-index: 99990;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(10, 15, 29, 0.62);
  font-family: var(--ch-font);
  color: var(--ch-ink);
}

.uk-champions-card {
  position: relative;
  width: min(880px, 100%);
  max-height: min(92vh, 92dvh);
  overflow-y: auto;
  background: var(--ch-paper);
  border: 1px solid var(--ch-line);
  border-radius: 20px;
  box-shadow: 0 30px 70px -20px rgba(10, 15, 29, 0.55);
  padding: 2rem 2rem 1.75rem;
}

/* Thin gold rule across the top as the only ornament on the shell */
.uk-champions-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: var(--ch-gold);
  border-radius: 20px 20px 0 0;
}

.uk-champions-close {
  position: absolute;
  top: 0.9rem;
  right: 0.9rem;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--ch-line);
  background: #fff;
  color: var(--ch-ink-soft);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.uk-champions-close:focus-visible { outline: 2px solid var(--ch-gold-deep); outline-offset: 2px; }

.uk-champions-head {
  text-align: center;
  margin: 0.25rem 0 1.5rem;
}

.uk-champions-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ch-gold-deep);
  margin-bottom: 0.6rem;
}
.uk-champions-eyebrow i { color: var(--ch-gold); }

.uk-champions-title {
  font-family: var(--ch-font-display);
  font-size: clamp(1.5rem, 3.2vw, 2.1rem);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.01em;
  margin: 0 0 0.5rem;
  color: var(--ch-ink);
}

.uk-champions-message {
  max-width: 60ch;
  margin: 0 auto;
  color: var(--ch-ink-soft);
  font-size: 0.95rem;
  line-height: 1.6;
  white-space: pre-line;
}

/* ============================================================================
   Champion grid — one card per grade (3 x 2 for the six grades)
   ============================================================================ */
.uk-champions-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.9rem;
  margin: 0 0 1.25rem;
}

.uk-champion {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.35rem;
  padding: 1.1rem 0.85rem 0.95rem;
  background: #ffffff;
  border: 1px solid var(--ch-line);
  border-radius: 14px;
}

.uk-champion-grade {
  position: absolute;
  top: 0.65rem;
  left: 0.65rem;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ch-gold-deep);
  background: var(--ch-gold-soft);
  padding: 0.22rem 0.5rem;
  border-radius: 999px;
}

.uk-champion-avatar-wrap {
  position: relative;
  width: 72px;
  height: 72px;
  margin-top: 0.35rem;
}

.uk-champion-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--ch-line);
  border: 3px solid var(--ch-gold);
  box-shadow: 0 0 0 3px #fff;
  display: block;
}

.uk-champion-name {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--ch-ink);
  line-height: 1.2;
  margin-top: 0.3rem;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.uk-champion-stats {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ch-ink-soft);
  font-variant-numeric: tabular-nums;
}
.uk-champion-stats span { display: inline-flex; align-items: center; gap: 0.25rem; }
.uk-champion-stats img { width: 1em; height: 1em; }
.uk-champion-stats .uk-champion-streak i { color: #ea580c; }

/* ============================================================================
   Crown, footer / CTA, loading & empty states, responsive
   ============================================================================ */
.uk-champion-crown {
  position: absolute;
  top: -14px;
  left: 50%;
  transform: translateX(-50%);
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--ch-gold);
  color: #fff;
  font-size: 0.7rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 0 3px #fff;
}

.uk-champions-foot {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  border-top: 1px solid var(--ch-line);
  padding-top: 1.1rem;
}

.uk-champions-cta {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: var(--ch-ink);
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.88rem;
  padding: 0.65rem 1.2rem;
  border-radius: 999px;
}
.uk-champions-cta:focus-visible { outline: 2px solid var(--ch-gold-deep); outline-offset: 2px; }

.uk-champions-dismiss {
  background: transparent;
  border: 0;
  color: var(--ch-ink-soft);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.uk-champions-note {
  width: 100%;
  text-align: center;
  font-size: 0.72rem;
  color: var(--ch-ink-soft);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-top: 0.25rem;
}

/* Skeleton while the leaderboard resolves */
.uk-champion.is-loading .uk-champion-avatar,
.uk-champion.is-loading .uk-champion-name,
.uk-champion.is-loading .uk-champion-stats {
  color: transparent;
  background: var(--ch-line);
  border-color: var(--ch-line);
  border-radius: 999px;
}
.uk-champion.is-loading .uk-champion-name  { width: 60%; height: 0.9rem; }
.uk-champion.is-loading .uk-champion-stats { width: 45%; height: 0.75rem; }

.uk-champions-empty {
  text-align: center;
  color: var(--ch-ink-soft);
  padding: 1.5rem 1rem;
  font-size: 0.9rem;
}

@media (max-width: 720px) {
  .uk-champions-card { padding: 1.5rem 1.1rem 1.25rem; border-radius: 16px; }
  .uk-champions-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.7rem; }
  .uk-champion-avatar-wrap, .uk-champion-avatar { width: 60px; height: 60px; }
}
@media (max-width: 420px) {
  .uk-champions-grid { grid-template-columns: 1fr 1fr; }
  .uk-champion { padding: 1rem 0.5rem 0.8rem; }
  .uk-champion-name { font-size: 0.85rem; }
}

@media (prefers-reduced-motion: reduce) {
  .uk-champions-overlay * { transition: none !important; animation: none !important; }
}

/* ============================================================================
   Teacher-portal preview — the same card, rendered inline and scaled to fit
   ============================================================================ */
.gc-preview-viewport {
  padding: 0.75rem;
  background: #eef0f3;
  border-radius: 10px;
  overflow: hidden;
}

.gc-preview-mount {
  /* Provide the tokens the card expects when it is not inside the overlay */
  --ch-ink: #16233b;
  --ch-ink-soft: #4a5670;
  --ch-paper: #fbfaf7;
  --ch-line: #e3dccd;
  --ch-gold: #c49a45;
  --ch-gold-deep: #8a6a22;
  --ch-gold-soft: rgba(196, 154, 69, 0.14);
  --ch-font-display: "Playfair Display", Georgia, serif;
  --ch-font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-family: var(--ch-font);
  color: var(--ch-ink);
  zoom: 0.72;                  /* fit the 880px card into the preview column */
}

.gc-preview-mount .uk-champions-card {
  max-height: none;
  overflow: visible;
  width: 100%;
  box-shadow: 0 8px 24px rgba(10, 15, 29, 0.12);
}

/* In the portal preview the card is not a dialog: no close, no dismiss */
.gc-preview-mount .uk-champions-close,
.gc-preview-mount .uk-champions-dismiss { display: none; }

/* Keep the preview readable when the column is narrow */
@media (max-width: 1100px) {
  .gc-preview-mount { zoom: 0.6; }
  .gc-preview-mount .uk-champions-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ============================================================================
   Balanced rows for any champion count
   Six champions: 3 + 3. Seven (grade 5 now has a leader): 4 + 3 instead of
   3 + 3 + a lone card. Eight would be 4 + 4.
   ============================================================================ */
.uk-champions-grid:has(> .uk-champion:nth-child(7)) {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
.uk-champions-grid:has(> .uk-champion:nth-child(7)) .uk-champion-avatar-wrap,
.uk-champions-grid:has(> .uk-champion:nth-child(7)) .uk-champion-avatar {
  width: 64px;
  height: 64px;
}
.uk-champions-grid:has(> .uk-champion:nth-child(7)) .uk-champion-name { font-size: 0.86rem; }

@media (max-width: 720px) {
  .uk-champions-grid:has(> .uk-champion:nth-child(7)) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
