/**
 * PEP英语课文打字练习样式
 */

html, body {
    overflow: hidden;
    height: 100%;
    margin: 0;
    padding: 0;
}

.shake {
    animation: shake 0.2s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* ===== 全屏容器 ===== */
.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;
    flex-shrink: 0;
    position: relative;
}

.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);
}

/* ===== 提示气泡 ===== */
.tips-bubble {
    position: absolute;
    top: 100%;
    right: 2vw;
    margin-top: 0.5vh;
    padding: 1vh 1.5vw;
    background: #164e3b;
    color: #d1fae5;
    font-size: 1.6vh;
    border-radius: var(--radius-sm);
    border: 1px solid #22c55e;
    box-shadow: 0 4px 12px rgba(34,197,94,0.2);
    white-space: nowrap;
    z-index: 1200;
    opacity: 0;
    transform: translateY(-0.5vh);
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: none;
}

.tips-bubble.show {
    opacity: 1;
    transform: translateY(0);
}

.tips-bubble::before {
    content: '';
    position: absolute;
    top: -0.6vh;
    right: 2vw;
    width: 1vh;
    height: 1vh;
    background: #164e3b;
    border-top: 1px solid #22c55e;
    border-left: 1px solid #22c55e;
    transform: rotate(45deg);
}

/* ===== 翻译开关 ===== */
.trans-toggle {
    display: flex;
    align-items: center;
    gap: 0.4vw;
    cursor: pointer;
    user-select: none;
}

.trans-toggle-label {
    font-size: 1.6vh;
    color: var(--text-light);
    font-weight: 500;
}

.trans-toggle-track {
    width: 4vh;
    height: 2.2vh;
    border-radius: 50px;
    background: var(--border-color);
    position: relative;
    transition: background 0.2s;
}

.trans-toggle.on .trans-toggle-track {
    background: var(--success-color);
}

.trans-toggle-thumb {
    width: 1.8vh;
    height: 1.8vh;
    border-radius: 50%;
    background: white;
    position: absolute;
    top: 0.2vh;
    left: 0.2vh;
    transition: left 0.2s;
}

.trans-toggle.on .trans-toggle-thumb {
    left: calc(100% - 2vh);
}

/* ===== 主区域 ===== */
.typing-main {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.typing-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0.8vh 2vw;
    overflow: hidden;
    height: 100%;
}

/* ===== 选择器区域 ===== */
.selector-area {
    display: flex;
    flex-direction: column;
    gap: 0.6vh;
    flex-shrink: 0;
    padding: 0.5vh 0;
}

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

.selector-pill {
    padding: 0.6vh 1.4vw;
    border-radius: 50px;
    font-size: 1.6vh;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--card-bg);
    color: var(--text-light);
    border: 1px solid var(--border-color);
    user-select: none;
    white-space: nowrap;
}

.selector-pill:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.selector-pill.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.selector-pill .done-mark {
    font-size: 1.2vh;
    margin-left: 0.2vw;
}

/* ===== 进度条 ===== */
.sentence-progress {
    display: flex;
    align-items: center;
    gap: 1vw;
    padding: 0.5vh 0;
    flex-shrink: 0;
}

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

.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #22c55e, #3b82f6);
    border-radius: 50px;
    transition: width 0.3s;
}

.progress-label {
    font-size: 1.4vh;
    color: var(--text-light);
    white-space: nowrap;
    min-width: 8vw;
    text-align: right;
}

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

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

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

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

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

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

.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); }

.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; }
}

/* 句子完成动画 */
.text-display.sentence-done {
    animation: sentenceDone 0.4s ease;
}

@keyframes sentenceDone {
    0% { transform: scale(1); }
    50% { transform: scale(1.02); border-color: var(--success-color); }
    100% { transform: scale(1); }
}

/* ===== 生词栏 ===== */
.vocab-bar {
    display: none;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 1.5vw;
    padding: 0.8vh 1vw;
    min-height: 4vh;
    background: rgba(34, 197, 94, 0.08);
    border: 1px solid rgba(34, 197, 94, 0.25);
    border-radius: var(--radius);
    flex-shrink: 0;
    animation: vocabFadeIn 0.3s ease;
}

.vocab-bar.show {
    display: flex;
}

@keyframes vocabFadeIn {
    from { opacity: 0; transform: translateY(-0.5vh); }
    to { opacity: 1; transform: translateY(0); }
}

.translation-text {
    font-size: 2vh;
    color: #e2e8f0;
    letter-spacing: 0.05em;
}

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

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

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

/* ===== 键盘区域 ===== */
.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: 15vh;
    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: 5vh;
    background: rgba(100,116,139,0.3);
    border-radius: 2vh 2vh 3vh 3vh;
}

.virtual-hand .finger {
    width: 3.2vh;
    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.1vh;
    color: white;
    font-weight: 600;
    opacity: 0.9;
}

.virtual-hand .finger.pinky { height: 6.5vh; background: linear-gradient(180deg, #ef4444 0%, #dc2626 100%); }
.virtual-hand .finger.ring { height: 9vh; background: linear-gradient(180deg, #f97316 0%, #ea580c 100%); }
.virtual-hand .finger.middle { height: 10vh; background: linear-gradient(180deg, #eab308 0%, #ca8a04 100%); }
.virtual-hand .finger.index { height: 8.5vh; background: linear-gradient(180deg, #22c55e 0%, #16a34a 100%); }
.virtual-hand .finger.thumb { height: 5vh; width: 3.5vh; 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.2vh) scale(1.1);
    box-shadow: 0 0 2.5vh rgba(251,191,36,0.8);
    z-index: 10;
}

.virtual-hand .finger.active::after {
    content: '\25BC';
    position: absolute;
    bottom: -2.2vh;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1.8vh;
    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.4vw;
    flex: 1;
    max-height: 5vh;
}

.keyboard-row.row-num {
    max-height: 4vh;
}

.key {
    width: 5vh;
    height: 100%;
    border-radius: 0.8vh;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: monospace;
    font-size: 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.key-sm {
    width: 4.5vh;
    font-size: 1.8vh;
}

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

.key.space {
    width: 24vw;
    max-width: 26vh;
    font-size: 1.6vh;
}

.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.3vh 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: 5vh; margin: 1.5vh 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-buttons {
    display: flex;
    gap: 2vw;
    justify-content: center;
    margin-top: 2vh;
}

.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; }

/* ===== 鼓励浮字动画 ===== */
.encourage-float {
    position: absolute;
    top: 20%;
    transform: translateX(-50%);
    font-size: 3vh;
    font-weight: 700;
    color: #facc15;
    text-shadow: 0 0 10px rgba(250, 204, 21, 0.5), 0 2px 4px rgba(0,0,0,0.3);
    pointer-events: none;
    z-index: 100;
    animation: floatUp 1.2s ease-out forwards;
    white-space: nowrap;
}

.combo-float {
    position: absolute;
    top: 50%;
    transform: translateX(-50%);
    font-size: 2.5vh;
    font-weight: 700;
    color: #f97316;
    text-shadow: 0 0 8px rgba(249, 115, 22, 0.5);
    pointer-events: none;
    z-index: 100;
    animation: comboPopUp 1.5s ease-out forwards;
    white-space: nowrap;
}

@keyframes floatUp {
    0% { opacity: 1; transform: translateX(-50%) translateY(0) scale(0.5); }
    30% { opacity: 1; transform: translateX(-50%) translateY(-1vh) scale(1.2); }
    100% { opacity: 0; transform: translateX(-50%) translateY(-6vh) scale(0.8); }
}

@keyframes comboPopUp {
    0% { opacity: 1; transform: translateX(-50%) scale(0.3); }
    20% { opacity: 1; transform: translateX(-50%) scale(1.3); }
    40% { transform: translateX(-50%) scale(1); }
    100% { opacity: 0; transform: translateX(-50%) translateY(-4vh) scale(0.7); }
}

/* ===== 响应式 ===== */
@media (max-height: 700px) {
    .virtual-hands { height: 12vh; }
    .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; }
    .virtual-hand .hand-palm { height: 3.5vh; }
}

@media (max-height: 550px) {
    .virtual-hands { display: none; }
    .selector-pill { padding: 0.4vh 1.2vw; font-size: 1.4vh; }
    .text-display { font-size: 3vh; }
    .text-display-wrapper { height: 10vh; }
    .stats-bar { height: 5vh; }
    .stat-item .value { font-size: 2vh; }
    .keyboard-row.row-num { display: none; }
}

@media (max-width: 768px) {
    .typing-header { padding: 0 3vw; }
    .typing-content { padding: 0.8vh 3vw; }
    .virtual-hands { gap: 4vw; }
    .hands-diagram { flex-direction: column; gap: 2vh; }
    .key { width: 8vw; min-width: 24px; }
    .key.space { width: 36vw; }
    .key.key-sm, .key.key-fn { width: 7vw; min-width: 22px; }
    .selector-pill { padding: 0.5vh 2vw; font-size: 1.5vh; }
}

@media (min-aspect-ratio: 16/9) {
    .keyboard-hands-container {
        max-width: 100vh;
        margin: 0 auto;
    }
}
