/* Collection quiz widget: the playable deck embedded in a topic page.
   Colours come from the token palette so both themes are covered by design-tokens.css.
   The per-game accent (--cq-accent, set inline on the mount) is used only for the top rule and a
   background tint, never behind text: the six game accents include very light greens and blues
   that cannot carry white text at 4.5:1. */

.cq-mount {
    /* Reserve the height the widget will occupy. The card is injected by script after first
       paint, and without this the article below it shifts (the CLS lesson from v2.14.1). */
    min-height: 430px;
    margin: var(--space-6) 0 var(--space-8);
}

.cq-card {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--neutral-200);
    border-radius: var(--radius-2xl);
    box-shadow: var(--shadow-md);
    padding: var(--space-6);
    overflow: hidden;
}

.cq-card::before {
    content: "";
    position: absolute;
    inset: 0 0 auto 0;
    height: 4px;
    background: var(--cq-accent, var(--primary-500));
}

.cq-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: var(--space-3);
    font-size: var(--text-sm);
    font-weight: var(--font-semibold);
    color: var(--on-surface-muted);
    letter-spacing: var(--tracking-wide);
    text-transform: uppercase;
}

.cq-bar {
    height: 4px;
    border-radius: var(--radius-full);
    background: var(--neutral-200);
    margin: var(--space-3) 0 var(--space-5);
    overflow: hidden;
}

.cq-bar > span {
    display: block;
    height: 100%;
    border-radius: var(--radius-full);
    background: var(--primary-500);
    transition: width var(--transition-slow) ease;
}

.cq-question {
    font-size: var(--text-xl);
    line-height: var(--leading-normal);
    font-weight: var(--font-semibold);
    color: var(--on-surface);
    margin: 0 0 var(--space-5);
}

.cq-ask {
    display: block;
    margin-top: var(--space-2);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    text-transform: uppercase;
    letter-spacing: var(--tracking-wide);
    color: var(--on-surface-muted);
}

.cq-options {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-3);
}

.cq-option {
    min-height: 56px;
    padding: var(--space-3) var(--space-4);
    font: inherit;
    font-size: var(--text-base);
    font-weight: var(--font-medium);
    text-align: left;
    color: var(--on-surface);
    background: var(--surface-variant);
    border: 2px solid var(--neutral-200);
    border-radius: var(--radius-xl);
    cursor: pointer;
    transition: border-color var(--transition-fast) ease,
                background var(--transition-fast) ease,
                transform var(--transition-fast) ease;
}

.cq-option:hover:not(:disabled) {
    border-color: var(--primary-500);
    background: var(--surface);
}

.cq-option:focus-visible {
    outline: 3px solid var(--primary-600);
    outline-offset: 2px;
}

.cq-option:disabled {
    cursor: default;
    opacity: 1;
}

.cq-option.is-correct {
    border-color: var(--success-500);
    background: rgba(16, 185, 129, 0.14); /* fallback where color-mix is unsupported */
    background: color-mix(in srgb, var(--success-500) 14%, var(--surface));
}

.cq-option.is-wrong {
    border-color: var(--error-500);
    background: rgba(239, 68, 68, 0.12);
    background: color-mix(in srgb, var(--error-500) 12%, var(--surface));
}

.cq-feedback {
    margin: var(--space-5) 0 0;
    font-size: var(--text-base);
    line-height: var(--leading-relaxed);
    color: var(--on-surface-variant);
    min-height: 1.75em;
}

.cq-feedback:empty {
    margin-top: 0;
}

.cq-verdict {
    font-weight: var(--font-bold);
}

.cq-feedback.is-correct .cq-verdict { color: var(--success-500); }
.cq-feedback.is-wrong .cq-verdict { color: var(--error-500); }

.cq-next,
.cq-again {
    margin-top: var(--space-5);
    min-height: 48px;
    padding: var(--space-3) var(--space-8);
    font: inherit;
    font-weight: var(--font-semibold);
    color: #ffffff;
    background: linear-gradient(135deg, var(--primary-600) 0%, var(--secondary-600) 100%);
    border: none;
    border-radius: var(--radius-full);
    cursor: pointer;
    box-shadow: var(--shadow-primary);
}

.cq-next:focus-visible,
.cq-again:focus-visible {
    outline: 3px solid var(--primary-700);
    outline-offset: 3px;
}

/* Dark mode: white on the dark theme's lighter primary fails contrast, so the filled button
   flips to a light container with dark text, the same treatment as the game buttons in v2.13.0. */
body.dark-mode .cq-next,
body.dark-mode .cq-again {
    background: linear-gradient(135deg, #818cf8 0%, #a5b4fc 100%);
    color: #171a3a;
}

/* ----- result state ----- */

.cq-done {
    text-align: center;
    background: var(--surface);
    background:
        radial-gradient(120% 90% at 50% 0%,
            color-mix(in srgb, var(--cq-accent, var(--primary-500)) 12%, transparent) 0%,
            transparent 70%),
        var(--surface);
}

.cq-result-score {
    margin: var(--space-4) 0 var(--space-2);
    font-size: var(--text-5xl);
    font-weight: var(--font-bold);
    line-height: 1;
    color: var(--on-surface);
}

.cq-result-score span {
    font-size: var(--text-2xl);
    font-weight: var(--font-medium);
    color: var(--on-surface-muted);
}

.cq-result-line {
    margin: 0 0 var(--space-6);
    font-size: var(--text-lg);
    color: var(--on-surface-variant);
}

.cq-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    justify-content: center;
    align-items: center;
}

.cq-actions .cq-again { margin-top: 0; }

.cq-cta {
    min-height: 48px;
    display: inline-flex;
    align-items: center;
    padding: var(--space-3) var(--space-6);
    font-weight: var(--font-semibold);
    color: var(--primary-700);
    background: rgba(99, 102, 241, 0.12);
    background: color-mix(in srgb, var(--primary-500) 12%, var(--surface));
    border-radius: var(--radius-full);
    text-decoration: none;
}

.cq-cta:hover { background: rgba(99, 102, 241, 0.20); background: color-mix(in srgb, var(--primary-500) 20%, var(--surface)); }

body.dark-mode .cq-cta {
    color: #c7ccff;
    background: rgba(129, 140, 248, 0.22);
    background: color-mix(in srgb, var(--primary-500) 22%, var(--surface));
}

.cq-note {
    margin: var(--space-6) 0 0;
    font-size: var(--text-sm);
    color: var(--on-surface-muted);
}

.cq-fallback {
    text-align: center;
    color: var(--on-surface-variant);
}

/* ----- the strip of sibling collections ----- */

.cq-siblings {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: var(--space-3);
    padding: 0;
    margin: var(--space-4) 0 0;
    list-style: none;
}

.cq-siblings a {
    display: block;
    height: 100%;
    padding: var(--space-4);
    background: var(--surface-variant);
    border: 1px solid var(--neutral-200);
    border-radius: var(--radius-lg);
    color: var(--on-surface);
    font-weight: var(--font-semibold);
    text-decoration: none;
    transition: border-color var(--transition-fast) ease;
}

.cq-siblings a:hover { border-color: var(--primary-500); }

.cq-siblings .cq-sib-blurb {
    display: block;
    margin-top: var(--space-1);
    font-size: var(--text-sm);
    font-weight: var(--font-regular);
    color: var(--on-surface-muted);
}

@media (max-width: 768px) {
    .cq-mount { min-height: 470px; }
    .cq-card { padding: var(--space-5) var(--space-4); }
    .cq-options { grid-template-columns: 1fr; }
    .cq-question { font-size: var(--text-lg); }
    .cq-result-score { font-size: var(--text-4xl); }
    .cq-actions { flex-direction: column; align-items: stretch; }
    .cq-actions .cq-again,
    .cq-cta { width: 100%; justify-content: center; text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
    .cq-bar > span,
    .cq-option { transition: none; }
}
