/* ========================================
   AI 对话 / 弹窗 / 播放器 — Lunati（布局与卡片见 layout.css）
   ======================================== */

/* ═══════════════════════════════════════
   AI Assistant Layout
   ═══════════════════════════════════════ */
.ai-full {
  height: 100%;
  display: flex;
  overflow: hidden;
  position: relative;
  background:
    radial-gradient(circle at 18% 0%, rgba(215, 180, 106, 0.08), transparent 30%),
    linear-gradient(180deg, #0d0e13, #111219);
}

[data-theme="light"] .ai-full {
  background:
    radial-gradient(circle at 18% 0%, rgba(215, 180, 106, 0.13), transparent 30%),
    linear-gradient(180deg, #f7f5f0, #eae5da);
}

.ai-sidebar {
  width: min(320px, 86vw);
  background: rgba(16, 17, 22, 0.96);
  border-right: 1px solid var(--accent-muted);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  z-index: 4;
  position: relative;
  box-shadow: 10px 0 34px rgba(0, 0, 0, 0.2);
  transition: width var(--duration-slow) var(--ease-in-out),
    margin var(--duration-slow) var(--ease-in-out);
}

[data-theme="light"] .ai-sidebar { background: rgba(255, 255, 255, 0.94); border-color: rgba(0, 0, 0, 0.06); box-shadow: 10px 0 34px rgba(120, 120, 150, 0.14); }
.ai-sidebar.collapsed { width: 0; margin-left: 0; box-shadow: none; }

.ai-sidebar-head {
  padding: var(--space-4) 18px;
  min-height: 60px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
  background: linear-gradient(180deg, rgba(215, 180, 106, 0.04), transparent);
}

.ai-sidebar-head h3 { font-size: var(--text-sm); color: var(--text-secondary); flex: 1; font-weight: 600; letter-spacing: 0.02em; }

.ai-new-btn {
  position: relative;
  overflow: hidden;
  background: var(--accent);
  color: #111219;
  padding: 10px var(--space-4);
  min-height: 36px;
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-weight: 600;
  box-shadow: 0 6px 20px var(--accent-muted);
  transition: all var(--duration-normal) var(--ease-out);
}

.ai-new-btn:hover { transform: translateY(-2px); box-shadow: 0 8px 24px var(--accent-glow); filter: brightness(1.15); }
.ai-new-btn:active { transform: scale(0.96); }

.ai-conversations { flex: 1; overflow-y: auto; padding: var(--space-2) 10px; }

.ai-conv-item {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 46px;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  padding-right: 44px;
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-1);
  border: 1px solid transparent;
  user-select: none;
  transition: background 0.12s var(--ease-in-out), border-color 0.12s, transform 0.12s;
}

.ai-conv-item:hover { background: rgba(215, 180, 106, 0.06); transform: translateX(2px); }
.ai-conv-item.active { background: var(--accent-muted); color: var(--text-primary); border-color: rgba(215, 180, 106, 0.2); }

.ai-conv-title { flex: 1; min-width: 0; font-size: var(--text-base); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.ai-conv-time { font-size: var(--text-xs); color: var(--text-tertiary); margin-left: var(--space-2); flex-shrink: 0; font-family: var(--font-mono); opacity: 0.7; }

.ai-conv-del {
  position: absolute;
  right: 10px;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(239, 68, 68, 0.12);
  color: var(--red-400);
  font-size: 0;
  font-weight: 700;
  transition: background var(--duration-fast), color var(--duration-fast);
}

.ai-conv-del::before { content: '删'; font-size: var(--text-sm); }
.ai-conv-del:hover { background: var(--red-500); color: #fff; }

.ai-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; position: relative; background: transparent; }

.ai-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: 10px var(--space-4);
  min-height: 56px;
  border-bottom: 1px solid var(--accent-muted);
  background: rgba(17, 18, 24, 0.82);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 3;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

[data-theme="light"] .ai-head { background: rgba(255, 255, 255, 0.8); border-bottom-color: rgba(0, 0, 0, 0.06); }

.ai-title-wrap { display: flex; flex-direction: column; min-width: 0; gap: 10px; }
.ai-title { font-family: var(--font-display); font-size: var(--text-md); color: var(--text-primary); letter-spacing: 0.04em; display: flex; align-items: center; gap: var(--space-2); }
.ai-title::before { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--green-500); box-shadow: 0 0 8px rgba(16, 185, 129, 0.5); }
.ai-subtitle { font-size: var(--text-sm); color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ai-current-title { min-width: 0; max-width: min(34vw, 360px); font-weight: 800; color: var(--text-primary); font-size: var(--text-md); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ai-current-title small { display: block; font-size: var(--text-xs); color: var(--text-secondary); font-weight: 600; margin-top: 10px; }

.ai-status-pill { display: inline-flex; align-items: center; gap: 10px; border: 1px solid var(--accent-muted); background: var(--accent-muted); color: var(--text-secondary); padding: 10px var(--space-3); border-radius: var(--radius-full); font-size: var(--text-sm); white-space: nowrap; }
.ai-status-pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }

.ai-actions { display: flex; gap: var(--space-2); align-items: center; }

.ai-clear,
.ai-toggle-sidebar,
.ai-bg-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 36px;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-default);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: 500;
  transition: transform var(--duration-fast) var(--spring), border-color var(--duration-fast), color var(--duration-fast);
}

.ai-clear:hover, .ai-toggle-sidebar:hover { color: var(--red-400); border-color: var(--red-500); }
.ai-bg-btn:hover { color: var(--text-primary); border-color: var(--accent); }
.ai-clear:active, .ai-toggle-sidebar:active, .ai-bg-btn:active { transform: scale(0.96); }

.ai-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  overflow: hidden;
  border: 1.5px solid var(--border-default);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated);
  cursor: pointer;
  transition: all var(--duration-normal) var(--spring);
}

.ai-avatar:hover { border-color: var(--accent); box-shadow: 0 0 12px var(--accent-glow); transform: scale(1.06); }
.ai-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* AI Body */
.ai-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-6) clamp(14px, 3vw, var(--space-8)) var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: linear-gradient(180deg, rgba(215, 180, 106, 0.035), transparent 28%), var(--bg-base);
}

.ai-msg {
  display: grid;
  gap: 0;
  align-items: start;
  max-width: min(820px, 82%);
  font-size: var(--text-md);
  line-height: 1.65;
  position: relative;
  z-index: var(--z-base);
}

.ai-msg.ai { align-self: flex-start; justify-items: start; }
.ai-msg.user { align-self: flex-end; justify-items: end; }

.ai-msg > .bubble { grid-row: 1; max-width: 100%; padding: 12px 15px; border-radius: var(--radius-2xl); word-break: break-word; white-space: pre-wrap; overflow-wrap: anywhere; transition: transform var(--duration-fast) var(--ease-in-out), background var(--duration-fast) var(--ease-in-out); }
.ai-msg.user .bubble { background: var(--accent); color: #101116; border-bottom-right-radius: 10px; box-shadow: 0 6px 24px var(--accent-muted); }
.ai-msg.ai .bubble { background: linear-gradient(180deg, rgba(239, 228, 207, 0.055), rgba(255, 255, 255, 0.018)); color: var(--text-primary); border: 1px solid var(--accent-muted); border-bottom-left-radius: 10px; }

[data-theme="light"] .ai-msg.ai .bubble { background: rgba(255, 255, 255, 0.86); color: #222236; border-color: rgba(0, 0, 0, 0.06); }
[data-theme="light"] .ai-msg.user .bubble { color: #fff; }

.ai-msg > .ai-msg-actions { grid-row: 2; display: flex; align-items: center; gap: 1px; margin: 10px 10px 0; opacity: 0.45; transition: opacity var(--duration-fast); flex-wrap: nowrap; width: max-content; max-width: 100%; }
.ai-msg.ai > .ai-msg-actions { justify-self: start; }
.ai-msg.user > .ai-msg-actions { justify-self: end; }
.ai-msg:hover > .ai-msg-actions, .ai-msg:focus-within > .ai-msg-actions { opacity: 0.88; }

.ai-msg-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 24px;
  padding: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text-secondary);
  transition: background var(--duration-fast), color var(--duration-fast);
}

.ai-msg-action svg { display: block; width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.ai-msg-action:hover, .ai-msg-action:focus-visible { background: var(--bg-elevated); color: var(--text-primary); outline: none; }
.ai-msg-action:focus-visible { box-shadow: 0 0 0 2px var(--accent-muted); }
.ai-msg-action.copied { color: var(--green-500); background: rgba(16, 185, 129, 0.08); }

/* Bubble content */
.ai-msg .bubble strong { font-weight: 700; color: var(--accent-hover); }
.ai-msg.ai .bubble strong { color: var(--accent); }
.ai-msg .bubble code { background: var(--bg-base); padding: 10px 10px; border-radius: 10px; font-family: var(--font-mono); font-size: 0.85em; border: 1px solid var(--border-default); word-break: break-word; }
.ai-msg .bubble pre { background: var(--bg-base); padding: var(--space-4); border-radius: var(--radius-md); overflow-x: auto; margin: 10px 0; font-size: 0.85em; border: 1px solid var(--border-default); white-space: pre; scrollbar-width: thin; }
.ai-msg .bubble pre code { background: none; border: none; padding: 0; }
.ai-msg .bubble a { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.ai-msg.user .bubble a { color: #fff; }
.ai-msg .bubble h1, .ai-msg .bubble h2, .ai-msg .bubble h3 { font-weight: 700; margin: var(--space-2) 0 10px; line-height: var(--leading-snug); }
.ai-msg .bubble h1 { font-size: var(--text-xl); }
.ai-msg .bubble h2 { font-size: var(--text-lg); }
.ai-msg .bubble h3 { font-size: var(--text-md); }
.ai-msg .bubble ul, .ai-msg .bubble ol { padding-left: var(--space-6); margin: var(--space-1) 0; }
.ai-msg .bubble ul { list-style: disc; }
.ai-msg .bubble ol { list-style: decimal; }
.ai-msg .bubble blockquote { border-left: 3px solid var(--accent); padding: 10px var(--space-4); margin: var(--space-2) 0; color: var(--text-secondary); background: var(--bg-base); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.ai-msg .bubble hr { border: none; border-top: 1px solid var(--border-default); margin: var(--space-3) 0; }

/* Thinking */
.ai-think-wrap { margin-bottom: var(--space-3); border-left: 2.5px solid var(--accent); padding-left: var(--space-4); border-radius: 0 var(--radius-xs, 4px) var(--radius-xs, 4px) 0; }
.ai-think-toggle { display: flex; align-items: center; gap: 10px; color: var(--accent); cursor: pointer; font-size: var(--text-sm); font-weight: 500; margin-bottom: var(--space-2); transition: color var(--duration-fast); }
.ai-think-toggle:hover { color: var(--accent-hover); }
.ai-think-toggle svg { width: 12px; height: 12px; transition: transform var(--duration-normal) var(--ease-in-out); }
.ai-think-toggle.open svg { transform: rotate(90deg); }
.ai-think-content { font-size: var(--text-base); color: var(--text-secondary); line-height: var(--leading-relaxed); padding: 10px var(--space-4); background: var(--bg-base); border-radius: var(--radius-md); white-space: pre-wrap; word-break: break-word; max-height: 220px; overflow-y: auto; scrollbar-width: thin; transition: all var(--duration-normal) var(--ease-in-out); }
.ai-think-content.collapsed { max-height: 0; overflow: hidden; padding: 0 var(--space-4); opacity: 0; }

/* Typing indicator */
.ai-typing { display: flex; gap: 10px; padding: 10px 10px; }
.ai-typing span { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: typing 1.4s infinite both; opacity: 0.6; }
.ai-typing span:nth-child(2) { animation-delay: 0.2s; }
.ai-typing span:nth-child(3) { animation-delay: 0.4s; }

/* AI Footer */
.ai-foot {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: var(--space-3);
  align-items: end;
  padding: var(--space-4) clamp(14px, 3vw, var(--space-6)) calc(16px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--accent-muted);
  background: rgba(17, 17, 24, 0.84);
  backdrop-filter: blur(20px);
  flex-shrink: 0;
}

[data-theme="light"] .ai-foot { background: rgba(255, 255, 255, 0.82); border-top-color: rgba(0, 0, 0, 0.06); }

.ai-inp {
  flex: 1;
  min-width: 0;
  width: 100%;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--accent-muted);
  border-radius: var(--radius-lg);
  padding: 14px var(--space-5);
  color: var(--text-primary);
  font-size: 16px;
  line-height: 1.5;
  resize: none;
  min-height: 48px;
  max-height: min(34dvh, 180px);
  overflow-y: auto;
  transition: border-color var(--duration-fast), box-shadow var(--duration-fast), background var(--duration-fast);
}

.ai-inp:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-muted); background: rgba(255, 255, 255, 0.05); }
.ai-inp::placeholder { color: var(--text-tertiary); }
[data-theme="light"] .ai-inp { background: rgba(255, 255, 255, 0.9); color: #222236; border-color: rgba(0, 0, 0, 0.08); }

.ai-attach {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--duration-fast) var(--ease-in-out);
}

.ai-attach:hover { color: var(--accent); border-color: var(--accent); background: var(--bg-cards); transform: translateY(-1px); }
.ai-attach:active { transform: scale(0.94); }

.ai-send {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-lg);
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 6px 20px var(--accent-glow);
  transition: transform var(--duration-fast) var(--spring), box-shadow var(--duration-normal);
}

.ai-send:hover { box-shadow: 0 8px 28px var(--accent-glow); transform: translateY(-2px); }
.ai-send:active { transform: scale(0.9); }
.ai-send:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.ai-send.sending { animation: sendPulse 1.1s ease-in-out infinite; }

/* Attachment preview */
.ai-attach-preview {
  display: none;
  grid-column: 1 / -1;
  gap: var(--space-2);
  align-items: stretch;
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0 10px 10px;
  max-height: 76px;
  scrollbar-width: thin;
  scroll-snap-type: x proximity;
}

.ai-attach-preview.show { display: flex; }

.ai-attach-preview .preview-item {
  display: inline-grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto auto;
  column-gap: var(--space-2);
  row-gap: 10px;
  flex: 0 0 auto;
  width: min(260px, 72vw);
  padding: 10px var(--space-4);
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  scroll-snap-align: start;
  cursor: grab;
  position: relative;
  touch-action: pan-x;
}

.ai-attach-preview .preview-item.dragging { opacity: 0.55; transform: scale(0.96); border-color: var(--accent); cursor: grabbing; }
.ai-attach-preview .preview-item span { grid-column: 1; grid-row: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.ai-attach-preview .preview-item small { grid-column: 1; grid-row: 2; opacity: 0.62; font-size: var(--text-xs); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-attach-preview .remove { grid-column: 2; grid-row: 1 / span 2; align-self: center; justify-self: end; width: 22px; height: 22px; border-radius: var(--radius-full); display: inline-flex; align-items: center; justify-content: center; background: rgba(239, 68, 68, 0.1); color: var(--red-400); border: none; cursor: pointer; }

.preview-thumb { grid-column: 1 / span 2; width: 100%; height: 86px; border-radius: var(--radius-sm); overflow: hidden; display: flex; align-items: center; justify-content: center; background: rgba(255, 255, 255, 0.08); }
.preview-thumb img, .preview-thumb video { width: 100%; height: 100%; object-fit: cover; }
[data-theme="light"] .ai-attach-preview .preview-item { background: rgba(0, 0, 0, 0.03); border-color: rgba(0, 0, 0, 0.08); }

/* Attachment card in message */
.ai-attachment-card {
  margin-top: var(--space-2);
  padding: 10px var(--space-4);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.13);
  border: 1px solid rgba(255, 255, 255, 0.22);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  max-width: 100%;
  white-space: normal;
  overflow: hidden;
  cursor: pointer;
}

.ai-attachment-card:hover { background: rgba(255, 255, 255, 0.18); border-color: rgba(255, 255, 255, 0.38); }
.ai-attachment-thumb { width: 96px; height: 72px; border-radius: var(--radius-sm); overflow: hidden; background: rgba(255, 255, 255, 0.12); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }

/* Dropzone */
.ai-drop-zone {
  position: absolute;
  inset: 70px var(--space-6) 92px;
  z-index: 6;
  display: none;
  align-items: center;
  justify-content: center;
  border: 2px dashed rgba(215, 180, 106, 0.58);
  border-radius: var(--radius-2xl);
  background: rgba(17, 17, 24, 0.66);
  backdrop-filter: blur(10px);
  pointer-events: none;
}

.ai-drop-zone.show { display: flex; }

/* Context menu */
.ai-context-menu {
  position: fixed;
  z-index: var(--z-max);
  display: none;
  min-width: 160px;
  padding: 10px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  background: var(--bg-overlay);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow-lg);
}

.ai-context-menu.open { display: block; animation: menuPop 0.12s var(--ease-out) both; }
.ai-context-menu button { width: 100%; text-align: left; background: transparent; color: var(--text-primary); font-size: var(--text-base); font-weight: 700; padding: 10px var(--space-3); border-radius: var(--radius-md); transition: background var(--duration-fast), color var(--duration-fast); }
.ai-context-menu button:hover { background: var(--accent-muted); color: var(--accent); }
.ai-context-menu button.danger { color: var(--red-400); }
.ai-context-menu button.danger:hover { background: rgba(239, 68, 68, 0.14); color: var(--red-500); }
[data-theme="light"] .ai-context-menu { background: rgba(255, 255, 255, 0.96); box-shadow: var(--shadow-lg); }

/* ═══════════════════════════════════════
   Modals
   ═══════════════════════════════════════ */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: var(--z-modal);
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
}

.overlay.open { display: flex; }

.modal-box {
  position: relative;
  overflow: hidden;
  background: linear-gradient(160deg, rgba(215, 180, 106, 0.05), rgba(255, 255, 255, 0.01)), var(--bg-cards);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-2xl);
  padding: 0;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
  will-change: transform, opacity;
}

[data-theme="light"] .modal-box { background: linear-gradient(160deg, rgba(255, 255, 255, 0.9), rgba(215, 180, 106, 0.02)), var(--bg-surface); border-color: rgba(0, 0, 0, 0.06); box-shadow: 0 30px 80px rgba(116, 88, 42, 0.12); }
.modal-box > *:not(.auth-tabs):not(.modal-title-bar) { padding-left: var(--space-7); padding-right: var(--space-7); }

.modal-title-bar { padding: var(--space-6) var(--space-7) 0; }
.modal-title { font-family: var(--font-serif); font-size: 1.22rem; font-weight: 900; color: var(--text-primary); letter-spacing: -0.04em; margin-bottom: var(--space-2); }
.modal-desc { font-size: var(--text-base); color: var(--text-secondary); margin: 10px 0 var(--space-4); text-align: center; }
.modal-footer { display: flex; gap: var(--space-2); justify-content: flex-end; margin-top: var(--space-4); padding: 0 var(--space-7) var(--space-6); }

.auth-tabs { display: flex; border-bottom: 1px solid var(--border-subtle); padding: 0 var(--space-7); }
.auth-tab { flex: 1; padding: var(--space-5) 10px var(--space-4); color: var(--text-secondary); font-size: var(--text-base); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; transition: color var(--duration-fast), border-color var(--duration-fast); }
.auth-tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.auth-panel { display: flex; flex-direction: column; padding: var(--space-6) var(--space-7) var(--space-2); }

.field {
  width: 100%;
  display: block;
  background: rgba(0, 0, 0, 0.15);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  border-radius: var(--radius-md);
  padding: 12px var(--space-4);
  font-size: var(--text-base);
  outline: none;
  transition: all var(--duration-fast) var(--ease-in-out);
}

.field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-muted); background: rgba(0, 0, 0, 0.2); }
[data-theme="light"] .field { background: rgba(0, 0, 0, 0.02); border-color: rgba(0, 0, 0, 0.08); }

.m-btn {
  padding: 12px var(--space-6);
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  font-weight: 600;
  transition: all var(--duration-fast) var(--ease-out);
  position: relative;
  overflow: hidden;
}

.m-btn.primary { background: linear-gradient(135deg, var(--accent), var(--amber-200)); color: #111219; box-shadow: 0 4px 12px var(--accent-muted); }
.m-btn.primary:hover { filter: brightness(1.12); transform: translateY(-1px); box-shadow: 0 6px 18px var(--accent-glow); }
.m-btn.secondary { background: rgba(255, 255, 255, 0.02); border: 1px solid var(--border-default); color: var(--text-secondary); }
.m-btn.secondary:hover { border-color: var(--accent); color: var(--accent); }
.m-btn.danger { background: var(--red-500); color: #fff; }
.m-btn.danger:hover { filter: brightness(1.1); }
.m-btn:active:not(:disabled) { transform: scale(0.96); }
.m-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.m-btn.is-loading { position: relative; pointer-events: none; }
.m-btn.is-loading::after { content: ''; display: inline-block; width: 0.72em; height: 0.72em; margin-left: 0.45em; border: 1.5px solid currentColor; border-right-color: transparent; border-radius: 50%; vertical-align: -0.1em; animation: spin 0.75s linear infinite; }

.msg-inline { font-size: var(--text-sm); padding: 10px var(--space-4); border-radius: 10px; margin: 10px var(--space-7) 0; display: none; }
.msg-inline.ok { background: rgba(16, 185, 129, 0.1); color: var(--green-500); display: block; border: 1px solid rgba(16, 185, 129, 0.2); }
.msg-inline.err { background: rgba(239, 68, 68, 0.1); color: var(--red-500); display: block; border: 1px solid rgba(239, 68, 68, 0.2); }

/* Password eye */
.pw-field-wrap { position: relative; }
.pw-field-wrap .field { padding-right: var(--space-12); }
.pw-eye { position: absolute; right: var(--space-3); top: 50%; transform: translateY(-50%); width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--border-default); border-radius: var(--radius-full); background: rgba(255, 255, 255, 0.06); color: var(--text-secondary); opacity: 0.74; transition: all var(--duration-fast); }
.pw-eye:hover { opacity: 1; color: var(--accent); border-color: var(--accent); }
.pw-eye:active { transform: translateY(-50%) scale(0.9); }
.pw-eye.is-visible { color: var(--accent); opacity: 1; }
.pw-eye svg { width: 17px; height: 17px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }

/* ═══════════════════════════════════════
   Music Player
   ═══════════════════════════════════════ */
.player {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  z-index: var(--z-overlay);
  min-width: 214px;
  max-width: 280px;
  padding: 12px var(--space-4) 10px;
  border-radius: var(--radius-2xl);
  background: linear-gradient(180deg, rgba(239, 228, 207, 0.072), rgba(255, 255, 255, 0.018)), rgba(14, 15, 19, 0.88);
  border: 1px solid rgba(215, 180, 106, 0.22);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 10px;
  user-select: none;
  will-change: transform;
  transition: transform var(--duration-normal) var(--ease-out), border-color var(--duration-normal);
}

.player:hover { transform: translateY(-3px); border-color: rgba(215, 180, 106, 0.38); }
[data-theme="light"] .player { background: linear-gradient(180deg, rgba(255, 255, 255, 0.7), rgba(239, 228, 207, 0.48)), rgba(255, 251, 243, 0.9); border-color: rgba(120, 92, 42, 0.18); }

.p_ctrl { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-top: var(--space-4); position: relative; z-index: var(--z-base); }

.p_btn {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  background: transparent;
  border: 1px solid var(--accent-muted);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--duration-normal) var(--spring);
}

.p_btn:hover { background: rgba(215, 180, 106, 0.075); border-color: var(--accent); color: var(--text-primary); transform: translateY(-1px); }
.p_btn:active { transform: scale(0.82); }

.p_play { width: 38px; height: 38px; border-radius: var(--radius-full); background: var(--accent); color: #111219; border: 1px solid rgba(255, 255, 255, 0.12); display: flex; align-items: center; justify-content: center; transition: all var(--duration-normal) var(--spring); }
.p_play:hover { background: var(--amber-200); transform: scale(1.08); }
.p_play:active { transform: scale(0.88); }
.p_play.playing { box-shadow: 0 0 0 4px var(--accent-muted); }

.p_prog { width: 100%; height: 2px; background: rgba(239, 228, 207, 0.12); border-radius: var(--radius-full); cursor: pointer; position: relative; z-index: var(--z-base); transition: height var(--duration-normal); }
.p_prog:hover { height: 4px; }
.p_bar { height: 100%; border-radius: var(--radius-full); width: 0%; background: linear-gradient(90deg, rgba(215, 180, 106, 0.72), rgba(239, 228, 207, 0.86)); position: relative; }
.p_bar::after { content: ''; position: absolute; right: -4px; top: 50%; transform: translateY(-50%); width: 8px; height: 8px; border-radius: 50%; background: var(--amber-50); opacity: 0; box-shadow: 0 0 10px rgba(255, 255, 255, 0.6); transition: opacity var(--duration-normal); }
.p_prog:hover .p_bar::after { opacity: 0.9; }
.p_time { display: flex; justify-content: space-between; font-family: var(--font-mono); font-size: var(--text-xs); color: var(--text-tertiary); margin-top: 10px; position: relative; z-index: var(--z-base); }

#specCanvas { position: fixed; bottom: 0; left: 0; right: 0; width: 100%; height: 90px; pointer-events: none; z-index: 799; opacity: 0; transition: opacity var(--duration-slow); filter: drop-shadow(0 -6px 18px var(--accent-glow)); }
#specCanvas.active { opacity: 0.82; }

/* ═══════════════════════════════════════
   Background canvas + footer
   ═══════════════════════════════════════ */
#bgCanvas { position: fixed; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: var(--z-base); opacity: 0.5; will-change: transform; }
[data-theme="light"] #bgCanvas { opacity: 0.14; }

footer { text-align: center; padding: var(--space-6); color: var(--text-secondary); font-size: var(--text-base); border-top: 1px solid var(--border-subtle); position: relative; z-index: 1; }

/* ═══════════════════════════════════════
   Reveal utility (Anime.js targets)
   ═══════════════════════════════════════ */
.reveal { opacity: 0; }
.reveal.is-visible { opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  html[data-allow-motion="true"] .reveal { opacity: 1; }
}

/* ═══════════════════════════════════════
   Responsive
   ═══════════════════════════════════════ */
@media (max-width: 900px) {
  nav { gap: var(--space-1); }
  .page-tabs { margin-left: 10px; margin-right: var(--space-1); }
  .nav-controls { gap: var(--space-1); }
  .ai-sidebar { position: absolute; left: 0; top: 0; bottom: 0; }
  .ai-msg { max-width: 92%; }
  .ai-status-pill { display: none; }
}

@media (max-width: 768px) {
  :root { --nav-height: 56px; }
  body { padding-top: var(--nav-height); }
  nav { overflow-x: auto; scrollbar-width: none; justify-content: flex-start; }
  nav::-webkit-scrollbar { display: none; }
  .nav-logo { margin-right: 10px; }
  .page-tabs { flex: 0 0 auto; margin: 0 var(--space-1) 0 10px; }
  .page-tab { padding: 10px var(--space-3); font-size: var(--text-sm); }
  .nav-btn { font-size: var(--text-xs); padding: 10px var(--space-2); }
  .page { padding: 0 var(--space-4); }
  .hero { display: flex; flex-direction: column; align-items: flex-start; text-align: left; min-height: auto; padding: 44px var(--space-5) var(--space-8); gap: var(--space-5); }
  .hero::before { inset: 14px var(--space-3) var(--space-4) var(--space-3); border-radius: var(--radius-2xl); }
  .hero-main { width: 100%; }
  .hero h1 { font-size: clamp(2.45rem, 15vw, 3.25rem); }
  .hero-bio { font-size: 0.92rem; line-height: var(--leading-relaxed); }
  .hero-note { font-size: var(--text-base); }
  .hero-btns { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
  .hero-btns .btn { width: 100%; }
  .hero-side { width: 100%; display: grid; grid-template-columns: 86px minmax(0, 1fr); gap: var(--space-3); align-items: stretch; }
  .avatar-wrap { width: 86px; height: 86px; border-radius: var(--radius-xl); grid-row: 1 / 3; align-self: start; justify-self: start; }
  .home-section { padding: var(--space-8) var(--space-4) 10px; }
  .portfolio-grid { grid-template-columns: 1fr; }
  .portfolio-item:first-child { grid-row: auto; }
  .contact-grid { grid-template-columns: repeat(2, 1fr); grid-auto-rows: 66px; }
  .contact-item { min-height: 66px; padding: 10px var(--space-3); }
  .qr-wrapper { grid-row: span 2; }
  #contact { padding-bottom: 140px; }
  .cmt-wrap { padding: 0 var(--space-4) var(--space-16); }
  .cmt-form { padding: var(--space-4); }
  .cmt-row { flex-direction: column; }
  .ai-head { padding: 10px var(--space-3); gap: var(--space-2); }
  .ai-body { padding: var(--space-4) var(--space-3) var(--space-5); gap: var(--space-4); }
  .ai-foot { grid-template-columns: 40px minmax(0, 1fr) 44px; padding: 10px var(--space-3) calc(var(--space-3) + env(safe-area-inset-bottom, 0px)); }
  .ai-attach { width: 40px; height: 40px; }
  .ai-send { width: 44px; height: 44px; }
  .ai-inp { padding: var(--space-3) var(--space-4); }
  .ai-msg .bubble { padding: var(--space-3) var(--space-4); border-radius: 18px; }
  .player { bottom: var(--space-4); right: var(--space-4); padding: var(--space-3) var(--space-4); min-width: 160px; max-width: 200px; border-radius: var(--radius-xl); }
  #specCanvas { height: 76px; }
  .lang-ui-menu { top: calc(var(--nav-height) + 10px); }
  footer { padding: var(--space-6) var(--space-4); }
}

@media (max-width: 560px) {
  .player { left: auto; right: var(--space-3); bottom: var(--space-3); width: 58px; min-width: 58px; max-width: 58px; height: 58px; padding: 0; border-radius: var(--radius-xl); display: grid; place-items: center; overflow: hidden; }
  .p_info, .p_prog, .p_time { display: none !important; }
  .p_ctrl { margin: 0; gap: 0; justify-content: center; }
  .p_btn { display: none; }
  .p_play { display: grid !important; width: 38px; height: 38px; border-radius: var(--radius-lg); }
}

@media (max-width: 480px) {
  :root { --nav-height: 54px; }
  .nav-logo img { width: 32px; height: 32px; }
  .hero h1 { font-size: 2.6rem; }
  .hero-btns { grid-template-columns: 1fr; }
  .contact-grid { gap: var(--space-2); }
  .contact-item { padding: var(--space-2) var(--space-3); }
  .contact-item h3 { font-size: var(--text-sm); }
  .contact-item p { font-size: var(--text-xs); }
}

@media (hover: none) {
  .portfolio-item:hover, .contact-item:hover, .btn:hover, .ai-send:hover, .avatar-wrap:hover { transform: none; }
  .ai-msg > .ai-msg-actions { opacity: 0.7; }
}


/* ═══════════════════════════════════════
   补遗：验证码行 / 加载态 / 附件卡片 / 主题重绘
   ═══════════════════════════════════════ */
.code-row { display: flex; gap: var(--space-2); align-items: center; }
.code-row .field { flex: 1; margin-bottom: 0; }

.send-code-btn {
  flex-shrink: 0;
  height: 28px;
  padding: 0 var(--space-2);
  white-space: nowrap;
  background: none;
  color: var(--accent);
  border: 1px solid var(--accent-muted);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1;
  transition: opacity var(--duration-fast), border-color var(--duration-fast), background var(--duration-fast);
}

.send-code-btn:hover { opacity: 0.85; border-color: var(--accent); background: var(--accent-muted); }
.send-code-btn:disabled { opacity: 0.35; cursor: default; background: none; }

.ai-loading-msg { text-align: center; color: var(--text-secondary); padding: var(--space-8); font-size: var(--text-base); }
.ai-loading-msg .dots { display: inline-flex; gap: var(--space-1); }
.ai-loading-msg .dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: typing 1.4s infinite both; }
.ai-loading-msg .dots span:nth-child(2) { animation-delay: 0.2s; }
.ai-loading-msg .dots span:nth-child(3) { animation-delay: 0.4s; }

.ai-attachment-icon { width: 30px; height: 30px; border-radius: 10px; background: rgba(255, 255, 255, 0.18); display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: var(--text-md); }
.ai-attachment-main { min-width: 0; display: flex; flex-direction: column; gap: 10px; flex: 1; }
.ai-attachment-name { font-weight: 700; font-size: var(--text-base); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-attachment-meta { font-size: var(--text-xs); opacity: 0.78; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-attachment-del { margin-left: auto; align-self: flex-start; border: 0; border-radius: var(--radius-full); background: rgba(255, 80, 110, 0.18); color: #fff; width: 24px; height: 24px; line-height: 24px; font-weight: 900; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.ai-attachment-del:hover { background: rgba(255, 80, 110, 0.34); }
.ai-attachment-card a { color: inherit; text-decoration: none; }

.think-label { line-height: 1; }

/* 主题切换时强制一次重绘，规避 backdrop-filter 残留 */
body.theme-repaint { transform: translateZ(0); }