:root {
    /* New Palette based on Kawaii Numbers Image */
    --primary: #88E4C6;
    /* Mint Green (Like '1', '4', '+') */
    --secondary: #FFBC97;
    /* Peach (Like '2') */
    --accent: #9CCBF8;
    /* Baby Blue (Like '3') */
    --purple: #CEA0E4;
    /* Lavender (Like '5') */
    --yellow: #FCE68A;
    /* Soft Yellow (Like '8', '=') */

    --bg-top: #E3F8FF;
    /* Pale Blue Sky */
    --bg-bottom: #FFF1EB;
    /* Pale Pink/Peach Ground */

    --text: #5D5D5D;
    /* Soft Charcoal */
    --white: #ffffff;
    --dark-cap: #3E3E66;
    /* Dark Blue from Caps */

    --btn-shadow: 0px 8px 0px rgba(0, 0, 0, 0.15);
    --btn-active-shadow: 0px 3px 0px rgba(0, 0, 0, 0.15);

    --success: #88E4C6;
    --error: #FF8BA0;
    /* Soft Red/Pink for errors */
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Nunito', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
    color: var(--text);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden;
    /* Prevent scrolling on game */
}

.app-container {
    width: 100%;
    max-width: 500px;
    height: 100vh;
    position: relative;
    background: var(--white);
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.05);
}

@media (min-width: 501px) {
    .app-container {
        height: 90vh;
        border-radius: 30px;
        overflow: hidden;
        border: 8px solid #fff;
    }
}

/* SCREENS */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    transform: scale(0.95);
    background: var(--white);
    z-index: 1;
}

.screen.active {
    opacity: 1;
    pointer-events: auto;
    transform: scale(1);
    z-index: 2;
}

.hidden {
    display: none;
    /* Helper for accessibility, though opacity handles vis */
}

/* SETTINGS BAR */
.settings-bar {
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 10;
}

.lang-flags {
    display: flex;
    gap: 15px;
}

.flag-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    border-radius: 12px;
    opacity: 0.6;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.flag-btn.active {
    opacity: 1;
    transform: scale(1.15);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.08);
    /* Soft kawaii shadow */
}

.kawaii-flag {
    border-radius: 12px;
    overflow: hidden;
    display: block;
}

.flag-btn:hover {
    transform: scale(1.08);
    opacity: 0.9;
}

.btn-sound {
    background: white;
    border: 2px solid #eee;
    border-radius: 50%;
    width: 45px;
    height: 45px;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
}

/* HEADER & LOGO */
.header-logo {
    text-align: center;
    margin-bottom: 40px;
}

.mascot-img {
    width: 100px;
    height: auto;
    margin-bottom: 5px;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0% {
        transform: translateY(0px);
    }

    50% {
        transform: translateY(-10px);
    }

    100% {
        transform: translateY(0px);
    }
}

h1 {
    font-family: 'Fredoka', cursive;
    color: var(--dark-cap);
    font-size: 2.5rem;
    margin-bottom: 5px;
    text-shadow: 2px 2px 0px rgba(255, 255, 255, 0.5);
}

h2 {
    font-family: 'Fredoka', cursive;
    color: var(--text);
    font-size: 2rem;
    margin-bottom: 30px;
}

p {
    font-size: 1.2rem;
    color: #888;
}

/* BUTTONS */
.menu-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    width: 100%;
    max-width: 380px;
    padding: 0 10px;
}

.btn {
    border: none;
    outline: none;
    padding: 15px;
    font-family: 'Fredoka', cursive;
    font-size: 1.2rem;
    border-radius: 25px;
    /* Softer, rounder corners */
    cursor: pointer;
    background: #fff;
    color: var(--text);
    box-shadow: var(--btn-shadow);
    transition: transform 0.1s, box-shadow 0.1s, background 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 100px;
    width: 100%;
    position: relative;
    overflow: hidden;
}

.btn::after {
    /* Shine effect for 3D plastic look */
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 35%;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.4) 0%, rgba(255, 255, 255, 0) 100%);
    pointer-events: none;
}

.btn .icon {
    font-size: 2rem;
}

.btn:active {
    transform: translateY(5px);
    box-shadow: var(--btn-active-shadow);
}

.btn-primary {
    background: var(--primary);
    color: white;
    text-shadow: 0 2px 0 rgba(0, 0, 0, 0.1);
}

.btn-secondary {
    background: var(--secondary);
    color: white;
    text-shadow: 0 2px 0 rgba(0, 0, 0, 0.1);
}

.btn-accent {
    background: var(--accent);
    color: white;
    text-shadow: 0 2px 0 rgba(0, 0, 0, 0.1);
}

.btn-level {
    background: white;
    border: 3px solid var(--primary);
    color: var(--text);
    box-shadow: 0 6px 0 rgba(0, 0, 0, 0.05);
}

.btn-level:hover {
    background: var(--bg-top);
}

#btn-level-5-6 {
    border-color: var(--primary);
}

#btn-level-7-8 {
    border-color: var(--secondary);
}

#btn-level-9-10 {
    border-color: var(--accent);
}

#btn-level-11-12 {
    border-color: var(--purple);
}

#btn-level-5-6 .icon {
    color: var(--primary);
}

#btn-level-7-8 .icon {
    color: var(--secondary);
}

#btn-level-9-10 .icon {
    color: var(--accent);
}

#btn-level-11-12 .icon {
    color: var(--purple);
}

.btn-back {
    position: absolute;
    top: 20px;
    left: 20px;
    background: white;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    border: 2px solid #eee;
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.05);
}

/* Exit button in game screen */
.btn-exit {
    margin-top: 20px;
    background: #fdfdfd;
    color: #888;
    border: 2px solid #eee;
    padding: 8px 15px;
    border-radius: 15px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    font-family: 'Fredoka', cursive;
}

.btn-exit:hover {
    background: #fff;
    color: #ff6b6b;
    border-color: #ff6b6b;
}

/* GAME UI */
.game-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    padding: 0 10px;
    margin-bottom: 40px;
    max-width: 400px;
}

.timer-badge,
.score-badge,
.mistake-badge {
    background: #fff;
    padding: 10px 20px;
    border-radius: 25px;
    font-weight: bold;
    font-size: 1.2rem;
    display: flex;
    gap: 10px;
    align-items: center;
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.05);
    border: 2px solid #f0f0f0;
}

.mistake-badge {
    background: #FFF0F0;
    border-color: #FFD6D6;
    color: var(--error);
}

.question-area {
    margin-bottom: 40px;
    text-align: center;
    height: 150px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.question {
    font-family: 'Fredoka', cursive;
    font-size: 4rem;
    color: var(--text);
}

.feedback {
    height: 30px;
    font-family: 'Fredoka', cursive;
    font-size: 1.5rem;
    margin-top: 10px;
}

.feedback.correct {
    color: #88dba3;
}

.feedback.wrong {
    color: var(--primary);
}

.answers-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    width: 100%;
    max-width: 400px;
}

.answers-grid .btn-option {
    background: white;
    border: 3px solid #eee;
    color: var(--text);
    font-size: 2rem;
    aspect-ratio: 1.5;
    /* wider buttons */
}

.answers-grid .btn-option:hover {
    background: #fafafa;
    border-color: #ddd;
}

.answers-grid .btn-option.correct {
    background: var(--success);
    border-color: var(--success);
    color: white;
    text-shadow: 0 2px 0 rgba(0, 0, 0, 0.1);
}

.answers-grid .btn-option.wrong {
    background: var(--error);
    border-color: var(--error);
    color: white;
    text-shadow: 0 2px 0 rgba(0, 0, 0, 0.1);
}

/* RESULTS */
.result-content {
    text-align: center;
}

.big-number {
    font-family: 'Fredoka', cursive;
    font-size: 6rem;
    color: var(--accent);
    display: block;
    margin: 20px 0;
    text-shadow: 4px 4px 0px rgba(0, 0, 0, 0.05);
}

.result-actions {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 250px;
    margin: 0 auto;
}

/* ANIMATIONS */
@keyframes pop {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }

    100% {
        transform: scale(1);
    }
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    10%,
    30%,
    50%,
    70%,
    90% {
        transform: translateX(-4px);
    }

    20%,
    40%,
    60%,
    80% {
        transform: translateX(4px);
    }
}

.animate-pop {
    animation: pop 0.4s ease;
}

.animate-shake {
    animation: shake 0.4s ease;
}

/* RANKINGS & NICKNAME STYLES */
.btn-rankings {
    background: var(--yellow);
    color: #8B7000;
    height: 100px;
    margin-top: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    line-height: 1.1;
    text-shadow: none;
}

.btn-rankings .btn-text {
    font-size: 1.2rem;
    font-weight: bold;
}

.btn-rankings .btn-sub {
    font-size: 0.8rem;
    opacity: 0.8;
}

.nickname-content,
.rankings-content {
    text-align: center;
    width: 100%;
    max-width: 400px;
}

.nickname-emoji {
    font-size: 4rem;
    margin-bottom: 20px;
    animation: pop 2s infinite;
}

.nickname-form {
    background: #fff;
    padding: 20px;
    border-radius: 20px;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.05);
}

#nickname-input {
    width: 100%;
    padding: 12px;
    border: 2px solid var(--secondary);
    border-radius: 15px;
    margin-bottom: 10px;
    font-size: 1.2rem;
    text-align: center;
}

.nickname-hint {
    font-weight: bold;
    color: var(--primary);
    margin-bottom: 20px;
}

.nickname-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.rankings-header {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    width: 100%;
    margin-bottom: 20px;
}

.rankings-filters {
    background: white;
    padding: 15px;
    border-radius: 20px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    margin-bottom: 20px;
    display: flex;
    gap: 12px;
}

.filter-group {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
    flex: 1;
}

.filter-group label {
    font-weight: bold;
    font-size: 0.9rem;
    color: var(--text);
    margin-left: 5px;
}

.filter-group select {
    width: 100%;
    padding: 12px;
    border-radius: 15px;
    border: 2px solid #eee;
    background: white;
    font-family: 'Fredoka', cursive;
    color: var(--text);
    cursor: pointer;
    outline: none;
    transition: border 0.2s;
}

.filter-group select:focus {
    border-color: var(--accent);
}

.rankings-list {
    flex: 1;
    width: 100%;
    overflow-y: auto;
    padding: 10px 5px;
}

.ranking-item {
    background: white;
    padding: 15px;
    border-radius: 25px;
    /* Softer roundness */
    margin-bottom: 12px;
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.05);
    /* Solid soft shadow like buttons */
    border: 2px solid #f5f5f5;
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 15px;
    transition: transform 0.2s ease;
}

.ranking-item:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 0 rgba(0, 0, 0, 0.05);
    border-color: var(--secondary);
}

/* Top 3 Styling */
.ranking-item:nth-child(1) {
    background: #FFF9C4;
    /* Pastel Yellow for Gold */
    border-color: #FCE68A;
}

.ranking-item:nth-child(2) {
    background: #F5F5F5;
    /* Pastel Grey for Silver */
    border-color: #E0E0E0;
}

.ranking-item:nth-child(3) {
    background: #FFE0B2;
    /* Pastel Orange for Bronze */
    border-color: #FFCC80;
}

.rank-position {
    font-weight: bold;
    font-size: 1.4rem;
    min-width: 40px;
    text-align: center;
}

.rank-position.top-1 {
    color: #FFD700;
    font-size: 1.8rem;
}

.rank-position.top-2 {
    color: #C0C0C0;
    font-size: 1.7rem;
}

.rank-position.top-3 {
    color: #CD7F32;
    font-size: 1.6rem;
}

.rank-flag {
    min-width: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.rank-info {
    flex: 1;
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.rank-nickname {
    font-weight: bold;
    font-size: 1.1rem;
    color: #333;
}

.rank-date {
    font-size: 0.8rem;
    color: #aaa;
}

.rank-score {
    font-weight: bold;
    font-size: 1.4rem;
    color: var(--primary);
    min-width: 50px;
    text-align: right;
}

.loading,
.no-rankings {
    padding: 20px;
    color: #999;
}
