@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700;900&family=Rajdhani:wght@400;600;700&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: #0a0a15;
    overflow: hidden;
    font-family: 'Rajdhani', 'Segoe UI', sans-serif;
    color: #ecf0f1;
    touch-action: none;
}

#gameCanvas {
    display: block;
    width: 100vw;
    height: 100vh;
}

/* ============ LOADING SCREEN ============ */
#loadingScreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: linear-gradient(135deg, #0a0a15 0%, #1a1a2e 50%, #16213e 100%);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 300;
}

#loadingScreen.hidden {
    display: none;
}

.loading-cube {
    width: 60px;
    height: 60px;
    margin-bottom: 40px;
    transform-style: preserve-3d;
    animation: cubeRotate 2s linear infinite;
}

.loading-cube .face {
    position: absolute;
    width: 60px;
    height: 60px;
    border: 2px solid rgba(52, 152, 219, 0.8);
    background: linear-gradient(135deg, rgba(52, 152, 219, 0.2), rgba(155, 89, 182, 0.2));
}

.loading-cube .front {
    transform: translateZ(30px);
}

.loading-cube .back {
    transform: rotateY(180deg) translateZ(30px);
}

.loading-cube .right {
    transform: rotateY(90deg) translateZ(30px);
}

.loading-cube .left {
    transform: rotateY(-90deg) translateZ(30px);
}

.loading-cube .top {
    transform: rotateX(90deg) translateZ(30px);
}

.loading-cube .bottom {
    transform: rotateX(-90deg) translateZ(30px);
}

@keyframes cubeRotate {
    0% {
        transform: rotateX(0deg) rotateY(0deg);
    }

    100% {
        transform: rotateX(360deg) rotateY(360deg);
    }
}

.loading-title {
    font-family: 'Orbitron', sans-serif;
    font-size: 36px;
    color: #3498db;
    margin-bottom: 30px;
    text-shadow: 0 0 20px rgba(52, 152, 219, 0.5);
}

.loading-bar-container {
    width: 300px;
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 15px;
}

#loadingProgress {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, #3498db, #9b59b6);
    border-radius: 4px;
    transition: width 0.3s ease;
}

#loadingText {
    font-size: 14px;
    color: #7f8c8d;
    text-transform: uppercase;
    letter-spacing: 2px;
}

/* ============ MAIN MENU ============ */
#mainMenu {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: linear-gradient(135deg, #0a0a15 0%, #1a1a2e 50%, #16213e 100%);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 200;
    opacity: 1;
    transition: opacity 0.5s ease, transform 0.5s ease;
}

#mainMenu.hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(1.1);
}

#mainMenu.fade-out {
    opacity: 0;
    transform: scale(0.95);
}

.menu-bg-animation {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    z-index: 0;
    perspective: 1000px;
    perspective-origin: 50% 50%;
}

/* 3D Grid Floor */
.grid-floor {
    position: absolute;
    width: 200%;
    height: 200%;
    left: -50%;
    top: 20%;
    background:
        linear-gradient(90deg, rgba(52, 152, 219, 0.15) 1px, transparent 1px),
        linear-gradient(rgba(52, 152, 219, 0.1) 1px, transparent 1px);
    background-size: 60px 60px;
    transform: rotateX(70deg);
    animation: gridScroll 15s linear infinite;
}

@keyframes gridScroll {
    0% {
        background-position: 0 0;
    }

    100% {
        background-position: 0 60px;
    }
}

/* 3D Cube */
.cube-3d {
    position: absolute;
    width: 50px;
    height: 50px;
    transform-style: preserve-3d;
}

.cube-3d .face {
    position: absolute;
    width: 100%;
    height: 100%;
    border: 1px solid rgba(52, 152, 219, 0.5);
    background: linear-gradient(135deg, rgba(52, 152, 219, 0.08), rgba(155, 89, 182, 0.08));
}

.cube-3d .front {
    transform: translateZ(25px);
}

.cube-3d .back {
    transform: rotateY(180deg) translateZ(25px);
}

.cube-3d .right {
    transform: rotateY(90deg) translateZ(25px);
}

.cube-3d .left {
    transform: rotateY(-90deg) translateZ(25px);
}

.cube-3d .top {
    transform: rotateX(90deg) translateZ(25px);
    background: rgba(52, 152, 219, 0.12);
}

.cube-3d .bottom {
    transform: rotateX(-90deg) translateZ(25px);
}

@keyframes spin3d {
    0% {
        transform: rotateX(0deg) rotateY(0deg);
    }

    100% {
        transform: rotateX(360deg) rotateY(360deg);
    }
}

@keyframes float3d {

    0%,
    100% {
        transform: translateY(0) rotateX(0deg) rotateY(0deg);
    }

    25% {
        transform: translateY(-30px) rotateX(90deg) rotateY(90deg);
    }

    50% {
        transform: translateY(0) rotateX(180deg) rotateY(180deg);
    }

    75% {
        transform: translateY(30px) rotateX(270deg) rotateY(270deg);
    }
}

@keyframes floatSlow {

    0%,
    100% {
        transform: translateY(0) rotateX(20deg) rotateY(0deg);
    }

    50% {
        transform: translateY(-40px) rotateX(200deg) rotateY(180deg);
    }
}

/* Glowing orbs */
.glow-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(60px);
    opacity: 0.4;
    animation: orbFloat 8s ease-in-out infinite;
}

@keyframes orbFloat {

    0%,
    100% {
        transform: translate(0, 0) scale(1);
        opacity: 0.3;
    }

    50% {
        transform: translate(20px, -20px) scale(1.2);
        opacity: 0.5;
    }
}

.menu-content {
    position: relative;
    z-index: 1;
    text-align: center;
    padding: 40px;
}

.game-title {
    font-family: 'Orbitron', sans-serif;
    font-size: 72px;
    font-weight: 900;
    background: linear-gradient(135deg, #3498db, #9b59b6, #e74c3c);
    background-size: 200% 200%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: gradientMove 3s ease infinite;
    text-shadow: 0 0 50px rgba(52, 152, 219, 0.3);
    margin-bottom: 10px;
    letter-spacing: 4px;
}

@keyframes gradientMove {

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

    50% {
        background-position: 100% 50%;
    }
}

.game-subtitle {
    font-size: 18px;
    color: #7f8c8d;
    letter-spacing: 8px;
    text-transform: uppercase;
    margin-bottom: 60px;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 50px;
}

.menu-btn {
    padding: 18px 60px;
    font-family: 'Rajdhani', sans-serif;
    font-size: 20px;
    font-weight: 700;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 2px;
    position: relative;
    overflow: hidden;
}

.menu-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

.menu-btn:hover::before {
    left: 100%;
}

#playBtn {
    background: linear-gradient(135deg, #2ecc71, #27ae60);
    color: white;
    box-shadow: 0 4px 20px rgba(46, 204, 113, 0.4);
}

#playBtn:hover {
    transform: scale(1.05) translateY(-2px);
    box-shadow: 0 8px 30px rgba(46, 204, 113, 0.6);
}

#howToPlayBtn {
    background: linear-gradient(135deg, #3498db, #2980b9);
    color: white;
    box-shadow: 0 4px 20px rgba(52, 152, 219, 0.4);
}

#howToPlayBtn:hover {
    transform: scale(1.05) translateY(-2px);
    box-shadow: 0 8px 30px rgba(52, 152, 219, 0.6);
}

.menu-settings {
    display: flex;
    gap: 20px;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
}

.setting-group {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.05);
    padding: 12px 20px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.setting-label {
    font-size: 14px;
    color: #95a5a6;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.setting-select {
    padding: 8px 15px;
    background: rgba(52, 152, 219, 0.2);
    border: 1px solid #3498db;
    border-radius: 6px;
    color: #ecf0f1;
    font-family: 'Rajdhani', sans-serif;
    font-size: 16px;
    cursor: pointer;
    outline: none;
}

.setting-select option {
    background: #1a1a2e;
    color: #ecf0f1;
    padding: 10px;
}

.setting-select:focus {
    box-shadow: 0 0 10px rgba(52, 152, 219, 0.5);
}

/* Seed Input Group */
.seed-group {
    gap: 8px;
}

.setting-input {
    padding: 8px 12px;
    background: rgba(52, 152, 219, 0.2);
    border: 1px solid #3498db;
    border-radius: 6px;
    color: #ecf0f1;
    font-family: 'Rajdhani', sans-serif;
    font-size: 16px;
    width: 100px;
    outline: none;
}

.setting-input::placeholder {
    color: #7f8c8d;
}

.setting-input:focus {
    box-shadow: 0 0 10px rgba(52, 152, 219, 0.5);
}

.seed-btn {
    padding: 8px 12px;
    background: linear-gradient(135deg, #f39c12, #e67e22);
    border: none;
    border-radius: 6px;
    color: white;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.seed-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 15px rgba(243, 156, 18, 0.5);
}

/* Volume Slider */
.volume-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: rgba(255, 255, 255, 0.05);
    padding: 12px 20px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    min-width: 180px;
}

.volume-label-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.volume-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: linear-gradient(135deg, #3498db, #9b59b6);
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.2s;
}

.volume-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.volume-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: linear-gradient(135deg, #3498db, #9b59b6);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.volume-value {
    font-size: 12px;
    color: #3498db;
    font-weight: 600;
}

.volume-group-vertical {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
}

.settings-content {
    margin: 20px 0;
}

#settingsBtn {
    background: linear-gradient(135deg, #9b59b6, #8e44ad);
    color: white;
    box-shadow: 0 4px 20px rgba(155, 89, 182, 0.4);
}

#settingsBtn:hover {
    transform: scale(1.05) translateY(-2px);
    box-shadow: 0 8px 30px rgba(155, 89, 182, 0.6);
}

/* How To Play Modal */
#howToPlayModal,
#settingsModal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 300;
    backdrop-filter: blur(10px);
}

#howToPlayModal.hidden,
#settingsModal.hidden {
    display: none;
}

.modal-content {
    background: linear-gradient(135deg, #1a1a2e, #16213e);
    padding: 40px;
    border-radius: 16px;
    max-width: 500px;
    text-align: center;
    border: 1px solid rgba(52, 152, 219, 0.3);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: modalPop 0.3s ease;
}

@keyframes modalPop {
    0% {
        transform: scale(0.8);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.modal-title {
    font-family: 'Orbitron', sans-serif;
    font-size: 28px;
    color: #3498db;
    margin-bottom: 25px;
}

.instructions {
    text-align: left;
    margin-bottom: 30px;
}

.instruction-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 12px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.instruction-icon {
    font-size: 28px;
    width: 50px;
    text-align: center;
}

.instruction-text {
    font-size: 16px;
    color: #bdc3c7;
}

.instruction-text strong {
    color: #ecf0f1;
}

#closeModalBtn,
#closeSettingsBtn {
    padding: 12px 40px;
    background: linear-gradient(135deg, #9b59b6, #8e44ad);
    border: none;
    border-radius: 8px;
    color: white;
    font-family: 'Rajdhani', sans-serif;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s;
}

#closeModalBtn:hover,
#closeSettingsBtn:hover {
    transform: scale(1.05);
    box-shadow: 0 5px 20px rgba(155, 89, 182, 0.5);
}

/* ============ GAME UI ============ */
#gameUI {
    display: none;
}

#gameUI.active {
    display: block;
}

.ui-overlay {
    position: fixed;
    pointer-events: none;
}

.ui-panel {
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    padding: 12px 16px;
    pointer-events: auto;
}

#topUI {
    top: 20px;
    left: 20px;
    display: flex;
    gap: 15px;
    align-items: center;
}

#timer {
    font-size: 28px;
    font-weight: bold;
    font-family: 'Orbitron', monospace;
    color: #3498db;
    text-shadow: 0 0 10px rgba(52, 152, 219, 0.5);
}

.seed-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.seed-label {
    font-size: 14px;
    color: #95a5a6;
}

#seedDisplay {
    font-family: 'Orbitron', monospace;
    font-size: 16px;
    color: #f39c12;
}

#seedInput {
    width: 100px;
    padding: 6px 10px;
    border: 1px solid #3498db;
    border-radius: 6px;
    background: rgba(52, 152, 219, 0.1);
    color: #ecf0f1;
    font-family: 'Orbitron', monospace;
    font-size: 14px;
    outline: none;
}

#seedInput:focus {
    border-color: #2980b9;
    box-shadow: 0 0 10px rgba(52, 152, 219, 0.3);
}

.game-btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    color: white;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

#restartBtn {
    background: linear-gradient(135deg, #3498db, #2980b9);
}

#menuBtn {
    background: linear-gradient(135deg, #9b59b6, #8e44ad);
}

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

#bottomUI {
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
}

.controls-hint {
    font-size: 12px;
    color: #7f8c8d;
    text-align: center;
}

/* ============ WIN OVERLAY ============ */
#winOverlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    backdrop-filter: blur(5px);
}

#winOverlay.hidden {
    display: none;
}

.win-content {
    text-align: center;
    animation: winPopup 0.5s ease-out;
}

@keyframes winPopup {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.win-title {
    font-family: 'Orbitron', sans-serif;
    font-size: 72px;
    font-weight: bold;
    background: linear-gradient(135deg, #2ecc71, #27ae60);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 20px;
    animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }
}

.win-time {
    font-size: 24px;
    color: #f39c12;
    margin-bottom: 30px;
}

.win-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
}

.win-btn {
    padding: 12px 30px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    pointer-events: auto;
}

#newGameBtn {
    background: linear-gradient(135deg, #2ecc71, #27ae60);
    color: white;
}

#playAgainBtn {
    background: linear-gradient(135deg, #3498db, #2980b9);
    color: white;
}

#backToMenuBtn {
    background: linear-gradient(135deg, #9b59b6, #8e44ad);
    color: white;
}

.win-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
}

/* Mobile */
@media (max-width: 768px) {
    .game-title {
        font-size: 36px;
        letter-spacing: 2px;
    }

    .game-subtitle {
        font-size: 12px;
        letter-spacing: 4px;
    }

    .menu-btn {
        padding: 15px 40px;
        font-size: 16px;
    }

    .setting-group {
        padding: 8px 12px;
    }

    #topUI {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .win-title {
        font-size: 48px;
    }

    #timer {
        font-size: 22px;
    }

    .modal-content {
        margin: 20px;
        padding: 25px;
    }
}