@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;700;900&display=swap');

/* ===== LOADING SCREEN ===== */
#loading-screen {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: linear-gradient(135deg, #ff9a9e 0%, #fad0c4 20%, #ffecd2 40%, #a8edea 60%, #90f9c4 80%, #b8cbb8 100%);
    display: flex;
    align-items: center;
    justify-content: center;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --accent-1: #e94560;
    --accent-2: #0f3460;
    --accent-3: #533483;
    --gold: #ffd700;
    --dot-idle: #ffffff;
    --dot-active: #e94560;
    --dot-done: #4ecca3;
    --line-color: #4ecca3;
    --text-light: #eaeaea;
    --text-dim: #8899aa;
}

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Nunito', sans-serif;
    background: linear-gradient(135deg, #ff9a9e 0%, #fad0c4 20%, #ffecd2 40%, #a8edea 60%, #90f9c4 80%, #b8cbb8 100%);
    color: var(--text-light);
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    touch-action: none;
    overscroll-behavior: none;
}

/* ===== SCREENS ===== */
.screen {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
    z-index: 1;
    overflow: hidden;
}

.screen.active {
    opacity: 1;
    pointer-events: auto;
    z-index: 10;
}

/* Game wrapper */
#game-wrapper {
    position: fixed;
    inset: 0;
    overflow: hidden;
}

/* ===== MENU ===== */
.menu-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    z-index: 2;
}

#menu-screen {
    background: url('assets/menubg.webp') center/cover no-repeat;
}

#menu-screen .menu-dots-bg {
    background: rgba(0, 0, 0, 0.45);
}

.game-title {
    font-size: 64px;
    font-weight: 900;
    text-align: center;
    line-height: 1.1;
    color: #ffffff;
    text-shadow: 0 3px 8px rgba(0, 0, 0, 0.6), 0 1px 3px rgba(0, 0, 0, 0.4);
}

@keyframes gradientShift {

    0%,
    100% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }
}

.game-subtitle {
    font-size: 18px;
    color: var(--text-dim);
    margin-bottom: 20px;
}

.menu-dots-bg {
    position: absolute;
    inset: 0;
    z-index: 0;
    background:
        radial-gradient(2px 2px at 10% 15%, rgba(233, 69, 96, 0.6), transparent),
        radial-gradient(2px 2px at 30% 70%, rgba(78, 204, 163, 0.6), transparent),
        radial-gradient(2px 2px at 50% 30%, rgba(255, 215, 0, 0.5), transparent),
        radial-gradient(2px 2px at 70% 80%, rgba(233, 69, 96, 0.5), transparent),
        radial-gradient(2px 2px at 85% 20%, rgba(78, 204, 163, 0.4), transparent),
        radial-gradient(2px 2px at 20% 90%, rgba(255, 215, 0, 0.4), transparent),
        radial-gradient(2px 2px at 90% 55%, rgba(83, 52, 131, 0.6), transparent),
        radial-gradient(2px 2px at 40% 45%, rgba(233, 69, 96, 0.3), transparent),
        radial-gradient(3px 3px at 60% 10%, rgba(78, 204, 163, 0.7), transparent),
        radial-gradient(3px 3px at 15% 50%, rgba(255, 215, 0, 0.6), transparent);
    animation: dotsFloat 8s ease-in-out infinite alternate;
}

@keyframes dotsFloat {
    0% {
        transform: translateY(0);
    }

    100% {
        transform: translateY(-10px);
    }
}

/* ===== BUTTONS ===== */
.btn {
    padding: 16px 48px;
    font-family: 'Nunito', sans-serif;
    font-size: 20px;
    font-weight: 700;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.btn-play {
    background: linear-gradient(135deg, #e94560, #ff6b6b);
    color: white;
    box-shadow: 0 6px 20px rgba(233, 69, 96, 0.4);
}

.btn-play:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px rgba(233, 69, 96, 0.6);
}

.btn-play:active {
    transform: translateY(1px);
}

.btn-levels {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-light);
    border: 2px solid rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
}

.btn-levels:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
}

.btn-icon {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    backdrop-filter: blur(10px);
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ===== LEVELS SCREEN ===== */
#levels-screen {
    background: url('assets/menubg.webp') center/cover no-repeat;
    justify-content: flex-start;
    padding-top: 16px;
}

#levels-screen::before {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 0;
}

#levels-screen>* {
    position: relative;
    z-index: 1;
}

.levels-header {
    display: flex;
    align-items: center;
    gap: 16px;
    width: 100%;
    padding: 0 20px;
    margin-bottom: 12px;
}

.levels-header h2 {
    font-size: 22px;
    font-weight: 700;
    color: #ffffff;
    text-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}

.levels-grid {
    display: flex;
    flex-direction: column;
    width: 100%;
    flex: 1;
    overflow: hidden;
    padding: 0 20px;
    min-height: 0;
}

.categories-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 12px;
    padding-bottom: 20px;
    align-content: center;
    flex: 1;
}

.category-card {
    position: relative;
    border-radius: 16px;
    overflow: hidden;
    aspect-ratio: 16 / 10;
    background-size: cover;
    background-position: center;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    border: 2px solid #000;
    grid-column: span 2;
}

.category-card:hover {
    transform: scale(1.03);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
    border-color: #000;
}

.category-card:active {
    transform: scale(0.98);
}

/* Center last row: 2 items in 3-col (6-subgrid) layout */
.categories-grid .category-card:nth-child(4) {
    grid-column: 2 / 4;
}

.categories-grid .category-card:nth-child(5) {
    grid-column: 4 / 6;
}

.category-card-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.75) 0%, rgba(0, 0, 0, 0.1) 50%, transparent 100%);
}

.category-card-content {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
}

.category-card-name {
    font-size: 18px;
    font-weight: 900;
    color: #fff;
    text-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
}

.category-card-progress {
    font-size: 13px;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.7);
    background: rgba(0, 0, 0, 0.3);
    padding: 3px 10px;
    border-radius: 10px;
    backdrop-filter: blur(4px);
}

/* Levels grid inner */
.levels-grid-inner {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    overflow-y: auto;
    padding-bottom: 20px;
}

.level-card {
    aspect-ratio: 1;
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    border: 2px solid #000;
    background-size: cover;
    background-position: center;
    overflow: hidden;
}

.level-card-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 0;
}

.locked-overlay {
    background: rgba(0, 0, 0, 0.7);
}

.level-card .level-number,
.level-card .level-stars,
.level-card .lock-icon {
    position: relative;
    z-index: 1;
}

.level-card.unlocked {
    border-color: rgba(78, 204, 163, 0.4);
}

.level-card.unlocked:hover,
.level-card.completed:hover {
    border-color: #4ecca3;
    box-shadow: 0 0 16px rgba(78, 204, 163, 0.7), 0 0 32px rgba(78, 204, 163, 0.3);
}

.level-card.locked {
    cursor: default;
}

.level-card.completed {
    border-color: rgba(78, 204, 163, 0.6);
}

.level-number {
    font-size: 22px;
    font-weight: 900;
    color: #fff;
    text-shadow: 0 2px 6px rgba(0, 0, 0, 0.7);
}

.level-card .lock-icon {
    opacity: 1;
    color: #ffd700;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
}

/* ===== GAME SCREEN ===== */
#game-screen {
    background: var(--bg-secondary);
}

.game-back-btn {
    position: absolute;
    top: 16px;
    left: 16px;
    z-index: 20;
}

#game-board {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 1280px;
    height: 720px;
    transform-origin: center center;
    transform: translate(-50%, -50%);
    background: var(--bg-primary);
    overflow: hidden;
}

#game-canvas {
    position: absolute;
    inset: 0;
    width: 1280px;
    height: 720px;
    display: block;
}

/* ===== COMPLETE OVERLAY ===== */
#complete-overlay {
    position: absolute;
    inset: 0;
    z-index: 15;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.6s ease;
}

#complete-overlay.hidden {
    display: none !important;
}

#complete-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

/* Stars at top */
.co-stars {
    display: flex;
    justify-content: center;
    gap: 12px;
    padding-top: 20px;
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.5));
}

.co-stars .star-icon {
    width: 52px;
    height: 52px;
    opacity: 0;
    transform: scale(0) rotate(-30deg);
}

#complete-overlay.active .co-stars .star-icon:nth-child(1) {
    animation: starBounce 0.5s 0.1s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

#complete-overlay.active .co-stars .star-icon:nth-child(2) {
    animation: starBounce 0.5s 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

#complete-overlay.active .co-stars .star-icon:nth-child(3) {
    animation: starBounce 0.5s 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

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

    60% {
        opacity: 1;
        transform: scale(1.3) rotate(5deg);
    }

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

.co-stars .star-icon.filled {
    fill: #ffd700;
    filter: drop-shadow(0 0 8px rgba(255, 215, 0, 0.6));
}

.co-stars .star-icon.empty {
    fill: none;
    stroke: rgba(255, 255, 255, 0.4);
    stroke-width: 1.5;
}

/* Bottom section */
.co-bottom {
    position: relative;
    padding-bottom: 24px;
}

.co-shadow {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 160px;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.7) 0%, rgba(0, 0, 0, 0.3) 50%, transparent 100%);
    pointer-events: none;
}

.co-buttons {
    position: relative;
    z-index: 2;
    display: flex;
    justify-content: center;
    gap: 16px;
    padding: 0 24px;
}

.co-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 32px;
    border: none;
    border-radius: 16px;
    font-family: 'Outfit', sans-serif;
    font-size: 17px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    backdrop-filter: blur(10px);
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

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

.co-btn-primary {
    background: linear-gradient(135deg, #4ecca3, #38b2ac);
    color: #fff;
    box-shadow: 0 4px 20px rgba(78, 204, 163, 0.4);
}

.co-btn-primary:hover {
    box-shadow: 0 6px 28px rgba(78, 204, 163, 0.6);
    transform: translateY(-2px);
}

.co-btn-secondary {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.co-btn-secondary:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: translateY(-2px);
}

/* Level stars in grid (keep) */
.star-icon {
    width: 16px;
    height: 16px;
}

.star-icon.filled {
    fill: #ffd700;
}

.star-icon.empty {
    fill: none;
    stroke: #ffd700;
    stroke-width: 1.5;
}

.level-stars {
    display: flex;
    gap: 2px;
    margin-top: 3px;
}

/* ===== ANIMATIONS ===== */
@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.15);
    }
}

.pulse {
    animation: pulse 0.8s ease infinite;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 400px) {
    .game-title {
        font-size: 48px;
    }

    .btn {
        padding: 14px 36px;
        font-size: 18px;
    }

    .levels-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}