/* Alibaba PuHuiTi 3 Web Fonts */
@font-face {
  font-family: "AlibabaPuHuiTi-3";
  src: url("/fonts/AlibabaPuHuiTi-3-55-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "AlibabaPuHuiTi-3";
  src: url("/fonts/AlibabaPuHuiTi-3-65-Medium.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "AlibabaPuHuiTi-3";
  src: url("/fonts/AlibabaPuHuiTi-3-75-SemiBold.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "AlibabaPuHuiTi-3";
  src: url("/fonts/AlibabaPuHuiTi-3-85-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #eef3fb;
  --bg-top: #dceafe;
  --bg-bottom: #f4f7fc;
  --bg-ambient:
    radial-gradient(60% 55% at 15% 10%, rgba(147, 197, 253, 0.42) 0%, transparent 65%),
    radial-gradient(55% 50% at 86% 14%, rgba(196, 181, 253, 0.34) 0%, transparent 64%),
    radial-gradient(50% 45% at 50% 92%, rgba(165, 243, 252, 0.32) 0%, transparent 68%),
    linear-gradient(180deg, #e7f0ff 0%, #f1f5fb 52%, #eef4fc 100%);
  --surface: #ffffff;
  --glass-scale: 1;
  --surface-soft: rgba(255, 255, 255, calc(0.62 * var(--glass-scale)));
  --surface-sub: rgba(255, 255, 255, calc(0.48 * var(--glass-scale)));
  --chip-bg: rgba(255, 255, 255, calc(0.52 * var(--glass-scale)));
  --chip-hover: rgba(255, 255, 255, calc(0.78 * var(--glass-scale)));
  --border: rgba(255, 255, 255, 0.68);
  --border-subtle: rgba(15, 23, 42, 0.08);
  --border-focus: rgba(59, 130, 246, 0.58);
  --text: #0f172a;
  --muted: #475569;
  --on-bg-text: #0f172a;
  --on-bg-muted: #475569;
  --primary: #2563eb;
  --primary-soft: rgba(37, 99, 235, 0.13);
  --accent-border: rgba(59, 130, 246, 0.36);
  --active-bg: rgba(37, 99, 235, 0.14);
  --active-text: #1d4ed8;
  --send-bg: linear-gradient(145deg, #3b82f6 0%, #2563eb 100%);
  --send-fg: #ffffff;
  --bubble-user-bg: linear-gradient(145deg, #3b82f6 0%, #2563eb 100%);
  --bubble-user-fg: #ffffff;
  --thinking-dot: #2563eb;
  --focus-ring: rgba(37, 99, 235, 0.18);
  --pet-glow: rgba(15, 23, 42, 0.16);
  --switch-active-bg: linear-gradient(145deg, rgba(255, 255, 255, 0.92), rgba(255, 255, 255, 0.74));
  --switch-active-text: #1d4ed8;
  --danger: #dc2626;
  --danger-bg: rgba(254, 242, 242, 0.8);
  --danger-text: #7f1d1d;
  --success: #059669;
  --backdrop: rgba(15, 23, 42, 0.34);
  --scrollbar-thumb: rgba(100, 116, 139, 0.32);
  --scrollbar-thumb-hover: rgba(71, 85, 105, 0.55);

  /* Apple Liquid Glass Material Tokens (Light) */
  --glass-bg: linear-gradient(155deg, rgba(255, 255, 255, calc(0.72 * var(--glass-scale))) 0%, rgba(255, 255, 255, calc(0.44 * var(--glass-scale))) 52%, rgba(255, 255, 255, calc(0.6 * var(--glass-scale))) 100%);
  --glass-bg-strong: linear-gradient(155deg, rgba(255, 255, 255, clamp(0.52, calc(0.84 * var(--glass-scale)), 0.96)) 0%, rgba(255, 255, 255, clamp(0.42, calc(0.64 * var(--glass-scale)), 0.92)) 55%, rgba(255, 255, 255, clamp(0.48, calc(0.76 * var(--glass-scale)), 0.94)) 100%);
  --glass-pill: linear-gradient(160deg, rgba(255, 255, 255, calc(0.74 * var(--glass-scale))) 0%, rgba(255, 255, 255, calc(0.48 * var(--glass-scale))) 100%);
  --glass-pill-hover: linear-gradient(160deg, rgba(255, 255, 255, calc(0.9 * var(--glass-scale))) 0%, rgba(255, 255, 255, calc(0.66 * var(--glass-scale))) 100%);
  --glass-sidebar: linear-gradient(180deg, rgba(255, 255, 255, calc(0.66 * var(--glass-scale))) 0%, rgba(255, 255, 255, calc(0.46 * var(--glass-scale))) 100%);
  --glass-border: rgba(255, 255, 255, 0.72);
  --glass-edge-outer: rgba(15, 23, 42, 0.08);
  --glass-blur: blur(24px) saturate(190%) brightness(1.04);
  --glass-blur-pill: blur(20px) saturate(185%) brightness(1.04);
  --glass-shadow:
    inset 0 1px 0 0 rgba(255, 255, 255, 0.88),
    inset 0 -1px 0 0 rgba(255, 255, 255, 0.3),
    0 12px 36px rgba(15, 23, 42, 0.08),
    0 2px 8px rgba(15, 23, 42, 0.04);
  --glass-pill-shadow:
    inset 0 1px 0 0 rgba(255, 255, 255, 0.88),
    inset 0 -1px 0 0 rgba(255, 255, 255, 0.28),
    0 6px 20px rgba(15, 23, 42, 0.07),
    0 1px 3px rgba(15, 23, 42, 0.04);
  --glass-active-shadow:
    inset 0 1px 0 0 rgba(255, 255, 255, 0.92),
    0 3px 10px rgba(37, 99, 235, 0.14);
  --glass-spring: cubic-bezier(0.22, 1, 0.36, 1);

  --shadow: var(--glass-shadow);
  --pet-size: 320px;
  --content-width: 820px;
}

body.theme-dark {
  /* 护眼深色液态玻璃：柔和深曜石底 + 烟熏玻璃折射层 + 低眩光柔白文字 */
  color-scheme: dark;
  --bg: #0c1018;
  --bg-top: #162238;
  --bg-bottom: #0a0d14;
  --bg-ambient:
    radial-gradient(58% 52% at 18% 12%, rgba(56, 189, 248, 0.16) 0%, transparent 65%),
    radial-gradient(52% 48% at 84% 16%, rgba(129, 140, 248, 0.16) 0%, transparent 65%),
    radial-gradient(52% 44% at 50% 94%, rgba(37, 99, 235, 0.14) 0%, transparent 68%),
    linear-gradient(180deg, #121a29 0%, #0d111a 54%, #090c12 100%);
  --surface: #1b202b;
  --surface-soft: rgba(24, 30, 44, 0.62);
  --surface-sub: rgba(30, 38, 54, 0.54);
  --chip-bg: rgba(255, 255, 255, 0.07);
  --chip-hover: rgba(255, 255, 255, 0.14);
  --border: rgba(255, 255, 255, 0.16);
  --border-subtle: rgba(255, 255, 255, 0.09);
  --border-focus: rgba(96, 165, 250, 0.6);
  --text: #edf2fb;
  --muted: #a1aec4;
  --on-bg-text: #edf2fb;
  --on-bg-muted: #9aa7be;
  --primary: #60a5fa;
  --primary-soft: rgba(96, 165, 250, 0.18);
  --accent-border: rgba(96, 165, 250, 0.42);
  --active-bg: rgba(96, 165, 250, 0.2);
  --active-text: #bfdbfe;
  --send-bg: linear-gradient(145deg, #60a5fa 0%, #3b82f6 100%);
  --send-fg: #ffffff;
  --bubble-user-bg: linear-gradient(145deg, #3b82f6 0%, #2563eb 100%);
  --bubble-user-fg: #f8fafc;
  --thinking-dot: #60a5fa;
  --focus-ring: rgba(96, 165, 250, 0.24);
  --pet-glow: rgba(96, 165, 250, 0.18);
  --switch-active-bg: linear-gradient(145deg, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0.11));
  --switch-active-text: #f8fafc;
  --danger: #f87171;
  --danger-bg: rgba(68, 18, 26, 0.74);
  --danger-text: #fecaca;
  --success: #34d399;
  --backdrop: rgba(2, 6, 23, 0.64);
  --scrollbar-thumb: rgba(148, 163, 184, 0.28);
  --scrollbar-thumb-hover: rgba(148, 163, 184, 0.5);

  /* Apple Liquid Glass Material Tokens (Dark) */
  --glass-bg: linear-gradient(155deg, rgba(36, 44, 62, calc(0.64 * var(--glass-scale))) 0%, rgba(20, 25, 38, calc(0.48 * var(--glass-scale))) 54%, rgba(30, 38, 54, calc(0.58 * var(--glass-scale))) 100%);
  --glass-bg-strong: linear-gradient(155deg, rgba(34, 42, 60, clamp(0.54, calc(0.82 * var(--glass-scale)), 0.96)) 0%, rgba(20, 25, 38, clamp(0.48, calc(0.72 * var(--glass-scale)), 0.94)) 55%, rgba(28, 35, 50, clamp(0.52, calc(0.78 * var(--glass-scale)), 0.95)) 100%);
  --glass-pill: linear-gradient(160deg, rgba(42, 52, 74, calc(0.62 * var(--glass-scale))) 0%, rgba(22, 28, 42, calc(0.46 * var(--glass-scale))) 100%);
  --glass-pill-hover: linear-gradient(160deg, rgba(56, 68, 96, calc(0.72 * var(--glass-scale))) 0%, rgba(30, 38, 56, calc(0.58 * var(--glass-scale))) 100%);
  --glass-sidebar: linear-gradient(180deg, rgba(28, 35, 50, calc(0.68 * var(--glass-scale))) 0%, rgba(16, 20, 32, calc(0.56 * var(--glass-scale))) 100%);
  --glass-border: rgba(255, 255, 255, 0.17);
  --glass-edge-outer: rgba(0, 0, 0, 0.36);
  --glass-blur: blur(26px) saturate(170%) brightness(0.98);
  --glass-blur-pill: blur(22px) saturate(165%) brightness(1.02);
  --glass-shadow:
    inset 0 1px 0 0 rgba(255, 255, 255, 0.2),
    inset 0 -1px 0 0 rgba(255, 255, 255, 0.05),
    0 16px 46px rgba(0, 0, 0, 0.46),
    0 2px 10px rgba(0, 0, 0, 0.28);
  --glass-pill-shadow:
    inset 0 1px 0 0 rgba(255, 255, 255, 0.22),
    inset 0 -1px 0 0 rgba(255, 255, 255, 0.06),
    0 8px 24px rgba(0, 0, 0, 0.36),
    0 1px 4px rgba(0, 0, 0, 0.24);
  --glass-active-shadow:
    inset 0 1px 0 0 rgba(255, 255, 255, 0.28),
    0 3px 12px rgba(0, 0, 0, 0.28);

  --shadow: var(--glass-shadow);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: "AlibabaPuHuiTi-3", "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: var(--bg-ambient);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.3s ease, color 0.2s ease;
}

textarea, input {
  user-select: text;
  -webkit-user-select: text;
  -webkit-touch-callout: default;
}

button, a, svg {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* Custom User-Uploaded Background */
body.has-custom-bg {
  background-color: var(--bg);
  background-image: var(--custom-bg-url);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

body.has-custom-bg::before {
  content: "";
  position: fixed;
  inset: 0;
  background: rgba(246, 248, 252, 0.14);
  pointer-events: none;
  z-index: 0;
}

body.theme-dark.has-custom-bg::before {
  background: rgba(10, 14, 24, 0.36);
}

body.has-custom-bg .layout {
  position: relative;
  z-index: 1;
}

body.has-custom-bg .last-user-line {
  padding: 3px 12px;
  border-radius: 999px;
  background: var(--glass-pill);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-pill-shadow);
  backdrop-filter: var(--glass-blur-pill);
  -webkit-backdrop-filter: var(--glass-blur-pill);
  color: var(--muted);
}

body.has-custom-bg .footnote {
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.35);
}

body.theme-dark.has-custom-bg .footnote {
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.55);
}

button, textarea, input {
  font-family: inherit;
}

.hidden {
  display: none !important;
}

.mobile-only-ctrl {
  display: none !important;
}

.layout {
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  display: flex;
  overflow: hidden;
}

.history-backdrop {
  display: none;
}

/* ==================== Minimal Collapsible Left History Sidebar (Liquid Glass) ==================== */
.history-sidebar {
  width: 248px;
  flex-shrink: 0;
  height: 100vh;
  height: 100dvh;
  background: var(--glass-sidebar);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-right: 1px solid var(--glass-border);
  box-shadow:
    inset -1px 0 0 0 rgba(255, 255, 255, 0.35),
    6px 0 28px rgba(15, 23, 42, 0.05);
  display: flex;
  flex-direction: column;
  padding: 14px 12px;
  gap: 12px;
  transition: width 0.24s var(--glass-spring), padding 0.24s var(--glass-spring), opacity 0.2s ease, transform 0.24s var(--glass-spring);
}

.layout.history-collapsed .history-sidebar {
  width: 0;
  padding-left: 0;
  padding-right: 0;
  border-right-color: transparent;
  opacity: 0;
  overflow: hidden;
}

/* Hide top-left "对话历史" button while sidebar is open */
.layout:not(.history-collapsed) .open-history-btn {
  display: none;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 2px 4px;
  white-space: nowrap;
}

.history-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.history-header-actions {
  display: flex;
  align-items: center;
  gap: 5px;
}

.new-chat-btn {
  border: 1px solid var(--accent-border);
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4);
  transition: all 0.18s var(--glass-spring);
}

.new-chat-btn:hover {
  background: var(--send-bg);
  border-color: transparent;
  color: var(--send-fg);
  transform: translateY(-0.5px);
}

.hide-sidebar-btn {
  border: 1px solid var(--glass-border);
  background: var(--glass-pill);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5);
  transition: all 0.18s var(--glass-spring);
}

.hide-sidebar-btn:hover {
  background: var(--glass-pill-hover);
  color: var(--primary);
}

.history-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.history-list::-webkit-scrollbar {
  width: 4px;
}

.history-list::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.32);
  border-radius: 999px;
}

.history-empty {
  font-size: 13px;
  color: var(--muted);
  opacity: 0.75;
  text-align: center;
  padding: 28px 8px;
}

.history-item {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 9px 28px 9px 11px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: all 0.15s ease;
  width: 100%;
}

.history-item:hover {
  background: var(--chip-bg);
}

.history-item.active {
  background: var(--primary-soft);
  border-color: var(--accent-border);
}

.history-item-title {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item-meta {
  font-size: 11.5px;
  color: var(--muted);
}

.history-del {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  display: grid;
  place-items: center;
  opacity: 0;
  cursor: pointer;
  transition: all 0.14s ease;
}

.history-item:hover .history-del {
  opacity: 0.78;
}

.history-del:hover {
  opacity: 1 !important;
  color: var(--danger);
  background: var(--danger-bg);
}

/* ==================== Full-Width Right Workspace ==================== */
.page {
  flex: 1;
  min-width: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  padding: 14px 22px max(10px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

/* Topbar stretches full width so top-actions align cleanly to the far right */
.topbar {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
}

.topbar-left {
  grid-column: 1;
  justify-self: start;
  min-width: 0;
}

.pet-zoom-bar {
  grid-column: 2;
  justify-self: center;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--glass-pill);
  border: 1px solid var(--glass-border);
  padding: 5px 12px;
  border-radius: 999px;
  box-shadow: var(--glass-pill-shadow);
  backdrop-filter: var(--glass-blur-pill);
  -webkit-backdrop-filter: var(--glass-blur-pill);
}

.zoom-btn {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid var(--glass-border);
  background: var(--glass-pill);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55);
  transition: all 0.18s var(--glass-spring);
}

.zoom-btn:hover {
  border-color: var(--accent-border);
  color: var(--primary);
  background: var(--glass-pill-hover);
  transform: scale(1.06);
}

.zoom-btn:active {
  transform: scale(0.94);
}

.pet-zoom-bar input[type="range"] {
  width: 112px;
  accent-color: var(--primary);
  cursor: pointer;
}

.zoom-val {
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  min-width: 38px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  user-select: none;
}

.zoom-sep {
  width: 1px;
  height: 14px;
  background: var(--border-subtle);
}

.zoom-action-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 500;
  padding: 2px 6px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.16s ease, opacity 0.16s ease;
}

.zoom-action-btn:hover {
  color: var(--primary);
}

.zoom-action-btn.active {
  color: var(--active-text);
  font-weight: 600;
}

.top-actions {
  grid-column: 3;
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 8px;
}

.bg-control,
.settings-control {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.icon-pill-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  line-height: 0;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: var(--glass-pill);
  color: var(--text);
  cursor: pointer;
  box-shadow: var(--glass-pill-shadow);
  backdrop-filter: var(--glass-blur-pill);
  -webkit-backdrop-filter: var(--glass-blur-pill);
  transition: transform 0.2s var(--glass-spring), background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.icon-pill-btn:hover {
  background: var(--glass-pill-hover);
  border-color: var(--accent-border);
  color: var(--primary);
  transform: translateY(-0.5px);
}

.icon-pill-btn:active {
  transform: scale(0.93);
}

.icon-pill-btn svg,
.input-mode-btn svg {
  display: block;
  flex-shrink: 0;
}

.settings-popover {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: min(76vw, 260px);
  max-height: 72dvh;
  overflow-y: auto;
  background: var(--glass-bg-strong);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  padding: 8px;
  box-shadow: var(--glass-shadow);
  z-index: 140;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.settings-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s ease;
}

.settings-item:hover,
.settings-item:active {
  background: var(--chip-bg);
}

.settings-item-val {
  font-size: 12.5px;
  color: var(--muted);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.settings-slider-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 12px 10px;
}

.settings-slider-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
}

.settings-range {
  width: 100%;
  margin: 0;
  accent-color: var(--primary);
  cursor: pointer;
}

.settings-divider {
  height: 1px;
  margin: 2px 8px;
  background: var(--border-subtle);
}

.settings-bg-list {
  max-height: 220px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px 2px 6px;
}

.bg-popover {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 244px;
  max-height: 328px;
  overflow-y: auto;
  background: var(--glass-bg-strong);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  padding: 8px;
  box-shadow: var(--glass-shadow);
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.bg-option {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: all 0.14s ease;
}

.bg-option:hover {
  background: var(--chip-bg);
}

.bg-option.active {
  background: var(--active-bg);
  border-color: var(--accent-border);
  color: var(--active-text);
  font-weight: 600;
}

.bg-thumb {
  width: 44px;
  height: 28px;
  border-radius: 6px;
  flex-shrink: 0;
  display: block;
  object-fit: cover;
  border: 1px solid var(--border);
  background: radial-gradient(circle at 50% 0%, var(--bg-top) 0%, var(--bg) 60%, var(--bg-bottom) 100%);
  background-size: cover;
  background-position: center;
}

.bg-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bg-empty-hint {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  padding: 6px 4px 2px;
}

.view-switch {
  display: inline-flex;
  background: var(--glass-pill);
  border: 1px solid var(--glass-border);
  padding: 3px;
  border-radius: 999px;
  box-shadow: var(--glass-pill-shadow);
  backdrop-filter: var(--glass-blur-pill);
  -webkit-backdrop-filter: var(--glass-blur-pill);
}

.switch-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  padding: 5px 13px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.2s var(--glass-spring);
}

.switch-btn:hover {
  color: var(--text);
}

.switch-btn.active {
  background: var(--switch-active-bg);
  color: var(--switch-active-text);
  font-weight: 600;
  box-shadow: var(--glass-active-shadow);
}

.text-btn {
  border: 1px solid var(--glass-border);
  background: var(--glass-pill);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: var(--glass-pill-shadow);
  backdrop-filter: var(--glass-blur-pill);
  -webkit-backdrop-filter: var(--glass-blur-pill);
  transition: all 0.2s var(--glass-spring);
  white-space: nowrap;
}

.text-btn:hover {
  background: var(--glass-pill-hover);
  border-color: var(--accent-border);
  color: var(--primary);
  transform: translateY(-0.5px);
}

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

/* Slim Awakening Bar (Blue Team only, Liquid Glass Capsule) */
.awakening-bar {
  display: none;
  align-items: center;
  gap: 10px;
  max-width: 560px;
  width: 100%;
  padding: 7px 18px;
  border-radius: 999px;
  background: var(--glass-pill);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-pill-shadow);
  backdrop-filter: var(--glass-blur-pill);
  -webkit-backdrop-filter: var(--glass-blur-pill);
  font-size: 13px;
}

.awakening-bar.show {
  display: flex;
}

.awakening-label {
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

.awakening-track {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.25);
  overflow: hidden;
}

.awakening-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #ef4444, #f59e0b, #10b981);
  transition: width 0.5s ease;
}

.awakening-val {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.awakening-delta {
  font-size: 12.5px;
  font-weight: 700;
}

.awakening-delta.up { color: var(--success); }
.awakening-delta.down { color: var(--danger); }
.awakening-delta.flat { color: var(--muted); }

/* ==================== View A: Centered Pet Conversation Mode ==================== */
.stage-pet {
  flex: 1;
  width: 100%;
  min-height: 0;
  padding: 4px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.pet-unit {
  width: 100%;
  max-width: var(--content-width);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  position: relative;
  z-index: 20;
  will-change: transform;
}

.pet-unit.dragging {
  z-index: 50;
}

.pet-dialog-wrap {
  width: 100%;
  flex: 0 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.pet-speech {
  position: relative;
  width: 100%;
  flex: 0 1 auto;
  min-height: 96px;
  max-height: 100%;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: 26px;
  padding: 20px 14px 20px 26px;
  box-shadow: var(--glass-shadow);
  display: flex;
  flex-direction: column;
  justify-content: center;
  transition: border-color 0.25s ease, background 0.25s ease, box-shadow 0.25s ease;
}

.pet-speech::after {
  display: none;
}

.pet-speech.emergency {
  background: var(--danger-bg);
  border: 1.5px solid var(--danger);
  color: var(--danger-text);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    0 12px 34px rgba(220, 38, 38, 0.18);
}

.replay-btn {
  position: absolute;
  top: 12px;
  right: 22px;
  z-index: 2;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  padding: 2px 6px;
  border-radius: 6px;
  cursor: pointer;
  opacity: 0.82;
  transition: color 0.16s ease, opacity 0.16s ease;
}

.replay-btn:hover {
  opacity: 1;
  color: var(--primary);
}

.pet-speech-body {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 64px;
  font-size: 17.5px;
  font-weight: 400;
  line-height: 1.85;
  letter-spacing: 0.015em;
  word-break: break-word;
  max-height: min(32vh, 280px);
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) transparent;
}

.pet-speech-body strong {
  font-weight: 600;
}

.pet-speech-body::-webkit-scrollbar,
.web-messages::-webkit-scrollbar,
.help-body::-webkit-scrollbar {
  width: 6px;
}

.pet-speech-body::-webkit-scrollbar-thumb,
.web-messages::-webkit-scrollbar-thumb,
.help-body::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 999px;
}

.pet-speech-body::-webkit-scrollbar-thumb:hover,
.web-messages::-webkit-scrollbar-thumb:hover,
.help-body::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover);
}

.last-user-line {
  flex-shrink: 0;
  font-size: 13px;
  color: var(--on-bg-muted);
  max-width: 92%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-height: 18px;
}

.last-user-line:empty {
  display: none;
}

/* Centerpiece Scalable & Draggable Transparent Whale-Girl */
.pet-figure {
  position: relative;
  width: var(--pet-size);
  height: var(--pet-size);
  max-width: 90vw;
  max-height: 44vh;
  flex-shrink: 0;
  cursor: grab;
  user-select: none;
  touch-action: none;
  z-index: 20;
  margin: 0 auto;
  transition: width 0.16s ease, height 0.16s ease;
}

.pet-figure.dragging {
  cursor: grabbing;
  z-index: 50;
}

.pet-figure.locked {
  cursor: pointer;
}

.pet-video-buf {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  transition: opacity 0.18s ease;
  pointer-events: none;
  filter: drop-shadow(0 12px 24px var(--pet-glow));
}

.pet-video-buf.active {
  opacity: 1;
}

/* ==================== View B: Clean Standard Web Chat Mode (Liquid Glass) ==================== */
.stage-web {
  flex: 1;
  width: 100%;
  max-width: var(--content-width);
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: 26px;
  box-shadow: var(--glass-shadow);
  overflow: hidden;
}

.web-messages {
  flex: 1;
  overflow-y: auto;
  padding: 22px 26px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.web-msg {
  max-width: 84%;
  padding: 13px 18px;
  border-radius: 20px;
  font-size: 16px;
  line-height: 1.78;
  letter-spacing: 0.01em;
  word-break: break-word;
  content-visibility: auto;
  contain-intrinsic-size: auto 72px;
}

.web-msg.user {
  align-self: flex-end;
  background: var(--bubble-user-bg);
  color: var(--bubble-user-fg);
  border-bottom-right-radius: 6px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    0 6px 18px rgba(37, 99, 235, 0.24);
}

.web-msg.assistant {
  align-self: flex-start;
  background: var(--glass-pill);
  border: 1px solid var(--glass-border);
  border-bottom-left-radius: 6px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.55),
    0 4px 14px rgba(15, 23, 42, 0.05);
}

.web-msg.emergency {
  background: var(--danger-bg);
  border: 1.5px solid var(--danger);
  color: var(--danger-text);
}

/* Shared Markdown Typography */
.pet-speech-body h1,
.pet-speech-body h2,
.pet-speech-body h3,
.pet-speech-body h4,
.web-msg h1,
.web-msg h2,
.web-msg h3,
.web-msg h4 {
  font-weight: 700;
  line-height: 1.45;
  margin: 12px 0 6px;
  color: inherit;
}

.pet-speech-body h1:first-child,
.pet-speech-body h2:first-child,
.pet-speech-body h3:first-child,
.pet-speech-body h4:first-child,
.web-msg h1:first-child,
.web-msg h2:first-child,
.web-msg h3:first-child,
.web-msg h4:first-child {
  margin-top: 0;
}

.pet-speech-body h1, .web-msg h1 { font-size: 1.18em; }
.pet-speech-body h2, .web-msg h2 { font-size: 1.09em; }
.pet-speech-body h3, .web-msg h3 { font-size: 1.03em; }
.pet-speech-body h4, .web-msg h4 { font-size: 0.98em; }

.pet-speech-body p + p,
.web-msg p + p {
  margin-top: 8px;
}

.pet-speech-body ul, .pet-speech-body ol,
.web-msg ul, .web-msg ol {
  padding-left: 22px;
  margin: 6px 0;
}

.pet-speech-body li, .web-msg li {
  margin: 4px 0;
}

.pet-speech-body blockquote,
.web-msg blockquote {
  margin: 8px 0;
  padding: 8px 14px;
  border-left: 3px solid var(--primary);
  background: var(--primary-soft);
  border-radius: 0 10px 10px 0;
  font-size: 0.95em;
}

.pet-speech.emergency blockquote,
.web-msg.emergency blockquote {
  border-left-color: var(--danger);
  background: rgba(220, 38, 38, 0.1);
}

.pet-speech-body hr,
.web-msg hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 12px 0;
}

.pet-speech-body pre,
.web-msg pre {
  margin: 8px 0;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--surface-sub);
  border: 1px solid var(--border);
  overflow-x: auto;
  line-height: 1.55;
}

.pet-speech-body pre code,
.web-msg pre code {
  padding: 0;
  background: transparent;
  border-radius: 0;
  font-size: 13.5px;
}

.pet-speech-body code, .web-msg code {
  font-family: Consolas, Monaco, monospace;
  font-size: 0.86em;
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--primary-soft);
}

.pet-speech-body em, .web-msg em {
  font-style: italic;
}

.pet-speech-body del, .web-msg del {
  opacity: 0.72;
}

.md-table-wrap {
  width: 100%;
  overflow-x: auto;
  margin: 8px 0;
}

.md-table-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9em;
  line-height: 1.55;
}

.md-table-wrap th,
.md-table-wrap td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}

.md-table-wrap th {
  background: var(--chip-bg);
  font-weight: 600;
}

.pet-speech-body a,
.web-msg a {
  color: var(--primary);
  text-decoration: underline;
  text-underline-offset: 3px;
  font-weight: 500;
  transition: opacity 0.15s ease;
}

.pet-speech-body a:hover,
.web-msg a:hover {
  opacity: 0.82;
}

.web-msg.user a {
  color: var(--bubble-user-fg);
}

/* ==================== Centered Unified Composer ==================== */
.composer-area {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.composer-area > .mode-tabs {
  width: 100%;
  max-width: var(--content-width);
  justify-content: flex-start;
  padding: 0 2px;
}

.composer-input-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
}

.composer-box {
  width: 100%;
  max-width: var(--content-width);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: 26px;
  padding: 10px 12px 10px 18px;
  box-shadow: var(--glass-shadow);
  transition: border-color 0.22s var(--glass-spring), box-shadow 0.22s var(--glass-spring), background 0.22s ease;
}

.composer-box.voice-input-mode {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  padding: 4px 0;
}

.composer-box:focus-within {
  border-color: var(--glass-border);
  box-shadow: var(--glass-shadow);
}

body.theme-dark .composer-box:focus-within {
  border-color: var(--glass-border);
  box-shadow: var(--glass-shadow);
}

.composer-box.voice-input-mode:focus-within {
  border-color: transparent;
  box-shadow: none;
}

.composer-box textarea {
  flex: 1;
  min-width: 0;
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  line-height: 1.55;
  min-height: 40px;
  max-height: 160px;
  padding: 8px 4px;
}

.input-mode-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  padding: 0;
  line-height: 0;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: var(--chip-bg);
  color: var(--text);
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.72),
    0 3px 10px rgba(15, 23, 42, 0.08),
    0 1px 3px rgba(15, 23, 42, 0.05);
  transition: transform 0.18s var(--glass-spring), background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}

.input-mode-btn:hover {
  background: var(--chip-hover);
  border-color: var(--accent-border);
  color: var(--primary);
  transform: translateY(-0.5px);
}

.input-mode-btn:active {
  transform: scale(0.93);
}

.input-mode-btn .icon-kbd {
  display: none;
}

.composer-box.voice-input-mode .input-mode-btn .icon-mic {
  display: none;
}

.composer-box.voice-input-mode .input-mode-btn .icon-kbd {
  display: block;
}

.hold-talk-btn {
  display: none;
  flex: 1;
  height: 44px;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: var(--glass-pill);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.03em;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
  box-shadow: var(--glass-pill-shadow);
  backdrop-filter: var(--glass-blur-pill);
  -webkit-backdrop-filter: var(--glass-blur-pill);
  transition: transform 0.16s var(--glass-spring), background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}

.hold-talk-btn:hover {
  background: var(--glass-pill-hover);
}

.composer-box.voice-input-mode textarea,
.composer-box.voice-input-mode .send-circle-btn {
  display: none;
}

.send-circle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  padding: 0;
  line-height: 0;
  border: none;
  border-radius: 999px;
  background: linear-gradient(145deg, #568eff 0%, #3b74f6 100%);
  color: #ffffff;
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.38),
    0 5px 14px rgba(59, 116, 246, 0.34);
  transition: transform 0.18s var(--glass-spring), background 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.send-circle-btn svg {
  display: block;
  flex-shrink: 0;
}

.send-circle-btn:hover:not(:disabled) {
  background: linear-gradient(145deg, #4b86ff 0%, #2d68f0 100%);
  transform: translateY(-1px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.45),
    0 7px 18px rgba(59, 116, 246, 0.42);
}

.send-circle-btn:active:not(:disabled) {
  transform: scale(0.93);
}

.send-circle-btn:disabled {
  background: rgba(114, 154, 255, 0.46);
  color: rgba(255, 255, 255, 0.94);
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

body.theme-dark .send-circle-btn:disabled {
  background: rgba(96, 145, 255, 0.28);
  color: rgba(255, 255, 255, 0.65);
}

.composer-box.voice-input-mode .hold-talk-btn {
  display: flex;
}

.composer-box.voice-input-mode .input-mode-btn {
  width: 44px;
  height: 44px;
  background: var(--glass-pill);
  box-shadow: var(--glass-pill-shadow);
  backdrop-filter: var(--glass-blur-pill);
  -webkit-backdrop-filter: var(--glass-blur-pill);
}

.hold-talk-btn.recording {
  background: var(--active-bg);
  border-color: var(--accent-border);
  color: var(--active-text);
  transform: scale(0.99);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.5),
    0 0 0 4px var(--focus-ring);
}

.hold-talk-btn.canceling {
  background: var(--danger-bg);
  border-color: var(--danger);
  color: var(--danger);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.3),
    0 0 0 4px rgba(220, 38, 38, 0.16);
}

.hold-talk-btn.processing {
  opacity: 0.72;
}

body.theme-dark .input-mode-btn {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.14),
    0 4px 12px rgba(0, 0, 0, 0.28);
}

.composer-box textarea::placeholder {
  color: var(--muted);
  opacity: 0.8;
}

.composer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding-top: 8px;
  border-top: 1px solid var(--border-subtle);
}

.mode-tabs {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.tab-btn {
  border: 1px solid var(--glass-border);
  background: var(--chip-bg);
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  padding: 5px 13px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.72),
    0 3px 10px rgba(15, 23, 42, 0.08),
    0 1px 3px rgba(15, 23, 42, 0.05);
  transition: all 0.2s var(--glass-spring);
}

.tab-btn:hover {
  color: var(--text);
  background: var(--chip-hover);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.82),
    0 5px 14px rgba(15, 23, 42, 0.11),
    0 1px 4px rgba(15, 23, 42, 0.06);
  transform: translateY(-0.5px);
}

.tab-btn.active {
  background: var(--active-bg);
  border-color: var(--accent-border);
  color: var(--active-text);
  font-weight: 600;
  box-shadow: var(--glass-active-shadow);
}

.composer-tools {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.tool-btn {
  border: 1px solid var(--glass-border);
  background: var(--chip-bg);
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 13px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.72),
    0 3px 10px rgba(15, 23, 42, 0.08),
    0 1px 3px rgba(15, 23, 42, 0.05);
  transition: all 0.2s var(--glass-spring);
}

.tool-btn:hover {
  border-color: var(--accent-border);
  background: var(--chip-hover);
  color: var(--primary);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.82),
    0 5px 14px rgba(15, 23, 42, 0.11),
    0 1px 4px rgba(15, 23, 42, 0.06);
}

body.theme-dark .tab-btn,
body.theme-dark .tool-btn {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.14),
    0 4px 12px rgba(0, 0, 0, 0.28);
}

.tool-btn.active {
  background: var(--primary-soft);
  border-color: var(--accent-border);
  color: var(--primary);
  font-weight: 600;
}

.tool-btn.recording {
  background: var(--danger-bg);
  border-color: var(--danger);
  color: var(--danger);
  font-weight: 600;
}

.send-btn {
  border: none;
  background: var(--send-bg);
  color: var(--send-fg);
  font-size: 14px;
  font-weight: 600;
  padding: 7px 22px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.42),
    0 6px 16px rgba(37, 99, 235, 0.28);
  transition: transform 0.2s var(--glass-spring), box-shadow 0.2s var(--glass-spring), opacity 0.16s ease;
}

.send-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.52),
    0 8px 22px rgba(37, 99, 235, 0.36);
}

.send-btn:active:not(:disabled) {
  transform: scale(0.96);
}

.send-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.footnote {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 10.5px;
  line-height: 1.4;
  color: var(--on-bg-muted);
  opacity: 0.56;
  text-align: center;
}

.footnote a {
  color: var(--on-bg-muted);
  text-decoration: none;
}

.footnote a:hover {
  text-decoration: underline;
}

.beian-sep {
  opacity: 0.45;
}

.beian-mps {
  opacity: 0.85;
}

.thinking-dots {
  display: inline-flex;
  gap: 6px;
  padding: 8px 2px;
}

.thinking-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--thinking-dot);
  opacity: 0.35;
  animation: pulse 1.1s infinite ease-in-out;
}

.thinking-dots span:nth-child(2) { animation-delay: 0.18s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.36s; }

@keyframes pulse {
  0%, 80%, 100% { transform: scale(0.8); opacity: 0.35; }
  40% { transform: scale(1.2); opacity: 1; }
}

/* ==================== Clean Modals (Liquid Glass) ==================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--backdrop);
  backdrop-filter: blur(10px) saturate(140%);
  -webkit-backdrop-filter: blur(10px) saturate(140%);
  display: grid;
  place-items: center;
  z-index: 200;
  padding: 20px;
}

.modal-card {
  width: 100%;
  max-width: 450px;
  background: var(--glass-bg-strong);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: 26px;
  padding: 24px 26px 20px;
  box-shadow: var(--glass-shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-wide {
  max-width: 580px;
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.modal-body {
  font-size: 14.5px;
  line-height: 1.75;
  color: var(--muted);
}

.help-body {
  max-height: 62vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-right: 4px;
}

.help-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.help-heading {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.help-body ul {
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.help-body b {
  color: var(--text);
  font-weight: 600;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
}

.modal-link {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--primary);
  text-decoration: none;
  padding: 6px 10px;
}

.modal-link:hover {
  text-decoration: underline;
}

@media (max-width: 768px) {
  /* Mobile-tuned Liquid Glass tokens: crisp hairline edges, zero corner halo/bleed */
  :root {
    --glass-border: rgba(255, 255, 255, 0.54);
    --glass-blur: blur(16px) saturate(165%);
    --glass-blur-pill: blur(14px) saturate(160%);
    --glass-shadow:
      inset 0 0.5px 0 0 rgba(255, 255, 255, 0.78),
      0 8px 24px rgba(15, 23, 42, 0.08),
      0 1px 4px rgba(15, 23, 42, 0.04);
    --glass-pill-shadow:
      inset 0 0.5px 0 0 rgba(255, 255, 255, 0.78),
      0 3px 10px rgba(15, 23, 42, 0.07),
      0 1px 2px rgba(15, 23, 42, 0.04);
  }

  body.theme-dark {
    --glass-border: rgba(255, 255, 255, 0.14);
    --glass-blur: blur(18px) saturate(155%);
    --glass-blur-pill: blur(14px) saturate(150%);
    --glass-shadow:
      inset 0 0.5px 0 0 rgba(255, 255, 255, 0.16),
      0 10px 28px rgba(0, 0, 0, 0.38),
      0 1px 4px rgba(0, 0, 0, 0.24);
    --glass-pill-shadow:
      inset 0 0.5px 0 0 rgba(255, 255, 255, 0.16),
      0 4px 12px rgba(0, 0, 0, 0.3),
      0 1px 2px rgba(0, 0, 0, 0.2);
  }

  .desktop-only-ctrl {
    display: none !important;
  }

  .mobile-only-ctrl {
    display: inline-flex !important;
  }

  .settings-item.mobile-only-ctrl {
    display: flex !important;
  }

  .settings-divider.mobile-only-ctrl {
    display: block !important;
  }

  .history-sidebar,
  .view-switch,
  .text-btn,
  .icon-pill-btn,
  .settings-popover,
  .bg-popover,
  .awakening-bar,
  .pet-speech,
  .stage-web,
  .composer-box,
  .modal-card {
    background-clip: padding-box;
    -webkit-background-clip: padding-box;
    isolation: isolate;
  }

  /* Mobile Settings Gear & Liquid Glass Settings Popover */
  .settings-control {
    position: relative;
    align-items: center;
  }

  .icon-pill-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    line-height: 0;
    border-radius: 999px;
    border: 1px solid var(--glass-border);
    background: var(--glass-pill);
    color: var(--text);
    cursor: pointer;
    box-shadow: var(--glass-pill-shadow);
    backdrop-filter: var(--glass-blur-pill);
    -webkit-backdrop-filter: var(--glass-blur-pill);
    transition: transform 0.2s var(--glass-spring), background 0.2s ease, color 0.2s ease;
  }

  .icon-pill-btn svg,
  .input-mode-btn svg {
    display: block;
    flex-shrink: 0;
  }

  .icon-pill-btn:active {
    transform: scale(0.92);
  }

  .settings-popover {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: min(76vw, 252px);
    max-height: 70dvh;
    overflow-y: auto;
    background: var(--glass-bg-strong);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 8px;
    box-shadow: var(--glass-shadow);
    z-index: 140;
    display: flex;
    flex-direction: column;
    gap: 4px;
  }

  .settings-item {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 9px 12px;
    border: none;
    border-radius: 12px;
    background: transparent;
    color: var(--text);
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s ease;
  }

  .settings-item:active {
    background: var(--chip-bg);
  }

  .settings-item-val {
    font-size: 12.5px;
    color: var(--muted);
    font-weight: 500;
    font-variant-numeric: tabular-nums;
  }

  .settings-slider-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px 12px 10px;
  }

  .settings-slider-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    font-size: 13.5px;
    font-weight: 500;
    color: var(--text);
  }

  .settings-range {
    width: 100%;
    margin: 0;
    accent-color: var(--primary);
    cursor: pointer;
  }

  .settings-divider {
    height: 1px;
    margin: 2px 8px;
    background: var(--border-subtle);
  }

  .settings-bg-list {
    max-height: 210px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 4px 2px 6px;
  }

  .page {
    padding: max(8px, env(safe-area-inset-top)) 12px max(8px, env(safe-area-inset-bottom));
    gap: 6px;
  }

  /* Drawer-style mobile history sidebar (iOS sheet rounded right edge) */
  .history-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(82vw, 300px);
    z-index: 160;
    background: var(--glass-bg-strong);
    border-radius: 0 24px 24px 0;
    padding: max(14px, env(safe-area-inset-top)) 12px max(14px, env(safe-area-inset-bottom));
    box-shadow: 0 16px 42px rgba(0, 0, 0, 0.28);
    transform: translateX(0);
    opacity: 1;
  }

  .layout.history-collapsed .history-sidebar {
    width: min(82vw, 300px);
    padding: max(14px, env(safe-area-inset-top)) 12px;
    transform: translateX(-105%);
    opacity: 0;
    pointer-events: none;
  }

  .history-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: var(--backdrop);
    backdrop-filter: blur(2px);
    z-index: 150;
    opacity: 1;
    transition: opacity 0.2s ease;
  }

  .layout.history-collapsed .history-backdrop {
    opacity: 0;
    pointer-events: none;
  }

  .history-del {
    opacity: 0.65;
  }

  /* Symmetrical 3-column mobile topbar: Left history, Center view-switch, Right settings gear */
  .topbar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 6px;
  }

  .pet-zoom-bar {
    display: none !important;
  }

  .top-actions {
    display: contents;
  }

  .view-switch {
    grid-column: 2;
    justify-self: center;
  }

  .settings-control {
    grid-column: 3;
    justify-self: end;
  }

  .switch-btn {
    padding: 5px 8px;
    font-size: 12px;
  }

  .text-btn {
    padding: 5px 9px;
    font-size: 12px;
    min-height: 32px;
  }

  .bg-popover {
    width: min(72vw, 236px);
  }

  /* Awakening bar compact */
  .awakening-bar {
    padding: 4px 12px;
    font-size: 12px;
  }

  /* Pet stage & speech bubble tuned for 360-430px phone screens */
  .pet-unit {
    gap: 4px;
  }

  .pet-speech {
    min-height: 76px;
    padding: 14px 10px 14px 16px;
    border-radius: 22px;
  }

  .replay-btn {
    top: 8px;
    right: 16px;
    font-size: 11px;
    padding: 2px 8px;
  }

  .pet-speech-body {
    font-size: 15.5px;
    line-height: 1.7;
    padding-right: 48px;
    max-height: min(35dvh, 250px);
    -webkit-overflow-scrolling: touch;
  }

  .last-user-line {
    font-size: 12px;
  }

  .pet-figure {
    width: min(44vw, 196px) !important;
    height: min(44vw, 196px) !important;
    max-height: 28dvh;
    cursor: pointer;
    touch-action: manipulation;
  }

  /* Web chat view on mobile */
  .stage-web {
    border-radius: 20px;
  }

  .web-messages {
    padding: 14px 12px;
    gap: 12px;
    -webkit-overflow-scrolling: touch;
  }

  .web-msg {
    max-width: 90%;
    padding: 10px 14px;
    font-size: 15px;
    line-height: 1.68;
  }

  /* Touch-friendly mobile composer: floating mode pills above + Text/Voice mode switch */
  .composer-area {
    gap: 6px;
  }

  .composer-box {
    border-radius: 24px;
    padding: 8px 10px;
    gap: 0;
  }

  .composer-box.voice-input-mode {
    background: transparent;
    border-color: transparent;
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    padding: 4px 0;
  }

  .composer-box.voice-input-mode .hold-talk-btn,
  .composer-box.voice-input-mode .input-mode-btn {
    background: var(--glass-pill);
    box-shadow: var(--glass-pill-shadow);
    backdrop-filter: var(--glass-blur-pill);
    -webkit-backdrop-filter: var(--glass-blur-pill);
    height: 42px;
  }

  .composer-box.voice-input-mode .input-mode-btn {
    width: 42px;
  }

  .composer-input-row {
    align-items: center;
    gap: 8px;
  }

  .input-mode-btn {
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    border-radius: 999px;
    border: 1px solid var(--glass-border);
    background: var(--chip-bg);
    color: var(--text);
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.55),
      0 2px 8px rgba(15, 23, 42, 0.08);
    transition: transform 0.18s var(--glass-spring), background 0.18s ease;
  }

  .input-mode-btn:active {
    transform: scale(0.92);
  }

  .input-mode-btn .icon-kbd {
    display: none;
  }

  .composer-box.voice-input-mode .input-mode-btn .icon-mic {
    display: none;
  }

  .composer-box.voice-input-mode .input-mode-btn .icon-kbd {
    display: block;
  }

  .composer-box textarea {
    flex: 1;
    min-width: 0;
    font-size: 16px;
    line-height: 1.45;
    min-height: 38px;
    max-height: 112px;
    padding: 7px 6px;
  }

  .hold-talk-btn {
    display: none !important;
    flex: 1;
    height: 40px;
    border-radius: 999px;
    border: 1px solid var(--glass-border);
    background: var(--chip-bg);
    color: var(--text);
    font-size: 14.5px;
    font-weight: 600;
    letter-spacing: 0.03em;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    touch-action: none;
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.65),
      0 3px 10px rgba(15, 23, 42, 0.08);
    transition: transform 0.16s var(--glass-spring), background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
  }

  .composer-box.voice-input-mode textarea,
  .composer-box.voice-input-mode .send-circle-btn {
    display: none !important;
  }

  .send-circle-btn {
    width: 38px;
    height: 38px;
  }

  .composer-box.voice-input-mode .hold-talk-btn {
    display: flex !important;
  }

  .hold-talk-btn.recording {
    background: var(--active-bg);
    border-color: var(--accent-border);
    color: var(--active-text);
    transform: scale(0.985);
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.5),
      0 0 0 4px var(--focus-ring);
  }

  .hold-talk-btn.canceling {
    background: var(--danger-bg);
    border-color: var(--danger);
    color: var(--danger);
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.3),
      0 0 0 4px rgba(220, 38, 38, 0.16);
  }

  .hold-talk-btn.processing {
    opacity: 0.72;
  }

  body.theme-dark .input-mode-btn,
  body.theme-dark .hold-talk-btn {
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.14),
      0 3px 10px rgba(0, 0, 0, 0.28);
  }

  .mode-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 7px;
    padding: 4px 4px 8px;
    margin: -4px -4px -4px;
  }

  .mode-tabs::-webkit-scrollbar {
    display: none;
  }

  .tab-btn {
    flex-shrink: 0;
    font-size: 12.5px;
    padding: 5px 12px;
    backdrop-filter: var(--glass-blur-pill);
    -webkit-backdrop-filter: var(--glass-blur-pill);
  }

  .composer-tools {
    width: 100%;
    justify-content: flex-end;
    margin-left: 0;
    gap: 8px;
  }

  .tool-btn {
    font-size: 13px;
    padding: 6px 12px;
    min-height: 36px;
  }

  .send-btn {
    font-size: 14px;
    padding: 7px 18px;
    min-height: 36px;
  }

  .footnote {
    font-size: 9.5px;
    gap: 4px;
  }

  .modal-card {
    padding: 18px 18px 14px;
    border-radius: 22px;
  }
}

/* Graceful fallback for older browsers without backdrop-filter support */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .history-sidebar,
  .pet-zoom-bar,
  .bg-popover,
  .view-switch,
  .text-btn,
  .awakening-bar,
  .pet-speech,
  .stage-web,
  .composer-box,
  .modal-card {
    background: var(--surface);
  }
}
