/* ============ GLOBAL STYLES ============ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

:root {
    --primary-color: #00e6cc;
    --secondary-color: #00a2ff;
    --danger-color: #ff4757;
    --warning-color: #ff9800;
    --success-color: #4CAF50;
    --dark-bg: #1a1a2e;
    --darker-bg: #0f0f1e;
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.8);
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--dark-bg), #16213e);
    overflow: hidden;
}

/* ============ GAME WRAPPER ============ */
.game-wrapper {
    display: flex;
    width: 95%;
    max-width: 1400px;
    height: 90vh;
    max-height: 800px;
    gap: 20px;
}

/* ============ GAME CONTAINER ============ */
.game-container {
    position: relative;
    flex: 1;
    background: var(--glass-bg);
    border-radius: 16px;
    backdrop-filter: blur(10px);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
    overflow: hidden;
    border: 1px solid var(--glass-border);
}
canvas {
    display: block;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, var(--darker-bg), #1a1a3a);
    border-radius: 16px;
    position: relative; /* ADD THIS */
    z-index: 1; /* ADD THIS - Lowest priority */
}

/* ============ INFO PANEL ============ */
.info-panel {
    width: 340px;
    background: var(--glass-bg);
    border-radius: 16px;
    backdrop-filter: blur(10px);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
    padding: 24px;
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
    border: 1px solid var(--glass-border);
    max-height: 100%;
}

.level-info {
    padding-bottom: 16px;
    border-bottom: 1px solid var(--glass-border);
}

.level-title {
    font-size: 1.8rem;
    margin-bottom: 12px;
    color: var(--primary-color);
    text-shadow: 0 0 12px rgba(0, 230, 204, 0.6);
    font-weight: 700;
}

.mission {
    font-size: 1rem;
    line-height: 1.6;
    opacity: 0.9;
}

.target-verb {
    background: linear-gradient(135deg, rgba(0, 230, 204, 0.15), rgba(0, 162, 255, 0.15));
    padding: 24px;
    border-radius: 12px;
    text-align: center;
    border: 2px solid rgba(0, 230, 204, 0.3);
    box-shadow: 0 8px 20px rgba(0, 230, 204, 0.1);
}

.target-label {
    font-size: 0.9rem;
    opacity: 0.8;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.target-text {
    font-size: 2.2rem;
    font-weight: 800;
    color: var(--primary-color);
    text-shadow: 0 0 15px rgba(0, 230, 204, 0.5);
}

.verb-image {
    width: 100%;
    height: 180px;
    background: linear-gradient(135deg, rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.1));
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    border: 1px solid var(--glass-border);
}

.verb-image img {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
}

.verb-fact, .hint-box {
    padding: 3rem;
    border-radius: 10px;
    font-size: 0.9rem;
    line-height: 1.5;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease, padding 0.4s ease;
}

.verb-fact {
    background: linear-gradient(135deg, rgba(0, 162, 255, 0.2), rgba(0, 100, 255, 0.2));
    border: 1px solid rgba(0, 162, 255, 0.3);
}

.hint-box {
    background: linear-gradient(135deg, rgba(255, 152, 0, 0.2), rgba(255, 100, 0, 0.2));
    border: 1px solid rgba(255, 152, 0, 0.4);
}

.verb-fact.show, .hint-box.show {
    max-height: 200px;
    padding: 16px;
}

/* ============ HEARTS & PERKS ============ */
.hearts-container {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.heart {
    font-size: 2rem;
    filter: drop-shadow(0 0 8px rgba(255, 20, 147, 0.6));
    animation: heartbeat 1.5s ease-in-out infinite;
}

@keyframes heartbeat {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.12); }
}

.perks-container {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: auto;
}

.perk {
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.06));
    border-radius: 14px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.6rem;
    position: relative;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 2px solid var(--glass-border);
    user-select: none;
}

.perk:hover {
    transform: translateY(-4px) scale(1.08);
    box-shadow: 0 12px 30px rgba(0, 230, 204, 0.4);
    border-color: var(--primary-color);
}

.perk:active {
    transform: translateY(-2px) scale(1.05);
}

.perk.hint { border-color: rgba(255, 152, 0, 0.6); }
.perk.speed { border-color: rgba(255, 204, 0, 0.6); }
.perk.freeze { border-color: rgba(0, 191, 255, 0.6); }
.perk.color { border-color: rgba(156, 39, 176, 0.6); }

/* ============ UI OVERLAY ============ */
.ui-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10; /* CHANGE from 10 to ensure proper layering */
}
.score-display, .level-display {
    position: absolute;
    top: 24px;
    color: var(--text-primary);
    font-size: 1.3rem;
    font-weight: 700;
    text-shadow: 0 0 12px rgba(0, 255, 200, 0.8);
    background: rgba(0, 0, 0, 0.5);
    padding: 14px 28px;
    border-radius: 30px;
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    pointer-events: all;
}

.score-display { right: 24px; }
.level-display { left: 24px; }

/* ============ SCREENS & MODALS ============ */
.welcome-screen, .start-screen, .level-complete, .game-over {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.85);
    color: var(--text-primary);
    text-align: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
    backdrop-filter: blur(12px);
    padding: 40px;
    overflow-y: auto;
    z-index: 100; /* ADD THIS - Base z-index for game screens */
}

.welcome-screen.show, .start-screen.show, 
.level-complete.show, .game-over.show {
    opacity: 1;
    pointer-events: all;
    z-index: 2000; /* ADD THIS - Higher when active */
}
h1 {
    font-size: 3.5rem;
    margin-bottom: 24px;
    text-shadow: 0 0 25px rgba(0, 255, 200, 1);
    letter-spacing: 3px;
    background: linear-gradient(45deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: 800;
}

.subtitle {
    font-size: 1.2rem;
    margin-bottom: 32px;
    opacity: 0.9;
}

.mission-text, .score-text {
    font-size: 1.3rem;
    margin: 20px 0;
    opacity: 0.95;
}

/* ============ BUTTONS ============ */
.game-btn {
    border: none;
    padding: 16px 40px;
    font-size: 1.2rem;
    border-radius: 50px;
    cursor: pointer;
    margin: 10px;
    pointer-events: all;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    position: relative;
    overflow: hidden;
}

.game-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.game-btn:hover::before {
    width: 300px;
    height: 300px;
}

.game-btn.primary {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: #fff;
    box-shadow: 0 8px 25px rgba(0, 230, 204, 0.4);
}

.game-btn.primary:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 35px rgba(0, 230, 204, 0.6);
}

.game-btn.secondary {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.15), rgba(255, 255, 255, 0.05));
    color: var(--text-primary);
    border: 2px solid var(--glass-border);
}

.game-btn.secondary:hover {
    transform: translateY(-4px);
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.25), rgba(255, 255, 255, 0.15));
    border-color: var(--primary-color);
}

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

.podium-btn {
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.25), rgba(255, 140, 0, 0.25));
    border: 2px solid rgba(255, 215, 0, 0.6);
    color: #ffd700;
    padding: 14px 32px;
    border-radius: 50px;
    cursor: pointer;
    margin-top: 12px;
    transition: all 0.3s ease;
    pointer-events: all;
    font-weight: 600;
    font-size: 1.1rem;
}

.podium-btn:hover {
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.35), rgba(255, 140, 0, 0.35));
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(255, 215, 0, 0.4);
}

/* ============ INPUT FIELDS ============ */
.player-name-input {
    width: 100%;
    max-width: 400px;
    padding: 16px 20px;
    margin-bottom: 20px;
    border-radius: 12px;
    border: 2px solid var(--glass-border);
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    font-size: 1.1rem;
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
}

.player-name-input:focus {
    border-color: var(--primary-color);
    outline: none;
    box-shadow: 0 0 20px rgba(0, 230, 204, 0.3);
}

.player-name-input::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

/* ============ DROPDOWN ============ */
.sets-dropdown {
    position: relative;
    width: 100%;
    max-width: 400px;
    margin-bottom: 24px;
}

.sets-button {
    width: 100%;
    padding: 16px 20px;
    border-radius: 12px;
    border: 2px solid var(--glass-border);
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    font-size: 1.1rem;
    cursor: pointer;
    text-align: left;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.sets-button:hover {
    border-color: var(--primary-color);
    background: rgba(255, 255, 255, 0.15);
}

.dropdown-arrow {
    transition: transform 0.3s ease;
}

.sets-button:hover .dropdown-arrow {
    transform: translateY(2px);
}

.sets-menu {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    width: 100%;
    background: rgba(0, 0, 0, 0.95);
    border-radius: 12px;
    max-height: 250px;
    overflow-y: auto;
    display: none;
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    z-index: 100;
}

.sets-menu.show {
    display: block;
    animation: slideDown 0.3s ease;
}

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

.set-option {
    padding: 14px 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.set-option:last-child {
    border-bottom: none;
}

.set-option:hover {
    background: rgba(0, 230, 204, 0.15);
    padding-left: 28px;
}

/* ============ HOW TO PLAY ============ */
.how-to-play {
    margin-top: 24px;
    text-align: left;
    max-width: 500px;
    background: rgba(255, 255, 255, 0.05);
    padding: 24px;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
}

.how-to-play-title {
    font-size: 1.3rem;
    margin-bottom: 16px;
    color: var(--primary-color);
    font-weight: 600;
}

.how-to-play-content {
    font-size: 0.95rem;
    line-height: 1.8;
    opacity: 0.85;
}

.how-to-play-content p {
    margin-bottom: 8px;
}

/* ============ MODAL POPUPS ============ */
.modal-popup {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.85);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    backdrop-filter: blur(10px);
    z-index: 500; /* ADD THIS - Lower than game screens */
}

.modal-popup.show {
    opacity: 1;
    pointer-events: all;
    z-index: 3000; /* ADD THIS - Highest priority when settings/leaderboard open */
}

.modal-content {
    background: rgba(10, 10, 20, 0.95);
    border-radius: 20px;
    padding: 0;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow: hidden;
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
    animation: modalAppear 0.3s ease;
}

@keyframes modalAppear {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-header {
    padding: 24px 28px;
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, rgba(0, 230, 204, 0.1), rgba(0, 162, 255, 0.1));
}

.modal-header h2 {
    color: var(--primary-color);
    font-size: 1.8rem;
    margin: 0;
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 2.5rem;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.3s ease;
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: rotate(90deg);
}

.modal-body {
    padding: 24px 28px;
    max-height: 50vh;
    overflow-y: auto;
}

.modal-footer {
    padding: 20px 28px;
    border-top: 1px solid var(--glass-border);
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
}

/* ============ SETTINGS ============ */
.settings-option {
    margin-bottom: 28px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.settings-label {
    font-weight: 600;
    font-size: 1.1rem;
}

.slider {
    width: 200px;
    height: 8px;
    border-radius: 8px;
    background: #333;
    outline: none;
    -webkit-appearance: none;
    cursor: pointer;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 230, 204, 0.5);
}

.slider::-moz-range-thumb {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 8px rgba(0, 230, 204, 0.5);
}

.volume-value {
    margin-left: 12px;
    font-weight: 700;
    color: var(--primary-color);
}

.toggle {
    position: relative;
    display: inline-block;
    width: 64px;
    height: 34px;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #555;
    transition: 0.4s;
    border-radius: 34px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 26px;
    width: 26px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: 0.4s;
    border-radius: 50%;
}

input:checked + .toggle-slider {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
}

input:checked + .toggle-slider:before {
    transform: translateX(30px);
}

/* ============ LEADERBOARD ============ */
.score-list {
    list-style: none;
    max-height: 400px;
    overflow-y: auto;
}

.score-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    transition: all 0.2s ease;
}

.score-item:hover {
    background: rgba(0, 230, 204, 0.08);
    padding-left: 28px;
}

.score-rank {
    color: #ffd700;
    font-weight: 800;
    margin-right: 20px;
    font-size: 1.3rem;
    min-width: 40px;
}

/* ============ MOBILE CONTROLS ============ */
.mobile-controls {
    position: absolute;
    bottom: 30px;
    width: 100%;
    display: flex;
    justify-content: center;
    pointer-events: none;
    gap: 12px;
}

.control-btn {
    background: rgba(255, 255, 255, 0.12);
    border: 2px solid rgba(255, 255, 255, 0.25);
    border-radius: 50%;
    width: 70px;
    height: 70px;
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: all;
    transition: all 0.2s ease;
    cursor: pointer;
    user-select: none;
    backdrop-filter: blur(10px);
}

.control-btn:active, .control-btn:hover {
    background: rgba(0, 230, 204, 0.3);
    transform: scale(1.1);
    border-color: var(--primary-color);
}

.control-btn svg {
    width: 32px;
    height: 32px;
    fill: #fff;
    filter: drop-shadow(0 0 6px rgba(0, 0, 0, 0.5));
}

/* ============ SETTINGS BUTTON ============ */
.settings-btn {
    position: absolute;
    top: 24px;
    right: 180px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--glass-border);
    border-radius: 50%;
    width: 52px;
    height: 52px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.3s ease;
    pointer-events: all;
    backdrop-filter: blur(10px);
}

.settings-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1) rotate(90deg);
    border-color: var(--primary-color);
}

.settings-btn svg {
    width: 26px;
    height: 26px;
    fill: #fff;
}

/* ============ LOADING OVERLAY ============ */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    backdrop-filter: blur(10px);
}

.loading-content {
    text-align: center;
    color: var(--text-primary);
}

.loading-content h2 {
    font-size: 2rem;
    margin-bottom: 24px;
    color: var(--primary-color);
}

.loading-bar {
    width: 400px;
    height: 12px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 16px;
}

.loading-progress {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #ffcc00, #4CAF50, var(--secondary-color), var(--danger-color));
    background-size: 200% 100%;
    animation: loadingGradient 2s ease infinite;
    transition: width 0.3s ease;
    border-radius: 12px;
}

@keyframes loadingGradient {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.loading-text {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--primary-color);
}

/* ============ RESPONSIVE DESIGN ============ */
@media (max-width: 1024px) {
    .game-wrapper {
        flex-direction: column;
        height: 100vh;
        width: 100%;
        max-width: none;
    }

    .info-panel {
        width: 100%;
        max-height: 200px;
        flex-direction: row;
        flex-wrap: wrap;
        overflow-x: auto;
        overflow-y: hidden;
        padding: 16px;
    }

    .level-info, .target-verb, .verb-image {
        width: calc(33.333% - 12px);
        min-width: 200px;
    }

    .verb-fact, .hint-box, .hearts-container {
        width: auto;
        flex: 1;
        min-width: 150px;
    }

    .perks-container {
        width: 100%;
        margin-top: 0;
    }

    h1 {
        font-size: 2.5rem;
    }

    .game-btn {
        padding: 14px 28px;
        font-size: 1rem;
    }

    .settings-btn {
        right: 24px;
        top: 80px;
    }
}

@media (max-width: 768px) {
    .info-panel {
        max-height: 180px;
        padding: 12px;
    }

    .level-title {
        font-size: 1.4rem;
    }

    .target-text {
        font-size: 1.6rem;
    }

    .verb-image {
        height: 120px;
    }

    h1 {
        font-size: 2rem;
    }

    .modal-content {
        width: 95%;
        max-width: none;
    }

    .loading-bar {
        width: 280px;
    }
}

/* ============ SCROLLBAR STYLING ============ */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, var(--secondary-color), var(--primary-color));
}

/* ============ PARTICLE EFFECTS ============ */
.particle-effect {
    position: absolute;
    pointer-events: none;
    width: 6px;
    height: 6px;
    background: var(--primary-color);
    border-radius: 50%;
    animation: particleFade 1s ease-out forwards;
}

@keyframes particleFade {
    0% {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
    100% {
        transform: scale(0) translateY(-50px);
        opacity: 0;
    }
}