/* ========================================
   拼音模式樣式
   ======================================== */

/* 基礎容器 */
.pinyin {
    line-height: 1.8;
    padding: 20px;
}

/* 字組容器 */
.pinyin .word {
    background-color: transparent;
    border: none;
    border-radius: 6px;
    margin: 2px;
    min-width: 45px;
    padding: 3px;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

/* 字組文字顯示 */
.pinyin .word .display {
    font-size: 36px;
    font-weight: 500;
    color: #aaa;
    line-height: 1.2;
}

/* 字組文字容器 */
.pinyin .word-char-text-container {
    padding: 5px 10px;
}

.pinyin .word.current .word-char-text-container {
    background: #FFF;
    border-radius: 4px;
}

/* 字符編碼顯示 */
.pinyin .chars {
    position: relative;
    margin-bottom: 6px;
    gap: 2px;
}

.pinyin .char .text {
    margin-top: 0px;
    padding: 3px 2px;
    font-size: 14px;
    font-weight: 400;
    font-family: 'Roboto Mono', 'Consolas', monospace;
    color: #999;
    opacity: 0.9;
}

.font-size-small .pinyin .char .text,
.font-size-small .pinyin .char .code {
    font-size: 14px !important;
}

.font-size-normal .pinyin .char .text,
.font-size-normal .pinyin .char .code {
    font-size: 16px !important;
}

.font-size-large .pinyin .char .text,
.font-size-large .pinyin .char .code {
    font-size: 20px !important;
}

.pinyin .char .code {
    padding: 0 3px;
    font-size: 14px;
    font-weight: 400;
    font-family: 'Roboto Mono', 'Consolas', monospace;
    color: #aaa;
}

/* 當前字符高亮 */
.pinyin .current.display {
    color: #000;
}

.pinyin .char.current {
    font-weight: 600;
}

.pinyin .char.current .code,
.pinyin .char.current .text {
    color: #FFF !important;
}

.pinyin .word .display.current,
.pinyin .char.current {
    border-bottom: none;
}

.pinyin .word .display {
    border-bottom: 4px solid transparent;
}

.pinyin .word .display.current {
    border-bottom: 4px solid #6974ff;
}

.pinyin .char .code {
    display: none;
}

/* 正確輸入樣式 */
.pinyin .char.correct:not(.wrong):not(.once-wronged) {
    background: #ebfde7 !important;
    animation: correct-flash 120ms ease-out forwards;
}

.pinyin .word .display.typed.correct,
.pinyin .char.typed.correct {
    background: transparent !important;
    color: #39c716;
}

.pinyin .correct .code,
.pinyin .correct .text {
    color: #39c716;
}

.pinyin .display.correct {
    color: #39c716;
    background: transparent;
}

.pinyin .display.correct.once-wronged {
    background: transparent !important;
    color: #f29910;
}

.pinyin .char.current {
    background: #000;
}

/* Once Wronged */
.pinyin .word .char.typed.correct.once-wronged,
.pinyin .char.typed.correct.once-wronged {
    background: #fff4d4 !important;
    animation: correct-flash-wronged 120ms ease-out forwards;
}

@keyframes wrong-shake {

    0%,
    100% {
        transform: translateX(0);
    }

    20% {
        transform: translateX(-4px);
    }

    40% {
        transform: translateX(4px);
    }

    60% {
        transform: translateX(-3px);
    }

    80% {
        transform: translateX(2px);
    }
}

@keyframes correct-flash {
    0% {
        transform: translateY(0);
        opacity: 0.88;
    }

    25% {
        transform: translateY(-5px);
        opacity: 1;
    }

    65% {
        transform: translateY(1px);
        opacity: 1;
    }

    100% {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes correct-flash-wronged {
    0% {
        transform: translateY(0);
        opacity: 0.88;
    }

    25% {
        transform: translateY(-5px);
        opacity: 1;
    }

    65% {
        transform: translateY(1px);
        opacity: 1;
    }

    100% {
        transform: translateY(0);
        opacity: 1;
    }
}

/* 錯誤輸入樣式 */
.pinyin .word .char.typed.wrong {
    color: #fd6680;
    background: #ffebee;
    box-shadow: 0 0 4px rgba(244, 67, 54, 0.35);
    animation: wrong-shake 120ms ease-out forwards;
}



.pinyin .word .char.correct.once-wronged .code,
.pinyin .word .char.correct.once-wronged .text {
    color: #f29910;
}

.pinyin .word .char.typed.wrong .code,
.pinyin .word .char.typed.wrong .text {
    color: #fd6680;
}

.pinyin .word .display.typed.wrong {
    color: #ec8092;
}

.pinyin .char.typed.wrong {
    color: #f44336;
}

@media (prefers-reduced-motion: reduce) {

    .pinyin .char.correct:not(.wrong):not(.once-wronged),
    .pinyin .word .char.typed.correct.once-wronged,
    .pinyin .char.typed.correct.once-wronged,
    .pinyin .word .char.typed.wrong {
        animation: none;
    }
}

/* 曾經輸入錯誤的樣式 */
.pinyin .word .display.typed.correct.once-wronged {
    background: linear-gradient(135deg, #fff9c4 0%, #fff59d 100%);
    color: #f57f17;
}

/* 空格字符特殊處理 */
.pinyin .word .display.space::after {
    content: "⎵";
    color: #95a5a6;
    font-size: 20px;
}

/* 移除邊框底線 */
.pinyin .char {
    border-bottom: none;
    border-radius: 2px;
}

.pinyin .char.current {
    background: #000 !important;
}

.pinyin .char.code-space {
    display: block;
    position: absolute;
    bottom: -24px;
    width: 100%;
    text-align: center;
}

.pinyin .char.code-space .text::after {
    content: "\2423";
}

/* ── Compositor cursor (live typing; replaces per-char .current background) ── */
.pinyin .article.compositor-cursor-active .typing-cursor-overlay {
    z-index: 0;
}

.pinyin .article.compositor-cursor-active .char .code,
.pinyin .article.compositor-cursor-active .char .text {
    position: relative;
    z-index: 1;
}

.pinyin .article.compositor-cursor-active:not(.burst-typing) .typing-cursor-shell {
    background: #000;
    border: none;
    border-radius: 2px;
    outline: none;
    animation: none;
    box-shadow: none;
}

.pinyin .article.burst-typing.compositor-cursor-active .typing-cursor-shell {
    background: #000;
    border: none;
    border-radius: 2px;
    outline: none;
    animation: none;
    box-shadow: none;
}

.pinyin .char.cursor-target {
    font-weight: 600;
}

.pinyin .char.cursor-target .code,
.pinyin .char.cursor-target .text {
    color: #FFF !important;
}