/* ═══════════════════════════════════════════════════════════════════
   Hanzi Hangman — name the pinyin syllables that spell the hidden word (D82)

   Hero: ink → lantern red → amber (#1a1523 → #b91c1c → #f59e0b). Deliberately
   distinct from Cloze's violet, Word Search's green, Grammar Gauntlet's cyan,
   Look-Alike's teal, Tone Pair Arcade's rose and Character Builder's indigo —
   every game hero reads as its own place.

   The gallows is a row of paper lanterns, one per wrong guess the level allows.
   It carries the same information a hangman drawing does — how close you are to
   losing this word — with an object from the culture the page is teaching rather
   than an execution on a page for language learners, and unlike a six-part figure
   it scales to a level that allows three wrong guesses or eight.
   ═══════════════════════════════════════════════════════════════════ */

/* ── Hero ────────────────────────────────────────────────────────── */
.hh-hero {
    background: linear-gradient(135deg, #1a1523 0%, #b91c1c 58%, #f59e0b 100%);
    border-radius: 0.5rem;
}

/* ── HUD ─────────────────────────────────────────────────────────── */
.hh-hud {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem 1rem;
    margin-bottom: 0.6rem;
}

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

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

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

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

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

/* ── The stage ───────────────────────────────────────────────────── */
.hh-stage {
    position: relative;
    min-height: 24rem;
}

.hh-shake {
    animation: hh-shake 0.32s ease;
}

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

/* The layer score popups and sparks are thrown onto. Empty on the server and
   pointer-inert, so it can never intercept a click meant for the board. */
.hh-effects {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 4;
}

.hh-spark {
    position: absolute;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    opacity: 0.95;
    animation: hh-spark 0.85s ease-out forwards;
}

.hh-spark.ink { background: #b91c1c; }
.hh-spark.gold { background: #f59e0b; }

@keyframes hh-spark {
    to {
        transform: translate(var(--dx), var(--dy)) scale(0.2);
        opacity: 0;
    }
}

.hh-popup {
    position: absolute;
    transform: translate(-50%, 0);
    font-weight: 800;
    font-size: 1.05rem;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
    animation: hh-popup 1.05s ease-out forwards;
    white-space: nowrap;
}

.hh-popup.good { color: #16a34a; }
.hh-popup.bad { color: #dc2626; }

@keyframes hh-popup {
    0% { opacity: 0; transform: translate(-50%, 0.4rem) scale(0.85); }
    25% { opacity: 1; transform: translate(-50%, -0.4rem) scale(1.05); }
    100% { opacity: 0; transform: translate(-50%, -2.6rem) scale(1); }
}

/* ── The lanterns ───────────────────────────────────────────────── */
.hh-lantern-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 0.6rem;
}

.hh-lanterns {
    display: flex;
    align-items: flex-end;
    gap: 0.3rem;
    min-height: 46px;
}

.hh-lantern {
    display: inline-block;
    width: 26px;
    transition: opacity 0.3s ease, transform 0.3s ease, filter 0.3s ease;
}

.hh-lantern svg {
    display: block;
    width: 100%;
    height: auto;
}

.hh-lantern .hh-body {
    fill: #dc2626;
    stroke: #7f1d1d;
    stroke-width: 1.5;
}

.hh-lantern .hh-cap {
    fill: #7f1d1d;
}

.hh-lantern .hh-rib {
    stroke: #7f1d1d;
    stroke-width: 1;
    opacity: 0.55;
}

.hh-lantern .hh-flame {
    fill: #fde68a;
    animation: hh-flicker 1.6s ease-in-out infinite;
}

.hh-lantern .hh-tassel {
    stroke: #b45309;
    stroke-width: 1.5;
}

@keyframes hh-flicker {
    0%, 100% { opacity: 1; }
    45% { opacity: 0.6; }
    70% { opacity: 0.9; }
}

/* Put out: grey, dimmed, and dropped a little, so the row reads at a glance. */
.hh-lantern.out {
    opacity: 0.35;
    transform: translateY(3px) scale(0.9);
    filter: grayscale(1);
}

.hh-lantern.out .hh-flame {
    opacity: 0;
    animation: none;
}

.hh-lantern-count {
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
}

.hh-lantern-count small {
    display: block;
    font-weight: 400;
    font-size: 0.72rem;
    color: var(--bs-secondary-color);
}

/* ── The hidden word ─────────────────────────────────────────────── */
.hh-word {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
    margin: 0.5rem 0 0.75rem;
}

.hh-slot {
    min-width: 4.5rem;
    padding: 0.4rem 0.5rem 0.5rem;
    border: 2px dashed var(--bs-border-color);
    border-radius: 0.6rem;
    text-align: center;
    background: var(--bs-tertiary-bg);
    transition: border-color 0.25s ease, background 0.25s ease;
}

.hh-slot.solved {
    border-style: solid;
    border-color: #16a34a;
    background: rgba(22, 163, 74, 0.08);
}

.hh-slot-pinyin {
    min-height: 1.15rem;
    font-size: 0.85rem;
    font-weight: 700;
    color: #b45309;
}

.hh-slot-char {
    font-size: 2.4rem;
    line-height: 1.15;
    font-weight: 700;
}

.hh-slot:not(.solved) .hh-slot-char {
    color: var(--bs-secondary-color);
    opacity: 0.5;
}

.hh-slot-dashes {
    font-family: var(--bs-font-monospace, monospace);
    letter-spacing: 0.12em;
    font-size: 0.8rem;
    color: var(--bs-secondary-color);
}

/* The ink drop: a solved character lands rather than appearing. */
.hh-slot.just-solved .hh-slot-char {
    animation: hh-ink 0.5s ease-out;
}

@keyframes hh-ink {
    0% { opacity: 0; transform: scale(1.9); filter: blur(6px); }
    60% { opacity: 1; transform: scale(0.95); filter: blur(0); }
    100% { transform: scale(1); }
}

/* Characters the player never got are shown at the end in a colour that says so. */
.hh-word.hh-revealed-late .hh-slot {
    border-color: #d97706;
    background: rgba(217, 119, 6, 0.08);
}

/* ── The clue ────────────────────────────────────────────────────── */
.hh-clue {
    text-align: center;
    margin-bottom: 0.75rem;
}

.hh-clue-meaning {
    font-size: 1.25rem;
    font-weight: 700;
}

.hh-clue-meta {
    font-size: 0.8rem;
    color: var(--bs-secondary-color);
}

/* ── The syllable board ──────────────────────────────────────────── */
.hh-board {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.35rem;
    margin-bottom: 0.75rem;
}

.hh-key {
    min-width: 3.6rem;
    padding: 0.35rem 0.6rem;
    border: 1px solid var(--bs-border-color);
    border-radius: 0.5rem;
    background: var(--bs-body-bg);
    color: var(--bs-body-color);
    font-weight: 700;
    font-size: 0.98rem;
    transition: transform 0.12s ease, background 0.2s ease, border-color 0.2s ease;
}

.hh-key:hover:not(:disabled) {
    border-color: #b91c1c;
    transform: translateY(-2px);
}

.hh-key.hit {
    background: #16a34a;
    border-color: #16a34a;
    color: #fff;
}

.hh-key.miss {
    background: var(--bs-secondary-bg);
    color: var(--bs-secondary-color);
    text-decoration: line-through;
    opacity: 0.6;
}

.hh-key:disabled {
    cursor: default;
}

/* ── Typing a syllable ───────────────────────────────────────────── */
.hh-guess {
    display: flex;
    justify-content: center;
    gap: 0.4rem;
    margin-bottom: 0.4rem;
}

.hh-guess input {
    max-width: 11rem;
}

.hh-guess-note {
    min-height: 1.1rem;
    text-align: center;
    font-size: 0.82rem;
    color: #b45309;
}

/* ── The stroke hint ─────────────────────────────────────────────── */
.hh-strokes {
    display: none;
    text-align: center;
    margin-bottom: 0.6rem;
}

.hh-strokes.shown {
    display: block;
}

.hh-stroke-target {
    display: inline-block;
    border: 1px dashed var(--bs-border-color);
    border-radius: 0.5rem;
    background: var(--bs-tertiary-bg);
    /* The 田字格 guides, drawn in CSS so the hint box reads as writing paper. */
    background-image:
        linear-gradient(to right, var(--bs-border-color) 1px, transparent 1px),
        linear-gradient(to bottom, var(--bs-border-color) 1px, transparent 1px);
    background-size: 50% 50%;
    background-position: center;
}

.hh-stroke-note {
    font-size: 0.8rem;
    color: var(--bs-secondary-color);
    min-height: 1.1rem;
}

/* ── The reveal ──────────────────────────────────────────────────── */
.hh-reveal {
    display: none;
    border-top: 1px solid var(--bs-border-color);
    padding-top: 0.75rem;
    text-align: center;
}

.hh-reveal.shown {
    display: block;
    animation: hh-fade 0.3s ease;
}

@keyframes hh-fade {
    from { opacity: 0; transform: translateY(0.4rem); }
    to { opacity: 1; transform: none; }
}

.hh-verdict {
    font-weight: 800;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    font-size: 0.85rem;
}

.hh-verdict.right { color: #16a34a; }
.hh-verdict.wrong { color: #dc2626; }

.hh-reveal-word {
    display: flex;
    align-items: baseline;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0.2rem 0;
}

.hh-reveal-hanzi {
    font-size: 2rem;
    font-weight: 700;
    text-decoration: none;
}

.hh-reveal-pinyin {
    font-size: 1.05rem;
    font-weight: 700;
    color: #b45309;
}

.hh-reveal-meaning {
    color: var(--bs-secondary-color);
}

.hh-next-row {
    margin-top: 0.6rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.hh-next-hint {
    font-size: 0.78rem;
    color: var(--bs-secondary-color);
}

/* ── Buttons and pickers ─────────────────────────────────────────── */
.hh-btn-primary {
    background: #b91c1c;
    border-color: #b91c1c;
    color: #fff;
    font-weight: 700;
}

.hh-btn-primary:hover,
.hh-btn-primary:focus {
    background: #991b1b;
    border-color: #991b1b;
    color: #fff;
}

.hh-picker {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
}

.hh-picker-label {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--bs-secondary-color);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.hh-pick-btn {
    padding: 0.25rem 0.7rem;
    border: 1px solid var(--bs-border-color);
    border-radius: 999px;
    background: var(--bs-body-bg);
    color: var(--bs-body-color);
    font-size: 0.85rem;
    font-weight: 600;
}

.hh-pick-btn.active {
    background: #b91c1c;
    border-color: #b91c1c;
    color: #fff;
}

/* ── Overlays ────────────────────────────────────────────────────── */
.hh-overlay {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    text-align: center;
    padding: 1rem;
    background: var(--bs-body-bg);
    border-radius: 0.5rem;
}

.hh-big-icon {
    font-size: 2.6rem;
    color: #b91c1c;
}

.hh-final-score {
    font-size: 3rem;
    font-weight: 800;
    line-height: 1;
    color: #b91c1c;
}

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

/* ── Worked example (the JavaScript-off half) ────────────────────── */
.hh-example-slot {
    min-width: 4.5rem;
    padding: 0.4rem 0.5rem 0.5rem;
    border: 2px dashed var(--bs-border-color);
    border-radius: 0.6rem;
    text-align: center;
    background: var(--bs-tertiary-bg);
}

.hh-example-slot.solved {
    border-style: solid;
    border-color: #16a34a;
    background: rgba(22, 163, 74, 0.08);
}

.hh-example-key {
    display: inline-block;
    min-width: 3.4rem;
    margin: 0.15rem;
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--bs-border-color);
    border-radius: 0.5rem;
    font-weight: 700;
    font-size: 0.9rem;
}

.hh-example-key.hit {
    background: #16a34a;
    border-color: #16a34a;
    color: #fff;
}

/* ── Sidebar study list ──────────────────────────────────────────── */
.hh-missed-row {
    padding: 0.35rem 0.4rem;
    border-bottom: 1px solid var(--bs-border-color);
}

.hh-missed-row:last-child {
    border-bottom: none;
}

.hh-missed-row a,
.hh-missed-row > span {
    font-size: 1.05rem;
    font-weight: 700;
}

/* ── Accessibility ───────────────────────────────────────────────── */
.hh-visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

@media (max-width: 575.98px) {
    .hh-slot {
        min-width: 3.6rem;
    }

    .hh-slot-char {
        font-size: 2rem;
    }

    .hh-key {
        min-width: 3.1rem;
        font-size: 0.9rem;
    }
}

/* Every animation on this page is decoration over a change the HUD and the live
   region have already reported, so switching them all off costs nothing. */
@media (prefers-reduced-motion: reduce) {
    .hh-shake,
    .hh-lantern .hh-flame,
    .hh-slot.just-solved .hh-slot-char,
    .hh-reveal.shown {
        animation: none;
    }

    .hh-key,
    .hh-slot,
    .hh-lantern,
    .hh-heart {
        transition: none;
    }
}
