#spelling-container {
    max-width: 300px;
    margin: 20px auto;
    text-align: center;
}

#medals-row {
    width: 100%;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#perfect-counter {
    font-size: 16px;
    font-weight: bold;
    color: #8B4513;
}

#unlocked-counter {
    width: 30px;
    height: 30px;
    border: 1px solid #A9A9A9;
    background: #f5f5f5;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
    color: #333;
    border-radius: 2px;
}

#progress-bar-overall {
    display: flex;
    align-items: center;
    gap: 8px;
}

#progress-fill {
    width: 150px;
    height: 12px;
    background: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 6px;
    position: relative;
    overflow: hidden;
}

#progress-fill::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: var(--progress-width, 0%);
    background: linear-gradient(90deg, #ff8c00, #ffd4a3);
    transition: width 0.5s ease;
    border-radius: 5px;
}

#progress-percentage {
    font-size: 14px;
    font-weight: bold;
    color: #ff8c00;
    min-width: 40px;
}

#spelling-grid {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
    /* REMOVED: aspect-ratio: 1; - This was causing iOS Safari issues */
    table-layout: fixed; /* Added for consistent cell sizing */
}

#spelling-grid td {
    width: 10%;
    height: 0;
    padding-bottom: 10%;
    border: 1px solid #A9A9A9;
    text-align: center;
    vertical-align: middle;
    cursor: pointer;
    background: #f5f5f5;
    position: relative;
    font-size: 10px;
    font-weight: normal;
    box-sizing: border-box;
}

#spelling-grid td.locked {
    background: #666;
    cursor: not-allowed;
    border: 1px solid #A9A9A9;
}

#spelling-grid td:not(.locked):hover {
    background: #e0e0e0;
}

/* 6-Tier Accuracy Color System */
#spelling-grid td.tier-perfect {
    background: linear-gradient(45deg, #FFD700, #FFA500, #FFD700); /* Gold gradient: 100% */
    color: #8B4513;
    font-weight: bold;
    box-shadow: 0 0 8px rgba(255, 215, 0, 0.6);
    animation: shimmer 2s infinite;
}

#spelling-grid td.tier-excellent {
    background: #28a745; /* Dark Green: 90-99% */
    color: white;
    font-weight: bold;
}

#spelling-grid td.tier-good {
    background: #20c997; /* Light Green: 80-89% */
    color: white;
    font-weight: bold;
}

#spelling-grid td.tier-average {
    background: #87CEEB; /* Light Blue: 70-79% */
    color: #2c5282;
    font-weight: bold;
}

#spelling-grid td.tier-below {
    background: #fd7e14; /* Orange: 60-69% */
    color: white;
    font-weight: bold;
}

#spelling-grid td.tier-poor {
    background: #dc3545; /* Red: 0-59% */
    color: white;
    font-weight: bold;
}

#spelling-grid td.active {
    background: #007bff !important;
    border: 1px solid #A9A9A9;
    color: white !important;
    font-weight: bold;
    box-shadow: 0 0 10px rgba(0, 123, 255, 0.5);
}

/* Perfect score animation */
@keyframes shimmer {
    0% { background: linear-gradient(45deg, #FFD700, #FFA500, #FFD700); }
    50% { background: linear-gradient(45deg, #FFA500, #FFD700, #FFA500); }
    100% { background: linear-gradient(45deg, #FFD700, #FFA500, #FFD700); }
}

/* Perfect square content positioning */
#spelling-grid td > span {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

#spelling-grid td.tier-perfect > span {
    font-size: 16px;
}

/* iOS Safari specific fixes */
@supports (-webkit-appearance: none) {
    #spelling-grid {
        /* Force recalculation on iOS Safari */
        will-change: transform;
        transform: translateZ(0);
    }
    
    #spelling-grid td {
        /* Ensure proper rendering on iOS */
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
    }
}

/* Additional iOS Safari compatibility */
@media screen and (-webkit-min-device-pixel-ratio: 1) {
    #spelling-grid {
        /* Remove any potential layout issues */
        contain: layout;
    }
}

/* Progress Bar Styling */
#progress-bar-container {
    margin: 20px 0;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #dee2e6;
}

#progress-bar {
    display: flex;
    height: 20px;
    background: #e9ecef;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid #ced4da;
}

.progress-segment {
    flex: 1;
    height: 100%;
    background: #e9ecef;
    border-right: 1px solid #ced4da;
    transition: background-color 0.3s ease;
    position: relative;
}

.progress-segment:last-child {
    border-right: none;
}

.progress-segment.current {
    background: #ffc107;
    animation: pulse 1s infinite;
}

.progress-segment.correct {
    background: #28a745;
}

.progress-segment.incorrect {
    background: #dc3545;
}

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

/* Input Container - New styling for standalone input field */
#spelling-input-container {
    margin: 15px 0;
    padding: 10px;
    background: #ffffff;
    border-radius: 8px;
    border: 1px solid #dee2e6;
}

#spelling-input {
    width: 100%;
    max-width: 280px;
    padding: 12px;
    border: 2px solid #ccc;
    border-radius: 6px;
    font-size: 16px;
    text-align: center;
    box-sizing: border-box;
    transition: border-color 0.3s ease, background-color 0.3s ease;
    /* MOBILE FIX: Prevent zoom on iOS */
    -webkit-text-size-adjust: 100%;
    /* MOBILE FIX: Ensure input stays focused */
    -webkit-user-select: text;
    user-select: text;
}

#spelling-input:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 5px rgba(0, 123, 255, 0.3);
    /* MOBILE FIX: Ensure focus is maintained */
    -webkit-tap-highlight-color: transparent;
}

#spelling-input:disabled {
    background: #f5f5f5;
    color: #999;
    border-color: #ddd;
}

#spelling-input.correct {
    border-color: #28a745;
    background: #d4edda;
}

#spelling-input.incorrect {
    border-color: #dc3545;
    background: #f8d7da;
}

/* Answer display styling for showing both English and Chinese */
#answer-display {
    margin-top: 10px;
    padding: 8px 12px;
    border-radius: 6px;
    font-weight: bold;
    text-align: center;
}

#answer-display.show-correct {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

#answer-display.show-incorrect {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

#answer-display .english {
    font-size: 16px;
    margin-bottom: 4px;
}

#answer-display .chinese {
    font-size: 14px;
    color: #666;
}

/* Quiz Controls - Updated to remove input field from flex layout */
#spelling-quiz {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    padding: 15px;
    border: 1px solid #ccc;
    background: #fafafa;
    border-radius: 8px;
}

#quiz-bank-selector {
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 6px;
    background: white;
    font-size: 14px;
    min-width: 120px;
    max-width: 180px;
}

#pronounce-btn, #back-btn {
    padding: 12px 16px;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 6px;
    white-space: nowrap;
    font-size: 14px;
    transition: background-color 0.2s ease;
    -webkit-tap-highlight-color: rgba(0,0,0,0.1);
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

#pronounce-btn:hover, #back-btn:hover {
    background: #f0f0f0;
}

#pronounce-btn:active, #back-btn:active {
    background: #e6e6e6;
    /* MOBILE FIX: Visual feedback without focus */
    transform: scale(0.98);
}

#pronounce-btn {
    display: none;
}

#pronounce-btn:disabled {
    background: #f5f5f5;
    color: #999;
    cursor: not-allowed;
}

/* MOBILE FIX: Specific mobile button styling */
@media (max-width: 768px) {
    #pronounce-btn, #back-btn {
        /* Ensure buttons don't interfere with input focus */
        -webkit-tap-highlight-color: transparent;
        /* Larger touch targets for mobile */
        min-height: 44px;
        min-width: 44px;
        /* Prevent accidental focus */
        -webkit-focus-ring-color: transparent;
        focus-ring-color: transparent;
    }
    
    /* MOBILE FIX: Ensure input field gets proper focus handling */
    #spelling-input {
        /* Larger touch target */
        min-height: 44px;
        /* Prevent zoom on focus for iOS */
        font-size: 16px;
        /* Better mobile input handling */
        -webkit-appearance: none;
        appearance: none;
        border-radius: 8px;
    }
    
    /* MOBILE FIX: Input focus state for mobile */
    #spelling-input:focus {
        /* Stronger focus indication on mobile */
        border-width: 3px;
        /* Ensure keyboard stays visible */
        -webkit-user-select: text;
        user-select: text;
    }
}

/* MOBILE FIX: iOS specific fixes */
@supports (-webkit-touch-callout: none) {
    #pronounce-btn, #back-btn {
        /* Prevent long press menu on iOS */
        -webkit-touch-callout: none;
        /* Prevent selection highlighting */
        -webkit-user-select: none;
        user-select: none;
        /* Prevent focus ring */
        -webkit-tap-highlight-color: transparent;
    }
    
    #spelling-input {
        /* iOS specific input handling */
        -webkit-appearance: none;
        appearance: none;
        /* Prevent auto-zoom on focus */
        font-size: 16px;
    }
}

/* Responsive Design */
@media (max-width: 400px) {
    #spelling-container {
        max-width: 250px; /* Even smaller on mobile */
    }
    
    #spelling-grid td {
        font-size: 8px;
    }
    
    #spelling-input-container {
        margin: 10px 0;
        padding: 8px;
    }
    
    #spelling-input {
        max-width: 100%;
        font-size: 16px; /* Keep 16px to prevent zoom on iOS */
        padding: 12px; /* Maintain good touch target */
        min-height: 44px; /* Apple's recommended minimum touch target */
    }
    
    #spelling-quiz {
        flex-direction: column;
        gap: 10px;
        padding: 10px;
    }
    
    #quiz-bank-selector {
        width: 50%;
        min-height: 44px;
        font-size: 16px; /* Prevent zoom on iOS */
    }
    
    #pronounce-btn, #back-btn {
        width: 100%;
        padding: 12px 20px;
        min-height: 44px; /* Apple's recommended minimum touch target */
    }
}