:root {
  --bg: #07111f;
  --bg-soft: #0a1a2c;
  --panel: rgba(14, 33, 52, 0.78);
  --panel-strong: #10263d;
  --line: rgba(148, 210, 255, 0.14);
  --line-strong: rgba(148, 210, 255, 0.26);
  --text: #e9f5ff;
  --muted: #8aa8c0;
  --muted-strong: #a9c4d8;
  --cyan: #7dd3fc;
  --blue: #3b82f6;
  --blue-deep: #1d4ed8;
  --danger: #fb7185;
  --page-glow-1: rgba(45, 130, 200, 0.28);
  --page-glow-2: rgba(14, 116, 144, 0.18);
  --page-glow-3: rgba(29, 78, 216, 0.16);
  --page-bg-1: #07111f;
  --page-bg-2: #081728;
  --page-bg-3: #06101d;
  --chat-overlay-1: rgba(6, 18, 31, 0.24);
  --chat-overlay-2: rgba(5, 15, 26, 0.62);
  --topbar-bg: rgba(6, 18, 31, 0.68);
  --composer-fade: rgba(6, 17, 29, 0.9);
  --composer-box-bg: rgba(11, 29, 47, 0.88);
  --bot-bubble-1: rgba(19, 43, 67, 0.96);
  --bot-bubble-2: rgba(12, 29, 48, 0.96);
  --bot-bubble-border: rgba(125, 211, 252, 0.11);
  --user-bubble-1: #3182f6;
  --user-bubble-2: #1f63d8;
  --user-bubble-text: #f5fbff;
  --send-from: #8ee7ff;
  --send-to: #4ca8ff;
  --send-text: #04101d;
  --sheet-glow: rgba(59, 130, 246, 0.18);
  --sheet-1: rgba(17, 42, 66, 0.98);
  --sheet-2: rgba(8, 23, 39, 0.99);
  --whale-1: rgba(56, 189, 248, 0.28);
  --whale-2: rgba(29, 78, 216, 0.22);
  --metric-bg: rgba(125, 211, 252, 0.045);
  --button-bg: rgba(125, 211, 252, 0.06);
  --button-hover: rgba(125, 211, 252, 0.12);
  --suggestion-text: #b9d9ec;
  --bg-photo-opacity: 0.35;
  --bg-photo-blur: 2px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --radius: 20px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
}

html[data-theme="sakura"] {
  --bg: #1b0d16;
  --bg-soft: #25101e;
  --panel: rgba(43, 20, 35, 0.8);
  --panel-strong: #321626;
  --line: rgba(249, 168, 212, 0.16);
  --line-strong: rgba(249, 168, 212, 0.3);
  --text: #fff0f7;
  --muted: #c79ab0;
  --muted-strong: #e0b4c8;
  --cyan: #f9a8d4;
  --blue: #ec4899;
  --blue-deep: #be185d;
  --danger: #fb7185;
  --page-glow-1: rgba(236, 72, 153, 0.24);
  --page-glow-2: rgba(249, 168, 212, 0.14);
  --page-glow-3: rgba(190, 24, 93, 0.18);
  --page-bg-1: #1b0d16;
  --page-bg-2: #25101e;
  --page-bg-3: #160a12;
  --chat-overlay-1: rgba(27, 13, 22, 0.24);
  --chat-overlay-2: rgba(20, 9, 16, 0.66);
  --topbar-bg: rgba(27, 13, 22, 0.7);
  --composer-fade: rgba(20, 9, 16, 0.92);
  --composer-box-bg: rgba(45, 21, 36, 0.9);
  --bot-bubble-1: rgba(54, 26, 43, 0.97);
  --bot-bubble-2: rgba(37, 16, 29, 0.97);
  --bot-bubble-border: rgba(249, 168, 212, 0.14);
  --user-bubble-1: #ec4899;
  --user-bubble-2: #be185d;
  --user-bubble-text: #fff0f7;
  --send-from: #f9a8d4;
  --send-to: #ec4899;
  --send-text: #2a0716;
  --sheet-glow: rgba(236, 72, 153, 0.18);
  --sheet-1: rgba(54, 26, 43, 0.99);
  --sheet-2: rgba(28, 12, 23, 0.99);
  --whale-1: rgba(249, 168, 212, 0.3);
  --whale-2: rgba(190, 24, 93, 0.24);
  --metric-bg: rgba(249, 168, 212, 0.07);
  --button-bg: rgba(249, 168, 212, 0.08);
  --button-hover: rgba(249, 168, 212, 0.16);
  --suggestion-text: #e7b9cd;
}

html[data-theme="forest"] {
  --bg: #071711;
  --bg-soft: #0c2118;
  --panel: rgba(13, 38, 27, 0.8);
  --panel-strong: #123626;
  --line: rgba(134, 239, 172, 0.15);
  --line-strong: rgba(134, 239, 172, 0.28);
  --text: #effff5;
  --muted: #8fb8a2;
  --muted-strong: #b4d8c2;
  --cyan: #86efac;
  --blue: #34d399;
  --blue-deep: #059669;
  --danger: #fb7185;
  --page-glow-1: rgba(52, 211, 153, 0.22);
  --page-glow-2: rgba(134, 239, 172, 0.13);
  --page-glow-3: rgba(5, 150, 105, 0.15);
  --page-bg-1: #071711;
  --page-bg-2: #0b2017;
  --page-bg-3: #06120d;
  --chat-overlay-1: rgba(7, 23, 17, 0.22);
  --chat-overlay-2: rgba(5, 17, 12, 0.66);
  --topbar-bg: rgba(7, 23, 17, 0.7);
  --composer-fade: rgba(5, 17, 12, 0.92);
  --composer-box-bg: rgba(14, 42, 29, 0.9);
  --bot-bubble-1: rgba(18, 48, 34, 0.97);
  --bot-bubble-2: rgba(10, 29, 21, 0.97);
  --bot-bubble-border: rgba(134, 239, 172, 0.13);
  --user-bubble-1: #34d399;
  --user-bubble-2: #059669;
  --user-bubble-text: #04140d;
  --send-from: #86efac;
  --send-to: #34d399;
  --send-text: #04140d;
  --sheet-glow: rgba(52, 211, 153, 0.16);
  --sheet-1: rgba(18, 48, 34, 0.99);
  --sheet-2: rgba(8, 24, 16, 0.99);
  --whale-1: rgba(134, 239, 172, 0.28);
  --whale-2: rgba(5, 150, 105, 0.22);
  --metric-bg: rgba(134, 239, 172, 0.06);
  --button-bg: rgba(134, 239, 172, 0.08);
  --button-hover: rgba(134, 239, 172, 0.16);
  --suggestion-text: #b8e6c9;
}

html[data-theme="midnight"] {
  --bg: #0b0a1a;
  --bg-soft: #12102a;
  --panel: rgba(24, 20, 52, 0.82);
  --panel-strong: #211b46;
  --line: rgba(196, 181, 253, 0.16);
  --line-strong: rgba(196, 181, 253, 0.3);
  --text: #f4f0ff;
  --muted: #a79bc9;
  --muted-strong: #c9bde3;
  --cyan: #c4b5fd;
  --blue: #8b5cf6;
  --blue-deep: #6d28d9;
  --danger: #fb7185;
  --page-glow-1: rgba(139, 92, 246, 0.24);
  --page-glow-2: rgba(196, 181, 253, 0.14);
  --page-glow-3: rgba(109, 40, 217, 0.18);
  --page-bg-1: #0b0a1a;
  --page-bg-2: #14102b;
  --page-bg-3: #080713;
  --chat-overlay-1: rgba(11, 10, 26, 0.24);
  --chat-overlay-2: rgba(7, 6, 17, 0.68);
  --topbar-bg: rgba(11, 10, 26, 0.72);
  --composer-fade: rgba(7, 6, 17, 0.92);
  --composer-box-bg: rgba(30, 25, 64, 0.92);
  --bot-bubble-1: rgba(35, 29, 72, 0.97);
  --bot-bubble-2: rgba(21, 17, 47, 0.97);
  --bot-bubble-border: rgba(196, 181, 253, 0.14);
  --user-bubble-1: #8b5cf6;
  --user-bubble-2: #6d28d9;
  --user-bubble-text: #f8f5ff;
  --send-from: #c4b5fd;
  --send-to: #8b5cf6;
  --send-text: #160b2e;
  --sheet-glow: rgba(139, 92, 246, 0.18);
  --sheet-1: rgba(35, 29, 72, 0.99);
  --sheet-2: rgba(15, 12, 32, 0.99);
  --whale-1: rgba(196, 181, 253, 0.3);
  --whale-2: rgba(109, 40, 217, 0.24);
  --metric-bg: rgba(196, 181, 253, 0.07);
  --button-bg: rgba(196, 181, 253, 0.08);
  --button-hover: rgba(196, 181, 253, 0.16);
  --suggestion-text: #c9bde3;
}

html[data-theme="cream"] {
  --bg: #f7efe4;
  --bg-soft: #efe2d2;
  --panel: rgba(255, 250, 244, 0.82);
  --panel-strong: #fffaf4;
  --line: rgba(120, 90, 62, 0.18);
  --line-strong: rgba(120, 90, 62, 0.32);
  --text: #30261d;
  --muted: #7b6a5b;
  --muted-strong: #5c4b3d;
  --cyan: #c27648;
  --blue: #b96536;
  --blue-deep: #8f4b24;
  --danger: #b33a3a;
  --page-glow-1: rgba(245, 190, 140, 0.45);
  --page-glow-2: rgba(255, 230, 200, 0.55);
  --page-glow-3: rgba(210, 150, 100, 0.22);
  --page-bg-1: #fbf4ea;
  --page-bg-2: #f4e7d7;
  --page-bg-3: #efe0ce;
  --chat-overlay-1: rgba(255, 250, 244, 0.48);
  --chat-overlay-2: rgba(247, 236, 222, 0.82);
  --topbar-bg: rgba(255, 250, 244, 0.82);
  --composer-fade: rgba(247, 236, 222, 0.95);
  --composer-box-bg: rgba(255, 251, 246, 0.94);
  --bot-bubble-1: rgba(255, 250, 243, 0.98);
  --bot-bubble-2: rgba(248, 238, 226, 0.98);
  --bot-bubble-border: rgba(120, 90, 62, 0.15);
  --user-bubble-1: #d68a5b;
  --user-bubble-2: #b96536;
  --user-bubble-text: #fff8f1;
  --send-from: #f0b88b;
  --send-to: #d68a5b;
  --send-text: #3b2213;
  --sheet-glow: rgba(245, 190, 140, 0.26);
  --sheet-1: rgba(255, 250, 244, 0.99);
  --sheet-2: rgba(244, 231, 217, 0.99);
  --whale-1: rgba(255, 200, 150, 0.5);
  --whale-2: rgba(214, 138, 91, 0.3);
  --metric-bg: rgba(120, 90, 62, 0.06);
  --button-bg: rgba(120, 90, 62, 0.06);
  --button-hover: rgba(120, 90, 62, 0.12);
  --suggestion-text: #5c4b3d;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  text-rendering: optimizeLegibility;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  content: "";
  background:
    radial-gradient(circle at 16% 8%, var(--page-glow-1), transparent 34%),
    radial-gradient(circle at 92% 18%, var(--page-glow-2), transparent 30%),
    radial-gradient(circle at 50% 110%, var(--page-glow-3), transparent 45%),
    linear-gradient(155deg, var(--page-bg-1) 0%, var(--page-bg-2) 55%, var(--page-bg-3) 100%);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

#app {
  position: relative;
  width: 100%;
  max-width: 820px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
}

/* ---------- Login ---------- */

.login-screen {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: calc(28px + var(--safe-top)) 22px calc(22px + var(--safe-bottom));
  overflow: hidden;
}

.login-screen::before,
.login-screen::after {
  position: absolute;
  border: 1px solid rgba(125, 211, 252, 0.1);
  border-radius: 999px;
  content: "";
  pointer-events: none;
}

.login-screen::before {
  top: -120px;
  right: -160px;
  width: 380px;
  height: 380px;
  background: radial-gradient(circle, rgba(59, 130, 246, 0.1), transparent 68%);
}

.login-screen::after {
  bottom: -180px;
  left: -170px;
  width: 420px;
  height: 420px;
  background: radial-gradient(circle, rgba(14, 116, 144, 0.09), transparent 68%);
}

.login-card {
  position: relative;
  z-index: 1;
  width: min(100%, 390px);
  padding: 30px 24px 24px;
  text-align: center;
  background: linear-gradient(160deg, var(--panel-strong), var(--panel));
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow:
    0 30px 80px rgba(0, 0, 0, 0.42),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
}

.login-avatar-wrap {
  position: relative;
  display: grid;
  width: 96px;
  height: 96px;
  margin: 0 auto 18px;
  place-items: center;
  background: rgba(125, 211, 252, 0.08);
  border: 1px solid rgba(125, 211, 252, 0.22);
  border-radius: 32px;
  box-shadow: 0 12px 38px rgba(34, 130, 200, 0.22);
}

.login-avatar {
  width: 82px;
  height: 82px;
  border-radius: 26px;
  object-fit: cover;
}

.online-dot {
  position: absolute;
  right: 12px;
  bottom: 10px;
  width: 13px;
  height: 13px;
  background: #34d399;
  border: 3px solid #0d2237;
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.12);
}

.online-dot.offline {
  background: #fb7185;
  box-shadow: 0 0 0 4px rgba(251, 113, 133, 0.12);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--cyan);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.28em;
}

.login-card h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.login-subtitle {
  max-width: 260px;
  margin: 10px auto 24px;
  color: var(--muted-strong);
  font-size: 14px;
  line-height: 1.7;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 11px;
}

#pin {
  width: 100%;
  height: 54px;
  padding: 0 14px;
  color: var(--text);
  font-size: 21px;
  font-weight: 600;
  letter-spacing: 0.38em;
  text-align: center;
  background: rgba(2, 12, 23, 0.5);
  border: 1px solid var(--line-strong);
  border-radius: 15px;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

#pin::placeholder {
  color: #5f7f98;
  font-size: 14px;
  font-weight: 400;
  letter-spacing: 0.06em;
}

#pin:focus {
  border-color: rgba(125, 211, 252, 0.7);
  box-shadow: 0 0 0 4px rgba(125, 211, 252, 0.1);
  outline: none;
}

.login-form button {
  width: 100%;
  height: 52px;
  color: #04101d;
  font-size: 16px;
  font-weight: 700;
  background: linear-gradient(135deg, #8ee7ff, #4ca8ff 58%, #3b82f6);
  border: 0;
  border-radius: 15px;
  box-shadow: 0 12px 26px rgba(59, 130, 246, 0.25);
  transition: transform 120ms ease, filter 160ms ease;
}

.login-form button:active {
  transform: scale(0.985);
}

.login-form button:disabled {
  cursor: wait;
  filter: saturate(0.5) brightness(0.8);
}

.form-message {
  min-height: 20px;
  margin: 10px 0 0;
  color: var(--danger);
  font-size: 13px;
}

.login-note {
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.login-footer {
  position: relative;
  z-index: 1;
  margin: 22px 0 0;
  color: rgba(138, 168, 192, 0.72);
  font-size: 11px;
  letter-spacing: 0.03em;
}

/* ---------- Chat shell ---------- */

.chat-screen {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  background: linear-gradient(180deg, var(--chat-overlay-1), var(--chat-overlay-2));
}

.chat-photo {
  position: absolute;
  inset: -12px;
  z-index: 0;
  background-position: center;
  background-size: cover;
  opacity: 0;
  filter: blur(var(--bg-photo-blur));
  pointer-events: none;
  transform: scale(1.04);
  transition: opacity 260ms ease;
}

.chat-screen.has-photo .chat-photo {
  opacity: var(--bg-photo-opacity);
}

.topbar {
  z-index: 5;
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
}

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

.avatar-wrap {
  position: relative;
  flex: 0 0 auto;
}

.avatar {
  display: block;
  width: 42px;
  height: 42px;
  background: #0f2a44;
  border: 1px solid rgba(125, 211, 252, 0.22);
  border-radius: 15px;
  object-fit: cover;
}

.avatar-wrap .online-dot {
  right: -1px;
  bottom: -1px;
  width: 11px;
  height: 11px;
  border-width: 2px;
}

.identity-text {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 2px;
}

.identity-text strong {
  overflow: hidden;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: 0.01em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#status-text {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.02em;
}

#status-text.offline {
  color: #fda4af;
}

body.owner-mode #status-text::after {
  color: var(--cyan);
  content: " · 主人模式";
}

.topbar-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 7px;
}

.ghost-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted-strong);
  background: var(--button-bg);
  border: 1px solid var(--line);
  transition: background 150ms ease, color 150ms ease, transform 120ms ease;
}

.ghost-button {
  height: 34px;
  gap: 5px;
  padding: 0 10px;
  font-size: 12px;
  border-radius: 11px;
}

.icon-button {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 11px;
}

.ghost-button svg,
.icon-button svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.ghost-button:hover,
.icon-button:hover {
  color: var(--text);
  background: var(--button-hover);
}

.ghost-button:active,
.icon-button:active {
  transform: scale(0.96);
}

#theme-button svg {
  width: 17px;
  height: 17px;
}

#theme-button svg circle {
  fill: currentColor;
  stroke: none;
}

.palette-glyph {
  display: block;
  font-size: 17px;
  line-height: 1;
  filter: saturate(0.9);
  transform: translateY(0.5px);
}

/* ---------- Messages ---------- */

.messages {
  position: relative;
  z-index: 1;
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
  padding: 18px 14px 10px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(125, 211, 252, 0.24) transparent;
  -webkit-overflow-scrolling: touch;
}

.messages::-webkit-scrollbar {
  width: 5px;
}

.messages::-webkit-scrollbar-thumb {
  background: rgba(125, 211, 252, 0.22);
  border-radius: 999px;
}

.welcome {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 360px;
  padding: 20px 10px 34px;
  text-align: center;
  animation: fade-in 420ms ease both;
}

.welcome-orbit {
  display: grid;
  width: 112px;
  height: 112px;
  margin-bottom: 20px;
  place-items: center;
  background:
    radial-gradient(circle at 50% 48%, rgba(125, 211, 252, 0.14), transparent 62%),
    rgba(9, 28, 47, 0.72);
  border: 1px solid rgba(125, 211, 252, 0.2);
  border-radius: 36px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.28);
  animation: float 5s ease-in-out infinite;
}

.welcome-avatar {
  width: 92px;
  height: 92px;
  border-radius: 30px;
  object-fit: cover;
}

.welcome h2 {
  margin: 0;
  font-size: 21px;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.welcome p {
  max-width: 300px;
  margin: 10px 0 20px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.75;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: 340px;
}

.suggestion {
  padding: 9px 13px;
  color: var(--suggestion-text);
  font-size: 12px;
  background: var(--button-bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  transition: background 150ms ease, border-color 150ms ease, transform 120ms ease;
}

.suggestion:hover {
  background: var(--button-hover);
  border-color: var(--line-strong);
}

.suggestion:active {
  transform: scale(0.97);
}

.message {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  width: 100%;
  margin-top: 10px;
  animation: message-in 240ms cubic-bezier(0.22, 0.8, 0.3, 1) both;
}

.message.bot {
  justify-content: flex-start;
}

.message.user {
  flex-direction: row-reverse;
  justify-content: flex-start;
}

.message-avatar {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  margin-bottom: 3px;
  border: 1px solid rgba(125, 211, 252, 0.16);
  border-radius: 10px;
  object-fit: cover;
}

.bubble {
  position: relative;
  max-width: min(82%, 600px);
  padding: 10px 13px;
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.message.bot .bubble {
  background: linear-gradient(145deg, var(--bot-bubble-1), var(--bot-bubble-2));
  border: 1px solid var(--bot-bubble-border);
  border-radius: 18px 18px 18px 6px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
}

.message.user .bubble {
  color: var(--user-bubble-text);
  background: linear-gradient(145deg, var(--user-bubble-1), var(--user-bubble-2));
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 18px 18px 6px 18px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.2);
}

.bubble p {
  margin: 0;
}

.bubble p + p {
  margin-top: 8px;
}

.bubble pre {
  max-width: 100%;
  margin: 8px 0 2px;
  padding: 10px 11px;
  overflow-x: auto;
  color: #c6e6ff;
  font-size: 12px;
  line-height: 1.55;
  background: rgba(3, 12, 21, 0.72);
  border: 1px solid rgba(125, 211, 252, 0.12);
  border-radius: 10px;
  -webkit-overflow-scrolling: touch;
}

.bubble code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.bubble :not(pre) > code {
  padding: 1px 5px;
  color: #b8e6ff;
  background: rgba(125, 211, 252, 0.1);
  border-radius: 5px;
}

.bubble.pending {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-width: 48px;
  min-height: 36px;
}

.typing-dot {
  width: 5px;
  height: 5px;
  background: var(--cyan);
  border-radius: 50%;
  opacity: 0.45;
  animation: typing 1.15s infinite ease-in-out;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.14s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.28s;
}

.message-time {
  flex: 0 0 auto;
  align-self: flex-end;
  padding-bottom: 2px;
  color: rgba(138, 168, 192, 0.52);
  font-size: 9px;
  white-space: nowrap;
}

.bubble-image {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: 320px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  object-fit: contain;
  background: rgba(3, 12, 21, 0.35);
}

.bubble-image + .bubble-content:not(.hidden) {
  margin-top: 8px;
}

.bubble-image.image-missing {
  width: 180px;
  height: 120px;
  padding: 12px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  background: rgba(3, 12, 21, 0.5);
}

/* ---------- Composer ---------- */

.composer {
  z-index: 4;
  flex: 0 0 auto;
  padding: 8px 12px calc(8px + var(--safe-bottom));
  background: linear-gradient(180deg, transparent, var(--composer-fade) 22%);
}

.image-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 420px;
  margin: 0 0 8px;
  padding: 8px;
  background: rgba(11, 29, 47, 0.92);
  border: 1px solid rgba(125, 211, 252, 0.18);
  border-radius: 15px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.18);
}

.image-preview img {
  flex: 0 0 auto;
  width: 68px;
  height: 68px;
  border-radius: 10px;
  object-fit: cover;
  background: rgba(3, 12, 21, 0.6);
}

.image-preview-info {
  display: flex;
  min-width: 0;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 6px;
}

#image-preview-status {
  overflow: hidden;
  color: var(--muted-strong);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-remove {
  align-self: flex-start;
  padding: 3px 9px;
  color: #fecdd3;
  font-size: 11px;
  background: rgba(251, 113, 133, 0.1);
  border: 1px solid rgba(251, 113, 133, 0.24);
  border-radius: 999px;
}

.image-remove:hover {
  background: rgba(251, 113, 133, 0.18);
}

.attach-button {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  margin-bottom: 2px;
  border-radius: 50%;
}

.attach-button svg {
  width: 18px;
  height: 18px;
}

.attach-button:disabled {
  cursor: default;
  opacity: 0.45;
}

.composer-box {
  display: flex;
  align-items: flex-end;
  gap: 7px;
  padding: 5px 5px 5px 8px;
  background: var(--composer-box-bg);
  border: 1px solid var(--line);
  border-radius: 23px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.composer-box:focus-within {
  border-color: var(--cyan);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.24), 0 0 0 3px var(--button-bg);
}

#message-input {
  flex: 1 1 auto;
  width: 100%;
  min-height: 38px;
  max-height: 128px;
  padding: 9px 4px 8px 6px;
  overflow-y: auto;
  color: var(--text);
  font-size: 16px;
  line-height: 1.42;
  resize: none;
  background: transparent;
  border: 0;
  outline: none;
  scrollbar-width: none;
}

#message-input::-webkit-scrollbar {
  display: none;
}

#message-input::placeholder {
  color: #65839b;
}

.send-button {
  display: grid;
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  padding: 0;
  place-items: center;
  color: var(--send-text);
  background: linear-gradient(135deg, var(--send-from), var(--send-to));
  border: 0;
  border-radius: 50%;
  box-shadow: 0 7px 18px rgba(0, 0, 0, 0.22);
  transition: transform 120ms ease, filter 150ms ease;
}

.send-button:active {
  transform: scale(0.94);
}

.send-button:disabled {
  cursor: default;
  filter: saturate(0.35) brightness(0.72);
  box-shadow: none;
}

.send-button svg {
  width: 19px;
  height: 19px;
  fill: currentColor;
}

.send-button .stop-icon {
  display: none;
}

.send-button.is-stop .send-icon {
  display: none;
}

.send-button.is-stop .stop-icon {
  display: block;
}

.composer-hint {
  margin: 5px 0 0;
  color: rgba(138, 168, 192, 0.42);
  font-size: 9px;
  text-align: center;
}

.chat-error {
  margin: 7px 14px 0;
  color: #fecdd3;
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
}

/* ---------- Motion ---------- */

@keyframes message-in {
  from {
    opacity: 0;
    transform: translateY(7px) scale(0.99);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes float {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-6px);
  }
}

@keyframes typing {
  0%,
  80%,
  100% {
    opacity: 0.28;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

@media (max-width: 370px) {
  .ghost-button span {
    display: none;
  }

  .ghost-button {
    width: 34px;
    padding: 0;
  }

  .bubble {
    max-width: 86%;
    font-size: 14px;
  }

  .login-card {
    padding-right: 18px;
    padding-left: 18px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------------------------------------------------------------- status */
.status-modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 14px;
  background: rgba(2, 9, 17, 0.68);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.status-sheet {
  width: min(100%, 460px);
  max-height: min(84vh, 760px);
  padding: 20px;
  overflow: auto;
  background:
    radial-gradient(circle at 100% 0, var(--sheet-glow), transparent 34%),
    linear-gradient(160deg, var(--sheet-1), var(--sheet-2));
  border: 1px solid var(--line-strong);
  border-radius: 26px 26px 18px 18px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.55);
  overscroll-behavior: contain;
}

.status-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.status-head h2 {
  margin: 2px 0 0;
  font-size: 24px;
  letter-spacing: 0.02em;
}

.status-head .eyebrow {
  margin: 0;
}

.status-head-actions {
  display: flex;
  gap: 8px;
}

.status-body {
  display: grid;
  gap: 14px;
}

.status-loading,
.status-error {
  padding: 28px 10px;
  color: var(--muted);
  text-align: center;
}

.status-error {
  color: var(--danger);
}

.status-section {
  padding: 14px;
  background: rgba(8, 24, 40, 0.64);
  border: 1px solid var(--line);
  border-radius: 16px;
}

.status-section h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  color: var(--muted-strong);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.status-metric {
  min-width: 0;
  padding: 10px;
  background: var(--metric-bg);
  border-radius: 12px;
}

.status-metric .label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
}

.status-metric .value {
  display: block;
  overflow-wrap: anywhere;
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
  line-height: 1.3;
}

.status-metric .subvalue {
  display: block;
  margin-top: 2px;
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

.status-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0;
  color: var(--muted-strong);
  font-size: 13px;
}

.status-line strong {
  color: var(--text);
  font-weight: 600;
  text-align: right;
}

.budget-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  color: var(--muted-strong);
  font-size: 13px;
}

.budget-row > span {
  flex: 0 0 auto;
}

.budget-input {
  width: 116px;
  min-width: 0;
  padding: 8px 10px;
  color: var(--text);
  background: var(--metric-bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  text-align: right;
}

.budget-input:focus {
  border-color: var(--accent);
  outline: 2px solid color-mix(in srgb, var(--accent) 26%, transparent);
  outline-offset: 1px;
}

.budget-check {
  justify-content: flex-start;
  gap: 8px;
  cursor: pointer;
}

.budget-check input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}

.budget-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.budget-button {
  flex: 1 1 132px;
  padding: 9px 12px;
  color: var(--text);
  background: var(--metric-bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.budget-button.primary {
  color: var(--accent-contrast, #04111d);
  background: var(--accent);
  border-color: var(--accent);
}

.budget-button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.budget-status {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}

.budget-status.budget-error {
  color: var(--danger);
}

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 6px;
  background: #34d399;
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.1);
  vertical-align: 1px;
}

.status-dot.off {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(251, 113, 133, 0.1);
}

.status-bar {
  height: 7px;
  margin-top: 9px;
  overflow: hidden;
  background: rgba(125, 211, 252, 0.1);
  border-radius: 999px;
}

.status-bar > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #38bdf8, #818cf8);
  border-radius: inherit;
  transition: width 0.35s ease;
}

.status-updated {
  margin: 14px 2px 0;
  color: var(--muted);
  font-size: 11px;
  text-align: right;
}

/* ---------------------------------------------------------------- whale */
.whale-widget {
  position: fixed;
  right: 16px;
  bottom: calc(104px + var(--safe-bottom));
  z-index: 40;
  display: grid;
  width: 62px;
  height: 62px;
  padding: 0;
  overflow: visible;
  background:
    radial-gradient(circle at 32% 22%, rgba(255, 255, 255, 0.32), transparent 42%),
    linear-gradient(150deg, var(--whale-1), var(--whale-2));
  border: 1px solid rgba(125, 211, 252, 0.34);
  border-radius: 22px;
  box-shadow:
    0 12px 32px rgba(2, 16, 33, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.16);
  place-items: center;
  touch-action: manipulation;
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}

.whale-widget:hover {
  transform: translateY(-2px);
  box-shadow:
    0 16px 38px rgba(2, 16, 33, 0.52),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.whale-widget:active,
.whale-widget.petting {
  transform: scale(0.9) rotate(-5deg);
}

.whale-emoji {
  display: block;
  font-size: 36px;
  line-height: 1;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.24));
  transition: transform 0.16s ease;
}

.whale-widget.petting .whale-emoji {
  animation: whale-wiggle 0.52s ease;
}

.whale-bubble {
  position: absolute;
  right: 4px;
  bottom: 72px;
  width: max-content;
  max-width: min(190px, calc(100vw - 40px));
  padding: 8px 11px;
  color: #062033;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.45;
  text-align: left;
  pointer-events: none;
  background: #e5f7ff;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 13px 13px 4px 13px;
  box-shadow: 0 10px 28px rgba(2, 16, 33, 0.32);
  opacity: 0;
  transform: translateY(6px) scale(0.96);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.whale-bubble.show {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.whale-heart {
  position: fixed;
  z-index: 41;
  color: #f9a8d4;
  font-size: 15px;
  pointer-events: none;
  animation: heart-float 0.9s ease-out forwards;
}

/* ---------- Theme panel ---------- */

.theme-modal {
  position: fixed;
  inset: 0;
  z-index: 95;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 14px;
  background: rgba(2, 9, 17, 0.68);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.theme-sheet {
  width: min(100%, 460px);
  max-height: min(88vh, 820px);
  padding: 20px;
  overflow: auto;
  background:
    radial-gradient(circle at 100% 0, var(--sheet-glow), transparent 34%),
    linear-gradient(160deg, var(--sheet-1), var(--sheet-2));
  border: 1px solid var(--line-strong);
  border-radius: 26px 26px 18px 18px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.55);
  overscroll-behavior: contain;
}

.theme-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.theme-head h2 {
  margin: 4px 0 0;
  color: var(--text);
  font-size: 24px;
}

.theme-head-actions {
  display: flex;
  gap: 6px;
}

.theme-body {
  display: grid;
  gap: 12px;
}

.theme-block {
  padding: 12px;
  background: var(--metric-bg);
  border: 1px solid var(--line);
  border-radius: 16px;
}

.theme-block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.theme-block h3 {
  margin: 0;
  color: var(--text);
  font-size: 13px;
}

.theme-block-head > span,
.theme-note {
  color: var(--muted);
  font-size: 11px;
}

.theme-presets {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 7px;
}

.theme-preset {
  display: grid;
  gap: 5px;
  min-width: 0;
  padding: 5px;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 11px;
  transition: border-color 150ms ease, background 150ms ease, transform 120ms ease;
}

.theme-preset:hover {
  background: var(--button-hover);
}

.theme-preset:active {
  transform: scale(0.96);
}

.theme-preset.selected {
  color: var(--text);
  background: var(--button-bg);
  border-color: var(--cyan);
  box-shadow: 0 0 0 2px var(--button-bg);
}

.theme-swatch {
  display: block;
  width: 100%;
  height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
}

.theme-preset-name {
  display: block;
  overflow: hidden;
  font-size: 10px;
  line-height: 1.2;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.accent-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.accent-row input[type="color"] {
  width: 42px;
  height: 34px;
  padding: 2px;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  cursor: pointer;
}

#accent-value {
  color: var(--muted-strong);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.background-row {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 10px;
}

.theme-button,
.theme-mini-button,
.theme-reset {
  color: var(--text);
  background: var(--button-bg);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  transition: background 150ms ease, border-color 150ms ease;
}

.theme-button {
  padding: 7px 11px;
  font-size: 12px;
}

.theme-button:hover {
  background: var(--button-hover);
  border-color: var(--cyan);
}

.theme-mini-button {
  padding: 4px 7px;
  color: var(--cyan);
  font-size: 11px;
}

.theme-mini-button:hover {
  background: var(--button-hover);
}

.theme-mini-button:disabled,
.theme-button:disabled {
  cursor: default;
  opacity: 0.4;
}

.theme-note {
  flex: 1 1 auto;
  min-width: 0;
  line-height: 1.4;
}

.theme-range {
  display: grid;
  gap: 6px;
  margin-top: 10px;
  color: var(--muted-strong);
  font-size: 11px;
}

.theme-range > span {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.theme-range b {
  color: var(--cyan);
  font-variant-numeric: tabular-nums;
}

.theme-range input[type="range"] {
  width: 100%;
  accent-color: var(--cyan);
}

.theme-range input[type="range"]:disabled {
  opacity: 0.35;
}

.theme-reset {
  width: 100%;
  padding: 9px;
  color: var(--muted-strong);
  font-size: 12px;
}

.theme-reset:hover {
  color: var(--text);
  background: var(--button-hover);
}

@media (max-width: 380px) {
  .theme-presets {
    gap: 5px;
  }

  .theme-swatch {
    height: 30px;
  }

  .theme-preset-name {
    font-size: 9px;
  }
}

@keyframes whale-wiggle {
  0% { transform: rotate(0) scale(1); }
  25% { transform: rotate(-12deg) scale(1.15); }
  55% { transform: rotate(9deg) scale(1.1); }
  80% { transform: rotate(-4deg) scale(1.04); }
  100% { transform: rotate(0) scale(1); }
}

@keyframes heart-float {
  0% { opacity: 0.95; transform: translate(0, 0) scale(0.8); }
  100% { opacity: 0; transform: translate(var(--dx), -48px) scale(1.15); }
}

@media (max-width: 370px) {
  .status-sheet {
    padding: 16px;
  }

  .status-grid {
    grid-template-columns: 1fr;
  }

  .whale-widget {
    right: 12px;
    bottom: calc(98px + var(--safe-bottom));
    width: 56px;
    height: 56px;
  }

  .whale-emoji {
    font-size: 32px;
  }
}

/* ---------------------------------------------------------------- relock + unlock */
.theme-relock {
  margin-top: 8px;
  color: #fcd34d;
  border-color: rgba(252, 211, 77, 0.28);
}

.theme-relock:hover {
  color: #fde68a;
  background: rgba(252, 211, 77, 0.08);
  border-color: rgba(252, 211, 77, 0.45);
}

.theme-relock-note {
  margin: 8px 2px 0;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.55;
  text-align: center;
}

.unlock-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px;
  background: rgba(2, 9, 17, 0.74);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.unlock-card {
  width: min(100%, 370px);
  padding: 26px 22px 20px;
  text-align: center;
  background:
    radial-gradient(circle at 50% 0, rgba(125, 211, 252, 0.18), transparent 42%),
    linear-gradient(160deg, var(--sheet-1), var(--sheet-2));
  border: 1px solid var(--line-strong);
  border-radius: 24px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.58);
  animation: unlock-in 0.28s ease both;
}

.unlock-badge {
  display: grid;
  width: 64px;
  height: 64px;
  margin: 0 auto 14px;
  font-size: 36px;
  background: linear-gradient(150deg, rgba(125, 211, 252, 0.18), rgba(129, 140, 248, 0.2));
  border: 1px solid rgba(125, 211, 252, 0.25);
  border-radius: 20px;
  place-items: center;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.unlock-card .eyebrow {
  margin: 0;
}

.unlock-card h2 {
  margin: 5px 0 10px;
  color: var(--text);
  font-size: 24px;
  letter-spacing: 0.02em;
}

.unlock-copy {
  margin: 0;
  color: var(--muted-strong);
  font-size: 13px;
  line-height: 1.7;
}

.unlock-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.unlock-secondary,
.unlock-primary {
  flex: 1;
  padding: 11px 12px;
  font-size: 13px;
  border-radius: 12px;
  transition: transform 120ms ease, filter 150ms ease, background 150ms ease;
}

.unlock-secondary {
  color: var(--muted-strong);
  background: var(--button-bg);
  border: 1px solid var(--line-strong);
}

.unlock-primary {
  color: var(--send-text);
  background: linear-gradient(135deg, var(--send-from), var(--send-to));
  border: 1px solid rgba(255, 255, 255, 0.16);
  font-weight: 700;
}

.unlock-secondary:hover,
.unlock-primary:hover {
  filter: brightness(1.08);
}

.unlock-secondary:active,
.unlock-primary:active {
  transform: scale(0.97);
}

@keyframes unlock-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}
