/* =========================================
   1. Variables & Reset
   ========================================= */
:root {
    --miku: #39c5bb;
    --bg: #39c5bb;
    --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;
    transition: background 0.8s ease;
    overflow: hidden;
    position: relative;
    /* -webkit-user-select: none;
    -moz-user-select: none;
    user-select: none; */
}

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

/* =========================================
   2. Utilities
   ========================================= */
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-col { display: flex; flex-direction: column; }
.abs-center { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); }
.full-size { width: 100%; height: 100%; }

/* Toast Notification */
.toast-msg {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    z-index: 1000;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
    font-size: 0.9rem;
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}
.toast-msg.visible { opacity: 1; }

/* Ambient Background */
#bgCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    filter: blur(60px) saturate(1.5); 
    opacity: 0.6;
    transition: opacity 0.8s ease;
}

#colorCanvas { display: none; }

/* =========================================
   3. Layout (Mobile First)
   ========================================= */
.player-card {
    width: 100%;
    height: 100vh;
    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;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    box-shadow: none;
    transition: all 0.3s ease;
}

.nav-bar {
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: 15px;
    z-index: 10;
}

.cover-section {
    width: 100%;
    flex: 1;
    min-height: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 20px;
    container-type: size; /* Enable container queries */
}

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

/* =========================================
   4. Components
   ========================================= */

/* Buttons */
.btn-icon {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    padding: 0;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, background-color 0.2s;
    border-radius: 50%;
}
.btn-icon:hover {
    background-color: rgba(128, 128, 128, 0.1);
    transform: scale(1.1);
}
.btn-icon:active {
    transform: scale(0.9);
    background: rgba(128, 128, 128, 0.2);
}
.btn-icon svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

/* Cover Art */
.cover-wrapper {
    width: 80cqmin; /* Scale based on container's smallest dimension */
    max-width: 400px; /* Cap for very large screens */
    display: flex;
    flex-direction: column;
    align-items: center;
}

.cover-box {
    width: 100%;
    aspect-ratio: 1/1;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    /* background-color: var(--miku); */
    background-image: url('/image/cover.png');
    background-size: cover;
    background-position: center;
    position: relative;
    transition: all 0.3s ease;
    object-fit: cover;
}

.cover-box:hover {
    transform: scale(1.02);
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.3);
}

.cover-source {
    text-align: center;
    font-size: 0.7rem;
    opacity: 0.5;
    margin-top: 8px;
    font-family: monospace;
    letter-spacing: 0.5px;
    height: 1em;
    transition: opacity 0.3s ease, transform 0.3s ease;
    white-space: nowrap;
}

/* Info Box (Title/Artist) */
.info-box {
    text-align: left;
    width: 100%;
    /* Reserve space to prevent layout shift */
    min-height: 60px; 
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 5px;
    white-space: nowrap;
    overflow: hidden;
    letter-spacing: -0.5px;
    display: inline-block;
    cursor: pointer;
    line-height: 1.3; /* Increased line-height */
    height: 1.3em; /* Increased height to accommodate descenders (g, j, p, q, y) */
    padding-bottom: 2px; /* Extra padding for safety */
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.artist {
    opacity: 0.7;
    font-size: 0.95rem;
    white-space: nowrap;
    display: inline-block;
    cursor: pointer;
    line-height: 1.3; /* Increased line-height */
    height: 1.3em; /* Increased height */
    padding-bottom: 2px;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.text-hidden {
    opacity: 0 !important;
    transform: translateY(5px);
}

.scroll-mask {
    width: 100%;
    overflow: hidden;
    white-space: nowrap;
    position: relative;
    height: 1.8em; /* Ensure container has height */
    display: flex;
    align-items: center;
}
.artist-mask { height: 1.2em; } /* Specific height for artist mask */

.scrolling {
    animation: marquee 15s linear infinite;
    padding-left: 100%;
    overflow: visible; /* Ensure text isn't clipped by itself */
    text-overflow: clip; /* Remove ellipsis during scroll */
}

/* Function Bar */
.function-bar { width: 100%; }

.like-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    position: relative; /* For absolute positioning of counter */
}

.heart-btn {
    padding: 8px;
    transition: color 0.3s ease, transform 0.2s ease;
}
.heart-btn.liked {
    color: #ff4757;
}
.heart-btn.liked svg {
    animation: heartBeat 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.heart-btn svg { fill: currentColor; }

/* Heart Icon Toggle */
.heart-btn .heart-filled { display: none; }
.heart-btn .heart-outline { display: block; }

.heart-btn.liked .heart-filled { display: block; }
.heart-btn.liked .heart-outline { display: none; }

.counter-text {
    font-size: 0.75rem;
    font-weight: 600;
    opacity: 0.8;
    font-family: monospace;
    display: none;
    
    /* Absolute positioning to not take space */
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-10px);
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
    margin-top: 2px;
    white-space: nowrap;
    pointer-events: none;
}

.counter-text.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Progress & Visualizer */
.progress-area {
    width: 100%;
    margin: 5px 0;
}

#visualizer {
    width: 100%;
    height: 60px;
    display: block;
    opacity: 0;
    transition: opacity 1s ease;
}

.time-row {
    margin-top: 5px;
    font-size: 0.75rem;
    font-weight: 600;
    opacity: 0.8;
}

.audio-specs-row { margin-top: 2px; }
.audio-specs {
    font-size: 0.65rem;
    opacity: 0.5;
    font-family: monospace;
    letter-spacing: 0.5px;
}

.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;
    box-shadow: 0 0 5px rgba(255, 71, 87, 0.5);
    transition: background-color 0.3s ease;
}
.live-badge.connected::before {
    background-color: #2ecc71;
    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 */
.control-bar {
    width: 100%;
    gap: 40px;
    position: relative;
}

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

.play-btn.loading svg { display: none; }
.play-btn.loading::after {
    content: "";
    width: 24px;
    height: 24px;
    border: 3px solid var(--bg);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

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

.vol-popup {
    position: absolute;
    bottom: 120%;
    left: 50%;
    transform: translateX(-50%) scale(0.9);
    width: 160px;
    height: 50px;
    background: var(--bg);
    border-radius: 25px;
    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-horizontal {
    width: 120px;
    height: 4px;
    accent-color: var(--text);
    cursor: pointer;
}

/* =========================================
   5. Modals & Overlays
   ========================================= */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    -webkit-backdrop-filter: blur(4px);
    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;
}
.modal-overlay.full-screen { z-index: 200; }

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

.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;
}

.about-footer {
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.credits {
    font-size: 0.9rem;
    opacity: 0.8;
    font-weight: 500;
}

.donate-group {
    display: flex;
    gap: 12px;
}

.btn-pill {
    background: rgba(128, 128, 128, 0.15);
    padding: 10px 24px;
    border-radius: 50px;
    text-decoration: none;
    color: var(--text);
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.2s ease;
    border: 1px solid rgba(128, 128, 128, 0.1);
}
.btn-pill:hover {
    background: rgba(128, 128, 128, 0.25);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}
.btn-pill:active { transform: scale(0.95); }

.close-btn-round {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid rgba(128, 128, 128, 0.2);
    background: rgba(128, 128, 128, 0.1);
    color: var(--text);
    cursor: pointer;
    box-shadow: none;
    transition: background 0.2s;
}
.close-btn-round:hover {
    background: rgba(128, 128, 128, 0.2);
}
.close-btn-round svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

.modal-content-full .close-btn-round {
    position: static;
    transform: none;
    margin: 0 auto;
    margin-top: auto;
}

/* 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);
}
.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;
    transition: opacity 0.2s, background-color 0.2s;
    border-radius: 8px;
}
.btn-text:hover {
    opacity: 1;
    background-color: rgba(128, 128, 128, 0.1);
}

/* 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);
    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;
    scrollbar-width: thin;
    scrollbar-color: rgba(128, 128, 128, 0.3) transparent;
}
.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-radius: 10px;
    border-bottom: 1px solid rgba(128, 128, 128, 0.1);
    display: flex;
    align-items: center;
    gap: 12px;
    transition: background-color 0.2s;
    cursor: default;
}
.list-item:hover {
    background-color: rgba(128, 128, 128, 0.1);
}
.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;
}

/* Source Selection */
.source-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 15px;
}
.btn-option {
    background: rgba(128, 128, 128, 0.15);
    border: 2px solid transparent;
    padding: 15px;
    padding-right: 45px;
    border-radius: 12px;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s;
    color: inherit;
    display: flex;
    flex-direction: column;
    gap: 4px;
    position: relative;
}
.btn-option:hover { background: rgba(128, 128, 128, 0.25); }
.btn-option:active { transform: scale(0.98); }
.btn-option.active {
    border-color: var(--miku);
    background: rgba(57, 197, 187, 0.15);
    box-shadow: 0 4px 12px rgba(57, 197, 187, 0.2);
}
.btn-option.active::after {
    content: "";
    position: absolute;
    top: 50%;
    right: 20px;
    width: 8px;
    height: 14px;
    border: solid var(--miku);
    border-width: 0 2.5px 2.5px 0;
    transform: translateY(-60%) rotate(45deg);
}
.option-title { font-weight: bold; font-size: 1rem; }
.option-desc { font-size: 0.8rem; opacity: 0.7; }

.ping-info {
    font-size: 0.75rem;
    margin-top: 5px;
    display: flex;
    align-items: center;
    gap: 6px;
    opacity: 0.9;
    font-weight: 500;
}
.ping-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #9e9e9e;
    box-shadow: 0 0 4px rgba(0,0,0,0.2);
}
.ping-dot.good { background: #4caf50; box-shadow: 0 0 6px #4caf50; }
.ping-dot.fair { background: #ff9800; box-shadow: 0 0 6px #ff9800; }
.ping-dot.poor { background: #f44336; box-shadow: 0 0 6px #f44336; }

/* Footer & Toggles */
.footer-info {
    height: 30px; /* Fixed height to prevent shift when toggle appears */
    align-items: center;
}

.online-badge .dot {
    width: 8px;
    height: 8px;
    background-color: #2ecc71;
    border-radius: 50%;
    margin-right: 6px;
    box-shadow: 0 0 5px rgba(46, 204, 113, 0.5);
}

.bg-toggle-container {
    display: flex;
    align-items: center;
    gap: 8px;
}
.switch-label { font-size: 0.75rem; opacity: 0.7; }

.switch {
    position: relative;
    display: inline-block;
    width: 34px;
    height: 20px;
}
.switch input { opacity: 0; width: 0; height: 0; }

.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(128,128,128,0.3);
    transition: .4s;
}
.slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
}
input:checked + .slider { background-color: var(--miku); }
input:checked + .slider:before { transform: translateX(14px); }
.slider.round { border-radius: 20px; }
.slider.round:before { border-radius: 50%; }

/* =========================================
   6. Landscape / Tablet Layout
   ========================================= */
@media (min-width: 768px) and (min-height: 500px) {
    .player-card {
        width: 90%;
        max-width: 850px;
        height: 500px;
        max-height: 80vh;
        flex-direction: row;
        padding: 0;
        align-items: stretch;
        background: rgba(255, 255, 255, 0.05);
        border-radius: 24px;
        -webkit-backdrop-filter: blur(10px);
        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;
        background: rgba(0, 0, 0, 0.1);
        padding: 40px;
    }

    .cover-wrapper {
        max-width: 100%; /* Reset mobile limit */
        width: 100%;
        height: auto;
    }

    .cover-box {
        width: 100%;
        height: auto;
        aspect-ratio: 1/1;
    }

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

    .nav-bar {
        position: absolute;
        top: 20px;
        left: 20px;
        width: auto !important;
        z-index: 5;
        right: auto;
        padding: 0;
    }

    /* Modal Adjustments */
    .modal-overlay.full-screen {
        background: rgba(0, 0, 0, 0.8);
        -webkit-backdrop-filter: blur(10px);
        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);
    }

    .modal-sheet, .modal-popup {
        position: relative;
        width: 390px;
        height: auto;
        max-height: 600px;
        border-radius: 16px;
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
        background: var(--bg);
        margin: 0;
        align-self: center;
        transform: none !important;
        top: auto; left: auto; bottom: auto; right: auto;
        transition: opacity 0.3s ease;
    }

    .modal-sheet {
        width: 320px;
        max-height: 500px;
        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; }

    #listModal h2 {
        margin-top: 15px;
    }
}

/* =========================================
   7. Animations
   ========================================= */
@keyframes marquee {
    0% { transform: translateX(0); }
    100% { transform: translateX(-100%); }
}

@keyframes heartBeat {
    0% { transform: scale(1); }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); }
}
