/* ==========================================
   移动端虚拟键盘样式 - 响应式设计
   ========================================== */

/* CSS变量 - 支持动态调整 */
:root {
    --vk-key-width: 40px;
    --vk-key-gap: 6px;
    --vk-key-padding: 12px;
    --vk-font-size: 16px;
    --vk-key-height: 46px;
    --vk-row-margin: 12px;
    --vk-max-height: 50vh;
}

@supports (height: 100dvh) {
    :root {
        --vk-max-height: 50dvh;
    }
}

.virtual-keyboard {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    background: rgba(0, 0, 51, 0.95);
    backdrop-filter: blur(10px);
    border-top: 2px solid rgba(255, 215, 0, 0.3);
    transform: translateY(100%);
    transition: transform 0.3s ease-in-out;
    max-height: var(--vk-max-height);
    overflow: hidden;
    box-sizing: border-box;
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

.virtual-keyboard.keyboard-visible {
    transform: translateY(0);
}

.virtual-keyboard-container {
    padding: 15px 10px 5px;
    max-width: 100%;
    margin: 0 auto;
    box-sizing: border-box;
}

.virtual-keyboard-keys {
    display: flex;
    flex-direction: column;
    gap: var(--vk-key-gap);
    align-items: center;
}

.virtual-keyboard-row {
    display: flex;
    justify-content: center;
    gap: var(--vk-key-gap);
    flex-wrap: nowrap;
    width: 100%;
    max-width: 100%;
    margin-bottom: var(--vk-row-margin, 12px);
    padding: 0 3px;
}

.virtual-keyboard-row:last-child {
    margin-bottom: 0;
}

.virtual-keyboard-row.control-row {
    margin-top: 10px;
    justify-content: center;
}

.virtual-key {
    background: rgba(255, 255, 255, 0.3);
    /* Match Learning Mode background */
    border: none;
    /* Match Learning Mode - no border */
    border-radius: 5px;
    /* Match Learning Mode smaller radius */
    color: #fff;
    font-size: var(--vk-font-size);
    font-weight: 400;
    /* Match Learning Mode */
    padding: 0;
    min-width: var(--vk-key-width);
    width: var(--vk-key-width);
    height: var(--vk-key-height, 46px);
    cursor: pointer;
    transition: all 0.1s;
    /* Faster transition like Learning Mode */
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    flex-shrink: 0;
    flex: 1;
    /* Match Learning Mode flex behavior */
    max-width: 100%;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.3);
    /* Match Learning Mode shadow */
}

.virtual-key:active,
.virtual-key.key-pressed,
.virtual-key.active {
    background: rgba(255, 255, 255, 0.5);
    /* Match Learning Mode */
    transform: none;
    /* No transform like Learning Mode */
    box-shadow: none;
}


.virtual-key.special-key {
    background: rgba(100, 100, 100, 0.5);
    /* Match Learning Mode special key */
    font-size: 18px;
    flex: 1.5;
}

.virtual-key-spacer {
    flex: 0;
}

.virtual-key-spacer.half {
    flex: 0.5;
}

.virtual-key-spacer.one-and-half {
    flex: 1.5;
}

.virtual-key.enter-key {
    background: #007AFF;
    /* Match Learning Mode blue */
    color: white;
    flex: 1;
    /* Full width */
    font-size: 18px;
    font-weight: 600;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.3);
    height: calc(var(--vk-key-height, 46px) + 4px);
}

.virtual-key.enter-key:active,
.virtual-key.enter-key.active {
    background: #0051a8;
    /* Match Learning Mode */
    transform: none;
}

.virtual-key.backspace-key {
    min-width: calc(var(--vk-key-width) * 1.5);
    width: calc(var(--vk-key-width) * 1.5);
}

.virtual-key.clear-key {
    min-width: calc(var(--vk-key-width) * 2);
    width: calc(var(--vk-key-width) * 2);
    font-size: calc(var(--vk-font-size) * 0.9);
}

/* 容器内边距按屏幕调整（键盘尺寸变量由 JS 动态计算） */

/* 超小屏幕设备 (< 320px) */
@media screen and (max-width: 320px) {
    .virtual-keyboard-container {
        padding: 10px 5px 3px;
    }
}

/* 平板设备 (769px - 1024px) */
@media screen and (min-width: 769px) and (max-width: 1024px) {
    .virtual-keyboard-container {
        padding: 20px 15px 8px;
    }
}

/* 横屏模式优化 */
.virtual-keyboard.landscape-mode {
    max-height: var(--vk-max-height);
}

.virtual-keyboard.landscape-mode .virtual-keyboard-container {
    padding: 10px 8px 3px;
}

.virtual-keyboard.landscape-mode .virtual-keyboard-keys {
    gap: calc(var(--vk-key-gap) * 0.8);
}

.virtual-keyboard.landscape-mode .virtual-keyboard-row {
    gap: calc(var(--vk-key-gap) * 0.8);
}

/* 短屏幕设备 - 按高度自适应 */
@media screen and (max-height: 700px) {
    :root {
        --vk-key-height: 40px;
        --vk-row-margin: 8px;
    }
}

@media screen and (max-height: 600px) {
    :root {
        --vk-key-height: 36px;
        --vk-row-margin: 6px;
        --vk-max-height: 45vh;
    }

    .virtual-keyboard-container {
        padding: 10px 8px 3px;
    }
}

@supports (height: 100dvh) {
    @media screen and (max-height: 600px) {
        :root {
            --vk-max-height: 45dvh;
        }
    }
}

/* 横屏且低高度的特殊情况 */
@media screen and (max-height: 400px) and (orientation: landscape) {
    :root {
        --vk-max-height: 35vh;
        --vk-key-height: 30px;
        --vk-row-margin: 4px;
        --vk-key-padding: 6px;
        --vk-font-size: 12px;
    }

    .virtual-keyboard-container {
        padding: 8px 5px 2px;
    }

    .virtual-keyboard.landscape-mode {
        max-height: var(--vk-max-height);
    }
}

@supports (height: 100dvh) {
    @media screen and (max-height: 400px) and (orientation: landscape) {
        :root {
            --vk-max-height: 35dvh;
        }
    }
}

/* 虚拟键盘动画效果 */
@keyframes keyPulse {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }

    100% {
        transform: scale(1);
    }
}

.virtual-key.key-pressed {
    animation: keyPulse 0.15s ease-in-out;
}

/* 防止在移动端出现选择和放大镜效果 */
@media screen and (max-width: 1024px) {
    .virtual-keyboard * {
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        -khtml-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
        -webkit-tap-highlight-color: transparent;
    }
}