/* ============================================================
   灰大叔漫剧工作台 · 手机适配层  mobile.css
   仅作用于 ≤768px 视口，桌面端零影响。
   必须在所有样式之后引入（index.html 最后一个 link）。
   ============================================================ */

@media (max-width: 768px) {

  /* ---------- 0. 基础：防横向溢出、防 iOS 字号自动放大 ---------- */
  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  body {
    overflow-x: hidden;
    padding-bottom: 32px; /* 给固定备案栏留位 */
  }

  /* iOS Safari 在 input 字号 <16px 时会自动放大整页，这里统一抬到 16px */
  input,
  textarea,
  select {
    font-size: 16px !important;
    line-height: 1.45;
  }

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

  pre {
    white-space: pre-wrap;
    word-break: break-word;
  }

  /* 长英文 / 长链接不撑破容器 */
  .book-asset-card p,
  .book-prefix-card p,
  .book-modal-body {
    overflow-wrap: anywhere;
  }

  /* ---------- 1. 工作台顶栏 ---------- */
  .book-topbar {
    flex-wrap: wrap;
    align-items: center;
    gap: 7px;
    min-height: 0;
    padding: 8px 12px;
  }

  /* 面包屑独占一行，永不竖排 */
  .book-breadcrumb {
    flex: 1 1 100%;
    min-width: 0;
    flex-wrap: nowrap;
    white-space: nowrap;
    gap: 6px;
    font-size: 12px;
  }

  .book-breadcrumb > * {
    flex: 0 0 auto;
  }

  .book-breadcrumb > strong {
    flex: 0 1 auto;
    min-width: 0;
    max-width: 56vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .book-top-project-manage {
    flex: 0 0 auto;
    margin-left: 4px;
    padding: 4px 9px;
    font-size: 11px;
    letter-spacing: 0;
    white-space: nowrap;
  }

  /* 动作区一行横滚，按钮不再叠成三行 */
  .book-top-actions {
    flex: 1 1 100%;
    flex-wrap: nowrap;
    justify-content: flex-start;
    gap: 6px;
    padding: 1px 0 3px;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .book-top-actions::-webkit-scrollbar {
    display: none;
  }

  .book-top-actions > * {
    flex: 0 0 auto;
  }

  .book-top-actions > span {
    display: none;
  }

  .book-top-actions .book-icon-button,
  .book-top-actions .book-secondary,
  .book-top-actions .book-primary {
    min-height: 34px;
    padding: 0 10px;
    font-size: 12px;
    white-space: nowrap;
  }

  .book-top-actions .acct-btn {
    min-height: 34px;
  }

  /* 顶栏右侧的出图档位组别被压扁 */
  .book-res-quick {
    min-height: 34px;
  }

  /* 右侧轻微渐隐，提示这一行可以横向滑动 */
  .book-top-actions {
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 18px), transparent 100%);
    mask-image: linear-gradient(to right, #000 calc(100% - 18px), transparent 100%);
  }

  /* ---------- 2. 侧栏 → 顶部横向 Tab ---------- */
  .book-workbench {
    display: block;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  .book-sidebar {
    position: sticky;
    top: 0;
    z-index: 8;
    display: block;
    padding: 7px 10px 5px;
    border-right: 0;
    border-bottom: 1px solid #29414b;
    backdrop-filter: blur(10px);
  }

  .book-brand {
    padding: 0 2px 7px;
    gap: 8px;
  }

  .book-logo {
    width: 30px;
    height: 30px;
    font-size: 15px;
  }

  .book-brand b {
    font-size: 13px;
  }

  .book-brand small {
    margin-top: 2px;
    font-size: 8px;
  }

  .book-project-switch,
  .book-sidebar-bottom,
  .book-nav-label {
    display: none;
  }

  /* 导航标签横滚，字号放大到可点 */
  .book-nav {
    display: flex;
    gap: 6px;
    padding-bottom: 2px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .book-nav::-webkit-scrollbar {
    display: none;
  }

  .book-nav button {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    flex: 0 0 auto;
    min-width: 0;
    min-height: 38px;
    padding: 0 13px;
    font-size: 13px;
    white-space: nowrap;
    border-radius: 10px;
  }

  .book-nav button span {
    font-size: 13px;
  }

  .book-nav button b {
    display: none;
  }

  /* ---------- 3. 主内容区 ---------- */
  .book-main {
    overflow: visible;
  }

  .book-content {
    max-width: 100%;
    padding: 14px 12px 28px;
  }

  /* 分段选择器（如章节风格「有系统 · Q版」）窄屏塞不下，改横滚不换行 */
  .book-segment {
    flex-wrap: nowrap;
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .book-segment::-webkit-scrollbar {
    display: none;
  }

  .book-segment button {
    flex: 0 0 auto;
    min-height: 32px;
    padding: 0 11px;
    font-size: 11px;
    white-space: nowrap;
  }

  /* 分镜 / 导出等操作条同理 */
  .book-segmented,
  .book-toolbar,
  .book-filter-bar {
    flex-wrap: nowrap;
    max-width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .book-page-heading {
    display: block;
    margin-bottom: 16px;
  }

  .book-page-heading h1 {
    margin: 5px 0;
    font-size: 21px;
    letter-spacing: -.2px;
  }

  .book-page-heading p {
    font-size: 12px;
    line-height: 1.6;
  }

  .book-heading-actions,
  .book-card-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 6px;
  }

  /* 两栏 / 多栏布局一律单列 */
  .book-overview-grid,
  .book-lower-grid,
  .book-scene-layout,
  .book-storyboard-layout,
  .book-rule-grid,
  .book-asset-grid,
  .asset-tile-grid,
  .manga-asset-grid {
    grid-template-columns: 1fr !important;
  }

  /* 流程步骤横滚而不是挤成条 */
  .book-workflow {
    gap: 8px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .book-workflow::-webkit-scrollbar {
    display: none;
  }

  .book-workflow button {
    flex: 0 0 auto;
    min-width: 74%;
    padding: 10px;
  }

  .book-workflow em {
    display: none;
  }

  .book-panel {
    padding: 14px;
  }

  .book-script-card textarea {
    min-height: 200px;
  }

  /* 资产卡：图片比例不变，文字可读 */
  .book-asset-card,
  .asset-tile {
    padding: 12px;
  }

  /* 竖版设定图在手机上会一张占满整屏，限高让一屏能看两张 */
  .book-asset-card > a,
  .book-asset-card > button:not(.book-asset-delete) {
    display: block;
    overflow: hidden;
    border-radius: 10px;
  }

  .book-asset-card img {
    aspect-ratio: auto !important;
    width: 100%;
    height: auto;
    max-height: 46vh;
    object-fit: contain;
    background: #0d171c;
    border-radius: 10px;
  }

  /* 未生成图片的占位块同样限高 */
  .book-asset-card > button[style*="aspect-ratio"] {
    max-height: 40vh;
    min-height: 110px;
  }

  /* 卡片内操作按钮：触屏点击目标放大 */
  .book-asset-card button:not(.book-asset-delete) {
    min-height: 38px !important;
    font-size: 12px !important;
    padding-left: 6px !important;
    padding-right: 6px !important;
  }

  /* 删除按钮：24px 在触屏上太难点，放大并常显 */
  .book-asset-card > .book-asset-delete {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 3;
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    min-height: 34px !important;
    padding: 0 !important;
    border: 1px solid #d89587;
    border-radius: 50%;
    font-size: 15px;
    line-height: 1;
    opacity: 1;
    overflow: visible;
    box-shadow: 0 2px 8px #0000002e;
  }

  .book-asset-card h3 {
    font-size: 15px;
  }

  .book-asset-card p {
    min-height: 0;
    font-size: 12px;
  }

  /* 项目库 / 资产库这类全屏弹窗留窄边 */
  .book-gallery-overlay {
    padding: 10px;
  }

  .book-asset-toolbar,
  .book-storyboard-meta {
    flex-wrap: wrap;
    gap: 8px;
  }

  /* 资产页头部动作按钮换行 */
  .asset-workbench-head {
    display: block;
  }

  .asset-head-actions {
    width: 100%;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 12px;
  }

  /* 资产页 tab（人物/场景/道具）横滚 */
  .asset-tabs,
  .manga-asset-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .asset-tabs::-webkit-scrollbar,
  .manga-asset-tabs::-webkit-scrollbar {
    display: none;
  }

  .asset-tabs > *,
  .manga-asset-tabs > * {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  /* 场景 / 分镜左右两栏，单列后要取消最小高度，避免大片空白 */
  .book-scene-list,
  .book-scene-detail,
  .book-video-list,
  .book-video-detail {
    min-height: 0;
  }

  /* 卡片上浮按钮在触屏上过大，收一点 */
  .book-primary,
  .book-secondary,
  .book-icon-button,
  .book-text-button {
    border-radius: 8px;
  }

  /* ---------- 4. 弹窗 → 底部抽屉 ---------- */
  .book-modal {
    place-items: end center; /* grid 容器：贴底居中，手机上更像原生抽屉 */
    padding: 0;
  }

  .book-modal-card {
    width: 100% !important;
    max-width: 100%;
    max-height: 90vh;
    border-radius: 16px 16px 0 0 !important;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  .book-modal-head {
    position: sticky;
    top: 0;
    z-index: 3;
    padding: 13px 14px;
    backdrop-filter: blur(10px);
  }

  .book-modal-head h2 {
    font-size: 16px;
  }

  .book-modal-head > button,
  #bookRulesClose,
  #bookApiClose,
  #bookImageSettingsClose,
  #bookThemeClose,
  #bookExportClose,
  #bookV3SkillClose {
    min-width: 40px;
    min-height: 40px;
    font-size: 20px;
  }

  .book-modal-body {
    padding: 13px;
    font-size: 12.5px;
    line-height: 1.7;
  }

  /* 底部按钮条要有实底，否则滚动内容会透上来和按钮叠在一起 */
  .book-modal-actions {
    position: sticky;
    bottom: 0;
    z-index: 2;
    gap: 8px;
    padding: 10px 0 4px;
    background: #fffdf7f2;
    backdrop-filter: blur(10px);
    box-shadow: 0 -10px 18px -12px #4b5b4a40;
  }

  /* 有底部按钮条的弹窗，给正文留出按钮高度，最后一行才不被压住 */
  .book-modal-card:has(.book-modal-actions) .book-modal-body {
    padding-bottom: 82px;
  }

  .book-modal-actions button {
    min-height: 42px;
    flex: 1;
    font-size: 13px;
  }

  /* 弹窗内表格 / 代码块可横滚 */
  .book-modal-body table,
  .book-modal-body pre,
  .book-modal-body code {
    display: block;
    max-width: 100%;
    overflow-x: auto;
  }

  /* ---------- 5. 底部备案栏：首页常驻，工作台内让位 ---------- */
  .site-beian-bar {
    z-index: 70;
    padding: 5px 8px;
    font-size: 10px;
    gap: 5px;
    padding-bottom: calc(5px + env(safe-area-inset-bottom, 0px));
  }

  /* 工作台是登录后的全屏内页，备案号在首页已展示，
     这里隐藏它，把底部 30px 还给操作区，也避免压住「生成图片」等按钮 */
  body:has(#bookWorkbench:not([hidden])) .site-beian-bar {
    display: none;
  }

  body:has(#bookWorkbench:not([hidden])) {
    padding-bottom: 0;
  }

  /* ---------- 6. 登录 / 注册面板 ---------- */
  .auth-gate {
    min-height: 100vh;
    padding: 16px;
  }

  .auth-panel {
    width: 100%;
    padding: 22px 18px;
  }

  .auth-panel h1 {
    font-size: 20px;
  }

  .auth-panel input,
  .auth-panel .wb-btn.wide {
    min-height: 46px;
  }

  /* ---------- 7. 首页模式入口卡 ---------- */
  .mode-card,
  .mode-entry,
  .wb-mode-card {
    padding: 16px;
  }

  /* ---------- 8. 触屏：去掉悬停位移 ---------- */
  @media (hover: none) {
    .book-workflow button:hover,
    .mode-card:hover,
    .book-panel:hover {
      transform: none !important;
    }
  }
}

/* ---------- 9. 超窄屏（≤360px，如老款安卓） ---------- */
@media (max-width: 360px) {
  .book-content {
    padding: 10px 8px 44px;
  }

  .book-nav button {
    padding: 0 10px;
    font-size: 12px;
  }

  .book-top-actions .book-icon-button,
  .book-top-actions .book-secondary,
  .book-top-actions .book-primary {
    padding: 0 8px;
    font-size: 11px;
  }
}

/* ---------- 10. 横屏手机（高度很小时压缩头部） ---------- */
@media (max-width: 900px) and (max-height: 460px) and (orientation: landscape) {
  .book-sidebar {
    position: static;
  }

  .book-brand {
    display: none;
  }

  .book-modal-card {
    max-height: 96vh;
  }
}
