/* ═══════════════════════════════════════════════════════════════════
   Triple Match — link 汉字 ↔ pīnyīn ↔ English across three columns (G9)
   Hero: violet #6b21a8 → #c026d3, distinct from Character Builder's
   indigo, Look-Alike's teal, Tone Pair Arcade's rose and Number
   Dictation's amber.
   ═══════════════════════════════════════════════════════════════════ */

/* ── Hero ────────────────────────────────────────────────────────── */
.tm-hero {
    background: linear-gradient(135deg, #581c87 0%, #7e22ce 55%, #c026d3 100%);
    border-radius: 0.5rem;
}

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

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

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

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

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

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

/* Round progress (words cleared out of the round's quota) */
.tm-progress {
    height: 5px;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.3);
    overflow: hidden;
    margin-bottom: 0.75rem;
}

.tm-progress-fill {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, #7e22ce, #c026d3);
    transition: width 0.3s ease;
}

/* ── The stage ───────────────────────────────────────────────────── */
.tm-stage {
    position: relative;
    /* Only tall enough for the game-over overlay — a 5-row Beginner board is
       shorter than a 7-row Advanced one and shouldn't leave a hole under it. */
    min-height: 400px;
    border-radius: 0.75rem;
    background: linear-gradient(180deg, #faf5ff 0%, #fdf4ff 100%);
    border: 1px solid rgba(126, 34, 206, 0.15);
    padding: 1rem;
    overflow: hidden;
}

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

.tm-timer-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #c026d3, #7e22ce);
}

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

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

/* ── The three columns ───────────────────────────────────────────── */
.tm-board {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.5rem;
    align-items: start;
}

.tm-col-head {
    text-align: center;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #7e22ce;
    padding-bottom: 0.35rem;
    margin-bottom: 0.4rem;
    border-bottom: 2px solid rgba(126, 34, 206, 0.2);
}

.tm-col {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

/* ── Tiles ───────────────────────────────────────────────────────── */
.tm-tile {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    width: 100%;
    min-height: 3.4rem;
    padding: 0.45rem 0.35rem;
    border: 2px solid rgba(126, 34, 206, 0.22);
    border-radius: 0.6rem;
    background: #fff;
    color: #0f172a;
    cursor: pointer;
    line-height: 1.2;
    transition: transform 0.12s, border-color 0.12s, background 0.12s, opacity 0.2s;
}

.tm-tile:hover:not(:disabled):not(.cleared) {
    border-color: #7e22ce;
    transform: translateY(-2px);
}

.tm-tile.selected {
    border-color: #7e22ce;
    background: #f3e8ff;
    box-shadow: 0 0 0 3px rgba(192, 38, 211, 0.2);
}

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

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

.tm-tile.hinted {
    border-color: #f59e0b;
    background: #fef3c7;
}

/* Kept in the layout so the columns never jump while a triple animates out. */
.tm-tile.cleared {
    opacity: 0;
    pointer-events: none;
}

.tm-tile-hanzi {
    font-size: clamp(1.3rem, 5vw, 1.75rem);
}

.tm-tile-pinyin {
    font-size: clamp(0.9rem, 3.2vw, 1.1rem);
    font-weight: 600;
    color: #6b21a8;
}

.tm-tile-english {
    font-size: clamp(0.75rem, 2.6vw, 0.9rem);
}

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

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

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

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

.tm-speaker {
    border: none;
    background: transparent;
    color: #7e22ce;
    padding: 0.1rem 0.35rem;
    cursor: pointer;
    border-radius: 0.25rem;
}

.tm-speaker:hover {
    background: rgba(126, 34, 206, 0.12);
}

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

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

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

/* ── Overlays ────────────────────────────────────────────────────── */
.tm-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;
}

.tm-big-icon {
    font-size: 2.5rem;
    color: #7e22ce;
}

.tm-btn-primary {
    background: linear-gradient(135deg, #7e22ce, #c026d3);
    border: none;
    color: #fff;
    font-weight: 600;
}

.tm-btn-primary:hover {
    background: linear-gradient(135deg, #581c87, #7e22ce);
    color: #fff;
}

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

.tm-level-btn {
    border: 2px solid rgba(126, 34, 206, 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;
}

.tm-level-btn:hover { border-color: #7e22ce; }

.tm-level-btn.active {
    background: linear-gradient(135deg, #7e22ce, #c026d3);
    border-color: #7e22ce;
    color: #fff;
}

.tm-final-score {
    font-size: 2.75rem;
    font-weight: 800;
    color: #7e22ce;
    line-height: 1;
}

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

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

.tm-chip {
    background: rgba(126, 34, 206, 0.12);
    border-radius: 999px;
    padding: 0.15rem 0.6rem;
    font-size: 1.05rem;
}

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

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

.tm-side-hanzi {
    font-size: 1.3rem;
    font-weight: 600;
    line-height: 1;
}

.tm-side-pinyin {
    color: #7e22ce;
    font-size: 0.85rem;
}

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

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

/* Three columns stay side by side even on phones — that is the game — but the
   tiles get tighter so a 7-row board still fits above the fold. */
@media (max-width: 575.98px) {
    .tm-board { gap: 0.3rem; }
    .tm-tile { min-height: 3rem; padding: 0.35rem 0.2rem; border-radius: 0.45rem; }
    .tm-stage { padding: 0.6rem; }
}

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

[data-bs-theme="dark"] .tm-col-head {
    color: #d8b4fe;
    border-bottom-color: rgba(192, 38, 211, 0.3);
}

[data-bs-theme="dark"] .tm-tile {
    background: #3b1170;
    border-color: rgba(192, 38, 211, 0.3);
    color: #e2e8f0;
}

[data-bs-theme="dark"] .tm-tile.selected {
    background: #581c87;
    border-color: #c026d3;
}

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

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

[data-bs-theme="dark"] .tm-tile.hinted {
    background: rgba(245, 158, 11, 0.25);
    border-color: #f59e0b;
}

[data-bs-theme="dark"] .tm-tile-pinyin { color: #e9d5ff; }

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

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

[data-bs-theme="dark"] .tm-status.ok { color: #4ade80; }
[data-bs-theme="dark"] .tm-status.bad { color: #f87171; }
[data-bs-theme="dark"] .tm-status.hint { color: #fbbf24; }
[data-bs-theme="dark"] .tm-side-pinyin { color: #d8b4fe; }
[data-bs-theme="dark"] .tm-float { color: #4ade80; }
[data-bs-theme="dark"] .tm-heart.lost { color: #475569; }

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