:root {
    --miku: #39c5bb;
    --bg: #eee;
    --text: #333;
    --glass: rgba(255, 255, 255, 0.7);
    --font-stack: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

body.is-dark {
    --text: #fff;
    --glass: rgba(0, 0, 0, 0.4);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-stack);
    background-color: var(--bg);
    color: var(--text);
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.8s ease;
    overflow: hidden;
}

button,
input {
    font-family: var(--font-stack);
}

/* --- Mobile Layout Fixes --- */
.player-card {
    width: 100%;
    height: 100vh; /* Full viewport height */
    max-width: none;
    max-height: none;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 20px;
    padding-top: 60px; /* Space for top nav */
    z-index: 2;
    position: relative;
    overflow: hidden;
    background: transparent;
    border-radius: 0;
    backdrop-filter: none;
    box-shadow: none;
    transition: all 0.3s ease;
}

.cover-section {
    width: 100%;
    flex: 1; /* Take available space */
    min-height: 0; /* Allow shrinking */
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 20px;
    /* No top margin needed as padding-top handles it */
}

.controls-section {
    width: 100%;
    flex-shrink: 0; /* Don't shrink controls */
    display: flex;
    flex-direction: column;
    gap: 15px;
    padding-bottom: 20px;
}

/* Landscape / Tablet Layout */
@media (min-width: 768px) and (min-height: 500px) {
    .player-card {
        width: 90%;
        /* Restore card width */
        max-width: 850px;
        height: 500px;
        max-height: 80vh;
        flex-direction: row;
        padding: 0;
        align-items: stretch;
        background: rgba(255, 255, 255, 0.05);
        /* Restore card bg */
        border-radius: 24px;
        backdrop-filter: blur(10px);
        box-shadow: 0 20px 50px rgba(0, 0, 0, 0.15);
    }

    .cover-section {
        width: 45%;
        height: 100%;
        margin-bottom: 0;
        margin-top: 0;
        /* Reset margin */
        background: rgba(0, 0, 0, 0.1);
        /* Slight bg for cover area */
        padding: 40px;
        /* Center the square */
    }

    .cover-box {
        width: 100%;
        height: auto;
        aspect-ratio: 1/1;
        border-radius: 20px;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    }

    .controls-section {
        width: 55%;
        padding: 30px;
        justify-content: center;
        gap: 20px;
        position: relative;
    }

    /* Adjust Nav Bar in Landscape */
    .nav-bar {
        position: absolute;
        top: 20px;
        right: 20px;
        width: auto !important;
        z-index: 5;
        /* Reset mobile styles */
        left: auto;
        padding: 0;
    }
}

.nav-bar {
    display: flex;
    justify-content: space-between;
    width: 100%;
    /* Mobile: Position at top of card/screen */
    position: absolute;
    top: 0;
    left: 0;
    padding: 15px;
    z-index: 10;
}

.btn-icon {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    padding: 10px;
    transition: transform 0.2s;
    border-radius: 50%;
}

.btn-icon:active {
    transform: scale(0.9);
    background: rgba(128, 128, 128, 0.1);
}

.btn-icon svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

.cover-box {
    width: 100%;
    max-width: 45vh; /* Limit width to ensure height doesn't exceed 45vh (1:1) */
    aspect-ratio: 1/1;
    margin: 0 auto; /* Center it */
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    background-color: #ccc;
    background-size: cover;
    background-position: center;
    position: relative;
    transition: all 0.3s ease;
    /* Ensure image fits within the box if aspect ratio is constrained */
    object-fit: cover; 
}

/* .cover-box img removed */

.info-box {
    text-align: left;
    width: 100%;
}

.title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: -0.5px;
}

.artist {
    opacity: 0.7;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.function-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

/* Heart Button */
.like-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.heart-btn {
    padding: 8px;
    color: #ff4757;
}

.heart-btn svg {
    fill: currentColor;
}

.counter-text {
    font-size: 0.75rem;
    font-weight: 600;
    opacity: 0.8;
    font-family: monospace;
}

.progress-area {
    width: 100%;
    margin: 5px 0;
}

#visualizer {
    width: 100%;
    height: 60px;
    display: block;
}

.time-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 5px;
    font-size: 0.75rem;
    font-weight: 600;
    opacity: 0.8;
}

.live-badge {
    background: transparent;
    color: var(--text);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.75rem;
    letter-spacing: 1px;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 6px;
    border: 1px solid rgba(128, 128, 128, 0.3);
}

.live-badge::before {
    content: '';
    display: block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #ff4757;
    /* Default Red */
    box-shadow: 0 0 5px rgba(255, 71, 87, 0.5);
    transition: background-color 0.3s ease;
}

.live-badge.connected::before {
    background-color: #2ecc71;
    /* Green */
    box-shadow: 0 0 5px rgba(46, 204, 113, 0.5);
}

.station-name {
    font-size: 0.75rem;
    opacity: 0.6;
    margin-top: 4px;
    text-align: right;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* --- Control Bar & Volume --- */
.control-bar {
    display: flex;
    justify-content: center; /* Center everything */
    align-items: center;
    width: 100%;
    gap: 40px; /* Space between buttons */
    position: relative;
}

.play-btn {
    width: 72px;
    height: 72px;
    background: var(--text);
    color: var(--bg);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s;
    flex-shrink: 0;
}
.play-btn:active { transform: scale(0.95); }
.play-btn svg { width: 32px; height: 32px; fill: currentColor; }

/* Volume Popup Wrapper */
.vol-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.vol-popup {
    position: absolute;
    bottom: 120%; /* Float above button */
    left: 50%;
    transform: translateX(-50%) scale(0.9);
    width: 40px;
    height: 120px;
    background: var(--bg);
    border-radius: 20px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: all 0.2s ease;
    z-index: 20;
}
.vol-popup.active {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(-50%) scale(1);
}

.vol-slider-vertical {
    width: 100px; /* Length of slider */
    height: 4px;
    transform: rotate(-90deg); /* Vertical */
    accent-color: var(--text);
    cursor: pointer;
}

/* Modals */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

/* Full Screen Modal (About) */
.modal-overlay.full-screen {
    z-index: 200;
}

.modal-content-full {
    width: 100%;
    height: 100%;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    padding: 40px;
    text-align: center;
    position: relative;
}

/* Landscape Modal Adjustments */
@media (min-width: 768px) and (min-height: 500px) {

    /* About Modal: Dark background overlay */
    .modal-overlay.full-screen {
        background: rgba(0, 0, 0, 0.8);
        backdrop-filter: blur(10px);
        padding: 40px;
    }

    .modal-content-full {
        max-width: 800px;
        max-height: 600px;
        margin: auto;
        border-radius: 24px;
        box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
        /* Keep background opaque inside the modal */
        background: var(--bg);
    }

    /* Floating Panes for List & Stream */
    .modal-sheet,
    .modal-popup {
        position: relative;
        /* Reset positioning */
        width: 360px;
        height: auto;
        max-height: 600px;
        border-radius: 16px;
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
        background: var(--bg);
        margin: 0;

        /* Flexbox Centering handled by parent */
        align-self: center;

        /* Reset transforms and coordinates */
        transform: none !important;
        top: auto;
        left: auto;
        bottom: auto;
        right: auto;
        
        transition: opacity 0.3s ease;
    }
    
    /* Playlist: Context Menu Style (Floating) */
    .modal-sheet {
        position: relative;
        width: 320px;
        height: auto;
        max-height: 500px;
        border-radius: 16px;
        background: var(--bg);
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
        
        /* Reset positioning */
        top: auto; right: auto; bottom: auto; left: auto;
        margin: 0;
        align-self: center;
        
        /* Animation: Scale/Fade */
        transform: scale(0.95) !important;
        opacity: 0;
        transition: all 0.2s ease !important;
    }
    
    .modal-overlay.active .modal-sheet {
        transform: scale(1) !important;
        opacity: 1;
    }
    
    .sheet-handle { display: none; }
}

.about-header h2 {
    font-size: 2rem;
    margin-bottom: 10px;
}

.about-visualizer-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    overflow: hidden;
}

#waveCanvas {
    width: 100%;
    height: 150px;
}

.proxy-info-box {
    background: rgba(128, 128, 128, 0.1);
    padding: 15px;
    border-radius: 12px;
    font-family: monospace;
    font-size: 0.8rem;
    margin-bottom: 20px;
}

/* Close Button for About Modal (Static flow) */
.modal-content-full .close-btn-round {
    position: static;
    transform: none;
    margin: 0 auto; /* Center horizontally */
    margin-top: auto; /* Push to bottom if flex container has space */
}

.close-btn-round {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: none;
    background: var(--text);
    color: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.close-btn-round svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

/* Popup (Custom Stream) */
.modal-popup {
    width: 85%;
    max-width: 360px;
    background: var(--bg);
    padding: 25px;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    transform: scale(0.9);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    color: var(--text);
    /* Flexbox centering handles position */
}

.modal-overlay.active .modal-popup {
    transform: scale(1);
}

.custom-input {
    width: 100%;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid rgba(128, 128, 128, 0.3);
    background: rgba(128, 128, 128, 0.05);
    color: inherit;
    outline: none;
    margin-top: 5px;
}

.custom-input:focus {
    border-color: var(--miku);
}

.btn-primary {
    background: var(--text);
    color: var(--bg);
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
}

.btn-text {
    background: none;
    border: none;
    color: inherit;
    padding: 10px 20px;
    cursor: pointer;
    opacity: 0.7;
}

/* Sheet (Playlist) */
.modal-sheet {
    width: 100%;
    height: 70%;
    background: var(--bg);
    border-radius: 24px 24px 0 0;
    box-shadow: 0 -5px 30px rgba(0, 0, 0, 0.2);
    transform: translateY(100%);
    transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
    display: flex;
    flex-direction: column;
    color: var(--text);

    /* Flexbox: Push to bottom on mobile */
    align-self: flex-end;
}

.modal-overlay.active .modal-sheet {
    transform: translateY(0);
}

.sheet-handle {
    width: 40px;
    height: 4px;
    background: rgba(128, 128, 128, 0.3);
    border-radius: 2px;
    margin: 12px auto;
    flex-shrink: 0;
}

.scroll-content {
    flex: 1;
    overflow-y: auto;
    padding: 0 15px 20px 15px;
    -webkit-overflow-scrolling: touch;
}

.scroll-content::-webkit-scrollbar {
    width: 4px;
}

.scroll-content::-webkit-scrollbar-thumb {
    background: rgba(128, 128, 128, 0.3);
    border-radius: 2px;
}

.list-item {
    padding: 10px;
    border-bottom: 1px solid rgba(128, 128, 128, 0.1);
    display: flex;
    align-items: center;
    gap: 12px;
}

.list-item:last-child {
    border-bottom: none;
}

.list-item img {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    object-fit: cover;
}

.list-item div {
    overflow: hidden;
    flex: 1;
}

.list-item p {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#colorCanvas {
    display: none;
}

/* Source Selection Styles */
.source-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 15px;
}

.btn-option {
    background: rgba(128, 128, 128, 0.1);
    border: 1px solid transparent;
    padding: 15px;
    border-radius: 12px;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s;
    color: inherit;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.btn-option:hover {
    background: rgba(128, 128, 128, 0.15);
}

.btn-option:active {
    transform: scale(0.98);
}

.btn-option.active {
    border-color: var(--miku);
    background: rgba(57, 197, 187, 0.1);
}

.option-title {
    font-weight: bold;
    font-size: 1rem;
}

.option-desc {
    font-size: 0.8rem;
    opacity: 0.7;
}