:root {
    --bg-color: #fce4ec; 
    --card-bg: rgba(255, 255, 255, 0.9);
    --text-primary: #37474f;
    --primary-color: #ba68c8; 
    --secondary-color: #81c784; 
    --error-color: #e57373; 
    --shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Nunito', sans-serif;
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background 1s ease;
    overflow-x: hidden;
}

.body-level-1 { background: linear-gradient(135deg, #FFDEE9 0%, #B5FFFC 100%); }
.body-level-2 { background: linear-gradient(135deg, #E0C3FC 0%, #8EC5FC 100%); }
.body-level-3 { background: linear-gradient(135deg, #a1c4fd 0%, #c2e9fb 100%); }
.body-level-4 { background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 100%); }
.body-level-5 { background: linear-gradient(135deg, #fbc2eb 0%, #a6c1ee 100%); }
.body-level-max { background: linear-gradient(135deg, #ffc3a0 0%, #ffafbd 100%); }

.app-container {
    background: var(--card-bg);
    width: 90%;
    max-width: 450px;
    border-radius: 24px;
    padding: 30px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.6);
    text-align: center;
    position: absolute;
    transition: opacity 0.4s ease, transform 0.4s ease, visibility 0.4s;
    visibility: visible;
}

.hidden {
    opacity: 0;
    transform: scale(0.95);
    visibility: hidden;
    pointer-events: none;
    z-index: -1;
}

.slide-in {
    opacity: 1;
    transform: scale(1);
    z-index: 1;
}

.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 20px;
    width: 85%;
    max-width: 350px;
    text-align: center;
    box-shadow: 0 15px 50px rgba(0,0,0,0.2);
    transform: scale(1);
    transition: transform 0.3s ease;
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}
.modal-overlay.hidden .modal-content { transform: scale(0.9); }

.user-greeting { font-size: 0.9rem; color: #78909c; text-align: left; margin-bottom: 5px; font-weight: bold; }
h1 { font-size: 2.2rem; color: var(--primary-color); margin: 0 0 5px 0; }
h2 { color: var(--text-primary); margin-top: 0; }
.subtitle { color: #78909c; margin-bottom: 25px; font-weight: 600; }

.action-btn {
    display: block;
    width: 100%;
    margin-bottom: 15px;
    padding: 15px;
    font-size: 1.1rem;
    font-weight: 800;
    color: white;
    border: none;
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}

.action-btn:active { transform: scale(0.96); box-shadow: 0 2px 5px rgba(0,0,0,0.1); }
.action-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }

.primary-btn { background: linear-gradient(45deg, #ba68c8, #ab47bc); }
.primary-btn:hover:not(:disabled) { transform: translateY(-3px); }

.secondary-btn { background: linear-gradient(45deg, #4fc3f7, #29b6f6); }
.secondary-btn:hover:not(:disabled) { transform: translateY(-3px); }

.leaderboard-btn { background: linear-gradient(45deg, #ffb74d, #ffa726); }
.leaderboard-btn:hover:not(:disabled) { transform: translateY(-3px); }

.back-btn { background: #e0e0e0; color: #555; }
.back-btn:hover { background: #d5d5d5; transform: translateY(-3px); }

.mt-20 { margin-top: 20px; }

.diff-buttons, .op-buttons {
    display: flex;
    gap: 10px;
    margin-bottom: 25px;
    justify-content: center;
    flex-wrap: wrap;
}

.diff-btn, .op-btn {
    flex: 1;
    padding: 10px;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    background: transparent;
    font-weight: bold;
    color: #555;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 65px;
}

.diff-btn.active, .op-btn.active {
    border-color: var(--primary-color);
    background: var(--primary-color);
    color: white;
    box-shadow: 0 4px 10px rgba(186, 104, 200, 0.3);
    transform: scale(1.05);
}

input[type="text"] {
    width: 100%;
    padding: 12px;
    font-size: 1rem;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    outline: none;
    font-family: inherit;
    text-align: center;
    margin-bottom: 10px;
    transition: border-color 0.3s;
}
input[type="text"]:focus { border-color: var(--primary-color); }

.error-pulse {
    animation: errorShake 0.4s ease-in-out;
    border-color: var(--error-color) !important;
}

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

.game-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.icon-btn { background: none; border: none; font-size: 1.5rem; cursor: pointer; transition: transform 0.2s; padding: 0; }
.icon-btn:hover { transform: scale(1.2); }
.lives { font-size: 1.2rem; letter-spacing: 2px; }

.stats {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 15px;
    background: rgba(255, 255, 255, 0.6);
    padding: 10px 20px;
    border-radius: 16px;
}
.stat-box { display: flex; flex-direction: column; font-weight: 600; }
.stat-box span:first-child { font-size: 0.8rem; color: #78909c; text-transform: uppercase; letter-spacing: 1px; }
.stat-box span:last-child { font-size: 1.6rem; font-weight: 800; }
.score-box span:last-child { color: var(--secondary-color); }
.level-box span:last-child { color: var(--primary-color); }

.progress-bar-container {
    width: 100%;
    height: 8px;
    background: rgba(0,0,0,0.05);
    border-radius: 4px;
    margin-bottom: 20px;
    overflow: hidden;
}
.progress-bar {
    height: 100%;
    background: var(--primary-color);
    width: 0%;
    transition: width 0.3s ease;
}

.question-container {
    font-size: 3.5rem;
    font-weight: 800;
    margin-bottom: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    color: #455a64;
    transition: transform 0.3s ease;
}

input[type="number"] {
    width: 100%;
    font-size: 2.2rem;
    padding: 12px;
    text-align: center;
    border: 3px solid #e0e0e0;
    border-radius: 16px;
    outline: none;
    transition: all 0.3s ease;
    background: white;
    font-family: inherit;
    color: var(--text-primary);
    font-weight: 800;
}

input[type="number"]:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 15px rgba(186, 104, 200, 0.2);
    transform: scale(1.02);
}
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

.feedback {
    margin-top: 15px;
    font-size: 1.2rem;
    font-weight: bold;
    height: 25px;
    transition: opacity 0.3s ease, transform 0.3s ease;
    opacity: 0;
    transform: translateY(10px);
}
.feedback.show { opacity: 1; transform: translateY(0); }
.feedback.success { color: var(--secondary-color); }
.feedback.error { color: var(--error-color); }

.tips-section {
    margin-top: 20px;
    background: rgba(255, 249, 196, 0.7);
    padding: 15px;
    border-radius: 16px;
    text-align: left;
    border-left: 5px solid #fff176;
    transition: opacity 0.3s ease;
}
.tips-section h3 { margin-top: 0; margin-bottom: 5px; color: #fbc02d; font-size: 1rem; }
.tip-content { font-size: 0.9rem; color: #5d4037; line-height: 1.4; }

.final-score span {
    display: block;
    font-size: 4rem;
    font-weight: 800;
    color: var(--primary-color);
    margin: 10px 0;
}
.final-score p { margin: 0; color: #78909c; font-weight: bold; font-size: 1.2rem; }

.leaderboard-container {
    max-height: 350px;
    overflow-y: auto;
    border-radius: 12px;
    background: white;
}
table { width: 100%; border-collapse: collapse; text-align: left; }
th, td { padding: 12px; border-bottom: 1px solid #eee; font-size: 0.9rem; }
th { background: #fafafa; color: #555; font-weight: 800; position: sticky; top: 0; }
tr:nth-child(1) td { font-weight: bold; color: #e65100; font-size: 1.05rem; }
tr:nth-child(2) td { font-weight: bold; color: #455a64; }
tr:nth-child(3) td { font-weight: bold; color: #5d4037; }

.custom-dropdown {
    position: relative;
    width: 100%;
    user-select: none;
}

.custom-dropdown-selected {
    width: 100%;
    padding: 12px 20px;
    border: 2px solid #f0f0f0;
    border-radius: 30px;
    font-size: 1.1rem;
    text-align: center;
    color: var(--text-primary);
    background-color: #f9f9f9;
    cursor: pointer;
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.02), 0 2px 10px rgba(0,0,0,0.05);
    transition: all 0.3s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

.custom-dropdown-selected::after {
    content: "▼";
    position: absolute;
    right: 20px;
    font-size: 0.8rem;
    transition: transform 0.3s ease;
}

.custom-dropdown.open .custom-dropdown-selected {
    border-color: var(--primary-color);
    box-shadow: 0 0 15px rgba(186, 104, 200, 0.2);
    background-color: #fff;
}

.custom-dropdown.open .custom-dropdown-selected::after {
    transform: rotate(180deg);
}

.custom-dropdown-options {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 8px;
    background-color: #fff;
    border: 2px solid #f0f0f0;
    border-radius: 20px;
    max-height: 180px;
    overflow-y: auto;
    z-index: 10;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-15px) scale(0.95);
    transform-origin: top;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
}

.custom-dropdown.open .custom-dropdown-options {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    border-color: var(--primary-color);
}

.custom-dropdown-option {
    padding: 12px 20px;
    cursor: pointer;
    font-size: 1.1rem;
    color: var(--text-primary);
    transition: background-color 0.2s;
}

.custom-dropdown-option:hover {
    background-color: #f3e5f5;
}

.custom-dropdown-option:first-child {
    border-top-left-radius: 18px;
    border-top-right-radius: 18px;
}

.custom-dropdown-option:last-child {
    border-bottom-left-radius: 18px;
    border-bottom-right-radius: 18px;
}

.custom-dropdown-options::-webkit-scrollbar {
    width: 6px;
}
.custom-dropdown-options::-webkit-scrollbar-thumb {
    background-color: #ccc;
    border-radius: 10px;
}

.answer-form-group {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

.answer-form-group input {
    flex: 1;
}

.submit-btn {
    background: linear-gradient(45deg, var(--primary-color), #ab47bc);
    color: white;
    border: none;
    border-radius: 16px;
    padding: 0 20px;
    font-size: 1.2rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}

.submit-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(186, 104, 200, 0.3);
}

.submit-btn:active {
    transform: scale(0.95);
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    50% { transform: translateX(10px); }
    75% { transform: translateX(-10px); }
}
.shake { animation: shake 0.4s ease-in-out; }

@keyframes pop {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); color: var(--secondary-color); }
    100% { transform: scale(1); }
}
.pop { animation: pop 0.4s ease-in-out; }

@media (max-width: 480px) {
    .app-container { width: 95%; padding: 20px; }
    h1 { font-size: 1.8rem; }
    .question-container { font-size: 3rem; }
    input[type="number"] { font-size: 1.8rem; padding: 10px; }
    .action-btn { padding: 12px; font-size: 1.1rem; }
    .submit-btn { padding: 0 15px; font-size: 1rem; }
}
