/* ============================================================
   应援创作室 · 移动端优先样式系统
   原则：手机优先，桌面渐进增强
   - 触控目标 ≥44px
   - 安全区 padding-bottom
   - 底部固定导航
   - 编辑器内隐藏全局导航
   ============================================================ */

/* ---------- 视口与基础 ---------- */
:root {
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --tab-h: 56px;
  --tool-h: 52px;
  --radius-mobile: 14px;
}

/* 移动端默认：窄容器、小内边距 */
@media (max-width: 720px) {
  .wrap, .wrap-narrow {
    max-width: 100%;
    padding: 0 14px;
  }

  body {
    font-size: 15px;
    /* 给底部导航留空间 */
    padding-bottom: calc(var(--tab-h) + var(--safe-bottom));
  }

  h1 { font-size: 22px; line-height: 1.4; }
  h2 { font-size: 17px; }
  h3 { font-size: 15px; }

  /* ---------- 底部固定导航 ---------- */
  .tabbar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--tab-h) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
    display: flex;
    z-index: 45;
  }
  .tabbar a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 550;
    min-height: 44px;
    transition: color .15s;
  }
  .tabbar a .ic {
    width: 24px;
    height: 24px;
    display: grid;
    place-items: center;
    font-size: 18px;
  }
  .tabbar a.on { color: var(--ink); }
  .tabbar a.on .ic { transform: scale(1.08); }

  /* 中间凸起的创作按钮 */
  .tabbar a.tab-create {
    position: relative;
  }
  .tabbar a.tab-create .ic {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--ink);
    color: #fff;
    margin-top: -10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  }

  /* ---------- 顶部导航移动端简化 ---------- */
  .topbar { height: 50px; }
  .topbar-in {
    height: 50px;
    padding: 0 14px;
    max-width: 100%;
  }
  /* ️不要给 .mobile-only 设统一的 display：
     曾因 `.mobile-only{display:block}` 在本块的最后出现，把前面 `.tabbar{display:flex}`
     覆盖成 block，导致三个底部入口竖排溢出屏幕。可见性由 display:none !important（桌面端）控制即可，
     组件自身需要的 display 保持原样。 */
  .tabbar.mobile-only { display: flex; }

  .topbar .nav { display: none; }
  .topbar .logo span:last-child { display: none; }

  /* ---------- 首页 Hero 移动端 ---------- */
  .hero {
    padding: 20px 0 16px;
  }
  .hero h1 {
    font-size: 21px;
    line-height: 1.38;
    max-width: 100%;
  }
  .hero p.lead {
    font-size: 14px;
    margin-top: 8px;
    max-width: 100%;
  }
  .hero .btn-row {
    margin-top: 14px;
    gap: 8px;
  }
  .hero .btn-row .btn {
    flex: 1;
    min-height: 44px;
  }
  .hero-facts {
    gap: 14px;
    margin-top: 18px;
  }
  .hero-facts b { font-size: 15px; }
  .hero-facts div { font-size: 12px; }

  /* ---------- 灵感广场移动端 ---------- */
  .section-head {
    margin: 20px 0 12px;
  }
  /* 筛选区：风格独占一行横滑；次要条件在「更多筛选」面板内分行展示 */
  .filterbar { padding: 10px 12px; }
  .filter-row { gap: 8px; }
  .filter-row .chip-line { padding-bottom: 2px; }
  .filter-check { min-height: 40px; }
  .chip {
    padding: 7px 13px;
    font-size: 13px;
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* 双列卡片 */
  .tpl-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  .tpl-card {
    border-radius: var(--radius-mobile);
  }
  .tpl-preview {
    aspect-ratio: 3 / 4;
  }
  .tpl-preview canvas {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }
  .tpl-body {
    padding: 8px 10px 10px;
  }
  .tpl-body .name {
    font-size: 13px;
    gap: 4px;
  }
  .tpl-body .name .tag {
    font-size: 10px;
    padding: 2px 6px;
  }
  .tpl-body .desc {
    font-size: 11px;
    margin-top: 2px;
    min-height: 0;
    -webkit-line-clamp: 2;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .tpl-body .btn-row {
    margin-top: 8px;
    gap: 5px;
  }
  .tpl-body .btn-row .btn {
    flex: 1;
    padding: 7px 8px;
    font-size: 12px;
    min-height: 36px;
  }
  .swatch i {
    width: 11px;
    height: 11px;
  }

  /* ---------- 模板详情移动端 ---------- */
  .detail {
    grid-template-columns: 1fr;
    gap: 16px;
    padding: 16px 0 calc(var(--tab-h) + var(--safe-bottom) + 80px);
  }
  .stage {
    min-height: auto;
    padding: 16px;
    border-radius: var(--radius-mobile);
  }
  .stage canvas {
    max-height: 50vh;
  }
  .stage-switch {
    margin-top: 12px;
    gap: 5px;
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: none;
  }
  .stage-switch::-webkit-scrollbar { display: none; }
  .stage-switch .chip {
    padding: 6px 11px;
    font-size: 12px;
  }

  /* 底部固定 CTA（在底部导航之上，避免被 tabbar 遮挡无法点击） */
  .cta-fixed {
    position: fixed;
    bottom: calc(var(--tab-h) + var(--safe-bottom));
    left: 0;
    right: 0;
    padding: 12px 14px calc(12px + var(--safe-bottom));
    background: rgba(255, 255, 255, 0.97);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
    z-index: 44;
    display: flex;
    gap: 10px;
    align-items: center;
  }
  .cta-fixed .price-info {
    flex: 1;
  }
  .cta-fixed .price-info b {
    font-size: 17px;
  }
  .cta-fixed .price-info .small {
    font-size: 11px;
  }
  .cta-fixed .btn {
    min-height: 44px;
    padding: 10px 22px;
    font-size: 15px;
  }

  /* ---------- 创作向导移动端 ---------- */
  .wizard {
    padding: 16px 0 calc(var(--tab-h) + var(--safe-bottom) + 80px);
  }
  .steps {
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: none;
    padding-bottom: 4px;
  }
  .steps::-webkit-scrollbar { display: none; }
  .step {
    flex-shrink: 0;
    white-space: nowrap;
  }
  .panel {
    border-radius: var(--radius-mobile);
    padding: 14px;
    margin-bottom: 12px;
  }

  .asset-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }
  .asset-card .thumb { height: 72px; }
  .dropzone {
    padding: 20px 16px;
    border-radius: var(--radius-mobile);
  }
  .dropzone .btn { min-height: 44px; }

  .product-pick {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .product-pick label {
    padding: 10px;
    min-height: 44px;
  }

  /* 向导底部固定按钮 */
  .wizard-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 10px 14px calc(10px + var(--safe-bottom));
    background: rgba(255, 255, 255, 0.97);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
    z-index: 44;
    display: flex;
    gap: 10px;
  }
  .wizard-nav .btn {
    flex: 1;
    min-height: 44px;
  }

  /* 向导 panel 内按钮在移动端 sticky 到底部，不脱离 DOM */
  .wizard .panel .row-b:last-child {
    position: sticky;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.97);
    backdrop-filter: blur(12px);
    padding: 10px 0 calc(10px + var(--safe-bottom));
    margin: 8px -14px -14px;
    padding-left: 14px;
    padding-right: 14px;
    border-top: 1px solid var(--line);
    z-index: 10;
  }
  .wizard .panel .row-b:last-child .btn {
    flex: 1;
    min-height: 44px;
  }

  /* ---------- 编辑器：隐藏全局导航 ---------- */
  body[data-page="editor"] {
    padding-bottom: 0;
  }
  body[data-page="editor"] .tabbar,
  body[data-page="editor"] .topbar {
    display: none;
  }

  /* ---------- 我的作品移动端 ---------- */
  .works-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  .work-card {
    padding: 10px;
    border-radius: var(--radius-mobile);
  }
  .work-thumb {
    height: 96px;
    padding: 8px;
  }

  /* ---------- 订单移动端 ---------- */
  .price-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .price-card {
    padding: 14px;
    border-radius: var(--radius-mobile);
  }

  /* ---------- 批量移动端 ---------- */
  .batch-preview {
    max-height: 260px;
    font-size: 12px;
  }

  /* ---------- Modal 移动端 ---------- */
  .modal-mask {
    padding: 0;
    align-items: flex-end;
  }
  .modal {
    max-width: 100%;
    border-radius: 18px 18px 0 0;
    max-height: 85vh;
    margin: 0;
    width: 100%;
  }
  .modal header {
    padding: 14px 16px 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .modal header::after {
    content: "";
    position: absolute;
    top: 6px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: var(--line-2);
  }
  .modal header {
    position: relative;
    padding-top: 18px;
  }
  .modal .body { padding: 4px 16px 14px; }
  .modal footer {
    padding: 10px 16px calc(14px + var(--safe-bottom));
    flex-direction: column-reverse;
    gap: 8px;
  }
  .modal footer .btn {
    width: 100%;
    min-height: 44px;
  }

  /* ---------- Toast 移动端 ---------- */
  #toasts {
    bottom: calc(var(--tab-h) + var(--safe-bottom) + 12px);
  }
  .toast {
    max-width: 92vw;
    font-size: 13px;
  }

  /* ---------- 底部安全区补丁 ---------- */
  .safe-bottom { padding-bottom: var(--safe-bottom); }

  /* 桌面端隐藏移动端专用元素（不在这里设 display，避免覆盖组件自身的 display） */
}

/* 桌面端：隐藏移动专用元素 */
@media (min-width: 721px) {
  .tabbar { display: none; }
  .mobile-only { display: none !important; }
  .cta-fixed { display: none; }
  .wizard-nav { position: static; }
  body { padding-bottom: 0; }
}

/* ---------- 触控目标通用规范 ---------- */
button, .btn, .chip, a[role="button"], input[type="checkbox"], input[type="radio"] {
  min-height: 36px;
}
.btn.sm { min-height: 36px; }
.btn, .btn.lg { min-height: 40px; }

@media (max-width: 720px) {
  button, .btn, .chip {
    min-height: 44px;
  }
  .btn.sm { min-height: 40px; }
}

/* ---------- 防横向溢出 ---------- */
html, body {
  overflow-x: hidden;
  max-width: 100vw;
}
img, canvas, video {
  max-width: 100%;
}

/* ---------- 触摸滚动优化 ---------- */
.scroll-x {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.scroll-x::-webkit-scrollbar { display: none; }

/* Shared phone ergonomics; decorative treatment stays on the home page. */
:focus-visible{outline:3px solid #638372;outline-offset:3px}
.modal header{display:flex;align-items:center;justify-content:space-between;gap:16px}
.modal header h2{overflow-wrap:anywhere;min-width:0}
.modal-close{flex:0 0 44px;width:44px;height:44px;border:0;border-radius:50%;background:#f0f2ed;color:#344139;font-size:25px;line-height:1}
.modal{display:flex;flex-direction:column;overflow:hidden}
.modal .body{overflow:auto;min-height:0;overscroll-behavior:contain;overflow-wrap:anywhere}
.modal header,.modal footer{flex-shrink:0;background:var(--surface)}
.modal footer{flex-wrap:wrap;border-top:1px solid var(--line)}
@media(max-width:720px){
 body{padding-bottom:calc(76px + env(safe-area-inset-bottom,0px))}
 main{min-width:0}img{max-width:100%}
 input:not([type]),input[type=text],input[type=email],input[type=password],input[type=number],input[type=date],input[type=search],input[type=url],input[type=tel],textarea,select{font-size:16px;min-height:48px;border-radius:12px;padding:11px 12px;max-width:100%}
 .btn,.btn.sm,.chip,summary{min-height:44px}
 .btn-row,.row-b{flex-wrap:wrap}.row>*{min-width:0}
 .tpl-preview .fav{width:44px;height:44px}
 .modal-mask{padding:0!important;align-items:end;height:100dvh;max-height:100dvh}
 .modal{max-height:calc(min(var(--dialog-viewport,100dvh),100dvh) - max(16px,env(safe-area-inset-top,0px)))!important;border-radius:22px 22px 0 0;max-width:100%!important}
 .modal header{padding:14px 18px 10px!important}.modal .body{padding:8px 18px 20px!important}
 .modal footer{padding:12px 18px calc(14px + env(safe-area-inset-bottom,0px))!important;gap:10px}
 .modal footer .btn{min-height:48px;flex:1 1 120px}
 #toasts{bottom:calc(90px + env(safe-area-inset-bottom,0px))}
 .hub-menu a{min-height:82px;border-radius:18px}.card,.panel{border-radius:16px}
}
@media(prefers-reduced-motion:reduce){*,*::before,*::after{animation:none!important;transition:none!important;scroll-behavior:auto!important}}
@media(max-width:720px){
 .modal footer{flex-direction:row}
 .tpl-card .btn.sm{min-height:44px}
 .tpl-body .btn-row .btn{min-height:44px}
 button.btn{min-width:44px}
}
