/*
 * Chengyu in Context — /games/chengyu-in-context.
 * A red-seal and rice-paper look: the gap is four empty squares, and a right answer is stamped
 * into them one character at a time. Every effect is decoration inside the stage, never clickable,
 * and switched off under prefers-reduced-motion. Dark mode follows [data-bs-theme="dark"].
 */

.cx-hero {
    background: linear-gradient(135deg, #991b1b 0%, #7f1d1d 50%, #450a0a 100%);
    position: relative;
    overflow: hidden;
}

.cx-hero::after {
    content: "";
    position: absolute;
    right: 1.5rem;
    top: 50%;
    width: 7rem;
    height: 7rem;
    transform: translateY(-50%) rotate(-8deg);
    border: 0.35rem solid rgba(255, 255, 255, 0.14);
    border-radius: 0.6rem;
    pointer-events: none;
}

.cx-hud {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding-bottom: 0.6rem;
    margin-bottom: 0.75rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

[data-bs-theme="dark"] .cx-hud { border-bottom-color: rgba(255, 255, 255, 0.12); }

.cx-hud-item { display: flex; flex-direction: column; line-height: 1.1; font-weight: 700; font-size: 1.15rem; }
.cx-hud-item small { font-size: 0.7rem; font-weight: 500; color: var(--bs-secondary-color); }
.cx-hearts { color: #dc2626; letter-spacing: 0.1em; }

.cx-combo { display: inline-block; color: #b45309; }
.cx-combo.cx-pop { animation: cx-pop 0.5s ease-out; }

.cx-stage {
    position: relative;
    min-height: 26rem;
    border-radius: 0.75rem;
    padding: 1rem;
    background:
        radial-gradient(circle at 20% 10%, rgba(185, 28, 28, 0.05), transparent 45%),
        #fffaf0;
}

[data-bs-theme="dark"] .cx-stage { background: #1f1715; }

.cx-progress { height: 5px; border-radius: 3px; background: rgba(0, 0, 0, 0.08); overflow: hidden; margin-bottom: 0.4rem; }
[data-bs-theme="dark"] .cx-progress { background: rgba(255, 255, 255, 0.1); }
.cx-progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, #f59e0b, #dc2626); transition: width 0.4s ease; }

.cx-meta { display: flex; justify-content: space-between; gap: 0.5rem; font-size: 0.75rem; color: var(--bs-secondary-color); margin-bottom: 0.9rem; }
.cx-band-pill { background: rgba(185, 28, 28, 0.1); color: #991b1b; border-radius: 1rem; padding: 0.05rem 0.55rem; font-weight: 600; }
[data-bs-theme="dark"] .cx-band-pill { background: rgba(248, 113, 113, 0.15); color: #fca5a5; }

.cx-sentence {
    font-size: 1.55rem;
    line-height: 2.2;
    text-align: center;
    word-break: break-all;
    margin-bottom: 0.4rem;
}

.cx-gap { display: inline-flex; gap: 0.12em; vertical-align: middle; margin: 0 0.15em; position: relative; }

.cx-gap-cell {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.35em;
    height: 1.35em;
    line-height: 1;
    border: 2px dashed rgba(185, 28, 28, 0.45);
    border-radius: 0.2em;
    background: rgba(255, 255, 255, 0.7);
}

[data-bs-theme="dark"] .cx-gap-cell { background: rgba(255, 255, 255, 0.05); border-color: rgba(248, 113, 113, 0.5); }

.cx-gap-cell.cx-stamped { border-style: solid; animation: cx-stamp 0.32s cubic-bezier(0.2, 1.6, 0.4, 1); }
.cx-gap.is-right .cx-gap-cell.cx-stamped { color: #fff; background: #b91c1c; border-color: #7f1d1d; }
.cx-gap.is-wrong .cx-gap-cell.cx-stamped { color: #991b1b; background: #fee2e2; border-color: #fca5a5; }
[data-bs-theme="dark"] .cx-gap.is-wrong .cx-gap-cell.cx-stamped { color: #fecaca; background: rgba(220, 38, 38, 0.2); }

.cx-seal {
    position: absolute;
    right: -0.9em;
    top: -0.7em;
    width: 1.3em;
    height: 1.3em;
    font-size: 0.7em;
    line-height: 1.3em;
    text-align: center;
    color: #fff;
    background: #dc2626;
    border-radius: 50%;
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.25);
    animation: cx-seal 0.45s ease-out;
    pointer-events: none;
}

.cx-english { text-align: center; color: var(--bs-secondary-color); font-style: italic; min-height: 1.5em; margin-bottom: 0.25rem; }
.cx-english.cx-hidden-text { display: none; }
.cx-peek { display: block; margin: 0 auto 0.75rem; }

.cx-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.6rem; }
@media (max-width: 420px) { .cx-options { grid-template-columns: 1fr; } }

.cx-option {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.1rem;
    padding: 0.7rem 0.6rem;
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-radius: 0.7rem;
    background: var(--bs-body-bg, #fff);
    color: inherit;
    transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}

.cx-option:hover:not(:disabled) { transform: translateY(-2px); border-color: #dc2626; box-shadow: 0 6px 16px rgba(185, 28, 28, 0.15); }
[data-bs-theme="dark"] .cx-option { border-color: rgba(255, 255, 255, 0.14); }

.cx-key {
    position: absolute;
    left: 0.45rem;
    top: 0.35rem;
    font-size: 0.65rem;
    color: var(--bs-secondary-color);
}

.cx-option-hanzi { font-size: 1.5rem; font-weight: 700; letter-spacing: 0.08em; }
.cx-option-pinyin { font-size: 0.8rem; color: #b45309; }
[data-bs-theme="dark"] .cx-option-pinyin { color: #fbbf24; }
.cx-option-meaning { font-size: 0.75rem; color: var(--bs-secondary-color); text-align: center; }

.cx-option.cx-right { border-color: #16a34a; background: rgba(22, 163, 74, 0.1); }
.cx-option.cx-wrong { border-color: #dc2626; background: rgba(220, 38, 38, 0.1); }
.cx-option:disabled { opacity: 1; cursor: default; }
.cx-option:disabled:not(.cx-right):not(.cx-wrong) { opacity: 0.55; }

.cx-status { text-align: center; min-height: 1.6rem; margin: 0.6rem 0 0.2rem; }
.cx-bonus { font-size: 0.75rem; color: #b45309; font-weight: 600; }

.cx-reveal { border-top: 1px dashed rgba(185, 28, 28, 0.3); margin-top: 0.6rem; padding-top: 0.8rem; text-align: center; }
.cx-reveal-idiom { display: inline-flex; align-items: center; gap: 0.8rem; text-align: left; padding: 0.5rem 0.8rem; border-radius: 0.6rem; margin-bottom: 0.6rem; }
.cx-reveal-idiom.is-right { background: rgba(22, 163, 74, 0.08); }
.cx-reveal-idiom.is-wrong { background: rgba(220, 38, 38, 0.08); }
.cx-reveal-hanzi { font-size: 1.8rem; font-weight: 700; color: #991b1b; }
[data-bs-theme="dark"] .cx-reveal-hanzi { color: #fca5a5; }
.cx-reveal-pinyin { color: #b45309; font-size: 0.9rem; }
.cx-reveal-meaning { font-size: 0.85rem; }
.cx-reveal-sentence { font-size: 1.15rem; }
.cx-reveal-sentence mark { background: rgba(245, 158, 11, 0.3); padding: 0 0.1em; border-radius: 0.15em; color: inherit; }
.cx-reveal-pinyin-line { font-size: 0.85rem; color: var(--bs-secondary-color); }
.cx-reveal-english { font-size: 0.9rem; margin: 0.15rem 0 0.3rem; }
.cx-speak { padding: 0.05rem 0.4rem; vertical-align: middle; }

.cx-btn-primary { background: #b91c1c; border-color: #b91c1c; color: #fff; }
.cx-btn-primary:hover, .cx-btn-primary:focus { background: #991b1b; border-color: #991b1b; color: #fff; }

.cx-overlay {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.65rem;
    text-align: center;
    padding: 1rem;
    border-radius: 0.75rem;
    background: var(--bs-body-bg, #fff);
    overflow-y: auto;
}

.cx-big-icon { font-size: 2.4rem; color: #b91c1c; }

.cx-band-picker { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.4rem; width: 100%; max-width: 30rem; }
@media (max-width: 420px) { .cx-band-picker { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.cx-band-btn {
    display: flex;
    flex-direction: column;
    padding: 0.45rem 0.3rem;
    border: 2px solid rgba(0, 0, 0, 0.12);
    border-radius: 0.6rem;
    background: transparent;
    color: inherit;
}

[data-bs-theme="dark"] .cx-band-btn { border-color: rgba(255, 255, 255, 0.16); }
.cx-band-btn.active { border-color: #b91c1c; background: rgba(185, 28, 28, 0.08); }
.cx-band-zh { font-weight: 700; }
.cx-band-en { font-size: 0.75rem; color: var(--bs-secondary-color); }

.cx-final-score { font-size: 2.6rem; font-weight: 800; color: #b91c1c; line-height: 1; }
.cx-final-stats { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.3rem 1rem; font-size: 0.85rem; }

.cx-chip {
    display: inline-block;
    padding: 0.1rem 0.5rem;
    border-radius: 1rem;
    background: rgba(185, 28, 28, 0.08);
    color: #991b1b;
    text-decoration: none;
    font-weight: 600;
}

[data-bs-theme="dark"] .cx-chip { background: rgba(248, 113, 113, 0.14); color: #fecaca; }

/* The effects layer: above the stage content, below the overlays, never clickable. */
.cx-fx { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 5; border-radius: 0.75rem; }

.cx-particle {
    position: absolute;
    width: 8px;
    height: 12px;
    border-radius: 2px;
    animation: cx-burst 0.85s ease-out forwards;
}

.cx-confetti {
    position: absolute;
    top: -12px;
    width: 8px;
    height: 14px;
    border-radius: 2px;
    animation: cx-fall 2.2s ease-in forwards;
}

.cx-shake { animation: cx-shake 0.4s ease; }

.cx-example { border-left: 4px solid #b91c1c; background: rgba(185, 28, 28, 0.04); padding: 0.6rem 0.9rem; border-radius: 0 0.5rem 0.5rem 0; }
.cx-example-sentence { font-size: 1.2rem; }
.cx-example-sentence mark { background: rgba(245, 158, 11, 0.3); color: inherit; }

.cx-visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@keyframes cx-stamp {
    0% { transform: scale(1.8) rotate(-8deg); opacity: 0; }
    100% { transform: scale(1) rotate(0); opacity: 1; }
}

@keyframes cx-seal {
    0% { transform: scale(2.4); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes cx-pop {
    0% { transform: scale(1); }
    40% { transform: scale(1.6); color: #dc2626; }
    100% { transform: scale(1); }
}

@keyframes cx-burst {
    0% { transform: translate(-50%, -50%) rotate(0); opacity: 1; }
    100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy) + 40px)) rotate(var(--rot)); opacity: 0; }
}

@keyframes cx-fall {
    0% { transform: translateY(0) rotate(0); opacity: 1; }
    100% { transform: translateY(28rem) rotate(540deg); opacity: 0; }
}

@keyframes cx-shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-6px); }
    40%, 80% { transform: translateX(6px); }
}

@media (prefers-reduced-motion: reduce) {
    .cx-gap-cell.cx-stamped, .cx-seal, .cx-combo.cx-pop, .cx-shake, .cx-particle, .cx-confetti { animation: none; }
    .cx-option { transition: none; }
}
