/* =========================================================
   响应式细节：手机、平板、横屏与安全区
   ========================================================= */

/* ---------------- 手机 ---------------- */
@media (max-width: 767px) {
  .topbar {
    height: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
    flex-basis: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
    padding-top: env(safe-area-inset-top, 0px);
  }

  .auth-brand {
    padding-top: calc(32px + env(safe-area-inset-top, 0px));
    padding-bottom: 12px;
  }

  .auth-brand h1 { font-size: 29px; }
  .auth-brand .brand-mark { width: 54px; height: 54px; flex-basis: 54px; }
  .auth-brand .brand-mark img { border-radius: 15px; }
  .auth-lead { font-size: 12px; }
  .auth-panel { padding-bottom: calc(28px + env(safe-area-inset-bottom, 0px)); }

  .home-hero { padding: 32px 20px 20px; }
  .hero-copy h2 { font-size: 40px; }

  .hero-actions .btn { flex: 1; min-width: 0; }

  .book-grid { gap: 13px 9px; }

  /* 封面列随卡片宽度伸缩：手机端比原来的固定 112px 更宽，插画不至于太小 */
  .detail-hero {
    grid-template-columns: clamp(104px, 40%, 150px) minmax(0, 1fr);
    gap: 14px;
    padding: 16px;
  }
  .detail-cover-wrap { width: 100%; }
  /* 窄列里缩小封面内的字号，避免书名被裁切 */
  .detail-cover-wrap .book-cover { padding: 11px; }
  /* 书名按封面宽度缩放，避免窄封面里最后一个字被单独挤到第二行 */
  .detail-cover-wrap .book-cover.lg .cover-title {
    font-size: 10.5px;
    font-size: clamp(10.5px, 10cqw, 14px);
  }
  /* 详情页封面插画按封面宽度放大，同时留出书名与页脚的空间 */
  .detail-cover-wrap .book-cover.lg .cover-emoji {
    font-size: clamp(40px, 12vw, 64px);
    font-size: clamp(44px, 48cqw, 72px);
  }
  .detail-cover-wrap .book-cover.lg .cover-kicker { font-size: 8px; }
  .detail-cover-wrap .book-cover.lg .cover-foot { font-size: 8.5px; }
  /* 顶部副标题在小屏会被挤成两行，信息已在上方标签中展示 */
  .detail-info .eyebrow { display: none; }
  .detail-info h2 { font-size: 20px; }
  .detail-actions .btn { min-width: 0; }

  /* 页缩略图在手机上适当放大，避免整页只剩一个小色块 */
  .page-thumb-art {
    width: 60px;
    height: 68px;
    flex-basis: 60px;
    font-size: 27px;
    border-radius: 14px;
  }

  .history-actions .history-view-btn { display: none; }

  .profile-head .logout-btn span { display: none; }
  .profile-head .logout-btn { width: 40px; padding: 0; font-size: 16px; }

  .flow-card { padding: 20px 16px; }
  .flow-card-head h2 { font-size: 23px; }
  .role-grid { gap: 10px; }
  .role-card { min-height: 128px; padding: 16px 14px; }
  .role-card strong { font-size: 19px; }
  .role-card .role-emoji { font-size: 34px; }

  .theme-grid { gap: 7px; }
  .theme-card { min-height: 100px; padding: 11px; }
  .theme-card .tc-emoji { margin-bottom: 12px; }

  .reader-stage {
    padding: 8px 12px 4px;
    gap: 8px;
  }

  .reader-art {
    flex-basis: 34vh;
    min-height: 190px;
    max-height: 300px;
    border-radius: var(--r-lg);
  }

  /* 正文改为紧贴插图顶部排列，消除手机上插图与文字之间的大块空白 */
  .reader-copy { justify-content: flex-start; padding-bottom: 8px; }

  .reader-nav-row .btn { min-height: 40px; font-size: 12px; }
  .reader-tools .btn { min-height: 36px; padding-left: 8px; padding-right: 8px; }

  .reader-top-actions .icon-btn { width: 36px; height: 36px; min-height: 36px; }
}

@media (max-width: 380px) {
  .view-root { padding-left: 12px; padding-right: 12px; }
  .auth-panel { padding-left: 12px; padding-right: 12px; }
  .auth-card { padding: 14px; border-radius: var(--r-lg); }
  .home-top h1 { font-size: 27px; }
  .hero-copy h2 { font-size: 36px; }
  .hero-copy > p:not(.eyebrow) { font-size: 14px; }
  .book-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .book-card-title { font-size: 11.5px; }
  .step-labels { font-size: 9.5px; }
  .role-card small { font-size: 11.5px; }
  .role-card { min-height: 120px; }
  .detail-hero {
    grid-template-columns: clamp(96px, 40%, 118px) minmax(0, 1fr);
    gap: 12px;
    padding: 12px;
  }
  .detail-cover-wrap .book-cover { padding: 9px; }
  .detail-info h2 { font-size: 18px; }
  /* 320px 宽度下四个按钮挤在一行，缩小字号与图标尺寸，避免文字被裁切 */
  .detail-actions { gap: 5px; }
  .detail-actions .btn { min-height: 44px; padding: 6px; font-size: 12.5px; }
  .detail-actions .icon-btn { flex: 0 0 40px; width: 40px; height: 40px; min-height: 40px; font-size: 15px; }
  .reader-text { font-size: 15px; }
  .reader-view.font-lg .reader-text { font-size: 17px; }
  .reader-view.font-xl .reader-text { font-size: 19px; }

  /* 创作流程底部「上一步 + 生成」在 320px 下会挤出卡片，收紧按钮内边距与字号 */
  .flow-actions { gap: 8px; }
  .flow-actions .btn-primary { min-height: 50px; padding-left: 12px; padding-right: 12px; font-size: 15.5px; }
  .flow-actions .btn-ghost { padding: 8px 12px; font-size: 13px; }

  /* 「继续阅读」两个按钮在 320px 下总宽超出卡片，收紧尺寸并允许换行 */
  .continue-actions { gap: 8px; flex-wrap: wrap; }
  .continue-actions .btn { padding: 8px 14px; font-size: 14px; }
  .continue-actions .btn-ghost { padding: 8px 12px; font-size: 12.5px; }

  /* 选中角标移到右上角，避免压住换行后的身份说明文字 */
  .role-card::after { top: 12px; bottom: auto; }
  .role-card small { padding-right: 0; }

  /* 主视觉鲸鱼在 320px 下会压住副标题，缩小并向两侧收拢 */
  .hero-art .whale.w1 { left: 8px; font-size: 32px; }
  .hero-art .whale.w2 { right: 6px; font-size: 38px; }
}

/* 稍宽的手机适当放大「继续阅读」封面，同时保证按钮仍在卡片内 */
@media (min-width: 381px) and (max-width: 767px) {
  .continue-cover { width: 108px; flex-basis: 108px; }
}

/* 手机横屏：阅读器改成左右两栏，优先利用宽度 */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 520px) {
  .app-window[data-mode="reader"] .reader-stage {
    display: grid;
    grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
    gap: 12px;
    overflow: hidden;
    padding: 6px 16px;
  }

  .reader-view .reader-art {
    flex: 1;
    height: auto;
    min-height: 0;
    max-height: none;
  }

  .reader-view .reader-copy { overflow-y: auto; padding: 2px 2px 8px; }
  .reader-view .reader-text { font-size: 14px; line-height: 1.8; }
  .reader-view .reader-page-title { font-size: 21px; }
  .reader-view .reader-art-emoji { font-size: 64px; }
  .reader-view .reader-topbar { padding-top: 4px; padding-bottom: 4px; }
  .reader-view .reader-controls { padding-top: 4px; padding-bottom: 6px; }
  .reader-dots { display: none; }
}

/* ---------------- 平板竖屏 ---------------- */
@media (min-width: 768px) and (max-width: 1023px) {
  .auth-view {
    grid-template-columns: 1fr;
    min-height: 100%;
  }

  .auth-brand {
    padding: 28px 34px 16px;
    min-height: 250px;
  }

  .auth-brand-inner {
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 24px;
    align-items: center;
    max-width: 760px;
  }

  .auth-brand .brand-mark,
  .auth-brand .eyebrow,
  .auth-brand h1,
  .auth-lead {
    grid-column: 1;
  }

  .auth-features {
    grid-column: 2;
    grid-row: 1 / span 5;
    margin-top: 0;
    padding-left: 20px;
    border-left: 1px solid var(--line-soft);
  }

  .auth-panel {
    padding: 20px 30px 34px;
  }

  .auth-card { max-width: 560px; }

  .home-grid { grid-template-columns: 1fr; }
  .home-side { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; position: static; }
  .home-side .tip-card { grid-column: 1 / -1; }

  .book-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }

  .detail-grid { grid-template-columns: 1fr; }
  /* 平板上详情副标题容易只剩一个字换行，主题已经显示在标签里 */
  .detail-info .eyebrow { display: none; }
  .detail-created { font-size: 10px; }

  /* 平板竖屏内容宽度有限，个人中心双列会把设置项挤成竖排文字 */
  .profile-grid { grid-template-columns: 1fr; }

  .flow-aside { display: block; }
  .flow-layout { grid-template-columns: 1fr; }
  .summary-card { position: static; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .summary-card h3 { grid-column: 1 / -1; margin-bottom: 0; }
  .summary-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .summary-tip { grid-column: 1 / -1; margin-top: 2px; }

  .theme-grid { grid-template-columns: repeat(4, 1fr); }

  .reader-stage { grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr); }
}

/* ---------------- 平板横屏 / 桌面 ---------------- */
@media (min-width: 1024px) {
  .home-side { display: flex; flex-direction: column; gap: 14px; }
  .home-side .tip-card { grid-column: auto; }

  .library-toolbar { max-width: 620px; }

  .history-toolbar { max-width: 520px; }

  .reader-guide-panel { width: min(34vw, 420px); }
}

/* ---------------- 大屏 ---------------- */
@media (min-width: 1440px) {
  .app-window {
    width: min(1240px, calc(100vw - 64px));
    height: min(900px, calc(100dvh - 64px));
    border-radius: 36px;
  }

  :root { --sidebar-w: 256px; }
}

/* ---------------- 触摸设备 ---------------- */
@media (hover: none) {
  .btn:hover,
  .icon-btn:hover,
  .book-card-cover:hover,
  .book-card-title:hover,
  .nav-item:hover,
  .quick-item:hover,
  .page-thumb:hover,
  .history-item:hover,
  .reader-option:hover {
    transform: none;
  }
}

/* ---------------- 高对比度 ---------------- */
@media (prefers-contrast: more) {
  :root {
    --line-soft: rgba(255, 255, 255, 0.22);
    --line: rgba(255, 215, 112, 0.48);
    --muted: #cdd8f2;
    --muted-2: #aab9dc;
  }
}
