body,
html {
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
    background-color: #000000;
    color: #ffffff;
    font-family: 'Pretendard', -apple-system, system-ui, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Custom Scrollbar - Dark & Minimal */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: #000000;
}

::-webkit-scrollbar-thumb {
    background: #333333;
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: #444444;
}

/* For Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: #333333 #000000;
    scrollbar-color: #222222 #0a0a0a;
}

/* Main Container: Responsive Layout */
.main-container {
    display: flex;
    flex-direction: row;
    gap: 30px;
    width: 100vw;
    height: 100vh;
    max-width: 100%;
    align-items: flex-start;
    /* List and Grid both starting from top */
    justify-content: center;
    padding: 40px 20px;
    /* Top-heavy padding for balance */
    box-sizing: border-box;
    overflow: hidden;
}

/* Left: Grid - Forces children to use its width */
.grid-container {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
    flex: 0 1 auto;
    /* Don't insist on growing to max width */
    max-width: 78vh;
    /* Conservative size for smaller grids (2x2, 3x3, 4x4) */
    max-height: 78vh;
    aspect-ratio: 1/1;
    min-width: 0;
    margin: 0;
}

/* Larger grids: maximize footprint */
.grid-container[data-theme="5x5"],
.grid-container.classic-layout {
    max-width: calc(100vh - 80px);
    max-height: calc(100vh - 80px);
}

/* Grid Override when NOT classic (using display: grid) */
.grid-container:not(.classic-layout) {
    display: grid !important;
}

.grid-container.classic-layout {
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    justify-content: center;
    gap: 0;
    aspect-ratio: auto;
}

.grid-item {
    position: relative;
    background-color: #111;
    overflow: hidden;
    cursor: pointer;
    border-radius: 2px;
}

.grid-container:not(.classic-layout) .grid-item {
    padding-top: 100%;
}

/* Classic Tiered Sizes - Precise Math */
.grid-item.large {
    width: 20%;
    aspect-ratio: 1/1;
    box-sizing: border-box;
    padding: 2px;
}

.grid-item.medium {
    width: 16.6666%;
    aspect-ratio: 1/1;
    box-sizing: border-box;
    padding: 2px;
}

.grid-item.small {
    width: 10%;
    aspect-ratio: 1/1;
    box-sizing: border-box;
    padding: 2px;
}

/* Alignment for classic items in flex mode */
.classic-layout .grid-item {
    flex-grow: 0;
    flex-shrink: 0;
}

.grid-item img,
.grid-item iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border: none;
}

/* Right: List - Constrained width to prioritize Grid */
.list-container {
    flex: 0 0 350px;
    min-width: 250px;
    max-height: 100%;
    overflow-y: auto;
    padding-left: 10px;
}

#track-list {
    margin: 0;
    padding: 0;
    list-style: none;
    counter-reset: track;
}

#track-list li {
    margin-bottom: 12px;
    counter-increment: track;
    display: flex;
    align-items: center;
    border-bottom: 1px solid #111;
    padding-bottom: 12px;
}

#track-list li::before {
    content: counter(track);
    color: #444;
    font-weight: 400;
    width: 30px;
    font-size: 0.9em;
}

#track-list li a {
    color: #eee;
    text-decoration: none;
    font-size: 0.95em;
    font-weight: 300;
    display: block;
    width: 100%;
    text-align: left;
    /* Ensure left alignment */
    white-space: normal;
    /* Allow wrapping */
    word-break: break-all;
    /* Ensure URLs or long words don't overflow */
    line-height: 1.4;
    padding-right: 10px;
    /* Space before scrollbar */
}

#track-list li a:hover {
    color: #3ea6ff;
}

.empty-li {
    color: #222;
}

/* Mobile Responsive */
@media (max-width: 850px) {

    body,
    html {
        overflow: hidden;
        /* Prevent body scroll, use container scroll */
    }

    .main-container {
        flex-direction: column;
        height: 100dvh;
        /* Dynamic viewport height */
        padding: 5px;
        padding-top: max(10px, env(safe-area-inset-top));
        /* Avoid clipping by notch/address bar */
        padding-bottom: env(safe-area-inset-bottom);
        gap: 5px;
        justify-content: flex-start;
        align-items: center;
    }

    .grid-container {
        flex: 0 0 auto;
        width: 100vw;
        max-width: 100vw;
        aspect-ratio: 1/1;
        height: 100vw;
    }

    .list-container {
        flex: 1;
        width: 100%;
        max-width: 100%;
        padding: 10px;
        box-sizing: border-box;
        overflow-y: auto;
        max-height: none !important;
        /* Override React sync on mobile */
    }

    #track-list li {
        padding-bottom: 8px;
        margin-bottom: 8px;
    }
}