html {
    position: fixed;
    width: 100%;
    height: 100%;
    overflow: hidden;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: fixed;
    font-family: 'Poppins', sans-serif;
    background: linear-gradient(135deg, var(--dark) 0%, var(--dark-light) 100%);
    color: var(--light);
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
}

:root {
    --primary: #8b5cf6;
    --primary-light: #a78bfa;
    --secondary: #06b6d4;
    --accent: #ec4899;
    --dark: #0f172a;
    --dark-light: #1e293b;
    --light: #f8fafc;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.15);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.3);
    --border-radius-sm: 8px;
    --border-radius-md: 12px;
    --border-radius-lg: 20px;
    --border-radius-full: 9999px;
    --transition-fast: 0.2s ease;
    --transition-normal: 0.3s ease;
    --transition-slow: 0.5s ease;
    --trail-size: 5px;
}

#game-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    background: linear-gradient(135deg, #121212 0%, #1e1e2e 100%);
}

#start-menu {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    background: linear-gradient(135deg, rgba(18, 18, 18, 0.9) 0%, rgba(30, 30, 46, 0.9) 100%);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.menu-content {
    background: rgba(30, 41, 59, 0.8);
    padding: clamp(1rem, 3vh, 2.5rem);
    border-radius: var(--border-radius-lg);
    border: 1px solid rgba(139, 92, 246, 0.3);
    box-shadow: var(--shadow-lg), 0 0 35px rgba(139, 92, 246, 0.2);
    width: min(90%, 500px);
    max-height: 90vh;
    display: grid;
    grid-template-rows: auto 1fr;
    gap: clamp(1rem, 2vh, 2rem);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    animation: fadeIn 0.5s ease-out;
}

.title-container {
    text-align: center;
}

.title-container h1 {
    font-size: clamp(2rem, 5vw, 3.5rem);
    font-weight: 800;
    margin: 0;
    background: linear-gradient(135deg, var(--primary-light), var(--secondary));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    text-transform: uppercase;
    letter-spacing: 2px;
    line-height: 1.1;
    position: relative;
    display: inline-block;
    text-shadow: 0 0 30px rgba(139, 92, 246, 0.3);
}

h1 .highlight {
    color: var(--accent);
    text-shadow: 0 0 15px rgba(253, 121, 168, 0.6);
}

.subtitle {
    font-size: clamp(0.9rem, 2vw, 1.2rem);
    margin-top: 0.5rem;
}

.controls {
    display: grid;
    gap: clamp(0.8rem, 2vh, 1.5rem);
    align-content: start;
}

.difficulty-controls {
    display: flex;
    justify-content: center;
    gap: min(0.75rem, 1.5vw);
    flex-wrap: wrap;
}

.difficulty-btn {
    background: rgba(139, 92, 246, 0.1);
    border: 1px solid rgba(139, 92, 246, 0.3);
    color: var(--light);
    padding: min(0.75rem, 1.5vh) min(1.5rem, 3vw);
    font-size: clamp(0.8rem, 2vw, 0.95rem);
    border-radius: var(--border-radius-full);
    cursor: pointer;
    transition: all var(--transition-normal);
    font-weight: 500;
    letter-spacing: 1px;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.difficulty-btn i {
    font-size: 1.1em;
}

.difficulty-btn:hover {
    background: rgba(139, 92, 246, 0.2);
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm), 0 0 15px rgba(139, 92, 246, 0.3);
}

.difficulty-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary-light);
    box-shadow: 0 0 20px rgba(139, 92, 246, 0.4);
}

.size-control {
    background: rgba(30, 30, 46, 0.5);
    padding: min(1rem, 2vh);
    border-radius: var(--border-radius-md);
    display: flex;
    flex-direction: column;
    gap: min(0.75rem, 1.5vh);
    border: 1px solid rgba(108, 92, 231, 0.2);
}

.size-control label {
    font-size: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#mazeSizeValue {
    background: var(--primary);
    color: white;
    padding: 0.2rem 0.6rem;
    border-radius: var(--border-radius-sm);
    font-weight: 600;
    min-width: 2rem;
    text-align: center;
}

#mazeSize {
    width: 100%;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: rgba(255, 255, 255, 0.2);
    outline: none;
    border-radius: var(--border-radius-full);
    overflow: hidden;
}

#mazeSize::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary-light);
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
    transition: all var(--transition-fast);
}

#mazeSize::-webkit-slider-thumb:hover {
    background: var(--primary);
    transform: scale(1.1);
}

#mazeSize::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary-light);
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
    transition: all var(--transition-fast);
}

#mazeSize::-moz-range-thumb:hover {
    background: var(--primary);
    transform: scale(1.1);
}

.mode-selection {
    background: rgba(30, 41, 59, 0.5);
    padding: min(1rem, 2vh);
    border-radius: var(--border-radius-md);
    border: 1px solid rgba(139, 92, 246, 0.2);
}

.mode-selection h3 {
    font-size: 1.1rem;
    margin: 0 0 1rem 0;
    color: var(--secondary);
    text-align: center;
    letter-spacing: 1px;
    text-transform: uppercase;
    font-weight: 600;
}

.mode-options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: min(0.75rem, 1.5vh);
    margin-top: min(0.75rem, 1.5vh);
}

.mode-option {
    position: relative;
    display: flex;
    align-items: center;
}

.mode-option input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.mode-option label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
    border-radius: var(--border-radius-full);
    background: rgba(139, 92, 246, 0.1);
    border: 1px solid rgba(139, 92, 246, 0.2);
    cursor: pointer;
    transition: all var(--transition-normal);
    font-weight: 500;
    font-size: clamp(0.8rem, 2vw, 0.9rem);
}

.mode-option label:hover {
    background: rgba(139, 92, 246, 0.15);
    transform: translateX(5px);
}

.mode-option input[type="checkbox"]:checked + label {
    background: var(--primary);
    color: white;
    border-color: var(--primary-light);
    box-shadow: 0 0 15px rgba(139, 92, 246, 0.3);
}

.toggle-container {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
}

#startBtn {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    border: none;
    padding: 1rem 2rem;
    font-size: 1.1rem;
    border-radius: var(--border-radius-full);
    cursor: pointer;
    transition: all var(--transition-normal);
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-top: 1rem;
    box-shadow: var(--shadow-md), 0 0 20px rgba(139, 92, 246, 0.3);
    animation: pulseStartBtn 2s infinite;
}

#startBtn:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg), 0 0 30px rgba(139, 92, 246, 0.4);
    filter: brightness(1.1);
}

#game-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--dark) 0%, var(--dark-light) 100%);
}

#game-stats {
    position: fixed;
    top: 20px;
    left: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 1000;
    background: rgba(30, 41, 59, 0.9);
    padding: 16px 20px;
    border-radius: var(--border-radius-md);
    border: 1px solid rgba(139, 92, 246, 0.3);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--light);
    font-size: 15px;
    font-weight: 500;
    min-width: 120px;
}

.stat-item i {
    color: var(--primary-light);
    font-size: 18px;
    width: 20px;
    text-align: center;
}

#mazeContainer {
    position: relative;
    width: 90vmin;
    height: 90vmin;
    max-width: 600px;
    max-height: 600px;
    margin: auto;
    display: flex;
    justify-content: center;
    align-items: center;
}

#mazeCanvas {
    width: 100%;
    height: 100%;
    display: block;
}

#particles {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 50;
}

.particle {
    position: absolute;
    width: 4px;
    height: 4px;
    background: var(--primary);
    border-radius: 50%;
    pointer-events: none;
    animation: particleFloat 2s ease-out forwards;
}

@keyframes particleFloat {
    0% {
        opacity: 1;
        transform: translate(0, 0) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(var(--random-x, 0), var(--random-y, -50px)) scale(0);
    }
}

#player {
    position: absolute;
    width: 16px;
    height: 16px;
    background: var(--primary);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: all 0.15s linear;
    z-index: 100;
    box-shadow: 0 0 15px var(--primary-light);
    pointer-events: none;
}

.glow-enabled #player {
    animation: playerPulse 2s ease-in-out infinite;
}

body.memory-mode #player {
    box-shadow: 
        0 0 20px var(--primary-light),
        0 0 40px var(--primary),
        0 0 60px rgba(139, 92, 246, 0.5);
    background: radial-gradient(circle, var(--primary-light), var(--primary));
    z-index: 200;
}

body.memory-mode #mazeCanvas::after {
    content: '';
    position: absolute;
    left: var(--end-x);
    top: var(--end-y);
    width: 25px;
    height: 25px;
    background: radial-gradient(circle, rgba(100, 255, 100, 1), rgba(0, 255, 0, 0.5));
    border-radius: 50%;
    z-index: 150;
    pointer-events: none;
    transform: translate(-50%, -50%);
}

@keyframes playerPulse {
    0%, 100% {
        box-shadow: 0 0 15px var(--primary-light);
    }
    50% {
        box-shadow: 0 0 25px var(--primary-light), 0 0 35px var(--primary);
    }
}

@keyframes memoryPlayerPulse {
    0%, 100% {
        box-shadow: 
            0 0 25px var(--primary-light),
            0 0 50px var(--primary),
            0 0 75px rgba(139, 92, 246, 0.8);
    }
    50% {
        box-shadow: 
            0 0 35px var(--primary-light),
            0 0 70px var(--primary),
            0 0 100px rgba(139, 92, 246, 1);
    }
}

.trail {
    position: absolute;
    width: var(--trail-size);
    height: var(--trail-size);
    background: var(--primary);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 10px var(--primary);
    pointer-events: none;
    z-index: 1;
    opacity: 0.8;
}

.guide-trail {
    background: rgba(0, 255, 0, 0.5);
    animation: guideTrailFade 3s ease-out forwards;
}

.game-controls {
    position: fixed;
    top: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 1000;
}

.game-controls button {
    background: rgba(139, 92, 246, 0.1);
    border: 1px solid rgba(139, 92, 246, 0.3);
    color: var(--light);
    padding: 12px 18px;
    font-size: 15px;
    border-radius: var(--border-radius-md);
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    min-width: 120px;
    justify-content: flex-start;
}

.game-controls button:hover {
    background: rgba(139, 92, 246, 0.2);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}

#victory-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    animation: fadeIn 0.5s ease-out;
}

.victory-content {
    background: rgba(30, 41, 59, 0.8);
    padding: clamp(1.5rem, 4vh, 2.5rem);
    border-radius: var(--border-radius-lg);
    text-align: center;
    border: 1px solid rgba(139, 92, 246, 0.3);
    box-shadow: var(--shadow-lg), 0 0 35px rgba(139, 92, 246, 0.2);
    animation: scaleIn 0.5s ease-out;
    width: min(95%, 500px);
    display: grid;
    gap: clamp(1rem, 2vh, 1.5rem);
}

.victory-content h2 {
    font-size: clamp(1.8rem, 4vw, 2.5rem);
    margin: 0 0 1rem;
    color: var(--primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
}

.victory-content h2 i {
    color: var(--warning);
    animation: trophyShine 2s infinite;
}

#victory-stats {
    display: grid;
    gap: 1rem;
    margin: 1rem 0;
}

.victory-stat {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-size: clamp(1rem, 2.5vw, 1.2rem);
    color: var(--light);
    background: rgba(139, 92, 246, 0.1);
    padding: 0.75rem 1.5rem;
    border-radius: var(--border-radius-md);
    border: 1px solid rgba(139, 92, 246, 0.2);
}

.victory-stat i {
    color: var(--primary-light);
}

.control-btn {
    background: linear-gradient(45deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    padding: 0.8rem 1.6rem;
    font-size: 1rem;
    border: none;
    border-radius: var(--border-radius-full);
    cursor: pointer;
    transition: all var(--transition-normal);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    box-shadow: var(--shadow-md), 0 0 15px rgba(108, 92, 231, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin: 0.25rem;
}

.control-btn:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md), 0 0 20px rgba(139, 92, 246, 0.4);
}

.control-btn.secondary {
    background: rgba(139, 92, 246, 0.2);
    border: 1px solid rgba(139, 92, 246, 0.3);
}

.control-btn.secondary:hover {
    background: rgba(139, 92, 246, 0.3);
}

#pause-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.95);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1500;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    animation: fadeIn 0.3s ease-out;
}

.pause-content {
    background: rgba(30, 41, 59, 0.9);
    padding: 2rem;
    border-radius: var(--border-radius-lg);
    text-align: center;
    border: 1px solid rgba(139, 92, 246, 0.3);
    box-shadow: var(--shadow-lg);
    animation: scaleIn 0.3s ease-out;
    width: min(90%, 400px);
}

.pause-content h2 {
    font-size: 2rem;
    margin: 0 0 2rem;
    color: var(--primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
}

.pause-buttons {
    display: grid;
    gap: 1rem;
}

.shifting-wall {
    animation: wallShift 0.5s ease-in-out;
}

@keyframes wallShift {
    0% {
        filter: hue-rotate(0deg) brightness(1);
    }
    25% {
        filter: hue-rotate(90deg) brightness(1.2);
    }
    50% {
        filter: hue-rotate(180deg) brightness(1.4);
    }
    75% {
        filter: hue-rotate(270deg) brightness(1.2);
    }
    100% {
        filter: hue-rotate(360deg) brightness(1);
    }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes fadeOut {
    0% {
        opacity: 0.8;
        transform: translate(-50%, -50%) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.5);
    }
}

@keyframes trailFade {
    0% {
        opacity: 0.8;
        transform: translate(-50%, -50%) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.5);
    }
}

@keyframes pulseStartBtn {
    0% {
        box-shadow: 0 0 0 0 rgba(139, 92, 246, 0.7);
    }
    70% {
        box-shadow: 0 0 0 15px rgba(139, 92, 246, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(139, 92, 246, 0);
    }
}

@keyframes trophyShine {
    0% { color: var(--warning); }
    50% { color: var(--success); }
    100% { color: var(--warning); }
}

@keyframes guideTrailFade {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
    20% { opacity: 0.8; transform: translate(-50%, -50%) scale(1.2); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(1); }
}

#how-to-play-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.95);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
}

#how-to-play-modal.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: rgba(30, 41, 59, 0.95);
    padding: clamp(1.5rem, 4vh, 2.5rem);
    border-radius: var(--border-radius-lg);
    width: min(90%, 600px);
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
    border: 1px solid rgba(139, 92, 246, 0.3);
    box-shadow: var(--shadow-lg), 0 0 35px rgba(139, 92, 246, 0.2);
    color: var(--light);
    animation: slideUp 0.3s ease-out;
    transform: translateY(0);
}

.modal-content h2 {
    font-size: clamp(1.5rem, 3.5vw, 2rem);
    margin: 0 0 1.5rem;
    color: var(--primary-light);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.modal-content h3 {
    font-size: clamp(1.1rem, 2.5vw, 1.2rem);
    margin: 1.5rem 0 0.75rem;
    color: var(--secondary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.modal-content p, 
.modal-content ul {
    margin: 0.75rem 0;
    line-height: 1.6;
    color: var(--light);
    opacity: 0.9;
    font-size: clamp(0.9rem, 2vw, 1rem);
}

.modal-content ul {
    padding-left: 1.5rem;
}

.modal-content li {
    margin: 0.5rem 0;
}

.modal-content i {
    color: var(--primary-light);
    font-size: 1.2em;
    width: 1.5em;
    text-align: center;
}

.close-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    color: var(--light);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    line-height: 1;
    opacity: 0.7;
    transition: all var(--transition-normal);
}

.close-btn:hover {
    opacity: 1;
    transform: scale(1.1);
}

.no-glow * {
    box-shadow: none !important;
    text-shadow: none !important;
}

.no-glow #player {
    box-shadow: none !important;
}

.no-glow .trail {
    box-shadow: none !important;
}

.no-glow .menu-content,
.no-glow .victory-content {
    box-shadow: none !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
}

.no-glow .difficulty-btn.active {
    box-shadow: none !important;
}

@media screen and (max-width: 768px) {
    #mazeContainer {
        width: 85vmin;
        height: 85vmin;
        max-width: none;
        max-height: none;
    }

    #game-stats {
        top: 10px;
        left: 10px;
        padding: 12px 16px;
        gap: 10px;
    }
    
    .stat-item {
        font-size: 13px;
        min-width: 100px;
    }
    
    .stat-item i {
        font-size: 16px;
        width: 18px;
    }
    
    .game-controls {
        top: 10px;
        right: 10px;
        gap: 10px;
    }
    
    .game-controls button {
        padding: 10px 14px;
        font-size: 13px;
        min-width: 100px;
    }
    
}

@media screen and (max-width: 480px) {
    #mazeContainer {
        width: 90vmin;
        height: 90vmin;
    }
    
    #game-stats {
        top: 8px;
        left: 8px;
        padding: 10px 12px;
        gap: 8px;
    }
    
    .stat-item {
        font-size: 12px;
        min-width: 90px;
    }
    
    .stat-item i {
        font-size: 14px;
        width: 16px;
    }
    
    .game-controls {
        top: 8px;
        right: 8px;
        gap: 8px;
    }
    
    .game-controls button {
        padding: 8px 12px;
        font-size: 12px;
        min-width: 90px;
    }
}

@media screen and (max-height: 600px) {
    #mazeContainer {
        width: 80vh;
        height: 80vh;
    }

    #game-stats,
    .game-controls {
        top: 5px;
    }
    
    #game-stats {
        left: 5px;
    }
    
    .game-controls {
        right: 5px;
    }
}

@supports (padding: max(0px)) {
    .menu-content,
    #game-stats,
    .modal-content {
        padding-left: max(env(safe-area-inset-left), 1rem);
        padding-right: max(env(safe-area-inset-right), 1rem);
        padding-bottom: max(env(safe-area-inset-bottom), 1rem);
        padding-top: max(env(safe-area-inset-top), 1rem);
    }
}
