/* ═══════════════════════════════════════════════════════════════════
   Chengyu Story Puzzle — unscramble the idiom, then read its origin (G11)
   Hero: seal-red #7f1d1d → #dc2626 (classical vermilion), distinct from
   Radical Hunt's emerald, Triple Match's violet, Character Builder's
   indigo, Look-Alike's teal, Tone Pair Arcade's rose and Number
   Dictation's amber.
   ═══════════════════════════════════════════════════════════════════ */

/* ── Hero ────────────────────────────────────────────────────────── */
.cy-hero {
    background: linear-gradient(135deg, #641414 0%, #991b1b 55%, #dc2626 100%);
    border-radius: 0.5rem;
}

/* ── HUD row above the stage ─────────────────────────────────────── */
.cy-hud {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem 1rem;
    margin-bottom: 0.5rem;
}

.cy-hud-item {
    font-weight: 700;
    font-size: 1.05rem;
    line-height: 1.2;
    white-space: nowrap;
}

.cy-hud-item small {
    display: block;
    font-weight: 400;
    font-size: 0.7rem;
    color: var(--bs-secondary-color);
}

.cy-heart {
    color: #ef4444;
    font-size: 1.15rem;
    transition: transform 0.15s, color 0.15s;
}

.cy-heart.lost {
    color: #cbd5e1;
    transform: scale(0.85);
}

.cy-combo-badge {
    display: inline-block;
    min-width: 2.4rem;
    padding: 0.05rem 0.4rem;
    border-radius: 999px;
    background: #991b1b;
    color: #fff;
    font-size: 0.95rem;
}

/* ── The stage ───────────────────────────────────────────────────── */
.cy-stage {
    position: relative;
    /* Tall enough for the story reveal, which is the longest overlay. */
    min-height: 460px;
    border-radius: 0.75rem;
    background: linear-gradient(180deg, #fef2f2 0%, #fffbeb 100%);
    border: 1px solid rgba(153, 27, 27, 0.15);
    padding: 1rem;
    overflow: hidden;
}

/* ── The clue ────────────────────────────────────────────────────── */
.cy-clue {
    text-align: center;
    min-height: 4.4rem;
    padding: 0.25rem 0 0.75rem;
}

.cy-clue-meaning {
    font-size: clamp(1.05rem, 4vw, 1.4rem);
    font-weight: 700;
    line-height: 1.25;
}

.cy-clue-pinyin {
    margin-top: 0.3rem;
    font-size: 1.05rem;
    font-weight: 600;
    color: #991b1b;
    letter-spacing: 0.03em;
}

.cy-clue-literal {
    margin-top: 0.2rem;
    font-size: 0.875rem;
    color: var(--bs-secondary-color);
}

.cy-clue-muted {
    opacity: 0.7;
}

/* Countdown bar */
.cy-timer {
    height: 8px;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.25);
    overflow: hidden;
    margin-bottom: 1rem;
}

.cy-timer-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #dc2626, #991b1b);
}

.cy-timer-fill.urgent {
    background: linear-gradient(90deg, #f97316, #ef4444);
    animation: cy-pulse 0.6s ease-in-out infinite;
}

@keyframes cy-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.55; }
}

/* ── The four answer slots ───────────────────────────────────────── */
.cy-slots {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.5rem;
    max-width: 24rem;
    margin: 0 auto 1.1rem;
}

.cy-slots.shake {
    animation: cy-shake 0.4s ease;
}

.cy-slot {
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1;
    width: 100%;
    padding: 0;
    border: 2px dashed rgba(153, 27, 27, 0.4);
    border-radius: 0.6rem;
    background: rgba(255, 255, 255, 0.6);
    color: #7f1d1d;
    font-size: clamp(1.8rem, 8vw, 2.6rem);
    line-height: 1;
    cursor: pointer;
    transition: transform 0.12s, border-color 0.12s, background 0.12s;
}

.cy-slot.filled {
    border-style: solid;
    border-color: #991b1b;
    background: #fff;
    animation: cy-pop 0.28s ease;
}

.cy-slot.drop-target {
    border-color: #dc2626;
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.25);
}

.cy-slot.locked {
    border-color: #f59e0b;
    background: #fffbeb;
    cursor: default;
}

.cy-slot.correct {
    border-color: #16a34a;
    background: #dcfce7;
    color: #14532d;
}

/* ── The character tray ──────────────────────────────────────────── */
.cy-tray {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
    min-height: 4rem;
}

.cy-tile {
    display: flex;
    align-items: center;
    justify-content: center;
    width: clamp(3rem, 14vw, 4rem);
    height: clamp(3rem, 14vw, 4rem);
    padding: 0;
    border: 2px solid rgba(153, 27, 27, 0.25);
    border-radius: 0.6rem;
    background: #fff;
    color: #0f172a;
    font-size: clamp(1.6rem, 7vw, 2.2rem);
    line-height: 1;
    cursor: grab;
    transition: transform 0.12s, border-color 0.12s, opacity 0.12s;
}

.cy-tile:hover:not(:disabled) {
    border-color: #991b1b;
    transform: translateY(-2px);
}

.cy-tile.used {
    opacity: 0.25;
    cursor: default;
    transform: none;
}

.cy-tile:disabled {
    cursor: default;
}

@keyframes cy-pop {
    0% { transform: scale(1); }
    45% { transform: scale(1.09); }
    100% { transform: scale(1); }
}

@keyframes cy-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-6px); }
    75% { transform: translateX(6px); }
}

/* ── Status line ─────────────────────────────────────────────────── */
.cy-status {
    min-height: 1.5rem;
    margin-top: 0.9rem;
    text-align: center;
    font-size: 0.9rem;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.cy-status.shown { opacity: 1; }
.cy-status.ok { color: #15803d; }
.cy-status.bad { color: #b91c1c; }
.cy-status.hint { color: #b45309; }

.cy-speaker {
    border: none;
    background: transparent;
    color: #991b1b;
    padding: 0.1rem 0.35rem;
    cursor: pointer;
    border-radius: 0.25rem;
}

.cy-speaker:hover {
    background: rgba(153, 27, 27, 0.12);
}

.cy-speaker.cy-speaker-loading {
    opacity: 0.45;
    cursor: progress;
}

/* ── Overlays ────────────────────────────────────────────────────── */
.cy-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    text-align: center;
    padding: 1.25rem;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(2px);
    z-index: 5;
    overflow-y: auto;
}

.cy-big-icon {
    font-size: 2.5rem;
    color: #991b1b;
}

.cy-btn-primary {
    background: linear-gradient(135deg, #991b1b, #dc2626);
    border: none;
    color: #fff;
    font-weight: 600;
}

.cy-btn-primary:hover {
    background: linear-gradient(135deg, #641414, #991b1b);
    color: #fff;
}

.cy-level-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
}

.cy-level-btn {
    border: 2px solid rgba(153, 27, 27, 0.3);
    background: #fff;
    border-radius: 0.5rem;
    padding: 0.4rem 0.9rem;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.12s;
}

.cy-level-btn:hover { border-color: #991b1b; }

.cy-level-btn.active {
    background: linear-gradient(135deg, #991b1b, #dc2626);
    border-color: #991b1b;
    color: #fff;
}

/* ── The story reveal ────────────────────────────────────────────── */
/* Unlike the other overlays this one is a block of prose, so it is fully
   opaque — at the shared 0.95 the board ghosts through behind the story. */
.cy-reveal {
    justify-content: flex-start;
    padding-top: 1rem;
    background: #fdf4f4;
}

.cy-reveal-head {
    font-weight: 700;
    font-size: 0.95rem;
}

.cy-reveal-head.ok { color: #15803d; }
.cy-reveal-head.bad { color: #b45309; }

.cy-reveal-chars {
    display: flex;
    gap: 0.4rem;
    justify-content: center;
}

.cy-reveal-char {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 3.2rem;
    padding: 0.25rem 0.35rem;
    border-radius: 0.5rem;
    background: rgba(153, 27, 27, 0.08);
}

.cy-reveal-hanzi {
    font-size: clamp(1.7rem, 7vw, 2.3rem);
    line-height: 1.1;
    color: #7f1d1d;
}

.cy-reveal-reading {
    font-size: 0.72rem;
    color: var(--bs-secondary-color);
}

.cy-reveal-pinyin {
    font-size: 1.05rem;
    font-weight: 600;
    color: #991b1b;
}

.cy-reveal-meaning {
    font-weight: 700;
}

.cy-reveal-literal {
    font-size: 0.875rem;
    color: var(--bs-secondary-color);
}

.cy-reveal-story {
    max-width: 34rem;
    font-size: 0.925rem;
    line-height: 1.55;
    text-align: left;
    padding: 0.7rem 0.9rem;
    border-left: 3px solid #dc2626;
    background: rgba(220, 38, 38, 0.06);
    border-radius: 0 0.4rem 0.4rem 0;
}

.cy-reveal-source {
    font-size: 0.78rem;
    color: var(--bs-secondary-color);
    font-style: italic;
}

.cy-reveal-score {
    font-weight: 700;
    color: #15803d;
}

/* ── Game over ───────────────────────────────────────────────────── */
.cy-final-score {
    font-size: 2.75rem;
    font-weight: 800;
    color: #991b1b;
    line-height: 1;
}

.cy-final-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem 1.1rem;
    justify-content: center;
    font-size: 0.875rem;
    color: var(--bs-secondary-color);
}

.cy-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    justify-content: center;
}

.cy-chip {
    background: rgba(153, 27, 27, 0.1);
    border-radius: 999px;
    padding: 0.15rem 0.7rem;
    font-size: 1rem;
}

/* ── Sidebar ─────────────────────────────────────────────────────── */
.cy-side-row {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    padding: 0.35rem 0;
    border-bottom: 1px solid var(--bs-border-color);
}

.cy-side-row:last-child { border-bottom: none; }

.cy-side-glyph {
    font-size: 1.05rem;
    font-weight: 600;
    line-height: 1;
    color: #991b1b;
    white-space: nowrap;
}

.cy-ref-char {
    font-size: 1.25rem;
    line-height: 1.5;
    white-space: nowrap;
}

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

@media (max-width: 575.98px) {
    .cy-stage { padding: 0.6rem; }
    .cy-slots { gap: 0.35rem; }
    .cy-tray { gap: 0.35rem; }
    .cy-reveal-story { font-size: 0.875rem; }
}

/* ── Dark mode ───────────────────────────────────────────────────── */
[data-bs-theme="dark"] .cy-stage {
    background: linear-gradient(180deg, #2b1010 0%, #1d0c0c 100%);
    border-color: rgba(220, 38, 38, 0.25);
}

[data-bs-theme="dark"] .cy-clue-pinyin { color: #fca5a5; }

[data-bs-theme="dark"] .cy-slot {
    background: rgba(69, 10, 10, 0.5);
    border-color: rgba(220, 38, 38, 0.45);
    color: #fecaca;
}

[data-bs-theme="dark"] .cy-slot.filled {
    background: #3b1414;
    border-color: #ef4444;
}

[data-bs-theme="dark"] .cy-slot.locked {
    background: rgba(245, 158, 11, 0.2);
    border-color: #f59e0b;
    color: #fde68a;
}

[data-bs-theme="dark"] .cy-slot.correct {
    background: rgba(22, 163, 74, 0.32);
    border-color: #22c55e;
    color: #bbf7d0;
}

[data-bs-theme="dark"] .cy-tile {
    background: #3b1414;
    border-color: rgba(220, 38, 38, 0.3);
    color: #e2e8f0;
}

[data-bs-theme="dark"] .cy-overlay { background: rgba(15, 23, 42, 0.95); }
[data-bs-theme="dark"] .cy-reveal { background: #160909; }

[data-bs-theme="dark"] .cy-level-btn {
    background: #3b1414;
    color: #e2e8f0;
}

[data-bs-theme="dark"] .cy-reveal-hanzi { color: #fca5a5; }
[data-bs-theme="dark"] .cy-reveal-pinyin { color: #fca5a5; }
[data-bs-theme="dark"] .cy-reveal-story { background: rgba(220, 38, 38, 0.12); }
[data-bs-theme="dark"] .cy-reveal-score { color: #4ade80; }
[data-bs-theme="dark"] .cy-status.ok { color: #4ade80; }
[data-bs-theme="dark"] .cy-status.bad { color: #f87171; }
[data-bs-theme="dark"] .cy-status.hint { color: #fbbf24; }
[data-bs-theme="dark"] .cy-side-glyph { color: #fca5a5; }
[data-bs-theme="dark"] .cy-heart.lost { color: #475569; }

@media (prefers-reduced-motion: reduce) {
    .cy-slot,
    .cy-tile,
    .cy-slots,
    .cy-timer-fill {
        animation: none !important;
        transition: none !important;
    }
}
