* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    /* Prevent text selection and default touch actions like pull-to-refresh */
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

body,
html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #222;
    font-family: 'Inter', 'Segoe UI', sans-serif;
    touch-action: none;
    /* Crucial for mobile games */
}

#game-container {
    padding-top: 28px;
    padding-bottom: 38px;
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #111;
}

canvas {
    display: block;
    /* The canvas will be sized by JS to fit the screen while maintaining aspect ratio */
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    background-color: #fcbe32;
    /* Yellow background from reference */
}

#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    /* Let touches pass through to canvas/joystick mostly */
}

.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: white;
    pointer-events: auto;
    /* Re-enable pointer events for buttons */
    transition: opacity 0.3s;
    backdrop-filter: blur(5px);
    overflow-y: auto;
    padding: 100px 20px 80px;
    /* Top padding for header, bottom for footer clearance */
}

.screen.hidden {
    opacity: 0;
    pointer-events: none;
}

h1 {
    font-size: 3rem;
    margin-bottom: 15px;
    background: linear-gradient(45deg, #fcbe32, #e11b22);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 2px;
}

/* Start screen logo/title images */
#start-logo {
    width: 120px;
    object-fit: contain;
    margin-bottom: 10px;
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.5));
}

#start-title {
    width: 70%;
    max-width: 350px;
    object-fit: contain;
    margin-bottom: 20px;
    filter: drop-shadow(0 8px 20px rgba(0, 0, 0, 0.4));
}

p {
    font-size: 1.2rem;
    margin-bottom: 30px;
    color: #ddd;
    text-align: center;
    max-width: 80%;
}

button {
    padding: 15px 40px;
    font-size: 1.5rem;
    border: none;
    border-radius: 30px;
    background: linear-gradient(45deg, #e11b22, #b8151b);
    color: white;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(225, 27, 34, 0.4);
    transition: transform 0.1s, box-shadow 0.1s;
}

button:active {
    transform: scale(0.95);
    box-shadow: 0 2px 10px rgba(225, 27, 34, 0.4);
}

/* Game Header Navbar Styles */
#game-header {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 110px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    border-bottom: 2px solid rgba(252, 190, 50, 0.5);
    z-index: 100;
    transition: opacity 0.3s;
}

/* Navbar left area with title image */
#navbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

#title-img {
    height: 90px;
    object-fit: contain;
    flex-shrink: 0;
}

#navbar-logos {
    display: flex;
    align-items: center;
    gap: 12px;
}

#navbar-logo,
#navbar-logo2,
#navbar-logo3 {
    height: 30px;
    object-fit: contain;
    flex-shrink: 0;
    opacity: 0.9;
    filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.6));
}

#start-logos {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    margin-bottom: 15px;
}

#start-logo {
    width: 50px;
    object-fit: contain;
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.5));
}

#start-logo2 {
    width: 120px;
    margin-top: -15px;
    object-fit: contain;
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.5));
}

#start-logo3 {
    width: 80px;
    object-fit: contain;
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.5));
}

/* Below-maze instruction text */
#maze-instruction {
    position: absolute;
    bottom: 42px;
    /* sits just above the footer ticker */
    left: 0;
    width: 100%;
    text-align: center;
    padding: 6px 16px;
    color: #fcbe32;
    font-size: 0.88rem;
    font-weight: 600;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(6px);
    border-top: 1px solid rgba(252, 190, 50, 0.25);
    z-index: 101;
    letter-spacing: 0.5px;
    pointer-events: none;
}

#maze-instruction.hidden {
    display: none;
}

#game-header.hidden {
    opacity: 0;
    pointer-events: none;
}

#instruction-text {
    color: #fff;
    font-size: 0.85rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 1px;
    max-width: 70%;
}

#timer-display {
    color: #fcbe32;
    font-size: 1.4rem;
    font-weight: bold;
    font-family: 'Courier New', Courier, monospace;
    min-width: 80px;
    text-align: right;
}

/* Quikzee Prize Styles */
#quikzee-prize {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: rgba(225, 27, 34, 0.15);
    border: 2px solid #e11b22;
    border-radius: 20px;
    padding: 15px;
    margin: 10px auto 20px;
    width: fit-content;
    box-shadow: 0 0 25px rgba(225, 27, 34, 0.3);
    animation: prize-pulse 2s infinite ease-in-out;
    backdrop-filter: blur(5px);
}

#quikzee-prize.hidden {
    display: none;
}

#quikzee-prize img {
    height: 60px;
    object-fit: contain;
    margin-bottom: 5px;
}

#quikzee-prize span {
    color: #e11b22;
    font-weight: 900;
    font-size: 1.5rem;
    letter-spacing: 3px;
    text-transform: uppercase;
}

@keyframes prize-pulse {
    0% {
        transform: scale(1);
        box-shadow: 0 0 25px rgba(225, 27, 34, 0.3);
    }

    50% {
        transform: scale(1.05);
        box-shadow: 0 0 45px rgba(225, 27, 34, 0.6);
    }

    100% {
        transform: scale(1);
        box-shadow: 0 0 25px rgba(225, 27, 34, 0.3);
    }
}


/* Result Screen Enhancements */
#screenshot-container {
    width: 250px;
    height: 250px;
    margin: 20px 0;
    border: 3px solid #fcbe32;
    border-radius: 10px;
    overflow: hidden;
    background: #000;
    box-shadow: 0 0 20px rgba(252, 190, 50, 0.3);
}

#screenshot-preview {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.result-actions {
    display: flex;
    gap: 15px;
    margin-bottom: 25px;
}

.action-btn {
    padding: 10px 25px;
    font-size: 1.1rem;
    background: #444;
    border: 1px solid #666;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.action-btn:hover {
    background: #555;
}

/* Win screen logos */
#win-header-logos {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    margin-bottom: 10px;
}

.win-logo {
    height: 40px;
    object-fit: contain;
    filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.5));
}

.win-title {
    height: 60px;
    object-fit: contain;
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.4));
}

#prize-promo,
#quikzee-prize-notice {
    background: rgba(252, 190, 50, 0.2);
    border: 1px solid #fcbe32;
    color: #fcbe32;
    padding: 10px 20px;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 20px;
    text-align: center;
    box-shadow: 0 4px 15px rgba(252, 190, 50, 0.2);
    animation: promo-glow 2s infinite alternate ease-in-out;
}

#quikzee-prize-notice {
    margin: 15px auto;
    max-width: 85%;
}

#quikzee-prize-notice.hidden {
    display: none;
}

@keyframes promo-glow {
    from {
        box-shadow: 0 4px 10px rgba(252, 190, 50, 0.2);
    }

    to {
        box-shadow: 0 4px 20px rgba(252, 190, 50, 0.5);
    }
}

#start-screen p {
    font-size: 1.2rem;
    color: rgba(255, 255, 255, 0.8);
    margin-bottom: 2rem;
    max-width: 80%;
}

/* Footer Ticker - always at the bottom of game-container */
#footer-ticker {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 38px;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
    border-top: 1px solid rgba(252, 190, 50, 0.4);
    overflow: hidden;
    display: flex;
    align-items: center;
    z-index: 1002;
}

.ticker-track {
    display: flex;
    width: max-content;
    animation: marquee-scroll 22s linear infinite;
}

.ticker-text {
    white-space: nowrap;
    padding: 0 20px;
    color: #fcbe32;
    font-size: 1rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
}

@keyframes marquee-scroll {
    0% {
        transform: translateX(0);
    }

    100% {
        transform: translateX(-50%);
    }
}

#restart-btn {
    background: linear-gradient(45deg, #fcbe32, #e11b22);
}

/* Full Screen Dialogue Overlay */
#dialogue-overlay {
    background: rgba(0, 0, 0, 0.95);
    /* Darker backdrop for focus */
    z-index: 1005;
    /* Above everything except header if needed */
    display: flex;
    justify-content: center;
    align-items: center;
}

#dialogue-content {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    /* Allow items to use align-self */
    width: 95%;
    max-width: 1100px;
    height: 85vh;
    position: relative;
    padding: 20px;
}

#dialogue-character {
    height: 65vh;
    max-height: 550px;
    object-fit: contain;
    filter: drop-shadow(0 0 25px rgba(255, 255, 255, 0.2));
    animation: character-slide-in 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    align-self: flex-end;
    /* Pin to bottom */
    margin-right: -30px;
    z-index: 2;
}

#thought-bubbles {
    display: flex;
    flex-direction: column-reverse;
    /* Bubbles stack upwards */
    gap: 15px;
    margin-bottom: 25vh;
    /* Connecting character to upper dialogue */
    margin-left: -10px;
    z-index: 1;
}

.bubble-small,
.bubble-medium {
    background: white;
    border-radius: 50%;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.6);
    animation: bubble-pop 0.4s both;
}

.bubble-small {
    width: 25px;
    height: 25px;
    margin-left: 20px;
    animation-delay: 0.3s;
}

.bubble-medium {
    width: 45px;
    height: 45px;
    margin-left: 60px;
    animation-delay: 0.45s;
}

#dialogue-img {
    flex: 0 0 auto;
    align-self: flex-start;
    /* Pin to top */   
    max-width: 550px;
    width: 55%;
    height: auto;
    object-fit: contain;
    filter: drop-shadow(0 0 50px rgba(0, 0, 0, 0.7));
    animation: dialogue-pop 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
    animation-delay: 0.7s;
    margin-left: auto;
    /* Push to the far right */
}

@keyframes character-slide-in {
    from {
        transform: translateX(-150px) translateY(50px);
        opacity: 0;
    }

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

@keyframes bubble-pop {
    from {
        transform: scale(0);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes dialogue-pop {
    from {
        transform: scale(0.6) translateY(40px);
        opacity: 0;
    }

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

/* Mobile Responsive Dialogue */
@media (max-width: 600px) {
    #dialogue-content {
        flex-direction: column-reverse;
        /* Character bottom, Dialogue top */
        align-items: center;
        justify-content: flex-end;
        padding-bottom: 20px;
        height: 90vh;
    }

    #dialogue-character {
        height: 38% !important;
        align-self: flex-start; /* Character on the left */
        margin: 0;
        margin-top: -10px;
    }

    #thought-bubbles {
        align-self: flex-start; /* Bubbles follow character */
        margin: 0;
        margin-left: 20px;
        margin-bottom: 20px;
        flex-direction: column;
        gap: 8px;
    }

    .bubble-small {
        margin-left: 0;
        width: 15px;
        height: 15px;
    }

    .bubble-medium {
        margin-left: 0;
        width: 30px;
        height: 30px;
    }

    #dialogue-img {
        width: 100%;
        max-width: 100%;
        align-self: center;
        margin-left: 0;
        margin-bottom: 10px;
    }
}