/* Maze Game CSS - Kid-friendly design with icons and full viewport fit */

/* Reset and Base Styles */
* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    max-height: 100vh;
    margin: 0;
    padding: 0;
    overflow: hidden;
    touch-action: manipulation;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    position: fixed;
    width: 100%;
}

.maze-wrapper {
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    padding: 1vh;
    display: flex;
    flex-direction: column;
    gap: 1vh;
    overflow: hidden;
    box-sizing: border-box;
    position: relative;
}

/* Game Header */
.maze-header {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    padding: 1vh 2vw;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    min-height: 8vh;
    display: flex;
    align-items: center;
    flex-shrink: 0;
    backdrop-filter: blur(10px);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    gap: 2vw;
}

.header-left, .header-center, .header-right {
    display: flex;
    align-items: center;
    gap: 1vw;
}

.header-center {
    flex: 1;
    justify-content: center;
}

/* Game Title Icon */
.game-title-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: clamp(40px, 8vw, 60px);
    height: clamp(40px, 8vw, 60px);
    background: linear-gradient(135deg, #FF6B6B, #FF8E8E);
    border-radius: 50%;
    box-shadow: 0 4px 15px rgba(255, 107, 107, 0.3);
    animation: bounce 2s infinite;
}

.maze-icon {
    font-size: clamp(20px, 4vw, 30px);
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-5px); }
    60% { transform: translateY(-3px); }
}

/* Difficulty Controls */
.difficulty-controls {
    display: flex;
    gap: 0.5vw;
    background: rgba(255, 255, 255, 0.8);
    padding: 0.5vh 1vw;
    border-radius: 25px;
    border: 2px solid rgba(255, 255, 255, 0.6);
}

.diff-btn {
    width: clamp(35px, 6vw, 45px);
    height: clamp(35px, 6vw, 45px);
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.9);
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(16px, 3vw, 20px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.diff-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}

.diff-btn.active {
    background: linear-gradient(135deg, #4CAF50, #45a049);
    transform: scale(1.1);
    box-shadow: 0 4px 15px rgba(76, 175, 80, 0.4);
}

/* Action Buttons */
.action-btn {
    width: clamp(40px, 7vw, 50px);
    height: clamp(40px, 7vw, 50px);
    border-radius: 15px;
    border: none;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(16px, 3vw, 20px);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.action-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

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

/* Stats */
.stat-box {
    display: flex;
    align-items: center;
    gap: 0.5vw;
    background: rgba(255, 255, 255, 0.9);
    padding: 1vh 1.5vw;
    border-radius: 20px;
    font-size: clamp(14px, 2.5vw, 16px);
    font-weight: 600;
    color: #333;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    border: 2px solid rgba(255, 255, 255, 0.6);
}

/* Main Game Container */
.maze-game-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2vh;
    overflow: hidden;
}

/* Maze Board */
.maze-board-wrapper {
    position: relative;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    width: min(90vw, 90vw, 600px);
    height: min(90vw, 90vw, 600px);
    aspect-ratio: 1 / 1 !important;
    overflow: hidden;
    box-sizing: border-box;
}

/* Alternative square enforcement using padding trick */
.maze-board-wrapper::before {
    content: '';
    display: block;
    width: 100%;
    height: 0;
    padding-bottom: 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: -1;
}

.maze-canvas, .draw-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
    border-radius: 15px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
    background: white;
    border: none;
    box-sizing: border-box;
}

.draw-canvas {
    z-index: 10;
    cursor: crosshair;
    touch-action: none;
}

/* Game Info */
.game-info-container {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
}

.maze-info {
    background: rgba(255, 255, 255, 0.95);
    padding: 1vh 3vw;
    border-radius: 25px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.6);
}

.info-text {
    font-family: 'Fredoka', cursive;
    font-size: clamp(14px, 3vw, 18px);
    font-weight: 600;
    color: #667eea;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Overlays */
.maze-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
}

.maze-overlay.show {
    display: flex;
    animation: fadeIn 0.3s ease;
}

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

/* Success Overlay */
.success-overlay {
    background: rgba(76, 175, 80, 0.9);
}

.success-animation {
    text-align: center;
    color: white;
    animation: celebrationBounce 0.6s ease-out;
}

@keyframes celebrationBounce {
    0% { transform: scale(0.5); opacity: 0; }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}

.big-emoji {
    font-size: clamp(60px, 15vw, 100px);
    display: block;
    margin-bottom: 2vh;
    animation: spin 0.8s ease-in-out;
}

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

.stars {
    display: flex;
    justify-content: center;
    gap: 1vw;
    margin: 2vh 0;
}

.stars span {
    font-size: clamp(25px, 6vw, 40px);
    animation: starTwinkle 1s ease-in-out infinite alternate;
}

.stars span:nth-child(2) {
    animation-delay: 0.2s;
}

.stars span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes starTwinkle {
    from { transform: scale(1); opacity: 0.8; }
    to { transform: scale(1.2); opacity: 1; }
}

.success-animation h2 {
    font-size: clamp(24px, 5vw, 36px);
    margin: 2vh 0 1vh 0;
    font-family: 'Fredoka', cursive;
}

.success-animation p {
    font-size: clamp(16px, 3vw, 20px);
    margin-bottom: 3vh;
    opacity: 0.9;
}

.play-again-btn {
    padding: 2vh 4vw;
    border: none;
    border-radius: 25px;
    background: linear-gradient(135deg, #FF6B6B, #FF8E8E);
    color: white;
    font-size: clamp(16px, 3vw, 18px);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: 'Fredoka', cursive;
    box-shadow: 0 4px 15px rgba(255, 107, 107, 0.3);
}

.play-again-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 107, 107, 0.4);
}

/* Hint Overlay */
.hint-overlay {
    background: rgba(0, 0, 0, 0.5);
}

.hint-bubble {
    background: linear-gradient(135deg, #FFF3E0, #FFECB3);
    border-radius: 20px;
    padding: 3vh 4vw;
    max-width: 80vw;
    text-align: center;
    border: 3px solid #FFB74D;
    box-shadow: 0 8px 30px rgba(255, 183, 77, 0.3);
    position: relative;
    animation: hintPop 0.4s ease-out;
}

@keyframes hintPop {
    0% { transform: scale(0.8); opacity: 0; }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); opacity: 1; }
}

.hint-icon {
    font-size: clamp(30px, 8vw, 50px);
    display: block;
    margin-bottom: 2vh;
    animation: glow 1.5s ease-in-out infinite alternate;
}

@keyframes glow {
    from { filter: drop-shadow(0 0 5px #FFB74D); }
    to { filter: drop-shadow(0 0 15px #FF9800); }
}

.hint-bubble p {
    font-size: clamp(16px, 3vw, 20px);
    color: #E65100;
    font-weight: 600;
    margin: 0;
    font-family: 'Fredoka', cursive;
}

.hint-close {
    position: absolute;
    top: 1vh;
    right: 1vw;
    background: none;
    border: none;
    font-size: clamp(16px, 3vw, 20px);
    cursor: pointer;
    color: #E65100;
    padding: 0.5vh;
}

/* Loading Overlay */
.loading-overlay {
    background: rgba(91, 134, 229, 0.9);
}

.loading-content {
    text-align: center;
    color: white;
}

.loading-icon {
    font-size: clamp(40px, 10vw, 60px);
    display: block;
    margin-bottom: 2vh;
    animation: spin 1s linear infinite;
}

.loading-content p {
    font-size: clamp(16px, 3vw, 20px);
    font-family: 'Fredoka', cursive;
    margin: 0;
}

/* Responsive Adjustments */
@media (max-width: 768px) {
    .maze-wrapper {
        padding: 0.5vh;
    }
    
    .header-content {
        flex-wrap: wrap;
        gap: 1vh;
    }
    
    .header-center {
        order: 3;
        width: 100%;
        justify-content: center;
    }
    
    .maze-board-wrapper {
        width: min(95vw, 95vw, 500px);
        height: min(95vw, 95vw, 500px);
        aspect-ratio: 1 / 1 !important;
    }
}

@media (max-height: 600px) {
    .maze-header {
        min-height: 10vh;
    }
    
    .maze-board-wrapper {
        width: min(85vw, 85vw, 450px);
        height: min(85vw, 85vw, 450px);
        aspect-ratio: 1 / 1 !important;
    }
    
    .size-selector-container {
        padding: 0.5vh 2vw;
    }
}

/* Touch improvements */
@media (pointer: coarse) {
    .diff-btn, .action-btn {
        min-width: 44px;
        min-height: 44px;
    }
    
    .size-btn {
        min-height: 44px;
    }
}

/* Wrong Path Character Popup */
.wrong-path-popup {
    position: fixed;
    z-index: 2000;
    pointer-events: none;
    animation: wrongPathPopup 2.5s ease-out forwards;
}

.character-popup {
    background: linear-gradient(135deg, #FF6B6B, #FF8E8E);
    border-radius: 20px;
    padding: 1vh 2vw;
    box-shadow: 0 8px 30px rgba(255, 107, 107, 0.6);
    text-align: center;
    border: 3px solid white;
    animation: bounceIn 0.6s ease-out;
}

.popup-character {
    font-size: clamp(30px, 8vw, 50px);
    display: block;
    margin-bottom: 0.5vh;
    animation: characterShake 0.8s ease-in-out infinite;
}

.popup-message {
    font-family: 'Fredoka', cursive;
    font-size: clamp(14px, 3vw, 18px);
    color: white;
    font-weight: 600;
    margin: 0;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

@keyframes wrongPathPopup {
    0% { 
        opacity: 0; 
        transform: translate(-50%, -50%) scale(0.3) rotate(-10deg);
    }
    15% { 
        opacity: 1; 
        transform: translate(-50%, -50%) scale(1.1) rotate(5deg);
    }
    25% { 
        transform: translate(-50%, -50%) scale(1) rotate(0deg);
    }
    85% { 
        opacity: 1; 
        transform: translate(-50%, -50%) scale(1) rotate(0deg);
    }
    100% { 
        opacity: 0; 
        transform: translate(-50%, -50%) scale(0.8) rotate(3deg);
    }
}

@keyframes bounceIn {
    0% { 
        transform: scale(0.3); 
        opacity: 0;
    }
    50% { 
        transform: scale(1.05);
        opacity: 1;
    }
    70% { 
        transform: scale(0.95);
    }
    100% { 
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes characterShake {
    0%, 100% { transform: translateX(0) rotate(0deg); }
    25% { transform: translateX(-2px) rotate(-2deg); }
    75% { transform: translateX(2px) rotate(2deg); }
}

/* Screen Flash Effect */
@keyframes flashEffect {
    0% { 
        opacity: 0;
        transform: scale(0.8);
    }
    50% { 
        opacity: 0.8;
        transform: scale(1.2);
    }
    100% { 
        opacity: 0;
        transform: scale(1);
    }
}

/* Screen Shake Effect */
.screen-shake {
    animation: screenShake 0.5s ease-in-out;
}

@keyframes screenShake {
    0%, 100% { 
        transform: translateX(0) translateY(0) rotate(0deg); 
    }
    10% { 
        transform: translateX(-3px) translateY(-2px) rotate(-0.5deg); 
    }
    20% { 
        transform: translateX(3px) translateY(2px) rotate(0.5deg); 
    }
    30% { 
        transform: translateX(-2px) translateY(-3px) rotate(-0.3deg); 
    }
    40% { 
        transform: translateX(2px) translateY(3px) rotate(0.3deg); 
    }
    50% { 
        transform: translateX(-4px) translateY(1px) rotate(-0.7deg); 
    }
    60% { 
        transform: translateX(4px) translateY(-1px) rotate(0.7deg); 
    }
    70% { 
        transform: translateX(-1px) translateY(-2px) rotate(-0.2deg); 
    }
    80% { 
        transform: translateX(1px) translateY(2px) rotate(0.2deg); 
    }
    90% { 
        transform: translateX(-2px) translateY(1px) rotate(-0.4deg); 
    }
}

/* Character Appearance Effect */
.character-appear {
    animation: characterAppear 0.6s ease-out;
}

@keyframes characterAppear {
    0% { 
        transform: scale(0) rotate(-180deg);
        opacity: 0;
        filter: blur(5px);
    }
    50% { 
        transform: scale(1.3) rotate(-90deg);
        opacity: 0.8;
        filter: blur(2px);
    }
    80% { 
        transform: scale(0.9) rotate(10deg);
        opacity: 1;
        filter: blur(0px);
    }
    100% { 
        transform: scale(1) rotate(0deg);
        opacity: 1;
        filter: blur(0px);
    }
}

/* High DPI adjustments */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .maze-canvas, .draw-canvas {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}