/* ============================================================================
   Nanobot Muse v3 — ProkBot / Grok Bot Minimalist Zen Design System
   Light: #FFFFFF canvas + #F5F6F8 sidebar + #18181B user bubble
   Dark:  #121316 canvas + #1B1C20 sidebar + #2E3138 user bubble
   ============================================================================ */

:root {
  --bg: #FFFFFF;
  --bg-elevated: #FFFFFF;
  --bg-sidebar: #F4F5F7;
  --bg-subtle: #F3F4F6;
  --bg-hover: #ECEEF2;
  --text: #111216;
  --text-secondary: #686D76;
  --text-tertiary: #8C929D;
  --text-muted: #9AA0A8;
  --border: rgba(17, 18, 22, 0.08);
  --border-strong: rgba(17, 18, 22, 0.14);
  --user-bubble: #18181B;
  --user-text: #FFFFFF;
  --glass: rgba(255, 255, 255, 0.86);
  --glass-dock: rgba(255, 255, 255, 0.94);
  --shadow-sm: 0 2px 10px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 8px 28px rgba(15, 23, 42, 0.08), 0 1px 3px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 18px 48px rgba(15, 23, 42, 0.16), 0 4px 12px rgba(15, 23, 42, 0.06);
  --shadow-dock: 0 10px 30px rgba(15, 23, 42, 0.09), 0 2px 6px rgba(15, 23, 42, 0.05);
  --accent: #18181B;
  --accent-inv: #FFFFFF;
  --accent-fg: #FFFFFF;
  --obsidian-body: #18181B;
  --obsidian-eye: #FFFFFF;
  --obsidian-orb: #18181B;
  --green: #16C66A;
  --amber: #F59E0B;
  --danger: #EF4444;
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Inter", "Segoe UI", "Microsoft YaHei", sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

html[data-theme="dark"] {
  --bg: #121316;
  --bg-elevated: #1A1C21;
  --bg-sidebar: #181A1F;
  --bg-subtle: #202329;
  --bg-hover: #282B33;
  --text: #F2F4F7;
  --text-secondary: #A1A7B3;
  --text-tertiary: #7A808D;
  --text-muted: #6C727F;
  --border: rgba(255, 255, 255, 0.085);
  --border-strong: rgba(255, 255, 255, 0.15);
  --user-bubble: #2E3138;
  --user-text: #F4F5F7;
  --glass: rgba(18, 19, 22, 0.86);
  --accent: #F4F5F7;
  --accent-inv: #121316;
  --accent-fg: #121316;
  --shadow-lg: 0 20px 54px rgba(0, 0, 0, 0.52);
  --obsidian-body: #ECEEF2;
  --obsidian-eye: #141519;
  --obsidian-orb: #ECEEF2;
  --glass-dock: rgba(28, 30, 36, 0.88);
  --shadow-sm: 0 2px 12px rgba(0, 0, 0, 0.28);
  --shadow-md: 0 10px 32px rgba(0, 0, 0, 0.42), 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow-dock: 0 12px 32px rgba(0, 0, 0, 0.48), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  --accent: #F4F5F7;
  --accent-inv: #121316;
}

*, *::before, *::after { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%; width: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font-family: var(--font-sans); font-size: 15.5px; line-height: 1.55;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}

button, input, textarea { font: inherit; color: inherit; }
button { background: none; border: none; cursor: pointer; padding: 0; }
.hidden { display: none !important; }

/* ==================== LOGIN GATE ==================== */
.login-gate {
  position: fixed; inset: 0; z-index: 90;
  display: flex; align-items: center; justify-content: center;
  padding: 24px; background: var(--bg);
}
.login-card {
  width: 100%; max-width: 340px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
}
.login-mascot-slot { min-height: 98px; display: flex; align-items: center; justify-content: center; }
.login-title { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -0.025em; }
.login-sub { margin: -6px 0 8px; font-size: 13.5px; color: var(--text-secondary); }
.login-form { width: 100%; display: flex; flex-direction: column; gap: 10px; }
.login-input {
  width: 100%; height: 48px; padding: 0 18px; border-radius: 999px;
  border: 1px solid var(--border-strong); background: var(--bg-subtle);
  font-size: 15px; outline: none; transition: border-color 0.16s, background 0.16s;
}
.login-input:focus { border-color: var(--text); background: var(--bg); }
.login-submit {
  width: 100%; height: 48px; border-radius: 999px;
  background: var(--accent); color: var(--accent-inv);
  font-weight: 600; font-size: 15px; letter-spacing: -0.01em;
  transition: opacity 0.15s, transform 0.12s;
}
.login-submit:active { transform: scale(0.985); }
.login-err { min-height: 20px; margin: 0; font-size: 13px; color: var(--danger); }

/* ==================== APP SHELL & VIEWS ==================== */
.app-shell { position: relative; width: 100%; height: 100dvh; overflow: hidden; background: var(--bg); }
.view-pane {
  position: absolute; inset: 0; display: none; flex-direction: column;
  background: var(--bg); overflow: hidden;
}
.view-pane.active { display: flex; animation: viewFadeIn 0.2s ease-out; }
@keyframes viewFadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==================== 1. MINIMALIST ZEN HOME STAGE ==================== */
#view-home, .home-pane {
  align-items: center; justify-content: center;
  background: var(--bg);
}
.home-stage {
  position: relative; z-index: 2;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: clamp(34px, 6.2vh, 62px);
  width: 100%; height: 100%; max-width: 460px; margin: 0 auto;
  padding: calc(clamp(82px, 14vh, 148px) + env(safe-area-inset-top, 0px)) 28px calc(22px + env(safe-area-inset-bottom, 0px));
  text-align: center;
}
.home-center {
  position: relative; z-index: 2;
  display: flex; flex-direction: column; align-items: center;
}
.home-ambient {
  position: absolute; width: 390px; height: 390px; border-radius: 50%;
  top: 46%; left: 50%; transform: translate(-50%, -50%) scale(1);
  background: radial-gradient(circle, var(--ambient-color, #F59E0B) 0%, transparent 68%);
  opacity: 0.11; filter: blur(40px); pointer-events: none; z-index: 0;
  transition: opacity 0.35s ease, transform 0.38s cubic-bezier(0.22, 1.3, 0.36, 1);
}
html[data-theme="dark"] .home-ambient { opacity: 0.17; }
.home-ambient.ambient-pulse {
  opacity: 0.26;
  transform: translate(-50%, -50%) scale(1.16);
}
html[data-theme="dark"] .home-ambient.ambient-pulse { opacity: 0.34; }

.home-poke-bubble {
  position: absolute; bottom: calc(100% + 2px); left: 50%;
  transform: translateX(-50%);
  z-index: 8; pointer-events: none;
  padding: 8px 16px; border-radius: 999px;
  background: var(--bg-elevated); color: var(--text);
  border: 1px solid var(--border-strong); box-shadow: var(--shadow-md);
  font-size: 13.5px; font-weight: 500; line-height: 1.3;
  white-space: nowrap; max-width: min(86vw, 310px);
  overflow: hidden; text-overflow: ellipsis;
  animation: pokePop 0.26s cubic-bezier(0.22, 1.35, 0.36, 1);
}
.home-poke-bubble::after {
  content: ''; position: absolute; left: 50%; bottom: -5px;
  width: 9px; height: 9px; transform: translateX(-50%) rotate(45deg);
  background: var(--bg-elevated);
  border-right: 1px solid var(--border-strong);
  border-bottom: 1px solid var(--border-strong);
}
@keyframes pokePop {
  from { opacity: 0; transform: translate(-50%, 10px) scale(0.88); }
  to { opacity: 1; transform: translate(-50%, 0) scale(1); }
}

.home-mascot-wrap {
  position: relative; z-index: 2;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; user-select: none; -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  padding: 4px;
}
.home-mascot-wrap::after {
  content: ''; position: absolute; left: 50%; bottom: 4px;
  width: 56%; height: 18px; transform: translateX(-50%);
  border-radius: 50%; pointer-events: none; z-index: 0;
  background: radial-gradient(ellipse at center, rgba(15, 23, 42, 0.13) 0%, transparent 72%);
  filter: blur(4px);
}
html[data-theme="dark"] .home-mascot-wrap::after {
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.48) 0%, transparent 72%);
}
.home-mascot-hero {
  position: relative; z-index: 1;
  width: clamp(232px, 62vw, 278px) !important;
  height: clamp(232px, 62vw, 278px) !important;
}
@media (max-height: 700px) {
  .home-stage {
    gap: 24px;
    padding-top: calc(58px + env(safe-area-inset-top, 0px));
  }
  .home-mascot-hero {
    width: 206px !important;
    height: 206px !important;
  }
}
.home-fx-layer {
  position: absolute; inset: -16px; pointer-events: none; overflow: visible; z-index: 6;
}
.home-fx-particle {
  position: absolute; left: 50%; top: 48%;
  font-size: 20px; line-height: 1; user-select: none; pointer-events: none;
  will-change: transform, opacity;
  animation: fxFloatUp 0.92s cubic-bezier(0.18, 0.85, 0.32, 1) forwards;
}
@keyframes fxFloatUp {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) translate(0, 4px) scale(0.45) rotate(0deg);
  }
  18% {
    opacity: 1;
    transform: translate(-50%, -50%) translate(calc(var(--dx, 0px) * 0.25), -14px) scale(1.12) rotate(calc(var(--rot, 0deg) * 0.35));
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) translate(var(--dx, 0px), var(--dy, -88px)) scale(0.86) rotate(var(--rot, 16deg));
  }
}
.home-mascot-name {
  position: relative; z-index: 2;
  margin: 10px 0 5px; font-size: 21px; font-weight: 650;
  letter-spacing: -0.02em; color: var(--text);
}
.home-status-row {
  position: relative; z-index: 2;
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 13px; color: var(--text-secondary);
}
.home-working-pill {
  position: relative; z-index: 2; margin-top: 18px;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 16px; border-radius: 999px;
  background: var(--bg-subtle); border: 1px solid var(--border-strong);
  font-size: 13px; font-weight: 500; color: var(--text);
  box-shadow: var(--shadow-sm); transition: transform 0.14s, background 0.15s;
}
.home-working-pill:hover { background: var(--bg-hover); }
.home-working-pill:active { transform: scale(0.97); }
.home-working-arrow { color: var(--text-secondary); font-weight: 600; }

/* Bottom Left & Right Dual Floating Circle Dock */
.home-dock {
  position: relative; z-index: 5;
  width: 100%; max-width: 280px;
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 0;
  pointer-events: auto;
}
.home-dock-item {
  pointer-events: auto;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  color: var(--text); transition: transform 0.16s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.home-dock-item:hover { transform: translateY(-2px); }
.home-dock-item:active { transform: scale(0.94); }
.home-circle {
  position: relative; width: 60px; height: 60px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--glass-dock);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-dock);
  color: var(--text);
  transition: background 0.16s, border-color 0.16s, box-shadow 0.16s;
}
.home-dock-item:hover .home-circle {
  background: var(--bg-elevated);
  border-color: var(--text-muted);
}
.home-circle svg { width: 24px; height: 24px; }
.home-dock-label {
  font-size: 11.5px; font-weight: 500; color: var(--text-secondary);
  letter-spacing: 0.01em;
}
.home-circle-dot {
  position: absolute; top: 10px; right: 10px;
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--green); border: 2px solid var(--bg-elevated);
  animation: dotPulse 1.4s ease-in-out infinite;
}

@media (min-width: 860px) {
  .home-dock {
    max-width: 320px; margin: 0 auto;
    padding-bottom: 0;
  }
  .home-mascot-wrap .mascot-stage { width: 192px !important; height: 192px !important; }
  .home-circle, .home-circle-btn { width: 64px; height: 64px; }
  .home-circle svg, .home-circle-btn svg { width: 25px; height: 25px; }
}

/* ==================== STATUS DOTS ==================== */
.status-dot {
  width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto;
  background: var(--green); display: inline-block;
}
.status-dot.working { background: var(--amber); animation: dotPulse 1.2s ease-in-out infinite; }
.status-dot.happy { background: var(--green); }
.status-dot.error { background: var(--danger); }
@keyframes dotPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.78); }
}

/* ==================== 2. PROKBOT FULL-SCREEN CHAT ==================== */
.chat-layout { display: flex; flex: 1 1 auto; min-height: 0; width: 100%; height: 100%; }

/* Desktop Left Sidebar (ProkBot #F5F6F8 / #18191D) */
.desktop-sidebar {
  display: none; width: 284px; flex: 0 0 284px;
  background: var(--bg-sidebar); border-right: 1px solid var(--border);
  flex-direction: column; min-height: 0;
}
@media (min-width: 860px) {
  .desktop-sidebar { display: flex; }
  .mobile-only { display: none !important; }
}
.sidebar-head {
  height: 56px; padding: 0 12px; display: flex; align-items: center; justify-content: space-between;
  flex: 0 0 auto;
}
.sidebar-home-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px 7px 9px; border-radius: 999px;
  font-size: 13.5px; font-weight: 600; color: var(--text);
  transition: background 0.15s;
}
.sidebar-home-btn:hover { background: var(--bg-hover); }
.sidebar-home-btn svg { width: 17px; height: 17px; }
.sidebar-search-wrap { padding: 0 12px 10px; flex: 0 0 auto; }
.search-input {
  width: 100%; height: 36px; padding: 0 13px; border-radius: 11px;
  border: 1px solid var(--border); background: var(--bg);
  font-size: 13.5px; outline: none; transition: border-color 0.15s;
}
.search-input:focus { border-color: var(--border-strong); }
.sidebar-topic-list {
  flex: 1 1 auto; overflow-y: auto; padding: 2px 8px 12px;
  display: flex; flex-direction: column; gap: 2px;
}
.sidebar-foot {
  flex: 0 0 auto; padding: 10px 12px; border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.sidebar-foot-id { display: flex; align-items: center; gap: 9px; min-width: 0; }
.sidebar-foot-name {
  font-size: 13.5px; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ProkBot Topic List Row (shared by Desktop Sidebar & Mobile Drawer) */
.topic-row {
  width: 100%; display: flex; align-items: center; gap: 11px;
  padding: 9px 10px; border-radius: 14px; text-align: left;
  transition: background 0.14s;
}
.topic-row:hover { background: var(--bg-hover); }
.topic-row.active { background: var(--bg); box-shadow: var(--shadow-sm); }
html[data-theme="dark"] .topic-row.active { background: var(--bg-subtle); box-shadow: none; }
.topic-row-avatar { flex: 0 0 36px; width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; }
.topic-row-body { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.topic-row-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.topic-row-title {
  font-size: 14px; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topic-row-time { font-size: 11.5px; color: var(--text-muted); flex: 0 0 auto; }
.topic-row-preview {
  font-size: 12.5px; color: var(--text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Chat Main Column */
.chat-main {
  position: relative; flex: 1 1 auto; min-width: 0; min-height: 0;
  display: flex; flex-direction: column; background: var(--bg);
}

/* Topbars */
.topbar {
  height: 56px; flex: 0 0 56px; padding: 0 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--glass); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--border); z-index: 10;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 4px; flex: 0 0 auto; }
.topbar-title {
  margin: 0; font-size: 16.5px; font-weight: 650; letter-spacing: -0.02em;
  flex: 1 1 auto; text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-spacer { width: 38px; flex: 0 0 38px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-secondary); transition: background 0.14s, color 0.14s;
}
.icon-btn:hover { background: var(--bg-subtle); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; }

.chat-identity {
  display: flex; align-items: center; gap: 9px; min-width: 0; flex: 1 1 auto;
  padding: 4px 10px 4px 6px; border-radius: 999px;
  text-align: left; transition: background 0.14s; max-width: 100%;
}
.chat-identity:hover { background: var(--bg-subtle); }
.header-mascot-slot { flex: 0 0 32px; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; }
.chat-identity-meta { min-width: 0; display: flex; flex-direction: column; }
.chat-title-text {
  font-size: 15px; font-weight: 650; letter-spacing: -0.015em; line-height: 1.25;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-status-line {
  display: flex; align-items: center; gap: 5px;
  font-size: 11.5px; color: var(--text-secondary); line-height: 1.2;
}
.chat-status-line span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Message Stream */
.chat-scroll {
  flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 18px 16px 26px;
}
.messages-inner {
  width: 100%; max-width: 740px; margin: 0 auto;
  display: flex; flex-direction: column; gap: 16px;
}
.msg-time-divider {
  display: flex; justify-content: center; margin: 4px 0 2px;
}
.msg-time-divider span {
  font-size: 11.5px; color: var(--text-muted); font-weight: 500;
}

.chat-empty-stage {
  margin: auto; padding: 64px 18px 28px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 10px; max-width: 420px;
}
.chat-empty-stage h2 { margin: 8px 0 0; font-size: 20px; font-weight: 650; letter-spacing: -0.02em; }
.chat-empty-stage p { margin: 0; font-size: 14px; color: var(--text-secondary); line-height: 1.6; }
.chat-empty-stage code {
  padding: 2px 6px; border-radius: 6px; background: var(--bg-subtle);
  font-family: var(--font-mono); font-size: 12.5px;
}
.quick-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 10px; }
.chip-btn {
  padding: 8px 14px; border-radius: 999px; font-size: 13px; font-weight: 500;
  background: var(--bg-subtle); border: 1px solid var(--border); color: var(--text);
  transition: background 0.14s, border-color 0.14s;
}
.chip-btn:hover { background: var(--bg-hover); border-color: var(--border-strong); }

/* User Bubble (ProkBot dark charcoal pill) */
.msg-row { display: flex; flex-direction: column; }
.msg-row.user { align-items: flex-end; }
.user-bubble {
  max-width: min(82%, 520px); padding: 10px 16px;
  border-radius: 20px 20px 6px 20px;
  background: var(--user-bubble); color: var(--user-text);
  font-size: 15px; line-height: 1.5; word-break: break-word; white-space: normal;
}
.user-bubble-text { white-space: pre-wrap; }
.user-bubble-images { margin-bottom: 8px; }

/* Assistant Message (ProkBot bubbleless crisp editorial prose) */
.msg-row.assistant { align-items: flex-start; gap: 8px; }
.assistant-body { width: 100%; color: var(--text); font-size: 15.5px; line-height: 1.66; }
.assistant-card--error {
  padding: 12px 14px; border-radius: var(--radius-md);
  background: rgba(239, 68, 68, 0.08); border: 1px solid rgba(239, 68, 68, 0.2);
}
.msg-err-text { color: var(--danger); margin: 8px 0 0; font-size: 14px; }
.msg-meta-row {
  display: flex; align-items: center; gap: 12px;
  font-size: 12px; color: var(--text-muted); margin-top: 2px;
}
.msg-action-link { color: var(--text-secondary); font-size: 12px; transition: color 0.14s; }
.msg-action-link:hover { color: var(--text); }

/* Live Working Mascot + Progress Card inside Chat Stream */
.working-mascot-row {
  display: flex; align-items: flex-start; gap: 12px; width: 100%;
}
.working-mascot-slot { flex: 0 0 52px; padding-top: 2px; }
.working-mascot-prog { flex: 1 1 auto; min-width: 0; }
.working-pill-inline {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 14px; border-radius: 14px;
  background: var(--bg-subtle); border: 1px solid var(--border);
  font-size: 13.5px; color: var(--text-secondary);
}
.progress-card {
  width: 100%; border-radius: 16px; overflow: hidden;
  background: var(--bg-subtle); border: 1px solid var(--border);
}
.progress-header {
  width: 100%; padding: 10px 13px; display: flex; align-items: center;
  justify-content: space-between; gap: 10px; text-align: left;
  font-size: 13.5px; color: var(--text);
}
.progress-head-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.progress-title { font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.progress-meta { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); flex: 0 0 auto; }
.progress-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); flex: 0 0 auto; }
.progress-dot.running { background: var(--amber); animation: dotPulse 1.1s ease-in-out infinite; }
.progress-dot.error { background: var(--danger); }
.progress-chevron { transition: transform 0.16s; font-size: 12px; }
.progress-card.open .progress-chevron { transform: rotate(90deg); }
.progress-body { padding: 0 13px 12px; border-top: 1px solid var(--border); }
.step-list { display: flex; flex-direction: column; gap: 8px; padding-top: 10px; }
.step-item { display: flex; align-items: flex-start; gap: 8px; font-size: 13px; }
.step-icon { width: 16px; height: 16px; display: inline-flex; align-items: center; justify-content: center; flex: 0 0 16px; margin-top: 2px; color: var(--green); }
.step-spinner {
  width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid var(--border-strong); border-top-color: var(--text);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.step-title { font-weight: 500; color: var(--text); }
.step-detail { font-size: 12px; color: var(--text-secondary); margin-top: 2px; word-break: break-all; }
.reasoning-box {
  margin-top: 10px; padding: 9px 11px; border-radius: 10px;
  background: var(--bg); border: 1px solid var(--border);
  font-size: 12.5px; color: var(--text-secondary); white-space: pre-wrap; max-height: 180px; overflow-y: auto;
}
.stream-cursor {
  display: inline-block; width: 7px; height: 16px; margin-left: 3px; vertical-align: -2px;
  border-radius: 2px; background: var(--text); animation: blinkCur 0.85s step-end infinite;
}
@keyframes blinkCur { 50% { opacity: 0; } }

/* Scroll-to-bottom floating pill */
.scroll-bottom-btn {
  position: absolute; right: 20px; bottom: 92px; z-index: 8;
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--bg-elevated); border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-md); color: var(--text);
  display: flex; align-items: center; justify-content: center;
}
.scroll-bottom-btn svg { width: 18px; height: 18px; }

/* ProkBot Floating White Capsule Composer */
.composer-wrap {
  flex: 0 0 auto; width: 100%; max-width: 772px; margin: 0 auto;
  padding: 6px 14px calc(14px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to top, var(--bg) 78%, transparent 100%);
}
.attach-strip { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; padding: 0 6px; }
.attach-chip {
  position: relative; width: 60px; height: 60px; border-radius: 12px;
  overflow: hidden; border: 1px solid var(--border-strong);
}
.attach-chip img { width: 100%; height: 100%; object-fit: cover; display: block; }
.attach-chip-remove {
  position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: rgba(0, 0, 0, 0.72); color: #FFF; font-size: 13px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.composer-shell {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 7px 7px 7px 10px; border-radius: 26px;
  background: var(--bg-elevated); border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-md);
  transition: border-color 0.16s, box-shadow 0.16s;
}
.composer-shell:focus-within {
  border-color: var(--text-muted);
}
.composer-icon-btn {
  width: 36px; height: 36px; border-radius: 50%; flex: 0 0 36px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-secondary); transition: background 0.14s, color 0.14s;
}
.composer-icon-btn:hover { background: var(--bg-subtle); color: var(--text); }
.composer-icon-btn svg { width: 20px; height: 20px; }
.composer-input {
  flex: 1 1 auto; min-height: 36px; max-height: 130px; padding: 7px 4px;
  border: none; outline: none; resize: none; background: transparent;
  font-size: 15.5px; line-height: 1.42; color: var(--text);
}
.composer-input::placeholder { color: var(--text-muted); }
.send-btn {
  width: 36px; height: 36px; border-radius: 50%; flex: 0 0 36px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent); color: var(--accent-inv);
  transition: opacity 0.15s, transform 0.12s;
}
.send-btn:disabled { opacity: 0.24; cursor: not-allowed; }
.send-btn:not(:disabled):active { transform: scale(0.92); }
.send-btn svg { width: 18px; height: 18px; }
.stop-btn { background: var(--danger); color: #FFF; }
.stop-btn svg { width: 13px; height: 13px; }

/* Media Grid in Messages */
.media-grid { display: grid; gap: 6px; margin-top: 8px; }
.media-grid.count-1 { grid-template-columns: minmax(0, 280px); }
.media-grid.count-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); max-width: 380px; }
.media-grid.count-many { grid-template-columns: repeat(3, minmax(0, 1fr)); max-width: 420px; }
.media-thumb {
  border-radius: 13px; overflow: hidden; border: 1px solid var(--border);
  aspect-ratio: 4 / 3; background: var(--bg-subtle); display: block;
}
.media-grid.count-1 .media-thumb { aspect-ratio: auto; max-height: 320px; }
.media-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.file-chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.file-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 11px;
  border-radius: 10px; background: var(--bg-subtle); border: 1px solid var(--border);
  font-size: 13px; color: var(--text); text-decoration: none;
}

/* ==================== MOBILE TOPICS DRAWER & POPOVER MENU ==================== */
.drawer-backdrop {
  position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, 0.36);
  opacity: 0; pointer-events: none; transition: opacity 0.22s;
}
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }
.topics-drawer {
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 45;
  width: min(84vw, 316px); background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  transform: translateX(-104%); transition: transform 0.24s cubic-bezier(0.2, 0.8, 0.2, 1);
  padding-top: env(safe-area-inset-top, 0px);
}
.topics-drawer.open { transform: translateX(0); }
.drawer-head {
  height: 54px; padding: 0 12px 0 16px; display: flex; align-items: center; justify-content: space-between;
}
.drawer-title { font-size: 17px; font-weight: 700; letter-spacing: -0.02em; }
.drawer-tools { padding: 0 12px 10px; display: flex; gap: 8px; align-items: center; }
.drawer-list { flex: 1 1 auto; overflow-y: auto; padding: 2px 8px 20px; display: flex; flex-direction: column; gap: 2px; }

.popover-menu {
  position: fixed; top: 54px; right: 12px; z-index: 50; min-width: 172px;
  padding: 6px; border-radius: 16px;
  background: var(--bg-elevated); border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-md); display: flex; flex-direction: column; gap: 2px;
}
.popover-item {
  width: 100%; text-align: left; padding: 10px 12px; border-radius: 10px;
  font-size: 14px; font-weight: 500; color: var(--text); transition: background 0.14s;
}
.popover-item:hover { background: var(--bg-subtle); }
.popover-item.danger { color: var(--danger); }
.popover-divider { height: 1px; background: var(--border); margin: 4px 6px; }

/* ==================== ALIGNED V3 SELECTORS (LOGIN / HOME / CHAT) ==================== */
.login-screen {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: 28px 20px; background: var(--bg);
}
.login-btn {
  width: 100%; height: 48px; border-radius: 999px;
  background: var(--accent); color: var(--accent-fg);
  font-size: 15.5px; font-weight: 600;
  transition: transform 0.14s, opacity 0.14s;
}
.login-btn:hover { opacity: 0.92; }
.login-btn:active { transform: scale(0.985); }
.login-error { min-height: 20px; margin: 12px 0 0; font-size: 13px; color: var(--danger); }

.home-center {
  position: relative; z-index: 2;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; transform: none;
}
.working-pill-pulse {
  width: 8px; height: 8px; border-radius: 50%; background: var(--ok);
  box-shadow: 0 0 0 0 rgba(22, 198, 106, 0.5);
  animation: statusPulse 1.4s ease-out infinite;
}
.working-pill-arrow { color: var(--text-tertiary); font-weight: 600; margin-left: 2px; }

.home-circle-btn {
  position: relative; width: 60px; height: 60px; border-radius: 50%;
  background: var(--bg-glass);
  backdrop-filter: blur(22px) saturate(160%); -webkit-backdrop-filter: blur(22px) saturate(160%);
  border: 1px solid var(--border-strong); color: var(--text);
  box-shadow: var(--shadow-float);
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.2s cubic-bezier(0.22, 1, 0.36, 1), background 0.16s, box-shadow 0.2s;
}
.home-circle-btn:hover { transform: translateY(-2px) scale(1.03); background: var(--bg); }
.home-circle-btn:active { transform: scale(0.93); }
.home-circle-btn svg { width: 23px; height: 23px; }
.home-btn-dot {
  position: absolute; top: 9px; right: 9px; width: 8px; height: 8px; border-radius: 50%;
  background: var(--ok); border: 1.5px solid var(--bg);
  animation: statusPulse 1.5s ease-out infinite;
}
.home-circle-label {
  font-size: 11.5px; font-weight: 500; color: var(--text-tertiary);
  letter-spacing: 0.02em; user-select: none;
}

.sidebar-search-input {
  width: 100%; height: 36px; padding: 0 12px 0 34px; border-radius: 999px;
  background: var(--bg); border: 1px solid var(--border); color: var(--text); font-size: 13.5px;
  transition: border-color 0.15s;
}
.sidebar-search-input:focus { border-color: var(--text-secondary); }
.search-ico {
  position: absolute; left: 24px; top: 50%; transform: translateY(-50%);
  width: 15px; height: 15px; color: var(--text-tertiary); pointer-events: none;
}
.sidebar-search-wrap, .drawer-search-wrap { position: relative; padding: 8px 14px 10px; }
.sidebar-footer {
  padding: 10px 12px calc(10px + var(--safe-bottom));
  border-top: 1px solid var(--border);
}
.sidebar-profile-btn {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 13px; transition: background 0.14s;
}
.sidebar-profile-btn:hover { background: var(--bg-subtle); }
.sidebar-mascot-mini { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; }
.sidebar-mascot-name {
  flex: 1 1 auto; text-align: left; font-size: 14px; font-weight: 600; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sidebar-gear-ico { width: 17px; height: 17px; color: var(--text-tertiary); flex: 0 0 auto; }

.chat-topbar, .sub-topbar {
  background: var(--bg-glass);
  backdrop-filter: blur(18px) saturate(160%); -webkit-backdrop-filter: blur(18px) saturate(160%);
}
.back-pill-btn {
  display: inline-flex; align-items: center; gap: 3px; height: 34px;
  padding: 0 11px 0 6px; border-radius: 999px; color: var(--text);
  font-size: 14px; font-weight: 550; transition: background 0.14s;
}
.back-pill-btn:hover { background: var(--bg-subtle); }
.back-pill-btn svg { width: 18px; height: 18px; }
.header-mascot-wrap { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; }
.chat-title-stack { display: flex; flex-direction: column; min-width: 0; }
.chat-status-row {
  display: flex; align-items: center; gap: 5px; font-size: 11.5px; color: var(--text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
@media (min-width: 860px) {
  .mobile-only-btn { display: none !important; }
}

.composer-plus-btn {
  width: 36px; height: 36px; border-radius: 50%; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-secondary); transition: background 0.14s, color 0.14s;
}
.composer-plus-btn:hover { background: var(--bg-subtle); color: var(--text); }
.composer-plus-btn svg { width: 20px; height: 20px; }
.composer-send-btn, .composer-stop-btn {
  width: 36px; height: 36px; border-radius: 50%; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent); color: var(--accent-fg);
  transition: transform 0.14s, opacity 0.14s, background 0.14s;
}
.composer-send-btn:disabled {
  background: var(--bg-muted); color: var(--text-tertiary); opacity: 0.7; cursor: not-allowed;
}
.composer-send-btn:not(:disabled):active, .composer-stop-btn:active { transform: scale(0.92); }
.composer-send-btn svg { width: 18px; height: 18px; }
.stop-sq { width: 11px; height: 11px; border-radius: 2.5px; background: currentColor; display: block; }

.drawer-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(12px + var(--safe-top)) 14px 6px 18px;
}
.drawer-head-actions { display: flex; align-items: center; gap: 4px; }
.popover-sep { height: 1px; background: var(--border); margin: 4px 6px; }

.load-more-wrap { display: flex; justify-content: center; padding: 4px 0 10px; }
.media-card {
  position: relative; border-radius: 14px; overflow: hidden;
  border: 1px solid var(--border); background: var(--bg-subtle);
  cursor: zoom-in; max-width: 260px; display: block;
}
.media-card img { display: block; width: 100%; max-height: 260px; object-fit: cover; }
.file-pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px;
  border-radius: 10px; background: var(--bg-subtle); border: 1px solid var(--border);
  font-size: 13px; color: var(--text); margin-top: 6px;
}
.progress-label { font-weight: 550; color: var(--text); }
.progress-timer { font-size: 12px; color: var(--text-tertiary); font-variant-numeric: tabular-nums; margin-left: auto; }
.step-content { min-width: 0; flex: 1 1 auto; }
.step-check { color: var(--ok); font-weight: 700; font-size: 12px; }
.step-err { color: var(--danger); font-weight: 700; font-size: 12px; }
.reasoning-title { font-size: 11.5px; font-weight: 600; color: var(--text-tertiary); margin-bottom: 4px; }
.reasoning-text { margin: 0; white-space: pre-wrap; word-break: break-word; font-family: inherit; }
.topic-mascot-badge { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; }

/* Final polish: home action circle balance, chat header spacing, refined sidebar topic dot */
.home-circle-btn {
  width: 56px; height: 56px;
  background: var(--bg-subtle); border: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}
.home-circle-btn:hover { background: var(--bg-hover); border-color: var(--border-strong); }
.chat-identity-btn { gap: 10px; padding: 4px 10px 4px 6px; }
.chat-topbar .topbar-left { gap: 6px; }
.sidebar-topic-list .topic-mascot-badge { opacity: 0.82; transform: scale(0.88); }
.sidebar-topic-list .topic-row.active .topic-mascot-badge { opacity: 1; transform: scale(0.95); }

/* ==================== XIAOBAO HOME STORY STAGE (v3.1.0) ==================== */
.home-mascot-wrap.is-story-active {
  padding: 0;
  width: 100%;
  overflow: visible;
}
.home-mascot-wrap.is-story-active::after {
  display: none;
}
.story-stage {
  position: relative;
  width: clamp(336px, 98vw, 420px);
  aspect-ratio: 480 / 340;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
  user-select: none;
  -webkit-user-select: none;
}
.story-bounce-wrap {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100%;
  transform-origin: 50% 86%;
}
.story-canvas-wrap {
  width: 100%;
  height: 100%;
  transform-origin: 50% 86%;
  transform: scale(1.09);
  transition: transform 0.65s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform;
}
.story-stage.story-phase-wake .story-canvas-wrap {
  transform: scale(0.99);
}
.story-canvas {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.story-ground-shadow {
  position: absolute;
  left: 50%;
  bottom: 10.5%;
  width: 44%;
  height: 18px;
  transform: translateX(-50%);
  border-radius: 50%;
  pointer-events: none;
  z-index: 1;
  background: radial-gradient(ellipse at center, rgba(15, 23, 42, 0.14) 0%, transparent 72%);
  filter: blur(4px);
  transition: width 0.55s ease, opacity 0.4s ease;
}
html[data-theme="dark"] .story-ground-shadow {
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.52) 0%, transparent 72%);
}
.story-stage.story-phase-sit .story-ground-shadow {
  width: 36%;
}
.story-stage.story-phase-wake .story-ground-shadow {
  width: 54%;
  opacity: 0.85;
}

/* Floating Zzz Sleep Symbols */
.story-zzz-layer {
  position: absolute;
  left: 56%;
  top: 27%;
  width: 78px;
  height: 76px;
  pointer-events: none;
  z-index: 4;
  opacity: 0;
  transition: opacity 0.32s ease, transform 0.32s ease;
}
.story-zzz-layer.is-sleeping {
  opacity: 1;
}
.story-zzz-layer.is-scattered {
  opacity: 0;
  transform: translate(16px, -22px) scale(1.18);
}
.story-zzz-layer.is-disturbed {
  animation: storyZzzJolt 0.56s cubic-bezier(0.22, 1.35, 0.36, 1);
}
.story-z {
  position: absolute;
  font-family: ui-rounded, 'SF Pro Rounded', 'PingFang SC', system-ui, sans-serif;
  font-weight: 800;
  font-style: italic;
  line-height: 1;
  color: rgba(217, 119, 6, 0.86);
  text-shadow: 0 2px 10px rgba(245, 158, 11, 0.25);
  opacity: 0;
  will-change: transform, opacity;
}
html[data-theme="dark"] .story-z {
  color: rgba(251, 191, 36, 0.90);
  text-shadow: 0 2px 12px rgba(245, 158, 11, 0.38);
}
.story-zzz-layer.is-sleeping .story-z {
  animation: storyZzzFloat 3.0s ease-in-out infinite;
}
.story-z.z1 {
  left: 4px;
  bottom: 6px;
  font-size: 16px;
  animation-delay: 0s;
}
.story-z.z2 {
  left: 20px;
  bottom: 12px;
  font-size: 21px;
  animation-delay: 0.95s;
}
.story-z.z3 {
  left: 36px;
  bottom: 18px;
  font-size: 27px;
  animation-delay: 1.9s;
}
@keyframes storyZzzFloat {
  0% {
    opacity: 0;
    transform: translate(0px, 10px) scale(0.62) rotate(-10deg);
  }
  20% {
    opacity: 0.95;
    transform: translate(6px, -4px) scale(0.96) rotate(-4deg);
  }
  58% {
    opacity: 0.88;
    transform: translate(16px, -24px) scale(1.06) rotate(7deg);
  }
  100% {
    opacity: 0;
    transform: translate(24px, -44px) scale(0.84) rotate(13deg);
  }
}
@keyframes storyZzzJolt {
  0%   { transform: translate(0, 0) rotate(0deg); }
  22%  { transform: translate(8px, -7px) rotate(11deg) scale(1.12); }
  52%  { transform: translate(-4px, -2px) rotate(-6deg) scale(0.96); }
  100% { transform: translate(0, 0) rotate(0deg); }
}

/* Tactile Bounce Animations */
.story-bounce-wrap.story-flick-jolt {
  animation: storyFlickJolt 0.28s cubic-bezier(0.22, 1.35, 0.36, 1);
}
@keyframes storyFlickJolt {
  0%   { transform: scale(1, 1); }
  36%  { transform: scale(1.03, 0.97) translateY(1px); }
  100% { transform: scale(1, 1); }
}
.story-bounce-wrap.story-tap-bounce {
  animation: storyTapBounce 0.42s cubic-bezier(0.22, 1.4, 0.36, 1);
}
@keyframes storyTapBounce {
  0%   { transform: scale(1, 1) translateY(0); }
  26%  { transform: scale(1.06, 0.93) translateY(4px); }
  58%  { transform: scale(0.96, 1.05) translateY(-7px); }
  82%  { transform: scale(1.02, 0.99) translateY(1px); }
  100% { transform: scale(1, 1) translateY(0); }
}

/* Harmonize Home Center Spacing & Adaptive Bubble Position When Story Active */
.home-center.story-mode .home-mascot-name {
  margin-top: -12px;
}
.home-center.story-mode .home-poke-bubble {
  transition: bottom 0.36s cubic-bezier(0.22, 1, 0.36, 1);
}
.home-center.story-mode.story-phase-sleep .home-poke-bubble,
.home-center.story-mode.story-phase-flick .home-poke-bubble {
  bottom: calc(100% - 88px);
}
.home-center.story-mode.story-phase-wake .home-poke-bubble {
  bottom: calc(100% - 48px);
}
.home-center.story-mode.story-phase-sit .home-poke-bubble {
  bottom: calc(100% - 32px);
}
.home-center.story-mode .home-status-row {
  padding: 3px 10px;
  border-radius: 999px;
  transition: background 0.16s ease;
}
.home-status-row.can-tuck-sleep {
  cursor: pointer;
}
.home-status-row.can-tuck-sleep:active {
  background: var(--bg-subtle);
}

@media (max-height: 700px) {
  .story-stage {
    width: clamp(304px, 90vw, 344px);
  }
  .home-center.story-mode .home-mascot-name {
    margin-top: -14px;
  }
  .home-center.story-mode.story-phase-sleep .home-poke-bubble,
  .home-center.story-mode.story-phase-flick .home-poke-bubble {
    bottom: calc(100% - 60px);
  }
}

/* ==================== v3.2.0 MUSE TOP-STAGE CHAT LAYOUT ==================== */
#view-chat {
  --chat-canvas: #F5F6F8;
  --chat-stage-bg: linear-gradient(160deg, #ECEFF4 0%, #F4F1EC 52%, #EAECEF 100%);
  --chat-stage-border: rgba(15, 23, 42, 0.065);
  --chat-glass-bg: rgba(255, 255, 255, 0.72);
  --chat-glass-border: rgba(15, 23, 42, 0.08);
  --chat-glass-fg: #1F2329;
  --chat-pill-bg: rgba(255, 255, 255, 0.80);
  --chat-pill-border: rgba(15, 23, 42, 0.08);
  --chat-ai-card: #FFFFFF;
  --chat-ai-border: rgba(15, 23, 42, 0.06);
  --chat-ai-shadow: 0 1px 3px rgba(15, 23, 42, 0.045);
  --chat-user-bg: #1B1C22;
  --chat-user-fg: #FFFFFF;
  --chat-prog-bg: rgba(15, 23, 42, 0.042);
  --chat-prog-border: rgba(15, 23, 42, 0.075);
  --chat-composer-bg: #FFFFFF;
  --chat-composer-border: rgba(15, 23, 42, 0.11);
  --chat-composer-shadow: 0 6px 22px rgba(15, 23, 42, 0.075), 0 1px 3px rgba(15, 23, 42, 0.04);
  background: var(--chat-canvas);
}

html[data-theme="dark"] #view-chat {
  --chat-canvas: #050505;
  --chat-stage-bg: linear-gradient(160deg, #171821 0%, #141419 52%, #111115 100%);
  --chat-stage-border: rgba(255, 255, 255, 0.075);
  --chat-glass-bg: rgba(14, 15, 20, 0.58);
  --chat-glass-border: rgba(255, 255, 255, 0.12);
  --chat-glass-fg: #F2F4F8;
  --chat-pill-bg: rgba(18, 19, 24, 0.70);
  --chat-pill-border: rgba(255, 255, 255, 0.11);
  --chat-ai-card: #19191D;
  --chat-ai-border: rgba(255, 255, 255, 0.055);
  --chat-ai-shadow: none;
  --chat-user-bg: #383B4C;
  --chat-user-fg: #F5F6FA;
  --chat-prog-bg: rgba(255, 255, 255, 0.048);
  --chat-prog-border: rgba(255, 255, 255, 0.075);
  --chat-composer-bg: #17171B;
  --chat-composer-border: rgba(255, 255, 255, 0.11);
  --chat-composer-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

#view-chat .chat-main {
  background: var(--chat-canvas);
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  position: relative;
}

/* Top Dynamic Hero Mascot Stage */
.chat-stage-wrap {
  flex: 0 0 auto;
  width: 100%;
  max-width: 772px;
  margin: 0 auto;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 12px 4px;
}

.chat-hero-stage {
  position: relative;
  height: 210px;
  border-radius: 26px;
  overflow: hidden;
  background: var(--chat-stage-bg);
  border: 1px solid var(--chat-stage-border);
  box-shadow: var(--chat-ai-shadow);
  transition: height 0.32s cubic-bezier(0.22, 1, 0.36, 1), border-radius 0.28s ease;
}

.stage-ambient-glow {
  position: absolute;
  left: 50%;
  top: 52%;
  width: 240px;
  height: 170px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(ellipse at center, color-mix(in srgb, var(--stage-accent, #F59E0B) 24%, transparent) 0%, transparent 72%);
  pointer-events: none;
  z-index: 0;
  transition: opacity 0.3s ease, transform 0.35s ease;
}
html[data-theme="dark"] .stage-ambient-glow {
  background: radial-gradient(ellipse at center, color-mix(in srgb, var(--stage-accent, #F59E0B) 22%, transparent) 0%, transparent 72%);
}
.chat-hero-stage.is-running .stage-ambient-glow {
  transform: translate(-50%, -50%) scale(1.14);
  animation: stageGlowPulse 2.4s ease-in-out infinite;
}
@keyframes stageGlowPulse {
  0%, 100% { opacity: 0.78; }
  50% { opacity: 1; }
}

.stage-top-bar {
  position: relative;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 10px 0;
}

.stage-btn-group {
  display: flex;
  align-items: center;
  gap: 7px;
  flex: 0 0 auto;
}

.stage-glass-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--chat-glass-bg);
  border: 1px solid var(--chat-glass-border);
  color: var(--chat-glass-fg);
  backdrop-filter: blur(16px) saturate(160%);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.14s ease, background 0.16s ease;
}
.stage-glass-btn:active { transform: scale(0.92); }
.stage-glass-btn svg { width: 17px; height: 17px; }

.stage-expand-btn { display: none; }

/* Compact inline identity hidden while stage is expanded */
.stage-compact-mid {
  display: none;
  flex: 1 1 auto;
  min-width: 0;
  align-items: center;
  gap: 9px;
  text-align: left;
  padding: 3px 6px;
  border-radius: 999px;
}
.stage-compact-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.stage-compact-mid .chat-title-text {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.stage-compact-mid .chat-status-row {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Live Animated Mascot Arena */
.stage-mascot-arena {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-bottom: 18px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.22s ease, transform 0.28s ease;
}
.stage-ground-shadow {
  position: absolute;
  left: 50%;
  bottom: 36px;
  width: 118px;
  height: 15px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(15, 23, 42, 0.13) 0%, transparent 72%);
  filter: blur(4px);
  pointer-events: none;
}
html[data-theme="dark"] .stage-ground-shadow {
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.56) 0%, transparent 72%);
}
.chat-stage-mascot {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-stage-hero-mascot {
  filter: drop-shadow(0 6px 14px rgba(15, 23, 42, 0.08));
}
html[data-theme="dark"] .chat-stage-hero-mascot {
  filter: drop-shadow(0 8px 18px rgba(0, 0, 0, 0.42));
}

/* Bottom Frosted Status Pill + Subtle Fold Button */
.stage-bottom-row {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 9px;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.stage-status-pill {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: calc(100% - 76px);
  height: 27px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--chat-pill-bg);
  border: 1px solid var(--chat-pill-border);
  backdrop-filter: blur(16px) saturate(160%);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  font-size: 12px;
  color: var(--chat-glass-fg);
}
.stage-pill-name {
  font-weight: 650;
  flex: 0 0 auto;
}
.stage-pill-sep {
  opacity: 0.42;
  flex: 0 0 auto;
}
.stage-pill-text {
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.stage-fold-btn {
  pointer-events: auto;
  position: absolute;
  right: 0;
  bottom: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--chat-glass-bg);
  border: 1px solid var(--chat-glass-border);
  color: var(--text-secondary);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.14s ease, color 0.15s ease;
}
.stage-fold-btn:active { transform: scale(0.9); }
.stage-fold-btn svg { width: 14px; height: 14px; }

/* Compact Folded Stage State (manual toggle OR mobile soft keyboard) */
.chat-hero-stage.is-compact {
  height: 54px;
  border-radius: 18px;
}
.chat-hero-stage.is-compact .stage-top-bar {
  height: 100%;
  padding: 0 9px;
}
.chat-hero-stage.is-compact .stage-mascot-arena,
.chat-hero-stage.is-compact .stage-bottom-row {
  opacity: 0;
  pointer-events: none;
}
.chat-hero-stage.is-compact .stage-compact-mid {
  display: flex;
}
.chat-hero-stage.is-compact .stage-expand-btn {
  display: inline-flex;
}

/* Message Stream: Clean Avatarless Muse Cards */
#view-chat .chat-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  padding: 10px 14px 20px;
}
#view-chat .messages-inner {
  width: 100%;
  max-width: 744px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#view-chat .msg-time-divider {
  display: flex;
  justify-content: center;
  margin: 2px 0;
}
#view-chat .msg-time-divider span {
  font-size: 11px;
  color: var(--text-tertiary);
  padding: 2px 9px;
  border-radius: 999px;
}

#view-chat .msg-row {
  display: flex;
  flex-direction: column;
  width: 100%;
}
#view-chat .msg-row.user {
  align-items: flex-end;
}
#view-chat .msg-row.assistant {
  align-items: flex-start;
}

#view-chat .user-bubble {
  max-width: 82%;
  padding: 10px 15px;
  border-radius: 20px 20px 6px 20px;
  background: var(--chat-user-bg);
  color: var(--chat-user-fg);
  font-size: 14.5px;
  line-height: 1.52;
  word-break: break-word;
  box-shadow: var(--chat-ai-shadow);
}
#view-chat .user-bubble-text {
  white-space: pre-wrap;
}

#view-chat .assistant-card {
  max-width: min(94%, 680px);
  width: fit-content;
  min-width: 84px;
  padding: 13px 16px;
  border-radius: 20px;
  background: var(--chat-ai-card);
  border: 1px solid var(--chat-ai-border);
  box-shadow: var(--chat-ai-shadow);
  color: var(--text);
}
#view-chat .assistant-card--error {
  border-color: rgba(239, 68, 68, 0.34);
}
#view-chat .assistant-body {
  padding: 0;
  background: transparent;
  border: none;
  box-shadow: none;
}
#view-chat .assistant-card .md-body {
  font-size: 14.5px;
  line-height: 1.62;
  color: var(--text);
}
#view-chat .assistant-card .md-body > *:first-child { margin-top: 0; }
#view-chat .assistant-card .md-body > *:last-child { margin-bottom: 0; }

/* Compact Inline Progress / Reasoning Pill inside AI Card */
#view-chat .progress-card {
  margin: 0 0 9px;
  border-radius: 13px;
  background: var(--chat-prog-bg);
  border: 1px solid var(--chat-prog-border);
  overflow: hidden;
}
#view-chat .assistant-card .progress-card:last-child {
  margin-bottom: 0;
}
#view-chat .progress-header {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 11px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  text-align: left;
}
#view-chat .progress-label {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#view-chat .progress-timer {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--text-tertiary);
}
#view-chat .progress-body {
  padding: 0 11px 10px;
  border-top: 1px solid var(--chat-prog-border);
}
#view-chat .reasoning-box {
  margin-top: 8px;
}
#view-chat .reasoning-text {
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--text-secondary);
  max-height: 220px;
  overflow-y: auto;
  white-space: pre-wrap;
}

/* Muse 3-Dot Minimal Typing Pill */
.typing-dots-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 11px 16px;
  border-radius: 18px;
  background: var(--chat-ai-card);
  border: 1px solid var(--chat-ai-border);
  box-shadow: var(--chat-ai-shadow);
  margin-top: 6px;
}
.msg-row.assistant > .typing-dots-pill:first-child {
  margin-top: 0;
}
.typing-dots-pill span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-tertiary);
  animation: museTypingDot 1.3s ease-in-out infinite;
}
.typing-dots-pill span:nth-child(2) { animation-delay: 0.18s; }
.typing-dots-pill span:nth-child(3) { animation-delay: 0.36s; }
@keyframes museTypingDot {
  0%, 80%, 100% { opacity: 0.32; transform: translateY(0) scale(0.88); }
  40% { opacity: 1; transform: translateY(-2px) scale(1.06); }
}

/* Subtle Action Footer under AI Card */
#view-chat .msg-meta-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 5px;
  padding-left: 6px;
  font-size: 11.5px;
  color: var(--text-tertiary);
}
#view-chat .msg-action-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 999px;
  color: var(--text-tertiary);
  font-size: 11.5px;
  transition: background 0.14s, color 0.14s;
}
#view-chat .msg-action-link:hover {
  background: var(--chat-prog-bg);
  color: var(--text);
}
#view-chat .msg-action-link svg {
  width: 12px;
  height: 12px;
}

/* Clean Empty State (No duplicate mascot; Xiaobao is live in Hero Stage above!) */
#view-chat .chat-empty-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 26px 8px 16px;
  max-width: 440px;
  margin: auto;
}
#view-chat .chat-empty-stage h2 {
  margin: 0 0 6px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}
#view-chat .chat-empty-stage p {
  margin: 0 0 20px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-secondary);
}
#view-chat .quick-chips {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}
#view-chat .chip-btn {
  padding: 12px 13px;
  border-radius: 16px;
  background: var(--chat-ai-card);
  border: 1px solid var(--chat-ai-border);
  box-shadow: var(--chat-ai-shadow);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.38;
  text-align: left;
  transition: transform 0.14s ease, border-color 0.15s ease;
}
#view-chat .chip-btn:active {
  transform: scale(0.97);
}

/* Ultra-Slim Single-Row Floating Pill Composer */
#view-chat .composer-wrap {
  flex: 0 0 auto;
  width: 100%;
  max-width: 772px;
  margin: 0 auto;
  padding: 6px 12px calc(12px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to top, var(--chat-canvas) 74%, transparent 100%);
}
#view-chat .composer-shell {
  display: flex;
  align-items: flex-end;
  gap: 7px;
  padding: 6px 6px 6px 8px;
  border-radius: 26px;
  background: var(--chat-composer-bg);
  border: 1px solid var(--chat-composer-border);
  box-shadow: var(--chat-composer-shadow);
}
#view-chat .composer-plus-btn {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: background 0.14s, color 0.14s;
}
#view-chat .composer-plus-btn:hover {
  background: var(--chat-prog-bg);
  color: var(--text);
}
#view-chat .composer-plus-btn svg { width: 19px; height: 19px; }

#view-chat .composer-input {
  flex: 1 1 auto;
  min-height: 34px;
  max-height: 120px;
  padding: 6px 4px;
  font-size: 15px;
  line-height: 1.42;
  color: var(--text);
}

#view-chat .composer-send-btn,
#view-chat .composer-stop-btn {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s, transform 0.12s;
}
#view-chat .composer-send-btn {
  background: var(--accent);
  color: var(--accent-inv);
}
#view-chat .composer-send-btn:disabled {
  opacity: 0.28;
}
#view-chat .composer-send-btn svg { width: 17px; height: 17px; }
#view-chat .composer-stop-btn {
  background: #4C4F66;
  color: #FFFFFF;
}
#view-chat .composer-stop-btn .stop-sq {
  width: 11px;
  height: 11px;
  border-radius: 2.5px;
  background: currentColor;
  display: block;
}

/* Popover menu aligns neatly under top-right glass button */
#chat-more-menu.popover-menu {
  top: calc(56px + env(safe-area-inset-top, 0px));
  right: 18px;
}

/* Scroll-to-bottom floating button position */
#view-chat .scroll-bottom-btn {
  position: absolute;
  right: 16px;
  bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  z-index: 15;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--chat-composer-bg);
  border: 1px solid var(--chat-composer-border);
  color: var(--text);
  box-shadow: var(--chat-composer-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Responsive Adjustments */
@media (max-height: 700px) {
  .chat-hero-stage { height: 176px; border-radius: 22px; }
  .stage-ground-shadow { bottom: 32px; }
}
@media (max-height: 520px) {
  /* Auto-compact when mobile soft keyboard is open */
  .chat-hero-stage { height: 52px; border-radius: 16px; }
  .chat-hero-stage .stage-top-bar { height: 100%; padding: 0 9px; }
  .chat-hero-stage .stage-mascot-arena,
  .chat-hero-stage .stage-bottom-row { opacity: 0; pointer-events: none; }
  .chat-hero-stage .stage-compact-mid { display: flex; }
}
@media (min-width: 860px) {
  .chat-stage-wrap { padding: 12px 16px 6px; }
  .chat-hero-stage { height: 190px; }
  #view-chat .mobile-only-btn { display: none !important; }
  #chat-more-menu.popover-menu { top: 64px; right: max(24px, calc(50% - 368px)); }
}

/* v3.2.1 Polish: eliminate nested scrollbars on thinking blocks & keep subtle scrollbar */
#view-chat .thinking-block {
  overflow: visible;
  max-height: none;
}
#view-chat .thinking-body {
  max-height: 240px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
}
#view-chat .thinking-body pre {
  overflow: visible;
  max-height: none;
  white-space: pre-wrap;
  word-break: break-word;
}

/* v3.2.2 Polish: dark color-scheme + sleek scrollbars + single scroll on reasoning cards */
html[data-theme="dark"] {
  color-scheme: dark;
}
html[data-theme="light"] {
  color-scheme: light;
}
#view-chat .chat-scroll::-webkit-scrollbar,
#view-chat .sidebar-topic-list::-webkit-scrollbar,
#view-chat .drawer-list::-webkit-scrollbar,
#view-chat .reasoning-body::-webkit-scrollbar,
#view-chat .reasoning-card::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}
#view-chat .chat-scroll::-webkit-scrollbar-track,
#view-chat .sidebar-topic-list::-webkit-scrollbar-track,
#view-chat .drawer-list::-webkit-scrollbar-track,
#view-chat .reasoning-body::-webkit-scrollbar-track,
#view-chat .reasoning-card::-webkit-scrollbar-track {
  background: transparent;
}
#view-chat .chat-scroll::-webkit-scrollbar-thumb,
#view-chat .sidebar-topic-list::-webkit-scrollbar-thumb,
#view-chat .drawer-list::-webkit-scrollbar-thumb,
#view-chat .reasoning-body::-webkit-scrollbar-thumb,
#view-chat .reasoning-card::-webkit-scrollbar-thumb {
  background: rgba(128, 134, 148, 0.28);
  border-radius: 999px;
}
html[data-theme="dark"] #view-chat ::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.16);
}
#view-chat .reasoning-card,
#view-chat .thought-card,
#view-chat .think-card,
#view-chat details.reasoning-card,
#view-chat details.think-details {
  overflow: visible !important;
  max-height: none !important;
}
#view-chat .reasoning-body,
#view-chat .thought-body,
#view-chat .think-body {
  max-height: 220px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
}
#view-chat .reasoning-body pre,
#view-chat .reasoning-body .md-body,
#view-chat .thought-body pre,
#view-chat .think-body pre {
  overflow: visible !important;
  max-height: none !important;
  white-space: pre-wrap;
  word-break: break-word;
}

#view-chat .reasoning-box { max-height: none !important; overflow: visible !important; }


/* ==================== v3.2.3 ULTRA-MINIMAL COLLAPSIBLE THINKING PILL ==================== */
#view-chat .progress-card {
  width: auto;
  max-width: 100%;
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  background: transparent;
  border: none;
  border-radius: 12px;
  margin-bottom: 10px;
  overflow: visible;
}
#view-chat .progress-card.is-expanded {
  display: flex;
  width: 100%;
}
#view-chat .progress-header {
  width: auto;
  max-width: 100%;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 9px;
  border-radius: 999px;
  background: var(--chat-prog-bg);
  border: 1px solid var(--chat-prog-border);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.3;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.14s ease, color 0.14s ease, border-color 0.14s ease;
}
#view-chat .progress-header:hover {
  color: var(--text-secondary);
  border-color: var(--border-strong);
}
#view-chat .progress-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#view-chat .progress-timer {
  font-variant-numeric: tabular-nums;
  font-size: 11.5px;
  opacity: 0.78;
}
#view-chat .progress-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex: 0 0 auto;
  background: var(--text-muted);
  opacity: 0.55;
}
#view-chat .progress-dot.is-done {
  background: var(--text-muted);
  opacity: 0.48;
}
#view-chat .progress-dot.is-live {
  background: #F59E0B;
  opacity: 1;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.22);
  animation: dotPulse 1.15s ease-in-out infinite;
}
#view-chat .progress-dot.is-error {
  background: var(--danger);
  opacity: 1;
}
#view-chat .progress-chevron {
  display: inline-block;
  font-size: 13px;
  line-height: 1;
  opacity: 0.65;
  margin-left: 1px;
  transition: transform 0.16s ease;
}
#view-chat .progress-card.is-expanded .progress-chevron {
  transform: rotate(90deg);
}
#view-chat .progress-card.is-collapsed .progress-body {
  display: none !important;
}
#view-chat .progress-body {
  width: 100%;
  margin-top: 8px;
  padding: 2px 0 2px 11px;
  border-top: none;
  border-left: 2px solid var(--chat-prog-border);
}
#view-chat .progress-body .step-list {
  padding-top: 0;
  gap: 5px;
  margin-bottom: 6px;
}
#view-chat .progress-body .step-item {
  font-size: 12px;
  color: var(--text-secondary);
}
#view-chat .reasoning-box {
  margin-top: 0;
  padding: 0;
  background: transparent;
  max-height: none !important;
  overflow: visible !important;
}
#view-chat .reasoning-text {
  font-size: 12px;
  line-height: 1.55;
  color: var(--text-muted);
  max-height: 180px;
  overflow-y: auto;
  padding-right: 4px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* === v3.2.4: Silky Auto Pull-Down & Auto-Fold During Tasks === */
.chat-hero-stage {
  transition:
    height 0.42s cubic-bezier(0.22, 1, 0.36, 1),
    border-radius 0.42s cubic-bezier(0.22, 1, 0.36, 1),
    border-color 0.3s ease,
    box-shadow 0.35s ease;
}
.chat-hero-stage .stage-mascot-arena {
  transform: translateY(0) scale(1);
  transition: opacity 0.28s ease, transform 0.42s cubic-bezier(0.22, 1, 0.36, 1);
}
.chat-hero-stage.is-compact .stage-mascot-arena {
  transform: translateY(-14px) scale(0.9);
}
.chat-hero-stage.is-working {
  border-color: rgba(245, 158, 11, 0.34);
  box-shadow: 0 8px 28px rgba(245, 158, 11, 0.10);
}
html[data-theme="dark"] .chat-hero-stage.is-working {
  border-color: rgba(251, 191, 36, 0.28);
  box-shadow: 0 8px 30px rgba(245, 158, 11, 0.12);
}

/* ==================== v3.2.5: Ultra-Clean 2-Button Header + Peeking Animated Cat-Head ==================== */
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* Bigger hero Xiaobao in expanded stage with subtle optical centering */
.chat-hero-stage {
  height: 228px;
}
.stage-mascot-arena {
  padding-top: 6px;
  padding-bottom: 42px;
}
.chat-stage-hero-mascot {
  transform: translateX(4%);
}
.chat-hero-stage[data-state="happy"] .chat-stage-hero-mascot {
  transform: translateX(1%);
}

/* Top bar: purely symmetrical Left Back + Right Integrated Menu */
.stage-top-bar {
  padding: 11px 12px 0;
  align-items: center;
}
.chat-hero-stage.is-compact {
  height: 60px;
  border-radius: 20px;
}
.chat-hero-stage.is-compact .stage-top-bar {
  padding: 0 12px;
  height: 60px;
}

/* Bottom status pill doubles as a subtle tap-to-fold control (zero extra corner buttons) */
button.stage-status-pill {
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.14s ease, background 0.16s ease, border-color 0.2s ease;
}
button.stage-status-pill:active {
  transform: scale(0.96);
}
.stage-pill-chevron {
  width: 13px;
  height: 13px;
  margin-left: 2px;
  opacity: 0.62;
  flex: 0 0 auto;
  transition: opacity 0.16s ease, transform 0.16s ease;
}
button.stage-status-pill:hover .stage-pill-chevron {
  opacity: 0.95;
  transform: translateY(-1px);
}

/* Compact-only center button: ONLY live animated peeking cat-head, zero text clutter */
.stage-compact-mid {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: none;
  align-items: center;
  justify-content: center;
  width: 96px;
  height: 60px;
  padding: 0;
  margin: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.chat-hero-stage.is-compact .stage-compact-mid {
  display: inline-flex;
  animation: catheadPopIn 0.28s cubic-bezier(0.22, 1, 0.36, 1) both;
}
@keyframes catheadPopIn {
  from { opacity: 0; transform: translate(-50%, -36%) scale(0.88); }
  to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
.stage-compact-mid:active .compact-cathead-window {
  transform: scale(0.94);
}

/* Peeking Cat-Head Window (frameless soft bottom fade, centered on Xiaobao's animated head) */
.compact-cathead-window {
  position: relative;
  display: block;
  width: 84px;
  height: 58px;
  overflow: hidden;
  pointer-events: none;
  transition: transform 0.16s cubic-bezier(0.22, 1, 0.36, 1);
  -webkit-mask-image: linear-gradient(to bottom, #000 0%, #000 58%, rgba(0, 0, 0, 0.45) 80%, transparent 99%);
  mask-image: linear-gradient(to bottom, #000 0%, #000 58%, rgba(0, 0, 0, 0.45) 80%, transparent 99%);
  filter: drop-shadow(0 3px 8px rgba(15, 23, 42, 0.12));
}
html[data-theme="dark"] .compact-cathead-window {
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.45));
}
.compact-cathead-window .mascot-stage.mascot-custom {
  width: 84px !important;
  height: 58px !important;
  --m-size: 84px !important;
  display: block;
}
.compact-cathead-window .mascot-stage.mascot-custom .mascot-inner {
  width: 84px !important;
  height: 58px !important;
  position: relative;
  transform: none !important;
  animation: none !important;
}
.compact-cathead-window .mascot-stage.mascot-custom .mascot-custom-img {
  position: absolute !important;
  max-width: none !important;
  max-height: none !important;
  object-fit: contain;
  animation: none !important;
  transform: none !important;
}
/* Pixel-calibrated head centers for all 4 live animated Xiaobao WebPs */
.compact-cathead-window[data-state="idle"] .mascot-custom .mascot-custom-img,
.compact-cathead-window .mascot-custom.mascot-state-idle .mascot-custom-img {
  width: 122px !important;
  height: 122px !important;
  left: 1px;
  top: -4px;
}
.compact-cathead-window[data-state="working"] .mascot-custom .mascot-custom-img,
.compact-cathead-window .mascot-custom.mascot-state-working .mascot-custom-img {
  width: 120px !important;
  height: 120px !important;
  left: 0px;
  top: -10px;
}
.compact-cathead-window[data-state="happy"] .mascot-custom .mascot-custom-img,
.compact-cathead-window .mascot-custom.mascot-state-happy .mascot-custom-img {
  width: 114px !important;
  height: 114px !important;
  left: -4px;
  top: -4px;
}
.compact-cathead-window[data-state="error"] .mascot-custom .mascot-custom-img,
.compact-cathead-window .mascot-custom.mascot-state-error .mascot-custom-img {
  width: 104px !important;
  height: 104px !important;
  left: 6px;
  top: -7px;
}
/* Fallback for built-in SVG presets */
.compact-cathead-window .mascot-stage.mascot-preset {
  width: 46px !important;
  height: 46px !important;
  margin: 6px auto 0;
}

/* Integrated Menu styling with crisp icons */
#chat-more-menu.popover-menu {
  min-width: 184px;
  padding: 6px;
  border-radius: 18px;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
#chat-more-menu .popover-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
}
#chat-more-menu .pop-ic {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  opacity: 0.78;
}
#chat-more-menu .popover-item.danger .pop-ic {
  opacity: 0.92;
}

@media (max-height: 560px) {
  .chat-hero-stage { height: 56px; border-radius: 18px; }
  .chat-hero-stage .stage-top-bar { padding: 0 12px; height: 56px; }
  .chat-hero-stage .stage-mascot-arena,
  .chat-hero-stage .stage-bottom-row { opacity: 0; pointer-events: none; }
  .chat-hero-stage .stage-compact-mid { display: inline-flex; height: 56px; }
}
@media (min-width: 860px) {
  .chat-hero-stage { height: 204px; }
  .chat-hero-stage.is-compact { height: 60px; }
  #chat-more-menu .mobile-only-menu-item { display: none !important; }
}

/* ==================== v3.2.6: Dedicated Warm-Orange Xiaobao Head Icon in Compact Bar ==================== */
@keyframes compactHeadFloat {
  0%, 100% { transform: translateY(0px) rotate(0deg); }
  50% { transform: translateY(-1.5px) rotate(1.6deg); }
}
.compact-cathead-window[data-mode="custom-head"] {
  width: 58px;
  height: 54px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
  -webkit-mask-image: none;
  mask-image: none;
  filter: drop-shadow(0 3px 7px rgba(15, 23, 42, 0.13));
}
html[data-theme="dark"] .compact-cathead-window[data-mode="custom-head"] {
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.52));
}
.compact-xiaobao-head-img {
  width: 50px;
  height: 50px;
  object-fit: contain;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
  animation: compactHeadFloat 3.6s ease-in-out infinite;
  will-change: transform;
}
.stage-compact-mid:hover .compact-cathead-window[data-mode="custom-head"] {
  transform: scale(1.06);
}
.stage-compact-mid:active .compact-cathead-window[data-mode="custom-head"] {
  transform: scale(0.92);
}
@media (prefers-reduced-motion: reduce) {
  .compact-xiaobao-head-img { animation: none; }
}

/* ==================== v3.2.7: Animated Compact Head Canvas + Pet Bounce, Particles & Bubble ==================== */
.chat-hero-stage.is-compact {
  touch-action: pan-x;
}
.chat-hero-stage.is-compact .stage-compact-mid {
  transform: translate(-50%, calc(-50% + var(--pull-y, 0px)));
  transition: transform 0.16s cubic-bezier(0.22, 1, 0.36, 1);
}
.compact-cathead-window[data-mode="custom-head"] {
  width: 60px;
  height: 56px;
}
.compact-head-canvas {
  display: block;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
  transition: opacity 0.18s ease;
  animation: compactHeadFloat 4.2s ease-in-out infinite;
}
.compact-xiaobao-head-img.is-fallback {
  position: absolute;
  width: 54px;
  height: 54px;
  transition: opacity 0.18s ease;
}
@keyframes compactHeadBounce {
  0%   { transform: scale(1, 1); }
  26%  { transform: scale(1.12, 0.90) translateY(2px); }
  58%  { transform: scale(0.95, 1.07) translateY(-2px); }
  82%  { transform: scale(1.03, 0.98) translateY(0px); }
  100% { transform: scale(1, 1); }
}
.compact-cathead-window.is-pet-bounce {
  animation: compactHeadBounce 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}
.compact-pet-particle {
  position: fixed;
  z-index: 1200;
  pointer-events: none;
  font-size: 13px;
  line-height: 1;
  user-select: none;
  transform: translate(-50%, -50%) scale(0.6);
  opacity: 0;
  animation: compactParticleFloat 1.05s cubic-bezier(0.2, 0.85, 0.3, 1) forwards;
}
@keyframes compactParticleFloat {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.55); }
  18%  { opacity: 1; transform: translate(calc(-50% + var(--dx, 0px) * 0.25), calc(-50% + var(--dy, 20px) * 0.18)) scale(1.08); }
  100% { opacity: 0; transform: translate(calc(-50% + var(--dx, 0px)), calc(-50% + var(--dy, 28px))) scale(0.82); }
}
.compact-pet-bubble {
  position: fixed;
  z-index: 1190;
  pointer-events: none;
  transform: translate(-50%, -4px) scale(0.92);
  opacity: 0;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.01em;
  white-space: nowrap;
  color: #7c4a12;
  background: rgba(255, 250, 242, 0.92);
  border: 1px solid rgba(245, 158, 11, 0.26);
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.10);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  transition: opacity 0.2s ease, transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}
html[data-theme="dark"] .compact-pet-bubble {
  color: #fde68a;
  background: rgba(30, 34, 46, 0.90);
  border-color: rgba(251, 191, 36, 0.28);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.42);
}
.compact-pet-bubble.is-visible {
  opacity: 1;
  transform: translate(-50%, 0px) scale(1);
}

/* ==================== v3.2.8: Enlarged Top Panel + Frosted Pure-Icon Capsule Buttons + Generous Touch Targets ==================== */
.chat-stage-wrap {
  padding: calc(8px + env(safe-area-inset-top, 0px)) 10px 6px;
}
.chat-hero-stage {
  height: 256px;
  border-radius: 28px;
}
.chat-hero-stage.is-compact {
  height: 84px;
  border-radius: 24px;
}
.stage-top-bar {
  padding: 14px 14px 0;
  align-items: center;
}
.chat-hero-stage.is-compact .stage-top-bar {
  padding: 0 14px;
  height: 84px;
}

/* Pure-icon frosted capsule buttons (64x44px visual + generous hit-slop, Apple HIG 44pt+ compliant) */
.stage-glass-btn {
  position: relative;
  width: 64px;
  height: 44px;
  padding: 0;
  border-radius: 999px;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.07), inset 0 1px 0 rgba(255, 255, 255, 0.72);
  transition: transform 0.14s cubic-bezier(0.22, 1, 0.36, 1), background 0.16s ease, box-shadow 0.16s ease;
}
.stage-glass-btn::after {
  content: '';
  position: absolute;
  inset: -5px -6px;
  border-radius: 999px;
}
html[data-theme="dark"] .stage-glass-btn {
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.36), inset 0 1px 0 rgba(255, 255, 255, 0.09);
}
.stage-glass-btn:hover {
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.10), inset 0 1px 0 rgba(255, 255, 255, 0.85);
}
html[data-theme="dark"] .stage-glass-btn:hover {
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.14);
}
.stage-glass-btn:active {
  transform: scale(0.93);
}
.stage-glass-btn svg {
  width: 21px;
  height: 21px;
}

/* Generous center touch zone for petting, long-press & pull-down */
.stage-compact-mid {
  width: min(176px, calc(100% - 172px));
  height: 84px;
}
.compact-cathead-window[data-mode="custom-head"] {
  width: 76px;
  height: 74px;
  filter: drop-shadow(0 4px 10px rgba(15, 23, 42, 0.14));
}
html[data-theme="dark"] .compact-cathead-window[data-mode="custom-head"] {
  filter: drop-shadow(0 5px 14px rgba(0, 0, 0, 0.54));
}
.compact-head-canvas {
  width: 70px;
  height: 70px;
}
.compact-xiaobao-head-img.is-fallback {
  width: 70px;
  height: 70px;
}
.compact-pet-particle {
  font-size: 15px;
}
.compact-pet-bubble {
  padding: 5px 13px;
  font-size: 12.5px;
}

/* Expanded stage proportions for larger 196px Hero Xiaobao + roomier bottom status pill */
.stage-ambient-glow {
  width: 270px;
  height: 192px;
}
.stage-mascot-arena {
  padding-top: 10px;
  padding-bottom: 50px;
}
button.stage-status-pill {
  position: relative;
  min-height: 36px;
  padding: 7px 16px;
  font-size: 13px;
}
button.stage-status-pill::after {
  content: '';
  position: absolute;
  inset: -6px -10px;
  border-radius: 999px;
}

/* Popover aligned cleanly underneath the taller right capsule button */
#chat-more-menu.popover-menu {
  top: calc(78px + env(safe-area-inset-top, 0px));
  right: 16px;
}

@media (max-height: 560px) {
  .chat-hero-stage { height: 72px; border-radius: 22px; }
  .chat-hero-stage .stage-top-bar { padding: 0 12px; height: 72px; }
  .chat-hero-stage .stage-compact-mid { display: inline-flex; height: 72px; }
  .stage-glass-btn { width: 58px; height: 40px; }
  .compact-cathead-window[data-mode="custom-head"] { width: 64px; height: 62px; }
  .compact-head-canvas, .compact-xiaobao-head-img.is-fallback { width: 58px; height: 58px; }
}
@media (min-width: 860px) {
  .chat-hero-stage { height: 232px; }
  .chat-hero-stage.is-compact { height: 84px; }
  #chat-more-menu.popover-menu { top: 84px; right: max(24px, calc(50% - 368px)); }
}

/* ==================== v3.2.9: Full-Area Cat-Head Hit-Test Fix (Zero Hidden-Overlay Occlusion) ==================== */
.stage-top-bar {
  pointer-events: none;
}
.stage-top-bar > .stage-glass-btn {
  pointer-events: auto;
  z-index: 8;
}
.stage-top-bar > .stage-compact-mid {
  pointer-events: auto;
  z-index: 5;
  touch-action: none;
  -webkit-touch-callout: none;
}
.chat-hero-stage.is-compact .stage-top-bar {
  z-index: 6;
}
/* Critical fix: children of .stage-bottom-row (#btn-chat-stage-toggle & its ::after) had pointer-events:auto,
   which overrode parent pointer-events:none and silently intercepted taps on the middle/lower half of the cat head! */
.chat-hero-stage.is-compact .stage-mascot-arena,
.chat-hero-stage.is-compact .stage-mascot-arena *,
.chat-hero-stage.is-compact .stage-bottom-row,
.chat-hero-stage.is-compact .stage-bottom-row * {
  pointer-events: none !important;
  visibility: hidden;
}
.chat-hero-stage.is-compact .stage-compact-mid {
  width: calc(100% - 172px);
  height: 100%;
  max-width: 240px;
  border-radius: 16px;
}
@media (max-height: 560px) {
  .chat-hero-stage .stage-mascot-arena,
  .chat-hero-stage .stage-mascot-arena *,
  .chat-hero-stage .stage-bottom-row,
  .chat-hero-stage .stage-bottom-row * {
    pointer-events: none !important;
    visibility: hidden;
  }
  .chat-hero-stage .stage-top-bar { z-index: 6; }
  .chat-hero-stage .stage-compact-mid {
    width: calc(100% - 144px);
    height: 100%;
    max-width: 240px;
  }
}

/* ==================== v3.3.0: Dedicated History Center (Timeline + Image Gallery ONLY) ==================== */
.history-topbar {
  position: relative;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 14px 10px;
  background: var(--bg);
  z-index: 12;
}

.history-capsule-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 44px;
  border-radius: 999px;
  background: var(--glass-dock);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  color: var(--text);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  transition: transform 0.14s ease, background 0.16s ease, border-color 0.16s ease;
  flex-shrink: 0;
}
.history-capsule-btn::after {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 999px;
}
.history-capsule-btn svg {
  width: 20px;
  height: 20px;
}
.history-capsule-btn:active {
  transform: scale(0.95);
}
.history-capsule-btn.is-active {
  background: var(--accent);
  color: var(--accent-inv);
  border-color: transparent;
}

/* Segmented Capsule Switcher: 时间线 | 图库 */
.history-seg {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  height: 44px;
  padding: 4px;
  min-width: 196px;
  max-width: 240px;
  flex: 1 1 auto;
  border-radius: 999px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.04);
}
.history-seg-thumb {
  position: absolute;
  top: 4px;
  left: 4px;
  width: calc(50% - 4px);
  height: calc(100% - 8px);
  border-radius: 999px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  transition: transform 0.24s cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
  z-index: 1;
}
html[data-theme="dark"] .history-seg-thumb {
  background: #2A2D35;
  border-color: rgba(255, 255, 255, 0.08);
}
.history-seg[data-active="gallery"] .history-seg-thumb {
  transform: translateX(100%);
}
.history-seg-btn {
  position: relative;
  z-index: 2;
  height: 36px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: color 0.18s ease;
  white-space: nowrap;
}
.history-seg-btn svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}
.history-seg-btn.active {
  color: var(--text);
  font-weight: 600;
}

/* Collapsible Search Drawer (RULE 7: visibility:hidden + descendant pointer-events:none when closed) */
.history-search-wrap {
  flex-shrink: 0;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  visibility: hidden;
  pointer-events: none;
  padding: 0 14px;
  transition: max-height 0.22s ease, opacity 0.18s ease, padding-bottom 0.22s ease;
}
.history-search-wrap * {
  pointer-events: none !important;
}
.history-search-wrap.is-open {
  max-height: 58px;
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  padding-bottom: 10px;
}
.history-search-wrap.is-open * {
  pointer-events: auto !important;
}
.history-search-box {
  position: relative;
  display: flex;
  align-items: center;
  height: 42px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  gap: 8px;
}
.history-search-box:focus-within {
  border-color: var(--border-strong);
  background: var(--bg-elevated);
}
.history-search-ic {
  width: 16px;
  height: 16px;
  color: var(--text-tertiary);
  flex-shrink: 0;
}
.history-search-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  outline: none;
  font-size: 14.5px;
  color: var(--text);
}
.history-search-input::placeholder {
  color: var(--text-tertiary);
}
.history-search-clear {
  width: 24px;
  height: 24px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--border);
  color: var(--text-secondary);
  flex-shrink: 0;
}
.history-search-clear svg {
  width: 13px;
  height: 13px;
}

/* Scroll Body */
.history-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 14px calc(env(safe-area-inset-bottom, 0px) + 28px);
  background: var(--bg);
}
.history-content {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
}

/* Subtle Meta Strip */
.history-meta-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 4px 14px;
}
.history-meta-text {
  font-size: 12.5px;
  color: var(--text-tertiary);
  letter-spacing: 0.01em;
}
.history-meta-syncing {
  font-size: 12px;
  color: var(--text-tertiary);
}

/* ==================== CHAT TIMELINE ==================== */
.tl-stream {
  display: flex;
  flex-direction: column;
}
.tl-day-group {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 10px;
}
.tl-day-rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 6px;
}
.tl-day-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--text-tertiary);
  flex-shrink: 0;
}
.tl-day-group.is-today .tl-day-dot {
  background: #F59E0B;
  border-color: #F59E0B;
  box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.18);
}
.tl-day-line {
  width: 1.5px;
  flex: 1;
  margin-top: 6px;
  background: var(--border);
  min-height: 18px;
}
.tl-day-group:last-child .tl-day-line {
  background: linear-gradient(to bottom, var(--border), transparent);
}
.tl-day-body {
  padding-bottom: 20px;
  min-width: 0;
}
.tl-day-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 9px;
}
.tl-day-label {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: -0.01em;
}
.tl-day-group.is-today .tl-day-label {
  color: var(--text);
}
.tl-day-count {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-tertiary);
  background: var(--bg-subtle);
  padding: 1px 7px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}
.tl-day-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.tl-card {
  width: 100%;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 14px;
  border-radius: 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  transition: transform 0.14s ease, background 0.16s ease, border-color 0.16s ease;
}
.tl-card:hover {
  border-color: var(--border-strong);
}
.tl-card:active {
  transform: scale(0.985);
  background: var(--bg-subtle);
}
.tl-card-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.tl-card-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}
.tl-card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.015em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tl-card-time {
  font-size: 12px;
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.tl-card-preview {
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}
.tl-card-chevron {
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* ==================== HISTORY IMAGE GALLERY ==================== */
.hg-filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 0 14px;
  overflow-x: auto;
  scrollbar-width: none;
}
.hg-filter-bar::-webkit-scrollbar {
  display: none;
}
.hg-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 34px;
  padding: 0 13px;
  border-radius: 999px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  transition: background 0.16s ease, color 0.16s ease, border-color 0.16s ease, transform 0.12s ease;
}
.hg-chip:active {
  transform: scale(0.96);
}
.hg-chip-n {
  font-size: 11.5px;
  opacity: 0.72;
  font-variant-numeric: tabular-nums;
}
.hg-chip.active {
  background: var(--accent);
  color: var(--accent-inv);
  border-color: transparent;
}
.hg-chip.active .hg-chip-n {
  opacity: 0.85;
}

.hg-sections {
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.hg-date-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 0 2px 8px;
}
.hg-date-label {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: -0.01em;
}
.hg-date-count {
  font-size: 12px;
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}
.hg-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5px;
}
@media (min-width: 640px) {
  .hg-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
  }
}
@media (min-width: 960px) {
  .hg-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 10px;
  }
}
.hg-tile {
  position: relative;
  aspect-ratio: 1 / 1;
  width: 100%;
  border-radius: 11px;
  overflow: hidden;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  padding: 0;
  display: block;
  transition: transform 0.14s ease, opacity 0.14s ease;
}
.hg-tile:active {
  transform: scale(0.965);
}
.hg-tile-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.hg-tile-badge {
  position: absolute;
  right: 5px;
  bottom: 5px;
  padding: 2px 6px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  line-height: 1.25;
  color: #FFFFFF;
  background: rgba(17, 18, 22, 0.56);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  pointer-events: none;
}

.hg-more-wrap {
  display: flex;
  justify-content: center;
  padding: 20px 0 6px;
}
.hg-more-btn {
  height: 40px;
  padding: 0 20px;
  border-radius: 999px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-secondary);
}
.hg-more-btn:active {
  transform: scale(0.97);
}

/* Empty & Skeleton states */
.history-empty {
  padding: 64px 20px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.history-empty-ic {
  width: 38px;
  height: 38px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.history-empty-title {
  font-size: 15.5px;
  font-weight: 600;
  color: var(--text);
}
.history-empty-sub {
  font-size: 13px;
  color: var(--text-secondary);
}
.history-retry-btn {
  margin-top: 8px;
  height: 36px;
  padding: 0 18px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-inv);
  font-size: 13.5px;
  font-weight: 600;
}
.history-skeleton-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 8px;
}
.history-skel-head {
  width: 110px;
  height: 16px;
  border-radius: 8px;
  background: var(--bg-subtle);
}
.history-skel-card {
  height: 68px;
  border-radius: 16px;
  background: var(--bg-subtle);
}
.history-skel-card.short {
  height: 52px;
}
.hg-skel-tile {
  aspect-ratio: 1 / 1;
  border-radius: 11px;
  background: var(--bg-subtle);
}

@media (max-width: 360px) {
  .history-topbar {
    padding-left: 10px;
    padding-right: 10px;
    gap: 8px;
  }
  .history-capsule-btn {
    width: 48px;
    height: 42px;
  }
  .history-seg {
    min-width: 168px;
    height: 42px;
  }
}

/* ==================== v3.3.1 Lightbox Image -> Conversation Jump ==================== */
.hg-tile-chat-dot {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: rgba(24, 24, 28, 0.68);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 214, 138, 0.45);
  color: #FFD98A;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.28);
}
.hg-tile-chat-dot svg {
  width: 11px;
  height: 11px;
}

.lightbox .lightbox-bar {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  padding: 12px 16px calc(14px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(180deg, rgba(14, 15, 19, 0.72) 0%, rgba(10, 11, 14, 0.94) 100%);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid rgba(255, 255, 255, 0.09);
}

.lightbox-meta-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.lightbox-meta-row .lightbox-counter {
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.78);
  letter-spacing: 0.02em;
}

.lightbox-meta-row .lightbox-caption {
  flex: 1;
  min-width: 0;
  font-size: 12.5px;
  color: rgba(255, 255, 255, 0.62);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lightbox-actions-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.lightbox-util-btns {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.lightbox .lightbox-btn-chat {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 13px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.24);
  color: #FFFFFF;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  transition: transform 0.15s ease, background 0.18s ease, border-color 0.18s ease;
}

.lightbox .lightbox-btn-chat svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.lightbox .lightbox-btn-chat.is-direct {
  background: rgba(245, 166, 35, 0.24);
  border-color: rgba(255, 206, 110, 0.56);
  color: #FFE7B3;
}

.lightbox .lightbox-btn-chat:active {
  transform: scale(0.96);
}

/* Lightbox Context Bottom Sheet (RULE 7 hidden pointer-events isolation) */
.lb-ctx-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(0, 0, 0, 0.48);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0 8px;
  animation: lbFadeIn 0.18s ease-out;
}

.lb-ctx-backdrop.hidden {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

.lb-ctx-backdrop.hidden * {
  pointer-events: none !important;
}

@keyframes lbFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.lb-ctx-sheet {
  width: 100%;
  max-width: 520px;
  max-height: 70dvh;
  display: flex;
  flex-direction: column;
  background: rgba(22, 23, 28, 0.94);
  backdrop-filter: blur(26px);
  -webkit-backdrop-filter: blur(26px);
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-bottom: none;
  border-radius: 22px 22px 0 0;
  color: #F5F5F7;
  box-shadow: 0 -14px 40px rgba(0, 0, 0, 0.52);
  padding: 10px 16px calc(18px + env(safe-area-inset-bottom, 0px));
  animation: lbSheetUp 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes lbSheetUp {
  from { transform: translateY(28px); opacity: 0.65; }
  to { transform: translateY(0); opacity: 1; }
}

.lb-ctx-handle {
  width: 38px;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  margin: 0 auto 12px;
  flex-shrink: 0;
}

.lb-ctx-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  flex-shrink: 0;
}

.lb-ctx-head-info {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.lb-ctx-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.11);
  color: rgba(255, 255, 255, 0.92);
  font-size: 11.5px;
  font-weight: 600;
}

.lb-ctx-time {
  font-size: 12.5px;
  color: rgba(255, 255, 255, 0.58);
  white-space: nowrap;
}

.lb-ctx-close {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.84);
  font-size: 18px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.lb-ctx-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-bottom: 4px;
}

.lb-ctx-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lb-ctx-sec-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.lb-ctx-sec-title {
  font-size: 13px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.92);
}

.lb-ctx-sec-sub {
  font-size: 11.5px;
  color: rgba(255, 255, 255, 0.48);
}

.lb-ctx-card {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 14px;
  padding: 12px 13px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lb-ctx-session-card {
  border-color: rgba(255, 206, 110, 0.34);
  background: rgba(245, 166, 35, 0.09);
}

.lb-ctx-sess-title {
  font-size: 14.5px;
  font-weight: 600;
  color: #FFFFFF;
}

.lb-ctx-entry-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 11.5px;
  color: rgba(255, 255, 255, 0.54);
}

.lb-ctx-tag {
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.78);
  font-size: 11px;
  font-weight: 500;
}

.lb-ctx-tag.is-accent {
  background: rgba(245, 166, 35, 0.22);
  color: #FFE09E;
}

.lb-ctx-entry-text {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lb-ctx-p {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.88);
  word-break: break-word;
}

.lb-ctx-p code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  padding: 1px 5px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.11);
  color: #FFE4AC;
}

.lb-ctx-primary-btn {
  width: 100%;
  margin-top: 2px;
  padding: 10px 14px;
  border-radius: 11px;
  border: 1px solid rgba(255, 206, 110, 0.48);
  background: rgba(245, 166, 35, 0.25);
  color: #FFE9B8;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}

.lb-ctx-sess-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.lb-ctx-sess-btn {
  width: 100%;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #F5F5F7;
  cursor: pointer;
  transition: background 0.15s ease;
}

.lb-ctx-sess-btn:active {
  background: rgba(255, 255, 255, 0.14);
}

.lb-ctx-sess-btn-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.lb-ctx-sess-btn-title {
  font-size: 13.5px;
  font-weight: 600;
  color: #FFFFFF;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lb-ctx-sess-btn-sub {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.56);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lb-ctx-sess-btn-time {
  flex: 0 0 auto;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.58);
}

.lb-ctx-empty {
  padding: 14px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.lb-ctx-empty-title {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.92);
}

.lb-ctx-empty-sub {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.55;
  color: rgba(255, 255, 255, 0.58);
}

.lb-ctx-footer {
  padding-top: 2px;
}

.lb-ctx-timeline-btn {
  width: 100%;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.9);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.lb-ctx-loading {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 8px 0;
}

.lb-ctx-skel {
  height: 54px;
  border-radius: 12px;
  background: linear-gradient(90deg, rgba(255,255,255,0.06) 25%, rgba(255,255,255,0.12) 50%, rgba(255,255,255,0.06) 75%);
  background-size: 200% 100%;
  animation: lbSkel 1.2s ease-in-out infinite;
}

.lb-ctx-skel.short {
  height: 36px;
  width: 72%;
}

@keyframes lbSkel {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Message highlight pulse when jumping from Gallery -> Chat */
.msg-row.msg-jump-highlight .user-bubble,
.msg-row.msg-jump-highlight .assistant-body {
  animation: msgJumpPulse 2.4s cubic-bezier(0.22, 1, 0.36, 1);
  border-radius: 18px;
}

@keyframes msgJumpPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(245, 166, 35, 0.55);
    background-color: rgba(245, 166, 35, 0.18);
  }
  28% {
    box-shadow: 0 0 0 8px rgba(245, 166, 35, 0.28);
    background-color: rgba(245, 166, 35, 0.14);
  }
  100% {
    box-shadow: 0 0 0 14px rgba(245, 166, 35, 0);
  }
}

/* === v3.3.2 Pure-Chat Context Thread in Lightbox Drawer === */
.lb-ctx-sheet {
  max-height: min(78vh, 620px);
}

.lb-chat-thread {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 2px 0;
}

.lb-chat-more-btn {
  align-self: center;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.78);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.lb-chat-more-btn:active,
.lb-chat-more-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  color: #FFFFFF;
}

.lb-chat-msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 90%;
}

.lb-chat-msg.is-user {
  align-self: flex-end;
  align-items: flex-end;
}

.lb-chat-msg.is-assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.lb-chat-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.46);
  padding: 0 4px;
}

.lb-chat-bubble {
  padding: 10px 13px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.56;
  color: rgba(255, 255, 255, 0.92);
  word-break: break-word;
  overflow-wrap: anywhere;
}

.lb-chat-msg.is-user .lb-chat-bubble {
  background: rgba(52, 211, 153, 0.19);
  border: 1px solid rgba(52, 211, 153, 0.32);
  border-bottom-right-radius: 5px;
}

.lb-chat-msg.is-assistant .lb-chat-bubble {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-bottom-left-radius: 5px;
}

.lb-chat-msg.is-anchor .lb-chat-bubble {
  border-color: rgba(52, 211, 153, 0.72);
  box-shadow: 0 0 0 1px rgba(52, 211, 153, 0.24), 0 6px 18px rgba(16, 185, 129, 0.18);
  background: rgba(16, 185, 129, 0.22);
}

.lb-chat-msg.is-assistant.is-anchor .lb-chat-bubble {
  background: rgba(255, 255, 255, 0.12);
}

.lb-chat-anchor-row {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 6px;
}

.lb-chat-anchor-row:last-child {
  margin-bottom: 0;
}

.lb-chat-media-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}

.lb-chat-media-row:last-child {
  margin-bottom: 0;
}

.lb-chat-thumb {
  width: 52px;
  height: 52px;
  border-radius: 9px;
  object-fit: cover;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(0, 0, 0, 0.35);
  flex-shrink: 0;
}

.lb-chat-thumb.is-mini {
  width: 44px;
  height: 44px;
  border-radius: 8px;
}

.lb-chat-pin {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(52, 211, 153, 0.26);
  border: 1px solid rgba(52, 211, 153, 0.45);
  color: #B7F7DE;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}

.lb-chat-img-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.78);
  font-size: 12px;
}

.lb-chat-text.md-body {
  font-size: 13.5px;
  line-height: 1.56;
  color: rgba(255, 255, 255, 0.92);
}

.lb-chat-text.md-body p {
  margin: 0 0 6px;
}

.lb-chat-text.md-body p:last-child {
  margin-bottom: 0;
}

.lb-chat-text.md-body ul,
.lb-chat-text.md-body ol {
  margin: 4px 0 6px;
  padding-left: 18px;
}

.lb-chat-text.md-body li {
  margin: 2px 0;
}

.lb-chat-text.md-body h1,
.lb-chat-text.md-body h2,
.lb-chat-text.md-body h3,
.lb-chat-text.md-body h4 {
  font-size: 13.8px;
  font-weight: 600;
  margin: 6px 0 4px;
  color: #FFFFFF;
}

.lb-chat-text.md-body strong {
  color: #FFFFFF;
}

.lb-chat-text.md-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  padding: 1px 5px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.12);
  color: #D1FAE5;
}

.lb-chat-text.md-body pre {
  margin: 6px 0;
  padding: 8px 10px;
  border-radius: 9px;
  background: rgba(0, 0, 0, 0.36);
  overflow-x: auto;
  font-size: 12px;
}

.lb-chat-expand-btn {
  margin-top: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.08);
  color: #A7F3D0;
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
}

.lb-chat-jump-btn {
  width: 100%;
  margin-top: 4px;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid rgba(52, 211, 153, 0.52);
  background: rgba(16, 185, 129, 0.24);
  color: #D1FAE5;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}

.lb-chat-jump-btn:active,
.lb-chat-jump-btn:hover {
  background: rgba(16, 185, 129, 0.36);
}
