/* Challenge page (challenge.html) — loaded after style.css, only on that
   page, so nothing here can restyle the daily. Bump `?v=N` on its <link>
   when a change must reach players before the 1-week cache expires. */

/* Same fix as Archive/Learn: the bar under the header adds ~64px of
   chrome that the daily's 144px width formula doesn't know about. */
@media (min-width: 768px) {
  body[data-page="challenge"] .section--puzzle {
    max-width: calc((100vh - 208px) * 1.115);
  }
}

/* ── Bar under the header ─────────────────────────────────────────── */
.challenge-bar__head {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.45em;
  min-height: 32px;
  padding: 0 12px;
}
.challenge-bar__title {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1.2;
}
.challenge-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.18em 0.7em;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  white-space: nowrap;
  color: #6d28d9;
  background: #f1e9fe;
  border: 1px solid #d9c6fb;
}
.challenge-pill[hidden] { display: none; }
.challenge-bar__tips a,
.challenge-link {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}
.challenge-bar__tips a:hover,
.challenge-link:hover { text-decoration: underline; }
.challenge-link {
  font: inherit;
  font-weight: 600;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}
@media (max-width: 480px) {
  .challenge-bar__title { font-size: 1.1rem; }
}

/* NOTES pill shares the bottom-left slot with SOLUTION (never both). */
.canvas-hint-btn[hidden] { display: none; }

/* Rules panel: the "Challenge Puzzles are experimental…" blurb above
   every challenge's rules (not on notes pages). */
.challenge-explainer {
  margin: 0 0 0.75rem;
  padding: 0.6rem 0.8rem;
  border-radius: 10px;
  background: #f5f0ff;
  border: 1px solid #d9c6fb;
  color: #4c1d95;
  font-size: 0.86rem;
  line-height: 1.4;
}
.challenge-explainer[hidden] { display: none; }

/* Win card: the ruleset pill sits in the daily's meta row slot. The
   daily's meta styles are uppercase + tracked; keep the pill's own case. */
#puzzle-solved-meta .challenge-pill { text-transform: none; letter-spacing: 0.04em; }

/* "Next challenge: Monday, October 5" under the win card's title. */
.challenge-next {
  margin: 0.2rem 0 0.9rem;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--muted);
  text-align: center;
  white-space: pre-line;   /* the date goes on its own line */
}
.challenge-next[hidden] { display: none; }

/* Notes can run to paragraphs: keep the author's line breaks. */
#intro-body,
.challenge-recap__body { white-space: pre-line; }

/* ── Last week's recap (Rule Recap / Solution Notes) ──────────────── */
/* The daily win card's black ✕ sits in the corner beside the badge;
   the tabs start below it. */
#challenge-recap .hint-modal__scroll { padding-top: 0.15rem; }
.challenge-tabs {
  display: flex;
  gap: 0.35rem;
  margin: 0.55rem 0 0.2rem;
  border-bottom: 1px solid var(--line-soft);
}
.challenge-tab {
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.45em 0.8em;
  margin-bottom: -1px;
  border: 1px solid transparent;
  border-radius: 8px 8px 0 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.challenge-tab[hidden] { display: none; }
.challenge-tab:hover { color: var(--fg); }
.challenge-tab--active {
  color: #6d28d9;
  background: var(--bg);
  border-color: var(--line-soft);
  border-bottom-color: var(--bg);
}
.challenge-recap__art.whatsnew-art { height: min(380px, 52vh); }
.challenge-recap__footer { justify-content: flex-end; }
#challenge-recap .hint-modal__panel {
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
}

.challenge-help {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 0.25rem 0 0.75rem;
}
.challenge-help .toolbar-btn {
  font-size: 0.95rem;
  padding: 0.6em 1em;
}

/* Status message over the empty canvas. */
.challenge-empty {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  font-size: 1rem;
  line-height: 1.4;
  color: var(--muted);
  pointer-events: none;
}
.challenge-empty[hidden] { display: none; }

/* ── Toast (blocked moves, one-time tips) ─────────────────────────── */
.challenge-toast {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  max-width: min(420px, calc(100% - 24px));
  width: max-content;
  padding: 0.5em 0.95em;
  border-radius: 10px;
  background: #fff;
  border: 1px solid var(--line-soft);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.14);
  font-size: 0.85rem;
  line-height: 1.35;
  text-align: center;
  color: var(--fg);
  pointer-events: none;
}
.challenge-toast[hidden] { display: none; }
.challenge-toast[data-kind="error"] {
  border-color: #f3b4ab;
  background: #fff5f3;
  color: #9f1d0f;
}
.challenge-toast[data-kind="tip"] {
  border-color: #b9d2fb;
  background: #f2f7ff;
  color: #174ea6;
}
.challenge-toast--in { animation: challenge-toast-in 180ms ease-out; }
@keyframes challenge-toast-in {
  from { opacity: 0; transform: translate(-50%, -6px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ── Double connections (ruleset double-v1) ───────────────────────── */
/* The face-to-face area between the two bond lines. */
.challenge-double {
  fill: color-mix(in srgb, var(--bond) 12%, transparent);
  stroke: none;
  pointer-events: none;
}
.challenge-double--fresh { animation: challenge-double-in 260ms ease-out; }
@keyframes challenge-double-in {
  from { fill: color-mix(in srgb, var(--accent) 45%, transparent); }
}

/* Blocked tap: the connection flashes red while it stretches and springs
   back (the stretch itself is animated in JS). */
.challenge-bond-blocked {
  stroke: #d93025;
  stroke-width: 5;
  stroke-linecap: round;
  pointer-events: none;
  animation: challenge-blocked-flash 360ms ease-out forwards;
}
@keyframes challenge-blocked-flash {
  0%   { opacity: 0; }
  25%  { opacity: 1; }
  100% { opacity: 0.2; }
}
.challenge-shape--blocked .shape__outline {
  animation: challenge-blame 360ms ease-out;
}
@keyframes challenge-blame {
  30% { stroke: #d93025; stroke-width: 4; }
}

@media (prefers-reduced-motion: reduce) {
  .challenge-toast--in,
  .challenge-double--fresh,
  .challenge-shape--blocked .shape__outline { animation: none; }
  .challenge-bond-blocked { animation: none; opacity: 0.8; }
}

/* The Clean Up bar sets its own display; hide it with no puzzle loaded. */
.canvas-zoom[hidden] { display: none; }

/* ── Rules intro: tap-to-double demo (doubleBond.js#renderIntroDemo) ──
   5s loop on section 1: the single connection is tapped (press disc +
   one ring, a quick tap, not a hold), B's group swings from its single
   pose into the face-to-face double pose, then the second line and the
   fill fade in. The swing's endpoints arrive as --cd-* custom properties
   (CSSOM, CSP-safe) computed from the live snap math, so the art can't
   drift from real play. Section 2 is static.
   Like the long-hold announcement, it runs under reduced motion too:
   the animation IS the explanation. */
#intro-art.whatsnew-art { height: min(380px, 52vh); }

.challenge-demo__caption {
  font-size: 17px;
  font-weight: 700;
  fill: var(--fg);
  text-anchor: middle;
}
.challenge-demo__sum {
  font-size: 16px;
  font-weight: 600;
  fill: var(--muted);
  text-anchor: middle;
}
.challenge-demo__plus {
  font-size: 19px;
  font-weight: 800;
  fill: #6d28d9;
  text-anchor: middle;
  dominant-baseline: central;
}

.challenge-demo__tap { animation: challenge-demo-cycle 5s linear infinite; }
@keyframes challenge-demo-cycle {
  0%        { opacity: 0; }
  4%, 92%   { opacity: 1; }
  98%, 100% { opacity: 0; }
}
.challenge-demo__swing {
  transform-box: view-box;
  transform-origin: 0 0;
  animation: challenge-demo-swing 5s ease-in-out infinite;
}
@keyframes challenge-demo-swing {
  0%, 32% {
    transform: translate(var(--cd-sx), var(--cd-sy)) rotate(var(--cd-rot)) translate(var(--cd-ndx), var(--cd-ndy));
  }
  48%, 100% {
    transform: translate(var(--cd-dx), var(--cd-dy)) rotate(0rad) translate(var(--cd-ndx), var(--cd-ndy));
  }
}
.challenge-demo__early { animation: challenge-demo-early 5s linear infinite; }
@keyframes challenge-demo-early {
  0%, 30%   { opacity: 1; }
  36%, 100% { opacity: 0; }
}
.challenge-demo__late { animation: challenge-demo-late 5s linear infinite; }
@keyframes challenge-demo-late {
  0%, 44%   { opacity: 0; }
  52%, 100% { opacity: 1; }
}
.challenge-demo__press {
  fill: rgba(26, 115, 232, 0.32);
  stroke: rgba(26, 115, 232, 0.6);
  stroke-width: 2;
  opacity: 0;
  transform-box: fill-box;
  transform-origin: center;
  animation: challenge-demo-press 5s ease-in-out infinite;
  pointer-events: none;
}
@keyframes challenge-demo-press {
  0%, 16%   { opacity: 0; transform: scale(1.35); }
  20%       { opacity: 0.85; transform: scale(1); }
  28%       { opacity: 0.85; transform: scale(0.94); }
  34%, 100% { opacity: 0; transform: scale(1.4); }
}
.challenge-demo__ring {
  fill: none;
  stroke: rgba(26, 115, 232, 0.45);
  stroke-width: 3;
  opacity: 0;
  transform-box: fill-box;
  transform-origin: center;
  animation: challenge-demo-ring 5s ease-out infinite;
  pointer-events: none;
}
@keyframes challenge-demo-ring {
  0%, 18%   { opacity: 0; transform: scale(0.5); }
  22%       { opacity: 0.8; }
  36%, 100% { opacity: 0; transform: scale(1.9); }
}

/* Short screens: the rules panel already caps itself at the viewport and
   scrolls its middle (.hint-modal__scroll), keeping Close pinned. But the
   shared cap is 100vh, which on iOS Safari is the LARGE viewport (it
   includes the area under the collapsing toolbars) — so on a short iPhone
   the panel's bottom, Close included, could sit behind Safari's toolbar.
   100dvh is the visible height; the 100vh line is the fallback for
   browsers without dynamic units. Challenge page only. */
#challenge-intro .hint-modal__panel {
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
}
#challenge-intro .hint-modal__scroll {
  overscroll-behavior: contain;   /* don't scroll-chain to the page behind */
}
