/* ═══════════════════════════════════════════════════════════════════
   Tone Pair Arcade — falling two-syllable words, tap the tone pattern
   Hero: rose #be185d → #9d174d (the Tone Pairs family colour, distinct
   from Word Rain's storm blue and the other tool accents).
   ═══════════════════════════════════════════════════════════════════ */

/* ── Hero / sidebar header ───────────────────────────────────────── */
.tpa-hero {
    background: linear-gradient(135deg, #9d174d 0%, #be185d 55%, #db2777 100%);
    border-radius: 0.5rem;
}

.tpa-panel-header {
    background: linear-gradient(135deg, #9d174d 0%, #be185d 100%);
    color: #fff;
    border-radius: 0.375rem 0.375rem 0 0;
}

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

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

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

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

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

@keyframes tpa-heart-pop {
    0% { transform: scale(1); }
    40% { transform: scale(1.6); }
    100% { transform: scale(0.85); }
}

.tpa-heart.popping {
    animation: tpa-heart-pop 0.4s ease;
}

.tpa-combo-badge {
    display: inline-block;
    min-width: 3.2rem;
    text-align: center;
    background: #f59e0b;
    color: #1f2937;
    border-radius: 999px;
    padding: 0.1rem 0.55rem;
    font-weight: 800;
}

@keyframes tpa-combo-bump {
    0% { transform: scale(1); }
    50% { transform: scale(1.25); }
    100% { transform: scale(1); }
}

.tpa-combo-badge.bump {
    animation: tpa-combo-bump 0.25s ease;
}

/* Wave progress bar */
.tpa-progress {
    height: 6px;
    border-radius: 999px;
    background: var(--pl-border, #e2e8f0);
    overflow: hidden;
    margin-bottom: 0.6rem;
}

.tpa-progress-fill {
    height: 100%;
    width: 0%;
    border-radius: 999px;
    background: linear-gradient(90deg, #9d174d, #db2777);
    transition: width 0.25s ease;
}

/* ── Stage ───────────────────────────────────────────────────────── */
.tpa-stage {
    position: relative;
    height: clamp(320px, 48vh, 480px);
    border-radius: 0.75rem;
    border: 1px solid var(--pl-border, #fbcfe8);
    background: linear-gradient(180deg, #fce7f3 0%, #fdf2f8 55%, #fff1f2 100%);
    overflow: hidden;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* Subtle animated music-note drizzle while a round is running */
.tpa-stage::before {
    content: "";
    position: absolute;
    inset: -60px 0 0 0;
    pointer-events: none;
    background-image:
        repeating-linear-gradient(100deg, transparent 0 22px, rgba(190, 24, 93, 0.08) 22px 24px),
        repeating-linear-gradient(100deg, transparent 0 47px, rgba(190, 24, 93, 0.05) 47px 49px);
    opacity: 0;
    transition: opacity 0.5s;
}

.tpa-stage.playing::before {
    opacity: 1;
    animation: tpa-drizzle 1.1s linear infinite;
}

@keyframes tpa-drizzle {
    from { transform: translateY(-24px); }
    to { transform: translateY(24px); }
}

.tpa-ground {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 14px;
    background: linear-gradient(180deg, rgba(190, 24, 93, 0.25), rgba(190, 24, 93, 0.5));
}

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

.tpa-stage.shaking {
    animation: tpa-shake 0.4s ease;
}

/* "Buffering audio" pulse shown when the next word is still fetching */
.tpa-buffering {
    position: absolute;
    left: 50%;
    top: 40%;
    transform: translate(-50%, -50%);
    color: #be185d;
    font-size: 0.9rem;
    font-weight: 600;
    z-index: 2;
    display: flex;
    align-items: center;
    gap: 0.45rem;
}

@keyframes tpa-buffer-pulse {
    0%, 100% { opacity: 0.45; }
    50% { opacity: 1; }
}

.tpa-buffering i {
    animation: tpa-buffer-pulse 0.9s ease infinite;
}

/* ── Falling word tile ───────────────────────────────────────────── */
.tpa-word {
    position: absolute;
    top: 0;
    transform: translate(-50%, -80px);
    background: #ffffff;
    border: 2px solid #f9a8d4;
    border-radius: 1rem;
    box-shadow: 0 4px 14px rgba(157, 23, 77, 0.18);
    padding: 0.4rem 1.05rem;
    text-align: center;
    max-width: 88%;
    will-change: transform;
    z-index: 2;
}

.tpa-word .tpa-word-hanzi {
    font-size: clamp(1.25rem, 4.5vw, 1.7rem);
    font-weight: 700;
    color: #1e293b;
    line-height: 1.15;
    word-break: keep-all;
}

.tpa-word .tpa-word-pinyin {
    font-size: 0.95rem;
    color: #64748b;
    line-height: 1.15;
}

.tpa-word .tpa-word-replay {
    border: none;
    background: transparent;
    color: #be185d;
    font-size: 0.9rem;
    padding: 0 0.25rem;
    cursor: pointer;
}

@keyframes tpa-danger-pulse {
    0%, 100% { box-shadow: 0 4px 14px rgba(220, 38, 38, 0.25); border-color: #fca5a5; }
    50% { box-shadow: 0 4px 22px rgba(220, 38, 38, 0.55); border-color: #ef4444; }
}

.tpa-word.danger {
    animation: tpa-danger-pulse 0.5s ease infinite;
}

@keyframes tpa-word-zap {
    to { transform: translate(-50%, var(--tpa-y, 0)) scale(0.1) rotate(12deg); opacity: 0; }
}

.tpa-word.zapped {
    animation: tpa-word-zap 0.28s ease forwards;
}

@keyframes tpa-word-splat {
    40% { transform: translate(-50%, var(--tpa-y, 0)) scaleY(0.5) scaleX(1.25); }
    to { transform: translate(-50%, var(--tpa-y, 0)) scaleY(0.3) scaleX(1.4); opacity: 0; }
}

.tpa-word.splat {
    animation: tpa-word-splat 0.5s ease forwards;
}

/* ── Tone-pattern answer buttons ─────────────────────────────────── */
.tpa-answers {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.6rem;
    margin-top: 0.75rem;
}

@media (max-width: 575.98px) {
    .tpa-answers {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

.tpa-answer-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.1rem;
    min-height: 64px;
    padding: 0.45rem 0.5rem;
    border: 2px solid var(--pl-border, #cbd5e1);
    border-radius: 0.65rem;
    background: var(--pl-card-bg, #ffffff);
    color: var(--pl-text, #1e293b);
    font-weight: 700;
    text-align: center;
    cursor: pointer;
    transition: transform 0.1s, border-color 0.1s, background-color 0.1s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.tpa-answer-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    border-color: #be185d;
}

.tpa-answer-btn:disabled {
    opacity: 0.55;
    cursor: default;
}

.tpa-answer-btn .tpa-combo-display {
    font-size: 1.25rem;
    line-height: 1.1;
}

.tpa-answer-btn .tpa-combo-arrows {
    font-size: 0.85rem;
    font-weight: 400;
    color: var(--bs-secondary-color);
}

.tpa-answer-btn .tpa-key-hint {
    font-size: 0.62rem;
    font-weight: 700;
    color: var(--bs-secondary-color);
    border: 1px solid var(--pl-border, #cbd5e1);
    border-radius: 0.3rem;
    padding: 0 0.28rem;
}

.tpa-answer-btn.correct {
    background: #d1e7dd;
    border-color: #198754;
    color: #0a3622;
    opacity: 1;
}

@keyframes tpa-btn-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.tpa-answer-btn.wrong {
    background: #f8d7da;
    border-color: #dc3545;
    color: #58151c;
    animation: tpa-btn-shake 0.3s ease;
    opacity: 1;
}

/* ── Floating score / particles / confetti ───────────────────────── */
.tpa-float {
    position: absolute;
    transform: translate(-50%, 0);
    font-weight: 800;
    font-size: 1.25rem;
    color: #16a34a;
    text-shadow: 0 1px 3px rgba(255, 255, 255, 0.7);
    pointer-events: none;
    z-index: 4;
    animation: tpa-float-up 0.9s ease-out forwards;
}

@keyframes tpa-float-up {
    to { transform: translate(-50%, -75px); opacity: 0; }
}

.tpa-particle {
    position: absolute;
    width: 9px;
    height: 9px;
    border-radius: 2px;
    pointer-events: none;
    z-index: 3;
    transition: transform 0.65s ease-out, opacity 0.65s ease-out;
}

.tpa-confetti {
    position: absolute;
    top: -14px;
    width: 10px;
    height: 14px;
    border-radius: 2px;
    pointer-events: none;
    z-index: 6;
    animation: tpa-confetti-fall linear forwards;
}

@keyframes tpa-confetti-fall {
    to { transform: translateY(560px) rotate(660deg); opacity: 0.2; }
}

/* ── Reveal toast (correct pattern after a miss) ─────────────────── */
.tpa-reveal {
    position: absolute;
    left: 50%;
    top: 42%;
    transform: translate(-50%, -50%);
    background: var(--pl-card-bg, #ffffff);
    border: 2px solid #f59e0b;
    border-radius: 0.75rem;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
    padding: 0.6rem 1.2rem;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--pl-text, #1e293b);
    text-align: center;
    z-index: 5;
    max-width: 92%;
}

.tpa-reveal small {
    display: block;
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--bs-secondary-color);
}

/* Short status toast (e.g. "Harder words joined the arcade!") */
.tpa-toast {
    position: absolute;
    left: 50%;
    top: 12%;
    transform: translateX(-50%);
    background: rgba(157, 23, 77, 0.92);
    color: #fff;
    border-radius: 999px;
    padding: 0.35rem 1rem;
    font-size: 0.9rem;
    font-weight: 600;
    white-space: nowrap;
    z-index: 5;
    animation: tpa-toast-in 2.4s ease forwards;
}

@keyframes tpa-toast-in {
    0% { opacity: 0; transform: translateX(-50%) translateY(-8px); }
    12%, 82% { opacity: 1; transform: translateX(-50%) translateY(0); }
    100% { opacity: 0; transform: translateX(-50%) translateY(-8px); }
}

/* ── Overlays (start / wave clear / game over / paused) ──────────── */
.tpa-overlay {
    position: absolute;
    inset: 0;
    z-index: 8;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.65rem;
    text-align: center;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    overflow-y: auto;
}

.tpa-overlay h2,
.tpa-overlay h3 {
    margin-bottom: 0;
}

.tpa-overlay .tpa-big-icon {
    font-size: 2.6rem;
    color: #be185d;
    line-height: 1;
}

.tpa-btn-primary {
    background: linear-gradient(135deg, #9d174d 0%, #db2777 100%);
    border: none;
    color: #fff;
}

.tpa-btn-primary:hover,
.tpa-btn-primary:focus {
    color: #fff;
    filter: brightness(1.1);
}

/* Mode picker (Listening / Reading) on the start overlay */
.tpa-mode-picker {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    justify-content: center;
}

.tpa-mode-btn {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    align-items: center;
    min-width: 150px;
    padding: 0.55rem 0.9rem;
    border: 2px solid var(--pl-border, #cbd5e1);
    border-radius: 0.65rem;
    background: var(--pl-card-bg, #ffffff);
    color: var(--pl-text, #1e293b);
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.1s, transform 0.1s;
}

.tpa-mode-btn:hover {
    transform: translateY(-2px);
}

.tpa-mode-btn.active {
    border-color: #be185d;
    background: rgba(190, 24, 93, 0.07);
}

.tpa-mode-btn small {
    font-weight: 400;
    font-size: 0.72rem;
    color: var(--bs-secondary-color);
}

.tpa-final-score {
    font-size: 2.8rem;
    font-weight: 800;
    line-height: 1;
    color: #be185d;
}

.tpa-final-stats {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.4rem 1.4rem;
    font-size: 0.95rem;
}

.tpa-final-stats strong {
    font-size: 1.15rem;
}

@keyframes tpa-newbest-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.12); }
}

.tpa-newbest {
    animation: tpa-newbest-pulse 0.9s ease infinite;
}

/* Missed-word chips (game-over review + sidebar) */
.tpa-chips {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.35rem;
    max-width: 100%;
}

.tpa-chip {
    display: inline-flex;
    align-items: baseline;
    gap: 0.35rem;
    background: rgba(190, 24, 93, 0.08);
    border: 1px solid rgba(190, 24, 93, 0.35);
    border-radius: 999px;
    padding: 0.15rem 0.65rem;
    font-size: 0.85rem;
    white-space: nowrap;
}

.tpa-chip .tpa-chip-answer {
    color: var(--bs-secondary-color);
    font-size: 0.78rem;
}

/* Pattern reference grid (content section below the game) */
.tpa-ref-cell {
    border: 1px solid var(--pl-border, #e2e8f0);
    border-radius: 0.5rem;
    padding: 0.45rem 0.3rem;
    text-align: center;
    height: 100%;
}

.tpa-ref-cell .tpa-ref-pattern {
    font-weight: 800;
    color: #be185d;
}

.tpa-ref-cell .tpa-ref-word {
    font-size: 0.85rem;
}

.tpa-ref-cell .tpa-ref-gloss {
    font-size: 0.72rem;
    color: var(--bs-secondary-color);
}

/* Visually hidden live region for screen readers */
.tpa-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"] .tpa-stage {
    background: linear-gradient(180deg, #1e1b2e 0%, #2b1e33 70%, #3f1d3a 100%);
    border-color: var(--pl-border, #3a4049);
}

[data-bs-theme="dark"] .tpa-stage::before {
    background-image:
        repeating-linear-gradient(100deg, transparent 0 22px, rgba(244, 114, 182, 0.10) 22px 24px),
        repeating-linear-gradient(100deg, transparent 0 47px, rgba(244, 114, 182, 0.06) 47px 49px);
}

[data-bs-theme="dark"] .tpa-word {
    background: var(--pl-card-bg, #2b3035);
    border-color: #9d174d;
}

[data-bs-theme="dark"] .tpa-word .tpa-word-hanzi {
    color: var(--pl-text, #e4e6eb);
}

[data-bs-theme="dark"] .tpa-word .tpa-word-pinyin {
    color: #94a3b8;
}

[data-bs-theme="dark"] .tpa-overlay {
    background: rgba(23, 15, 25, 0.9);
}

[data-bs-theme="dark"] .tpa-float {
    color: #4ade80;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
}

[data-bs-theme="dark"] .tpa-answer-btn.correct {
    background: #14532d;
    border-color: #22c55e;
    color: #dcfce7;
}

[data-bs-theme="dark"] .tpa-answer-btn.wrong {
    background: #58151c;
    border-color: #ef4444;
    color: #f8d7da;
}

[data-bs-theme="dark"] .tpa-mode-btn.active {
    background: rgba(244, 114, 182, 0.12);
}

/* ── Reduced motion ──────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    .tpa-stage.playing::before,
    .tpa-stage.shaking,
    .tpa-word.danger,
    .tpa-combo-badge.bump,
    .tpa-newbest,
    .tpa-confetti,
    .tpa-buffering i {
        animation: none;
    }
}
