/* Molecule challenge and shared result pages.
   The dark panel echoes the share card, so what people see here is what they post. */

.ch { --ch-navy: #0b1b3f; --ch-navy-2: #10285c; --ch-edge: #2b4b8e; --ch-teal: #5fe3e5; --ch-soft: #9fb3e0; --ch-amber: #ffd166; }

/* ---------- top of the page ---------- */
.ch-hero { padding: 64px 0 28px; }
.ch-hero h1 { margin: 0; font-size: clamp(2rem, 4.4vw, 3.2rem); letter-spacing: -0.02em; line-height: 1.08; color: var(--ink, #0b1b3f); }
.ch-lede { margin: 14px 0 0; max-width: 52ch; font-size: 1.12rem; line-height: 1.55; color: var(--muted, #5d6a82); }
.ch-beat { display: inline-flex; align-items: center; gap: 8px; margin: 18px 0 0; padding: 8px 14px; border-radius: 999px; background: #fff4d6; color: #7a4a06; font-weight: 600; }
.ch-beat svg { width: 18px; height: 18px; }

/* ---------- editor and panel ---------- */
.ch-play { padding: 8px 0 56px; }
.ch-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(330px, 0.95fr); gap: 28px; align-items: start; }

.ch-frame { position: relative; height: 580px; border: 1px solid var(--line, #e2e8f1); border-radius: 18px; overflow: hidden; background: #fff; }
.ch-frame iframe { display: block; width: 100%; height: 100%; border: 0; }
.ch-frame-load { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; color: var(--muted, #5d6a82); background: #fff; pointer-events: none; }
.ch-frame-load[hidden] { display: none; }

.ch-starters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 14px; }
.ch-starters > span { margin-right: 4px; font-size: 0.9rem; color: var(--muted, #5d6a82); }

.ch-chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; font: inherit; font-size: 0.9rem; font-weight: 600;
  color: var(--ink, #0b1b3f); background: #fff; border: 1px solid var(--line-2, #cfd8e6); border-radius: 999px; cursor: pointer; text-decoration: none;
}
.ch-chip:hover { border-color: var(--brand, #1a4dd8); color: var(--brand, #1a4dd8); }
.ch-chip:focus-visible, .ch-share-main:focus-visible, .ch-submit-btn:focus-visible { outline: 3px solid #5b8cff; outline-offset: 2px; }
.ch-chip-quiet { font-weight: 500; color: var(--muted, #5d6a82); }
.ch-chip svg { width: 16px; height: 16px; flex: none; }

.ch-panel {
  position: sticky; top: 84px; max-height: calc(100vh - 100px); overflow-y: auto; padding: 20px; color: #fff; border: 1px solid var(--ch-edge); border-radius: 24px;
  background: radial-gradient(120% 80% at 80% 0%, rgba(19, 196, 198, 0.16), transparent 60%), linear-gradient(180deg, var(--ch-navy), var(--ch-navy-2));
  box-shadow: 0 24px 60px rgba(8, 21, 47, 0.28);
}
.ch-panel[hidden], .ch-panel [hidden] { display: none !important; }

/* ---------- the score ring ---------- */
.ch-gauge { position: relative; width: 132px; margin: 0 auto 2px; }
.ch-ring { display: block; width: 100%; transform: rotate(-90deg); overflow: visible; }
.ch-ring circle { fill: none; stroke-width: 10; }
.ch-ring-track { stroke: rgba(255, 255, 255, 0.14); }
.ch-ring-fill { stroke: url(#chGrad); stroke-linecap: round; transition: stroke-dashoffset 0.6s cubic-bezier(.2, .8, .2, 1); }
.ch-ring-beat { stroke: var(--ch-amber); stroke-width: 4; stroke-linecap: round; }
.ch-gauge-num { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ch-gauge-num strong { font-size: 2.55rem; line-height: 1; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.ch-gauge-num span { margin-top: 4px; font-size: 0.8rem; color: var(--ch-soft); }

.ch-status { min-height: 2.6em; margin: 4px 0 10px; font-size: 0.95rem; text-align: center; line-height: 1.4; color: #dbe6ff; }
.ch-status.is-error { color: #ffb4a3; }
.ch-status.is-win { color: var(--ch-teal); font-weight: 600; }

/* ---------- the five rules ---------- */
.ch-rows { display: grid; gap: 4px; margin: 0; padding: 0; list-style: none; }
.ch-rows li { display: grid; grid-template-columns: 22px 1fr auto; column-gap: 10px; align-items: start; padding: 7px 0; border-top: 1px solid rgba(255, 255, 255, 0.09); }
.ch-rows li:first-child { border-top: 0; }
.ch-tick { font-weight: 800; line-height: 1.3; text-align: center; }
.is-met .ch-tick { color: var(--ch-teal); }
.is-short .ch-tick { color: var(--ch-amber); font-size: 1.4rem; line-height: 1; }
.ch-row-main { display: grid; gap: 2px; min-width: 0; }
.ch-row-top { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; }
.ch-row-label { font-weight: 650; }
.ch-row-value { font-size: 0.82rem; color: var(--ch-soft); }
.ch-row-hint { font-size: 0.82rem; line-height: 1.35; color: var(--ch-amber); }
.ch-row-pts { font-size: 0.86rem; font-variant-numeric: tabular-nums; color: #dbe6ff; }
.ch-row-bar { grid-column: 2 / 4; height: 3px; margin-top: 5px; background: rgba(255, 255, 255, 0.1); border-radius: 4px; overflow: hidden; }
.ch-row-bar i { display: block; height: 100%; background: linear-gradient(90deg, #2fe0d4, #5b8cff); border-radius: 4px; transition: width 0.5s ease; }
.ch-formula { margin: 8px 0 0; text-align: center; font-size: 0.9rem; color: var(--ch-soft); min-height: 1.3em; }

/* ---------- submit ---------- */
.ch-submit { display: grid; gap: 8px; margin: 0 0 14px; }
.ch-submit.has-name { grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); align-items: end; }
.ch-submit .ch-signin { grid-column: 1 / -1; text-align: center; }
.ch-name { display: grid; gap: 6px; font-size: 0.85rem; color: var(--ch-soft); }
.ch-name select {
  width: 100%; padding: 12px 10px; font: inherit; color: #fff; background: #0e2350; border: 1px solid var(--ch-edge); border-radius: 10px;
}
.ch-signin { margin: 0; font-size: 0.88rem; color: var(--ch-soft); }
.ch-signin a { color: var(--ch-teal); font-weight: 600; }
.ch-submit-btn {
  padding: 14px 18px; font: inherit; font-weight: 750; color: #06122b; background: linear-gradient(90deg, #2fe0d4, #5b8cff);
  border: 0; border-radius: 12px; cursor: pointer; transition: transform 0.15s ease, filter 0.15s ease;
}
.ch-submit-btn:hover:not(:disabled) { filter: brightness(1.06); transform: translateY(-1px); }
.ch-submit-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.ch-fineprint { margin: 8px 0 0; font-size: 0.78rem; line-height: 1.45; text-align: center; color: var(--ch-soft); }
.ch-best { margin: 8px 0 0; text-align: center; font-size: 0.85rem; color: var(--ch-teal); }

/* ---------- result and sharing ---------- */
.ch-result-title { margin: 0 0 12px; font-size: 1.15rem; font-weight: 750; text-align: center; }
.ch-card-img { display: block; width: 100%; height: auto; aspect-ratio: 1200 / 630; border-radius: 12px; background: rgba(255, 255, 255, 0.06); border: 1px solid var(--ch-edge); }
.ch-card-img.is-loading { animation: ch-pulse 1.2s ease-in-out infinite; }
@keyframes ch-pulse { 50% { opacity: 0.55; } }
.ch-rank { margin: 12px 0 0; text-align: center; color: var(--ch-teal); font-weight: 600; }

.ch-share { display: grid; gap: 12px; margin-top: 16px; }
.ch-share-main {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px; padding: 15px 18px; font: inherit; font-size: 1.05rem; font-weight: 750;
  color: #06122b; background: linear-gradient(90deg, #2fe0d4, #5b8cff); border: 0; border-radius: 14px; cursor: pointer;
}
.ch-share-main svg { width: 20px; height: 20px; }
.ch-share-main:hover { filter: brightness(1.06); }
.ch-share-row { display: flex; flex-wrap: wrap; gap: 8px; }
.ch-share .ch-chip, .ch-hero-dark .ch-chip { color: #e9f0ff; background: rgba(255, 255, 255, 0.07); border-color: rgba(255, 255, 255, 0.22); }
.ch-share .ch-chip:hover, .ch-hero-dark .ch-chip:hover { color: #fff; border-color: var(--ch-teal); background: rgba(95, 227, 229, 0.12); }
.ch-share .ch-chip-quiet { color: var(--ch-soft); }
.ch-share-note { min-height: 1.2em; margin: 0; text-align: center; font-size: 0.85rem; color: var(--ch-teal); }
.ch-again { width: 100%; margin-top: 8px; color: #e9f0ff; background: transparent; border: 1px solid rgba(255, 255, 255, 0.25); border-radius: 12px; padding: 12px; font: inherit; font-weight: 600; cursor: pointer; }
.ch-again:hover { border-color: var(--ch-teal); }

/* ---------- leaderboard ---------- */
.ch-boardwrap { padding: 56px 0; background: var(--canvas, #f4f7fb); }
.ch-board-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px 24px; margin-bottom: 22px; }
.ch-board-head h2 { margin: 0; font-size: 1.6rem; }
.ch-board-head p { margin: 0; color: var(--muted, #5d6a82); }
.ch-board-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr)); gap: 12px; margin: 0; padding: 0; list-style: none; }
.ch-board-list li { display: grid; grid-template-columns: 28px 120px 1fr auto; align-items: center; gap: 14px; padding: 10px 16px 10px 14px; background: #fff; border: 1px solid var(--line, #e2e8f1); border-radius: 16px; }
.ch-rank-no { font-weight: 800; color: var(--muted, #5d6a82); text-align: center; }
.ch-board-list li:nth-child(-n+3) .ch-rank-no { color: #c98a0a; }
.ch-thumb { display: block; height: 70px; border-radius: 10px; background: #f7f9fd; }
.ch-thumb svg { display: block; width: 100%; height: 100%; }
.ch-board-name { font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.ch-board-score { font-size: 1.5rem; font-variant-numeric: tabular-nums; color: var(--ink, #0b1b3f); }
.ch-ownrank { margin: 16px 0 0; font-weight: 600; }
.ch-empty { margin: 0; color: var(--muted, #5d6a82); }

/* ---------- rules ---------- */
.ch-rules { padding: 32px 0 72px; }
.ch-rules details { max-width: 70ch; }
.ch-rules summary { cursor: pointer; font-weight: 700; font-size: 1.05rem; }
.ch-rules p, .ch-rules li { line-height: 1.6; color: var(--ink-2, #33415c); }
.ch-h2 { margin: 0 0 14px; font-size: 1.5rem; }
.ch-more { margin-top: 18px; }
.ch-more a { color: var(--brand, #1a4dd8); font-weight: 600; }

/* ---------- shared result page ---------- */
.ch-hero-dark { padding: 56px 0; color: #fff; background: radial-gradient(90% 90% at 80% 0%, rgba(19, 196, 198, 0.2), transparent 60%), linear-gradient(180deg, var(--ch-navy), var(--ch-navy-2)); }
.ch-hero-dark h1 { color: #fff; }
.ch-result-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(300px, 1fr); gap: 36px; align-items: center; }
.ch-result-card img { display: block; width: 100%; height: auto; border-radius: 18px; border: 1px solid var(--ch-edge); box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35); }
.ch-result-by { margin: 0; color: var(--ch-soft); }
.ch-hero-dark h1 { margin: 6px 0 4px; font-size: clamp(3.2rem, 8vw, 5.5rem); line-height: 1; }
.ch-hero-dark h1 span { font-size: 0.34em; margin-left: 6px; color: var(--ch-soft); font-weight: 600; }
.ch-result-stats { margin: 0 0 18px; color: var(--ch-soft); }
.ch-cta { display: inline-flex; align-items: center; gap: 8px; }
.ch-cta svg { width: 18px; height: 18px; }
.ch-rows-static li { grid-template-columns: 22px 1fr auto auto; max-width: 560px; border-top-color: var(--line, #e2e8f1); }
.ch-rows-static .ch-row-label { font-weight: 650; }
.ch-rows-static .ch-row-value, .ch-rows-static .ch-row-pts { color: var(--muted, #5d6a82); }
.ch-rows-static .is-met .ch-tick { color: #0e9fa2; }
.ch-rows-static .is-short .ch-tick { color: #a2610a; }
.ch-rows-static .ch-row-main { display: contents; }

/* ---------- small screens ---------- */
@media (max-width: 900px) {
  .ch-grid, .ch-result-grid { grid-template-columns: 1fr; }
  .ch-panel { position: static; max-height: none; overflow: visible; }
  .ch-frame { height: 440px; }
  .ch-hero { padding-top: 40px; }
}
@media (max-width: 520px) {
  .ch-board-list li { grid-template-columns: 24px 96px 1fr auto; gap: 10px; }
  .ch-rows-static li { grid-template-columns: 22px 1fr auto; }
  .ch-rows-static .ch-row-value { grid-column: 2; }
}
@media (prefers-reduced-motion: reduce) {
  .ch-ring-fill, .ch-row-bar i, .ch-submit-btn { transition: none; }
  .ch-card-img.is-loading { animation: none; }
}
