:root {
    --bg-color: #050510;
    --lane-color: rgba(255, 255, 255, 0.03);
    --lane-border: rgba(255, 255, 255, 0.1);
    --neon-blue: #00f3ff;
    --neon-pink: #ff00ff;
    --neon-green: #00ff9d;
    --neon-yellow: #ffea00;
    --text-color: #ffffff;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
}

#game-window-wrapper {
    position: relative;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    display: flex;
    justify-content: center;
}

#video-background {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: 100%;
    z-index: -1;
    pointer-events: none;
    opacity: 1;
    /* Changed from 0.8 for visibility */
}

/* Force iframe to cover */
#video-background iframe {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100vw;
    height: 56.25vw;
    /* 16:9 aspect ratio (9/16 = 0.5625) */
    min-height: 100vh;
    min-width: 177.78vh;
    /* 16/9 * 100vh = 1.7778 */
    transform: translate(-50%, -50%);
    pointer-events: none;
}

@media (min-aspect-ratio: 16/9) {

    /* Screen is wider than 16:9 */
    #video-background iframe {
        width: 100vw;
        height: 56.25vw;
    }
}

#lane-backdrop {
    position: absolute;
    top: 0;
    height: 100%;
    height: 100%;
    /* background: rgba(0, 0, 0, 0.4); Removed to prevent sharp frame */
    backdrop-filter: blur(8px);
    /* Blur the video behind */
    -webkit-backdrop-filter: blur(8px);
    z-index: 0;
    /* Above video (-1 or 0?), Canvas is 1 */
    pointer-events: none;
}

@media (max-aspect-ratio: 16/9) {

    /* Screen is taller/narrower than 16:9 */
    #video-background iframe {
        width: 177.78vh;
        height: 100vh;
    }
}

#visualizer-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 20;
    pointer-events: none;
    mix-blend-mode: screen;
    /* Adapt colors */
}

body {
    background-color: var(--bg-color);
    font-family: 'Outfit', sans-serif;
    color: var(--text-color);
    overflow: hidden;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

#game-container {
    position: relative;
    width: 600px;
    height: 100vh;
    /* Gradient: Black (top) -> Silver (bottom) */
    /* Gradient: Black (top) -> Silver (bottom) - MORE TRANSPARENT */
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.8) 0%, rgba(30, 30, 30, 0.9) 100%);
    box-shadow: 0 0 20px rgba(0, 243, 255, 0.1);
    border-left: 1px solid var(--lane-border);
    border-right: 1px solid var(--lane-border);
}

#game-canvas {
    display: block;
    width: 100%;
    height: 100%;
    z-index: 1;
}

#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

/* UI Elements */
#progress-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px; /* Tiny */
    background: rgba(255, 255, 255, 0.1);
    z-index: 20;
}

#progress-bar {
    width: 0%;
    height: 100%;
    background: var(--neon-blue);
    box-shadow: 0 0 10px var(--neon-blue);
    transition: width 0.1s linear;
}

#score-board {
    position: absolute;
    top: 20px;
    left: 20px;
    text-align: left;
}

.score-label {
    font-size: 14px;
    opacity: 0.7;
    letter-spacing: 2px;
}

#score-value {
    font-size: 32px;
    font-weight: 900;
    text-shadow: 0 0 10px var(--neon-blue);
}

#combo-board {
    position: absolute;
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    opacity: 0;
    /* Hidden by default, shown when combo > 0 */
    transition: opacity 0.2s, transform 0.1s;
}

#combo-board.active {
    opacity: 1;
}

#combo-value {
    font-size: 64px;
    font-weight: 900;
    color: var(--neon-yellow);
    text-shadow: 0 0 20px rgba(255, 234, 0, 0.5);
    line-height: 1;
}

.combo-label {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 4px;

    color: #fff;
}

#judgment-display {
    position: absolute;
    top: 60%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    font-size: 48px;
    font-weight: 900;
    opacity: 0;
    pointer-events: none;
    z-index: 5;
}

.judge-perfect-plus {
    color: var(--neon-blue);
    text-shadow: 0 0 20px var(--neon-blue);
    animation: popFade 0.5s ease-out forwards;
}

.judge-perfect {
    color: var(--neon-green);
    text-shadow: 0 0 20px var(--neon-green);
    animation: popFade 0.5s ease-out forwards;
}

.judge-great {
    color: var(--neon-yellow);
    text-shadow: 0 0 20px var(--neon-yellow);
    animation: popFade 0.5s ease-out forwards;
}

.judge-miss {
    color: #ff3333;
    animation: fadeOut 0.5s ease-out forwards;
}

@keyframes popFade {
    0% {
        transform: translate(-50%, -50%) scale(0.8);
        opacity: 0;
    }

    20% {
        transform: translate(-50%, -50%) scale(1.2);
        opacity: 1;
    }

    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0;
    }
}

@keyframes fadeOut {
    0% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }

    100% {
        opacity: 0;
        transform: translate(-50%, -40%) scale(0.9);
    }
}


/* Overlays */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(5px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 10;
    pointer-events: auto;
    transition: opacity 0.5s;
}

.shake {
    animation: shake 0.2s cubic-bezier(.36, .07, .19, .97) both;
}

@keyframes shake {

    10%,
    90% {
        transform: translate3d(-1px, 0, 0);
    }

    20%,
    80% {
        transform: translate3d(2px, 0, 0);
    }

    30%,
    50%,
    70% {
        transform: translate3d(-4px, 0, 0);
    }

    40%,
    60% {
        transform: translate3d(4px, 0, 0);
    }
}

.overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.logo-img {
    display: block;
    margin: 0 auto 20px auto;
    max-width: 70%;
    height: auto;
    filter: drop-shadow(0 0 20px rgba(0, 243, 255, 0.4));
    animation: floatLogo 3s ease-in-out infinite;
}

@keyframes floatLogo {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

input[type="file"] {
    margin: 20px 0;
    padding: 10px;
    border: 1px solid var(--lane-border);
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.05);
    color: white;
}

.glow-btn {
    padding: 15px 40px;
    font-size: 24px;
    font-weight: 700;
    color: white;
    background: transparent;
    border: 2px solid var(--neon-pink);
    border-radius: 50px;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 2px;
    box-shadow: 0 0 15px rgba(255, 0, 255, 0.2);
    transition: all 0.3s;
}

.glow-btn:hover {
    background: var(--neon-pink);
    box-shadow: 0 0 30px rgba(255, 0, 255, 0.6);
    transform: scale(1.05);
}

.glow-btn.hidden {
    display: none;
}

#countdown-number {
    font-size: 150px;
    font-weight: 900;
    color: white;
    text-shadow: 0 0 50px white;
    animation: pulse 1s infinite alternate;
}

@keyframes pulse {
    from {
        transform: scale(1);
        opacity: 1;
    }

    to {
        transform: scale(1.1);
        opacity: 0.8;
    }
}

/* Controls Hint (Visual only) */
#controls-hint {
    position: absolute;
    /* Top set dynamically in JS */
    left: 0;
    width: 100%;
    transform: translateY(-50%);
    display: flex;
    justify-content: space-around;
    padding: 0 20px;
    pointer-events: none;
    z-index: 50;
    /* Ensure on top of canvas (z-index 1) and hit bar */
}

.key-hint {
    width: 40px;
    height: 40px;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.9);
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}

/* Hide hints on Mobile */
@media (hover: none) and (pointer: coarse) {
    #controls-hint {
        display: none;
    }
}

/* Song Selection */
#start-screen {
    justify-content: flex-start;
    padding-top: 80px;
}

#song-selection {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin: 30px 0;

    /* Use available height but leave room for logo/controls */
    height: 60vh;
    max-height: 70vh;

    overflow-y: auto;
    width: 100%;
    align-items: center;
    padding: 20px;
    /* Scrollbar styling */
    scrollbar-width: thin;
    scrollbar-color: var(--neon-blue) transparent;
}

#song-selection::-webkit-scrollbar {
    width: 6px;
}

#song-selection::-webkit-scrollbar-thumb {
    background-color: var(--neon-blue);
    border-radius: 3px;
}

/* Ensure list is scrollable and doesn't squeeze items */
#song-selection {
    flex-wrap: nowrap;
    /* Ensure they stack */
}

.song-card {
    background: #111;
    background-size: cover;
    background-position: center;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    padding: 0;
    /* Reset padding, layout handled internally */
    width: 340px;
    /* Slightly wider for better 16:9 feel */
    aspect-ratio: 16 / 9;
    height: auto;
    /* Let aspect ratio drive height */

    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);

    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: flex-start;
    position: relative;
    overflow: hidden;

    /* No shadow here, handled by gradient overlay */
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);

    /* VITAL: Prevent squeezing */
    flex-shrink: 0;
}

.song-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    z-index: 0;
    transition: transform 0.5s ease;
}

.song-card:hover .song-bg {
    transform: scale(1.1);
}

/* Gradient Overlay - The "Black Gradient" */
.song-card::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 70%;
    /* Covers bottom 70% */
    background: linear-gradient(to top, rgba(0, 0, 0, 1) 0%, rgba(0, 0, 0, 0.8) 30%, transparent 100%);
    z-index: 1;
    pointer-events: none;
}

/* Mobile responsive width */
@media (max-width: 600px) {
    .song-card {
        width: 100%;
        /* Full width on mobile */
        max-width: 400px;
    }
}

.song-card:hover {
    transform: scale(1.05);
    border-color: var(--neon-blue);
    z-index: 10;
    box-shadow: 0 10px 30px rgba(0, 243, 255, 0.3);
}

.song-card .song-title {
    position: relative;
    font-size: 18px;
    font-weight: 900;
    margin: 0 15px 4px 15px;
    /* Side margins 15px */
    color: white;
    text-align: left;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.9);
    z-index: 2;
    /* Above gradient */

    /* Font Metrics */
    line-height: 1.4;

    /* Layout */
    width: calc(100% - 30px);
    /* Full width minus margins */

    /* Wrapping */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    /* Standard property for compatibility */
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.song-card .song-artist {
    position: relative;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.8);
    margin: 0 15px 15px 15px;
    /* Bottom margin 15px */
    text-align: left;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.9);
    z-index: 2;
    /* Above gradient */

    /* Font Metrics */
    line-height: 1.4;

    /* Layout */
    width: calc(100% - 30px);

    /* Ellipsis */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Badge - Top Right, No Overlap */
.song-card .difficulty-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 900;
    letter-spacing: 0.5px;
    color: white;
    text-transform: uppercase;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: none;
}

/* Difficulty Specific Styles */
.difficulty-normal .difficulty-badge {
    color: var(--neon-green);
    border-color: var(--neon-green);
}

.difficulty-hard .difficulty-badge {
    color: var(--neon-yellow);
    border-color: var(--neon-yellow);
}

.difficulty-extreme .difficulty-badge {
    color: var(--neon-pink);
    border-color: var(--neon-pink);
}

/* Results Screen */
.results-title {
    font-size: 48px;
    font-weight: 900;
    color: white;
    margin-bottom: 30px;
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
}

.results-score-label {
    font-size: 16px;
    letter-spacing: 4px;
    color: rgba(255, 255, 255, 0.6);
    margin-bottom: 10px;
}

/* Utility */
.hidden {
    display: none !important;
    opacity: 0 !important;
    pointer-events: none !important;
}


#results-score {
    font-size: 80px;
    font-weight: 900;
    color: var(--neon-blue);
    text-shadow: 0 0 40px var(--neon-blue);
    margin-bottom: 30px;
}

#results-medal {
    font-size: 36px;
    font-weight: 900;
    padding: 10px 40px;
    border-radius: 50px;
    background: white;
    color: black;
    margin-bottom: 40px;
    box-shadow: 0 0 30px white;
    animation: pulse 1s infinite alternate;
}

.medal-none {
    display: none;
}

.medal-gold {
    background: #FFD700;
    box-shadow: 0 0 30px #FFD700;
}

.medal-platinum {
    background: #E5E4E2;
    box-shadow: 0 0 30px #E5E4E2;
}

.medal-diamond {
    background: #B9F2FF;
    box-shadow: 0 0 30px #B9F2FF;
}

.medal-diamond-perfect {
    background: linear-gradient(45deg, #B9F2FF, #FFD700);
    box-shadow: 0 0 40px #B9F2FF;
}

/* Results Stats */
#results-stats {
    display: flex;
    gap: 30px;
    margin-bottom: 40px;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-label {
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 5px;
    opacity: 0.8;
}

.stat-value {
    font-size: 32px;
    font-weight: 900;
}

.stat-item.perfect-plus .stat-label,
.stat-item.perfect-plus .stat-value {
    color: var(--neon-blue);
    text-shadow: 0 0 15px rgba(0, 243, 255, 0.5);
}

.stat-item.perfect .stat-label,
.stat-item.perfect .stat-value {
    color: var(--neon-green);
    text-shadow: 0 0 15px rgba(0, 255, 157, 0.5);
}

.stat-item.great .stat-label,
.stat-item.great .stat-value {
    color: var(--neon-yellow);
    text-shadow: 0 0 15px rgba(255, 234, 0, 0.5);
}

.stat-item.miss .stat-label,
.stat-item.miss .stat-value {
    text-shadow: 0 0 15px rgba(255, 51, 51, 0.5);
}

/* Visualizer */
#viz-track {
    min-height: 100%;
}

.viz-lane {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 200px;
    /* Borders handled inline for middle lane */
}

.viz-note {
    position: absolute;
    width: 180px;
    /* 200 - 20 padding */
    left: 10px;
    /* Gradient Body: #2a2a35 to #111115 */
    background: linear-gradient(to bottom, #2a2a35, #111115);
    border: 2px solid rgba(255, 255, 255, 0.8);
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 5;
    overflow: hidden;
    /* For shine clipping */
}

/* New Shine Element */
.viz-note-shine {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 40%;
    background: rgba(255, 255, 255, 0.4);
    border-top-left-radius: 6px;
    border-top-right-radius: 6px;
    pointer-events: none;
}

.viz-note-strip {
    /* Exact stats from game loop */
    width: 70%;
    height: 12px;
    border-radius: 2px;
    background: white;
    /* Box shadow simulates the glow opacity/blur */
    box-shadow: 0 0 10px currentColor, 0 0 5px currentColor;
    z-index: 2;
    /* The color is set inline by JS */
}

.viz-time-marker {
    position: absolute;
    border-top: 1px dashed #333;
    color: #555;
    font-size: 10px;
    padding-left: 5px;
    pointer-events: none;
    z-index: 10;
}