/* Reset và base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 30px;
    color: white;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

header p {
    font-size: 1.1rem;
    opacity: 0.9;
}

/* Header Row */
.header-row {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 24px;
    position: relative;
}

.header-left {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
}

.header-row h1 {
    margin: 0;
    letter-spacing: -1px;
}

.main-title {
    color: #fff; /* Đổi sang trắng, hoặc dùng #6d28d9 cho tím sẫm */
    font-family: 'Montserrat', 'Arial', sans-serif;
    font-size: 2.6rem;
    font-weight: 700;
    margin: 0;
    text-align: center;
    letter-spacing: -1px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-icon {
    font-size: 1.5em;
}

/* Telex Help Link */
.telex-help-link {
    position: absolute;
    right: 32px;
    top: 50%;
    transform: translateY(-50%);
    color: #fff;
    background: #7c3aed;
    border-radius: 8px;
    padding: 8px 20px;
    text-decoration: none;
    font-weight: 500;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.2s;
}

.telex-help-link span {
    color: #e11d48;
    font-size: 1.5em;
}

.telex-help-link:hover {
    background: #5b21b6;
}

/* Stats Panel */
.stats-panel {
    display: flex;
    justify-content: center;
    gap: 40px;
    margin-bottom: 30px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border-radius: 15px;
    padding: 20px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.stat {
    text-align: center;
    color: white;
}

.stat-label {
    display: block;
    font-size: 0.9rem;
    opacity: 0.8;
    margin-bottom: 5px;
}

.stat-value {
    display: block;
    font-size: 2rem;
    font-weight: 700;
    line-height: 1;
}

.stat-unit {
    display: block;
    font-size: 0.8rem;
    opacity: 0.7;
    margin-top: 2px;
}

/* Lesson Selector */
.lesson-selector {
    background: white;
    padding: 20px;
    border-radius: 15px;
    margin-bottom: 20px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.lesson-selector label {
    font-weight: 600;
    color: #555;
}

#lesson-select {
    flex: 1;
    min-width: 250px;
    padding: 12px 15px;
    border: 2px solid #e1e5e9;
    border-radius: 8px;
    font-size: 1rem;
    background: white;
    transition: border-color 0.3s ease;
}

#lesson-select:focus {
    outline: none;
    border-color: #667eea;
}

#start-btn, #reset-btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

#start-btn {
    background: #4caf50;
    color: white;
}

#start-btn:hover {
    background: #45a049;
    transform: translateY(-2px);
}

#start-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

#reset-btn {
    background: #ff6b6b;
    color: white;
}

#reset-btn:hover {
    background: #ff5252;
    transform: translateY(-2px);
}

/* Text Display */
.text-display {
    background: white;
    border-radius: 15px;
    margin-bottom: 30px;
    overflow: hidden;
    box-shadow: 0 8px 25px rgba(0,0,0,0.1);
}

#text-to-type {
    white-space: pre-line;
    word-break: break-word;
    max-height: 220px;
    overflow-y: auto;
    padding: 8px;
    background: #fff;
    border-radius: 6px;
    box-sizing: border-box;
}

.input-area {
    padding: 20px 30px;
}

/* SỬA LẠI INPUT STYLES */
#typing-input {
    width: 100%;
    padding: 15px;
    font-size: 1.2rem;
    border: 3px solid #e0e0e0;
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    background: #ffffff;
    resize: none;
    outline: none;
    transition: all 0.3s ease;
    cursor: text;
    user-select: text;
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
}

#typing-input:focus {
    border-color: #4a90e2;
    box-shadow: 0 0 10px rgba(74, 144, 226, 0.3);
}

/* Animation khi có lỗi */
#typing-input.shake {
    animation: shake 0.5s ease-in-out;
}

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

/* Keyboard Container */
.keyboard-container {
    width: 1100px; /* tăng lên cho vừa các phím */
    max-width: 100vw;
    margin: 0 auto;
    padding: 32px 0 0 0;
    background: rgba(255,255,255,0.08);
    border-radius: 18px;
    box-shadow: 0 6px 32px rgba(76, 81, 109, 0.12);
    border: 3px solid #7c3aed;
}

/* Virtual Keyboard */
.virtual-keyboard {
    width: 100%;
    min-width: 1050px; /* đảm bảo không bị co lại */
    margin: 0 auto;
}

.keyboard-row {
    display: flex;
    justify-content: center;
    margin-bottom: 8px;
    gap: 4px;
}

.keyboard-row.numbers-row {
    justify-content: center;
    gap: 8px;
    margin-bottom: 8px;
}

.key {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    min-width: 60px;
    height: 60px;
    font-size: 1.4rem;
    border-radius: 10px;
    margin: 6px;
    background: linear-gradient(to bottom, #ffffff, #f1f3f4);
    border: 1px solid #dadce0;
    font-family: 'Courier New', monospace;
    font-weight: 500;
    color: #3c4043;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.key:hover {
    background: linear-gradient(to bottom, #f8f9fa, #e8eaed);
    transform: translateY(-1px);
    box-shadow: 0 2px 5px rgba(0,0,0,0.15);
}

.key .shift-char {
    font-size: 1.1rem;
    color: #f39c12;
    font-weight: bold;
    margin-bottom: 2px;
    line-height: 1;
}

.key .main-char {
    font-size: 1.5rem;
    color: #3c4043;
    font-weight: 500;
    line-height: 1.2;
}

.space-bar {
    min-width: 320px;
    height: 60px;
    font-size: 1.2rem;
}

/* Key highlighting */
.key.next-key {
    background: linear-gradient(135deg, #4a90e2 0%, #357abd 100%) !important;
    color: white !important;
    transform: scale(1.05) !important;
    box-shadow: 0 0 15px rgba(74, 144, 226, 0.8) !important;
    z-index: 10 !important;
    border: 2px solid #ffd700 !important;
}

@keyframes next-key-glow {
    0%, 100% { box-shadow: 0 0 5px #4a90e2; }
    50% { box-shadow: 0 0 20px #4a90e2, 0 0 30px #4a90e2; }
}

.key.home-key {
    background: linear-gradient(to bottom, #ffffff, #f1f3f4) !important;
    border: 1px solid #dadce0 !important;
    font-weight: bold !important;
    color: #3c4043 !important;
}

.key.finger-highlight {
    background: linear-gradient(to bottom, #fff3cd, #ffeaa7);
}

.key.error-key {
    background: linear-gradient(to bottom, #ffebee, #ffcdd2);
    border-color: #e74c3c;
    animation: shake 0.5s ease-in-out;
}

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

/* Finger Guide */
/*.finger-guide {
    margin-bottom: 25px;
    position: fixed;
    bottom: 20px;
    left: 20px;
    background: linear-gradient(135deg, #4a90e2 0%, #357abd 100%);
    color: white;
    border-radius: 12px;
    padding: 15px 20px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.3);
    z-index: 1000;
    display: none;
    min-width: 200px;
}*/

.finger-guide-old {
    margin-bottom: 25px;
    position: fixed;
    bottom: 20px;
    left: 20px;
    background: linear-gradient(135deg, #4a90e2 0%, #357abd 100%);
    color: white;
    border-radius: 12px;
    padding: 15px 20px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.3);
    z-index: 1000;
    display: block;
    min-width: 200px;
    max-width: 400px;
    text-align: center;
}

.finger-instruction {
    text-align: center;
}

.key-to-press {
    font-size: 1.2rem;
    margin-bottom: 8px;
}

.key-highlight {
    background: rgba(255,255,255,0.3);
    padding: 4px 12px;
    border-radius: 6px;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    font-size: 1.4rem;
}

.finger-name {
    font-size: 1rem;
    opacity: 0.9;
}

.finger-color {
    font-weight: bold;
    padding: 2px 8px;
    border-radius: 4px;
}

/* Màu sắc cho từng ngón tay */
.finger-pinky-left, .finger-pinky-right { 
    background-color: #e74c3c; 
    color: white;
}

.finger-ring-left, .finger-ring-right { 
    background-color: #f39c12; 
    color: white;
}

.finger-middle-left, .finger-middle-right { 
    background-color: #27ae60; 
    color: white;
}

.finger-index-left, .finger-index-right { 
    background-color: #3498db; 
    color: white;
}

.finger-thumb { 
    background-color: #9b59b6; 
    color: white;
}

/* Cải thiện highlight keyboard */
.key.finger-highlight {
    animation: finger-pulse 1.5s infinite;
}

@keyframes finger-pulse {
    0%, 100% { 
        transform: scale(1); 
        box-shadow: 0 0 5px rgba(255,255,255,0.5); 
    }
    50% { 
        transform: scale(1.1); 
        box-shadow: 0 0 15px rgba(255,255,255,0.8); 
    }
}

@keyframes slideInFromRight {
    from {
        opacity: 0;
        transform: translateX(50px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.text-correct {
    background-color: rgba(39, 174, 96, 0.3) !important;
    color: #27ae60 !important;
    font-weight: bold !important;
    padding: 1px 2px;
    border-radius: 2px;
}

.text-current {
    background-color: rgba(52, 152, 219, 0.5) !important;
    border: 2px solid #3498db !important;
    padding: 2px 4px !important;
    border-radius: 3px !important;
    font-weight: bold !important;
    animation: blink-cursor 1s infinite;
}

@keyframes blink-cursor {
    0%, 50% { background-color: rgba(52, 152, 219, 0.5); }
    51%, 100% { background-color: rgba(52, 152, 219, 0.8); }
}

/* Input field styles */
#typing-input {
    font-size: 1.2rem !important;
    font-weight: normal !important;
    transition: color 0.2s ease !important;
}

.key.telex-next-main {
    background: #ffb74d !important; /* cam nhạt */
    color: #222 !important;
    border-color: #ffa726 !important;
    box-shadow: 0 0 0 2px #ffa726;
}
.key.telex-done {
    background: linear-gradient(135deg, #1abc9c 0%, #16a085 100%) !important;
    color: #fff !important;
    font-weight: bold !important;
    border: 2px solid #16a085 !important;
}
.key.telex-next {
    background: none !important; /* bỏ nền xanh */
    color: #222 !important;
    border: 2px solid #ffd700 !important; /* viền vàng */
    font-weight: normal !important;
    box-shadow: none !important;
}

/* Đảm bảo finger-guide hiển thị đúng */
#finger-guide {
    position: static; /* hoặc absolute nếu cần, nhưng không fixed */
    margin: 32px auto 0 auto;
    display: flex;
    justify-content: center;
    align-items: center;
    background: none;
    box-shadow: none;
    border-radius: 0;
    padding: 0;
    min-width: unset;
    max-width: unset;
    opacity: 1;
    z-index: 1;
}

/* Tạo layout mới cho nội dung finger-guide */
#finger-guide .finger-guide-content {
    flex-direction: column;
    align-items: center;
}

#finger-guide .finger-visual {
    margin: 0;
    font-size: 2.8rem;
}

#finger-guide svg {
    width: 420px !important;
    height: 180px !important;
    display: block;
    margin: 0 auto;
}

/* Telex Guide Popup (góc trên phải) */
#telex-guide-popup {
    position: fixed;
    top: 16px;
    right: 16px;
    max-width: 340px;
    max-height: 320px;
    overflow-y: auto;
    background: #f9f9f9;
    border-radius: 8px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.12);
    padding: 16px;
    z-index: 1000;
    font-size: 1rem;
    color: #222;
    word-break: break-word;
    white-space: pre-line;
}

.target-char {
    font-size: 2.5rem;
    text-align: center;
    margin-bottom: 15px;
    font-weight: bold;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.sequence-instruction {
    text-align: center;
    margin-bottom: 15px;
    font-size: 1.1rem;
}

.key-step {
    display: inline-block;
    background: rgba(255,255,255,0.2);
    border: 2px solid rgba(255,255,255,0.3);
    padding: 8px 12px;
    margin: 0 3px;
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    font-size: 1rem;
    transition: all 0.3s ease;
}

.key-step.completed {
    background: rgba(39, 174, 96, 0.8) !important;
    border-color: #27ae60 !important;
    color: white !important;
}

.key-step.current {
    background: rgba(52, 152, 219, 0.8) !important;
    border-color: #3498db !important;
    color: white !important;
    animation: pulse 1s infinite;
}

.key-step.pending {
    background: rgba(255,255,255,0.2) !important;
    border-color: rgba(255,255,255,0.3) !important;
    opacity: 0.7;
}

.plus {
    color: rgba(255,255,255,0.8);
    margin: 0 5px;
    font-size: 1.2rem;
}

.progress {
    text-align: center;
    margin-top: 10px;
    font-size: 0.9rem;
    opacity: 0.8;
    border-top: 1px solid rgba(255,255,255,0.3);
    padding-top: 10px;
}

.typing-method {
    text-align: center;
    margin: 15px 0;
}

.base-word, .then-tone {
    margin: 8px 0;
    font-size: 1rem;
}

.word-highlight {
    background: rgba(46, 204, 113, 0.8);
    color: white;
    padding: 4px 8px;
    border-radius: 6px;
    font-weight: bold;
}

.tone-highlight {
    background: rgba(241, 196, 15, 0.8);
    color: white;
    padding: 4px 8px;
    border-radius: 6px;
    font-weight: bold;
}

.typing-progress, .tone-progress {
    text-align: center;
    margin: 15px 0;
}

.word-progress, .tone-typing {
    font-family: 'Courier New', monospace;
    font-size: 1.2rem;
    margin: 8px 0;
}

.typed {
    background: rgba(39, 174, 96, 0.8);
    color: white;
    padding: 4px 6px;
    border-radius: 4px;
}

.to-type {
    background: rgba(255,255,255,0.3);
    color: white;
    padding: 4px 6px;
    border-radius: 4px;
}

.word-done {
    color: #2ecc71;
    font-weight: bold;
    margin-bottom: 8px;
}

.next-tone {
    font-size: 0.9rem;
    opacity: 0.8;
}

/* Thêm vào cuối styles.css */

.lesson-type-badge {
    background: rgba(52, 152, 219, 0.8);
    color: white;
    padding: 4px 12px;
    border-radius: 15px;
    font-size: 0.8rem;
    text-align: center;
    margin-bottom: 10px;
    font-weight: bold;
}

.natural-typing {
    background: rgba(46, 204, 113, 0.2);
    color: #27ae60;
    padding: 8px 12px;
    border-radius: 8px;
    margin-top: 10px;
    font-size: 0.9rem;
    text-align: center;
    font-weight: bold;
}

.encouragement {
    background: rgba(241, 196, 15, 0.2);
    color: #f39c12;
    padding: 6px 10px;
    border-radius: 6px;
    margin-top: 8px;
    font-size: 0.85rem;
    text-align: center;
}

.almost-done {
    background: rgba(155, 89, 182, 0.2);
    color: #9b59b6;
    padding: 6px 10px;
    border-radius: 6px;
    margin-top: 8px;
    font-size: 0.85rem;
    text-align: center;
    font-weight: bold;
}

.buffer-vs-target {
    font-size: 0.9rem;
    opacity: 0.9;
    background: rgba(52, 152, 219, 0.1);
    padding: 4px 8px;
    border-radius: 4px;
    margin-top: 5px;
}

.key.home-key[data-key="f"],
.key.home-key[data-key="j"] {
    position: relative;
}

.key.home-key[data-key="f"]::after,
.key.home-key[data-key="j"]::after {
    content: "";
    display: block;
    position: absolute;
    left: 8px;
    right: 8px;
    bottom: 6px;
    height: 5px;
    border-radius: 3px;
    background: #222 !important; /* màu đen */
}

.key .shift-char {
    color: #f39c12;
    font-weight: bold;
    font-size: 1.1rem;
}

.key.shift-key {
    background: #ffe066 !important;
    border-color: #f39c12 !important;
    color: #222 !important;
}

.key.enter-key {
    min-width: 90px;
    background: #e0e0e0;
    color: #222;
    font-weight: bold;
    border: 2px solid #4a90e2;
}
