/* 添加手机端字幕样式 */
@media (max-width: 768px) {

    /* 首页布局 */
    body {
        flex-direction: column;
    }

    #sidebar {
        width: 100%;
        height: auto;
        max-height: 200px;
        order: 2;
    }

    #main-content {
        height: auto;
        flex: 1;
        order: 1;
    }

    #video-grid {
        grid-template-columns: 1fr;
    }

    /* 播放页面 */
    .danmaku-subtitle {
        font-size: 14px !important;
        max-width: calc(100vw - 20px);
        overflow: hidden;
        text-overflow: ellipsis;
    }

    #video-container {
        height: calc(100vh - 80px);
    }

    #header {
        padding: 8px 12px !important;
        font-size: 14px !important;
        overflow: hidden !important;
        width: calc(100vw - 40px) !important;
        max-width: 100% !important;
        justify-content: flex-start !important;
    }

    #back-button {
        flex-shrink: 0 !important;
        font-size: 12px !important;
        padding: 6px 10px !important;
        margin-right: 8px !important;
    }

    #video-title {
        flex: 1 !important;
        min-width: 0 !important;
        font-size: 13px !important;
        margin: 0 !important;
        padding: 0 8px !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        white-space: nowrap !important;
        text-align: center !important;
        max-width: calc(100vw - 200px) !important;
        scrollbar-width: none !important;
        -ms-overflow-style: none !important;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
    }

    #video-title::-webkit-scrollbar {
        display: none !important;
    }

    #subtitle-controls {
        flex-shrink: 0 !important;
        margin-left: 8px !important;
        display: flex !important;
        align-items: center !important;
        gap: 4px !important;
    }

    #subtitle-toggle {
        font-size: 10px !important;
        padding: 4px 6px !important;
    }

    #subtitle-status {
        font-size: 9px !important;
    }

    .player-page {
        padding: 10px;
        gap: 10px;
    }

    .player-page #loading,
    .player-page #error {
        padding: 20px;
        margin: 10px;
        position: relative;
        top: auto;
        left: auto;
        transform: none;
    }
}

/* 移动端横屏时标题自动隐藏功能 */
/* iPhone Safari 兼容的横屏检测 */
@media (max-width: 926px) and (max-height: 428px) {

    /* 横屏时的页面布局调整 */
    .player-page {
        padding: 0;
        gap: 0;
        height: 100vh;
        overflow: hidden;
        background: #1a1a1a;
        /* 深灰色背景，不会让弹幕消失 */
    }

    /* 标题栏横屏时的样式 */
    #header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1000;
        margin: 0;
        border-radius: 0;
        padding: 6px 10px;
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(10px);

        /* 默认隐藏 */
        transform: translateY(-100%);
        opacity: 0;
        transition: all 0.3s ease-in-out;
    }

    /* 显示状态 */
    #header.show {
        transform: translateY(0);
        opacity: 1;
    }

    /* 视频容器横屏时调整 */
    #video-container {
        margin: 0;
        height: 100vh;
        max-height: 100vh;
        width: 100vw;
        border-radius: 0;
        border: none;
        box-shadow: none;
        background: #1a1a1a;
        /* 与页面背景一致的深灰色 */
    }

    /* 确保视频填满整个屏幕 */
    .video-wrapper {
        height: 100vh;
        width: 100vw;
        background: #1a1a1a;
        /* 深灰色背景 */
    }

    #youtube-player,
    #fallback-iframe {
        height: 100vh;
        width: 100vw;
    }

    /* 标题文字大小调整 */
    #video-title {
        font-size: 12px !important;
    }

    #back-button {
        font-size: 11px !important;
        padding: 4px 8px !important;
    }

    #subtitle-toggle {
        font-size: 9px !important;
        padding: 3px 6px !important;
    }

    #subtitle-status {
        font-size: 8px !important;
    }
}

/* 竖屏时保持原样 */
@media (max-width: 768px) and (orientation: portrait) {
    #header {
        position: static;
        /* 竖屏时正常显示 */
        transform: none;
        opacity: 1;
    }
}