/**
 * Counting Caterpillar Game Styles
 */

/* ============================================
   Game Container
   ============================================ */

.game-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
    min-height: 100vh;
    position: relative;
    z-index: 1;
}

/* ============================================
   Back Link
   ============================================ */

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--primary);
    text-decoration: none;
    font-weight: 700;
    font-size: 1.1rem;
    margin-bottom: 1rem;
    transition: all 0.3s ease;
}

.back-link:hover {
    color: var(--primary-dark);
    transform: translateX(-5px);
}

.back-link span {
    font-size: 1.5rem;
}

/* ============================================
   Screen Visibility
   ============================================ */

.screen {
    display: none;
    max-width: 800px;
    margin: 0 auto;
    animation: fadeIn 0.5s ease;
}

.screen.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================
   Level Selection Screen
   ============================================ */

.game-title {
    font-family: var(--font-heading);
    font-size: clamp(2rem, 6vw, 3.5rem);
    text-align: center;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.5rem;
}

.game-subtitle {
    text-align: center;
    font-size: 1.25rem;
    color: var(--primary-dark);
    margin-bottom: 2rem;
    font-weight: 700;
}

.levels-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 1.5rem;
    padding: 1rem;
    max-width: 600px;
    margin: 0 auto;
}

.level-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
    width: 100%;
    aspect-ratio: 1;
    background: var(--white);
    border: 4px solid var(--primary-light);
    border-radius: var(--radius-xl);
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: var(--shadow-md);
    position: relative;
    overflow: hidden;
}

.level-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--gradient-primary);
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 0;
}

.level-card:hover::before {
    opacity: 0.1;
}

.level-card:hover {
    transform: translateY(-8px) scale(1.05);
    border-color: var(--primary);
    box-shadow: var(--shadow-lg), var(--shadow-glow);
}

.level-card:active {
    transform: translateY(-2px) scale(0.98);
}

.level-icon {
    font-size: 3rem;
    margin-bottom: 0.5rem;
    z-index: 1;
    animation: wiggle 3s ease-in-out infinite;
}

@keyframes wiggle {

    0%,
    100% {
        transform: rotate(0deg);
    }

    25% {
        transform: rotate(-5deg);
    }

    75% {
        transform: rotate(5deg);
    }
}

.level-name {
    font-family: var(--font-heading);
    font-size: 1.75rem;
    color: var(--primary-dark);
    z-index: 1;
}

.level-range {
    font-size: 0.95rem;
    color: var(--gray-200);
    font-weight: 600;
    z-index: 1;
}

/* ============================================
   Question Screen Header
   ============================================ */

.question-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    font-size: 1.25rem;
    font-weight: 700;
}

.current-level {
    background: var(--gradient-primary);
    color: var(--white);
    padding: 0.5rem 1.25rem;
    border-radius: var(--radius-full);
    font-size: 1.1rem;
}

.question-counter {
    color: var(--primary);
}

/* Progress */
.progress-container {
    margin-bottom: 2rem;
}

/* Question Area */
.question-area {
    text-align: center;
    padding: 2rem;
    background: var(--white);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    margin-bottom: 2rem;
}

/* ============================================
   Results Screen
   ============================================ */

.results-header {
    text-align: center;
    margin-bottom: 2rem;
}

.results-title {
    font-family: var(--font-heading);
    font-size: clamp(2rem, 6vw, 3rem);
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 1rem;
}

.score-display {
    display: flex;
    justify-content: center;
    align-items: baseline;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.score-number {
    font-family: var(--font-heading);
    font-size: 5rem;
    color: var(--success);
}

.score-divider {
    font-family: var(--font-heading);
    font-size: 3rem;
    color: var(--gray-200);
}

.score-total {
    font-family: var(--font-heading);
    font-size: 3rem;
    color: var(--gray-800);
}

.score-message {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
}

/* Results List */
.results-list {
    max-height: 300px;
    overflow-y: auto;
    margin-bottom: 2rem;
    padding: 1rem;
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

/* Results Actions */
.results-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 1rem;
}

/* ============================================
   Caterpillar Display
   ============================================ */

.caterpillar-container {
    display: flex;
    justify-content: center;
    margin-bottom: 1rem;
    min-height: 80px;
}

.caterpillar {
    display: flex;
    align-items: center;
    gap: 0;
    transition: transform 0.3s ease;
}

.caterpillar.happy {
    animation: wiggle 0.5s ease-in-out;
}

.caterpillar.sad {
    animation: shake 0.4s ease-in-out;
}

@keyframes wiggle {

    0%,
    100% {
        transform: rotate(0deg);
    }

    25% {
        transform: rotate(-5deg) scale(1.1);
    }

    50% {
        transform: rotate(5deg) scale(1.15);
    }

    75% {
        transform: rotate(-3deg) scale(1.1);
    }
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px);
    }

    50% {
        transform: translateX(5px);
    }

    75% {
        transform: translateX(-5px);
    }
}

.caterpillar-head {
    font-size: 3rem;
    z-index: 10;
    filter: drop-shadow(2px 2px 4px rgba(0, 0, 0, 0.2));
}

.caterpillar-body {
    display: flex;
    align-items: center;
    gap: 0;
}

.caterpillar-segment {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    margin-left: -8px;
    animation: popIn 0.3s ease-out forwards;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15);
}

@keyframes popIn {
    0% {
        transform: scale(0);
        opacity: 0;
    }

    60% {
        transform: scale(1.2);
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ============================================
   Objects Display Area
   ============================================ */

.prompt-text {
    font-family: 'Fredoka One', cursive;
    font-size: 1.5rem;
    color: #6b21a8;
    text-align: center;
    margin-bottom: 1rem;
}

.objects-area {
    position: relative;
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border-radius: 20px;
    min-height: 200px;
    margin-bottom: 1.5rem;
    padding: 1rem;
    box-shadow: inset 0 4px 15px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.object-item {
    position: absolute;
    font-size: 2.5rem;
    animation: bounceIn 0.4s ease-out forwards;
    filter: drop-shadow(2px 2px 3px rgba(0, 0, 0, 0.2));
    cursor: default;
    user-select: none;
}

@keyframes bounceIn {
    0% {
        transform: scale(0) rotate(-10deg);
        opacity: 0;
    }

    50% {
        transform: scale(1.2) rotate(5deg);
    }

    100% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
}

.object-item:hover {
    transform: scale(1.15);
    transition: transform 0.15s ease;
}

/* ============================================
   Number Grid
   ============================================ */

.number-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.75rem;
    max-width: 400px;
    margin: 0 auto 1rem;
}

.number-btn {
    background: linear-gradient(135deg, #a855f7 0%, #9333ea 100%);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 1rem;
    font-family: 'Fredoka One', cursive;
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 10px rgba(147, 51, 234, 0.3);
}

.number-btn:hover:not(:disabled) {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 6px 15px rgba(147, 51, 234, 0.4);
}

.number-btn:active:not(:disabled) {
    transform: translateY(-1px) scale(1.02);
}

.number-btn:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

.number-btn.selected {
    transform: scale(1.1);
}

.number-btn.correct {
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
    box-shadow: 0 4px 15px rgba(34, 197, 94, 0.4);
    opacity: 1;
}

.number-btn.wrong {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.4);
}

/* ============================================
   Feedback
   ============================================ */

.feedback {
    text-align: center;
    font-family: 'Fredoka One', cursive;
    font-size: 1.25rem;
    min-height: 2rem;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.feedback.show {
    opacity: 1;
}

.feedback.correct {
    color: #16a34a;
}

.feedback.wrong {
    color: #dc2626;
}

/* ============================================
   Results Screen
   ============================================ */

.caterpillar-final {
    margin: 1.5rem 0;
    display: flex;
    justify-content: center;
}

.caterpillar-final .caterpillar {
    animation: wiggle 1s ease-in-out infinite;
}

.caterpillar-final .caterpillar-head {
    font-size: 4rem;
}

.caterpillar-final .caterpillar-segment {
    width: 36px;
    height: 36px;
    margin-left: -10px;
}

.result-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: white;
    border-radius: 12px;
    margin-bottom: 0.5rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.result-item.correct {
    border-left: 4px solid #22c55e;
}

.result-item.wrong {
    border-left: 4px solid #ef4444;
}

.result-number {
    font-weight: 700;
    color: #6b7280;
    min-width: 30px;
}

.result-objects {
    font-size: 1.25rem;
    min-width: 100px;
}

.result-count {
    color: #6b21a8;
    font-weight: 600;
    flex: 1;
}

.result-answer {
    color: #6b7280;
}

.result-icon {
    font-size: 1.25rem;
    font-weight: 700;
}

.result-item.correct .result-icon {
    color: #22c55e;
}

.result-item.wrong .result-icon {
    color: #ef4444;
}

/* ============================================
   Responsive
   ============================================ */

@media (max-width: 600px) {
    .levels-grid {
        flex-direction: column;
        align-items: center;
    }

    .level-card {
        width: 100%;
        max-width: 280px;
    }

    .number-grid {
        grid-template-columns: repeat(5, 1fr);
        gap: 0.5rem;
    }

    .number-btn {
        padding: 0.75rem 0.5rem;
        font-size: 1.25rem;
    }

    .object-item {
        font-size: 2rem;
    }

    .result-objects {
        min-width: 60px;
        font-size: 1rem;
    }
}