:root {
  color-scheme: light;
  --bg: #faf9f6;
  --bg-soft: #f3f1ec;
  --surface: rgba(255, 255, 255, 0.9);
  --surface-strong: rgba(255, 255, 255, 0.97);
  --control: rgba(255, 255, 255, 0.88);
  --control-strong: rgba(255, 255, 255, 0.96);
  --card: #ffffff;
  --bubble-user: linear-gradient(180deg, #ffffff, #f7f5f1);
  --bubble-assistant: linear-gradient(180deg, #ffffff, #fbfaf7);
  --mobile-panel: #ffffff;
  --auth-overlay: rgba(247, 245, 239, 0.76);
  --history-hover: rgba(255,255,255,0.66);
  --history-active: rgba(255,255,255,0.92);
  --focus-ring: rgba(32, 48, 71, 0.05);
  --soft-shadow: rgba(30, 57, 92, 0.08);
  --chart-empty: #eef1f5;
  --stroke: rgba(22, 58, 105, 0.08);
  --stroke-strong: rgba(22, 58, 105, 0.14);
  --text: #203047;
  --muted: #6f7d90;
  --primary: #4b5563;
  --primary-soft: #f3f4f6;
  --success: #6b7280;
  --sad: #9ca3af;
  --shadow-lg: 0 10px 24px rgba(30, 57, 92, 0.04);
  --shadow-md: 0 3px 10px rgba(30, 57, 92, 0.035);
  --radius-xl: 32px;
  --radius-lg: 24px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1420;
  --bg-soft: #151d2b;
  --surface: rgba(18, 25, 38, 0.88);
  --surface-strong: rgba(24, 33, 49, 0.96);
  --control: rgba(26, 36, 53, 0.9);
  --control-strong: rgba(31, 42, 60, 0.96);
  --card: #141d2b;
  --bubble-user: linear-gradient(180deg, #1d2b3f, #172234);
  --bubble-assistant: linear-gradient(180deg, #182536, #121b2a);
  --mobile-panel: #101827;
  --auth-overlay: rgba(7, 11, 18, 0.78);
  --history-hover: rgba(44, 58, 80, 0.48);
  --history-active: rgba(54, 70, 96, 0.62);
  --focus-ring: rgba(73, 211, 180, 0.12);
  --soft-shadow: rgba(0, 0, 0, 0.24);
  --chart-empty: #202b3c;
  --stroke: rgba(201, 216, 238, 0.12);
  --stroke-strong: rgba(201, 216, 238, 0.22);
  --text: #e8eef8;
  --muted: #9aa9bd;
  --primary: #7dd3fc;
  --primary-soft: #1e2a3c;
  --success: #49d3b4;
  --sad: #7b8798;
  --shadow-lg: 0 18px 42px rgba(0, 0, 0, 0.26);
  --shadow-md: 0 8px 20px rgba(0, 0, 0, 0.2);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  color: var(--text);
  font-family: "Vivo Sans", "vivo Sans", Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background-color: var(--bg);
}
body {
  min-height: 100%;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  overflow: hidden;
  position: relative;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(circle at 18px 18px, rgba(75, 85, 99, 0.08) 0 1.4px, transparent 1.8px),
    radial-gradient(circle at 58px 42px, rgba(255, 79, 139, 0.08) 0 1.5px, transparent 1.9px),
    radial-gradient(circle at 32px 66px, rgba(73, 211, 180, 0.08) 0 1.3px, transparent 1.8px),
    linear-gradient(135deg, transparent 0 42px, rgba(32, 48, 71, 0.035) 42px 43px, transparent 43px 86px),
    linear-gradient(45deg, transparent 0 54px, rgba(32, 48, 71, 0.03) 54px 55px, transparent 55px 108px),
    linear-gradient(180deg, #fffefc 0%, #fbfaf7 45%, #f5f3ee 100%);
  background-size: 92px 92px, 92px 92px, 92px 92px, 128px 128px, 156px 156px, auto;
}

:root[data-theme="dark"] body::before {
  background:
    radial-gradient(circle at 18px 18px, rgba(125, 211, 252, 0.11) 0 1.4px, transparent 1.8px),
    radial-gradient(circle at 58px 42px, rgba(255, 79, 139, 0.1) 0 1.5px, transparent 1.9px),
    radial-gradient(circle at 32px 66px, rgba(73, 211, 180, 0.1) 0 1.3px, transparent 1.8px),
    linear-gradient(135deg, transparent 0 42px, rgba(232, 238, 248, 0.045) 42px 43px, transparent 43px 86px),
    linear-gradient(45deg, transparent 0 54px, rgba(232, 238, 248, 0.035) 54px 55px, transparent 55px 108px),
    linear-gradient(180deg, #0b111b 0%, #0e1420 48%, #121a28 100%);
  background-size: 92px 92px, 92px 92px, 92px 92px, 128px 128px, 156px 156px, auto;
}
button, textarea { font: inherit; }

.app-shell {
  width: min(100%, 1180px);
  margin: 0 auto;
  padding: 16px;
  height: 100dvh;
}

.glass {
  background: var(--surface);
  border: 1px solid var(--stroke);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(16px);
}

h1, h2, h3, p { margin: 0; }
h2 { font-size: 18px; letter-spacing: -0.02em; }
h3 { font-size: 22px; letter-spacing: -0.03em; }
.layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 16px;
  align-items: stretch;
  height: 100%;
  min-height: 0;
}

.history-panel {
  border-radius: var(--radius-xl);
  height: 100%;
  min-height: 0;
  max-height: 100%;
  padding: 16px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: 12px;
  overflow: hidden;
}

.history-top {
  display: grid;
  gap: 12px;
}

.history-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.new-chat-button {
  min-height: 42px;
  flex: 1 1 auto;
  border: 1px solid var(--stroke);
  border-radius: 999px;
  background: var(--control);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 0 14px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.new-chat-button span {
  font-size: 21px;
  line-height: 1;
}

.history-search input {
  width: 100%;
  height: 42px;
  border: 1px solid var(--stroke);
  border-radius: 999px;
  background: var(--control);
  color: var(--text);
  padding: 0 14px;
  outline: none;
}

.history-search input:focus {
  border-color: var(--stroke-strong);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.history-section-title {
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
  padding: 2px 8px 0;
}

.icon-button {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: 1px solid var(--stroke);
  background: var(--control);
  color: var(--text);
  font-size: 24px;
  line-height: 1;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.theme-toggle {
  position: relative;
}

.sidebar-bottom-actions {
  display: grid;
  gap: 8px;
}

.sidebar-theme-toggle,
.sidebar-install-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  min-height: 44px;
  border: 1px solid var(--stroke);
  border-radius: 999px;
  background: var(--control);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  text-align: left;
}

.sidebar-theme-toggle:hover,
.sidebar-install-btn:hover {
  background: var(--control-strong);
}

.sidebar-theme-label {
  flex: 1;
}

.theme-toggle-icon {
  width: 17px;
  height: 17px;
  border-radius: 999px;
  background: var(--text);
  box-shadow: inset -5px -4px 0 var(--control);
  transition: transform .18s ease, box-shadow .18s ease, background .18s ease;
}

:root[data-theme="dark"] .theme-toggle-icon {
  background: #ffd166;
  box-shadow: 0 0 0 4px rgba(255, 209, 102, 0.14);
  transform: rotate(18deg) scale(0.92);
}

.history-close,
.mobile-history-button {
  display: none;
}

.history-list {
  display: grid;
  align-content: start;
  gap: 8px;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding-right: 2px;
}

.history-list::-webkit-scrollbar {
  width: 10px;
}

.history-list::-webkit-scrollbar-track {
  background: transparent;
}

.history-list::-webkit-scrollbar-thumb {
  background: rgba(32, 48, 71, 0.16);
  border: 3px solid transparent;
  border-radius: 999px;
  background-clip: padding-box;
}

.history-empty {
  color: var(--muted);
  font-size: 13px;
  padding: 10px 8px;
}

.history-item {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 18px;
  background: transparent;
  color: var(--text);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 28px;
  gap: 8px;
  align-items: center;
  padding: 5px;
}

.history-item:hover {
  background: var(--history-hover);
  border-color: var(--stroke);
}

.history-item.active {
  background: var(--history-active);
  border-color: var(--stroke-strong);
  box-shadow: var(--shadow-md);
}

.history-open-button {
  min-width: 0;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  display: grid;
  gap: 5px;
  padding: 6px 7px;
  text-align: left;
}

.history-title {
  font-size: 14px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-delete {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 0;
  background: transparent;
  cursor: pointer;
  color: #9ca3af;
  display: grid;
  place-items: center;
  font-size: 19px;
  line-height: 1;
  opacity: 0;
}

.history-item:hover .history-delete,
.history-item.active .history-delete,
.history-delete:focus-visible {
  opacity: 1;
}

.history-delete:hover,
.history-delete:focus-visible {
  background: rgba(239, 68, 68, 0.08);
  color: #b42318;
  outline: none;
}

.history-meta {
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-panel {
  border-radius: var(--radius-xl);
  padding: 18px;
  display: grid;
  gap: 14px;
  overflow: hidden;
  min-height: 0;
}

.chat-panel--full {
  height: 100%;
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.chat-body {
  position: relative;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
}

.chat-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.chat-presence {
  display: flex;
  align-items: center;
  gap: 14px;
}

#statusLine {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  margin-top: 4px;
}

.chat-presence h3 {
  font-size: 20px;
}

.chat-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.user-menu {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 7px;
  border: 1px solid var(--stroke);
  border-radius: 18px;
  background: var(--control);
}

.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  object-fit: cover;
  background: var(--primary-soft);
}

.user-name {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
}

.user-menu .ghost-button {
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 800;
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: var(--auth-overlay);
  backdrop-filter: blur(12px);
}

.auth-panel {
  width: min(100%, 420px);
  border-radius: 28px;
  padding: 28px;
  display: grid;
  justify-items: center;
  gap: 14px;
  text-align: center;
}

.auth-mark {
  width: 86px;
  height: 86px;
  display: grid;
  place-items: center;
}

.auth-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.auth-panel h1 {
  color: var(--text);
  font-size: 26px;
  line-height: 1.1;
}

.auth-panel p {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.google-login-button {
  min-height: 48px;
  border: 1px solid var(--stroke-strong);
  border-radius: 999px;
  background: var(--card);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0 18px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: var(--shadow-md);
}

.google-login-button span {
  width: 24px;
  height: 24px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  border: 1px solid var(--stroke);
  color: #4285f4;
  font-weight: 900;
}

.google-login-button:disabled {
  cursor: not-allowed;
  opacity: 0.56;
}

.character-stage {
  position: relative;
  overflow: visible;
  display: grid;
  place-items: center;
  isolation: isolate;
}

.character-stage--inline {
  width: 132px;
  height: 132px;
  padding: 0;
  border-radius: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
  flex: 0 0 auto;
}

.ambient-ring,
.character-aura {
  position: absolute;
  border-radius: 999px;
  pointer-events: none;
}

.ambient-ring,
.character-aura {
  opacity: 0;
}

.squid {
  position: relative;
  width: 108px;
  height: 108px;
  z-index: 2;
  animation: none;
  transform-origin: 50% 72%;
}

.squid img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  border-radius: 0;
}

.character-stage--inline .squid::before,
.character-stage--inline .squid::after,
.chat-center-stage .squid::before,
.chat-center-stage .squid::after {
  position: absolute;
  pointer-events: none;
  opacity: 0;
}

.character-stage--inline .squid::before,
.chat-center-stage .squid::before {
  content: "";
  right: 0;
  top: 6px;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #45d4c7;
  box-shadow: 13px 8px 0 #ffd44d, -10px 12px 0 #9b7cff;
}

.character-stage--inline .squid::after,
.chat-center-stage .squid::after {
  content: "";
  left: 50%;
  bottom: -6px;
  width: 42px;
  height: 9px;
  border-radius: 999px;
  background: rgba(32, 48, 71, 0.1);
  transform: translateX(-50%);
}

.chat-center-stage {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 150px;
  height: 150px;
  transform: translate(-50%, -50%);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}

.chat-center-stage .squid {
  width: 124px;
  height: 124px;
}

body.chat-empty .chat-center-stage {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.messages {
  display: grid;
  align-content: start;
  gap: 14px;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 4px 4px;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.messages::-webkit-scrollbar {
  width: 10px;
}

.messages::-webkit-scrollbar-track {
  background: transparent;
}

.messages::-webkit-scrollbar-thumb {
  background: rgba(32, 48, 71, 0.16);
  border: 3px solid transparent;
  border-radius: 999px;
  background-clip: padding-box;
}

.message-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  width: 100%;
}
.message-row.user {
  justify-content: flex-end;
  padding-left: 18%;
}
.message-row.assistant { justify-content: flex-start; }

.message-row.assistant .message-content {
  max-width: min(100%, 560px);
}

.message-avatar {
  width: 62px;
  height: 62px;
  border-radius: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
  display: grid;
  place-items: center;
  overflow: visible;
  flex: 0 0 auto;
  opacity: 1;
  visibility: visible;
  z-index: 1;
}

.message-avatar .squid {
  width: 58px;
  height: 58px;
  transform: none !important;
  opacity: 1;
  visibility: visible;
}

.message-avatar .squid img {
  border-radius: 0;
  display: block;
  opacity: 1;
  visibility: visible;
}

.message-avatar .squid::before,
.message-avatar .squid::after {
  content: none;
}

.message-content {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.message-name {
  font-size: 12px;
  color: var(--muted);
  padding-left: 4px;
}

.bubble {
  max-width: min(100%, 560px);
  border-radius: 24px;
  padding: 13px 16px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  box-shadow: var(--shadow-md);
}

.message-row.user .bubble {
  background: var(--bubble-user);
  border: 1px solid var(--stroke);
  margin-left: auto;
}

.message-row.assistant .bubble {
  background: var(--bubble-assistant);
  border: 1px solid var(--stroke);
  max-width: 100%;
}

.dynamic-stack {
  display: grid;
  gap: 10px;
  width: min(100%, 620px);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.metric-card {
  border: 1px solid var(--stroke);
  border-radius: 18px;
  background: var(--card);
  padding: 12px;
  box-shadow: var(--shadow-md);
  min-width: 0;
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 5px;
}

.metric-value {
  display: block;
  color: var(--text);
  font-size: 19px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.chart-card {
  width: min(100%, 560px);
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--stroke);
  border-radius: 24px;
  background: var(--card);
  box-shadow: var(--shadow-md);
}

.chart-pie {
  width: 150px;
  aspect-ratio: 1;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px var(--stroke);
}

.chart-legend {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.chart-legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: var(--text);
  font-size: 13px;
  line-height: 1.35;
}

.chart-legend-item span:last-child {
  min-width: 0;
  overflow-wrap: anywhere;
}

.chart-swatch {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  flex: 0 0 auto;
}

.combo-chart-card {
  width: min(100%, 680px);
  border: 1px solid var(--stroke);
  border-radius: 18px;
  background: var(--card);
  padding: 14px;
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.combo-chart-title {
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
  padding: 0 2px 8px;
}

.combo-chart-card svg {
  width: 100%;
  height: auto;
  display: block;
}

.combo-grid line {
  stroke: var(--stroke);
  stroke-width: 1;
}

.combo-grid text,
.combo-axis-label,
.combo-x-label,
.combo-bar-value {
  fill: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.combo-axis-label {
  fill: var(--text);
}

.combo-axis-label-right {
  fill: #0f766e;
}

.combo-bars rect {
  fill: #4f9dff;
}

.combo-bar-value {
  fill: var(--text);
  font-size: 10px;
}

.combo-line polyline {
  fill: none;
  stroke: #0f766e;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.combo-line circle {
  fill: var(--card);
  stroke: #0f766e;
  stroke-width: 2;
}

.combo-legend {
  display: flex;
  gap: 14px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  padding: 6px 2px 0;
}

.combo-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.combo-legend i {
  width: 18px;
  height: 8px;
  border-radius: 999px;
  display: inline-block;
}

.legend-bar {
  background: #4f9dff;
}

.legend-line {
  background: #0f766e;
  height: 3px !important;
}

.data-table-card {
  width: min(100%, 620px);
  border: 1px solid var(--stroke);
  border-radius: 24px;
  background: var(--card);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.data-table-title {
  padding: 12px 14px 0;
  font-weight: 800;
  font-size: 14px;
}

.data-table-scroll {
  max-height: 360px;
  overflow: auto;
  padding: 10px 14px 14px;
}

.data-table-card table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  line-height: 1.35;
}

.data-table-card th,
.data-table-card td {
  border-bottom: 1px solid var(--stroke);
  padding: 8px 7px;
  text-align: left;
  vertical-align: top;
}

.data-table-card th {
  color: var(--muted);
  font-weight: 800;
  white-space: nowrap;
}

.data-table-card td.numeric,
.data-table-card th.numeric {
  text-align: right;
}

.ghost-button, .send-button {
  border: 1px solid var(--stroke);
  color: var(--text);
  background: var(--control);
}
.ghost-button {
  border-radius: 999px;
  padding: 10px 14px;
}
.ghost-button:hover,
.send-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 24px var(--soft-shadow);
}
.send-button {
  border-radius: 24px;
  min-height: 56px;
  padding: 0 24px;
  background: linear-gradient(180deg, var(--control-strong), var(--bg-soft));
  font-weight: 700;
  align-self: stretch;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: stretch;
}

#chatInput {
  width: 100%;
  border-radius: 24px;
  border: 1px solid var(--stroke-strong);
  background: var(--control-strong);
  color: var(--text);
  resize: none;
  min-height: 56px;
  max-height: 180px;
  padding: 16px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.18);
}
#chatInput::placeholder { color: #96a0ae; }
.hidden { display: none; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.character-stage[data-mood="thinking"] .squid { animation: thinkFloat 1.35s infinite ease-in-out; }
.character-stage[data-mood="thinking"] .squid::before { animation: thoughtDots 1.35s infinite ease-in-out; }
.character-stage[data-mood="thinking"] .squid::after { animation: shadowThink 1.35s infinite ease-in-out; opacity: 1; }
.character-stage[data-mood="thinking"] .character-aura { background: radial-gradient(circle, rgba(255,255,255,0.78), rgba(226,232,240,0) 72%); opacity: 1; }
.character-stage[data-mood="working"] .squid { animation: workingType 0.62s infinite steps(2, end); }
.character-stage[data-mood="working"] .squid::before { animation: workSparks 0.62s infinite steps(2, end); }
.character-stage[data-mood="working"] .squid::after { animation: shadowWork 0.62s infinite steps(2, end); opacity: 1; }
.character-stage[data-mood="working"] .ambient-ring { border-color: rgba(75, 85, 99, 0.12); opacity: 1; }
.character-stage[data-mood="happy"] .squid { animation: happyBounce 1.8s infinite ease-in-out; }
.character-stage[data-mood="happy"] .character-aura { background: radial-gradient(circle, rgba(255,255,255,0.85), rgba(229,231,235,0) 72%); opacity: 1; }
.character-stage[data-mood="serious"] .squid,
.character-stage[data-mood="error"] .squid,
.character-stage[data-mood="timeout"] .squid { animation: seriousFloat 2.3s infinite ease-in-out; }
.character-stage[data-mood="serious"] .ambient-ring,
.character-stage[data-mood="error"] .ambient-ring,
.character-stage[data-mood="timeout"] .ambient-ring { border-color: rgba(107, 114, 128, 0.14); }
.character-stage[data-mood="error"] .character-aura,
.character-stage[data-mood="timeout"] .character-aura { background: radial-gradient(circle, rgba(229,231,235,0.7), rgba(229,231,235,0) 72%); opacity: 1; }

:root[data-theme="dark"] .character-stage[data-mood="thinking"] .character-aura {
  background: radial-gradient(circle, rgba(125,211,252,0.18), rgba(15,23,42,0) 72%);
}

:root[data-theme="dark"] .character-stage[data-mood="working"] .ambient-ring {
  border-color: rgba(73, 211, 180, 0.18);
}

:root[data-theme="dark"] .character-stage[data-mood="happy"] .character-aura {
  background: radial-gradient(circle, rgba(73,211,180,0.18), rgba(15,23,42,0) 72%);
}

:root[data-theme="dark"] .character-stage[data-mood="error"] .character-aura,
:root[data-theme="dark"] .character-stage[data-mood="timeout"] .character-aura {
  background: radial-gradient(circle, rgba(255, 79, 139, 0.14), rgba(15,23,42,0) 72%);
}

@keyframes thinkFloat { 0%,100% { transform: translateY(0) rotate(-1deg) scale(1); } 50% { transform: translateY(-7px) rotate(1deg) scale(1.035); } }
@keyframes thoughtDots { 0%,100% { opacity: .2; transform: translate(0, 3px) scale(.82); } 45% { opacity: 1; transform: translate(2px, -5px) scale(1); } }
@keyframes shadowThink { 0%,100% { transform: translateX(-50%) scaleX(1); opacity: .16; } 50% { transform: translateX(-50%) scaleX(.72); opacity: .08; } }
@keyframes workingType { 0%,100% { transform: translate(0, 0) rotate(-1deg); } 25% { transform: translate(2px, 1px) rotate(1.5deg); } 50% { transform: translate(-1px, -1px) rotate(-.5deg); } 75% { transform: translate(1px, 1px) rotate(1deg); } }
@keyframes workSparks { 0%,100% { opacity: .2; transform: translateY(4px) scale(.8); } 50% { opacity: 1; transform: translateY(-2px) scale(1.08); } }
@keyframes shadowWork { 0%,100% { transform: translateX(-50%) scaleX(.92); opacity: .13; } 50% { transform: translateX(-50%) scaleX(1.12); opacity: .2; } }
@keyframes happyBounce { 0%,100% { transform: translateY(0) rotate(-2deg); } 40% { transform: translateY(-9px) rotate(2deg); } 70% { transform: translateY(-2px) rotate(1deg); } }
@keyframes seriousFloat { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
@keyframes pulse { 0%,100% { transform: scale(.96); opacity: .32; } 50% { transform: scale(1.04); opacity: .8; } }
@keyframes breathe { 0%,100% { transform: scale(.92); opacity: .6; } 50% { transform: scale(1.05); opacity: 1; } }
@media (max-width: 720px) {
  body {
    overflow: hidden;
  }

  body.history-open::after {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(8, 12, 20, 0.38);
    z-index: 8;
  }

  .app-shell {
    padding: 0;
    height: 100dvh;
  }

  .layout {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .history-panel {
    position: fixed;
    inset: 10px auto 10px 10px;
    z-index: 9;
    width: min(63vw, 248px);
    height: calc(100dvh - 20px);
    max-height: calc(100dvh - 20px);
    min-height: 0;
    background: var(--mobile-panel);
    border: 1px solid var(--stroke);
    box-shadow: 0 20px 48px rgba(30, 57, 92, 0.16);
    backdrop-filter: none;
    transform: translateX(calc(-100% - 18px));
    transition: transform .22s ease;
  }

  body.history-open .history-panel {
    transform: translateX(0);
  }

  .history-close,
  .mobile-history-button {
    display: grid;
  }

  .glass {
    background: transparent;
    border: 0;
    box-shadow: none;
    backdrop-filter: none;
  }

  .history-panel.glass {
    background: var(--mobile-panel);
    border: 1px solid var(--stroke);
    box-shadow: 0 20px 48px rgba(30, 57, 92, 0.16);
  }

  .chat-panel {
    border-radius: 0;
    padding: 0 12px 12px;
  }

  .chat-panel--full {
    height: 100dvh;
    min-height: 0;
    margin-top: -10px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
    grid-template-rows: auto 1fr auto;
  }

  .chat-head {
    align-items: center;
    flex-direction: row;
    gap: 8px;
    padding-top: 6px;
  }

  .chat-actions {
    width: auto;
    margin-left: auto;
    align-self: flex-start;
    padding-top: 14px;
  }

  .mobile-history-button {
    width: 42px;
    height: 42px;
    min-height: 42px;
    padding: 0;
    font-size: 20px;
  }

  .messages {
    padding-top: 0;
    padding-bottom: 8px;
    height: 100%;
    max-height: 100%;
    overflow-y: auto;
  }

  .composer {
    position: sticky;
    bottom: 0;
    padding-top: 6px;
    background: transparent;
  }

  #chatInput,
  .send-button {
    min-height: 60px;
  }

  .bubble {
    max-width: calc(100vw - 110px);
  }

  .chart-card {
    grid-template-columns: 106px minmax(0, 1fr);
    width: min(100%, calc(100vw - 110px));
    padding: 12px;
  }

  .chart-pie {
    width: 106px;
  }

  .metric-grid {
    grid-template-columns: 1fr;
    width: min(100%, calc(100vw - 110px));
  }

  .dynamic-stack,
  .combo-chart-card,
  .data-table-card {
    width: min(100%, calc(100vw - 110px));
  }

  .message-row.user {
    padding-left: 16%;
  }

  .message-row.user .bubble {
    max-width: min(82vw, 520px);
  }

  .message-row.assistant .message-content {
    max-width: calc(100vw - 110px);
  }
}
