/* CSS Reset & Base */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    background: linear-gradient(135deg, #ff6b6b, #ff9f43);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 15px;
}

/* Preloader */
#preloader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #fff;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.3s ease;
}

#preloader.hide {
    opacity: 0;
    pointer-events: none;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #ff6b6b;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-text {
    margin-top: 20px;
    font-size: 1.2em;
    color: #666;
}

/* Game Container */
.game-container {
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.15);
    max-width: 900px;
    width: 100%;
    padding: 30px;
    opacity: 0;
    animation: fadeIn 0.5s ease forwards;
}

@keyframes fadeIn {
    to { opacity: 1; }
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 25px;
}

.title {
    color: #2d3748;
    font-size: 2.5em;
    font-weight: bold;
    margin-bottom: 10px;
}

.subtitle {
    color: #718096;
    font-size: 1.2em;
}

/* Operation & Difficulty Selectors */
.operation-selector, .difficulty-selector {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-bottom: 20px;
}

.operation-btn, .difficulty-btn {
    background: #ff6b6b;
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 15px;
    font-size: 1em;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 600;
}

.operation-btn:hover, .difficulty-btn:hover {
    transform: translateY(-2px);
    background: #ff5252;
}

.operation-btn.active {
    background: #ff9f43;
}

.difficulty-btn {
    background: #5f27cd;
}

.difficulty-btn.active {
    background: #00d2d3;
}

/* Progress Bar */
.progress-container {
    background: #e2e8f0;
    height: 12px;
    border-radius: 6px;
    margin-bottom: 20px;
    overflow: hidden;
}

.progress-fill {
    background: linear-gradient(90deg, #ff6b6b, #ff9f43);
    height: 100%;
    width: 0%;
    transition: width 0.3s ease;
    border-radius: 6px;
}

/* Game Stats */
.game-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    margin-bottom: 20px;
}

.stat-card {
    background: #5f27cd;
    padding: 15px;
    border-radius: 12px;
    color: white;
    text-align: center;
    transition: transform 0.2s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
}

.stat-value {
    font-size: 1.8em;
    font-weight: bold;
    margin-bottom: 5px;
}

.stat-label {
    font-size: 0.9em;
    opacity: 0.9;
}

/* Question Section */
.question-section {
    background: #f8f9fa;
    padding: 25px;
    border-radius: 15px;
    margin-bottom: 20px;
    border: 2px solid #e2e8f0;
}

.operation-type {
    background: #ff6b6b;
    color: white;
    padding: 10px 20px;
    border-radius: 20px;
    display: inline-block;
    font-size: 1em;
    margin-bottom: 20px;
    font-weight: bold;
}

.problem {
    font-size: 1.5em;
    color: #2d3748;
    margin-bottom: 20px;
    text-align: center;
    font-weight: 600;
}

.expression-display {
    font-family: 'Courier New', monospace;
    background: #fff5f5;
    padding: 20px;
    border-radius: 15px;
    font-size: 1.6em;
    text-align: center;
    margin: 20px 0;
    color: #c53030;
    font-weight: bold;
    border: 2px solid #feb2b2;
}

/* Options Grid */
.options-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    margin-bottom: 20px;
}

.option {
    background: #00d2d3;
    color: white;
    border: none;
    padding: 15px 20px;
    border-radius: 12px;
    font-size: 1.2em;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 600;
    min-height: 70px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.option:hover {
    transform: translateY(-2px);
    background: #17a2b8;
}

.option.correct {
    background: #28a745;
    animation: correctPulse 0.5s ease;
}

.option.incorrect {
    background: #dc3545;
    animation: shake 0.3s ease;
}

@keyframes correctPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

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

/* Feedback */
.feedback {
    padding: 20px;
    border-radius: 12px;
    margin: 20px 0;
    text-align: center;
    font-weight: bold;
    font-size: 1.2em;
    animation: fadeIn 0.3s ease;
}

.feedback.correct {
    background: #d4edda;
    color: #155724;
    border: 2px solid #c3e6cb;
}

.feedback.incorrect {
    background: #f8d7da;
    color: #721c24;
    border: 2px solid #f5c6cb;
}

/* Helper Boxes */
.hint-box {
    background: #fff3cd;
    color: #856404;
    padding: 15px;
    border-radius: 10px;
    margin: 15px 0;
    border: 2px solid #ffeaa7;
}

.steps-box {
    background: #e8f4f8;
    color: #0c5460;
    padding: 20px;
    border-radius: 12px;
    margin: 20px 0;
    border-left: 4px solid #17a2b8;
}

.step {
    margin: 10px 0;
    font-size: 1.1em;
}

.step-title {
    font-weight: bold;
    margin-bottom: 10px;
}

.formula-box {
    background: #f0f3ff;
    color: #1e3a8a;
    padding: 20px;
    border-radius: 12px;
    margin: 20px 0;
    border: 2px solid #3b82f6;
}

/* Control Buttons */
.control-buttons {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin: 20px 0;
    flex-wrap: wrap;
}

.control-btn {
    background: #5f27cd;
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 15px;
    font-size: 1em;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: bold;
}

.control-btn:hover {
    transform: translateY(-2px);
    background: #341f97;
}

/* Results Screen */
.results-screen {
    text-align: center;
    padding: 30px;
    background: linear-gradient(135deg, #ffecd2, #fcb69f);
    border-radius: 20px;
    animation: fadeIn 0.5s ease;
}

.performance-chart {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    margin: 25px 0;
}

.chart-item {
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.chart-value {
    font-size: 2.2em;
    font-weight: bold;
    color: #2d3748;
    margin-bottom: 5px;
}

.chart-label {
    color: #718096;
    margin-top: 5px;
}

/* Formula Reference */
.formula-reference {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 15px;
    margin-top: 25px;
    border: 2px solid #dee2e6;
}

.formula-reference h3 {
    color: #2d3748;
    margin-bottom: 15px;
    text-align: center;
    font-size: 1.3em;
}

.formula-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 12px;
}

.formula-item {
    background: white;
    padding: 12px;
    border-radius: 8px;
    border-left: 4px solid #ff6b6b;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

/* Timer Warning */
.timer-warning {
    background: #dc3545 !important;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .game-container {
        padding: 20px;
        margin: 10px;
    }
    
    .title {
        font-size: 2em;
    }
    
    .expression-display {
        font-size: 1.3em;
        padding: 15px;
    }
    
    .options-grid {
        grid-template-columns: 1fr;
    }
    
    .game-stats {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .control-buttons {
        gap: 10px;
    }
    
    .control-btn {
        padding: 10px 15px;
        font-size: 0.9em;
    }
    
    .formula-grid {
        grid-template-columns: 1fr;
    }
}