* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --primary-color: #2ecc71;
    --primary-light: #a8e6cf;
    --primary-dark: #27ae60;
    --secondary-color: #3498db;
    --text-color: #2c3e50;
    --text-secondary: #64748b;
    --background-color: #f0f7f4;
    --card-background: #ffffff;
    --border-color: #e2e8f0;
    --success-color: #2ecc71;
    --error-color: #e74c3c;
    --hint-color: #9b59b6;
    --border-radius: 16px;
    --transition: all 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    --shadow-light: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-medium: 0 4px 16px rgba(0, 0, 0, 0.12);
    --shadow-heavy: 0 8px 32px rgba(0, 0, 0, 0.16);
}

/* Dark theme variables */
body.dark-theme {
    --text-color: #f1f5f9;
    --text-secondary: #94a3b8;
    --background-color: #0f172a;
    --card-background: #1e293b;
    --border-color: #334155;
    --primary-light: #065f46;
    --shadow-light: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-medium: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-heavy: 0 8px 32px rgba(0, 0, 0, 0.5);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: var(--text-color);
    line-height: 1.6;
    min-height: 100vh;
    min-height: -webkit-fill-available;
    padding: 0;
    margin: 0;
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    overflow-x: hidden;
    position: relative;
    transition: var(--transition);
}

body.dark-theme {
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
}

.container {
    max-width: 100vw;
    width: 100%;
    min-height: 100vh;
    min-height: -webkit-fill-available;
    margin: 0;
    padding: 0;
    background: var(--card-background);
    transform: translateZ(0);
    backface-visibility: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
}

.navbar {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: env(safe-area-inset-top, 16px) 1rem 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: white;
    position: relative;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    transition: var(--transition);
}

body.dark-theme .navbar {
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    border-bottom: 1px solid var(--border-color);
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
}

.brand-icon {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.brand-text {
    display: flex;
    flex-direction: column;
}

.brand-title {
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1.2;
}

.brand-subtitle {
    font-size: 0.8rem;
    opacity: 0.8;
    font-weight: 400;
}



.content-area {
    flex: 1;
    padding: 1rem;
    background: var(--card-background);
    border-radius: 20px 20px 0 0;
    margin-top: -10px;
    position: relative;
    z-index: 2;
    box-shadow: 0 -5px 20px rgba(0, 0, 0, 0.1);
}

form {
    margin-bottom: 1.5rem;
    text-align: center;
}

select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    padding: 0.875rem 2.5rem 0.875rem 1.25rem;
    font-size: 1rem;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    background: var(--card-background) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%232ecc71' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E") no-repeat right 0.75rem center/1.5rem;
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-color);
    min-width: 200px;
    max-width: 100%;
    width: auto;
    transform: translateZ(0);
}

select:hover {
    border-color: var(--primary-color);
    transform: translateY(-1px) translateZ(0);
    box-shadow: var(--shadow-light);
}

select:focus {
    border-color: var(--primary-color);
    transform: translateY(-1px) translateZ(0);
    box-shadow: 0 0 0 3px rgba(46, 204, 113, 0.15);
    outline: none;
}



#card-container {
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--card-background) 100%);
    padding: 1.5rem 1rem;
    border-radius: 15px;
    margin-bottom: 1rem;
    min-height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1rem, 3vw, 1.2rem);
    text-align: center;
    transition: var(--transition);
    box-shadow: var(--shadow-medium);
    -webkit-overflow-scrolling: touch;
    transform: translateZ(0);
    will-change: transform, opacity;
    position: relative;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

#card-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
    transition: left 0.5s;
}

#card-container.loading::before {
    left: 100%;
}

.word-details {
    background: white;
    padding: clamp(1.25rem, 4vw, 2rem);
    border-radius: var(--border-radius);
    margin-top: 1.5rem;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
}

.word-details h3 {
    font-size: clamp(1.1rem, 4vw, 1.3rem);
    color: var(--primary-color);
    margin-bottom: 1rem;
    border-bottom: 2px solid var(--primary-light);
    padding-bottom: 0.5rem;
    font-weight: 600;
}

.word-details p {
    font-size: clamp(0.92rem, 2.5vw, 1rem);
    line-height: 1.7;
    color: var(--text-color);
    margin-bottom: 1rem;
}

.word-details ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

.word-details li {
    font-size: clamp(1rem, 3.5vw, 1.1rem);
    line-height: 1.8;
    color: var(--text-color);
    margin-bottom: 1rem;
    padding-left: 1.5rem;
    position: relative;
}

.word-details li:before {
    content: "•";
    position: absolute;
    left: 0;
    color: var(--primary-color);
}

#user-input {
    width: 100%;
    padding: 1.2rem;
    font-size: 1.1rem;
    border: 2px solid var(--border-color);
    border-radius: 15px;
    margin-bottom: 1rem;
    transition: var(--transition);
    background: var(--card-background);
    color: var(--text-color);
    -webkit-appearance: none;
    appearance: none;
    box-shadow: var(--shadow-light);
    text-align: center;
    font-weight: 500;
}

#user-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(46, 204, 113, 0.15);
}

#user-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(46, 204, 113, 0.2);
}

.button-group {
    display: flex;
    gap: 0.8rem;
    justify-content: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    padding: 0 0.5rem;
}

button {
    padding: 1rem 2rem;
    font-size: 1.1rem;
    border: none;
    border-radius: 15px;
    cursor: pointer;
    transition: var(--transition);
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-width: 140px;
    min-height: 50px;
    -webkit-appearance: none;
    appearance: none;
    transform: translateZ(0);
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    -webkit-tap-highlight-color: transparent;
}

button::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.3s, height 0.3s;
}

button:active::before {
    width: 300px;
    height: 300px;
}

#check-btn {
    background: var(--primary-color);
    color: white;
}

#next-btn {
    background: var(--secondary-color);
    color: white;
}

button:hover, button:focus {
    transform: translateY(-1px) translateZ(0);
    box-shadow: var(--shadow-medium);
    outline: none;
}

#check-btn:hover, #check-btn:focus {
    background: var(--primary-dark);
}

#next-btn:hover, #next-btn:focus {
    background: #2980b9;
}

#feedback {
    text-align: center;
    padding: 1rem;
    border-radius: var(--border-radius);
    margin-top: 1rem;
    font-weight: 500;
    transition: var(--transition);
    font-size: clamp(0.9rem, 3vw, 1rem);
}

.correct {
    background: #d4f8e8;
    color: var(--success-color);
    border: 2px solid var(--success-color);
}

.incorrect {
    background: #fde8e8;
    color: var(--error-color);
    border: 2px solid var(--error-color);
}

.hint {
    background: #f3e8ff;
    color: var(--hint-color);
    border: 2px solid var(--hint-color);
}

.tip {
    background: #e8f8f3;
    padding: 1.5rem;
    border-radius: var(--border-radius);
    border-left: 4px solid var(--primary-color);
    margin-top: 1.5rem;
    font-size: clamp(0.9rem, 3vw, 1rem);
}

.keyboard-hint {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-top: 1rem;
    padding: 0.8rem;
    background: var(--card-background);
    border-radius: 15px;
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
}

.keyboard-hint kbd {
    background: var(--primary-color);
    color: white;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
}

.progress-info {
    margin-top: 1.5rem;
    padding: 1.2rem;
    background: var(--card-background);
    border-radius: 20px;
    box-shadow: var(--shadow-medium);
    border: 1px solid var(--border-color);
    backdrop-filter: blur(10px);
}

.progress-container {
    margin-bottom: 1rem;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #e2e8f0;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.progress {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--primary-light));
    border-radius: 4px;
    transition: width 0.3s ease;
    position: relative;
}

.progress::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

.progress-text {
    text-align: center;
    font-weight: 600;
    color: var(--text-color);
    font-size: 0.9rem;
}

.stats {
    display: flex;
    justify-content: space-around;
    gap: 1rem;
    flex-wrap: wrap;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-color);
    font-size: 0.9rem;
    font-weight: 500;
}

.stat-item i {
    color: var(--primary-color);
    width: 16px;
    text-align: center;
}

.menu-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: white;
    cursor: pointer;
    transition: var(--transition);
    backdrop-filter: blur(10px);
}

.menu-icon:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-1px);
}

.menu-icon.active {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.4);
}

.menu-icon i {
    font-size: 14px;
    transition: var(--transition);
}

.menu-icon.active i {
    transform: rotate(90deg);
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--card-background);
    border-radius: 0 0 15px 15px;
    box-shadow: var(--shadow-medium);
    min-width: 180px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: var(--transition);
    z-index: 1000;
    border: 1px solid var(--border-color);
    border-top: none;
}

.dropdown-menu.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.875rem 1rem;
    background: transparent;
    border: none;
    color: var(--text-color);
    font-size: 0.95rem;
    cursor: pointer;
    transition: var(--transition);
    border-bottom: 1px solid var(--border-color);
    text-align: left;
}

.menu-item:last-child {
    border-bottom: none;
    border-radius: 0 0 15px 15px;
}

.menu-item:hover {
    background: var(--primary-light);
    color: var(--primary-color);
}

.menu-item.active {
    background: var(--primary-light);
    color: var(--primary-color);
}

.menu-item i {
    width: 18px;
    text-align: center;
    font-size: 0.9rem;
}

.settings-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
}

.settings-panel.show {
    display: flex;
}

.settings-content {
    background: var(--card-background);
    padding: 2rem;
    border-radius: 20px;
    width: 90%;
    max-width: 400px;
    box-shadow: var(--shadow-heavy);
    animation: slideIn 0.3s ease;
    border: 1px solid var(--border-color);
}

.settings-content h3 {
    margin-bottom: 1.5rem;
    color: var(--primary-color);
    font-size: 1.3rem;
    text-align: center;
}

.setting-item {
    margin-bottom: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.setting-item label {
    font-weight: 500;
    color: var(--text-color);
}

.setting-item input, .setting-item select {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    width: 100px;
    background: var(--card-background);
    color: var(--text-color);
}

.close-settings {
    width: 100%;
    margin-top: 1rem;
    background: var(--primary-color);
    color: white;
}

.user-stats {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
    justify-content: space-around;
}

.stat-card {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-light));
    color: white;
    padding: 1rem;
    border-radius: 15px;
    display: flex;
    align-items: center;
    gap: 0.8rem;
    flex: 1;
    box-shadow: 0 4px 15px rgba(46, 204, 113, 0.3);
    transition: var(--transition);
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(46, 204, 113, 0.4);
}

.stat-card i {
    font-size: 1.5rem;
    opacity: 0.9;
}

.stat-info {
    display: flex;
    flex-direction: column;
}

.stat-number {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1;
}

.stat-label {
    font-size: 0.8rem;
    opacity: 0.9;
    font-weight: 500;
}

.round-score {
    margin-top: 1.5rem;
    padding: 1.5rem;
    background: var(--card-background);
    border-radius: 20px;
    box-shadow: var(--shadow-medium);
    border: 1px solid var(--border-color);
    text-align: center;
}

.score-header h3 {
    color: var(--primary-color);
    margin-bottom: 1rem;
    font-size: 1.3rem;
}

.score-stats {
    display: flex;
    justify-content: space-around;
    margin-bottom: 1.5rem;
    gap: 1rem;
}

.score-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.score-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.score-value {
    font-size: 1.8rem;
    font-weight: 700;
    padding: 0.5rem 1rem;
    border-radius: 10px;
    min-width: 50px;
}

.score-value.correct {
    color: white;
    background: var(--success-color);
}

.score-value.incorrect {
    color: white;
    background: var(--error-color);
}

.score-value.points {
    color: white;
    background: linear-gradient(135deg, #f39c12, #e67e22);
}

.new-round-btn {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    padding: 1rem 2rem;
    border: none;
    border-radius: 15px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin: 0 auto;
    min-width: 150px;
}

.new-round-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-medium);
}

.empty-state, .welcome-state {
    text-align: center;
    padding: 3rem 1rem;
    color: #64748b;
}

.empty-icon, .welcome-icon {
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, var(--primary-light), var(--primary-color));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1.5rem;
    box-shadow: 0 8px 25px rgba(46, 204, 113, 0.3);
}

.empty-icon i, .welcome-icon i {
    font-size: 2rem;
    color: white;
}

.empty-state h3, .welcome-state h3 {
    font-size: 1.5rem;
    color: var(--text-color);
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.empty-state p, .welcome-state p {
    font-size: 1rem;
    line-height: 1.6;
    max-width: 300px;
    margin: 0 auto;
}

@keyframes fadeIn {
    from { 
        opacity: 0; 
        transform: translateY(10px) translateZ(0); 
    }
    to { 
        opacity: 1; 
        transform: translateY(0) translateZ(0); 
    }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-20px) translateZ(0);
    }
    to {
        opacity: 1;
        transform: translateX(0) translateZ(0);
    }
}

@keyframes pulse {
    0%, 100% { transform: scale(1) translateZ(0); }
    50% { transform: scale(1.02) translateZ(0); }
}

.fade-in {
    animation: fadeIn 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.slide-in {
    animation: slideIn 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.pulse {
    animation: pulse 0.5s ease-in-out;
}

/* Mobile Optimizations */
@media (max-width: 768px) {
    .content-area {
        padding: 1rem 0.8rem;
        border-radius: 25px 25px 0 0;
    }

    .button-group {
        flex-direction: column;
        gap: 0.8rem;
        padding: 0;
    }

    button {
        width: 100%;
        min-height: 55px;
        font-size: 1.1rem;
    }

    select {
        width: 100%;
        padding: 1rem 2.5rem 1rem 1rem;
        font-size: 1.1rem;
        border-radius: 15px;
    }

    #card-container {
        margin: 0 0 1rem;
        border-radius: 12px;
        min-height: 100px;
        padding: 1rem 0.8rem;
        font-size: 1rem;
    }
    
    /* Optimize for virtual keyboard */
    @media (max-height: 600px) {
        #card-container {
            min-height: 80px;
            padding: 0.8rem;
            margin-bottom: 0.8rem;
        }
        
        .content-area {
            padding: 0.8rem;
        }
        
        .progress-info {
            margin-top: 1rem;
            padding: 1rem;
        }
    }

    .word-details {
        border-radius: 15px;
        padding: 1.5rem;
    }
    
    .stats {
        flex-direction: row;
        justify-content: space-around;
        gap: 0.5rem;
    }
    
    .stat-item {
        font-size: 0.85rem;
    }
    
    .title-main {
        font-size: 1.8rem;
    }
    
    .title-sub {
        font-size: 1.1rem;
    }
    
    .app-title {
        gap: 0.8rem;
    }
    
    .title-icon {
        width: 45px;
        height: 45px;
    }
    
    .title-icon i {
        font-size: 1.3rem;
    }
    
    .user-stats {
        flex-direction: column;
        gap: 0.8rem;
    }
    
    .stat-card {
        justify-content: center;
    }
    
    .score-stats {
        flex-direction: column;
        gap: 1rem;
    }
    
    .score-item {
        flex-direction: row;
        justify-content: space-between;
        padding: 0.5rem 1rem;
        background: rgba(0, 0, 0, 0.05);
        border-radius: 10px;
    }
    
    .score-value {
        font-size: 1.5rem;
        min-width: 40px;
    }
    
    .dropdown-menu {
        min-width: 160px;
    }
    
    .menu-item {
        padding: 1rem;
        font-size: 1rem;
    }
    
    .keyboard-hint {
        font-size: 0.8rem;
        line-height: 1.4;
        padding: 0.8rem;
    }
    
    .keyboard-hint kbd {
        font-size: 0.75rem;
        padding: 0.15rem 0.4rem;
    }
    
    .brand-title {
        font-size: 1.1rem;
    }
    
    .brand-subtitle {
        font-size: 0.75rem;
    }
    
    .brand-icon {
        width: 35px;
        height: 35px;
        font-size: 1rem;
    }
    
    .navbar {
        padding: env(safe-area-inset-top, 12px) 1rem 12px;
    }
}

/* iPhone X and newer safe areas */
@supports (padding: max(0px)) {
    .app-header {
        padding-top: max(env(safe-area-inset-top), 20px);
    }
    
    .content-area {
        padding-bottom: max(env(safe-area-inset-bottom), 1rem);
    }
}

/* Touch improvements */
@media (hover: none) and (pointer: coarse) {
    button:hover {
        transform: none;
    }
    
    button:active {
        transform: scale(0.98);
    }
    
    select:hover {
        transform: none;
    }
}

/* Word details dark theme */
.word-details {
    background: var(--card-background);
    border: 1px solid var(--border-color);
}

/* Empty states dark theme */
.empty-state h3, .welcome-state h3 {
    color: var(--text-color);
}

.empty-state p, .welcome-state p {
    color: var(--text-secondary);
}

/* Sound and theme button states */
.control-btn.sound-off i::before {
    content: '\f026';
}

body.dark-theme {
    --text-color: #e2e8f0;
    --card-background: #1a202c;
    --primary-light: #4a5568;
}

body.dark-theme .app-header {
    background: linear-gradient(135deg, #2d3748 0%, #1a202c 100%);
}