/* ==========================================================================
   tablet-pad.css — 清清童创 H5 Pad 横屏双栏布局优化 (2026-08-01)
   --------------------------------------------------------------------------
   铁律（严格遵守）:
     - 只做布局/UI 覆盖，绝不触碰任何功能逻辑（画布大小、按钮行为、
       结果反显、DOM 结构）。不加任何 DOM 元素、不用 :has() 隐藏逻辑。
     - 只新增覆盖规则，全部置于 @media 断点内，手机(<600px)零影响。
     - 双栏 grid 的 grid-template-areas 必须包含所有子元素
       （result/loading/coach 等），避免被丢进隐式列导致不可见。
     - 左栏超高时内部滚动(max-height+overflow-y)，绝不顶出生成按钮。
   --------------------------------------------------------------------------
   断点:
     @media (min-width:768px)              → 竖屏平板加宽
     @media (min-width:1024px)+landscape   → 横屏：侧边导航 + 双栏
   ========================================================================== */

/* ==== 竖屏平板 (≥768px)：内容容器与底部导航适度加宽 ==== */
@media (min-width: 768px) and (max-width: 1023px) {
  .page {
    max-width: min(94vw, 720px);
  }
  .tab-bar {
    max-width: min(90vw, 600px);
  }
}

/* ==== 横屏平板 (≥1024px + landscape)：底部 TabBar → 左侧导航栏 ==== */
/* 复用成熟方案：TabBar 固定左侧 72px 竖排，内容区右移避开。 */
@media (min-width: 1024px) and (orientation: landscape) {
  .tab-bar {
    position: fixed;
    left: 0 !important;            /* 覆盖 style.css @768+ left:0 !important */
    right: auto !important;        /* 覆盖 style.css @768+ right:0 !important */
    top: 0;
    bottom: 0;
    width: 72px;
    max-width: none;               /* 覆盖 @768+ 520px / @1024+ 600px */
    height: auto;
    margin: 0;
    flex-direction: column;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-4) var(--space-1);
    border-radius: 0 var(--radius-xl) var(--radius-xl) 0;
    box-shadow: var(--surface-glow-purple), 6px 0 24px rgba(91, 59, 184, 0.08);
  }
  .tab-bar .tab-item {
    flex: 0 0 auto;
    width: 56px;
    min-height: 56px;
    align-self: center;
  }
  /* 中间伙伴按钮的浮起/缩放在纵向排列中不再适用，避免与相邻项重叠 */
  .tab-item-middle,
  .tab-item-partner-float {
    transform: none;
  }

  /* 内容区整体右移，避开 72px 侧栏（#page-container 即 .page 本身） */
  #page-container {
    margin-left: 72px;
  }

  /* 横屏加宽容器：覆盖 style.css @1024+ 的 800px，
     为双栏(绘画/涂鸦/故事)+画布提供足够横向空间 */
  #page-container.page {
    max-width: min(calc(100vw - 72px), 1080px);
    margin-right: auto;
  }

  /* 家长模式「回到儿童模式」浮条：移到侧栏右下方，不遮挡内容 */
  .parent-mode-bar {
    left: 84px;
    right: auto;
    bottom: var(--space-4);
  }
}

/* ==== 横屏平板：绘画页 双向网格（修正 style.css 旧类名双栏 + result 显式占位）==== */
@media (min-width: 1024px) and (orientation: landscape) {
  .drawing-body {
    display: grid;
    grid-template-columns: minmax(320px, 420px) 1fr;
    gap: var(--space-4) var(--space-6);
    align-items: start;
    grid-template-areas:
      "coach    coach"
      "input    result"
      "options  result"
      "prompts  result"
      "generate history";
  }
  #coach-pre-guidance-container { grid-area: coach; }
  .drw-clay-input-card          { grid-area: input; }
  .drawing-options              { grid-area: options; }
  .drawing-recent-prompts       { grid-area: prompts; }
  /* 生成按钮：主态 #drawing-generate / 访客态 #drawing-generate-guest 均为 .drw-clay-btn */
  .drawing-body > .drw-clay-btn { grid-area: generate; }
  /* 加载态 + 结果区：右栏上部；历史作品：右栏下部（右栏据此有内容, 平衡左右） */
  .drw-clay-loading,
  .drw-clay-result              { grid-area: result; min-width: 0; }
  .drawing-history              { grid-area: history; min-width: 0; }

  /* 左栏超高时内部滚动，绝不顶出生成按钮 */
  #coach-pre-guidance-container,
  .drawing-options,
  .drawing-recent-prompts {
    min-width: 0;
  }
}

/* ==== 横屏平板：涂鸦页 双栏（左工具操作 | 右画布+结果）====
   画布尺寸由 JS 控制(不碰)，CSS 仅控制双栏布局与显示位置。 */
@media (min-width: 1024px) and (orientation: landscape) {
  .doodle-body {
    display: grid;
    grid-template-columns: minmax(300px, 360px) 1fr;
    gap: var(--space-4) var(--space-6);
    align-items: start;
    max-width: none;
    margin-left: 0;
    margin-right: 0;
    grid-template-areas:
      "coach  coach"
      "tools  canvas"
      "prompt canvas"
      "styles canvas"
      "gen    canvas"
      "result result";
  }
  #coach-pre-guidance-container { grid-area: coach; }
  .ddl-clay-tools        { grid-area: tools; }
  .doodle-prompt-section { grid-area: prompt; }
  .doodle-styles-section { grid-area: styles; }
  .doodle-body > .ddl-clay-btn { grid-area: gen; }
  .doodle-canvas-section { grid-area: canvas; align-self: start; }
  /* 加载态 + 结果区：显式占位画布下方整行，避免丢隐式列 */
  .drw-clay-loading,
  .ddl-clay-result       { grid-area: result; min-width: 0; }
  /* 画布尺寸由 JS 完全控制(不碰)，CSS 不干预 canvas 本身，
     仅让 canvas-section 在右栏正常容纳 */
  .doodle-canvas-section { min-width: 0; }
}

/* ==== 横屏平板：故事页 双栏（左主题+自定义 | 右篇幅+生成+结果）==== */
@media (min-width: 1024px) and (orientation: landscape) {
  .story-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-4) var(--space-6);
    align-items: start;
    grid-template-areas:
      "coach    coach"
      "themes  length"
      "custom  length"
      "generate result"
      "history result";
  }
  #coach-pre-guidance-container { grid-area: coach; }
  .story-input-section  { grid-area: themes; }
  .story-custom-section { grid-area: custom; }
  .story-length-section { grid-area: length; }
  .story-body > .sty-clay-btn,
  .story-body > #story-generate-btn,
  .story-body > #story-generate-btn-guest { grid-area: generate; }
  /* 结果区 + 加载态：显式占位右栏(length 下方)，避免丢隐式列，且填充右栏 */
  .sty-clay-result,
  #story-result,
  .sty-clay-loading,
  #story-loading,
  .drw-clay-loading { grid-area: result; min-width: 0; }
  /* 双栏子块不超出所在列 */
  .story-input-section,
  .story-custom-section,
  .story-length-section { min-width: 0; }
}

/* ==== 横屏平板：伙伴页 消息区/输入条 限宽居中（避免气泡超宽难读）==== */
@media (min-width: 1024px) and (orientation: landscape) {
  .dialog-messages {
    max-width: min(92%, 860px);
    margin-left: auto;
    margin-right: auto;
  }
  .dlg-clay-input-bar,
  .dlg-input-bar,
  #dlg-input-bar {
    max-width: min(92%, 860px);
    margin-left: auto;
    margin-right: auto;
  }
  /* 气泡不无限拉长 */
  .message-bubble {
    max-width: 78%;
  }
  /* 快捷意图卡在横屏下更紧凑 */
  .refinement-option-grid,
  .quick-replies,
  [class*="quick-reply"] {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ==== 横屏平板：绘画页 细节对齐统一 ==== */
@media (min-width: 1024px) and (orientation: landscape) {
  /* 左栏元素水平对齐统一：清除 input/options/按钮 的额外 margin，都贴 grid 列左缘
     (注: options 在 drawing.js 含内联 margin, 需 !important 覆盖) */
  .drw-clay-input-card,
  .drawing-options,
  .drawing-recent-prompts,
  .drw-clay-btn {
    margin-left: 0 !important;
    margin-right: 0 !important;
    width: 100%;
  }
}

/* ==== 横屏平板：涂鸦/故事 左栏元素水平对齐统一 ==== */
@media (min-width: 1024px) and (orientation: landscape) {
  /* 涂鸦左栏 tools/生成按钮 对齐 */
  .ddl-clay-tools {
    margin-left: 0 !important;
    margin-right: 0 !important;
  }
  .doodle-body > .ddl-clay-btn {
    margin-left: 0 !important;
    margin-right: 0 !important;
  }
  /* 故事 generate 按钮 对齐 */
  .story-body > .sty-clay-btn {
    margin-left: 0 !important;
    margin-right: 0 !important;
  }
}

/* ==== 横屏平板：侧边导航后 减少底部为 TabBar 预留的多余留白 ==== */
@media (min-width: 1024px) and (orientation: landscape) {
  .drawing-body,
  .doodle-body,
  .story-body,
  .dialog-container,
  .home-v31-container {
    padding-bottom: var(--space-6);   /* 原 5-6.5rem(80-104px) → 24px，底部无 TabBar */
  }
}

/* ==== 横屏平板：涂鸦 风格卡更紧凑（平衡左栏高度, 保留触控）==== */
@media (min-width: 1024px) and (orientation: landscape) {
  .doodle-style-card {
    padding: var(--space-2) var(--space-1);
    min-height: 66px;
    gap: 2px;
  }
  .doodle-style-icon {
    font-size: 1.35rem;
    line-height: 1;
  }
  .doodle-styles-grid {
    margin-top: var(--space-2);
  }
}

