/* =========================
   NyaCraft · 手机端适配层
   只负责窄屏：整份文件包在 media query 里，
   并且各页面用 media="screen and (max-width: 720px)" 引入，
   桌面端不会下载也不会应用，不会影响现有桌面布局。
   断点：≤720px 手机 / 平板竖屏，≤420px 小屏收窄
========================= */

@media (max-width: 720px) {

    /* ---------- 全局框架 ---------- */

    html {
        -webkit-text-size-adjust: 100%;
    }

    /* 底部导航高约 58px，主内容统一留出空间，避免最后一屏被压住 */
    main {
        padding-bottom: calc(108px + env(safe-area-inset-bottom, 0px)) !important;
    }

    /* 悬浮播放器抬到导航之上，不再压住底部菜单 */
    #music-card {
        right: 10px !important;
        bottom: calc(78px + env(safe-area-inset-bottom, 0px)) !important;
    }

    .asmr-player {
        left: 10px !important;
        right: 10px !important;
        bottom: calc(78px + env(safe-area-inset-bottom, 0px)) !important;
        max-width: none !important;
    }

    /* 主题钮缩小，避免在窄屏右上角占太多位置 */
    .theme-switcher {
        top: 8px;
        right: 8px;
        gap: 6px;
    }

    .theme-switcher-toggle {
        width: 30px;
        height: 30px;
        font-size: 11px;
    }

    .theme-switcher-list button {
        min-height: 32px;
        font-size: 12px;
    }

    /* 侧边栏展开态遮罩时，浮层让位 */
    :root.has-expanded-sidebar #music-card,
    :root.has-expanded-sidebar .asmr-player {
        opacity: 0.2;
        pointer-events: none;
    }

    /* ---------- 底部导航 ----------
       sidebar.css 只把侧栏变成 58px 的横条，11 个入口放不下（实测宽 520px，
       超出的入口在手机上点不到），这里改成可横向滑动 + 图标下带小字 */
    .site-sidebar {
        height: auto;
        min-height: 64px;
        padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
        justify-content: flex-start;
        gap: 6px;
        overflow: hidden;
    }

    .site-sidebar-brand {
        flex: 0 0 auto;
        width: 42px !important;
        height: 42px !important;
        justify-content: center;
        padding: 0 !important;
        border-radius: 10px;
    }

    .site-sidebar-brand .site-nav-label {
        display: none !important;
    }

    .site-side-nav {
        flex: 1 1 auto;
        min-width: 0;
        display: flex;
        gap: 4px;
        overflow-x: auto;
        overflow-y: hidden;
        scroll-snap-type: x proximity;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        overscroll-behavior-x: contain;
    }

    .site-side-nav::-webkit-scrollbar {
        display: none;
    }

    .site-side-nav a {
        flex: 0 0 auto;
        width: auto !important;
        min-width: 56px;
        height: 50px;
        padding: 5px 7px !important;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        border-radius: 10px;
        scroll-snap-align: center;
    }

    .site-side-nav a .site-nav-icon {
        width: 18px;
        height: 18px;
    }

    .site-nav-label,
    :root.has-expanded-sidebar .site-nav-label {
        display: block !important;
        opacity: 1 !important;
        padding: 0 !important;
        max-width: 56px;
        font-size: 9px;
        font-weight: 600;
        line-height: 1.1;
        letter-spacing: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* ---------- 首页欢迎页 ---------- */

    #welcome {
        padding: 16px;
    }

    .welcome-card {
        width: 100%;
        max-width: 100%;
        padding: 34px 22px;
        border-radius: 22px;
    }

    .welcome-card h1 {
        font-size: clamp(30px, 9vw, 40px);
        line-height: 1.1;
    }

    .welcome-card p {
        font-size: 13px;
    }

    .enter {
        width: 100%;
        margin-top: 22px;
        padding: 12px 16px;
    }

    /* ---------- 提示词寄存处 ---------- */

    .prompt-head h1 {
        font-size: 22px;
    }

    .prompt-head-stat {
        gap: 12px;
        font-size: 11px;
    }

    .prompt-import-drop {
        flex-wrap: wrap;
        gap: 8px;
        margin: 10px 12px 0;
        padding: 10px 12px;
    }

    .prompt-import-copy {
        flex: 1 1 140px;
        min-width: 0;
    }

    .prompt-import-copy strong {
        font-size: 12.5px;
    }

    .prompt-import-copy small {
        font-size: 10.5px;
    }

    .prompt-import-button {
        width: 100%;
        min-height: 34px;
    }

    .prompt-import-status {
        width: 100%;
        max-width: none;
        padding-left: 0;
        font-size: 11px;
    }

    .prompt-compose-title {
        padding: 12px 12px 0;
    }

    .prompt-compose textarea {
        min-height: 150px;
        padding: 12px;
        font-size: 13px;
    }

    .prompt-compose-tools {
        flex-wrap: wrap;
        gap: 8px;
        padding: 0 12px 12px;
    }

    /* 模型名较长独占一行，分类 / 比例并排两列，分级和"负面 Prompt"各占半行 */
    .prompt-select {
        flex: 1 1 calc(50% - 4px);
    }

    .prompt-select:first-child {
        flex: 1 1 100%;
    }

    .prompt-select input {
        width: auto;
        flex: 1 1 auto;
    }

    .prompt-ghost-btn {
        flex: 1 1 calc(50% - 4px);
        justify-content: center;
    }

    .prompt-compose-foot {
        flex-wrap: wrap;
        gap: 8px;
        padding: 12px;
    }

    .prompt-compose-foot .prompt-btn.is-primary {
        width: 100%;
        margin-left: 0;
    }

    .prompt-gallery-tools {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .prompt-search,
    .prompt-sort {
        width: 100%;
        flex: 1 1 auto;
    }

    .prompt-list-head {
        flex-wrap: wrap;
        gap: 8px;
    }

    .prompt-list-tools {
        flex-wrap: wrap;
        gap: 6px;
    }

    .prompt-cards {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .prompt-card-media.is-image img {
        height: 200px;
    }

    /* 详情页 */
    .prompt-detail-head,
    .prompt-detail {
        padding-left: 0;
        padding-right: 0;
    }

    .prompt-raw-wrap,
    .prompt-card,
    .prompt-shots,
    .prompt-comments {
        border-radius: 14px;
    }

    .prompt-shots,
    .prompt-comments {
        padding: 16px 14px;
    }

    .prompt-shot-grid {
        grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
        gap: 8px;
    }

    .prompt-shot-form {
        flex-wrap: wrap;
        gap: 8px;
    }

    .prompt-shot-form .prompt-btn {
        width: 100%;
    }

    .prompt-name-input {
        min-width: 0;
        flex: 1 1 100%;
    }

    /* ---------- 随笔 ---------- */

    .notes-head h1,
    .notes-hero h1 {
        font-size: 24px;
    }

    .notes-card,
    .note-card {
        padding: 16px 14px;
    }

    .notes-editor-grid,
    .notes-editor-body {
        grid-template-columns: 1fr;
    }

    /* ---------- 磁带听歌室 ----------
       music-room.css 里的选择器都带 .music-room 前缀（特异度更高），
       所以这里的规则也必须带上同样的前缀才会生效 */
    .music-room {
        padding-left: 14px;
        padding-right: 14px;
        font-size: 13px;
    }

    .music-room .mr-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        margin-bottom: 18px;
    }

    .music-room .mr-header h1 {
        font-size: 26px;
    }

    .music-room .mr-top-grid {
        grid-template-columns: minmax(0, 1fr);
        gap: 16px;
    }

    .music-room .mr-deck-window {
        padding: 14px 10px;
    }

    .music-room .mr-deck-caption {
        font-size: 8px;
    }

    .music-room .mr-controls {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        margin: 12px 0 14px;
    }

    .music-room .mr-list-toolbar {
        grid-template-columns: minmax(0, 1fr);
        gap: 10px;
        margin: 16px 0 14px;
    }

    .music-room .mr-track-head {
        display: none;
    }

    .music-room .mr-track-row {
        grid-template-columns: minmax(0, 1fr) 40px;
        padding: 6px 8px;
        min-height: 52px;
    }

    .music-room .mr-track-play {
        grid-template-columns: 34px minmax(0, 1fr);
        gap: 8px;
    }

    .music-room .mr-shelf {
        grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
        gap: 8px;
    }

    .music-room .mr-volume,
    .music-room .mr-effects {
        grid-template-columns: 48px minmax(0, 1fr) 30px;
        gap: 8px;
        font-size: 10px;
    }

    .music-room .mr-wishes-head,
    .music-room .mr-section-head {
        gap: 8px;
    }

    /* ---------- OC 档案 ---------- */

    .oc-page {
        min-width: 0;
    }

    .oc-main {
        width: 100%;
        padding-left: 14px;
        padding-right: 14px;
    }

    .oc-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .oc-header h1 {
        font-size: 28px;
    }

    .oc-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    .oc-grid > * img,
    .oc-card img,
    .oc-item img {
        max-height: 260px;
        object-fit: cover;
    }

    .oc-dialog {
        grid-template-columns: 1fr;
        width: 100%;
        max-height: 92svh;
        overflow: auto;
        padding: 12px;
    }

    /* ---------- 拼豆图纸 ---------- */

    .perler-main {
        padding-left: 14px;
        padding-right: 14px;
    }

    .perler-layout,
    .perler-editor,
    .perler-workbench {
        grid-template-columns: 1fr !important;
    }

    .perler-hero h1 {
        font-size: 26px;
    }

    /* ---------- 图片工坊 ---------- */

    .crop-main {
        padding-left: 14px;
        padding-right: 14px;
    }

    .crop-hero h1 {
        font-size: 26px;
    }

    .crop-editor-grid,
    .crop-layout,
    .crop-stage-grid {
        grid-template-columns: 1fr;
    }

    .crop-modes,
    .crop-tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
    }

    /* ---------- AI 生图（iframe 外壳页） ----------
       这页是个整屏 iframe，自带 inline 样式和旧的 padding-bottom:58px，
       手机上要把"顶栏 + iframe"正好卡在底部导航之上，别让页面整体滚动 */

    /* 这页是整屏生图应用，右下角悬浮播放器会挡住应用界面，直接收起来 */
    .image-page #music-card {
        display: none !important;
    }

    .image-shell {
        min-height: 0 !important;
        height: calc(100svh - 64px - env(safe-area-inset-bottom, 0px));
        padding-bottom: 0 !important;
        overflow: hidden;
    }

    .image-bar {
        min-height: 0;
        padding: 8px 12px;
        gap: 10px;
    }

    .image-mark {
        width: 30px;
        height: 30px;
        border-radius: 8px;
        font-size: 14px;
    }

    .image-bar h1 {
        font-size: 15px;
    }

    /* 手机上那行长路径说明没必要占位置，藏掉给生图界面腾高度 */
    .image-bar p {
        display: none;
    }

    .image-frame-wrap {
        height: 100%;
        min-height: 0;
    }

    .image-frame-wrap iframe {
        height: 100%;
        min-height: 0;
    }

    .image-fallback {
        inset: 12px;
        padding: 16px;
        border-radius: 12px;
    }

    .image-fallback h2 {
        font-size: 17px;
    }

    .image-fallback p {
        font-size: 12px;
        line-height: 1.6;
    }

    /* ---------- 图片元数据工具（内部页面，原本写死 min-width:980px） ---------- */

    /* 这一页把 html/body 写死了 min-width:980px，用 :has() 才能反悔 */
    :root:has(.metadata-page),
    body:has(.metadata-page),
    .metadata-page,
    .metadata-main {
        min-width: 0 !important;
    }

    .metadata-main {
        padding: 14px 12px calc(108px + env(safe-area-inset-bottom, 0px));
    }

    .metadata-main .app {
        width: 100%;
    }

    .metadata-main .head {
        flex-wrap: wrap;
        gap: 8px;
    }

    .metadata-main .drop {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .metadata-main .drop .primary {
        width: 100%;
    }

    .metadata-main .workspace {
        grid-template-columns: minmax(0, 1fr);
    }

    .metadata-main pre,
    .metadata-main .panel {
        min-width: 0;
        overflow-x: auto;
    }

    /* ---------- AI 模型库 ---------- */

    .ai-model-main {
        padding-left: 14px;
        padding-right: 14px;
    }

    .ai-model-grid {
        grid-template-columns: 1fr;
    }

    /* ---------- 阅读 ---------- */

    .reader-page {
        padding-left: 14px;
        padding-right: 14px;
    }

    .reader-page h1 {
        font-size: 24px;
    }
}

@media (max-width: 420px) {

    .prompt-head h1,
    .oc-header h1,
    .perler-hero h1,
    .crop-hero h1,
    .reader-page h1,
    .notes-head h1 {
        font-size: 22px;
    }

    .mr-controls {
        grid-template-columns: 1fr;
    }

    #music-card {
        right: 8px !important;
        bottom: calc(74px + env(safe-area-inset-bottom, 0px)) !important;
    }
}
