/* ═══════════════════════════════════════════════════════════════════
   Tone Mark Trainer (D87)
   Embedded in /Articles/HowToTypePinyinWithToneMarks — an article widget,
   not a /games page, so it wears the article's own indigo → fuchsia rather
   than claiming one of the game heroes.

   Everything colour-neutral uses Bootstrap's own CSS variables so the widget
   follows the site's dark mode without a second palette to keep in step.
   ═══════════════════════════════════════════════════════════════════ */

.tmt {
    --tmt-a: #4338ca;
    --tmt-b: #7c3aed;
    --tmt-c: #c026d3;
    border-radius: 0.75rem;
    overflow: hidden;
}

.tmt-hero {
    background: linear-gradient(135deg, var(--tmt-a) 0%, var(--tmt-b) 55%, var(--tmt-c) 100%);
    color: #fff;
}

/* ── Level picker ────────────────────────────────────────────────── */
.tmt-levels {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.6rem;
}

.tmt-level {
    border: 2px solid var(--bs-border-color);
    background: var(--bs-body-bg);
    color: var(--bs-body-color);
    border-radius: 0.6rem;
    padding: 0.7rem 0.75rem;
    text-align: left;
    transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease;
}

.tmt-level:hover,
.tmt-level:focus-visible {
    transform: translateY(-2px);
    border-color: var(--tmt-b);
    box-shadow: 0 6px 18px rgba(124, 58, 237, .25);
}

.tmt-level .tmt-level-name {
    font-weight: 700;
    display: block;
}

.tmt-level .tmt-level-sub {
    font-size: .78rem;
    opacity: .75;
    display: block;
}

.tmt-level .tmt-best {
    font-size: .72rem;
    font-weight: 700;
    color: var(--tmt-b);
}

.tmt-level[data-tier="1"] { border-left: 6px solid #10b981; }
.tmt-level[data-tier="2"] { border-left: 6px solid #0ea5e9; }
.tmt-level[data-tier="3"] { border-left: 6px solid #f59e0b; }
.tmt-level[data-tier="4"] { border-left: 6px solid #e11d48; }

/* ── HUD ─────────────────────────────────────────────────────────── */
.tmt-hud {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: .35rem .9rem;
    font-weight: 700;
}

.tmt-hud small {
    display: block;
    font-weight: 400;
    font-size: .7rem;
    opacity: .7;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.tmt-combo {
    font-weight: 800;
    color: #f59e0b;
    transition: transform .15s ease;
}

.tmt-combo.tmt-combo-hot {
    color: #e11d48;
    transform: scale(1.15);
}

.tmt-timerbar {
    height: 6px;
    border-radius: 3px;
    background: var(--bs-secondary-bg);
    overflow: hidden;
}

.tmt-timerbar > span {
    display: block;
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #10b981, #f59e0b, #e11d48);
    transform-origin: left center;
}

/* ── Prompt ──────────────────────────────────────────────────────── */
.tmt-prompt {
    font-size: clamp(2.1rem, 9vw, 3.4rem);
    font-weight: 800;
    line-height: 1.15;
    letter-spacing: .02em;
    text-align: center;
    margin: .35rem 0 .1rem;
    /* Tone marks sit above the x-height; a tight line box clips ǚ on Android. */
    padding-top: .15rem;
}

.tmt-prompt-hint {
    text-align: center;
    font-size: .85rem;
    opacity: .75;
}

.tmt-build {
    text-align: center;
    font-size: clamp(1.6rem, 7vw, 2.4rem);
    font-weight: 700;
    min-height: 2.6rem;
    letter-spacing: .04em;
}

.tmt-build .tmt-slot {
    display: inline-block;
    min-width: 1.1ch;
    border-bottom: 3px solid var(--tmt-b);
    color: var(--tmt-c);
}

/* ── Options ─────────────────────────────────────────────────────── */
.tmt-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: .55rem;
}

.tmt-option {
    border: 2px solid var(--bs-border-color);
    background: var(--bs-body-bg);
    color: var(--bs-body-color);
    border-radius: .6rem;
    padding: .75rem .5rem;
    font-size: 1.6rem;
    font-weight: 700;
    transition: transform .1s ease, background-color .15s ease, border-color .15s ease;
}

.tmt-option:hover:not(:disabled) {
    transform: translateY(-2px);
    border-color: var(--tmt-b);
}

.tmt-option .tmt-key {
    display: block;
    font-size: .68rem;
    font-weight: 600;
    opacity: .55;
}

.tmt-option.tmt-right {
    background: #10b981;
    border-color: #10b981;
    color: #fff;
    animation: tmt-pop .32s ease;
}

.tmt-option.tmt-wrong {
    background: #e11d48;
    border-color: #e11d48;
    color: #fff;
    animation: tmt-shake .34s ease;
}

/* ── Vowel palette (level 2) ─────────────────────────────────────── */
.tmt-palette {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: .3rem;
    max-width: 24rem;
    margin: 0 auto;
}

.tmt-palette-row-label {
    grid-column: 1 / -1;
    font-size: .7rem;
    opacity: .6;
    text-transform: uppercase;
    letter-spacing: .06em;
    margin-top: .25rem;
}

.tmt-vowel {
    border: 1px solid var(--bs-border-color);
    background: var(--bs-body-bg);
    color: var(--bs-body-color);
    border-radius: .45rem;
    padding: .35rem 0 .5rem;
    font-size: 1.35rem;
    font-weight: 700;
    line-height: 1.4;
    transition: transform .1s ease, background-color .15s ease;
}

.tmt-vowel:hover:not(:disabled) {
    transform: translateY(-2px);
    background: var(--bs-secondary-bg);
}

.tmt-vowel.tmt-right {
    background: #10b981;
    border-color: #10b981;
    color: #fff;
    animation: tmt-pop .32s ease;
}

.tmt-vowel.tmt-wrong {
    background: #e11d48;
    border-color: #e11d48;
    color: #fff;
    animation: tmt-shake .34s ease;
}

/* ── Typed answer (level 4) ──────────────────────────────────────── */
.tmt-typebox {
    max-width: 18rem;
    margin: 0 auto;
    font-size: 1.35rem;
    font-weight: 700;
    text-align: center;
    letter-spacing: .08em;
}

/* ── Feedback ────────────────────────────────────────────────────── */
.tmt-feedback {
    min-height: 2.5rem;
    text-align: center;
    font-weight: 600;
}

.tmt-float {
    position: absolute;
    left: 50%;
    top: 40%;
    transform: translateX(-50%);
    font-size: 1.6rem;
    font-weight: 800;
    color: #10b981;
    pointer-events: none;
    animation: tmt-float 900ms ease-out forwards;
    text-shadow: 0 2px 10px rgba(0, 0, 0, .25);
}

.tmt-stage {
    position: relative;
}

/* A burst of six sparks, CSS only — no library, no images, nothing to load. */
.tmt-spark {
    position: absolute;
    left: 50%;
    top: 45%;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    pointer-events: none;
    animation: tmt-spark 700ms ease-out forwards;
}

.tmt-levelup {
    animation: tmt-pop .5s ease;
}

.tmt-dots {
    display: flex;
    gap: .25rem;
    justify-content: center;
}

.tmt-dot {
    width: .55rem;
    height: .55rem;
    border-radius: 50%;
    background: var(--bs-secondary-bg);
    border: 1px solid var(--bs-border-color);
}

.tmt-dot.tmt-dot-hit { background: #10b981; border-color: #10b981; }
.tmt-dot.tmt-dot-miss { background: #e11d48; border-color: #e11d48; }
.tmt-dot.tmt-dot-now { background: var(--tmt-b); border-color: var(--tmt-b); }

@keyframes tmt-pop {
    0% { transform: scale(.85); }
    60% { transform: scale(1.08); }
    100% { transform: scale(1); }
}

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

@keyframes tmt-float {
    0% { opacity: 1; transform: translate(-50%, 0) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -70px) scale(1.25); }
}

@keyframes tmt-spark {
    0% { opacity: 1; transform: translate(0, 0) scale(1); }
    100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(.35); }
}

/* Respect the visitor's own setting — every effect here is decorative. */
@media (prefers-reduced-motion: reduce) {
    .tmt-option,
    .tmt-vowel,
    .tmt-level,
    .tmt-combo,
    .tmt-float,
    .tmt-spark,
    .tmt-levelup {
        animation: none !important;
        transition: none !important;
    }

    .tmt-float { opacity: 1; }
}

@media (min-width: 576px) {
    .tmt-options { grid-template-columns: repeat(4, 1fr); }
    .tmt-palette { grid-template-columns: repeat(8, 1fr); max-width: 32rem; }
}
