/* =================================================================
   responsive.css - 移动端终极适配方案
   描述: 针对 768px 以下屏幕的样式重置与优化
   包含: 搜索栏修复、播放器重构、榜单美化、交互修复
   ================================================================= */

@media (max-width: 768px) {

    /* ========================================
       1. 全局与基础容器
       作用: 固定视口，防止整体滚动，移除桌面端背景
    ======================================== */
    html,
    body {
        position: fixed;
        width: 100%;
        height: 100%;
        overflow: hidden; /* 防止页面整体滚动 */
    }

    #app {
        width: 100%;
        height: 100%;
        max-width: none;
        border: none;
        box-shadow: none;
    }

    #app::before {
        display: none; /* 隐藏桌面端的背景装饰 */
    }

    /* ========================================
       2. 顶部导航栏 (原侧边栏变形)
       作用: 变为顶部黑条，包含Logo
    ======================================== */
    .sidebar {
        width: 100%;
        height: calc(60px + env(safe-area-inset-top)); /* 适配刘海屏 */
        padding-top: env(safe-area-inset-top);
        min-height: auto;
        border-right: none;
        border-bottom: 1px solid #282828;
        
        display: flex;
        flex-direction: row;
        align-items: center;
        overflow: visible;
        z-index: 20;
        background: #000;
    }

    .logo {
        padding: 0 15px;
        font-size: 18px;
        flex: 1;
        height: 100%;
        display: flex;
        align-items: center;
        text-shadow: none;
        filter: none;
    }

    /* 隐藏不需要的桌面端组件 */
    .playlist-container,
    #online-music-nav,
    .sidebar-footer {
        display: none !important;
    }

    /* ========================================
       3. 用户区域
       作用: 右上角定位，显示头像和登录按钮
    ======================================== */
    .user-section {
        position: absolute;
        top: env(safe-area-inset-top);
        right: 0;
        width: auto;
        height: 60px;
        padding: 0 10px;
        
        display: flex;
        align-items: center;
        background: transparent;
        border: none;
        backdrop-filter: none;
    }

    #user-info {
        display: flex;
        gap: 5px;
        align-items: center;
    }

    .username-text {
        max-width: 80px;
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        color: #fff;
        font-size: 13px;
    }

    .fa-user-circle {
        font-size: 20px;
        color: #666;
    }

    .theme-toggle-btn {
        margin-right: 5px;
        width: 30px;
        height: 30px;
        font-size: 12px;
    }

    #btn-login-trigger {
        padding: 4px 8px;
        font-size: 12px;
        width: auto;
        box-shadow: none;
    }

    /* ========================================
       4. 主内容区与搜索栏
       作用: 垂直布局，修复搜索框样式
    ======================================== */
    .main-wrapper {
        flex-direction: column;
    }

    .content {
        padding: 10px 15px 0 15px; /* 增加左右内边距 */
    }

    /* --- [搜索栏修复] --- */
    .search-bar {
        display: flex !important;
        align-items: center !important;
        gap: 8px !important;
        margin-bottom: 15px;
        width: 100%;
        box-sizing: border-box;
    }

    /* 左侧下拉框: 变窄 (60px) */
    .source-select {
        flex-shrink: 0;
        width: 60px !important;
        height: 38px !important;
        line-height: 38px;
        padding: 0 !important;
        font-size: 11px !important;
        text-align: center;
        text-indent: 0 !important;
        
        background: #222;
        border: 1px solid #333;
        border-radius: 8px !important;
        margin: 0 !important;
    }

    /* 右侧输入框组: 占满剩余空间 */
    .search-input-group {
        flex: 1 !important;
        height: 38px !important;
        background: #222;
        border: 1px solid #333;
        border-radius: 8px !important;
        
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        overflow: hidden;
    }

    .search-input-group input {
        flex: 1 !important;
        width: 10px !important; /* 配合flex防止溢出 */
        min-width: 0 !important;
        height: 100% !important;
        border: none !important;
        background: transparent !important;
        padding: 0 10px !important;
        font-size: 13px !important;
        color: #fff;
    }

    /* 搜索按钮: 强制显示 */
    #btn-search,
    .search-btn {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 40px !important;
        height: 100% !important;
        flex-shrink: 0;
        
        background: transparent !important;
        border: none !important;
        border-left: 1px solid rgba(255, 255, 255, 0.05) !important;
        color: #bbb !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    /* --- [搜索栏修复结束] --- */

    /* ========================================
       5. Tab 切换栏
    ======================================== */
    .tab-header {
        justify-content: space-around;
        gap: 0;
        margin-bottom: 10px;
    }

    .tab-item {
        padding: 10px 0;
        font-size: 14px;
        flex: 1;
        text-align: center;
    }

    #tab-my-playlist {
        display: block !important; /* 强制显示我的歌单Tab */
    }

    /* ========================================
       6. 榜单/歌单区域美化 (核心修复)
       作用: 网格布局，且允许 JS 控制隐藏
    ======================================== */
    
    /* 外层容器 */
    #charts-tabs {
        width: 100%;
        /* 注意: 这里去掉了 !important，否则切换到我的歌单时JS无法隐藏它 */
        display: block; 
        margin-bottom: 20px;
    }

    /* 内部按钮容器 */
    #chart-tags-container {
        /* 注意: 这里去掉了 !important，但保留 grid 布局 */
        display: grid; 
        grid-template-columns: repeat(3, 1fr); /* 强制 3 列 */
        gap: 10px;
        width: 100%;
    }

    /* 榜单按钮样式 */
    #chart-tags-container > * {
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        
        width: auto !important;
        height: 40px !important;
        margin: 0 !important;
        padding: 0 5px !important;
        float: none !important;
        
        /* 玻璃质感 */
        background: rgba(255, 255, 255, 0.08) !important;
        border: 1px solid rgba(255, 255, 255, 0.05) !important;
        border-radius: 8px !important;
        
        /* 文字 */
        font-size: 12px !important;
        color: #ccc !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        cursor: pointer;
        transition: all 0.2s ease;
    }

    /* 按钮点击/激活态 */
    #chart-tags-container > *:active,
    #chart-tags-container > *.active {
        background: rgba(31, 214, 159, 0.15) !important;
        border-color: #1fd69f !important;
        color: #1fd69f !important;
        transform: scale(0.96);
    }

    /* ========================================
       7. 歌曲列表
    ======================================== */
    #song-list-container {
        margin-top: 5px;
        padding-right: 0;
        padding-bottom: 120px; /* 底部留白给播放器 */
    }

    .song-item {
        display: flex !important;
        align-items: center;
        gap: 8px;
        padding: 12px 5px;
        background: transparent;
        border-bottom: 1px solid #222;
        border-radius: 0;
        margin: 0;
        box-shadow: none;
        transform: none;
    }

    .song-item:hover {
        background: #1a1a1a;
        transform: none;
    }

    .col-action { order: -1; width: 30px; text-align: center; }
    .col-index { order: 0; width: 25px; font-size: 12px; text-align: center; color: #666; }
    .col-name { order: 1; flex: 1; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .col-artist, .col-album { display: none; /* 隐藏多余列 */ }

    /* ========================================
       8. 底部播放器控制条 (完美适配版)
       作用: 按钮等距，隐藏封面文字，保留功能
    ======================================== */
    .player-bar {
        position: relative;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: calc(85px + env(safe-area-inset-bottom));
        padding-bottom: env(safe-area-inset-bottom);
        
        display: flex !important;
        align-items: center !important;
        justify-content: center !important; /* 整体居中 */
        gap: 12px !important; /* 按钮间距 */
        padding: 0 10px !important;
        
        background: rgba(20, 20, 20, 0.95);
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        z-index: 99;
    }

    /* 使用 contents 拆除容器，直接排列按钮 */
    .player-left,
    .player-center,
    .player-controls,
    .player-right {
        display: contents !important;
    }

    /* 隐藏封面图和歌曲信息 */
    .player-left img,
    .player-left .cover,
    .player-left .music-cover,
    .player-left .music-info,
    .player-left .song-info,
    .player-left span,
    .player-left div:not(.quality-select) {
        display: none !important;
    }

    /* [1] 音质按钮 */
    .quality-select {
        display: block !important;
        width: 42px !important;
        height: 24px !important;
        font-size: 10px !important;
        text-align: center;
        background: rgba(0, 0, 0, 0.6);
        border: 1px solid #333;
        border-radius: 4px;
        color: #ddd;
        padding: 0 !important;
        margin: 0 !important;
        flex-shrink: 0;
        order: 1;
    }

    /* [2] 循环/上一首/下一首 */
    .control-btn {
        width: 32px !important;
        height: 32px !important;
        font-size: 16px !important;
        background: transparent !important;
        border: none !important;
        color: #ccc !important;
        padding: 0 !important;
        margin: 0 !important;
        display: flex !important;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
        order: 2;
    }

    /* [3] 播放/暂停大按钮 */
    .btn-play,
    #btn-play-pause {
        width: 46px !important;
        height: 46px !important;
        font-size: 22px !important;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.08) !important;
        color: #fff !important;
        display: flex !important;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
        order: 2;
    }

    /* [4] 下载/歌词按钮 */
    .player-right .btn-download,
    .player-right .control-btn[onclick="toggleLyricPage()"] {
        width: 32px !important;
        height: 32px !important;
        border-radius: 50%;
        background: rgba(30, 30, 30, 0.9) !important;
        border: 1px solid rgba(255, 255, 255, 0.15) !important;
        color: #ccc !important;
        display: flex !important;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
        order: 3;
    }

    /* 点击效果 */
    .control-btn:active,
    .quality-select:active,
    .player-right .btn-download:active {
        transform: scale(0.9);
        color: #31c27c !important;
    }

    /* 进度条 (吸附在播放器顶部) */
    .progress-section {
        position: absolute;
        bottom: calc(0px + env(safe-area-inset-bottom));
        left: 0;
        right: 0;
        height: 3px;
        width: 100%;
        z-index: 101;
    }

    .progress-bar::after,
    .time {
        display: none;
    }

    /* ========================================
       9. 歌词页与底部
    ======================================== */
    .lyric-cover {
        width: 140px;
        height: 140px;
        margin-bottom: 15px;
        border-radius: 20px;
        display: block !important;
    }

    .lyric-song-name {
        font-size: 20px;
    }

    .private-tag {
        display: none;
    }

    /* 底部版权 */
    .footer-info {
        display: block !important;
        position: fixed;
        bottom: 95px;
        left: 0;
        width: 100%;
        text-align: center;
        font-size: 10px;
        color: rgba(255, 255, 255, 0.3);
        z-index: 1;
        pointer-events: none;
    }

    .footer-info a {
        pointer-events: auto;
    }

    .logout-popup {
        top: 60px !important;
        bottom: auto !important;
        right: 10px !important;
        left: auto !important;
        transform-origin: top right;
    }

    /* ========================================
       10. 浅色模式适配 (Light Mode)
       作用: 覆盖深色样式
    ======================================== */
    body.light-mode .player-bar {
        background: rgba(255, 255, 255, 0.98);
        border-top: 1px solid rgba(0, 0, 0, 0.05);
    }

    body.light-mode .quality-select {
        background: #f5f5f5 !important;
        color: #333 !important;
        border: 1px solid #ddd !important;
    }

    body.light-mode .control-btn {
        color: #555 !important;
    }

    body.light-mode .btn-play,
    body.light-mode #btn-play-pause {
        background: rgba(0, 0, 0, 0.05) !important;
        color: #333 !important;
    }

    body.light-mode .player-right .btn-download,
    body.light-mode .player-right .control-btn[onclick="toggleLyricPage()"] {
        background: #fff !important;
        border: 1px solid #eee !important;
        color: #555 !important;
    }

    body.light-mode .song-item {
        border-bottom: 1px solid #eee;
    }

    /* 搜索栏浅色 */
    body.light-mode .source-select {
        background: #fff !important;
        border-color: #ddd !important;
        color: #333 !important;
    }

    body.light-mode .search-input-group {
        background: #fff !important;
        border-color: #ddd !important;
    }

    body.light-mode .search-input-group input {
        color: #333 !important;
    }

    body.light-mode #btn-search,
    body.light-mode .search-btn {
        border-left-color: #eee !important;
        color: #666 !important;
    }

    /* 榜单区域浅色 */
    body.light-mode #chart-tags-container > * {
        background: #f8f8f8 !important;
        border: 1px solid #e0e0e0 !important;
        color: #555 !important;
    }

    body.light-mode #chart-tags-container > *:active {
        background: #fff !important;
        border-color: #31c27c !important;
        color: #31c27c !important;
    }
}
