:root {
    --primary-bg: #8E2DE2; /* Fallback */
    --gradient-bg: linear-gradient(135deg, #4A00E0, #8E2DE2);
    --card-bg: rgba(255, 255, 255, 0.95);
    --text-main: #2d3436;
    --text-muted: #636e72;
    --primary-color: #6c5ce7;
    --primary-hover: #5f27cd;
    --secondary-color: #00cec9;
    --success-color: #00b894;
    --danger-color: #d63031;
    --btn-shadow: 0 4px 6px rgba(0,0,0,0.1);
    --card-shadow: 0 10px 30px rgba(0,0,0,0.2);
    --radius: 16px;
    --font-family: 'Outfit', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: var(--font-family);
    -webkit-tap-highlight-color: transparent;
}

body {
    background: var(--gradient-bg);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--text-main);
    padding: 20px;
}

.app-container {
    width: 100%;
    max-width: 480px;
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--card-shadow);
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
}

.screen {
    display: none;
    flex-direction: column;
    padding: 20px;
    height: 100%;
    flex: 1;
    animation: fadeIn 0.4s ease-out;
}

.screen.active {
    display: flex;
}

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

/* Typography */
h1 {
    text-align: center;
    color: var(--primary-color);
    font-size: 2.2rem;
    margin-bottom: 5px;
    font-weight: 800;
}

h2 {
    text-align: center;
    font-size: 2rem;
    color: var(--primary-color);
    margin-bottom: 20px;
}

.subtitle {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 25px;
    font-size: 1.1rem;
}

.text-success { color: var(--success-color); font-weight: bold; }
.text-danger { color: var(--danger-color); font-weight: bold; }

/* Setup Screen */
.tables-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    margin-bottom: 25px;
}

.checkbox-btn {
    position: relative;
    display: block;
    cursor: pointer;
}

.checkbox-btn input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
}

.checkbox-btn span {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 50px;
    background: #f1f2f6;
    border-radius: 12px;
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-muted);
    transition: all 0.2s ease;
    border: 2px solid transparent;
}

.checkbox-btn input:checked ~ span {
    background: rgba(108, 92, 231, 0.1);
    color: var(--primary-color);
    border-color: var(--primary-color);
    box-shadow: 0 4px 10px rgba(108, 92, 231, 0.2);
    transform: translateY(-2px);
}

.checkbox-btn:hover span {
    transform: translateY(-2px);
    box-shadow: var(--btn-shadow);
}

.settings-group {
    display: flex;
    flex-direction: column;
    margin-bottom: 20px;
    background: #f1f2f6;
    padding: 15px;
    border-radius: 12px;
}

.settings-group label {
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--text-main);
}

.settings-group input[type="number"] {
    padding: 12px;
    border: 2px solid #dfe6e9;
    border-radius: 8px;
    font-size: 1.2rem;
    outline: none;
    transition: border-color 0.2s;
    text-align: center;
    font-weight: bold;
    color: var(--primary-color);
}

.settings-group input[type="number"]:focus {
    border-color: var(--primary-color);
}

/* Buttons */
button {
    border: none;
    outline: none;
    cursor: pointer;
    font-family: var(--font-family);
    transition: transform 0.1s, box-shadow 0.2s, background 0.2s;
}

button:active {
    transform: scale(0.95);
}

.primary-btn {
    background: var(--primary-color);
    color: white;
    padding: 16px;
    border-radius: 12px;
    font-size: 1.3rem;
    font-weight: bold;
    width: 100%;
    box-shadow: 0 6px 15px rgba(108, 92, 231, 0.4);
    margin-top: auto;
}

.primary-btn:hover {
    background: var(--primary-hover);
    box-shadow: 0 8px 20px rgba(108, 92, 231, 0.5);
    transform: translateY(-2px);
}

.secondary-btn {
    background: transparent;
    color: var(--text-muted);
    padding: 12px;
    font-size: 1.1rem;
    font-weight: 600;
    width: 100%;
    margin-top: 15px;
}

.secondary-btn:hover {
    color: var(--text-main);
}

/* Game Screen */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    font-size: 1.2rem;
    font-weight: bold;
    background: #f1f2f6;
    padding: 10px 20px;
    border-radius: 30px;
}

.timer-display {
    color: var(--danger-color);
    display: flex;
    align-items: center;
    gap: 5px;
}

.score-display {
    color: var(--primary-color);
}

.equation-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 20px;
    flex: 1;
    justify-content: center;
}

#equation {
    font-size: 3rem;
    font-weight: 800;
    color: var(--text-main);
    margin-bottom: 10px;
    text-align: center;
}

.answer-box {
    width: 150px;
    height: 70px;
    background: #f1f2f6;
    border: 3px solid #dfe6e9;
    border-radius: 16px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--primary-color);
    transition: all 0.3s;
}

.answer-box.correct {
    background: #dff9fb;
    border-color: var(--success-color);
    color: var(--success-color);
    animation: popIn 0.3s ease;
}

.answer-box.wrong {
    background: #ffebcc;
    border-color: var(--danger-color);
    color: var(--danger-color);
    animation: shake 0.4s ease;
}

@keyframes popIn {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

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

/* Numpad */
.numpad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 15px;
}

.num-btn {
    background: white;
    border: 2px solid #dfe6e9;
    color: var(--text-main);
    font-size: 1.6rem;
    font-weight: bold;
    height: 60px;
    border-radius: 12px;
    box-shadow: 0 4px 0 #dfe6e9;
    transition: all 0.1s;
}

.num-btn:active {
    transform: translateY(4px);
    box-shadow: 0 0 0 #dfe6e9;
}

.action-btn {
    font-size: 1.4rem;
    font-weight: bold;
    height: 60px;
    border-radius: 12px;
    color: white;
    box-shadow: 0 4px 0 rgba(0,0,0,0.2);
}

.action-btn:active {
    transform: translateY(4px);
    box-shadow: 0 0 0 transparent;
}

.clear-btn {
    background: #ff7675;
    border: 2px solid #d63031;
    box-shadow: 0 4px 0 #d63031;
}

.submit-btn {
    background: var(--success-color);
    border: 2px solid #00a884;
    box-shadow: 0 4px 0 #00a884;
}

/* Result Screen */
.final-score-container {
    background: var(--gradient-bg);
    color: white;
    border-radius: 16px;
    padding: 20px;
    text-align: center;
    margin-bottom: 20px;
    box-shadow: 0 6px 15px rgba(74, 0, 224, 0.3);
}

.final-score-container p {
    font-size: 1rem;
    margin-bottom: 5px;
    opacity: 0.9;
}

.final-score-value {
    font-size: 3.5rem;
    font-weight: 800;
    line-height: 1;
}

.stats {
    background: #f1f2f6;
    padding: 15px;
    border-radius: 16px;
    margin-bottom: 20px;
    font-size: 1.1rem;
}

.stats p {
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
}

.stats p:last-child {
    margin-bottom: 0;
}

.table-stats {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 8px;
    margin-bottom: 20px;
}

.table-stat-item {
    background: #f1f2f6;
    padding: 8px;
    border-radius: 12px;
    text-align: center;
    font-size: 0.9rem;
    font-weight: 600;
}

.table-stat-item span {
    display: block;
    font-size: 1.1rem;
    font-weight: 800;
    margin-top: 4px;
}

.table-stat-item .good { color: var(--success-color); }
.table-stat-item .bad { color: var(--danger-color); }
.table-stat-item .neutral { color: var(--text-muted); }

@media (max-width: 480px) {
    .tables-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    .checkbox-btn span {
        height: 40px;
    }
    #equation {
        font-size: 2.5rem;
    }
    .answer-box {
        width: 130px;
        height: 55px;
        font-size: 2rem;
    }
    .num-btn, .action-btn {
        height: 55px;
    }
}
