/* Premium UI Overhaul */
body, html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #05080f;
    font-family: 'Outfit', sans-serif;
    color: #f8fafc;
    user-select: none;
}

.screen {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: radial-gradient(circle at center, rgba(15, 23, 42, 0.9) 0%, rgba(5, 8, 15, 0.98) 100%);
    backdrop-filter: blur(12px);
    z-index: 100;
}

.title {
    font-size: 5rem;
    font-weight: 900;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 8px;
    background: linear-gradient(to bottom, #fff 30%, #eab308 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 0 15px rgba(234, 179, 8, 0.5));
}

.glow-text {
    text-shadow: 0 0 20px rgba(234, 179, 8, 0.4), 0 0 40px rgba(234, 179, 8, 0.2);
}

.subtitle {
    font-size: 1.6rem;
    color: #e5e7eb;
    margin-bottom: 2.5rem;
    letter-spacing: 4px;
    font-weight: 700;
    text-transform: uppercase;
}

.menu-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    width: min(600px, calc(100vw - 40px));
    margin: 20px 0 30px;
}

.menu-grid > div {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 15px;
    text-align: center;
    color: #f1f5f9;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    transition: all 0.3s ease;
}

.menu-grid > div:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(34, 211, 238, 0.4);
    transform: translateY(-2px);
}

.menu-grid span {
    display: block;
    color: #22d3ee;
    font-size: 1.5rem;
    font-weight: 900;
    margin-top: 5px;
}

.menu-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 16px;
}

.construction-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(3, 7, 18, 0.86);
    backdrop-filter: blur(8px);
    z-index: 220;
    pointer-events: all;
}

.construction-panel {
    width: min(520px, calc(100vw - 32px));
    padding: 28px;
    border: 1px solid rgba(34, 211, 238, 0.45);
    background: rgba(15, 23, 42, 0.92);
    box-shadow: 0 0 34px rgba(34, 211, 238, 0.16), 0 16px 60px rgba(0, 0, 0, 0.45);
}

.construction-title {
    font-size: 0.85rem;
    font-weight: 900;
    letter-spacing: 4px;
    color: #22d3ee;
    text-transform: uppercase;
}

.construction-label {
    margin-top: 8px;
    font-size: 2.2rem;
    line-height: 1.05;
    font-weight: 950;
    color: #ffffff;
    text-transform: uppercase;
    overflow-wrap: anywhere;
}

.construction-bar {
    width: 100%;
    height: 12px;
    margin-top: 22px;
    background: rgba(148, 163, 184, 0.18);
    border: 1px solid rgba(148, 163, 184, 0.28);
    overflow: hidden;
}

#construction-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #22d3ee, #eab308);
    transition: width 0.18s ease-out;
}

.construction-row {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    margin-top: 12px;
    color: #f1f5f9;
    font-size: 0.95rem;
    font-weight: 700;
}

#construction-detail {
    min-width: 0;
    overflow-wrap: anywhere;
}

/* UI Layer */
#ui-layer {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none;
    z-index: 10;
}

.top-bar {
    position: absolute;
    top: 0; left: 0; width: 100%;
    pointer-events: none;
    z-index: 20;
}

.stats {
    position: absolute;
    top: 25px; left: 40px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.stat {
    font-size: 2.2rem;
    font-weight: 950;
    letter-spacing: 1.5px;
    text-shadow: 0 2px 4px rgba(0,0,0,1.0), 0 0 15px rgba(0,0,0,0.5);
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.8));
}

.stat.hp { color: #f43f5e; }
.stat.vibe { color: #22d3ee; }
.stat.ticket { color: #eab308; }

.state-info {
    position: absolute;
    top: 25px; right: 40px;
    text-align: right;
}

.state-info h2 {
    margin: 0;
    font-size: 1.4rem;
    font-weight: 900;
    color: #a78bfa;
    text-shadow: 0 0 20px rgba(167, 139, 250, 0.6), 0 2px 4px #000;
    text-transform: uppercase;
    letter-spacing: 3px;
}

/* Rhythm Metronome */
#rhythm-metronome {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none;
}

.metronome-border {
    position: absolute;
    inset: 0;
    border: 0px solid rgba(234, 179, 8, 0);
    transition: border-width 0.05s ease-out, border-color 0.1s ease-out;
}

.beat-active-border {
    border-width: 12px;
    border-color: rgba(234, 179, 8, 0.3);
}

#beat-indicator {
    position: absolute;
    bottom: 50px;
    left: 50%;
    transform: translateX(-50%);
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 0 15px rgba(0,0,0,0.4);
    transition: all 0.1s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.beat-active {
    background: #eab308 !important;
    transform: translateX(-50%) scale(1.6) !important;
    border-color: #fff !important;
    box-shadow: 0 0 30px #eab308, 0 0 60px rgba(234, 179, 8, 0.4) !important;
}

#combat-feedback {
    position: absolute;
    top: 25%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 4rem;
    font-weight: 900;
    color: #4ade80;
    text-shadow: 0 0 30px #16a34a, 0 0 60px rgba(22, 163, 74, 0.4);
    opacity: 0;
    pointer-events: none;
    text-transform: uppercase;
    font-style: italic;
}

@keyframes flyUpFade {
    0% { opacity: 0; transform: translate(-50%, -10%) scale(0.8); }
    15% { opacity: 1; transform: translate(-50%, -40%) scale(1.0); }
    85% { opacity: 1; transform: translate(-50%, -60%) scale(1.0); }
    100% { opacity: 0; transform: translate(-50%, -100%) scale(1.1); }
}

.feedback-anim {
    animation: flyUpFade 1.2s cubic-bezier(0.1, 0.9, 0.2, 1) forwards;
}

/* Protect DJ */
#dj-hp-container {
    position: absolute;
    top: 90px;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    background: rgba(0,0,0,0.4);
    padding: 15px 30px;
    border-radius: 20px;
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

#dj-name {
    margin: 0 0 10px 0;
    font-weight: 900;
    color: #fca5a5;
    letter-spacing: 3px;
    text-transform: uppercase;
    font-size: 0.9rem;
}

.dj-hp-bar-bg {
    width: 320px;
    height: 10px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 5px;
    overflow: hidden;
    position: relative;
}

#dj-hp-bar {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #f43f5e, #ef4444);
    box-shadow: 0 0 15px rgba(239, 68, 68, 0.6);
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#survive-timer {
    font-size: 2.5rem;
    font-weight: 900;
    color: #fff;
    margin-top: 12px;
    text-shadow: 0 0 20px rgba(255,255,255,0.4);
    font-variant-numeric: tabular-nums;
}

/* Glass Panels */
.glass-panel {
    background: rgba(5, 8, 15, 0.92);
    backdrop-filter: blur(24px);
    border: 2px solid rgba(255, 255, 255, 0.2);
    padding: 40px;
    border-radius: 24px;
    box-shadow: 0 30px 60px -12px rgba(0, 0, 0, 0.9), 0 0 50px rgba(34, 211, 238, 0.2);
    text-align: center;
    pointer-events: auto; /* Ensure we can click buttons */
    color: #f8fafc;
}

.glass-panel h1,
.glass-panel h2,
.glass-panel h3,
.glass-panel p,
.glass-panel label,
.modal-content,
.upgrade-options {
    color: #f8fafc;
}

#interaction-text {
    position: absolute;
    bottom: 120px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(45deg, #7c3aed, #db2777);
    padding: 12px 28px;
    border-radius: 12px;
    font-weight: 900;
    color: #fff;
    box-shadow: 0 5px 15px rgba(0,0,0,0.5);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: translateX(-50%) scale(1); opacity: 0.9; }
    50% { transform: translateX(-50%) scale(1.05); opacity: 1; }
    100% { transform: translateX(-50%) scale(1); opacity: 0.9; }
}

/* Buttons */
.btn-main {
    background: linear-gradient(135deg, #7c3aed 0%, #db2777 100%);
    border: none;
    padding: 18px 45px;
    color: white;
    font-family: inherit;
    font-size: 1.4rem;
    font-weight: 900;
    border-radius: 12px;
    cursor: pointer;
    box-shadow: 0 8px 25px rgba(219, 39, 119, 0.4);
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    text-transform: uppercase;
    letter-spacing: 2px;
}

.btn-main:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 12px 30px rgba(219, 39, 119, 0.6);
}

.btn-main:active {
    transform: translateY(0) scale(0.98);
}

.btn-upgrade {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 12px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 18px;
    text-align: left;
    transition: all 0.2s ease;
    color: #f8fafc;
    font-family: inherit;
    font-weight: 800;
}

.btn-upgrade:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: #22d3ee;
    transform: translateX(5px);
}

.btn-upgrade small {
    color: #e5e7eb;
    font-size: 0.8rem;
    text-transform: none;
}

.btn-close {
    background: transparent;
    border: 2px solid rgba(255, 255, 255, 0.2);
    margin-top: 20px;
    font-size: 1rem;
    padding: 12px 30px;
    color: #f8fafc;
    font-family: inherit;
    font-weight: 800;
}

.btn-close:hover {
    border-color: #fff;
    background: rgba(255, 255, 255, 0.1);
}

/* Modals */
.modal {
    position: absolute;
    inset: 0;
    background: rgba(5, 8, 15, 0.8);
    backdrop-filter: blur(10px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 150;
}

.setting-row {
    margin: 20px 0;
    color: #f8fafc;
}

input[type=range] {
    accent-color: #22d3ee;
    width: 240px;
}

/* Mobile Controls */
#mobile-controls {
    position: fixed;
    inset: auto 0 0 0;
    height: min(42vh, 340px);
    pointer-events: none;
    z-index: 60;
}

#joystick-zone {
    position: absolute;
    left: max(16px, env(safe-area-inset-left));
    bottom: max(18px, env(safe-area-inset-bottom));
    width: 138px;
    height: 138px;
    border-radius: 50%;
    background: rgba(15, 23, 42, 0.46);
    border: 2px dashed rgba(255, 255, 255, 0.28);
    pointer-events: auto;
    box-shadow: inset 0 0 22px rgba(34, 211, 238, 0.12), 0 10px 28px rgba(0,0,0,0.45);
}

#joystick-knob {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 54px;
    height: 54px;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    background: rgba(34, 211, 238, 0.72);
    pointer-events: none;
}

.touch-btn {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 90px;
    height: 90px;
    border-radius: 50%;
    background: rgba(234, 179, 8, 0.1);
    border: 2px solid rgba(234, 179, 8, 0.3);
    backdrop-filter: blur(4px);
    transition: transform 0.1s;
    color: #f8fafc;
    font-weight: 900;
    font-size: 0.95rem;
    pointer-events: auto;
    user-select: none;
    box-shadow: 0 12px 30px rgba(0,0,0,0.38);
}

#btn-shoot {
    right: max(18px, env(safe-area-inset-right));
    bottom: max(18px, env(safe-area-inset-bottom));
}

#btn-point {
    right: max(108px, calc(env(safe-area-inset-right) + 108px));
    bottom: max(30px, calc(env(safe-area-inset-bottom) + 30px));
}

.touch-btn:active {
    transform: scale(0.9);
    background: rgba(234, 179, 8, 0.3);
}

.point-btn {
    background: rgba(34, 211, 238, 0.1);
    border-color: rgba(34, 211, 238, 0.3);
    color: #f8fafc;
}

@media (max-width: 700px), (max-height: 760px) {
    .title {
        font-size: 2.8rem;
        letter-spacing: 3px;
        text-align: center;
    }

    .subtitle {
        font-size: 1rem;
        letter-spacing: 2px;
        margin-bottom: 1rem;
    }

    .menu-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 6px;
        width: calc(100vw - 22px);
        margin: 10px 0 14px;
    }

    .menu-grid > div {
        padding: 8px 5px;
        border-radius: 8px;
        font-size: 0.68rem;
        letter-spacing: 0.3px;
    }

    .menu-grid span {
        font-size: 1rem;
        margin-top: 2px;
    }

    .menu-actions {
        gap: 8px;
    }

    .btn-main {
        padding: 12px 18px;
        font-size: 0.95rem;
        letter-spacing: 0.8px;
        border-radius: 9px;
    }

    .stats {
        top: max(8px, env(safe-area-inset-top));
        left: max(10px, env(safe-area-inset-left));
        gap: 3px;
    }

    .stat {
        font-size: 1.15rem;
        letter-spacing: 0.4px;
    }

    .state-info {
        top: max(8px, env(safe-area-inset-top));
        right: max(10px, env(safe-area-inset-right));
        max-width: 48vw;
    }

    .state-info h2 {
        font-size: 0.78rem;
        letter-spacing: 1px;
        overflow-wrap: anywhere;
    }

    #dj-hp-container {
        top: max(54px, calc(env(safe-area-inset-top) + 44px));
        padding: 8px 12px;
        border-radius: 12px;
    }

    #dj-name {
        font-size: 0.7rem;
        letter-spacing: 1px;
        margin-bottom: 5px;
    }

    .dj-hp-bar-bg {
        width: min(250px, calc(100vw - 48px));
    }

    #survive-timer {
        font-size: 1.45rem;
        margin-top: 6px;
    }

    #truck-progress-container {
        top: max(56px, calc(env(safe-area-inset-top) + 48px)) !important;
        width: min(270px, calc(100vw - 44px)) !important;
    }

    #combat-feedback {
        font-size: 2.1rem;
        width: 90vw;
        text-align: center;
    }

    #interaction-text {
        bottom: calc(max(18px, env(safe-area-inset-bottom)) + 145px);
        padding: 9px 14px;
        font-size: 0.8rem;
        max-width: calc(100vw - 40px);
        white-space: normal;
        text-align: center;
    }

    .glass-panel {
        width: calc(100vw - 28px);
        max-height: calc(100vh - 34px);
        overflow-y: auto;
        padding: 18px;
        border-radius: 14px;
        box-sizing: border-box;
    }

    .glass-panel h2 {
        margin: 0 0 10px;
        font-size: 1.3rem;
    }

    .btn-upgrade {
        padding: 10px;
        margin-bottom: 8px;
        border-radius: 8px;
        font-size: 0.82rem;
        line-height: 1.15;
    }

    .btn-upgrade small {
        font-size: 0.68rem;
    }

    .construction-panel {
        padding: 18px;
    }

    .construction-label {
        font-size: 1.45rem;
    }
}

@media (orientation: portrait) and (max-width: 520px) {
    #mobile-controls {
        height: 245px;
    }

    #joystick-zone {
        width: 118px;
        height: 118px;
        left: max(12px, env(safe-area-inset-left));
        bottom: max(14px, env(safe-area-inset-bottom));
    }

    #joystick-knob {
        width: 46px;
        height: 46px;
    }

    .touch-btn {
        width: 68px;
        height: 68px;
        font-size: 0.72rem;
    }

    #btn-shoot {
        right: max(14px, env(safe-area-inset-right));
        bottom: max(16px, env(safe-area-inset-bottom));
    }

    #btn-point {
        right: max(84px, calc(env(safe-area-inset-right) + 84px));
        bottom: max(24px, calc(env(safe-area-inset-bottom) + 24px));
    }

    #beat-indicator {
        bottom: calc(max(12px, env(safe-area-inset-bottom)) + 106px);
        width: 18px;
        height: 18px;
    }
}
