/* ==========================================================================
 * challenge.css — the per-game page under /games/<slug>/ (and every
 * /games/<slug>/c/<id> challenge link nginx maps onto it).
 *
 * Phone-first, ONE screen: plaque header / card / primary action / store
 * row / footer in a single column that never scrolls on a 390x844 or 360x740
 * phone (tools/check-links.sh measures it in headless Chrome). The hero is
 * the card's board tray, sized against the viewport height (~1/3), never
 * its natural size.
 *
 * Look: the game's own (approved direction 2026-10-17, "carved workbench"):
 * the page wears the game's palette, declared once per game as --cp-* tokens
 * on body[data-game]. Site tokens (tokens.css / site.css) still supply the
 * type stack, radii, tap floor and focus ring. No new fonts.
 * ======================================================================== */

/* ---- per-game palettes -------------------------------------------------- */
body.cp-body {
  /* Fox & Hare is the default: maple to walnut planks, cream card, rust CTA. */
  --cp-plank-1: #a8743f;
  --cp-plank-2: #8a5a30;
  --cp-plank-3: #6b4423;
  --cp-plank-line: rgba(43, 24, 10, 0.45);
  --cp-plaque: #d9a86b;
  --cp-plaque-edge: #a8743f;
  --cp-plaque-ink: #3a2414;
  --cp-card: #fbf2ed;
  --cp-rim: #6b4423;
  --cp-ink: #3a2414;
  --cp-ink-soft: #7a5a44;
  --cp-tray: #6b4423;
  --cp-tile: #e9d3b4;
  --cp-tile-alt: #dcc29e;
  --cp-brass: #d9a441;
  --cp-primary: #b85c24;
  --cp-primary-under: #7e3c15;
  --cp-primary-ink: #fbf2ed;
  --cp-foot: #fbf2ed;
  --cp-pill: #e6efd9;
  --cp-pill-ink: #3d5a2a;
}
body.cp-body[data-game="backyard-truce"] {
  /* Night garden from its own feature graphic: indigo fence, moon cream,
   * lantern orange. */
  --cp-plank-1: #34327a;
  --cp-plank-2: #2a2866;
  --cp-plank-3: #1d1b4a;
  --cp-plank-line: rgba(10, 8, 30, 0.5);
  --cp-plaque: #f6e7c8;
  --cp-plaque-edge: #d8bf8c;
  --cp-plaque-ink: #2a2350;
  --cp-card: #fbf2ed;
  --cp-rim: #3b3780;
  --cp-ink: #2a2350;
  --cp-ink-soft: #625a8c;
  --cp-tray: #3b3780;
  --cp-tile: #e4f0d6;
  --cp-tile-alt: #d3e6c0;
  --cp-brass: #f2c46b;
  --cp-primary: #e0873a;
  --cp-primary-under: #9c5418;
  --cp-primary-ink: #2a1a08;
  --cp-foot: #f6e7c8;
  --cp-pill: #fdebd2;
  --cp-pill-ink: #8a4a12;
}
body.cp-body[data-game="brick-box"] {
  /* Night playroom from its own design tokens (voidcraft-block-puzzle
   * docs/design/design-system/tokens.json): night blues, cream panel, navy
   * ink, green primary (role cta.primary). */
  --cp-plank-1: #3846b0;
  --cp-plank-2: #2f3c9d;
  --cp-plank-3: #26308a;
  --cp-plank-line: rgba(15, 20, 64, 0.45);
  --cp-plaque: #fff4dc;
  --cp-plaque-edge: #b8863e;
  --cp-plaque-ink: #1b2a5b;
  --cp-card: #fff4dc;
  --cp-rim: #0f1440;
  --cp-ink: #1b2a5b;
  --cp-ink-soft: #5b6690;
  --cp-tray: #12163f;
  --cp-tile: #4352b8;
  --cp-tile-alt: #3846b0;
  --cp-brass: #ffc52e;
  --cp-primary: #4cd137;
  --cp-primary-under: #1b6b14;
  --cp-primary-ink: #0b3a07;
  --cp-foot: #fff4dc;
  --cp-pill: #efd6a3;
  --cp-pill-ink: #1b2a5b;
}

/* ---- ground ------------------------------------------------------------- */
body.cp-body {
  color: var(--cp-ink);
  background-color: var(--cp-plank-3);
  /* Vertical planks: three tones, hairline seams. Pure CSS, no image. */
  background-image:
    repeating-linear-gradient(90deg, transparent 0 calc(25% - 2px), var(--cp-plank-line) calc(25% - 2px) 25%),
    linear-gradient(90deg, var(--cp-plank-2) 0 25%, var(--cp-plank-1) 25% 50%, var(--cp-plank-2) 50% 75%, var(--cp-plank-3) 75% 100%);
  background-attachment: fixed;
}
body.cp-body::before,
body.cp-body::after {
  display: none;
}

.cp-wrap {
  flex: 1 0 auto;
  display: flex;
  justify-content: center;
  align-items: stretch;
  gap: clamp(2rem, 5vw, 4rem);
  width: 100%;
  padding: 0 16px;
}

.cp {
  width: 100%;
  max-width: 480px;
  min-height: 100vh; /* engines without dvh */
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto auto auto;
  row-gap: clamp(0.5rem, 1.5dvh, 0.9rem);
  padding: max(clamp(0.6rem, 1.8dvh, 1.1rem), env(safe-area-inset-top)) 0
    max(clamp(0.5rem, 1.4dvh, 0.9rem), env(safe-area-inset-bottom));
}

/* ---- plaque header ------------------------------------------------------ */
.cp__head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.45rem 0.7rem;
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, color-mix(in srgb, var(--cp-plaque) 85%, white), var(--cp-plaque));
  border: 2px solid var(--cp-plaque-edge);
  box-shadow: 0 4px 0 var(--cp-plaque-edge), 0 10px 22px rgba(0, 0, 0, 0.3);
  color: var(--cp-plaque-ink);
}
.cp__icon {
  width: 40px;
  height: 40px;
  border-radius: 22.5%;
  flex: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}
.cp__title {
  flex: 1;
  min-width: 0;
  text-align: center;
}
.cp__name {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 800;
  line-height: 1.15;
}
.cp__pitch {
  margin: 0;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  line-height: 1.3;
  opacity: 0.75;
}
.cp__head-spacer {
  width: 40px;
  flex: none;
}

/* ---- the card ----------------------------------------------------------- */
.cp__card {
  align-self: center;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding: 0.8rem 0.85rem 0.9rem;
  border-radius: var(--radius-xl, 28px);
  background: var(--cp-card);
  border: 3px solid var(--cp-rim);
  box-shadow: 0 6px 0 color-mix(in srgb, var(--cp-rim) 70%, black), 0 18px 36px rgba(0, 0, 0, 0.35);
  min-height: 0;
}
.cp__who {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding-bottom: 0.45rem;
  border-bottom: 1px solid color-mix(in srgb, var(--cp-rim) 18%, transparent);
}
.cp__who[hidden],
.cp__id[hidden],
.cp__record[hidden],
.cp__expires[hidden] {
  display: none;
}
/* Brass medallion: the challenger's avatar slot (backend read fills it). */
.cp__avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--cp-tone, var(--cp-brass)) 60%, white), var(--cp-tone, var(--cp-brass)) 60%, color-mix(in srgb, var(--cp-tone, var(--cp-brass)) 65%, black));
  border: 2px solid color-mix(in srgb, var(--cp-tone, var(--cp-brass)) 60%, black);
  color: var(--cp-ink);
  font-weight: 800;
  font-size: 0.9rem;
}
.cp__who-text {
  flex: 1;
  min-width: 0;
}
.cp__kicker {
  margin: 0;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--cp-ink-soft);
  line-height: 1.2;
}
.cp__challenger {
  margin: 0;
  font-weight: 800;
  line-height: 1.2;
  color: var(--cp-ink);
}
.cp__record {
  flex: none;
  padding: 0.15rem 0.6rem;
  border-radius: var(--radius-pill);
  background: var(--cp-pill);
  color: var(--cp-pill-ink);
  font-size: 0.75rem;
  font-weight: 700;
}
.cp__line {
  margin: 0;
  text-align: center;
  font-size: clamp(1.1rem, 2.9dvh, 1.45rem);
  font-weight: 800;
  line-height: 1.2;
  color: var(--cp-ink);
}
.cp__sub {
  margin: 0;
  text-align: center;
  font-size: 0.85rem;
  line-height: 1.3;
  color: var(--cp-ink-soft);
}
/* The board tray: the hero. Square, ~1/3 of the viewport height, capped by
 * the card width. Decorative — the page cannot know the challenge's board. */
.cp__tray {
  align-self: center;
  height: 36vh;
  height: 36dvh;
  max-height: 100%;
  max-width: 100%;
  aspect-ratio: 1;
  margin: 0.15rem 0;
  padding: 2.5%;
  border-radius: var(--radius-lg);
  background: var(--cp-tray);
  box-shadow: inset 0 3px 8px rgba(0, 0, 0, 0.45), 0 2px 0 rgba(255, 255, 255, 0.4);
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(6, 1fr);
  gap: 2.5%;
}
/* Rush emblem: the tray's box and wood, holding the challenger's count. */
.cp__rush {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  padding: 6%;
  text-align: center;
  color: var(--cp-card);
}
.cp__rush[hidden],
.cp__tray[hidden] {
  display: none;
}
.cp__rush-pieces {
  display: flex;
  gap: 0.4rem;
}
.cp__rush-pieces img {
  width: clamp(36px, 7dvh, 64px);
  height: auto;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.35));
}
.cp__rush-label {
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--cp-brass);
}
.cp__rush-num {
  font-size: clamp(3rem, 11dvh, 5.5rem);
  font-weight: 900;
  line-height: 1;
  color: var(--cp-card);
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
}
.cp__rush-unit {
  font-size: clamp(0.9rem, 2.2dvh, 1.1rem);
  font-weight: 700;
  color: color-mix(in srgb, var(--cp-card) 85%, transparent);
}

.cp__cell {
  display: grid;
  place-items: center;
  border-radius: 18%;
  background: var(--cp-tile);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.12);
  min-width: 0;
  min-height: 0;
}
.cp__cell:nth-child(odd) {
  background: var(--cp-tile-alt);
}
.cp__cell img {
  width: 86%;
  height: 86%;
  object-fit: contain;
}
.cp__id,
.cp__expires {
  margin: 0;
  text-align: center;
  font-size: 0.72rem;
  line-height: 1.2;
  color: var(--cp-ink-soft);
}
.cp__id {
  font-family: var(--font-mono);
}

/* The face's tone: com.voidcraft.ui PlayerSeed tone = (hash / 8) % 8, so the
 * same player wears the same colour here and in the game. Eight warm metals
 * and woodland tints that sit on the cream card; brass is tone 0. */
.cp__avatar[data-tone="0"] { --cp-tone: #d9a441; }
.cp__avatar[data-tone="1"] { --cp-tone: #c8743a; }
.cp__avatar[data-tone="2"] { --cp-tone: #9bb062; }
.cp__avatar[data-tone="3"] { --cp-tone: #74a7c9; }
.cp__avatar[data-tone="4"] { --cp-tone: #a985c0; }
.cp__avatar[data-tone="5"] { --cp-tone: #d9918f; }
.cp__avatar[data-tone="6"] { --cp-tone: #66b3a3; }
.cp__avatar[data-tone="7"] { --cp-tone: #c4a06a; }

/* ---- primary action ----------------------------------------------------- */
.cp__action {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.5rem 0.75rem;
  min-height: 56px;
}
.cp__primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  min-height: 56px;
  padding: 0 1.25rem;
  border-radius: var(--radius-lg);
  background: var(--cp-primary);
  color: var(--cp-primary-ink);
  font-weight: 800;
  font-size: 1.1rem;
  text-decoration: none;
  box-shadow: 0 5px 0 var(--cp-primary-under), 0 12px 24px rgba(0, 0, 0, 0.3);
  transform: translateY(0);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.cp__primary:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--cp-primary-under), 0 6px 12px rgba(0, 0, 0, 0.3);
}
.cp__badge-link {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap-min);
  border-radius: var(--radius-sm);
}
/* Both artworks at the same visible height. Google's PNG carries its own
 * transparent margin (646x250 for a ~564x167 badge), so it is drawn taller
 * and pulled in to match Apple's edge-to-edge SVG. */
.cp__badge {
  display: block;
  width: auto;
  height: 48px;
}
.cp__badge--play {
  height: 72px;
  margin: -12px -10px;
}
.cp__stores .cp__badge {
  height: 40px;
}
.cp__stores .cp__badge--play {
  height: 60px;
  margin: -10px -8px;
}
.cp__status {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 1rem;
  border-radius: var(--radius-pill);
  background: rgba(0, 0, 0, 0.28);
  border: 1px dashed color-mix(in srgb, var(--cp-foot) 55%, transparent);
  color: var(--cp-foot);
  font-size: 0.85rem;
  font-weight: 700;
}

/* ---- store row ---------------------------------------------------------- */
.cp__stores {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.25rem 0.75rem;
  font-size: 0.85rem;
  color: var(--cp-foot);
}
.cp__stores:empty {
  display: none;
}
.cp__stores a {
  color: var(--cp-foot);
  text-underline-offset: 3px;
}

/* ---- footer ------------------------------------------------------------- */
.cp__foot {
  display: flex;
  justify-content: center;
  gap: 1rem;
  font-size: 0.78rem;
  color: var(--cp-foot);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}
.cp__foot a {
  color: var(--cp-foot);
  text-decoration: none;
  opacity: 0.9;
}
.cp__foot a:hover {
  opacity: 1;
  text-decoration: underline;
}

/* A game without a two-piece board shows its landscape picture in the tray's
 * place (render-game-pages.py HERO): same height budget, 16:9 instead of square. */
.cp__hero {
  aspect-ratio: 16 / 9;
  height: auto;
  width: 100%;
  max-height: 36dvh;
  padding: 0;
  display: block;
  overflow: hidden;
}
.cp__hero img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ---- desktop: the game screenshot beside the column, only with room ----- */
.cp-shot {
  display: none;
}
@media (min-width: 900px) {
  .cp-wrap {
    align-items: center;
  }
  .cp-shot {
    display: block;
    flex: none;
    height: min(78vh, 720px);
    width: auto;
    border-radius: var(--radius-2xl, 34px);
    border: 3px solid var(--cp-rim);
    box-shadow: 0 6px 0 color-mix(in srgb, var(--cp-rim) 70%, black), 0 18px 40px rgba(0, 0, 0, 0.4);
  }
}

/* A short landscape phone cannot hold the tray AND the buttons: give the
 * tray less, not the page a scrollbar. */
@media (max-height: 560px) {
  .cp__tray {
    height: 22vh;
    height: 22dvh;
  }
}
