.kb-key.key-animating {
    background: #2BEFBB !important;
    box-shadow: 0 0 4px rgb(39, 63, 201), 0 0 0 #000;
    color: #222 !important;
    position: relative;
    overflow: visible !important;
    transition: background 0.02s, box-shadow 0.08s, color 0.02s;
    z-index: 10;
}

.kb-key.key-animating::after {
    content: '';
    display: none;
    position: absolute;
    left: 50%;
    top: 50%;
    width: 124px;
    height: 124px;
    border-radius: 50%;
    pointer-events: none;
    background: radial-gradient(#2BEFBB, transparent 80%);
    animation: circle-explode 0.18s cubic-bezier(0.25, 0.4, 0.45, 1.2);
    z-index: 999;
    opacity: 1;
    transform: translate(-50%, -50%) scale(0.2);
}

@keyframes circle-explode {
    0% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(0.2);
    }

    75% {
        opacity: 0.8;
        transform: translate(-50%, -50%) scale(1.05);
    }

    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(1.3);
    }
}

.kb-key.key-wrong-animating {
    background: #f44336 !important;
    box-shadow: 0 0 4px #f44336, 0 0 0 #000;
    color: #fff !important;
    position: relative;
    overflow: visible !important;
    transition: background 0.02s, box-shadow 0.08s, color 0.02s;
    z-index: 10;
}

.kb-key.key-wrong-animating::after {
    content: '';
    display: none;
    position: absolute;
    left: 50%;
    top: 50%;
    width: 124px;
    height: 124px;
    border-radius: 50%;
    pointer-events: none;
    background: radial-gradient(#f44336, transparent 80%);
    animation: circle-explode 0.18s cubic-bezier(0.25, 0.4, 0.45, 1.2);
    z-index: 999;
    opacity: 1;
    transform: translate(-50%, -50%) scale(0.2);
}

#status-keyboard-container {
    position: fixed;
    bottom: 0px;
    right: 0;
    left: 0;
    z-index: 2;
    width: 100%;
    background: rgba(125, 125, 125, .1);
    backdrop-filter: blur(26px);
    -webkit-backdrop-filter: blur(26px);
    padding: 0px 0px 4px 0px;
}

#floating-keyboard {
    margin: 0px auto 46px;
    max-width: 850px;
    background: linear-gradient(135deg, #fefefe 60%, #fefefe 100%);
    border-radius: 16px;
    box-shadow: 0 6px 30px 0 rgba(54, 93, 159, 0.08), 0 1.5px 6px rgba(80, 80, 80, 0.04);
    padding: 20px 16px 14px 16px;
    z-index: 2;
    min-width: 600px;
    min-height: 220px;
    font-family: 'Roboto Mono', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    user-select: none;
    border: 1.5px solid #d3daf3;
    zoom: 0.9;
}

.keyboard-row {
    display: flex;
    justify-content: center;
    margin-bottom: 6px;
}

.kb-key {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    margin-right: 5px;
    border-radius: 6px;
    background: #fff;
    box-shadow: 0 1px 2px #00000013;
    font-size: 16px;
    color: #837f7a;
    border: 1.5px solid #e0e1e6;
    position: relative;
    transition: background 0.18s, border 0.18s;
    flex-direction: column;
}

.kb-key:last-child {
    margin-right: 0;
}

.kb-key:has(.key-top) {
    align-items: flex-start;
}

.kb-key .key-top {
    font-size: 11px;
    line-height: 1;
    margin-bottom: 2px;
    opacity: 0.7;
    margin-left: 12px;
}

.kb-key .key-bottom {
    font-size: 16px;
    line-height: 1;
    font-weight: 500;
    margin-left: 12px;
}

/* 速成码和英文显示控制 */
.kb-key .key-cangjie {
    display: none;
}

.kb-key .key-en {
    display: none;
}

.lower .kb-key .key-en {
    display: none;
}

.upper .kb-key .key-en {
    display: inline;
}

.upper .kb-key .key-en-lower {
    display: none;
}

.lower .kb-key .key-en-lower {
    display: inline;
}

/* 当键盘是 keyboard-cangjie 模式时，显示速成码，隐藏英文 */
#floating-keyboard.keyboard-cangjie .kb-key .key-cangjie {
    display: inline;
}

#floating-keyboard.keyboard-cangjie .kb-key .key-en {
    display: none;
}

#floating-keyboard.keyboard-cangjie .kb-key .key-en-lower {
    display: none;
}

.kb-key.finger-highlight {
    background: #4ee6bb;
    color: #fff;
    border: 2px solid #23b693;
    z-index: 1;
}

.kb-key.label {
    font-size: 13px;
    color: #837f7a;
    width: 60px;
}

/* Redefine width based on keyboard key unit */
.kb-key.wide-125u {
    width: calc(1.25 * 52px);
}

.kb-key.wide-150u {
    width: calc(1.5 * 52px);
}

.kb-key.wide-175u {
    width: calc(1.75 * 52px);
}

.kb-key.wide-200u {
    width: calc(2 * 52px);
}

.kb-key.wide-225u {
    width: calc(2.25 * 52px);
}

.kb-key.wide-275u {
    width: calc(2.75 * 52px);
}

.kb-key.wide-700u {
    width: calc(7 * 52px);
}

.kb-hands {
    position: absolute;
    left: 3px;
    top: 32px;
    pointer-events: none;
    z-index: 0;
    width: 96%;
    opacity: 0.72;
}

@media (max-width: 500px) {
    #floating-keyboard {
        min-width: 330px;
        padding: 9px 2px 8px 2px;
    }

    .kb-key {
        width: 28px;
        height: 28px;
        font-size: 13px;
    }

    .kb-key.label,
    .kb-key.wide,
    .kb-key.extra-large {
        width: 40px;
        font-size: 10px;
    }
}

#keyboard-hand-overlay-container {
    position: absolute;
    width: 884px;
    height: 496px;
    z-index: 1000;
    pointer-events: none;

}

#keyboard-hand-overlay img,
#keyboard-hand-overlay svg {
    height: 100%;
    object-fit: cover;
}

#keyboard-hand-overlay svg {
    width: auto;
    display: none;
}

/* Hand position classes */
.keyboard-hand-image-default-left {
    margin-top: 30px;
    margin-left: -80px;
}

.keyboard-hand-image-default-right {
    margin-top: 30px;
    margin-left: -60px;
}

.keyboard-hand-image-num_1 {
    margin-top: 0px;
    margin-left: -120px;
}

.keyboard-hand-image-num_2 {
    margin-top: -4px;
    margin-left: -114px;
}

.keyboard-hand-image-num_3 {
    margin-top: 0px;
    margin-left: -99px;
}

.keyboard-hand-image-num_4 {
    margin-top: -5px;
    margin-left: -94px;
}

.keyboard-hand-image-num_5 {
    margin-top: 0px;
    margin-left: -80px;
}

.keyboard-hand-image-num_6 {
    margin-top: -10px;
    margin-left: -114px;
}

.keyboard-hand-image-num_7 {
    margin-top: -10px;
    margin-left: -104px;
}

.keyboard-hand-image-num_8 {
    margin-top: -10px;
    margin-left: -95px;
}

.keyboard-hand-image-num_9 {
    margin-top: -10px;
    margin-left: -97px;
}

.keyboard-hand-image-num_0 {
    margin-top: -10px;
    margin-left: -75px;
}

.keyboard-hand-image-a {
    margin-top: 40px;
    margin-left: -100px;
}

.keyboard-hand-image-b {
    margin-top: 40px;
    margin-left: -80px;
}

.keyboard-hand-image-c {
    margin-top: 50px;
    margin-left: -100px;
}

.keyboard-hand-image-d {
    margin-top: 20px;
    margin-left: -100px;
}

.keyboard-hand-image-e {
    margin-top: 20px;
    margin-left: -100px;
}

.keyboard-hand-image-f {
    margin-top: 28px;
    margin-left: -90px;
}

.keyboard-hand-image-g {
    margin-top: 26px;
    margin-left: -84px;
}

.keyboard-hand-image-h {
    margin-top: 18px;
    margin-left: -116px;
}

.keyboard-hand-image-i {
    margin-top: 4px;
    margin-left: -94px;
}

.keyboard-hand-image-j {
    margin-top: 8px;
    margin-left: -98px;
}

.keyboard-hand-image-k {
    margin-top: 9px;
    margin-left: -88px;
}

.keyboard-hand-image-l {
    margin-top: 3px;
    margin-left: -81px;
}

.keyboard-hand-image-n {
    margin-top: 34px;
    margin-left: -111px;
}

.keyboard-hand-image-m {
    margin-top: 25px;
    margin-left: -109px;
}

.keyboard-hand-image-o {
    margin-top: 4px;
    margin-left: -83px;
}

.keyboard-hand-image-p {
    margin-top: 3px;
    margin-left: -75px;
}

.keyboard-hand-image-q {
    margin-top: 18px;
    margin-left: -114px;
}

.keyboard-hand-image-r {
    margin-top: 15px;
    margin-left: -95px;
}

.keyboard-hand-image-s {
    margin-top: 23px;
    margin-left: -105px;
}

.keyboard-hand-image-t {
    margin-top: 18px;
    margin-left: -83px;
}

.keyboard-hand-image-u {
    margin-top: 6px;
    margin-left: -109px;
}

.keyboard-hand-image-v {
    margin-top: 45px;
    margin-left: -91px;
}

.keyboard-hand-image-w {
    margin-top: 17px;
    margin-left: -114px;
}

.keyboard-hand-image-x {
    margin-top: 37px;
    margin-left: -87px;
}

.keyboard-hand-image-y {
    margin-top: 5px;
    margin-left: -112px;
}

.keyboard-hand-image-z {
    margin-top: 34px;
    margin-left: -126px;
}

.keyboard-hand-image-left_shift {
    margin-top: 45px;
    margin-left: -137px;
}

.keyboard-hand-image-right_shift {
    margin-top: 30px;
    margin-left: -60px;
}

.keyboard-hand-image-SEMICOLON {
    margin-top: 9px;
    margin-left: -67px;
}

.keyboard-hand-image-PERIOD {
    margin-top: 49px;
    margin-left: -71px;
}

.keyboard-hand-image-COMMA {
    margin-top: 45px;
    margin-left: -91px;
}

.keyboard-hand-image-SLASH {
    margin-top: 127px;
    margin-left: -165px;
}

.keyboard-hand-image-BRACKET_LEFT {
    margin-top: 3px;
    margin-left: -65px;
}

.keyboard-hand-image-BRACKET_RIGHT {
    margin-top: 6px;
    margin-left: -57px;
}

.keyboard-hand-image-HYPHEN {
    margin-top: -10px;
    margin-left: -63px;
}

.keyboard-hand-image-EQUAL {
    margin-top: -13px;
    margin-left: -52px;
}

.keyboard-hand-image-BACKSLASH {
    margin-top: 6px;
    margin-left: -42px;
}

.keyboard-hand-image-BACKQUOTE {
    margin-top: 1px;
    margin-left: -149px;
}

.keyboard-hand-image-QUOTE {
    margin-top: 6px;
    margin-left: -54px;
}

.keyboard-hand-image-space {
    margin-top: 60px;
    margin-left: -100px;
}

.keyboard-hand-image {
    display: none;
}

#keyboard-hand-overlay.on-input .keyboard-hand-image-default {
    display: block;
}

#keyboard-hand-overlay.on-input-active .keyboard-hand-image-default {
    display: none;
}

#keyboard-left-hand {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 50%;
}

#keyboard-right-hand {
    position: absolute;
    top: 0;
    bottom: 0;
    right: 0;
    width: 50%;
}

#keyboard-hand-overlay.show-left.on-input-active #keyboard-right-hand .keyboard-hand-image-default {
    display: block;
}

#keyboard-hand-overlay.show-right.on-input-active #keyboard-left-hand .keyboard-hand-image-default {
    display: block;
}

#keyboard-hand-overlay.on-input-active .keyboard-hand-image-active {
    display: block;
}

#status-container {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;
}

/* Typing Status Styles */
#typing-status {
    margin: 0 auto;
    max-width: 850px;
    padding: 0 16px;
}

.typing-stats-container {
    border-radius: 8px;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    gap: 30px;

}

.progress-section {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    position: relative;
    flex-direction: column;
}

.progress-bar-wrapper {
    width: 100%;
    height: 8px;
    background: #fff;
    border-radius: 4px;
    overflow: hidden;
    margin-top: 24px;
}

.progress-bar {
    height: 100%;
    background: var(--theme-accent);
    border-radius: 4px;
    transition: width 0.3s ease;
}

.progress-percentage {
    font-size: 16px;
    font-weight: 600;
    color: #666;
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
}

.stats-section {
    display: flex;
    gap: 30px;
    align-items: center;
}

.stat-item {
    display: flex;
    align-items: baseline;
    gap: 4px;
    white-space: nowrap;
}

.stat-label {
    font-size: 14px;
    color: #666;
}

.stat-value {
    font-size: 20px;
    font-weight: 700;
    color: #333;
    font-variant-numeric: tabular-nums;
}

.stat-unit {
    font-size: 13px;
    color: #999;
}

.keyboard-collapse-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: linear-gradient(135deg, #3c55c7 0%, #286cbd 100%);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.keyboard-toggle-button-wrapper {
    display: flex;
    align-items: center;
    position: relative;
}

.keyboard-stat-toggle-row {
    display: flex;
    align-items: center;
    position: relative;
}

.keyboard-stat-toggle-row .blind-kb-disabled-tooltip-right {
    position: absolute;
    left: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%);
}

.keyboard-toggle-button-wrapper-disabled {
    cursor: not-allowed;
}

.keyboard-toggle-disabled {
    opacity: 0.55;
    cursor: not-allowed;
    box-shadow: none;
}

.keyboard-toggle-disabled:hover {
    transform: none;
    box-shadow: none;
}

.keyboard-collapse-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.keyboard-collapse-button:active {
    transform: translateY(0);
}

.keyboard-collapse-button .collapse-icon {
    color: #fff;
    transition: transform 0.3s ease;
    transform: rotate(180deg);
}

#floating-keyboard-container {
    max-height: 500px;
    overflow: hidden;
    transition: max-height 0.4s ease, opacity 0.3s ease, padding 0.4s ease;

    opacity: 1;
}

#floating-keyboard-container.keyboard-hidden {
    max-height: 0;
    height: 0;
    opacity: 0;
    padding: 0;
    margin: 0;
    overflow: hidden;
    pointer-events: none;
}

/* Hidden teaching keyboard must not leave its 46px bottom margin as a blank
   strip above the iPad system keyboard (container is pinned to visualViewport). */
#floating-keyboard-container.keyboard-hidden #floating-keyboard {
    margin: 0;
    min-height: 0;
    padding: 0;
    border-width: 0;
}

#status-keyboard-container:has(#floating-keyboard-container.keyboard-hidden) {
    padding-bottom: 0;
}

#status-keyboard-container:has(#floating-keyboard-container.keyboard-hidden) .keyboard-collapse-button .collapse-icon {
    transform: rotate(0deg);
}

/* ── Short viewports: shrink the on-screen keyboard so it covers less of the
      article and the text being typed stays visible above it. ── */
@media (max-height: 820px) {
    #floating-keyboard {
        zoom: 0.74;
        min-height: 170px;
        margin-bottom: 18px;
        padding: 12px 12px 10px 12px;
    }
}

@media (max-height: 680px) {
    #floating-keyboard {
        zoom: 0.6;
        min-height: 140px;
        margin-bottom: 8px;
        padding: 8px 8px 6px 8px;
    }
}

@media (max-width: 768px) {
    .typing-stats-container {
        flex-direction: column;
        gap: 15px;
        padding: 15px;
    }

    .progress-section {
        width: 100%;
    }

    .stats-section {
        width: 100%;
        justify-content: space-around;
        gap: 20px;
    }
}