/* =====================================================================
 * AI 音乐助手「小音」—— 悬浮入口 + 对话面板
 * ---------------------------------------------------------------------
 * 设计约束（和全站一致）：
 *   1) 只用 tokens（--glass / --brand / --panel / --r-* ），不写死颜色 ——
 *      6 套主题 × 5 个年代皮肤都要能看；
 *   2) 面板一律用 flex 纵向布局 + 「滚动区自己滚」，**不碰隐式 grid 列**。
 *      本项目已经栽过一次：容器只写 display:grid 不声明 grid-template-columns 时，
 *      隐式列按 max-content 撑开，在 fixed 层里会静默裁切右侧内容；
 *   3) 层级：悬浮球 78（低于沉浸播放页 80 / 抽屉遮罩 85），面板 130（高于弹窗 120，低于提示 200）。
 * ===================================================================== */

/* ------------------------------ 悬浮入口 ------------------------------ */
.ai-fab {
  position: fixed;
  right: 22px;
  /* 桌面端播放条 bottom:14px + 高 var(--player-h)，悬浮球要落在它上沿之上 */
  bottom: calc(14px + var(--player-h) + 18px);
  z-index: 78;
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid color-mix(in srgb, var(--brand) 40%, transparent);
  background: linear-gradient(140deg, var(--brand), var(--brand-2));
  color: var(--on-brand);
  box-shadow: 0 14px 34px color-mix(in srgb, var(--brand) 32%, transparent), var(--shadow-1);
  transition: transform var(--dur) var(--ease), box-shadow var(--dur), opacity var(--dur);
}
.ai-fab .ic { width: 27px; height: 27px; }
.ai-fab:hover { transform: translateY(-3px) scale(1.04); }
.ai-fab:active { transform: translateY(0) scale(0.97); }
.ai-fab::after {
  /* 呼吸光圈：提示「这里有个助手」，但不抢视觉 */
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 1.5px solid color-mix(in srgb, var(--brand) 46%, transparent);
  animation: aiBreath 3.2s var(--ease) infinite;
  pointer-events: none;
}
@keyframes aiBreath {
  0%, 100% { transform: scale(0.9); opacity: 0.85; }
  55% { transform: scale(1.12); opacity: 0; }
}
/* 沉浸播放页 / 弹窗 / 抽屉打开时把悬浮球让开，别压在别人的界面上。
   :has() 不支持时只是「球还在」，属优雅降级。 */
body:has(.stage:not([hidden])) .ai-fab,
body:has(.modal:not([hidden])) .ai-fab,
body.drawer-open .ai-fab {
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px) scale(0.88);
}
body.ai-open .ai-fab { opacity: 0; pointer-events: none; }

/* ------------------------------ 对话面板 ------------------------------ */
.ai-panel {
  position: fixed;
  right: 22px;
  bottom: calc(14px + var(--player-h) + 18px);
  z-index: 130;
  width: 396px;
  height: min(622px, calc(100vh - var(--player-h) - 130px));
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  border-radius: var(--r-lg);
  border: 1px solid var(--hair);
  background: var(--glass-2);
  backdrop-filter: blur(26px) saturate(1.7);
  -webkit-backdrop-filter: blur(26px) saturate(1.7);
  box-shadow: var(--shadow-3);
  animation: aiPanelIn 0.32s var(--ease-out);
}
.ai-panel[hidden] { display: none; }
@keyframes aiPanelIn {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to { opacity: 1; transform: none; }
}

.ai-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--line);
}
.ai-avatar {
  flex: none;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: linear-gradient(140deg, var(--brand), var(--brand-2));
  color: var(--on-brand);
}
.ai-avatar .ic { width: 20px; height: 20px; }
.ai-head-main { flex: 1; min-width: 0; }
.ai-head-main b { display: block; font-size: 14px; }
.ai-head-main span {
  display: block;
  font-size: 11px;
  color: var(--mute);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ai-dot {
  display: inline-block;
  width: 6px; height: 6px;
  margin-right: 5px;
  border-radius: 50%;
  background: #34d399;
  vertical-align: middle;
}
.ai-dot.local { background: var(--brand); }

/* 消息滚动区：必须自己滚动（外层 overflow:hidden 只负责切圆角） */
.ai-log {
  flex: 1;
  min-height: 0;
  min-width: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.ai-msg { display: flex; gap: 9px; min-width: 0; }
.ai-msg.from-me { flex-direction: row-reverse; }
.ai-bubble {
  max-width: 84%;
  min-width: 0;
  padding: 10px 13px;
  border-radius: 15px;
  font-size: 13.5px;
  line-height: 1.62;
  word-break: break-word;
  white-space: pre-wrap;
}
.ai-msg.from-bot .ai-bubble {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-top-left-radius: 5px;
  color: var(--text);
}
.ai-msg.from-me .ai-bubble {
  background: linear-gradient(140deg, var(--brand), var(--brand-2));
  color: var(--on-brand);
  border-top-right-radius: 5px;
  font-weight: 500;
}
.ai-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
  font-size: 11px;
  color: var(--mute);
}

/* 思考中：三点 */
.ai-typing { display: inline-flex; gap: 4px; align-items: center; height: 18px; }
.ai-typing i {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--brand);
  animation: aiDot 1.05s infinite ease-in-out;
}
.ai-typing i:nth-child(2) { animation-delay: 0.16s; }
.ai-typing i:nth-child(3) { animation-delay: 0.32s; }
@keyframes aiDot {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.45; }
  40% { transform: scale(1); opacity: 1; }
}

/* 结果歌单 */
.ai-result { margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 9px; min-width: 0; }
.ai-result-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 7px;
  font-size: 11.5px;
  color: var(--mute);
}
.ai-song {
  display: grid;
  /* ★ 显式声明列：隐式列会按 max-content 撑开，把标题挤没（本项目已踩过） */
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  padding: 6px 7px;
  border-radius: 10px;
  cursor: pointer;
  transition: background var(--dur);
  min-width: 0;
}
.ai-song:hover { background: var(--panel-3); }
.ai-song img {
  width: 34px; height: 34px;
  border-radius: 9px;
  object-fit: cover;
  background: var(--panel-3);
}
.ai-song .t { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.ai-song .t b { font-size: 12.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-song .t span { font-size: 11px; color: var(--mute); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-song .icon-btn { width: 28px; height: 28px; flex: none; }
.ai-song .icon-btn .ic { width: 15px; height: 15px; }

/* 快捷问句 */
.ai-chips {
  flex: none;
  display: flex;
  gap: 7px;
  padding: 0 14px 10px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.ai-chips::-webkit-scrollbar { display: none; }
.ai-chip {
  flex: none;
  height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  background: var(--panel);
  color: var(--dim);
  font-size: 12px;
  white-space: nowrap;
  transition: color var(--dur), border-color var(--dur), background var(--dur);
}
.ai-chip:hover { color: var(--brand); border-color: color-mix(in srgb, var(--brand) 46%, transparent); background: var(--panel-2); }

/* 输入区 */
.ai-composer {
  flex: none;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--glass-2) 70%, transparent);
}
.ai-input {
  flex: 1;
  min-width: 0;
  height: 42px;
  max-height: 96px;
  padding: 11px 13px;
  border-radius: 13px;
  border: 1px solid var(--line-2);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  resize: none;
  line-height: 1.45;
  transition: border-color var(--dur);
}
.ai-input::placeholder { color: var(--mute); }
.ai-input:focus { outline: none; border-color: color-mix(in srgb, var(--brand) 55%, transparent); }
.ai-send {
  flex: none;
  width: 42px; height: 42px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  background: linear-gradient(140deg, var(--brand), var(--brand-2));
  color: var(--on-brand);
  transition: transform var(--dur), opacity var(--dur);
}
.ai-send .ic { width: 19px; height: 19px; }
.ai-send:hover { transform: translateY(-1px); }
.ai-send[disabled] { opacity: 0.5; transform: none; cursor: not-allowed; }

.ai-foot {
  flex: none;
  padding: 0 14px 11px;
  font-size: 10.5px;
  color: var(--mute);
  line-height: 1.5;
}

/* ------------------------------ 响应式 ------------------------------ */
/* 平板：面板略窄，仍浮在右下 */
@media (max-width: 1023px) {
  .ai-panel { width: 356px; height: min(560px, calc(100vh - var(--player-h) - 122px)); }
}

/* 手机：面板改为全屏（键盘弹起时最稳），悬浮球抬到「迷你播放器 + 标签栏」之上 */
@media (max-width: 767px) {
  .ai-fab {
    right: 14px;
    /* 标签栏 60px + 迷你播放器 56px = 116px，再留 12px 间隙 */
    bottom: 128px;
    width: 52px;
    height: 52px;
  }
  .ai-fab .ic { width: 24px; height: 24px; }
  .ai-panel {
    inset: 0;
    width: auto;
    height: auto;
    border-radius: 0;
    border: none;
  }
  .ai-bubble { max-width: 88%; }
  .ai-log { padding: 12px; }
  .ai-chips { padding: 0 12px 10px; }
  .ai-composer { padding: 9px 10px calc(11px + env(safe-area-inset-bottom, 0px)); }
}

/* 折叠屏外屏等超窄屏 */
@media (max-width: 400px) {
  .ai-fab { width: 48px; height: 48px; }
  .ai-song { grid-template-columns: 30px minmax(0, 1fr) auto; gap: 8px; }
  .ai-song img { width: 30px; height: 30px; border-radius: 8px; }
}

/* 横屏手机（高度很小）：面板别超过可视高 */
@media (max-height: 520px) {
  .ai-panel { height: calc(100vh - 96px); }
}
