/* ========================================
   倉頡模式樣式
   ======================================== */

/* 基礎容器 */
.cangjie {
    line-height: 1.8;
    padding: 20px;
}

/* 字組容器 */
.cangjie .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;
}

/* 字組文字顯示 */
.cangjie .word .display {
    font-size: 36px;
    font-weight: 500;
    color: #aaa;
    line-height: 1.2;
}

/* 字組文字容器 */
.cangjie .word-char-text-container {
    padding: 5px 10px;
}

.cangjie .word.current .word-char-text-container {
    background: #FFF;
    border-radius: 4px;
}

/* 字符編碼顯示 */
.cangjie .chars {
    position: relative;
    margin-bottom: 24px;
    gap: 3px;
}

.cangjie .char .text {
    margin-top: -4px;
    padding: 0 3px;
    font-size: 14px;
    font-weight: 400;
    font-family: 'Roboto Mono', 'Microsoft YaHei', 'PingFang SC', sans-serif;
    color: #999;
    opacity: 0.9;
}

.cangjie .char .code {
    padding: 0 3px;
    font-size: 14px;
    font-weight: 400;
    font-family: 'Roboto Mono', 'Consolas', monospace;
    color: #aaa;
}

/* 當前字符高亮 */
.cangjie .current.display {
    color: #000;
}

.cangjie .char.current {
    font-weight: 600;
}

.cangjie .char.current .code,
.cangjie .char.current .text {
    color: #FFF !important;
}

.cangjie .word .display.current,
.cangjie .char.current {
    border-bottom: none;
}

.cangjie .word .display {
    border-bottom: 4px solid transparent;
}

.cangjie .word .display.current {
    border-bottom: 4px solid #6974ff;
}

/* Compositor word-image tooltip (single overlay; no per-word DOM) */
.typing-word-tooltip-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 86px;
    height: 86px;
    z-index: 50200;
    pointer-events: none;
    visibility: hidden;
}

.typing-word-tooltip-shell {
    position: relative;
    width: 86px;
    height: 86px;
    padding: 6px;
    background: #f6f6f6;
    border: 1px solid #b7b7b7;
    border-radius: 5px;
    box-sizing: border-box;
}

.typing-word-tooltip-shell::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;
}

.typing-word-tooltip-shell::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;
}

.typing-word-tooltip-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

/* 正確輸入樣式 */
.cangjie .char.correct:not(.wrong):not(.once-wronged) {
    background: #ebfde7 !important;
    animation: correct-flash 120ms ease-out forwards;
}

.cangjie .word .display.typed.correct,
.cangjie .char.typed.correct {
    background: transparent !important;
    color: #39c716;
}

.cangjie .correct .code,
.cangjie .correct .text {
    color: #39c716;
}

.cangjie .display.correct {
    color: #39c716;
    background: transparent;
}

.cangjie .display.correct.once-wronged {
    background: transparent !important;
    color: #f29910;
}

.cangjie .char.current {
    background: #000;
}

/* Once Wronged */
.cangjie .word .char.typed.correct.once-wronged,
.cangjie .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;
    }
}

/* 錯誤輸入樣式 */
.cangjie .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;
}

.cangjie .word .char.once-wronged {
    /* background: #fff4d4; */
}

.cangjie .word .char.once-wronged.correct .code,
.cangjie .word .char.once-wronged.correct .text {
    color: #f29910;
}


.cangjie .word .char.typed.wrong .code,
.cangjie .word .char.typed.wrong .text {
    color: #fd6680;
}

.cangjie .word .display.typed.wrong {
    color: #ec8092;
}

.cangjie .char.typed.wrong {
    color: #f44336;
}

@media (prefers-reduced-motion: reduce) {

    .cangjie .char.correct:not(.wrong):not(.once-wronged),
    .cangjie .word .char.typed.correct.once-wronged,
    .cangjie .char.typed.correct.once-wronged,
    .cangjie .word .char.typed.wrong {
        animation: none;
    }
}

/* 曾經輸入錯誤的樣式 */
.cangjie .word .display.typed.correct.once-wronged {
    background: linear-gradient(135deg, #fff9c4 0%, #fff59d 100%);
    color: #f57f17;
}

/* 空格字符特殊處理 */
.cangjie .word .display.space::after {
    content: "⎵";
    color: #95a5a6;
    font-size: 20px;
}

/* 移除邊框底線 */
.cangjie .char {
    border-bottom: none;
    border-radius: 2px;
}

.cangjie .char.current {
    background: #000 !important;
}

.cangjie .char.code-space {
    display: block;
    position: absolute;
    bottom: -24px;
    width: 100%;
    text-align: center;
}

.font-size-small .cangjie .char.code-space {
    bottom: -16px;
}

.font-size-normal .cangjie .char.code-space {
    bottom: -20px;
}

.font-size-large .cangjie .char.code-space {
    bottom: -28px;
}

.font-size-small .cangjie .chars {
    margin-bottom: 24px;
}

.font-size-normal .cangjie .chars {
    margin-bottom: 28px;
}

.font-size-large .cangjie .chars {
    margin-bottom: 36px;
}

.cangjie .char.code-space .text::after {
    content: "\2423";
}

/* ── Compositor cursor (live typing; replaces per-char .current background) ── */
.cangjie .article.compositor-cursor-active .typing-cursor-overlay {
    z-index: 0;
}

.cangjie .article.compositor-cursor-active .char .code,
.cangjie .article.compositor-cursor-active .char .text {
    position: relative;
    z-index: 1;
}

.cangjie .article.compositor-cursor-active:not(.burst-typing) .typing-cursor-shell {
    background: #000;
    border: none;
    border-radius: 2px;
    outline: none;
    animation: none;
    box-shadow: none;
}

.cangjie .article.burst-typing.compositor-cursor-active .typing-cursor-shell {
    background: #000;
    border: none;
    border-radius: 2px;
    outline: none;
    animation: none;
    box-shadow: none;
}

.cangjie .char.cursor-target {
    font-weight: 600;
}

.cangjie .char.cursor-target .code,
.cangjie .char.cursor-target .text {
    color: #FFF !important;
}