/* v1.2.0 challenge mode: start-screen entry, level picker, problems, rank badge, confetti.
 * Loaded after styles.css and reuses its tokens (--surface, --text, --accent ...). */
:root {
  --gold-1: #fff3c4; --gold-2: #f2c94c; --gold-3: #8a6100; --gold-ink: #3b2a00;
  --ok: #1f7a3a; --ok-soft: #e3f6e8; --no: #b42335; --no-soft: #fde7ea;
  --hint-bg: #fff8e1; --hint-border: #c99a2e;
  --aha-bg: #fffaf0; --paper-bg: #f3f6ff;
}
@media (prefers-color-scheme: dark) {
  :root {
    --gold-3: #f2c94c; --gold-ink: #2a1d00;
    --ok: #6fdd8b; --ok-soft: #173524; --no: #ff8a9a; --no-soft: #3d1c24;
    --hint-bg: #2c2615; --hint-border: #8a7230;
    --aha-bg: #262011; --paper-bg: #1a2238;
  }
}

/* start-screen entry */
.ch-entry {
  margin-top: 18px; padding: 18px 18px 16px; border-radius: 14px;
  background: linear-gradient(135deg, rgba(242, 201, 76, .16), rgba(36, 67, 184, .08));
  border: 2px solid var(--gold-2);
}
.ch-entry-eyebrow { margin: 0; font-size: 14px; font-weight: 800; letter-spacing: .03em; color: var(--gold-3); }
.ch-entry-title { margin: 4px 0 6px; font-size: 20px; line-height: 1.35; }
.ch-entry-desc { margin: 0 0 14px; color: var(--muted); font-size: 15px; }
.ch-entry-btn {
  background: linear-gradient(180deg, #ffe48a, #f2c94c 55%, #d9a520); border-color: #b8860b; color: var(--gold-ink);
  position: relative; overflow: hidden;
}
.ch-entry-btn:hover { border-color: #8a6100; filter: brightness(1.04); }
.ch-entry-btn::after {
  content: ""; position: absolute; top: 0; bottom: 0; left: -40%; width: 30%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .7), transparent);
  transform: skewX(-20deg); animation: chShine 3.2s ease-in-out 1s infinite;
}
@keyframes chShine { 0% { left: -40%; } 55%, 100% { left: 130%; } }

/* level picker */
.cg-grid { list-style: none; padding: 0; margin: 4px 0 14px; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.cg-btn {
  width: 100%; display: flex; align-items: center; gap: 12px; text-align: left;
  font: inherit; color: var(--text); background: var(--surface); cursor: pointer;
  border: 1px solid var(--border); border-left: 6px solid var(--c); border-radius: 12px; padding: 10px 12px; min-height: 64px;
}
.cg-btn:hover { border-color: var(--c); box-shadow: 0 2px 10px rgba(0, 0, 0, .12); }
@media (prefers-color-scheme: dark) { .cg-btn { border-left-color: var(--c2); } .cg-btn:hover { border-color: var(--c2); } }
.cg-icon { flex: none; display: flex; }
.cg-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.35; }
.cg-short { font-weight: 800; font-size: 17px; }
.cg-name { font-size: 14px; color: var(--muted); }
.cg-corps { font-size: 14px; font-weight: 600; }
.cg-best { margin-top: 2px; font-size: 13px; font-weight: 700; color: var(--gold-3); }

/* problem */
.cp-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.cp-chip { display: inline-flex; align-items: center; gap: 6px; background: var(--c); color: #fff; font-weight: 700; font-size: 14px; border-radius: 999px; padding: 3px 12px 3px 4px; max-width: 100%; }
.cp-chip-icon { display: flex; flex: none; }
@media (prefers-color-scheme: dark) { .cp-chip { box-shadow: inset 0 0 0 1.5px var(--c2); } }
.cp-count { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.cp-progress .progress-fill { background: var(--c); }
@media (prefers-color-scheme: dark) { .cp-progress .progress-fill { background: var(--c2); } }
.cp-field { margin: 14px 0 4px; font-size: 13px; font-weight: 800; letter-spacing: .05em; color: var(--muted); text-transform: uppercase; }
.cp-title { margin-bottom: 8px; }
.cp-prompt { font-size: 17px; line-height: 1.75; margin: 0 0 16px; }
.cp-form { margin: 0; }
.cp-label { display: block; font-weight: 700; margin-bottom: 6px; }
.cp-input-row { display: flex; align-items: center; gap: 10px; }
.cp-input {
  font: inherit; font-size: 20px; font-weight: 700; width: 100%; max-width: 240px; min-height: 48px; min-width: 0;
  padding: 8px 12px; border-radius: 10px; border: 2px solid var(--border); background: var(--surface-2); color: var(--text);
}
.cp-input:focus { border-color: var(--accent); }
.cp-unit { font-size: 17px; font-weight: 700; color: var(--muted); flex: none; }
.cp-help { font-size: 14px; color: var(--muted); margin: 6px 0 0; }
.cp-choices { border: 0; padding: 0; margin: 0; display: grid; gap: 8px; min-width: 0; }
.cp-legend { font-weight: 700; margin-bottom: 6px; padding: 0; }
.cp-choice {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; min-height: 48px;
  border: 2px solid var(--border); border-radius: 12px; background: var(--surface); cursor: pointer;
}
.cp-choice input { width: 20px; height: 20px; flex: none; margin: 0; accent-color: var(--c); }
.cp-choice-mark { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 14px; background: var(--surface-2); }
.cp-choice-text { min-width: 0; }
.cp-choice:hover { border-color: var(--c); }
.cp-choice:has(input:checked) { border-color: var(--c); background: var(--surface-2); }
@media (prefers-color-scheme: dark) {
  .cp-choice:hover, .cp-choice:has(input:checked) { border-color: var(--c2); }
  .cp-choice input { accent-color: var(--c2); }
}
.cp-choice:has(input:disabled) { cursor: default; }
.cp-hint { margin-top: 12px; padding: 12px 14px; border-radius: 10px; background: var(--hint-bg); border: 1px dashed var(--hint-border); }
.cp-hint-label { margin-right: 4px; }
.cp-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.cp-actions .btn.primary { background: var(--c); border-color: var(--c); color: #fff; }
@media (prefers-color-scheme: dark) { .cp-actions .btn.primary { background: var(--c2); border-color: var(--c2); color: #0e131c; } }
.cp-status { min-height: 1.4em; margin: 10px 0 0; font-size: 15px; font-weight: 600; }
.cp-reveal { margin-top: 6px; }
.cp-verdict { font-size: 20px; margin: 4px 0 6px; padding: 10px 14px; border-radius: 10px; }
.cp-verdict.ok { color: var(--ok); background: var(--ok-soft); }
.cp-verdict.no { color: var(--no); background: var(--no-soft); }
.cp-your { margin: 0 0 4px; color: var(--muted); font-size: 15px; }
.aha-card { background: var(--aha-bg); border: 2px solid var(--gold-2); }
.aha-h, .paper-h { display: flex; align-items: center; gap: 8px; }
.aha-h .ico { color: var(--gold-3); flex: none; }
.card .aha-line { font-size: 18px; font-weight: 700; line-height: 1.6; margin: 0 0 10px; }
.sol-h { margin: 8px 0 4px; font-size: 15px; color: var(--muted); }
.sol { line-height: 1.7; }
.paper-card { background: var(--paper-bg); border-left: 6px solid var(--accent); }
.paper-h .ico { color: var(--accent); flex: none; }
.card .paper-skill { display: inline-block; margin: 0 0 8px; padding: 3px 12px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 14px; }
.cp-origin a { color: var(--accent); }
.cp-reveal .btn-row { margin-top: 16px; }

/* result */
.cr-title { font-size: 24px; margin-bottom: 6px; }
.cr-live { margin: 0 0 12px; color: var(--muted); }
.cr-badge-wrap { position: relative; display: flex; justify-content: center; margin: 6px 0 14px; }
.cr-badge { width: 100%; max-width: 340px; line-height: 0; position: relative; z-index: 1; }
.cr-badge svg { width: 100%; height: auto; display: block; filter: drop-shadow(0 10px 24px rgba(0, 0, 0, .35)); }
.is-marshal .cr-title {
  background: linear-gradient(90deg, #8a6100, #c99a2e, #8a6100, #c99a2e, #8a6100); -webkit-background-clip: text; background-clip: text;
  color: transparent; background-size: 200% 100%; animation: goldText 4s linear infinite;
}
@media (prefers-color-scheme: dark) { .is-marshal .cr-title { background-image: linear-gradient(90deg, #f2c94c, #fff3c4, #ffd43b, #fff3c4, #f2c94c); } }
@keyframes goldText { from { background-position: 0% 0; } to { background-position: 200% 0; } }
.is-marshal .cr-badge-wrap::before {
  content: ""; position: absolute; left: 50%; top: 50%; width: 120%; max-width: 460px; aspect-ratio: 1; transform: translate(-50%, -50%);
  background: radial-gradient(circle, rgba(255, 214, 102, .55), rgba(255, 214, 102, 0) 65%); animation: glowPulse 2.6s ease-in-out infinite;
}
@keyframes glowPulse { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }
.cr-actions { justify-content: center; }
@media (max-width: 480px) { .cr-actions .btn { flex: 1 1 100%; } }
.cr-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.cr-list li { display: flex; gap: 10px; align-items: flex-start; background: var(--surface-2); border-radius: 10px; padding: 8px 10px; }
.cr-mark { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 14px; color: #fff; }
.cr-list li.ok .cr-mark { background: var(--ok); }
.cr-list li.no .cr-mark { background: var(--no); }
@media (prefers-color-scheme: dark) { .cr-mark { color: #0e131c; } }
.cr-body { display: flex; flex-direction: column; min-width: 0; }
.cr-meta { font-size: 14px; color: var(--muted); }
.cr-ladder-box summary { cursor: pointer; font-weight: 700; min-height: 32px; }
.cr-ladder { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 4px; }
.cr-ladder li { display: flex; gap: 8px; align-items: center; justify-content: space-between; padding: 6px 10px; border-radius: 8px; background: var(--surface-2); font-size: 14px; flex-wrap: wrap; }
.cr-ladder li.me { outline: 2px solid var(--gold-2); font-weight: 800; }
.lad-name { flex: 1 1 auto; min-width: 0; }
.lad-min { color: var(--muted); font-variant-numeric: tabular-nums; }
.lad-you { background: var(--gold-2); color: var(--gold-ink); border-radius: 999px; padding: 0 8px; font-size: 13px; font-weight: 800; }

/* badge animation hooks (classes inside the inline SVG from badge.js) */
.bdg .bdg-shine { animation: bdgShine 3.8s ease-in-out .9s infinite; }
@keyframes bdgShine { 0% { transform: translateX(-220px); } 55%, 100% { transform: translateX(420px); } }
.bdg .bdg-rays { animation: bdgSpin 30s linear infinite; }
.bdg .bdg-rays2 { animation: bdgSpin 16s linear infinite reverse; }
@keyframes bdgSpin { to { transform: rotate(360deg); } }
.bdg .bdg-laurel { animation: bdgBreathe 2.6s ease-in-out infinite; }
@keyframes bdgBreathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.035); } }
.bdg .bdg-spark { animation: bdgTwinkle 1.9s ease-in-out infinite; }
@keyframes bdgTwinkle { 0%, 100% { opacity: .25; transform: scale(.6); } 50% { opacity: 1; transform: scale(1.15); } }
.bdg .bdg-pop { transform-box: fill-box; transform-origin: center; animation: bdgPop .75s cubic-bezier(.2, 1.6, .4, 1) both; }
@keyframes bdgPop { from { opacity: 0; transform: scale(.25); } to { opacity: 1; transform: scale(1); } }

/* confetti for the marshal reveal */
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 50; }
.confetti[hidden] { display: none; }
.confetti .cf { position: absolute; top: -24px; width: 8px; height: 14px; border-radius: 2px; opacity: .95; animation-name: cfFall; animation-timing-function: cubic-bezier(.3, .6, .6, 1); animation-fill-mode: forwards; }
.confetti .cf-round { width: 10px; height: 10px; border-radius: 50%; }
@keyframes cfFall { 0% { transform: translate(0, 0) rotate(0); } 100% { transform: translate(var(--dx), 112vh) rotate(var(--rot)); opacity: .9; } }

@media (prefers-reduced-motion: reduce) {
  .ch-entry-btn::after { animation: none; display: none; }
  .bdg .bdg-shine { animation: none; display: none; }
  .bdg .bdg-rays, .bdg .bdg-rays2, .bdg .bdg-laurel, .bdg .bdg-spark, .bdg .bdg-pop { animation: none; }
  .is-marshal .cr-title, .is-marshal .cr-badge-wrap::before { animation: none; }
  .confetti { display: none; }
}
