/* ═══════════════════════════════════════════════════════════════════
   Character Builder — assemble hanzi from their components (G5)
   Hero: indigo #3730a3 → #6366f1, distinct from Look-Alike's teal,
   Tone Pair Arcade's rose and Number Dictation's amber.
   ═══════════════════════════════════════════════════════════════════ */

/* ── Hero ────────────────────────────────────────────────────────── */
.cb-hero {
    background: linear-gradient(135deg, #312e81 0%, #4338ca 55%, #6366f1 100%);
    border-radius: 0.5rem;
}

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

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

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

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

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

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

/* Round progress */
.cb-progress {
    height: 5px;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.3);
    overflow: hidden;
    margin-bottom: 0.75rem;
}

.cb-progress-fill {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, #4338ca, #6366f1);
    transition: width 0.3s ease;
}

/* ── The stage ───────────────────────────────────────────────────── */
.cb-stage {
    position: relative;
    min-height: 460px;
    border-radius: 0.75rem;
    background: linear-gradient(180deg, #eef2ff 0%, #f5f3ff 100%);
    border: 1px solid rgba(67, 56, 202, 0.15);
    padding: 1rem;
    overflow: hidden;
}

/* ── Prompt ──────────────────────────────────────────────────────── */
.cb-prompt {
    text-align: center;
    min-height: 5.6rem;
    padding: 0.35rem 0 0.6rem;
}

.cb-prompt-pinyin {
    font-size: clamp(1.9rem, 6.5vw, 2.75rem);
    font-weight: 700;
    line-height: 1.1;
    color: #3730a3;
}

.cb-prompt-meaning {
    font-size: 1.05rem;
    color: var(--bs-secondary-color);
    margin-top: 0.15rem;
}

.cb-prompt-note {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--bs-secondary-color);
    opacity: 0.8;
    margin-top: 0.2rem;
}

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

.cb-timer-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #6366f1, #4338ca);
}

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

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

/* ── Assembly slots ──────────────────────────────────────────────── */
.cb-slots {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    margin-bottom: 1rem;
}

.cb-slot {
    display: flex;
    align-items: center;
    justify-content: center;
    width: clamp(4rem, 17vw, 5.5rem);
    height: clamp(4rem, 17vw, 5.5rem);
    border: 2px dashed rgba(67, 56, 202, 0.4);
    border-radius: 0.75rem;
    background: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    transition: transform 0.12s, border-color 0.12s, background 0.12s;
}

.cb-slot.filled {
    border-style: solid;
    border-color: #4338ca;
    background: #fff;
}

.cb-slot.drop-target {
    border-color: #6366f1;
    background: #e0e7ff;
    transform: scale(1.05);
}

.cb-slot-char {
    font-size: clamp(2.2rem, 9vw, 3rem);
    line-height: 1;
    color: #0f172a;
}

.cb-slot-index {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--bs-secondary-color);
    opacity: 0.5;
}

.cb-slot.correct {
    border-color: #16a34a;
    background: #dcfce7;
    animation: cb-pop 0.35s ease;
}

.cb-slot.wrong {
    border-color: #dc2626;
    background: #fee2e2;
    animation: cb-shake 0.35s ease;
}

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

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

/* ── Component tray ──────────────────────────────────────────────── */
.cb-tray {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
    min-height: 5.5rem;
}

.cb-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.05rem;
    min-width: 4.25rem;
    padding: 0.4rem 0.5rem;
    border: 2px solid rgba(67, 56, 202, 0.25);
    border-radius: 0.6rem;
    background: #fff;
    cursor: grab;
    transition: transform 0.12s, border-color 0.12s, opacity 0.12s;
}

.cb-tile:hover:not(:disabled) {
    border-color: #4338ca;
    transform: translateY(-2px);
}

.cb-tile:active:not(:disabled) {
    cursor: grabbing;
}

.cb-tile.used {
    opacity: 0.3;
    cursor: default;
}

.cb-tile-char {
    font-size: 1.9rem;
    line-height: 1;
    color: #0f172a;
}

.cb-tile-gloss {
    font-size: 0.72rem;
    font-weight: 600;
    color: #4338ca;
}

.cb-tile-meaning {
    font-size: 0.65rem;
    color: var(--bs-secondary-color);
    max-width: 6.5rem;
    text-align: center;
    line-height: 1.15;
}

/* ── Hint line ───────────────────────────────────────────────────── */
.cb-hint {
    min-height: 1.4rem;
    margin-top: 0.6rem;
    text-align: center;
    font-size: 0.875rem;
    color: #b45309;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.cb-hint.shown {
    opacity: 1;
}

/* ── Reveal panel ────────────────────────────────────────────────── */
.cb-reveal {
    margin-top: 0.6rem;
    /* Reserved so the stage does not jump when the etymology appears. */
    min-height: 9rem;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.cb-reveal.shown {
    opacity: 1;
}

.cb-reveal-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.4rem;
}

.cb-reveal-head {
    font-weight: 700;
}

.cb-reveal-head.ok { color: #15803d; }
.cb-reveal-head.bad { color: #b91c1c; }

.cb-reveal-equation {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.3rem 0.5rem;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.cb-reveal-part {
    display: inline-flex;
    align-items: baseline;
    gap: 0.3rem;
}

.cb-reveal-part > [lang] {
    font-size: 1.5rem;
    line-height: 1;
}

.cb-reveal-plus {
    font-weight: 700;
    color: var(--bs-secondary-color);
}

.cb-reveal-answer {
    font-size: 2rem;
    line-height: 1;
    font-weight: 600;
    color: #4338ca;
}

.cb-reveal-reading {
    font-size: 0.9rem;
    margin-bottom: 0.35rem;
}

.cb-reveal-ety {
    font-size: 0.875rem;
    background: rgba(99, 102, 241, 0.1);
    border-left: 3px solid #6366f1;
    border-radius: 0.25rem;
    padding: 0.5rem 0.65rem;
}

.cb-speaker {
    border: none;
    background: transparent;
    color: #4338ca;
    padding: 0.1rem 0.35rem;
    cursor: pointer;
    border-radius: 0.25rem;
}

.cb-speaker:hover {
    background: rgba(67, 56, 202, 0.12);
}

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

/* Floating score */
.cb-float {
    position: absolute;
    top: 30%;
    left: 50%;
    transform: translateX(-50%);
    font-weight: 800;
    font-size: 1.5rem;
    color: #15803d;
    pointer-events: none;
    animation: cb-float-up 0.9s ease-out forwards;
}

@keyframes cb-float-up {
    0% { opacity: 1; transform: translate(-50%, 0); }
    100% { opacity: 0; transform: translate(-50%, -60px); }
}

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

.cb-big-icon {
    font-size: 2.5rem;
    color: #4338ca;
}

.cb-btn-primary {
    background: linear-gradient(135deg, #4338ca, #6366f1);
    border: none;
    color: #fff;
    font-weight: 600;
}

.cb-btn-primary:hover {
    background: linear-gradient(135deg, #312e81, #4338ca);
    color: #fff;
}

/* Level picker on the start screen */
.cb-level-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
}

.cb-level-btn {
    border: 2px solid rgba(67, 56, 202, 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;
}

.cb-level-btn:hover {
    border-color: #4338ca;
}

.cb-level-btn.active {
    background: linear-gradient(135deg, #4338ca, #6366f1);
    border-color: #4338ca;
    color: #fff;
}

.cb-final-score {
    font-size: 2.75rem;
    font-weight: 800;
    color: #4338ca;
    line-height: 1;
}

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

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

.cb-chip {
    background: rgba(67, 56, 202, 0.12);
    border-radius: 999px;
    padding: 0.15rem 0.6rem;
    font-size: 1.1rem;
}

/* Sidebar rows */
.cb-stat-char {
    font-size: 1.35rem;
    font-weight: 600;
    line-height: 1;
}

.cb-side-parts {
    font-size: 1rem;
    color: #4338ca;
    margin-bottom: 0.15rem;
}

/* Reference character cells in the article-style cards */
.cb-ref-char {
    font-size: 1.5rem;
    line-height: 1.4;
}

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

/* ── Dark mode ───────────────────────────────────────────────────── */
[data-bs-theme="dark"] .cb-stage {
    background: linear-gradient(180deg, #1e1b4b 0%, #17163a 100%);
    border-color: rgba(99, 102, 241, 0.25);
}

[data-bs-theme="dark"] .cb-prompt-pinyin {
    color: #a5b4fc;
}

[data-bs-theme="dark"] .cb-slot {
    background: rgba(30, 27, 75, 0.6);
    border-color: rgba(99, 102, 241, 0.4);
}

[data-bs-theme="dark"] .cb-slot.filled {
    background: #272457;
    border-color: #6366f1;
}

[data-bs-theme="dark"] .cb-slot.drop-target {
    background: #312e81;
}

[data-bs-theme="dark"] .cb-slot-char,
[data-bs-theme="dark"] .cb-tile-char {
    color: #e2e8f0;
}

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

[data-bs-theme="dark"] .cb-slot.wrong {
    background: rgba(220, 38, 38, 0.28);
    border-color: #ef4444;
}

[data-bs-theme="dark"] .cb-tile {
    background: #272457;
    border-color: rgba(99, 102, 241, 0.3);
}

[data-bs-theme="dark"] .cb-tile-gloss {
    color: #a5b4fc;
}

[data-bs-theme="dark"] .cb-overlay {
    background: rgba(15, 23, 42, 0.94);
}

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

[data-bs-theme="dark"] .cb-reveal-head.ok { color: #4ade80; }
[data-bs-theme="dark"] .cb-reveal-head.bad { color: #f87171; }
[data-bs-theme="dark"] .cb-reveal-answer { color: #a5b4fc; }
[data-bs-theme="dark"] .cb-side-parts { color: #a5b4fc; }
[data-bs-theme="dark"] .cb-hint { color: #fbbf24; }

[data-bs-theme="dark"] .cb-float { color: #4ade80; }

[data-bs-theme="dark"] .cb-heart.lost { color: #475569; }

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