/* ============================================= */
/* Tertis World Tour - Styles                   */
/* ============================================= */

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    overflow: hidden;
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Canvas Elements */
#bgCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
}

#particleCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 999;
}

#gameCanvas {
    display: block;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 15px;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.8);
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
    image-rendering: -webkit-optimize-contrast;
}

/* ============================================= */
/* Dashboard Navigation Button - Cosmic HUD     */
/* ============================================= */
.dashboard-nav-btn {
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 9999;
    padding: 10px 18px;
    background: linear-gradient(135deg, rgba(34, 211, 238, 0.25), rgba(168, 85, 247, 0.25));
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    border: 2px solid rgba(34, 211, 238, 0.5);
    border-radius: 30px;
    color: #fff;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 4px 20px rgba(34, 211, 238, 0.3), 0 0 40px rgba(34, 211, 238, 0.1);
    animation: navGlow 3s ease-in-out infinite alternate;
}

@keyframes navGlow {
    0% {
        box-shadow: 0 4px 20px rgba(34, 211, 238, 0.3), 0 0 40px rgba(34, 211, 238, 0.1);
    }

    100% {
        box-shadow: 0 4px 25px rgba(168, 85, 247, 0.4), 0 0 50px rgba(168, 85, 247, 0.15);
    }
}

.dashboard-nav-btn:hover {
    transform: translateY(-3px) scale(1.05);
    background: linear-gradient(135deg, rgba(34, 211, 238, 0.4), rgba(168, 85, 247, 0.4));
    border-color: #22d3ee;
    box-shadow: 0 8px 30px rgba(34, 211, 238, 0.5), 0 0 60px rgba(34, 211, 238, 0.2);
}

.dashboard-nav-btn:active {
    transform: translateY(0) scale(0.98);
}

/* ============================================= */
/* Game Container & Layout                       */
/* ============================================= */
.game-container {
    width: 100%;
    height: 100%;
    max-width: 800px;
    max-height: 900px;
    display: flex;
    flex-direction: column;
}

.game-wrapper {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    position: relative;
}

.game-board {
    position: relative;
    background: linear-gradient(145deg, rgba(0, 0, 0, 0.9), rgba(20, 20, 40, 0.9));
    -webkit-backdrop-filter: blur(15px);
    backdrop-filter: blur(15px);
    border-radius: 20px;
    padding: 25px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
    border: 3px solid rgba(255, 255, 255, 0.2);
    transition: border-color 0.15s ease;
}

/* Collision Effects */
.game-board.collision-left {
    border-left-color: rgba(255, 100, 100, 0.8) !important;
}

.game-board.collision-right {
    border-right-color: rgba(255, 100, 100, 0.8) !important;
}

.game-board.collision-bottom {
    border-bottom-color: rgba(255, 215, 0, 0.8) !important;
}

/* ============================================= */
/* Top Bar                                       */
/* ============================================= */
.top-bar {
    background: linear-gradient(135deg, rgba(0, 0, 0, 0.8), rgba(30, 30, 60, 0.8));
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: white;
    font-size: 14px;
    flex-wrap: wrap;
    gap: 10px;
    border-radius: 10px 10px 0 0;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    border: 2px solid rgba(255, 255, 255, 0.1);
}

.top-bar-section {
    display: flex;
    align-items: center;
    gap: 15px;
}

.icon-btn {
    background: linear-gradient(145deg, rgba(80, 80, 120, 0.8), rgba(40, 40, 80, 0.8));
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: white;
    font-size: 20px;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.icon-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.4);
}

.icon-btn:active {
    transform: scale(0.95);
}

/* ============================================= */
/* Side Panels (Hold & Next)                     */
/* ============================================= */
.side-panel {
    position: absolute;
    background: linear-gradient(145deg, rgba(0, 0, 0, 0.85), rgba(30, 30, 60, 0.85));
    -webkit-backdrop-filter: blur(15px);
    backdrop-filter: blur(15px);
    padding: 20px;
    border-radius: 15px;
    color: white;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.5);
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.next-panel {
    top: 20px;
    right: 20px;
    width: 130px;
}

.hold-panel {
    top: 20px;
    left: 20px;
    width: 130px;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.hold-panel:hover {
    transform: scale(1.03);
    box-shadow: 0 10px 25px rgba(102, 126, 234, 0.4);
}

.hold-panel:active {
    transform: scale(0.98);
}

.side-panel h3 {
    text-align: center;
    margin-bottom: 15px;
    font-size: 15px;
    background: linear-gradient(90deg, #667eea, #764ba2);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.hold-hint {
    text-align: center;
    font-size: 10px;
    color: #aaa;
    margin-top: 8px;
}

/* ============================================= */
/* Mobile Controls                               */
/* ============================================= */
.mobile-controls {
    display: none;
    position: fixed;
    bottom: 15px;
    bottom: calc(15px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
    gap: 40px;
    padding: 18px 30px;
    background: linear-gradient(145deg, rgba(0, 0, 0, 0.85), rgba(20, 20, 50, 0.85));
    -webkit-backdrop-filter: blur(15px);
    backdrop-filter: blur(15px);
    border-radius: 30px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
    border: 2px solid rgba(255, 255, 255, 0.3);
    z-index: 100;
    touch-action: none;
    transition: all 0.3s ease;
}

.d-pad {
    position: relative;
    width: 180px;
    height: 180px;
}

.d-pad-btn {
    position: absolute;
    width: 62px;
    height: 62px;
    background: linear-gradient(145deg, rgba(100, 100, 170, 0.9), rgba(60, 60, 130, 0.9));
    border: 3px solid rgba(255, 255, 255, 0.5);
    border-radius: 14px;
    color: rgba(255, 255, 255, 0.95);
    font-size: 30px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-user-select: none;
    user-select: none;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.4);
    opacity: 1;
    transition: transform 0.08s ease, box-shadow 0.1s ease;
    -webkit-tap-highlight-color: transparent;
}

.d-pad-btn:active,
.d-pad-btn.active {
    transform: scale(0.88);
    background: linear-gradient(145deg, rgba(130, 130, 200, 1), rgba(90, 90, 160, 1));
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5), inset 0 2px 10px rgba(255, 255, 255, 0.2);
}

.d-pad-up {
    top: 0;
    left: 50%;
    transform: translateX(-50%);
}

.d-pad-down {
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
}

.d-pad-left {
    left: 0;
    top: 50%;
    transform: translateY(-50%);
}

.d-pad-right {
    right: 0;
    top: 50%;
    transform: translateY(-50%);
}

@keyframes collisionFlash {
    0% {
        box-shadow: 0 0 0 rgba(255, 100, 100, 0);
    }

    50% {
        box-shadow: 0 0 25px rgba(255, 100, 100, 0.8);
    }

    100% {
        box-shadow: 0 0 0 rgba(255, 100, 100, 0);
    }
}

.d-pad-btn.collision {
    animation: collisionFlash 0.2s ease-out;
}

.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.action-btn {
    width: 72px;
    height: 72px;
    background: linear-gradient(145deg, rgba(120, 60, 180, 0.85), rgba(80, 40, 130, 0.85));
    border: 3px solid rgba(255, 255, 255, 0.4);
    border-radius: 50%;
    color: rgba(255, 255, 255, 0.95);
    font-size: 12px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 5px 18px rgba(100, 50, 150, 0.5);
    opacity: 1;
    transition: transform 0.08s ease, box-shadow 0.1s ease;
    -webkit-tap-highlight-color: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
}

.action-btn:first-child {
    background: linear-gradient(145deg, rgba(255, 100, 100, 0.85), rgba(200, 60, 60, 0.85));
    box-shadow: 0 5px 18px rgba(255, 80, 80, 0.5);
}

.action-btn:last-child {
    background: linear-gradient(145deg, rgba(100, 180, 255, 0.85), rgba(60, 130, 200, 0.85));
    box-shadow: 0 5px 18px rgba(100, 150, 255, 0.5);
}

.action-btn:active {
    transform: scale(0.88);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4), inset 0 2px 10px rgba(255, 255, 255, 0.15);
}

/* ============================================= */
/* Menu System                                   */
/* ============================================= */
.menu-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(0, 0, 0, 0.95), rgba(20, 20, 50, 0.95));
    -webkit-backdrop-filter: blur(25px);
    backdrop-filter: blur(25px);
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    color: white;
    padding: 20px;
    overflow-y: auto;
}

.menu-screen.active {
    display: flex;
}

.menu-title {
    font-size: 48px;
    font-weight: bold;
    margin-bottom: 40px;
    text-shadow: 0 0 30px rgba(102, 126, 234, 0.8);
    background: linear-gradient(45deg, #667eea, #764ba2, #f093fb, #667eea);
    background-size: 300% 300%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: gradientFlow 4s ease infinite;
}

@keyframes gradientFlow {

    0%,
    100% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 18px;
    width: 100%;
    max-width: 450px;
}

.menu-btn {
    padding: 18px 35px;
    font-size: 18px;
    font-weight: 600;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.9), rgba(118, 75, 162, 0.9));
    border: 3px solid rgba(255, 255, 255, 0.4);
    border-radius: 18px;
    color: white;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

.menu-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 30px rgba(102, 126, 234, 0.5);
}

.menu-btn:active {
    transform: translateY(0);
}

.menu-btn.exit-btn {
    background: linear-gradient(145deg, rgba(255, 80, 80, 0.6), rgba(180, 40, 40, 0.6));
}

.menu-close-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 45px;
    height: 45px;
    background: linear-gradient(145deg, rgba(255, 80, 80, 0.8), rgba(180, 40, 40, 0.8));
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    color: white;
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1001;
    transition: all 0.3s;
    box-shadow: 0 4px 15px rgba(255, 80, 80, 0.4);
}

.menu-close-btn:hover {
    transform: scale(1.1) rotate(90deg);
    box-shadow: 0 6px 20px rgba(255, 80, 80, 0.6);
}

.menu-close-btn:active {
    transform: scale(0.95);
}

/* ============================================= */
/* Level Select Grid                             */
/* ============================================= */
.level-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
    width: 100%;
    max-width: 500px;
    max-height: 65vh;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 15px;
    scroll-padding-top: 0;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 20px;
    -webkit-overflow-scrolling: touch;
}

.level-card {
    aspect-ratio: 1;
    background: linear-gradient(145deg, rgba(60, 60, 100, 0.6), rgba(30, 30, 60, 0.6));
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s;
    position: relative;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.level-card:hover {
    transform: scale(1.08) translateY(-3px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.5);
}

.level-card.locked {
    opacity: 0.4;
    cursor: not-allowed;
}

.level-card.completed .trophy {
    position: absolute;
    top: 8px;
    right: 8px;
    font-size: 22px;
}

/* ============================================= */
/* Popup                                         */
/* ============================================= */
.popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: linear-gradient(145deg, rgba(30, 30, 60, 0.98), rgba(10, 10, 30, 0.98));
    -webkit-backdrop-filter: blur(25px);
    backdrop-filter: blur(25px);
    padding: 40px;
    border-radius: 25px;
    border: 3px solid rgba(255, 255, 255, 0.4);
    color: white;
    text-align: center;
    z-index: 2000;
    max-width: 90%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
    display: none;
}

.popup.show {
    display: block;
}

.popup-close-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 36px;
    height: 36px;
    background: linear-gradient(145deg, rgba(255, 80, 80, 0.9), rgba(200, 40, 40, 0.9));
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-radius: 50%;
    color: white;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2001;
    transition: all 0.3s;
    box-shadow: 0 4px 12px rgba(255, 80, 80, 0.4);
}

.popup-close-btn:hover {
    transform: scale(1.15) rotate(90deg);
    box-shadow: 0 6px 18px rgba(255, 80, 80, 0.6);
}

.popup-close-btn:active {
    transform: scale(0.95);
}

.popup-title {
    font-size: 36px;
    margin-bottom: 20px;
    background: linear-gradient(90deg, #667eea, #764ba2, #f093fb);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.popup-buttons {
    display: flex;
    gap: 15px;
    margin-top: 25px;
    justify-content: center;
    flex-wrap: wrap;
}

/* ============================================= */
/* Floating Text Animation                       */
/* ============================================= */
.floating-text {
    position: absolute;
    font-size: 28px;
    font-weight: bold;
    color: #FFD700;
    text-shadow: 0 0 15px rgba(255, 215, 0, 0.9);
    pointer-events: none;
    animation: floatUp 1.2s ease-out forwards;
    z-index: 1000;
}

@keyframes floatUp {
    0% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }

    100% {
        opacity: 0;
        transform: translateY(-120px) scale(1.5);
    }
}

/* ============================================= */
/* Stats & Settings                              */
/* ============================================= */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    max-width: 700px;
    margin: 25px auto;
}

.stat-card {
    background: linear-gradient(145deg, rgba(60, 60, 100, 0.6), rgba(30, 30, 60, 0.6));
    padding: 20px;
    border-radius: 15px;
    text-align: center;
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.stat-value {
    font-size: 36px;
    font-weight: bold;
    background: linear-gradient(90deg, #FFD700, #FFA500);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.stat-label {
    font-size: 14px;
    opacity: 0.9;
    margin-top: 8px;
}

.settings-panel {
    background: rgba(0, 0, 0, 0.3);
    padding: 25px;
    border-radius: 15px;
    max-width: 500px;
    margin: 20px auto;
    scrollbar-width: thin;
    scrollbar-color: #667eea rgba(0, 0, 0, 0.3);
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    margin: 10px 0;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

.toggle-btn {
    width: 60px;
    height: 30px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 15px;
    position: relative;
    cursor: pointer;
    transition: background 0.3s;
}

.toggle-btn.active {
    background: linear-gradient(135deg, #667eea, #764ba2);
}

.toggle-btn::after {
    content: '';
    position: absolute;
    width: 26px;
    height: 26px;
    background: white;
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: left 0.3s;
}

.toggle-btn.active::after {
    left: 32px;
}

/* ============================================= */
/* Custom Scrollbar                              */
/* ============================================= */
.settings-panel::-webkit-scrollbar,
#promptText::-webkit-scrollbar {
    width: 12px;
}

.settings-panel::-webkit-scrollbar-track,
#promptText::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 10px;
    margin: 5px;
}

.settings-panel::-webkit-scrollbar-thumb,
#promptText::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #667eea 0%, #764ba2 100%);
    border-radius: 10px;
    border: 2px solid rgba(0, 0, 0, 0.3);
    box-shadow: 0 0 10px rgba(102, 126, 234, 0.5);
}

.settings-panel::-webkit-scrollbar-thumb:hover,
#promptText::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, #764ba2 0%, #667eea 100%);
    box-shadow: 0 0 15px rgba(118, 75, 162, 0.8);
}

/* ============================================= */
/* Responsive Design                             */
/* ============================================= */
@media (hover: none) and (pointer: coarse) {
    .mobile-controls {
        display: flex !important;
    }

    .game-wrapper {
        padding-bottom: 200px;
    }
}

@media (max-width: 480px) {
    .level-grid {
        grid-template-columns: repeat(5, 1fr);
        gap: 8px;
        padding: 10px;
        max-width: 100%;
    }

    .level-card {
        font-size: 12px;
    }
}

@media (min-width: 481px) and (max-width: 768px) {
    .level-grid {
        grid-template-columns: repeat(5, 1fr);
        gap: 10px;
        max-width: 400px;
    }
}

@media (min-width: 769px) {
    .level-grid {
        grid-template-columns: repeat(10, 1fr);
        max-width: 800px;
        gap: 12px;
    }
}

@media (max-width: 768px) {
    .mobile-controls {
        display: flex !important;
    }

    .game-wrapper {
        padding-bottom: 200px;
    }

    .side-panel {
        display: none;
    }

    .top-bar {
        font-size: 11px;
        padding: 8px 12px;
    }

    .icon-btn {
        width: 35px;
        height: 35px;
        font-size: 18px;
    }

    .menu-title {
        font-size: 32px;
    }
}