/* ========================================================================
   首页：AI 对话入口 hero + 抽卡推荐
   ======================================================================== */
.hero {
  position: relative;
  min-height: calc(100vh - 36px);
  display: flex;
  align-items: center;
  padding-block: clamp(18px, 4vw, 42px) var(--space-6);
  overflow: hidden;
  transition: padding .25s var(--ease);
}
body.ai-active .hero { padding-block: clamp(14px, 3vw, 28px) var(--space-5); }
/* 背景画布：柔和色面 + 细网格（夜间 TUI 感），非纯白 */
.hero::before {
  content: ""; position: absolute; inset: 0; z-index: -1;
  background:
    radial-gradient(60% 70% at 18% 0%, var(--accent-soft), transparent 70%),
    radial-gradient(50% 60% at 100% 30%, var(--accent-2-soft), transparent 70%);
}
.hero::after {
  content: ""; position: absolute; inset: 0; z-index: -1; opacity: .35;
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 44px 44px;
  -webkit-mask-image: radial-gradient(70% 60% at 50% 30%, #000, transparent 75%);
          mask-image: radial-gradient(70% 60% at 50% 30%, #000, transparent 75%);
}
.hero__inner {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  box-sizing: border-box;
}
.hero h1 {
  font-size: clamp(28px, 5vw, var(--fs-2xl));
  letter-spacing: -.01em; margin-bottom: var(--space-3);
}
.hero__lead { font-size: var(--fs-lg); color: var(--text-muted); margin-bottom: var(--space-6); }

/* AI 输入框：放在对话区下方，作为当前会话的输入栏 */
.ai-box {
  width: 100%;
  box-sizing: border-box;
  margin-top: var(--space-4);
  padding: 16px 18px; border-radius: var(--radius);
  background: rgb(var(--glass) / .88); backdrop-filter: blur(12px);
  border: 1px solid var(--line);
  box-shadow: 0 12px 40px rgb(var(--shadow) / .15);
  position: sticky; bottom: var(--space-3); z-index: 5;
}
.ai-box textarea {
  display: block; width: 100%; resize: none; border: 0; background: transparent;
  color: var(--text); font-family: var(--font-sans); font-size: var(--fs-base);
  line-height: 1.6; min-height: 28px; max-height: 140px;
}
.ai-box textarea:focus { outline: none; }

.ai-note {
  margin-top: var(--space-2); font-family: var(--font-mono);
  font-size: var(--fs-xs); color: var(--text-muted);
}
.ai-note b { color: var(--warn); font-weight: 600; }

.chips { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-top: var(--space-4); }
.chips--samples {
  flex-wrap: nowrap;
  overflow: hidden;
  padding-bottom: 2px;
  margin: var(--space-4) 0 var(--space-2);
}
.chips--samples .chip { flex: 0 0 auto; }
.chip {
  padding: 7px var(--space-3); border-radius: var(--radius-pill);
  border: 1px solid var(--line); background: var(--card);
  color: var(--text-muted); font-size: var(--fs-sm); cursor: pointer;
  white-space: nowrap;
  transition: all .15s var(--ease);
}
.chip:hover { color: var(--text); border-color: var(--accent); background: var(--accent-soft); }

/* 手机首屏专用分类速览：桌面已有完整推荐网格，默认不显示 */
.home-tags { display: none; }
.home-tags__stat { font-size: var(--fs-xs); color: var(--text-muted); margin-right: 2px; }

/* ======================================================================
   AI 结果区：推荐/搜索时展示可点小卡片；参数/单板类直接弹大卡片
   ====================================================================== */
.ai-result {
  margin-top: var(--space-4);
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); overflow: hidden;
  animation: ai-fadein .2s var(--ease);
}
@keyframes ai-fadein { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; } }

.ai-result__label {
  padding: var(--space-2) var(--space-4);
  font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--text-muted);
  background: var(--surface); border-bottom: 1px solid var(--line);
}

.ai-result__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1px; background: var(--line);
}

/* 结果小卡片（可点，触发大卡片弹出） */
.ai-res-card {
  display: flex; flex-direction: column;
  background: var(--card); border: 0; cursor: pointer; text-align: left;
  transition: background-color .14s var(--ease);
}
.ai-res-card:hover { background: var(--accent-soft); }
.ai-res-card img { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; }
.ai-res-name {
  padding: var(--space-2) var(--space-3) 2px;
  font-size: var(--fs-sm); font-weight: 700; line-height: 1.3;
}
.ai-res-sum {
  padding: 0 var(--space-3) var(--space-3);
  font-size: var(--fs-xs); color: var(--text-muted); line-height: 1.4;
}

@media (max-width: 640px) {
  .ai-result__grid { grid-template-columns: repeat(2, 1fr); }
}

/* ── 对话区（Claude 风格：用户气泡右，AI 纯文字左） ──────── */
.ai-chat {
  width: 100%;
  box-sizing: border-box;
  margin-top: 0; display: flex; flex-direction: column; gap: var(--space-5);
  min-height: clamp(430px, 70vh, 760px); max-height: min(78vh, 820px);
  overflow-y: auto; overscroll-behavior: contain;
  padding: 0;
  border: 0; border-radius: 0; background: transparent; backdrop-filter: none; box-shadow: none;
  scroll-behavior: smooth;
}
.ai-chat[hidden] { display: none; }

.ai-welcome {
  padding: 0 0 var(--space-2); border: 0; border-radius: 0; background: transparent;
}
.ai-welcome__hero {
  max-width: 920px; font-size: clamp(30px, 3.2vw, 46px);
  line-height: 1.12; letter-spacing: -.02em; font-weight: 900; margin: 0 0 16px;
}
.ai-welcome__title { font-size: var(--fs-lg); font-weight: 800; margin-bottom: var(--space-2); }
.ai-welcome__text { max-width: none; color: var(--text-muted); line-height: 1.7; font-size: var(--fs-base); }
/* 固定 2 行高度 + 溢出隐藏：小贴士文字长短不一，打字机效果换到长/短文案时
   不会撑高或收缩容器，避免把下面的输入框顶得上下移动 */
.ai-tip { height: 3.4em; overflow: hidden; }
.ai-tip__prefix { color: var(--accent); font-weight: 700; }
.ai-tip__cursor {
  display: inline-block; width: .58em; height: 1.15em; margin-left: 2px;
  transform: translateY(.18em); background: var(--accent);
  animation: ai-cursor-blink .85s steps(1) infinite;
}
@keyframes ai-cursor-blink { 50% { opacity: 0; } }
.ai-welcome .chips { margin-top: var(--space-4); }

.ai-draw {
  width: 100%;             /* 与输入框/示例同宽，视觉对齐不违和 */
  margin: 0 auto;
}
body.ai-active .ai-draw { display: none; }
/* HTML 包含全库卡片；随机脚本完成前全部隐藏，避免首屏闪出 376 张卡片。 */
#draw-grid.is-pending .card-small { display: none !important; }
/* 推荐区由 draw.js 精确控制四张卡片的显隐；不能再按 DOM 序号隐藏，
   因为脚本会把选中的卡片移动到末尾。 */
.ai-draw .card-grid { max-height: none; overflow: visible; }
/* #ai-chat 平时给对话流预留 ~70vh；但首页未开始对话时里面只有欢迎语，
   这个大高度会撑高并在居中布局下把标题挤出可视区。首屏态清掉它。 */
body[data-page="home"]:not(.ai-active) #ai-chat { min-height: 0; max-height: none; overflow: visible; }

/* 对话态是一块固定在当前视口内的工作区：消息区独立滚动，输入栏始终占据底部一行。
   不再让消息内容参与整页高度计算，否则第二轮起会把输入框持续往下推。 */
body[data-page="home"].ai-active {
  height: 100dvh;
  min-height: 100dvh;
  overflow: hidden;
}
body[data-page="home"].ai-active main {
  height: 100%;
  min-height: 0;
  overflow: hidden;
}
/* 进入 AI 对话后，顶栏退化为左右两组紧凑浮动按钮，不再像一条横向栏占住首行。 */
body[data-page="home"].ai-active .topbar {
  padding: 8px 16px;
  gap: var(--space-2);
}
body[data-page="home"].ai-active .brand {
  padding: 4px;
}
body[data-page="home"].ai-active .brand__text {
  display: none;
}
body[data-page="home"].ai-active .topbar__tools .fab {
  width: 32px; height: 32px;
}
body[data-page="home"].ai-active .topnav__link {
  height: 32px;
  padding-inline: 10px;
}
body[data-page="home"].ai-active .hero {
  height: 100%;
  min-height: 0;
  align-items: stretch;
  padding-block:
    calc(52px + env(safe-area-inset-top, 0px))
    calc(36px + env(safe-area-inset-bottom, 0px));
  overflow: hidden;
}
/* 宽屏两侧有足够空白容纳浮动按钮，消息内容可以真正贴到视口顶边。 */
@media (min-width: 1440px) {
  body[data-page="home"].ai-active .hero {
    padding-top: env(safe-area-inset-top, 0px);
  }
}
body[data-page="home"].ai-active .hero__inner {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: var(--space-3);
  overflow: hidden;
}
/* 顶部画布仍由消息区占满，但欢迎标题自身稍微下沉，避免紧贴视口边缘。 */
body[data-page="home"].ai-active .ai-welcome {
  padding-top: 20px;
}
body[data-page="home"].ai-active #ai-chat {
  min-height: 0;
  max-height: none;
  height: auto;
  overflow-y: auto;
  padding-bottom: var(--space-2);
  scroll-padding-block: var(--space-2);
}
body[data-page="home"].ai-active .ai-box {
  position: relative;
  bottom: auto;
  align-self: end;
  margin: 0;
}
/* 会话开始后这些首屏入口让位给消息。 */
body[data-page="home"].ai-active .chips--samples,
body[data-page="home"].ai-active .ai-draw,
body[data-page="home"].ai-active .home-tags { display: none; }
/* 备案在对话态保留为底部轻量悬浮信息；hero 已为它预留空间，不覆盖输入栏。 */
body[data-page="home"].ai-active .site-footer {
  display: flex;
  position: fixed;
  left: 50%;
  bottom: calc(6px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 3;
  padding: 0 var(--space-3);
  width: max-content;
  max-width: calc(100vw - 32px);
  flex-wrap: nowrap;
  white-space: nowrap;
  font-size: 10px;
  line-height: 1.4;
}

/* 首屏纯画布：关掉 hero 的渐变色块 + 网格装饰，整屏只有一层背景色，干净 */
body[data-page="home"]:not(.ai-active) .hero::before,
body[data-page="home"]:not(.ai-active) .hero::after { display: none; }

/* ==== 首页布局：能一屏就一屏（上部起笔、向下展开），装不下就正常翻页（不裁内容）====
   body 至少一屏高、竖向 flex；main/hero 用 flex:1 0 auto（可长大、不收缩），
   内容超出视口时页面自然出现滚动条，绝不重叠或截断。 */
body[data-page="home"]:not(.ai-active) {
  min-height: 100dvh;
  display: flex; flex-direction: column;
}
body[data-page="home"]:not(.ai-active) main {
  flex: 1 0 auto;
  display: flex; flex-direction: column;
  padding-top: 60px;                 /* 避开固定顶栏 */
}
body[data-page="home"]:not(.ai-active) .hero {
  flex: 1 0 auto;
  display: flex; flex-direction: column; justify-content: flex-start;
  align-items: stretch;
  padding-block: clamp(52px, 8vh, 76px) var(--space-6);
  overflow: visible;                 /* 不裁内容（装饰已关，无需裁切） */
}
body[data-page="home"]:not(.ai-active) .hero__inner {
  display: flex; flex-direction: column; gap: clamp(18px, 2.4vh, 28px);
  width: 100%;
}
/* 首屏由父级 gap 统一节奏，避免 chips / 输入框 / 推荐区各自 margin 叠加。 */
body[data-page="home"]:not(.ai-active) .ai-welcome { padding-bottom: 0; }
body[data-page="home"]:not(.ai-active) .chips--samples,
body[data-page="home"]:not(.ai-active) .ai-box,
body[data-page="home"]:not(.ai-active) .ai-draw { margin: 0; }
body[data-page="home"]:not(.ai-active) .ai-tip { height: 1.7em; }
body[data-page="home"]:not(.ai-active) .site-footer {
  position: static; left: auto; bottom: auto; transform: none;  /* 覆盖 base 的 fixed，回到流内贴底 */
  flex: 0 0 auto;
  padding: var(--space-2) var(--space-4) calc(var(--space-2) + env(safe-area-inset-bottom, 0px));
}
.ai-turn { display: flex; flex-direction: column; gap: var(--space-3); animation: ai-turn-in .22s var(--ease); }
@keyframes ai-turn-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.ai-turn__q { display: flex; justify-content: flex-end; }
.ai-turn__q span {
  max-width: 72%; padding: var(--space-2) var(--space-4);
  background: var(--surface-2); color: var(--text);
  border-radius: 18px;
  font-size: var(--fs-base); line-height: 1.6;
}

.ai-turn__a {
  max-width: 92%;
  font-size: var(--fs-base); line-height: 1.8; color: var(--text);
}
.ai-turn__a p { margin: 0 0 .65em; }
.ai-turn__a ul, .ai-turn__a ol { margin: .35em 0 .75em 1.35em; padding: 0; }
.ai-turn__a ul { list-style: none; }
.ai-turn__a ul > li { position: relative; }
.ai-turn__a ul > li::before {
  content: "•";
  position: absolute;
  right: calc(100% + .65em);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-weight: 400;
}
.ai-turn__a table {
  width: 100%; margin: .6em 0 1em; border-collapse: collapse;
  font-size: var(--fs-sm); background: var(--card); border: 1px solid var(--line);
}
.ai-turn__a th, .ai-turn__a td { padding: 7px 9px; border: 1px solid var(--line); text-align: left; vertical-align: top; }
.ai-turn__a th { background: var(--surface); font-weight: 700; }
.ai-turn__a code { font-family: var(--font-mono); font-size: .92em; background: var(--surface); padding: 1px 4px; border-radius: 5px; }
.ai-turn__meta {
  margin-top: var(--space-3); color: var(--text-muted); font-family: var(--font-mono);
  font-size: var(--fs-xs); border-top: 1px dashed var(--line); padding-top: var(--space-2);
}
.ai-turn__a .btn { margin-top: var(--space-3); }
/* 首页不重复显示「AI智能问答」标语，也不为它保留空白。 */
.ai-welcome .eyebrow { display: none; }

/* AI 回答里内嵌的开发板图片 */
.ai-turn__a .ai-inline-img {
  max-width: 280px; width: 100%; height: auto; display: block;
  margin: var(--space-2) 0; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface-2); cursor: zoom-in;
  transition: border-color .15s var(--ease);
}
.ai-turn__a .ai-inline-img:hover { border-color: var(--accent); }
/* 分隔线 / 引用 */
.ai-turn__a hr { border: 0; border-top: 1px solid var(--line); margin: var(--space-3) 0; }
.ai-turn__a blockquote {
  margin: var(--space-2) 0; padding: 2px 0 2px var(--space-3);
  border-left: 3px solid var(--accent); color: var(--text-muted);
}
.ai-turn__a blockquote p { margin: 0; }

.ai-action-status {
  display: inline-flex; align-items: center; gap: 8px;
  margin-top: var(--space-3); color: var(--text-muted);
  font-family: var(--font-mono); font-size: var(--fs-xs);
}
.ai-action-status span {
  width: 8px; height: 8px; border-radius: 50%; background: var(--accent);
  box-shadow: 0 0 0 0 var(--accent-soft); animation: ai-dot-pulse 1s infinite ease-in-out;
}
.ai-action-status.is-done span { background: var(--good); animation: none; }
@keyframes ai-dot-pulse { 50% { transform: scale(1.45); opacity: .55; } }

.ai-inline-cards {
  margin-top: var(--space-4); padding-top: var(--space-3);
  border-top: 1px dashed var(--line);
}
.ai-inline-cards__label {
  font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--text-muted);
  margin-bottom: var(--space-2);
}
.ai-inline-cards__grid {
  margin-top: var(--space-2);
}

.ai-thinking {
  display: grid; grid-template-columns: 34px 1fr; gap: var(--space-3); align-items: start;
  max-width: 96%; padding: var(--space-3); border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--card);
}
.ai-thinking__orb {
  width: 28px; height: 28px; border-radius: 50%; position: relative;
  background: radial-gradient(circle at 35% 30%, var(--accent-2), var(--accent) 58%, transparent 60%);
  box-shadow: 0 0 0 0 rgb(var(--shadow) / .2), 0 0 28px var(--accent-soft);
  animation: ai-orb 1.35s infinite ease-in-out;
}
.ai-thinking__orb::after {
  content: ""; position: absolute; inset: -5px; border-radius: inherit;
  border: 1px solid var(--accent); opacity: .45; animation: ai-ring 1.35s infinite ease-out;
}
@keyframes ai-orb { 0%,100% { transform: scale(.92) rotate(0deg); } 50% { transform: scale(1.08) rotate(18deg); } }
@keyframes ai-ring { from { transform: scale(.65); opacity: .55; } to { transform: scale(1.35); opacity: 0; } }
.ai-thinking__head { display: flex; justify-content: space-between; gap: var(--space-3); align-items: center; }
.ai-thinking__head b { font-weight: 700; }
.ai-thinking__time { font-family: var(--font-mono); color: var(--text-muted); font-size: var(--fs-xs); }
.ai-thinking__status { color: var(--text-muted); font-size: var(--fs-sm); margin-top: 2px; }
.ai-thinking__bar { height: 4px; margin-top: var(--space-3); border-radius: var(--radius-pill); overflow: hidden; background: var(--surface-2); }
.ai-thinking__bar i {
  display: block; width: 42%; height: 100%; border-radius: inherit;
  background: linear-gradient(90deg, transparent, var(--accent), var(--accent-2), transparent);
  animation: ai-bar 1.1s infinite ease-in-out;
}
@keyframes ai-bar { from { transform: translateX(-110%); } to { transform: translateX(250%); } }
.ai-thinking__details { margin-top: var(--space-2); color: var(--text-muted); font-size: var(--fs-xs); }
.ai-thinking__details summary { cursor: pointer; color: var(--accent); }
.ai-thinking__details ul { margin-bottom: 0; }

@media (max-width: 900px) {
  .hero { align-items: flex-start; }
  /* 普通首屏叠加 main 的 60px 顶部留白；对话态没有这层，单独预留完整安全区。 */
  body[data-page="home"]:not(.ai-active) .hero { padding-top: 44px; }
  body[data-page="home"].ai-active .hero {
    padding-top: calc(52px + env(safe-area-inset-top, 0px));
  }
}

@media (max-width: 640px) {
  .ai-turn__q span { max-width: 88%; }
  /* 手机：隐藏抽卡推荐(155 张卡片太占地)，改用底部的分类速览胶囊 */
  .ai-draw { display: none; }
  /* 首屏内容整组居中（骨架已是全局的弹性列，这里只做手机的居中/文案对齐） */
  body[data-page="home"]:not(.ai-active) .ai-welcome { text-align: center; }
  body[data-page="home"]:not(.ai-active) .ai-tip { height: 3.4em; }
  /* 左对齐后 home.js 才能准确判断剩余宽度，放不下的示例会被移除，
     不再因居中溢出而把首尾按钮各裁掉一截。 */
  body[data-page="home"]:not(.ai-active) .chips--samples { justify-content: flex-start; }
  /* 分类速览：手机首屏显示，靠近底部，填掉下半屏空白 */
  body[data-page="home"]:not(.ai-active) .home-tags {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
    gap: var(--space-2); padding: 0 var(--space-4);
  }
  /* 装饰背景（色块+网格）按旧矮盒子调的，撑满一屏后上下不统一，手机上关掉只留纯色 */
  body[data-page="home"]:not(.ai-active) .hero::before,
  body[data-page="home"]:not(.ai-active) .hero::after { display: none; }
  body[data-page="home"]:not(.ai-active) .site-footer { font-size: 10px; }
}
