/**
 * 打字练习工具样式
 * 全屏100%高度布局 - 纯vh比例版本
 */

/* 全屏容器 */
.typing-fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: var(--bg-color);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    z-index: 1000;
}

/* 顶部导航栏 - 5vh */
.typing-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2vw;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    height: 5vh;
}

.typing-header .back-btn {
    display: flex;
    align-items: center;
    gap: 0.5vw;
    color: var(--text-color);
    text-decoration: none;
    font-weight: 500;
    font-size: 1.8vh;
    padding: 0.8vh 1.2vw;
    border-radius: var(--radius-sm);
    transition: background 0.2s;
}

.typing-header .back-btn:hover {
    background: var(--bg-color);
}

.typing-header .title {
    font-size: 2.2vh;
    font-weight: 500;
    color: #4b5563;
}

.typing-header .settings-btn {
    background: none;
    border: none;
    color: var(--text-light);
    font-size: 2.4vh;
    cursor: pointer;
    padding: 0.6vh;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

.typing-header .settings-btn:hover {
    background: var(--bg-color);
    color: var(--text-color);
}

/* 主内容区 - 95vh */
.typing-main {
    flex: 1;
    display: flex;
    overflow: hidden;
    height: 95vh;
}

/* 侧边栏 - 关卡选择 */
.typing-sidebar {
    width: 18vw;
    min-width: 200px;
    max-width: 280px;
    background: var(--card-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    height: 100%;
}

.typing-sidebar.collapsed {
    width: 0;
    min-width: 0;
    overflow: hidden;
}

.sidebar-header {
    padding: 1.5vh 1vw;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.sidebar-header h3 {
    font-size: 1.6vh;
    color: var(--text-light);
    margin-bottom: 0.8vh;
}

.progress-mini {
    background: var(--bg-color);
    border-radius: 50px;
    height: 1vh;
    overflow: hidden;
}

.progress-mini .fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    transition: width 0.3s;
}

.progress-text {
    font-size: 1.4vh;
    color: var(--text-light);
    margin-top: 0.5vh;
}

.level-list {
    flex: 1;
    overflow-y: auto;
    padding: 1vh 0.5vw;
}

.level-item {
    display: flex;
    align-items: center;
    gap: 0.8vw;
    padding: 1.2vh 0.8vw;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 0.5vh;
}

.level-item:hover {
    background: var(--bg-color);
}

.level-item.active {
    background: var(--primary-color);
    color: white;
}

.level-item.completed .level-num {
    background: var(--success-color);
    color: white;
}

.level-item.locked {
    opacity: 0.5;
    cursor: not-allowed;
}

.level-num {
    width: 4vh;
    height: 4vh;
    border-radius: 50%;
    background: var(--bg-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 1.6vh;
    flex-shrink: 0;
}

.level-item.active .level-num {
    background: rgba(255,255,255,0.2);
}

.level-info-mini {
    flex: 1;
    min-width: 0;
}

.level-info-mini .name {
    font-size: 1.5vh;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.level-info-mini .keys {
    font-size: 1.2vh;
    color: var(--text-light);
    font-family: monospace;
    margin-top: 0.3vh;
}

.level-item.active .level-info-mini .keys {
    color: rgba(255,255,255,0.7);
}

.level-stars {
    font-size: 1.4vh;
    flex-shrink: 0;
}

/* 练习区域 */
.typing-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 1vh 2vw;
    overflow: hidden;
    height: 100%;
}

/* 当前关卡信息 - 7vh */
.current-level-info {
    text-align: center;
    height: 7vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    flex-shrink: 0;
}

.current-level-info h2 {
    font-size: 2.4vh;
    color: var(--primary-color);
    margin-bottom: 0.3vh;
}

.current-level-info p {
    color: var(--text-light);
    font-size: 1.6vh;
}

/* 统计条 - 8vh */
.stats-bar {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 4vw;
    background: var(--card-bg);
    border-radius: var(--radius);
    height: 8vh;
    flex-shrink: 0;
}

.stat-item {
    text-align: center;
}

.stat-item .value {
    font-size: 3vh;
    font-weight: 700;
    color: var(--primary-color);
}

.stat-item .label {
    font-size: 1.4vh;
    color: var(--text-light);
    margin-top: 0.2vh;
}

/* 文本显示区 - 14vh */
.text-display-wrapper {
    height: 14vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5vh 0;
    flex-shrink: 0;
}

.text-display {
    width: 100%;
    height: 100%;
    font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 4.5vh;
    line-height: 1.5;
    padding: 1vh 2vw;
    background: #0a0f1a;
    border-radius: var(--radius);
    text-align: center;
    letter-spacing: 0.08em;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    border: 1px solid var(--border-color);
    box-sizing: border-box;
}

.text-display .char {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.1s;
    min-width: 0.55em;
}

.text-display .correct {
    color: var(--success-color);
}

.text-display .wrong {
    color: var(--danger-color);
    background: rgba(248, 113, 113, 0.2);
    border-radius: 0.5vh;
}

.text-display .current {
    background: var(--primary-color);
    color: white;
    padding: 0 0.12em;
    border-radius: 0.5vh;
    animation: pulse 1s infinite;
}

.text-display .pending {
    color: var(--text-light);
}

/* 空格 - CSS绘制的下划线样式 */
.text-display .space {
    min-width: 1.1em;
    margin: 0 0.05em;
}

.text-display .space .space-bar {
    display: inline-block;
    width: 0.9em;
    height: 0.12em;
    background: var(--secondary-color);
    border-radius: 0.3vh;
    vertical-align: middle;
    position: relative;
    top: 0.12em;
}

.text-display .space.correct .space-bar {
    background: var(--success-color);
}

.text-display .space.current {
    background: var(--primary-color);
    padding: 0.08em 0.15em;
}

.text-display .space.current .space-bar {
    background: white;
}

.text-display .space.pending .space-bar {
    background: var(--text-light);
    opacity: 0.6;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* 控制按钮 - 6vh */
.controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 2vw;
    height: 6vh;
    flex-shrink: 0;
}

.controls .btn {
    font-size: 1.8vh;
    padding: 1vh 2vw;
}

.controls .btn-lg {
    font-size: 2vh;
    padding: 1.2vh 2.5vw;
}

/* 键盘区域 - 剩余空间约55vh */
.keyboard-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 0;
    padding: 0.5vh 0;
}

.keyboard-hands-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    gap: 1vh;
}

/* 虚拟手 */
.virtual-hands {
    display: flex;
    justify-content: center;
    gap: 8vw;
    height: 18vh;
    flex-shrink: 0;
}

.virtual-hand {
    position: relative;
    display: flex;
    align-items: flex-end;
    gap: 0.8vh;
    padding-bottom: 3vh;
}

.virtual-hand .hand-palm {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    height: 5.6vh;
    background: rgba(100, 116, 139, 0.3);
    border-radius: 2vh 2vh 3vh 3vh;
}

.virtual-hand .finger {
    width: 3.5vh;
    border-radius: 1.5vh 1.5vh 1vh 1vh;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    position: relative;
    z-index: 1;
}

.virtual-hand .finger span {
    font-size: 1.2vh;
    color: white;
    font-weight: 600;
    opacity: 0.9;
}

/* 手指高度和颜色 */
.virtual-hand .finger.pinky {
    height: 8vh;
    background: linear-gradient(180deg, #ef4444 0%, #dc2626 100%);
}

.virtual-hand .finger.ring {
    height: 11vh;
    background: linear-gradient(180deg, #f97316 0%, #ea580c 100%);
}

.virtual-hand .finger.middle {
    height: 12vh;
    background: linear-gradient(180deg, #eab308 0%, #ca8a04 100%);
}

.virtual-hand .finger.index {
    height: 10vh;
    background: linear-gradient(180deg, #22c55e 0%, #16a34a 100%);
}

.virtual-hand .finger.thumb {
    height: 6vh;
    width: 4vh;
    background: linear-gradient(180deg, #8b5cf6 0%, #7c3aed 100%);
    border-radius: 1.2vh;
    align-self: flex-end;
    margin-bottom: 1vh;
}

/* 左手拇指位置 */
.left-hand .finger.thumb {
    margin-left: 1vh;
}

/* 右手拇指位置 */
.right-hand .finger.thumb {
    margin-right: 1vh;
}

/* 手指激活状态 */
.virtual-hand .finger.active {
    transform: translateY(-1.5vh) scale(1.1);
    box-shadow: 0 0 3vh rgba(251, 191, 36, 0.8);
    z-index: 10;
}

.virtual-hand .finger.active::after {
    content: '▼';
    position: absolute;
    bottom: -2.5vh;
    left: 50%;
    transform: translateX(-50%);
    font-size: 2vh;
    color: var(--warning-color);
    animation: bounce 0.5s infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateX(-50%) translateY(0); }
    50% { transform: translateX(-50%) translateY(-0.5vh); }
}

/* 键盘 */
.keyboard {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 1.2vh 1vw;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.6vh;
    flex: 1;
}

.keyboard-row {
    display: flex;
    justify-content: center;
    gap: 0.5vw;
    flex: 1;
    max-height: 6vh;
}

.key {
    width: 5vh;
    height: 100%;
    border-radius: 0.8vh;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: monospace;
    font-size: 2.2vh;
    font-weight: 600;
    background: var(--bg-color);
    border: 0.2vh solid var(--border-color);
    color: var(--text-color);
    transition: all 0.08s;
    user-select: none;
}

.key.space {
    width: 28vw;
    max-width: 30vh;
    font-size: 1.8vh;
}

.key.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
    transform: scale(0.92);
}

.key.highlight {
    border-color: var(--warning-color);
    box-shadow: 0 0 1.5vh rgba(251, 191, 36, 0.7);
    animation: glow 1s infinite;
}

@keyframes glow {
    0%, 100% { box-shadow: 0 0 1.5vh rgba(251, 191, 36, 0.7); }
    50% { box-shadow: 0 0 2.5vh rgba(251, 191, 36, 0.9); }
}

.key.home-key {
    border-bottom: 0.35vh solid var(--secondary-color);
}

/* 手指颜色 */
.key.finger-pinky-l { background: linear-gradient(145deg, rgba(239,68,68,0.3) 0%, var(--bg-color) 60%); }
.key.finger-ring-l { background: linear-gradient(145deg, rgba(249,115,22,0.3) 0%, var(--bg-color) 60%); }
.key.finger-middle-l { background: linear-gradient(145deg, rgba(234,179,8,0.3) 0%, var(--bg-color) 60%); }
.key.finger-index-l { background: linear-gradient(145deg, rgba(34,197,94,0.3) 0%, var(--bg-color) 60%); }
.key.finger-index-r { background: linear-gradient(145deg, rgba(34,197,94,0.3) 0%, var(--bg-color) 60%); }
.key.finger-middle-r { background: linear-gradient(145deg, rgba(234,179,8,0.3) 0%, var(--bg-color) 60%); }
.key.finger-ring-r { background: linear-gradient(145deg, rgba(249,115,22,0.3) 0%, var(--bg-color) 60%); }
.key.finger-pinky-r { background: linear-gradient(145deg, rgba(239,68,68,0.3) 0%, var(--bg-color) 60%); }
.key.finger-thumb { background: linear-gradient(145deg, rgba(139,92,246,0.3) 0%, var(--bg-color) 60%); }

/* 完成弹窗 */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.85);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.modal-overlay.show {
    display: flex;
}

.modal-box {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 4vh 4vw;
    text-align: center;
    width: min(50vh, 85vw);
    border: 1px solid var(--border-color);
    animation: modalIn 0.3s ease;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.modal-box h2 {
    font-size: 4vh;
    margin-bottom: 1vh;
}

.modal-box h2.success {
    color: var(--success-color);
}

.modal-box h2.retry {
    color: var(--warning-color);
}

.modal-stars {
    font-size: 6vh;
    margin: 2vh 0;
}

.modal-stats {
    display: flex;
    justify-content: center;
    gap: 3vw;
    margin: 2vh 0;
    padding: 2vh;
    background: var(--bg-color);
    border-radius: var(--radius-sm);
}

.modal-stat {
    text-align: center;
}

.modal-stat .val {
    font-size: 3vh;
    font-weight: 700;
    color: var(--primary-color);
}

.modal-stat .lbl {
    font-size: 1.6vh;
    color: var(--text-light);
    margin-top: 0.5vh;
}

.modal-message {
    color: var(--text-light);
    margin-bottom: 2vh;
    font-size: 2vh;
}

.modal-buttons {
    display: flex;
    gap: 2vw;
    justify-content: center;
}

.modal-buttons .btn {
    font-size: 2vh;
    padding: 1.2vh 2.5vw;
}

/* 手部指法提示面板 */
.hands-panel {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 3vh 3vw;
    z-index: 1500;
    border: 1px solid var(--border-color);
    width: min(55vh, 90vw);
}

.hands-panel.show {
    display: block;
}

.hands-panel h3 {
    text-align: center;
    color: var(--primary-color);
    margin-bottom: 1.5vh;
    font-size: 2.5vh;
}

.hands-panel p {
    text-align: center;
    color: var(--text-light);
    margin-bottom: 2vh;
    font-size: 1.8vh;
}

.hands-diagram {
    display: flex;
    justify-content: center;
    gap: 4vw;
}

.hand-group {
    text-align: center;
}

.hand-label {
    font-size: 1.6vh;
    color: var(--text-light);
    margin-bottom: 1vh;
}

.fingers-row {
    display: flex;
    gap: 0.5vw;
    justify-content: center;
}

.finger-key {
    width: 5vh;
    border-radius: 2.5vh 2.5vh 1vh 1vh;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 0.8vh;
    font-size: 1.8vh;
    color: white;
    font-weight: 600;
}

.finger-key.pinky { background: #ef4444; height: 5vh; }
.finger-key.ring { background: #f97316; height: 6.5vh; }
.finger-key.middle { background: #eab308; height: 7.5vh; }
.finger-key.index { background: #22c55e; height: 6.5vh; }

.thumb-key {
    width: 12vh;
    height: 4vh;
    background: #8b5cf6;
    border-radius: 1vh;
    margin: 1.5vh auto 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.6vh;
}

.hands-panel .close-btn {
    display: block;
    margin: 2vh auto 0;
    font-size: 2vh;
    padding: 1.2vh 3vw;
}

.panel-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1400;
}

.panel-backdrop.show {
    display: block;
}

/* 响应式 - 小屏幕侧边栏处理 */
@media (max-width: 900px) {
    .typing-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: min(280px, 75vw);
        z-index: 1100;
        transform: translateX(-100%);
        transition: transform 0.3s;
    }

    .typing-sidebar.open {
        transform: translateX(0);
    }

    .sidebar-backdrop {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 1050;
    }

    .sidebar-backdrop.show {
        display: block;
    }
}

/* 响应式 - 小高度屏幕 */
@media (max-height: 600px) {
    .current-level-info {
        height: 5vh;
    }

    .current-level-info p {
        display: none;
    }

    .stats-bar {
        height: 6vh;
    }

    .stat-item .value {
        font-size: 2.5vh;
    }

    .text-display-wrapper {
        height: 12vh;
    }

    .text-display {
        font-size: 3.5vh;
    }

    .controls {
        height: 5vh;
    }

    .virtual-hands {
        height: 14vh;
    }

    .virtual-hand .finger.pinky { height: 6vh; }
    .virtual-hand .finger.ring { height: 8vh; }
    .virtual-hand .finger.middle { height: 9vh; }
    .virtual-hand .finger.index { height: 7.5vh; }
    .virtual-hand .finger.thumb { height: 4.5vh; }
    .virtual-hand .hand-palm { height: 3vh; }
}

/* 响应式 - 非常小的高度屏幕 */
@media (max-height: 500px) {
    .virtual-hands {
        height: 12vh;
    }

    .virtual-hand .finger {
        width: 3vh;
    }

    .virtual-hand .finger.pinky { height: 5vh; }
    .virtual-hand .finger.ring { height: 7vh; }
    .virtual-hand .finger.middle { height: 8vh; }
    .virtual-hand .finger.index { height: 6.5vh; }
    .virtual-hand .finger.thumb { height: 4vh; width: 3.5vh; }
    .virtual-hand .hand-palm { height: 2.5vh; }

    .virtual-hand .finger span {
        font-size: 1vh;
    }

    .key {
        width: 4vh;
        font-size: 1.8vh;
    }

    .keyboard-row {
        max-height: 5vh;
    }
}

/* 响应式 - 手机等窄屏 */
@media (max-width: 768px) {
    .typing-header {
        padding: 0 3vw;
    }

    .typing-content {
        padding: 1vh 3vw;
    }

    .virtual-hands {
        gap: 4vw;
    }

    .hands-diagram {
        flex-direction: column;
        gap: 2vh;
    }

    .key {
        width: 8vw;
        min-width: 24px;
    }

    .key.space {
        width: 40vw;
    }
}

/* 宽屏优化 - 防止键盘过宽 */
@media (min-aspect-ratio: 16/9) {
    .keyboard-hands-container {
        max-width: 100vh;
        margin: 0 auto;
    }
}
