*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #000;
    font-family: 'Courier New', Courier, monospace;
    color: #fff;
    overscroll-behavior: none;
    -webkit-font-smoothing: antialiased;
}

#canvas-container {
    width: 100vw;
    height: 100vh;
    display: none;
}

/* --- APP BORDER GLOW --- */
#app-border {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5000;
    box-shadow: inset 0 0 40px rgba(136, 0, 255, 0.15);
    /* Persistent subtle purple glow */
    border: 1px solid rgba(255, 255, 255, 0.03);
    transition: box-shadow 0.3s ease;
}

#app-border.flash {
    animation: borderFlashEffect 0.6s ease-out;
}

@keyframes borderFlashEffect {
    0% {
        box-shadow: inset 0 0 80px rgba(255, 255, 255, 0.5);
        border-color: rgba(255, 255, 255, 0.4);
    }

    100% {
        box-shadow: inset 0 0 40px rgba(136, 0, 255, 0.15);
        border-color: rgba(255, 255, 255, 0.03);
    }
}

/* --- PASSWORD GATE --- */
#password-gate {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    border-bottom: 2px solid #333;
    padding-bottom: 5px;
    transition: border-color 0.4s ease;
}

#password-gate input {
    background: transparent;
    border: none;
    color: #fff;
    font-family: 'Courier New', monospace;
    font-size: 2rem;
    text-align: center;
    width: 180px;
    outline: none;
    letter-spacing: 10px;
    caret-color: #fff;
}

#password-gate input:placeholder-shown {
    caret-color: transparent;
}

#unlock-btn {
    background: none;
    border: none;
    color: #333;
    font-size: 2rem;
    cursor: pointer;
    padding: 0 10px;
    transition: all 0.3s ease;
}

#unlock-btn:hover {
    color: #fff;
    transform: translateX(5px);
}

#password-gate p {
    letter-spacing: 4px;
    color: #444;
    font-size: 0.8rem;
    text-transform: uppercase;
    margin-bottom: 30px;
}

/* --- LOADER --- */
#loader-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    transition: opacity 0.8s ease;
}

.loading-text {
    letter-spacing: 8px;
    margin-bottom: 20px;
    font-size: 0.8rem;
    color: #666;
}

.progress-container {
    width: 300px;
    height: 2px;
    background: #1a1a1a;
    position: relative;
    overflow: hidden;
}

#progress-bar {
    width: 0%;
    height: 100%;
    background: #fff;
    transition: width 0.1s linear;
    box-shadow: 0 0 10px #fff;
}

.loader-shortcuts {
    position: absolute;
    bottom: 40px;
    font-size: 0.65rem;
    color: #444;
    letter-spacing: 2px;
    text-transform: uppercase;
    text-align: center;
    width: 100%;
    font-family: 'Courier New', Courier, monospace;
}

/* --- RIGHT PANEL --- */
#info-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 40%;
    height: 100%;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10;
    pointer-events: none;
    transition: transform 0.6s cubic-bezier(0.23, 1, 0.32, 1);
}

#info-panel.panel-hidden {
    transform: translateX(110%);
}

.panel-card {
    width: 75%;
    max-height: 80%;
    padding: 40px;
    border-radius: 20px;
    background: #0a0a0a;
    border: 1px solid #1a1a1a;
    box-shadow: 20px 20px 40px #000;
    pointer-events: all;
    overflow-y: hidden;
    /* Hide overflow to prevent scrollbar during animation */
}

#info-panel h2 {
    font-size: 1.1rem;
    letter-spacing: 4px;
    border-bottom: 1px solid #222;
    padding-bottom: 15px;
    margin-bottom: 20px;
    text-transform: uppercase;
}

/* --- TRACKLIST GLOW --- */
.track-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.track-item {
    padding: 12px 10px;
    border-bottom: 1px solid #111;
    color: #444;
    font-size: 0.85rem;
    display: flex;
    justify-content: space-between;
    cursor: pointer;
    transition: all 0.4s ease;
}

.track-item:hover {
    color: #888;
    background: #0f0f0f;
}

.track-item.active {
    color: #fff !important;
    text-shadow: 0 0 10px #fff, 0 0 20px rgba(255, 255, 255, 0.2);
    background: #111;
}

.track-item.active span {
    color: #fff !important;
}

.track-item span {
    color: #222;
    transition: color 0.4s ease;
}

#panel-content {
    line-height: 1.8;
    color: #aaa;
    font-size: 0.95rem;
    position: relative;
    will-change: transform, opacity;
}

#panel-content p {
    margin-bottom: 15px;
}

.back-btn {
    margin-top: 25px;
    font-size: 0.7rem;
    color: #444;
    cursor: pointer;
    text-decoration: underline;
    display: inline-block;
}

.back-btn:hover {
    color: #fff;
}

/* --- ANIMATIONS --- */
@keyframes slideUpOut {
    0% {
        transform: translateY(0);
        opacity: 1;
    }

    100% {
        transform: translateY(-30px);
        opacity: 0;
    }
}

@keyframes slideUpIn {
    0% {
        transform: translateY(30px);
        opacity: 0;
    }

    100% {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes slideDownOut {
    0% {
        transform: translateY(0);
        opacity: 1;
    }

    100% {
        transform: translateY(30px);
        opacity: 0;
    }
}

@keyframes slideDownIn {
    0% {
        transform: translateY(-30px);
        opacity: 0;
    }

    100% {
        transform: translateY(0);
        opacity: 1;
    }
}

.animate-up-out {
    animation: slideUpOut 0.1s forwards ease-in;
}

.animate-up-in {
    animation: slideUpIn 0.1s forwards ease-out;
}

.animate-down-out {
    animation: slideDownOut 0.1s forwards ease-in;
}

.animate-down-in {
    animation: slideDownIn 0.1s forwards ease-out;
}

/* --- SHORTCUTS MODAL --- */
#shortcuts-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 400px;
    background: rgba(10, 10, 10, 0.95);
    border: 1px solid #333;
    padding: 30px;
    z-index: 3000;
    display: none;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.8), 0 0 20px rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(10px);
    border-radius: 10px;
}

#shortcuts-modal h3 {
    font-size: 0.9rem;
    letter-spacing: 4px;
    border-bottom: 1px solid #222;
    padding-bottom: 15px;
    margin-bottom: 20px;
    margin-top: 0;
    text-transform: uppercase;
    color: #fff;
    text-align: center;
}

.shortcuts-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.shortcut-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid #111;
    font-size: 0.75rem;
    color: #888;
    letter-spacing: 1px;
}

.shortcut-key {
    color: #fff;
    text-transform: uppercase;
}

#shortcuts-modal-close {
    margin-top: 25px;
    text-align: center;
    font-size: 0.7rem;
    color: #444;
    cursor: pointer;
    text-decoration: underline;
    display: block;
}

#shortcuts-modal-close:hover {
    color: #fff;
}

/* --- GAME UI --- */
#game-ui {
    position: fixed;
    top: 20px;
    right: 30px;
    z-index: 1500;
    pointer-events: none;
    font-family: 'Courier New', Courier, monospace;
    text-align: right;
    display: none;
    /* Hidden until loaded */
}

#score-label {
    font-size: 0.8rem;
    color: #888;
    letter-spacing: 2px;
    text-transform: uppercase;
}

#score-display {
    font-size: 2.5rem;
    color: #fff;
    font-weight: bold;
    text-shadow: 0 0 10px #8800ff, 0 0 20px rgba(136, 0, 255, 0.4);
    transition: transform 0.1s ease;
}

.score-bump {
    transform: scale(1.2);
    color: #ff00ff !important;
}

.score-penalty {
    transform: scale(0.9);
    color: #ff0000 !important;
}

#game-message {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -40%);
    color: #00ff66;
    font-size: 3rem;
    font-family: 'Courier New', Courier, monospace;
    font-weight: bold;
    letter-spacing: 8px;
    z-index: 2000;
    pointer-events: none;
    text-shadow: 0 0 20px rgba(0, 255, 102, 0.8),
        0 0 40px rgba(0, 255, 102, 0.4);
    opacity: 0;
    visibility: hidden;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    text-transform: uppercase;
    background: rgba(0, 0, 0, 0.5);
    padding: 20px 40px;
    border-radius: 4px;
    backdrop-filter: blur(5px);
    border: 1px solid rgba(0, 255, 102, 0.2);
}

#game-message.visible {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%);
    animation: message-pulse 2s infinite ease-in-out;
}

#close-detail-btn:hover {
    transform: scale(1.1);
    box-shadow: inset 0 0 10px rgba(136, 0, 255, 0.6), 0 0 20px rgba(255, 255, 255, 0.4);
}

/* --- PORTRAIT NOTICE --- */
#portrait-notice {
    position: fixed;
    bottom: 20%;
    left: 50%;
    transform: translateX(-50%);
    display: none;
    color: rgba(255, 255, 255, 0.4);
    font-size: 0.65rem;
    letter-spacing: 4px;
    text-transform: uppercase;
    z-index: 5000;
    text-align: center;
    pointer-events: none;
    width: 90%;
}

@keyframes rotate-warning {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(90deg);
    }
}

@keyframes message-pulse {

    0%,
    100% {
        text-shadow: 0 0 20px rgba(0, 255, 102, 0.8), 0 0 40px rgba(0, 255, 102, 0.4);
        border-color: rgba(0, 255, 102, 0.2);
    }

    50% {
        text-shadow: 0 0 35px rgba(0, 255, 102, 1), 0 0 60px rgba(0, 255, 102, 0.6);
        border-color: rgba(0, 255, 102, 0.5);
        transform: translate(-50%, -50%) scale(1.02);
    }
}

/* --- MOBILE BACK BUTTON (HIDDEN BY DEFAULT) --- */
#mobile-back-btn {
    display: none;
}

/* --- MOBILE LAYOUT (PORTRAIT) --- */
@media screen and (max-width: 768px) {

    /* 1. Prevent all accidental scrolling/wiggle */
    html,
    body {
        position: fixed;
        width: 100%;
        height: 100%;
        overflow: hidden;
        touch-action: none;
        -webkit-overflow-scrolling: none;
        overscroll-behavior: none;
    }

    #app-border {
        display: none !important;
    }

    #canvas-container {
        position: fixed;
        width: 100%;
        height: 100%;
        top: 0;
        left: 0;
        overflow: hidden;
        display: block;
        /* Ensure it doesn't cause late-layout shifts */
    }

    /* 2. PREMIUM MOBILE LOADER REWORK - FIT FIX */
    #loader-screen {
        padding: 0;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        background: #000;
        width: 100%;
        height: 100%;
        position: fixed;
        top: 0;
        left: 0;
        overflow: hidden;
    }

    #loader-screen::before {
        content: "";
        position: absolute;
        width: 100%;
        height: 100%;
        background: repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.02) 0px, transparent 1px);
        background-size: 100% 3px;
        pointer-events: none;
        animation: scanline 15s linear infinite;
    }

    @keyframes scanline {
        from {
            transform: translateY(0);
        }

        to {
            transform: translateY(-100px);
        }
    }

    .loading-text {
        font-size: 0;
        /* Hide original text */
        font-family: 'Courier New', monospace;
        letter-spacing: 0;
        /* Clear inherited spacing to prevent pushing content off-screen */
        color: #fff;
        text-transform: uppercase;
        margin-bottom: 30px;
        opacity: 0.7;
        text-shadow: 0 0 8px rgba(255, 255, 255, 0.3);
        display: block;
        text-align: center;
        width: 100%;
        padding: 0;
        text-indent: 12px;
        /* Offset the trailing space for perfect horizontal centering */
    }

    .loading-text::after {
        content: "LOADING";
        font-size: 11px;
        letter-spacing: 12px;
        display: inline-block;
    }

    .progress-container {
        width: 40%;
        /* Narrower for cleaner look */
        height: 1px;
        background: rgba(255, 255, 255, 0.1);
        position: relative;
    }

    #progress-bar {
        background: #fff;
        box-shadow: 0 0 15px #fff;
        height: 100%;
        transition: width 0.1s linear;
    }

    /* Decorative corner elements for sci-fi feel */
    #loader-screen::after {
        content: "EST. 2025 // ARCHIVE_v2.6";
        position: absolute;
        bottom: env(safe-area-inset-bottom, 40px);
        font-size: 7px;
        letter-spacing: 2px;
        color: #333;
        font-family: 'Courier New', monospace;
    }

    .loader-shortcuts {
        display: none !important;
    }

    /* 3. Allow access in portrait */
    #portrait-notice {
        display: none !important;
    }

    #app-border {
        display: none;
    }

    /* 4. Dynamic Info Panel Sheet */
    #info-panel {
        top: auto;
        bottom: 0px;
        left: 0;
        width: 100%;
        height: auto;
        max-height: 50vh;
        z-index: 4000;
        align-items: flex-end;
        justify-content: center;
        transform: translateY(100%);
        visibility: hidden;
        /* Hide to prevent vertical overflow/wiggle */
        transition: transform 0.6s cubic-bezier(0.16, 1, 0.3, 1), visibility 0s 0.6s;
        padding-bottom: 20px;
    }

    /* Active state: slid up */
    #info-panel.mobile-active {
        transform: translateY(0%);
        visibility: visible;
        transition: transform 0.6s cubic-bezier(0.16, 1, 0.3, 1), visibility 0s 0s;
    }

    #info-panel.panel-hidden {
        transform: translateY(110%);
        visibility: hidden;
    }

    .panel-card {
        width: 90%;
        height: auto;
        max-height: 45vh;
        border-radius: 20px 20px 0 0;
        border-bottom: none;
        padding: 25px;
        box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.8);
        background: rgba(10, 10, 10, 0.95);
        backdrop-filter: blur(10px);
        overflow-y: auto;
        /* Allow internal scrolling */
        -webkit-overflow-scrolling: touch;

        /* Hide Scrollbar */
        -ms-overflow-style: none;
        /* IE/Edge */
        scrollbar-width: none;
        /* Firefox */
    }

    .panel-card::-webkit-scrollbar {
        display: none;
        /* Chrome, Safari, Edge */
    }

    /* Grab handle visual */
    .panel-card::before {
        content: '';
        display: block;
        width: 40px;
        height: 4px;
        background: rgba(255, 255, 255, 0.2);
        margin: 0 auto 15px auto;
        border-radius: 2px;
    }

    /* Hide keyboard shortcuts and close button on mobile sheet */
    #track-description,
    #close-detail-btn {
        display: none !important;
    }

    #panel-title {
        font-size: 0.9rem;
        text-align: center;
        margin-bottom: 10px;
        padding-bottom: 10px;
    }

    /* Game UI adjustments */
    #game-ui {
        top: 20px;
        right: 20px;
        transform: scale(0.8);
        transform-origin: top right;
    }

    #mobile-back-btn {
        display: none;
        position: fixed;
        top: 30px;
        left: 30px;
        width: 44px;
        height: 44px;
        background: rgba(15, 15, 15, 0.6);
        backdrop-filter: blur(10px);
        border: 1px solid rgba(255, 255, 255, 0.1);
        border-radius: 50%;
        color: #fff;
        z-index: 5001;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        opacity: 0;
        transition: opacity 0.4s ease, transform 0.3s ease;
        transform: scale(0.8);
        pointer-events: all;
    }

    #mobile-back-btn.visible {
        display: flex;
        opacity: 1;
        transform: scale(1);
    }

    #mobile-back-btn svg {
        width: 24px;
        height: 24px;
        opacity: 0.8;
    }

}