/* START MENU STYLES */
.menu-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 1;
    visibility: visible;
    transition: opacity 0.5s ease-in-out, visibility 0.5s ease-in-out;
    pointer-events: auto;
}

.menu-screen.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    z-index: -1;
}

.menu-content {
    text-align: center;
    background: rgba(255, 255, 255, 0.95);
    padding: 40px 60px;
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    max-width: 600px;
    max-height: 90vh;
    margin: 20px;
    overflow-y: auto;
    position: relative;
    z-index: 1001;
}

.logo-container {
    margin-bottom: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.game-logo {
    max-width: 300px;
    max-height: 200px;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    animation: logoGlow 4s ease-in-out infinite;
}

.game-logo:hover {
    transform: scale(1.05);
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.3);
}

@keyframes logoGlow {
    0%, 100% { 
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2), 
                    0 0 20px rgba(102, 126, 234, 0.1);
    }
    50% { 
        box-shadow: 0 15px 40px rgba(0, 0, 0, 0.3), 
                    0 0 30px rgba(102, 126, 234, 0.3);
    }
}

.game-title {
    font-size: 2.8em;
    font-weight: bold;
    background: linear-gradient(45deg, #ff6b6b, #4ecdc4, #45b7d1, #96ceb4);
    background-size: 300% 300%;
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
    margin: 15px 0 10px 0;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    animation: gradientShift 3s ease-in-out infinite;
}

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

.studio-credit {
    font-size: 1.1em;
    color: #666;
    margin: 0 0 30px 0;
    font-style: italic;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    align-items: center;
}

.menu-btn {
    padding: 12px 35px;
    font-size: 1.1em;
    font-weight: bold;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 180px;
    text-transform: uppercase;
    letter-spacing: 1px;
    position: relative;
    z-index: 1002;
    pointer-events: auto;
}

.menu-btn.primary {
    background: linear-gradient(45deg, #ff6b6b, #ee5a24);
    color: white;
    box-shadow: 0 5px 15px rgba(255, 107, 107, 0.4);
}

.menu-btn.primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(255, 107, 107, 0.6);
}

.menu-btn:not(.primary) {
    background: linear-gradient(45deg, #4ecdc4, #44a08d);
    color: white;
    box-shadow: 0 5px 15px rgba(78, 205, 196, 0.4);
}

.menu-btn:not(.primary):hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(78, 205, 196, 0.6);
}

.menu-btn.danger {
    background: linear-gradient(45deg, #ff6b6b, #e74c3c);
    color: white;
    box-shadow: 0 5px 15px rgba(255, 107, 107, 0.4);
}

.menu-btn.danger:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(255, 107, 107, 0.6);
    background: linear-gradient(45deg, #e74c3c, #c0392b);
}

.menu-btn:active {
    transform: translateY(0);
}

.instructions-title {
    font-size: 2.5em;
    color: #333;
    margin: 0 0 30px 0;
    font-weight: bold;
}

.instructions-text {
    text-align: left;
    font-size: 1.1em;
    line-height: 1.8;
    color: #444;
    margin-bottom: 40px;
    max-width: 450px;
    margin-left: auto;
    margin-right: auto;
}

.instructions-text p {
    margin: 15px 0;
    padding: 10px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 10px;
    border-left: 4px solid #4ecdc4;
}

.instructions-text strong {
    color: #333;
}

/* Hide game controls initially */
.game-hidden {
    display: none !important;
}

/* @tweakable Add CSS variables for tweaking animations */
:root {
    /* @tweakable Duration of the trippy canvas filter animation. Lower is faster. */
    --trippy-canvas-duration: 5s;
    /* @tweakable Controls the maximum saturation applied during the trippy canvas effect. 100% is normal, higher is more saturated. */
    --trippy-canvas-saturate-max: 250%;
    /* @tweakable Controls the maximum contrast applied during the trippy canvas effect. 100% is normal, higher is more contrast. */
    --trippy-canvas-contrast-max: 180%;
    /* @tweakable Controls the maximum blur applied during the trippy canvas effect (in pixels). */
    --trippy-canvas-blur-max: 4px;
    /* @tweakable Controls the maximum invert applied during the trippy canvas effect (0-1). 0 is normal, 1 is fully inverted. */
    --trippy-canvas-invert-max: 0.1; /* A subtle invert */
    /* @tweakable Controls the maximum brightness applied during the trippy canvas effect. 100% is normal. */
    --trippy-canvas-brightness-max: 130%;

    /* @tweakable Duration of the pulsating glow on UI buttons. Lower is faster. */
    --trippy-button-glow-duration: 1.5s;
    /* @tweakable Duration of the color-cycling animation for the 'Crashed!' text. Lower is faster. */
    --trippy-crashed-text-duration: 2s;
}

body {
    margin: 0;
    overflow: hidden;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #e0e0e0;
}

/* --- TRIPPY ANIMATION KEYFRAMES --- */
/* Combines hue rotation, saturation, contrast, blur, invert, and brightness for a trippy effect */
@keyframes trippy-canvas-filters {
    0% {
        filter: hue-rotate(0deg) saturate(100%) contrast(100%) blur(0px) invert(0) brightness(100%);
    }
    20% {
        filter: hue-rotate(72deg) saturate(var(--trippy-canvas-saturate-max)) contrast(100%) blur(0px) invert(0) brightness(100%);
    }
    40% {
        filter: hue-rotate(144deg) saturate(100%) contrast(var(--trippy-canvas-contrast-max)) blur(0px) invert(0) brightness(var(--trippy-canvas-brightness-max));
    }
    60% {
        filter: hue-rotate(216deg) saturate(100%) contrast(100%) blur(var(--trippy-canvas-blur-max)) invert(var(--trippy-canvas-invert-max)) brightness(100%);
    }
    80% {
        filter: hue-rotate(288deg) saturate(var(--trippy-canvas-saturate-max)) contrast(100%) blur(0px) invert(0) brightness(100%);
    }
    100% {
        filter: hue-rotate(360deg) saturate(100%) contrast(100%) blur(0px) invert(0) brightness(100%);
    }
}

@keyframes trippy-button-glow {
    0% { box-shadow: 0 0 3px 0px rgba(0, 150, 255, 0.5); }
    50% { box-shadow: 0 0 10px 3px rgba(0, 150, 255, 0.9); }
    100% { box-shadow: 0 0 3px 0px rgba(0, 150, 255, 0.5); }
}

@keyframes trippy-crashed-text {
    0%   { color: #ff4d4d; text-shadow: 2px 2px 8px #ff0000; }
    25%  { color: #ffff4d; text-shadow: 2px 2px 8px #ffff00; }
    50%  { color: #4dff4d; text-shadow: 2px 2px 8px #00ff00; }
    75%  { color: #4d4dff; text-shadow: 2px 2px 8px #0000ff; }
    100% { color: #ff4d4d; text-shadow: 2px 2px 8px #ff0000; }
}

.trippy-mode #gameCanvas {
    /* @tweakable Toggles the trippy hue-rotate animation on the canvas */
    animation: trippy-canvas-filters var(--trippy-canvas-duration) linear infinite;
}

/* Game Canvas */
#gameCanvas {
    border: 1px solid #333;
    background-color: #ffffff;
    cursor: crosshair;
    touch-action: manipulation; /* Allow pinch-zoom but prevent double-tap zoom */
}

.trippy-mode #controls {
    /* @tweakable Toggles the pulsating glow animation on the control panel buttons */
    animation: trippy-button-glow var(--trippy-button-glow-duration) ease-in-out infinite;
}

#controls {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 10;
    background: rgba(255, 255, 255, 0.8);
    padding: 10px;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
}

button {
    margin-right: 10px;
    padding: 8px 16px;
    font-size: 16px;
    cursor: pointer;
    border: 1px solid #ccc;
    border-radius: 5px;
    background-color: #f0f0f0;
    transition: background-color 0.2s;
}

button:hover {
    background-color: #d8d8d8;
}

button:active {
    background-color: #ccc;
}

.tool-separator {
    width: 1px;
    height: 30px;
    background-color: #ccc;
    margin: 0 10px;
}

#tool-selection, #draw-mode-selection {
    display: flex;
    border-radius: 5px;
    overflow: hidden;
}

.tool-btn {
    margin-right: 0;
    border-radius: 0;
    border: 1px solid #ccc;
    border-left-width: 0;
}

.tool-btn:first-child {
    border-top-left-radius: 5px;
    border-bottom-left-radius: 5px;
    border-left-width: 1px;
}
.tool-btn:last-child {
    border-top-right-radius: 5px;
    border-bottom-right-radius: 5px;
    margin-right: 10px;
}

.tool-btn.active {
    background-color: #a0c4ff;
    color: white;
    border-color: #7a9ee0;
}
.tool-btn.active:hover {
    background-color: #8ab4f8;
}

#instructions {
    font-size: 14px;
    color: #333;
}

/* New styles for the restart screen */
#restartScreen {
    /* @tweakable Background color of the restart screen overlay */
    background-color: rgba(0, 0, 0, 0.7);
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease-in-out, visibility 0.3s ease-in-out;
}

#restartScreen.visible {
    opacity: 1;
    visibility: visible;
}

.trippy-mode #restartScreen h1 {
    /* @tweakable Toggles the trippy color-cycling animation on the 'Crashed!' text */
    animation: trippy-crashed-text var(--trippy-crashed-text-duration) linear infinite;
}

#restartScreen h1 {
    /* @tweakable Text color for the "Crashed!" title */
    color: #ff4d4d;
    font-size: 4em;
    margin-bottom: 20px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
}

#restartScreen p {
    /* @tweakable Text color for the crash reason */
    color: #ffffff;
    font-size: 1.5em;
    margin-bottom: 30px;
}

#restartScreen button {
    /* @tweakable Background color for the restart button */
    background-color: #4CAF50;
    /* @tweakable Text color for the restart button */
    color: white;
    padding: 15px 30px;
    font-size: 1.8em;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
    transition: background-color 0.2s, transform 0.2s;
}

#restartScreen button:hover {
    background-color: #45a049;
    transform: translateY(-2px);
}

#restartScreen button:active {
    background-color: #3e8e41;
    transform: translateY(0);
}

.hidden {
    display: none !important; /* Use important to ensure it overrides flex/block */
}

/* CHALLENGES STYLES */
.challenges-content {
    max-width: 700px;
    max-height: 80vh;
    overflow-y: auto;
}

.challenges-title {
    font-size: 2.5em;
    color: #333;
    margin: 0 0 30px 0;
    font-weight: bold;
}

.challenges-list {
    display: grid;
    gap: 15px;
    margin-bottom: 30px;
}

.challenge-item {
    background: rgba(255, 255, 255, 0.7);
    border-radius: 12px;
    padding: 20px;
    border-left: 5px solid #4ecdc4;
    transition: all 0.3s ease;
    position: relative;
}

.challenge-item.completed {
    border-left-color: #2ecc71;
    background: rgba(46, 204, 113, 0.1);
}

.challenge-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
}

.challenge-title {
    font-size: 1.3em;
    font-weight: bold;
    color: #333;
    margin: 0 0 8px 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.challenge-description {
    color: #666;
    font-size: 1em;
    margin: 0 0 10px 0;
    line-height: 1.4;
}

.challenge-progress {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9em;
    color: #555;
}

.challenge-status {
    font-weight: bold;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8em;
    text-transform: uppercase;
}

.challenge-status.completed {
    background: #2ecc71;
    color: white;
}

.challenge-status.in-progress {
    background: #f39c12;
    color: white;
}

.challenge-status.not-started {
    background: #95a5a6;
    color: white;
}

/* BACK TO MENU BUTTON */
.back-to-menu-btn {
    background: linear-gradient(45deg, #e74c3c, #c0392b) !important;
    color: white !important;
    border: none !important;
    font-weight: bold !important;
    font-size: 0.9em !important;
    padding: 8px 16px !important;
    border-radius: 25px !important;
    margin-right: 15px !important;
    transition: all 0.3s ease !important;
    cursor: pointer !important;
}

.back-to-menu-btn:hover {
    background: linear-gradient(45deg, #c0392b, #a93226) !important;
    transform: translateY(-1px) !important;
    box-shadow: 0 4px 12px rgba(231, 76, 60, 0.4) !important;
}

/* CHALLENGE NOTIFICATIONS */
.challenge-notifications {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 500;
    pointer-events: none;
}

.challenge-notification {
    background: linear-gradient(135deg, #2ecc71, #27ae60);
    color: white;
    padding: 15px 20px;
    border-radius: 12px;
    margin-bottom: 10px;
    box-shadow: 0 4px 15px rgba(46, 204, 113, 0.3);
    transform: translateX(100%);
    opacity: 0;
    transition: all 0.5s ease;
    pointer-events: auto;
    min-width: 300px;
    border-left: 5px solid #fff;
}

.challenge-notification.show {
    transform: translateX(0);
    opacity: 1;
}

.challenge-notification.hide {
    transform: translateX(100%);
    opacity: 0;
}

.challenge-notification-title {
    font-size: 1.1em;
    font-weight: bold;
    margin: 0 0 5px 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.challenge-notification-description {
    font-size: 0.9em;
    margin: 0;
    opacity: 0.9;
}

/* MOBILE RESPONSIVE DESIGN */
@media screen and (max-width: 768px) {
    .menu-content {
        padding: 25px 35px;
        margin: 10px;
        max-height: 95vh;
        max-width: 90vw;
    }
    
    .game-title {
        font-size: 2.2em;
    }
    
    .game-logo {
        max-width: 250px;
        max-height: 150px;
    }
    
    .menu-btn {
        padding: 10px 25px;
        font-size: 1em;
        min-width: 160px;
    }
    
    .instructions-text {
        font-size: 1em;
        max-width: 100%;
    }
    
    .challenges-content {
        max-width: 95vw;
        padding: 20px;
    }
    
    .challenge-item {
        padding: 15px;
    }

    .save-progress-title {
        font-size: 1.8em;
    }

    .save-section {
        padding: 15px;
        margin-bottom: 15px;
    }

    .save-section h3 {
        font-size: 1.1em;
    }

    .save-section p {
        font-size: 0.9em;
    }

    .save-info {
        padding: 15px;
    }

    #progressSummary {
        font-size: 0.8em;
        padding: 10px;
    }
}

/* MOBILE CONTROLS */
@media screen and (max-width: 768px) {
    #controls {
        position: fixed;
        top: 10px;
        left: 10px;
        right: 10px;
        z-index: 100;
        background: rgba(255, 255, 255, 0.95);
        padding: 8px;
        border-radius: 8px;
        box-shadow: 0 2px 10px rgba(0,0,0,0.3);
        display: flex;
        flex-wrap: wrap;
        gap: 5px;
        font-size: 0.8em;
    }
    
    #controls button {
        font-size: 0.8em;
        padding: 6px 10px;
        margin-right: 5px;
    }
    
    .back-to-menu-btn {
        font-size: 0.7em !important;
        padding: 6px 12px !important;
    }
    
    .tool-btn {
        font-size: 0.7em;
        padding: 4px 8px;
    }
    
    #instructions {
        font-size: 0.7em;
        flex-basis: 100%;
        text-align: center;
        margin-top: 5px;
    }
    
    /* Stack tool groups vertically on very small screens */
    #tool-selection, #draw-mode-selection {
        flex-wrap: wrap;
    }
}

/* VIRTUAL D-PAD */
.virtual-dpad {
    position: fixed;
    bottom: 20px;
    left: 20px;
    width: 120px;
    height: 120px;
    z-index: 200;
    display: none; /* Hidden by default, shown on mobile */
}

/* Force show on mobile devices */
.virtual-dpad.mobile-visible {
    display: block !important;
}

@media screen and (max-width: 768px) {
    .virtual-dpad {
        display: block;
    }
}

.dpad-container {
    position: relative;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.5);
}

.dpad-button {
    position: absolute;
    background: rgba(255, 255, 255, 0.8);
    border: 2px solid #333;
    border-radius: 8px;
    color: #333;
    font-weight: bold;
    font-size: 16px;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.1s ease;
    z-index: 201;
}

.dpad-button:active {
    background: rgba(0, 255, 255, 0.8);
    transform: scale(0.95);
}

.dpad-up {
    top: 5px;
    left: 50%;
    transform: translateX(-50%);
    width: 30px;
    height: 25px;
}

.dpad-down {
    bottom: 5px;
    left: 50%;
    transform: translateX(-50%);
    width: 30px;
    height: 25px;
}

.dpad-left {
    left: 5px;
    top: 50%;
    transform: translateY(-50%);
    width: 25px;
    height: 30px;
}

.dpad-right {
    right: 5px;
    top: 50%;
    transform: translateY(-50%);
    width: 25px;
    height: 30px;
}

.dpad-center {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 25px;
    height: 25px;
    border-radius: 50%;
    background: rgba(255, 0, 255, 0.8);
    font-size: 12px;
}

/* MOBILE TOUCH INSTRUCTIONS */
.mobile-instructions {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 10px;
    border-radius: 8px;
    font-size: 0.8em;
    max-width: 150px;
    text-align: center;
    z-index: 150;
    display: none;
}

/* Force show on mobile devices */
.mobile-instructions.mobile-visible {
    display: block !important;
}

@media screen and (max-width: 768px) {
    .mobile-instructions {
        display: block;
    }
}

/* MOBILE CHALLENGE NOTIFICATIONS */
@media screen and (max-width: 768px) {
    .challenge-notifications {
        top: 100px; /* Move below mobile controls */
        right: 10px;
        left: 10px;
    }
    
    .challenge-notification {
        min-width: auto;
        margin-bottom: 5px;
        padding: 10px 15px;
        font-size: 0.9em;
    }
    
    .challenge-notification-title {
        font-size: 1em;
    }
    
    .challenge-notification-description {
        font-size: 0.8em;
    }
}

/* MOBILE GAME CANVAS */
@media screen and (max-width: 768px) {
    #gameCanvas {
        touch-action: none !important; /* Completely disable default touch on mobile */
    }
}

/* Save Progress Screen Styles */
.save-progress-title {
    font-size: 2.2em;
    color: #333;
    margin: 0 0 25px 0;
    font-weight: bold;
}

.save-progress-content {
    text-align: left;
    max-width: 500px;
    margin: 0 auto;
}

.save-section {
    background: rgba(255, 255, 255, 0.7);
    border-radius: 15px;
    padding: 18px;
    margin-bottom: 18px;
    border-left: 4px solid #4ecdc4;
    transition: all 0.3s ease;
}

.save-section:hover {
    background: rgba(255, 255, 255, 0.9);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.save-section h3 {
    margin: 0 0 8px 0;
    color: #333;
    font-size: 1.2em;
}

.save-section p {
    margin: 0 0 12px 0;
    color: #666;
    line-height: 1.5;
    font-size: 0.95em;
}

.save-info {
    background: rgba(78, 205, 196, 0.1);
    border-radius: 15px;
    padding: 18px;
    margin-top: 18px;
    border-left: 4px solid #4ecdc4;
}

.save-info h4 {
    margin: 0 0 12px 0;
    color: #333;
    font-size: 1.1em;
}

#progressSummary {
    font-family: monospace;
    background: rgba(255, 255, 255, 0.8);
    padding: 12px;
    border-radius: 10px;
    border: 1px solid #ddd;
    line-height: 1.6;
    color: #444;
    font-size: 0.9em;
}

.progress-stat {
    display: flex;
    justify-content: space-between;
    margin: 4px 0;
    padding: 4px 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.progress-stat:last-child {
    border-bottom: none;
}

.progress-stat-label {
    font-weight: bold;
}

.progress-stat-value {
    color: #4ecdc4;
    font-weight: bold;
}

@media screen and (max-width: 480px) {
    .menu-content {
        padding: 20px 25px;
        margin: 5px;
    }

    .game-title {
        font-size: 1.8em;
    }

    .menu-btn {
        padding: 8px 20px;
        font-size: 0.9em;
        min-width: 140px;
    }

    .save-progress-title {
        font-size: 1.5em;
    }

    .save-section {
        padding: 12px;
    }

    .save-section h3 {
        font-size: 1em;
    }
}