@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700;800&display=swap');

/* Reset and Core Variables Overrides */
body {
    background: #090d16 !important;
    background-image: radial-gradient(circle at 50% 50%, #15102a 0%, #090d16 100%) !important;
    color: #f8fafc !important;
    min-height: 100vh;
    font-family: 'Poppins', sans-serif !important;
    margin: 0;
    display: flex;
    flex-direction: column;
}

/* Custom Back Button Override */
.back-btn {
    align-self: flex-start;
    color: #c084fc !important;
    background: rgba(139, 92, 246, 0.15) !important;
    border: 1px solid rgba(139, 92, 246, 0.3) !important;
    box-shadow: 0 0 10px rgba(139, 92, 246, 0.1) !important;
    transition: all 0.3s ease !important;
}

.back-btn:hover {
    background: rgba(139, 92, 246, 0.25) !important;
    box-shadow: 0 0 15px rgba(139, 92, 246, 0.3) !important;
    transform: translateX(-5px) !important;
}

/* Premium Glass Container */
.game-container {
    background: rgba(15, 23, 42, 0.75) !important;
    backdrop-filter: blur(20px);
    border: 1px solid rgba(139, 92, 246, 0.25) !important;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4), 0 0 30px rgba(139, 92, 246, 0.15) !important;
    color: #f1f5f9 !important;
    border-radius: 24px !important;
    padding: 2.5rem !important;
    margin: 1.5rem auto 3rem auto !important;
    width: 90%;
    max-width: 900px !important;
    box-sizing: border-box;
}

.game-header {
    text-align: center;
    margin-bottom: 2rem;
}

.game-title {
    font-size: 2.4rem !important;
    margin-bottom: 0.5rem;
    font-weight: 800;
    letter-spacing: 1px;
}

.game-title i {
    color: var(--primary-color);
    margin-right: 10px;
    filter: drop-shadow(0 0 8px rgba(139, 92, 246, 0.6));
}

.game-title span {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 800;
    filter: drop-shadow(0 0 10px rgba(236, 72, 153, 0.4));
}

.game-desc {
    color: #94a3b8 !important;
    font-size: 0.95rem !important;
    max-width: 650px;
    margin: 0 auto;
    line-height: 1.6;
}

/* Top menu bar */
.menu-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
    margin-bottom: 2rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.difficulty-select {
    display: flex;
    background: rgba(15, 23, 42, 0.6);
    padding: 5px;
    border-radius: 50px;
    border: 1px solid rgba(139, 92, 246, 0.25);
}

.diff-btn {
    background: none;
    border: none;
    color: #94a3b8;
    padding: 8px 22px;
    border-radius: 50px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.85rem;
    font-family: 'Poppins', sans-serif;
    letter-spacing: 0.5px;
}

.diff-btn:hover {
    color: #ffffff;
}

.diff-btn.active {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: #ffffff;
    box-shadow: 0 0 15px rgba(139, 92, 246, 0.5);
}

.control-actions {
    display: flex;
    gap: 12px;
}

.action-btn {
    background: rgba(30, 41, 59, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: #f1f5f9;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 1.05rem;
}

.action-btn:hover {
    border-color: var(--primary-color);
    box-shadow: 0 0 12px rgba(139, 92, 246, 0.4);
    color: #c084fc;
    transform: translateY(-2px);
}

/* Statistics panel */
.stats-panel {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    margin-bottom: 2rem;
}

.stat-item {
    background: rgba(30, 41, 59, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.05);
    padding: 12px 8px;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.stat-item:hover {
    border-color: rgba(139, 92, 246, 0.3);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
    transform: translateY(-2px);
}

.stat-label {
    font-size: 0.75rem;
    color: #94a3b8;
    font-weight: 700;
    letter-spacing: 1.2px;
    margin-bottom: 4px;
}

.stat-val {
    font-size: 1.35rem;
    font-weight: 700;
    color: #ffffff;
}

#time-val { color: #38bdf8; text-shadow: 0 0 10px rgba(56, 189, 248, 0.35); }
#moves-val { color: #f472b6; text-shadow: 0 0 10px rgba(244, 114, 182, 0.35); }
#score-val { color: #fbbf24; text-shadow: 0 0 10px rgba(251, 191, 36, 0.35); }
#hint-val { color: #a78bfa; text-shadow: 0 0 10px rgba(167, 139, 250, 0.35); }

/* Main game layout */
.game-layout {
    display: flex;
    gap: 30px;
    justify-content: center;
    align-items: flex-start;
    margin-top: 10px;
}

.canvas-wrapper {
    position: relative;
    background: #0d121f;
    border-radius: 20px;
    padding: 10px;
    border: 1px solid rgba(139, 92, 246, 0.35);
    box-shadow: 0 15px 45px rgba(0, 0, 0, 0.5), inset 0 0 30px rgba(139, 92, 246, 0.15);
    display: flex;
    justify-content: center;
    align-items: center;
    flex: 1 1 500px;
    max-width: 500px;
    width: 100%;
    aspect-ratio: 1 / 1;
    box-sizing: border-box;
}

#maze-canvas {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 12px;
    background-color: #060911;
}

.ui-panel {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 250px;
    flex-shrink: 0;
}

/* Glowing Neon Buttons */
.btn {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    color: #ffffff !important;
    border: none;
    padding: 14px 28px;
    font-size: 1rem;
    font-weight: 700;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    letter-spacing: 0.8px;
    text-transform: uppercase;
}

.btn-hint {
    background: linear-gradient(135deg, #d97706, #b45309);
    box-shadow: 0 4px 15px rgba(217, 119, 6, 0.35);
    border: 1px solid rgba(251, 191, 36, 0.2);
}

.btn-hint:hover:not(:disabled) {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(217, 119, 6, 0.5);
    border-color: rgba(251, 191, 36, 0.4);
}

.btn-hint:disabled {
    background: #1e293b;
    color: #64748b !important;
    box-shadow: none;
    border-color: transparent;
    cursor: not-allowed;
}

.btn-restart {
    background: linear-gradient(135deg, #0284c7, #0369a1);
    box-shadow: 0 4px 15px rgba(2, 132, 199, 0.35);
    border: 1px solid rgba(56, 189, 248, 0.2);
}

.btn-restart:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(2, 132, 199, 0.5);
    border-color: rgba(56, 189, 248, 0.4);
}

/* Virtual Game Controller D-Pad */
.dpad-container {
    background: rgba(30, 41, 59, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.05);
    padding: 20px;
    border-radius: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: inset 0 0 15px rgba(0, 0, 0, 0.2);
}

.dpad {
    display: grid;
    grid-template-columns: repeat(3, 52px);
    grid-template-rows: repeat(3, 52px);
    gap: 8px;
    width: 172px;
    height: 172px;
}

.dpad-btn {
    background: rgba(15, 23, 42, 0.85);
    border: 1px solid rgba(139, 92, 246, 0.3);
    color: #a78bfa;
    border-radius: 12px;
    font-size: 1.25rem;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.15s ease-out;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.dpad-btn:hover {
    border-color: var(--primary-color);
    color: #c084fc;
    background: rgba(139, 92, 246, 0.1);
}

.dpad-btn:active, .dpad-btn.pressed {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: #ffffff;
    border-color: transparent;
    box-shadow: 0 0 18px var(--primary-color);
    transform: scale(0.92);
}

.dpad-btn.up { grid-row: 1; grid-column: 2; border-radius: 16px 16px 8px 8px; }
.dpad-btn.left { grid-row: 2; grid-column: 1; border-radius: 16px 8px 8px 16px; }
.dpad-center {
    grid-row: 2;
    grid-column: 2;
    background: rgba(30, 41, 59, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.05);
    color: #475569;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.15rem;
    border-radius: 8px;
}
.dpad-btn.right { grid-row: 2; grid-column: 3; border-radius: 8px 16px 16px 8px; }
.dpad-btn.down { grid-row: 3; grid-column: 2; border-radius: 8px 8px 16px 16px; }

/* Modals and Overlays Styling */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(6, 9, 17, 0.85);
    backdrop-filter: blur(10px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 20px;
    box-sizing: border-box;
}

.modal-overlay.show {
    display: flex;
    animation: fadeIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.glass-panel {
    background: #0f172a !important;
    padding: 35px 30px;
    border-radius: 24px;
    text-align: center;
    max-width: 440px;
    width: 100%;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.6), 0 0 40px rgba(139, 92, 246, 0.25) !important;
    border: 1px solid rgba(139, 92, 246, 0.4) !important;
    animation: slideUp 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
}

.modal-close-x {
    position: absolute;
    top: 15px;
    right: 20px;
    background: none;
    border: none;
    font-size: 28px;
    font-weight: 700;
    color: #64748b;
    cursor: pointer;
    transition: color 0.2s;
    line-height: 1;
    padding: 5px;
}

.modal-close-x:hover {
    color: #f8fafc;
}

.glass-panel h2 {
    color: #ffffff !important;
    font-size: 1.85rem;
    font-weight: 800;
    margin-bottom: 20px;
    text-shadow: 0 0 15px rgba(139, 92, 246, 0.4);
}

/* Help specific modal */
.help-content {
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 25px;
}

.help-content p {
    margin: 0;
    display: flex;
    align-items: flex-start;
    gap: 14px;
    color: #cbd5e1 !important;
    font-size: 0.95rem;
    line-height: 1.5;
}

.help-content i {
    font-size: 1.35rem;
    margin-top: 2px;
    flex-shrink: 0;
}

/* Success specific modal */
.success-panel {
    border-color: rgba(16, 185, 129, 0.4) !important;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.6), 0 0 45px rgba(16, 185, 129, 0.25) !important;
}

.success-icon {
    font-size: 4rem;
    color: #10b981;
    margin-bottom: 12px;
    display: inline-block;
    filter: drop-shadow(0 0 15px rgba(16, 185, 129, 0.6));
    animation: bouncePop 1s infinite alternate cubic-bezier(0.4, 0, 0.2, 1);
}

.success-subtitle {
    color: #94a3b8 !important;
    font-size: 1.05rem;
    margin-top: 0;
    margin-bottom: 20px;
}

.result-rank {
    font-size: 1.4rem;
    font-weight: 800;
    color: #10b981 !important;
    margin: 15px 0 20px 0;
    padding: 12px;
    background: rgba(16, 185, 129, 0.1) !important;
    border-radius: 14px;
    border: 2px dashed rgba(16, 185, 129, 0.3) !important;
    letter-spacing: 0.5px;
    text-shadow: 0 0 10px rgba(16, 185, 129, 0.3);
}

.modal-stats {
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: rgba(15, 23, 42, 0.6);
    padding: 18px;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    margin-bottom: 25px;
}

.modal-stat {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1.05rem;
    font-weight: 600;
}

.modal-stat .m-label {
    color: #94a3b8;
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-stat .m-label i {
    font-size: 0.95rem;
}

.modal-stat .m-val {
    color: #ffffff;
    font-weight: 700;
}

.modal-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    border: none;
    padding: 12px 26px;
    border-radius: 50px;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 15px rgba(139, 92, 246, 0.4);
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(236, 72, 153, 0.5);
}

.btn-secondary {
    background: rgba(30, 41, 59, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: #f8fafc;
    padding: 12px 26px;
    border-radius: 50px;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.btn-secondary:hover {
    background: rgba(30, 41, 59, 1);
    border-color: #64748b;
    transform: translateY(-2px);
}

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

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

@keyframes bouncePop {
    from { transform: translateY(0) scale(1); }
    to { transform: translateY(-8px) scale(1.06); }
}

/* Responsive CSS Styles */
@media (max-width: 768px) {
    .game-container {
        padding: 1.5rem !important;
        margin: 1rem auto 2rem auto !important;
    }
    
    .game-title {
        font-size: 2rem !important;
    }
    
    .stats-panel {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        margin-bottom: 1.5rem;
    }
    
    .stat-val {
        font-size: 1.2rem;
    }

    .game-layout {
        flex-direction: column;
        align-items: center;
        gap: 20px;
    }
    
    .canvas-wrapper {
        flex: 1 1 100%;
        max-width: 100%;
    }
    
    .ui-panel {
        width: 100%;
        max-width: 500px;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: space-between;
        gap: 12px;
    }
    
    .ui-panel .btn {
        flex: 1 1 calc(50% - 6px);
        padding: 12px;
        font-size: 0.9rem;
    }
    
    .dpad-container {
        flex: 1 1 100%;
        margin-top: 5px;
        padding: 15px;
    }
}

@media (max-width: 480px) {
    .menu-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    
    .difficulty-select {
        justify-content: center;
    }
    
    .control-actions {
        justify-content: center;
    }

    .modal-actions {
        flex-direction: column;
        gap: 10px;
    }
    
    .modal-actions button {
        width: 100%;
    }
}
