/* ============================================================
   小神空间 — 移动端统一适配
   只在窄屏覆盖布局，不改变桌面端的视觉结构。
   ============================================================ */

@media (max-width: 768px) {
    :root {
        --mobile-gutter: 16px;
    }

    html,
    body {
        width: 100%;
        min-width: 0;
    }

    html.site-scroll-locked,
    body.site-scroll-locked {
        overscroll-behavior: none;
    }

    body {
        padding-right: 0;
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }

    img,
    video {
        max-width: 100%;
    }

    /* 页面头部与页脚：为刘海屏和窄屏文字留出稳定空间 */
    .page-hero {
        width: 100%;
        max-width: 100%;
        padding: calc(120px + env(safe-area-inset-top)) var(--mobile-gutter) 32px;
    }
    .page-hero .section-title,
    .section-title {
        overflow-wrap: anywhere;
    }
    .page-hero .section-description {
        max-width: 36rem;
        margin-inline: auto;
    }
    .footer {
        gap: 16px;
        padding-inline: var(--mobile-gutter);
    }
    .footer-text {
        max-width: 100%;
        line-height: 1.55;
        overflow-wrap: anywhere;
    }
    .footer-links {
        justify-content: center;
        flex-wrap: wrap;
        gap: 8px 14px;
    }

    /* 侧栏改为触控友好的抽屉，避免遮挡正文 */
    .side-nav {
        width: min(82vw, 300px);
        padding: calc(72px + env(safe-area-inset-top)) 16px 24px;
    }
    .side-nav-close {
        position: absolute;
        top: max(14px, env(safe-area-inset-top));
        right: 14px;
        display: grid;
        place-items: center;
        width: 44px;
        height: 44px;
        border: 1px solid rgba(29, 78, 216, 0.18);
        border-radius: 50%;
        background: #fff;
        color: #1d4ed8;
        font: 600 28px/1 Arial, sans-serif;
        cursor: pointer;
    }
    .side-nav-item {
        min-height: 46px;
        padding: 11px 12px;
    }
    .side-nav-toggle {
        top: max(12px, env(safe-area-inset-top));
        left: 12px;
        width: 44px;
        height: 44px;
    }

    /* 首页评论弹窗：内容较长时在卡片内部滚动，不挤出屏幕 */
    .lm-overlay {
        padding: max(14px, env(safe-area-inset-top)) var(--mobile-gutter) max(14px, env(safe-area-inset-bottom));
        overflow: hidden;
        overscroll-behavior: contain;
        touch-action: none;
    }
    html.lm-scroll-locked,
    body.lm-scroll-locked {
        overflow: hidden;
        overscroll-behavior: none;
        touch-action: none;
    }
    .lm-card {
        width: min(100%, 420px);
        max-height: calc(100svh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 28px);
        overflow-x: hidden;
        overflow-y: auto;
        overscroll-behavior: contain;
        touch-action: pan-y;
        -webkit-overflow-scrolling: touch;
        min-height: 0;
    }
    .lm-card:not(.lm-history) {
        overflow-y: hidden;
        touch-action: none;
    }
    .lm-history {
        display: flex;
        flex-direction: column;
        overflow-x: hidden;
        overflow-y: hidden;
        touch-action: none;
    }
    .lm-history-list {
        max-height: min(42svh, 280px);
        min-height: 0;
        overflow-x: hidden;
        overflow-y: auto;
        overscroll-behavior: contain;
        touch-action: pan-y;
        -webkit-overflow-scrolling: touch;
    }

    /* 剪辑作品入口：介绍文字和作品入口改为单列，避免横向挤压 */
    .ul-grid {
        width: 100%;
        gap: 24px;
    }
    .ul-title {
        font-size: clamp(2rem, 10vw, 2.7rem);
        line-height: 1.2;
        overflow-wrap: anywhere;
    }
    .ul-quote-text {
        text-align: left;
        line-height: 1.85;
    }
    .uf-watch-card {
        min-height: 82px;
        padding: 20px 18px;
    }
    .uf-watch-info {
        flex: 1;
    }
    .uf-watch-text,
    .uf-watch-sub {
        overflow-wrap: anywhere;
    }
    .uf-watch-arrow {
        font-size: 26px;
    }

    /* 文件提交页：上传卡片、列表和预览弹窗使用全宽触控布局 */
    .upload-section {
        width: 100%;
        max-width: 100%;
        margin-bottom: 32px;
    }
    .uf-card-header {
        align-items: flex-start;
    }
    .uf-card-sub {
        line-height: 1.55;
        overflow-wrap: anywhere;
    }
    .uf-file-item {
        width: 100%;
    }
    .uf-file-info {
        flex: 1 1 0;
        min-width: 0;
    }
    .uf-file-meta {
        min-width: 0;
    }
    .uf-preview-overlay {
        padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
        overflow: hidden;
        overscroll-behavior: contain;
        touch-action: none;
    }
    .uf-preview-modal,
    .uf-history-modal {
        width: 100%;
        max-width: 100%;
        max-height: calc(100svh - 24px);
    }
    .uf-preview-body,
    .uf-history-body {
        overscroll-behavior: contain;
        touch-action: pan-y;
        -webkit-overflow-scrolling: touch;
    }
    .uf-preview-info {
        grid-template-columns: minmax(60px, 76px) minmax(0, 1fr);
    }

    /* 作品视频列表：手机上将序号/名称与视频预览分成清晰的三行 */
    .vp-page,
    .ip-page,
    .dp-page {
        width: 100%;
        max-width: 100%;
    }
    .vp-title,
    .ip-title,
    .dp-title {
        overflow-wrap: anywhere;
    }
}

@media (max-width: 560px) {
    .vp-card {
        display: grid;
        grid-template-columns: 40px minmax(0, 1fr);
        align-items: center;
        gap: 10px;
        padding: 12px;
    }
    .vp-num {
        grid-column: 1;
        grid-row: 1;
        min-width: 40px;
        width: 40px;
        height: 40px;
    }
    .vp-card-info {
        grid-column: 2;
        grid-row: 1;
        width: 100%;
    }
    .vp-video-box {
        grid-column: 1 / -1;
        grid-row: 2;
        width: 100%;
        min-width: 0;
    }
    .vp-video-name {
        white-space: normal;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        overflow: hidden;
        line-height: 1.45;
    }
}

@media (max-width: 480px) {
    :root {
        --mobile-gutter: 12px;
    }

    .page-hero {
        padding-inline: var(--mobile-gutter);
    }

    /* 首页和关于页的标题/正文保持可读的紧凑比例 */
    .hero-subtitle {
        max-width: 31rem;
        overflow-wrap: anywhere;
    }
    .about-text .section-description {
        line-height: 1.8;
    }

    /* 上传页面头部避免副标题把卡片横向撑大 */
    .uf-card-header {
        gap: 9px;
        padding-inline: 14px;
    }
    .uf-card-body {
        padding-inline: 12px;
    }
    .uf-card-sub {
        font-size: 0.76rem;
    }
    .uf-dz-hint {
        max-width: 22rem;
        margin-inline: auto;
        line-height: 1.55;
    }
    .uf-file-item {
        gap: 8px;
        padding: 10px;
    }
    .uf-file-name {
        max-width: 100%;
    }
    .uf-preview-info {
        gap: 7px 10px;
        padding: 12px;
    }

    /* 管理中心：顶部避开抽屉按钮，发布操作纵向排列 */
    .ad-page {
        width: 100%;
        max-width: 100%;
        margin: 0;
        padding: calc(72px + env(safe-area-inset-top)) var(--mobile-gutter) calc(32px + env(safe-area-inset-bottom));
    }
    .ad-toolbar {
        min-height: 44px;
        margin-bottom: 20px;
    }
    .ad-title {
        max-width: 100%;
        line-height: 1.3;
        overflow-wrap: anywhere;
    }
    .ad-section-head {
        align-items: flex-start;
        gap: 8px;
    }
    .ad-section-title {
        min-width: 0;
        line-height: 1.4;
        overflow-wrap: anywhere;
    }
    .ad-count {
        max-width: 46vw;
        padding: 5px 8px;
        font-size: 0.72rem;
        line-height: 1.35;
        text-align: right;
        white-space: normal;
    }
    .ad-publish {
        padding: 14px 12px;
        margin-bottom: 28px;
    }
    .ad-pub-row {
        width: 100%;
    }
    .ad-pub-file {
        width: 100%;
        min-width: 0;
        flex-basis: 100%;
    }
    .ad-pub-name {
        width: 100%;
        min-width: 0;
        flex-basis: 100%;
    }
    .ad-pub-file-copy {
        min-width: 0;
        max-width: 100%;
    }
    .ad-pub-file-copy small {
        max-width: 58vw;
    }
    .ad-pub-actions {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
    }
    .ad-pub-actions .ad-btn {
        width: 100%;
        min-height: 44px;
    }
    .ad-pub-preview {
        max-width: 100%;
    }
    .ad-filters {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 6px;
        width: 100%;
    }
    .ad-filters .ad-stat {
        width: 100%;
        justify-content: center;
        gap: 4px;
        padding: 9px 4px;
    }
    .ad-filters .ad-stat-icon {
        font-size: 0.9rem;
    }
    .ad-filters .ad-stat-num {
        font-size: 0.9rem;
    }
    .ad-filters .ad-stat-label {
        font-size: 0.7rem;
    }
    .ad-cat-actions {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 6px;
        margin-inline: 0;
    }
    .ad-cat-actions .ad-btn {
        width: 100%;
        min-height: 44px;
        padding-inline: 4px;
        font-size: 0.72rem;
        white-space: nowrap;
    }
    .ad-item {
        align-items: flex-start;
        gap: 9px;
        padding: 11px 10px;
    }
    .ad-info {
        padding-top: 2px;
    }
    .ad-name {
        white-space: normal;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        overflow: hidden;
        line-height: 1.45;
    }
    .ad-del {
        min-width: 44px;
        padding-inline: 9px;
    }
    .ad-modal-mask {
        padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
        overflow: hidden;
        overscroll-behavior: contain;
        touch-action: none;
    }
    .ad-modal {
        max-height: calc(100svh - 24px);
        overflow-y: auto;
        padding: 24px 18px 18px;
        overscroll-behavior: contain;
        touch-action: pan-y;
        -webkit-overflow-scrolling: touch;
    }

    /* 预览列表：序号、缩略图和文件信息始终保持可见 */
    .ip-card {
        display: grid;
        grid-template-columns: 40px 76px minmax(0, 1fr);
        gap: 10px;
        padding: 10px;
    }
    .ip-num {
        min-width: 40px;
        width: 40px;
        height: 40px;
    }
    .ip-thumb-box {
        width: 76px;
    }
    .ip-card-info {
        min-width: 0;
    }
    .ip-photo-name {
        white-space: normal;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        overflow: hidden;
        line-height: 1.45;
    }
    .dp-item {
        display: grid;
        grid-template-columns: 40px 40px minmax(0, 1fr);
        gap: 10px;
        padding: 11px;
    }
    .dp-num {
        min-width: 40px;
        width: 40px;
        height: 40px;
    }
    .dp-icon {
        width: 40px;
        height: 40px;
    }
    .dp-info {
        min-width: 0;
    }
    .dp-name {
        white-space: normal;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        overflow: hidden;
        line-height: 1.45;
    }
    .dp-download {
        grid-column: 2 / -1;
        justify-self: start;
        padding-inline: 14px;
    }
}

@media (max-width: 360px) {
    .hero-title-en {
        letter-spacing: 0.18em;
        text-indent: 0.18em;
    }
    .nav-logo {
        font-size: 0.98rem;
    }
    .ul-title {
        font-size: 1.95rem;
    }
    .ad-filters .ad-stat-label {
        display: none;
    }
    .ad-cat-actions .ad-btn {
        font-size: 0.68rem;
    }
    .ip-card {
        grid-template-columns: 38px 70px minmax(0, 1fr);
        gap: 8px;
    }
    .ip-num {
        min-width: 38px;
        width: 38px;
        height: 38px;
    }
    .ip-thumb-box {
        width: 70px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .vp-num,
    .ip-num,
    .dp-num,
    .ad-num {
        animation: none;
    }
}

@media (min-width: 769px) {
    .side-nav-close { display: none; }
}
