* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

/* RTL Support */
body.rtl {
    direction: rtl;
}

body.rtl .sentence-display {
    direction: rtl;
    text-align: right;
}

.screen {
    display: none;
    width: 100%;
    max-width: 1400px;
    animation: fadeIn 0.3s ease-in;
}

.screen.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.container {
    background: white;
    border-radius: 20px;
    padding: 40px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

h1 {
    text-align: center;
    color: #333;
    margin-bottom: 30px;
    font-size: 2.5em;
}

h2 {
    text-align: center;
    color: #333;
    margin-bottom: 20px;
}

h3 {
    color: #555;
    margin-bottom: 15px;
    text-align: center;
}

/* Language Selector */
.language-selector {
    text-align: center;
    margin-bottom: 20px;
}

.language-selector label {
    font-size: 1.1em;
    color: #555;
    margin-right: 10px;
}

.language-selector select {
    padding: 10px 20px;
    font-size: 1em;
    border: 2px solid #667eea;
    border-radius: 8px;
    background: white;
    cursor: pointer;
    outline: none;
}

.language-selector select:hover {
    border-color: #764ba2;
}

/* Level Selector */
.level-selector {
    text-align: center;
    margin-bottom: 30px;
}

.level-selector label {
    font-size: 1.1em;
    color: #555;
    margin-right: 10px;
}

.level-selector select {
    padding: 10px 20px;
    font-size: 1em;
    border: 2px solid #667eea;
    border-radius: 8px;
    background: white;
    cursor: pointer;
    outline: none;
}

.level-selector select:hover {
    border-color: #764ba2;
}

/* Mode Buttons */
.mode-buttons {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-bottom: 40px;
}

.mode-btn {
    padding: 25px;
    border: none;
    border-radius: 12px;
    font-size: 1.3em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.mode-btn.learn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.mode-btn.test {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
}

.mode-btn.race {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: white;
}

.mode-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

.mode-desc {
    font-size: 0.5em;
    font-weight: normal;
    opacity: 0.9;
}

/* Progress Summary */
.progress-summary {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 10px;
}

#progressDisplay {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
    margin-top: 15px;
}

.progress-item {
    background: white;
    padding: 10px;
    border-radius: 8px;
    text-align: center;
    border: 2px solid #e0e0e0;
}

.progress-item.completed {
    border-color: #4caf50;
    background: #e8f5e9;
}

/* Game Screen */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    flex-wrap: wrap;
    gap: 15px;
}

.back-btn {
    padding: 10px 20px;
    background: #6c757d;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1em;
    transition: background 0.3s ease;
}

.back-btn:hover {
    background: #5a6268;
}

.game-info {
    display: flex;
    gap: 20px;
    font-weight: bold;
    color: #333;
}

.game-stats {
    display: flex;
    gap: 20px;
}

.stat {
    padding: 8px 15px;
    background: #f8f9fa;
    border-radius: 8px;
    font-weight: bold;
}

.stat.hidden {
    display: none;
}

/* Typing Area */
.typing-area {
    margin-bottom: 20px;
    margin-top: 0;
    width: 100%;
}

.sentence-display {
    background: #f8f9fa;
    padding: 50px;
    border-radius: 12px;
    font-size: 20px;
    font-family: 'Courier New', monospace;
    line-height: 2.2;
    letter-spacing: 2px;
    word-wrap: break-word;
    word-break: break-word;
    white-space: normal;
    min-height: 250px;
    width: 100%;
    box-sizing: border-box;
}

.char {
    position: relative;
    display: inline-block;
}

.char.current {
    background: #ffd700;
    animation: pulse 1s infinite;
}

.char.current.error {
    background: #ff4444;
    animation: shake 0.3s;
}

.char.correct {
    color: #4caf50;
}

.char.space {
    width: 8px;
}

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

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

/* Keyboard Layout */
.keyboard-layout {
    background: #f8f9fa;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 30px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.keyboard-layout.hidden {
    display: none;
}

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

.key {
    width: 45px;
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-weight: bold;
    font-size: 14px;
    background: #ffffff;
    position: relative;
    transition: all 0.2s ease;
    cursor: default;
    user-select: none;
}

.key-space {
    width: 300px;
}

/* Finger Color Coding */
.key[data-finger="left-pinky"] {
    background: #fce4ec;
    border-color: #e91e63;
}

.key[data-finger="left-ring"] {
    background: #f3e5f5;
    border-color: #9c27b0;
}

.key[data-finger="left-middle"] {
    background: #e3f2fd;
    border-color: #2196f3;
}

.key[data-finger="left-index"] {
    background: #cacac4;
    border-color: #4caf50;
}

.key[data-finger="right-index"] {
    background: #cacac4;
    border-color: #4caf50;
}

.key[data-finger="right-middle"] {
    background: #e3f2fd;
    border-color: #2196f3;
}

.key[data-finger="right-ring"] {
    background: #f3e5f5;
    border-color: #9c27b0;
}

.key[data-finger="right-pinky"] {
    background: #fce4ec;
    border-color: #e91e63;
}

.key[data-finger="thumb"] {
    background: #fff9c4;
    border-color: #fbc02d;
}

/* Inactive keys (not in current level) */
.key.key-inactive {
    background: #e0e0e0 !important;
    border-color: #bdbdbd !important;
    color: #9e9e9e;
    opacity: 0.5;
}

/* Current key to press */
.key.key-current {
    background: #ffd700 !important;
    border-color: #ffa000 !important;
    border-width: 3px;
    transform: scale(1.1);
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.6);
    animation: pulseKey 1s infinite;
    z-index: 10;
}

@keyframes pulseKey {
    0%, 100% {
        box-shadow: 0 0 15px rgba(255, 215, 0, 0.6);
    }
    50% {
        box-shadow: 0 0 25px rgba(255, 215, 0, 0.9);
    }
}

/* Home row keys (F and J) */
.key-home {
    font-weight: 900;
}

.home-indicator {
    position: absolute;
    bottom: 8px;
    width: 8px;
    height: 8px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 50%;
}

/* Rabbit Track */
.rabbit-track {
    margin-top: 20px;
    position: relative;
    height: 60px;
    background: #e8f5e9;
    border-radius: 10px;
    padding: 10px;
}

.rabbit-track.hidden {
    display: none;
}

.rabbit {
    font-size: 2em;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    transition: left 0.1s linear;
}

/* Feedback Message */
.feedback-message {
    text-align: center;
    font-size: 1.2em;
    min-height: 30px;
    color: #333;
}

/* Results Screen */
.results-content {
    text-align: center;
}

#resultsStats {
    background: #f8f9fa;
    padding: 30px;
    border-radius: 12px;
    margin-bottom: 30px;
    font-size: 1.1em;
}

.stat-row {
    padding: 10px;
    margin: 10px 0;
}

.stat-label {
    font-weight: bold;
    color: #555;
}

.stat-value {
    color: #667eea;
    font-size: 1.3em;
    font-weight: bold;
}

.results-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
}

.btn-primary,
.btn-secondary {
    padding: 15px 30px;
    border: none;
    border-radius: 8px;
    font-size: 1.1em;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-primary:hover,
.btn-secondary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 20px;
    }

    h1 {
        font-size: 1.8em;
    }

    .sentence-display {
        font-size: 1.3em;
        padding: 20px;
    }

    .mode-btn {
        font-size: 1.1em;
        padding: 20px;
    }

    .game-header {
        flex-direction: column;
        align-items: flex-start;
    }

    /* Keyboard responsive adjustments */
    .keyboard-layout {
        padding: 10px;
    }

    .key {
        width: 35px;
        height: 35px;
        font-size: 12px;
    }

    .key-space {
        width: 200px;
    }

    .keyboard-row {
        gap: 3px;
        margin-bottom: 3px;
    }
}

@media (max-width: 480px) {
    .key {
        width: 28px;
        height: 28px;
        font-size: 10px;
    }

    .key-space {
        width: 150px;
    }

    .keyboard-row {
        gap: 2px;
        margin-bottom: 2px;
    }

    .home-indicator {
        width: 6px;
        height: 6px;
        bottom: 4px;
    }
}
