/* ========================================
   拼音模式樣式
   ======================================== */

/* 基礎容器 */
.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 .word-img-container {
    display: none;
}

/* 當前字符的圖片提示框 */
.pinyin .word.current .word-img-container {
    display: none;
    position: absolute;
    top: -106px;
    width: 86px;
    height: 86px;
    padding: 6px;
    background: #f6f6f6;
    border: 1px solid #b7b7b7;
    border-radius: 5px;
}

.pinyin .word-img-container {
    display: none;
}

.word-tooltips-active .pinyin .current .word-img-container {
    display: block;
}

.pinyin .word.current .word-img-container img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* 提示框三角形箭頭 - 邊框層 */
.pinyin .word.current .word-img-container::before {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 11px solid transparent;
    border-right: 11px solid transparent;
    border-top: 10px solid #b7b7b7;
    z-index: 1;
}

/* 提示框三角形箭頭 - 填充層 */
.pinyin .word.current .word-img-container::after {
    content: "";
    position: absolute;
    top: calc(100% - 0.5px);
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-top: 9px solid #f6f6f6;
    z-index: 2;
}

.pinyin .char .code {
    display: none;
}

/* 正確輸入樣式 */
.pinyin .char.correct:not(.wrong):not(.once-wronged) {
    background: #ebfde7 !important;
    animation: correct-flash 240ms 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 240ms 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 240ms 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";
}