:root {
  color-scheme: dark;
  --bg: #050a12;
  --bg-elevated: #0a1420;
  --card: rgba(8, 18, 30, 0.78);
  --text: #e8f1fa;
  --muted: #7f93a8;
  --primary: #14b8a6;
  --primary-hover: #2dd4bf;
  --accent: #22d3ee;
  --accent-2: #38bdf8;
  --border: rgba(56, 189, 248, 0.22);
  --user-bg: rgba(20, 184, 166, 0.16);
  --bot-bg: rgba(6, 14, 24, 0.82);
  --sidebar-w: 272px;
  --glow: rgba(34, 211, 238, 0.28);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --font-display: "Orbitron", "IBM Plex Sans", sans-serif;
  --font-ui: "IBM Plex Sans", "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body {
  height: 100%;
  margin: 0;
}
body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
body:has(#app:not(.hidden)) {
  overflow: hidden;
  height: 100%;
  min-height: 0;
}

.fx-grid,
.fx-vignette {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 0;
}
.fx-grid {
  background-image:
    linear-gradient(rgba(34, 211, 238, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(34, 211, 238, 0.045) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse 70% 60% at 50% 40%, #000 20%, transparent 75%);
  opacity: 0.7;
}
.fx-vignette {
  background:
    radial-gradient(900px 520px at 72% 12%, rgba(20, 184, 166, 0.14), transparent 58%),
    radial-gradient(700px 480px at 18% 88%, rgba(56, 189, 248, 0.1), transparent 55%),
    radial-gradient(ellipse at center, transparent 45%, rgba(0, 0, 0, 0.55) 100%);
}

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

/* —— Login —— */
.login-screen {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(24px + var(--safe-top)) 24px calc(24px + var(--safe-bottom));
}
.login-card {
  width: min(400px, 100%);
  background: linear-gradient(180deg, rgba(12, 24, 38, 0.95), rgba(6, 12, 20, 0.96));
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  box-shadow:
    0 0 0 1px rgba(34, 211, 238, 0.06),
    0 20px 60px rgba(0, 0, 0, 0.45),
    0 0 40px rgba(34, 211, 238, 0.08);
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.login-kicker {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  color: var(--accent);
}
.login-card h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 32px;
  letter-spacing: 0.08em;
  text-shadow: 0 0 28px var(--glow);
}
.login-card input {
  width: 100%;
  margin: 16px 0 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 16px;
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  outline: none;
}
.login-card input:focus {
  border-color: rgba(34, 211, 238, 0.55);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.12);
}
.login-card button,
.composer button,
.header-actions button,
.history-head button {
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
}
.login-card button {
  width: 100%;
  background: linear-gradient(135deg, #0f766e, #0284c7);
  color: #fff;
  font-weight: 600;
  letter-spacing: 0.04em;
  box-shadow: 0 0 24px rgba(20, 184, 166, 0.3);
}
.login-card button:hover { filter: brightness(1.08); }

/* —— App shell —— */
.app {
  position: relative;
  z-index: 1;
  max-width: 1180px;
  margin: 0 auto;
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  overflow: hidden;
  display: flex;
  gap: 0;
  padding: 0;
}

.history-panel {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: rgba(5, 12, 20, 0.92);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  backdrop-filter: blur(14px);
}
.history-head {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 12px 10px;
  padding-top: calc(14px + var(--safe-top));
  border-bottom: 1px solid var(--border);
}
.history-head h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-family: var(--font-mono);
  color: var(--accent);
}
.history-head-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.history-backdrop { display: none; }
.history-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px;
  -webkit-overflow-scrolling: touch;
}
.history-item {
  display: flex;
  align-items: stretch;
  gap: 4px;
  border: 1px solid transparent;
  border-radius: 10px;
  margin-bottom: 4px;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.history-item:hover { background: rgba(255, 255, 255, 0.04); }
.history-item.active {
  background: rgba(20, 184, 166, 0.14);
  border-color: rgba(45, 212, 191, 0.35);
  box-shadow: 0 0 16px rgba(34, 211, 238, 0.08);
  border-left: 3px solid rgba(34, 211, 238, 0.85);
}
.history-open {
  flex: 1;
  min-width: 0;
  text-align: left;
  border: none;
  background: transparent;
  border-radius: 10px;
  padding: 12px 10px;
  cursor: pointer;
  font: inherit;
  color: inherit;
}
.history-delete {
  flex-shrink: 0;
  width: 36px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  border-radius: 8px;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}
.history-item:hover .history-delete,
.history-item:focus-within .history-delete {
  opacity: 1;
}
.history-delete:hover {
  background: rgba(180, 35, 24, 0.25);
  color: #fda29b;
}
.history-item .preview {
  font-size: 13px;
  font-weight: 500;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.history-item .meta {
  margin-top: 4px;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--muted);
}
.history-empty {
  padding: 16px 10px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}
.load-more {
  flex-shrink: 0;
  margin: 4px 8px calc(12px + var(--safe-bottom));
  width: calc(100% - 16px);
}

.chat-pane {
  flex: 1;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 16px;
  padding-top: calc(12px + var(--safe-top));
  padding-bottom: calc(12px + var(--safe-bottom));
  padding-left: calc(16px + var(--safe-left));
  padding-right: calc(16px + var(--safe-right));
}

.header {
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  position: relative;
  z-index: 2;
}
.header-main {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.brand-block { min-width: 0; }
.brand-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.header h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 22px;
  letter-spacing: 0.12em;
  text-shadow: 0 0 24px var(--glow);
  animation: brandPulse 4.5s ease-in-out infinite;
}
@keyframes brandPulse {
  0%, 100% { text-shadow: 0 0 18px rgba(34, 211, 238, 0.22); }
  50% { text-shadow: 0 0 32px rgba(34, 211, 238, 0.45), 0 0 48px rgba(20, 184, 166, 0.2); }
}
.header-sub { margin-top: 2px; }
.header-actions { display: flex; gap: 8px; flex-shrink: 0; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid rgba(34, 211, 238, 0.35);
  background: rgba(34, 211, 238, 0.08);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--accent);
}
.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #64748b;
  box-shadow: 0 0 0 0 rgba(34, 211, 238, 0.4);
}
.status-dot.live {
  background: #2dd4bf;
  animation: livePulse 1.8s ease-out infinite;
}
@keyframes livePulse {
  0% { box-shadow: 0 0 0 0 rgba(45, 212, 191, 0.55); }
  70% { box-shadow: 0 0 0 8px rgba(45, 212, 191, 0); }
  100% { box-shadow: 0 0 0 0 rgba(45, 212, 191, 0); }
}

.ghost {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border) !important;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.ghost:hover {
  border-color: rgba(34, 211, 238, 0.45) !important;
  box-shadow: 0 0 16px rgba(34, 211, 238, 0.12);
}
.ghost.small {
  padding: 6px 10px;
  font-size: 13px;
}
.icon-btn {
  width: 40px;
  height: 40px;
  padding: 0 !important;
  display: inline-grid;
  place-items: center;
  font-size: 18px;
  flex-shrink: 0;
}

/* —— Stage / blob —— */
.chat-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: 18px;
  overflow: hidden;
  --ptr-x: 50%;
  --ptr-y: 42%;
  --ptr-nx: 0;
  --ptr-ny: 0;
  background:
    radial-gradient(ellipse 40% 36% at var(--ptr-x) var(--ptr-y), rgba(34, 211, 238, 0.16), transparent 70%),
    radial-gradient(ellipse 55% 48% at 50% 42%, rgba(34, 211, 238, 0.12), transparent 68%),
    radial-gradient(ellipse 80% 70% at 50% 100%, rgba(8, 47, 73, 0.35), transparent 55%),
    rgba(3, 8, 14, 0.72);
  box-shadow:
    inset 0 0 80px rgba(34, 211, 238, 0.05),
    0 0 0 1px rgba(34, 211, 238, 0.04),
    0 12px 40px rgba(0, 0, 0, 0.25);
  transition: box-shadow 0.25s ease;
}
.chat-stage.pointer-near {
  box-shadow:
    inset 0 0 90px rgba(34, 211, 238, 0.08),
    0 0 0 1px rgba(34, 211, 238, 0.12),
    0 0 36px rgba(34, 211, 238, 0.12);
}
.chat-stage.thinking {
  box-shadow:
    inset 0 0 100px rgba(34, 211, 238, 0.1),
    0 0 28px rgba(34, 211, 238, 0.18);
}
.chat-stage::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 3px,
    rgba(34, 211, 238, 0.015) 3px,
    rgba(34, 211, 238, 0.015) 4px
  );
  opacity: 0.55;
}
.stage-frame {
  position: absolute;
  inset: 10px;
  z-index: 2;
  pointer-events: none;
  transform: translate3d(calc(var(--ptr-nx, 0) * 4px), calc(var(--ptr-ny, 0) * -3px), 0);
  transition: transform 0.14s ease-out;
}
.stage-frame .corner {
  position: absolute;
  width: 16px;
  height: 16px;
  border: 1.5px solid rgba(34, 211, 238, 0.55);
  opacity: 0.7;
}
.stage-frame .tl { top: 0; left: 0; border-right: 0; border-bottom: 0; }
.stage-frame .tr { top: 0; right: 0; border-left: 0; border-bottom: 0; }
.stage-frame .bl { bottom: 0; left: 0; border-right: 0; border-top: 0; }
.stage-frame .br { bottom: 0; right: 0; border-left: 0; border-top: 0; }
.stage-frame .corner {
  box-shadow: 0 0 10px rgba(34, 211, 238, 0.35);
}
.stage-frame .tl::after,
.stage-frame .tr::after,
.stage-frame .bl::after,
.stage-frame .br::after {
  content: "";
  position: absolute;
  background: rgba(34, 211, 238, 0.55);
}
.stage-frame .tl::after { left: 0; top: 14px; width: 2px; height: 8px; }
.stage-frame .tr::after { right: 0; top: 14px; width: 2px; height: 8px; }
.stage-frame .bl::after { left: 0; bottom: 14px; width: 2px; height: 8px; }
.stage-frame .br::after { right: 0; bottom: 14px; width: 2px; height: 8px; }

.stage-hex {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.12;
  background-image:
    linear-gradient(30deg, rgba(34, 211, 238, 0.15) 1px, transparent 1px),
    linear-gradient(150deg, rgba(34, 211, 238, 0.12) 1px, transparent 1px),
    linear-gradient(90deg, rgba(56, 189, 248, 0.08) 1px, transparent 1px);
  background-size: 28px 48px, 28px 48px, 14px 14px;
  mask-image: radial-gradient(ellipse 70% 60% at 50% 42%, #000 10%, transparent 72%);
}

.hud-telemetry {
  position: absolute;
  top: 12px;
  left: 18px;
  right: 18px;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  pointer-events: none;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  color: rgba(125, 240, 255, 0.75);
  text-shadow: 0 0 12px rgba(34, 211, 238, 0.35);
  transform: translate3d(calc(var(--ptr-nx, 0) * 6px), calc(var(--ptr-ny, 0) * -4px), 0);
  transition: transform 0.12s ease-out;
}
.hud-telemetry b {
  color: #e0f7ff;
  font-weight: 500;
}
.hud-metrics {
  display: flex;
  gap: 12px;
  opacity: 0.85;
}
.hud-ticks {
  position: absolute;
  top: 18%;
  bottom: 18%;
  z-index: 2;
  width: 10px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  pointer-events: none;
}
.hud-ticks.left {
  left: 10px;
  transform: translate3d(calc(var(--ptr-nx, 0) * 3px), calc(var(--ptr-ny, 0) * 8px), 0);
}
.hud-ticks.right {
  right: 10px;
  align-items: flex-end;
  transform: translate3d(calc(var(--ptr-nx, 0) * -3px), calc(var(--ptr-ny, 0) * 8px), 0);
}
.hud-ticks span {
  display: block;
  height: 1px;
  width: 6px;
  background: rgba(34, 211, 238, 0.28);
  box-shadow: 0 0 6px rgba(34, 211, 238, 0.2);
}
.hud-ticks span:nth-child(odd) { width: 9px; opacity: 0.9; }
.chat-stage.thinking .hud-ticks span {
  animation: tickFlow 1.1s linear infinite;
  animation-delay: calc(var(--i, 0) * 0.06s);
}
@keyframes tickFlow {
  0%, 100% { background: rgba(34, 211, 238, 0.25); }
  50% { background: rgba(125, 240, 255, 0.95); box-shadow: 0 0 10px rgba(34, 211, 238, 0.7); }
}

.scan-line {
  position: absolute;
  left: 8%;
  right: 8%;
  height: 2px;
  z-index: 2;
  pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(34, 211, 238, 0.55), transparent);
  box-shadow: 0 0 16px rgba(34, 211, 238, 0.45);
  animation: scanSweep 5.5s ease-in-out infinite;
  opacity: 0.55;
}
.chat-stage.thinking .scan-line {
  opacity: 0.95;
  animation-duration: 1.6s;
}
@keyframes scanSweep {
  0% { top: 12%; opacity: 0; }
  12% { opacity: 0.7; }
  50% { top: 78%; }
  88% { opacity: 0.7; }
  100% { top: 12%; opacity: 0; }
}

.hud-progress {
  position: absolute;
  left: 16%;
  right: 16%;
  bottom: 12px;
  height: 2px;
  z-index: 3;
  pointer-events: none;
  background: rgba(34, 211, 238, 0.08);
  border-radius: 2px;
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.chat-stage.thinking .hud-progress,
.chat-stage.speaking .hud-progress {
  opacity: 1;
}
.hud-progress span {
  display: block;
  height: 100%;
  width: 35%;
  background: linear-gradient(90deg, transparent, #22d3ee, transparent);
  animation: progressSlide 1.2s linear infinite;
}
@keyframes progressSlide {
  from { transform: translateX(-120%); }
  to { transform: translateX(320%); }
}

.particle-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  opacity: 0.85;
}

.chat-stage.booting .scan-line {
  animation: scanSweep 0.7s linear 1;
  opacity: 1;
}
.chat-stage.booting .blob-canvas {
  animation: bootBloom 0.85s ease-out 1;
}
.chat-stage.glitch {
  animation: stageGlitch 70ms steps(2) 1;
}
@keyframes bootBloom {
  from { opacity: 0.15; filter: drop-shadow(0 0 4px rgba(34, 211, 238, 0.1)); }
  to { opacity: 0.98; filter: drop-shadow(0 0 28px rgba(34, 211, 238, 0.35)); }
}
@keyframes stageGlitch {
  0% { filter: none; transform: none; }
  40% { filter: hue-rotate(20deg) brightness(1.15); transform: translateX(1px); }
  100% { filter: none; transform: none; }
}

.status-pill[data-mode="thinking"] {
  border-color: rgba(251, 191, 36, 0.45);
  color: #fbbf24;
  box-shadow: 0 0 16px rgba(251, 191, 36, 0.2);
}
.status-pill[data-mode="thinking"] .status-dot {
  background: #fbbf24;
}
.status-pill[data-mode="speaking"] {
  border-color: rgba(56, 189, 248, 0.55);
  color: #7dd3fc;
}
body[data-core-mode="thinking"] .header h1 {
  text-shadow: 0 0 36px rgba(251, 191, 36, 0.35), 0 0 48px rgba(34, 211, 238, 0.25);
}
body[data-core-mode="speaking"] .header h1 {
  text-shadow: 0 0 36px rgba(56, 189, 248, 0.45);
}

.blob-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  opacity: 0.98;
  transition: opacity 0.35s ease, transform 0.45s ease;
  filter: drop-shadow(0 0 28px rgba(34, 211, 238, 0.25));
}
.chat-stage.has-messages .blob-canvas {
  opacity: 0.38;
  transform: scale(0.82) translateY(-8%);
  filter: drop-shadow(0 0 16px rgba(34, 211, 238, 0.15));
}
.chat-stage.thinking .blob-canvas {
  opacity: 1;
  filter: drop-shadow(0 0 40px rgba(34, 211, 238, 0.45));
}

.blob-hint {
  position: absolute;
  left: 50%;
  bottom: 16%;
  transform: translateX(-50%);
  z-index: 1;
  text-align: center;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.blob-hint .hint-line {
  display: block;
  color: var(--text);
  font-size: 14px;
  letter-spacing: 0.18em;
  font-family: var(--font-mono);
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.7);
}
.blob-hint .hint-sub {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.06em;
}
.chat-stage.has-messages .blob-hint { opacity: 0; }

.messages {
  position: relative;
  z-index: 1;
  height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px;
  background: transparent;
  -webkit-overflow-scrolling: touch;
}
.messages:empty { pointer-events: none; }

.msg {
  margin-bottom: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  line-height: 1.55;
  font-size: 15px;
  backdrop-filter: blur(10px);
  max-width: min(720px, 100%);
  animation: msgIn 0.28s ease;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
.msg.user {
  background: var(--user-bg);
  border: 1px solid rgba(45, 212, 191, 0.4);
  margin-left: auto;
  box-shadow: 0 0 22px rgba(20, 184, 166, 0.12);
  border-radius: 12px 12px 4px 12px;
}
.msg.assistant {
  background: linear-gradient(135deg, rgba(6, 16, 28, 0.9), rgba(8, 20, 34, 0.78));
  border: 1px solid rgba(34, 211, 238, 0.28);
  border-left: 3px solid rgba(34, 211, 238, 0.75);
  box-shadow: 0 0 0 1px rgba(34, 211, 238, 0.06), 0 0 28px rgba(34, 211, 238, 0.08), 0 8px 24px rgba(0, 0, 0, 0.25);
  border-radius: 4px 12px 12px 12px;
}
.msg .role {
  font-size: 11px;
  color: var(--accent);
  margin-bottom: 6px;
  font-weight: 600;
  font-family: var(--font-mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.msg.user .role { color: var(--primary-hover); }
.msg.streaming .msg-body::after {
  content: "";
  display: inline-block;
  width: 0.55em;
  height: 1.05em;
  margin-left: 3px;
  vertical-align: text-bottom;
  background: var(--accent);
  box-shadow: 0 0 10px rgba(34, 211, 238, 0.7);
  animation: blink 0.9s step-end infinite;
}
@keyframes blink {
  50% { opacity: 0; }
}

.msg-text { white-space: pre-wrap; }
.msg-body.markdown { white-space: normal; word-break: break-word; }
.msg-body.markdown > :first-child { margin-top: 0; }
.msg-body.markdown > :last-child { margin-bottom: 0; }
.msg-body.markdown p { margin: 0.45em 0; }
.msg-body.markdown h1,
.msg-body.markdown h2,
.msg-body.markdown h3,
.msg-body.markdown h4 {
  margin: 0.75em 0 0.35em;
  line-height: 1.35;
  font-weight: 600;
}
.msg-body.markdown h1 { font-size: 1.25em; }
.msg-body.markdown h2 { font-size: 1.15em; }
.msg-body.markdown h3 { font-size: 1.05em; }
.msg-body.markdown ul,
.msg-body.markdown ol {
  margin: 0.45em 0;
  padding-left: 1.35em;
}
.msg-body.markdown li { margin: 0.2em 0; }
.msg-body.markdown blockquote {
  margin: 0.45em 0;
  padding: 0.2em 0 0.2em 12px;
  border-left: 3px solid rgba(45, 212, 191, 0.55);
  color: var(--muted);
}
.msg-body.markdown code {
  background: rgba(148, 163, 184, 0.16);
  padding: 0.12em 0.35em;
  border-radius: 4px;
  font-size: 0.9em;
  font-family: var(--font-mono);
}
.msg-body.markdown pre {
  margin: 0.55em 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: #061018;
  border: 1px solid rgba(34, 211, 238, 0.15);
  color: #e2e8f0;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.45;
}
.msg-body.markdown pre code {
  background: transparent;
  padding: 0;
  color: inherit;
  font-size: inherit;
}
.msg-body.markdown table {
  display: block;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  margin: 0.55em 0;
  font-size: 14px;
  -webkit-overflow-scrolling: touch;
}
.msg-body.markdown th,
.msg-body.markdown td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
  vertical-align: top;
}
.msg-body.markdown th {
  background: rgba(34, 211, 238, 0.06);
  font-weight: 600;
}
.msg-body.markdown a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.msg-body.markdown hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.75em 0;
}

.thinking-block {
  margin-bottom: 10px;
  border: 1px solid rgba(56, 189, 248, 0.32);
  border-radius: 8px;
  background: rgba(2, 10, 18, 0.72);
  overflow: hidden;
  box-shadow: inset 0 0 20px rgba(34, 211, 238, 0.04);
}
.thinking-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
  cursor: pointer;
  text-align: left;
  min-height: 40px;
}
.thinking-toggle:hover { color: var(--accent); }
.thinking-toggle .chevron {
  transition: transform 0.2s ease;
  opacity: 0.7;
}
.thinking-block.open .thinking-toggle .chevron {
  transform: rotate(180deg);
}
.thinking-body {
  display: none;
  padding: 0 12px 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  border-top: 1px solid rgba(56, 189, 248, 0.15);
  max-height: 200px;
  overflow-y: auto;
  font-family: var(--font-mono);
}
.thinking-block.open .thinking-body {
  display: block;
  padding-top: 8px;
}

.composer {
  flex-shrink: 0;
  margin-top: 12px;
  position: relative;
  z-index: 2;
}
.composer-main {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px 12px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(6, 12, 20, 0.88);
  box-shadow: 0 0 24px rgba(34, 211, 238, 0.06);
  backdrop-filter: blur(12px);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.composer-main:focus-within {
  border-color: rgba(34, 211, 238, 0.5);
  box-shadow: 0 0 0 1px rgba(34, 211, 238, 0.15), 0 0 28px rgba(34, 211, 238, 0.16);
}
.composer-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  color: rgba(125, 240, 255, 0.55);
}
.composer-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.composer-tools {
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
}
.composer textarea {
  flex: 1;
  resize: none;
  min-height: 44px;
  max-height: 120px;
  padding: 11px 12px;
  border: 1px solid transparent;
  border-radius: 12px;
  font: inherit;
  font-size: 16px;
  line-height: 1.4;
  background: rgba(0, 0, 0, 0.28);
  color: var(--text);
  outline: none;
}
.composer textarea:focus {
  border-color: rgba(34, 211, 238, 0.35);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.1);
}
.composer textarea::placeholder { color: #5f7388; }
.composer button#send-btn {
  background: linear-gradient(135deg, #0f766e, #0284c7);
  color: #fff;
  min-width: 72px;
  min-height: 44px;
  border: none;
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 0 22px rgba(20, 184, 166, 0.28);
  letter-spacing: 0.04em;
}
.composer button#send-btn:disabled { opacity: 0.55; cursor: not-allowed; }

.attachment-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px;
}
.attachment-item {
  position: relative;
  width: 64px;
  height: 64px;
}
.attachment-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.attachment-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: #b42318;
  color: #fff;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.msg-images {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.msg-images img {
  max-width: min(240px, 100%);
  max-height: 240px;
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: zoom-in;
  object-fit: contain;
  background: rgba(0, 0, 0, 0.25);
}

.muted { color: var(--muted); font-size: 13px; margin: 0; }
.error { color: #fda29b; font-size: 13px; margin-top: 8px; }

/* —— Mobile —— */
@media (max-width: 768px) {
  .mobile-only { display: inline-grid; }
  .history-delete { opacity: 1; }
  .fx-grid { background-size: 36px 36px; opacity: 0.45; }

  .history-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 19;
    background: rgba(0, 4, 10, 0.55);
    backdrop-filter: blur(2px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }
  .history-backdrop.visible {
    opacity: 1;
    pointer-events: auto;
  }
  .history-panel {
    position: fixed;
    left: 0;
    top: 0;
    width: min(86vw, 300px);
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    z-index: 20;
    box-shadow: 8px 0 40px rgba(0, 0, 0, 0.45), 0 0 30px rgba(34, 211, 238, 0.08);
    transform: translateX(-105%);
    transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
    border-right-color: rgba(34, 211, 238, 0.28);
  }
  .history-panel.open {
    transform: translateX(0);
    box-shadow: 8px 0 40px rgba(0, 0, 0, 0.45), 0 0 36px rgba(34, 211, 238, 0.14);
  }

  .app { max-width: 100%; }
  .chat-pane {
    padding: 8px;
    padding-top: calc(6px + var(--safe-top));
    padding-bottom: calc(6px + var(--safe-bottom));
  }
  .header {
    margin-bottom: 8px;
    gap: 8px;
    align-items: center;
  }
  .header h1 { font-size: 18px; letter-spacing: 0.1em; }
  .header-sub { display: none; }
  .header-actions .ghost {
    padding: 8px 10px;
    font-size: 12px;
    min-height: 36px;
  }
  .status-pill {
    font-size: 9px;
    padding: 2px 6px;
  }

  .chat-stage {
    border-radius: 14px;
    min-height: 0;
  }
  .stage-frame { inset: 8px; }
  .stage-frame .corner { width: 12px; height: 12px; }
  .hud-telemetry {
    top: 8px;
    left: 12px;
    right: 12px;
    font-size: 9px;
  }
  .hud-metrics .hud-net { display: none; }
  .hud-ticks { top: 22%; bottom: 22%; }
  .scan-line { opacity: 0.35; }
  .stage-hex { opacity: 0.08; }
  .particle-canvas { opacity: 0.65; }
  .blob-canvas {
    transform: scale(0.62) translateY(-4%);
    opacity: 0.92;
  }
  .chat-stage.has-messages .blob-canvas {
    opacity: 0.28;
    transform: scale(0.48) translateY(-10%);
  }
  .chat-stage.thinking .blob-canvas {
    opacity: 0.95;
    transform: scale(0.68) translateY(-4%);
  }
  .composer-label { font-size: 9px; }

  .messages { padding: 12px 10px 16px; }
  .msg {
    font-size: 14px;
    padding: 11px 12px;
    margin-bottom: 10px;
    max-width: 100%;
    border-radius: 14px;
  }
  .msg.user { border-radius: 14px 14px 4px 14px; }
  .msg.assistant { border-radius: 14px 14px 14px 4px; }

  .composer { margin-top: 8px; }
  .composer-main {
    padding: 8px;
    border-radius: 18px;
  }
  .composer textarea {
    min-height: 42px;
    max-height: 100px;
    font-size: 16px; /* iOS 防缩放 */
  }
  .composer button#send-btn {
    min-width: 64px;
    border-radius: 14px;
  }

  .msg-images img {
    max-width: min(200px, 72vw);
    max-height: 200px;
  }

  body.history-drawer-open {
    overflow: hidden;
  }
}

@media (max-width: 380px) {
  .header-actions #logout-btn { display: none; }
  .brand-row .status-pill { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .header h1,
  .status-dot.live,
  .scan-line,
  .hud-progress span,
  .hud-ticks span,
  .msg,
  .chat-stage.booting .blob-canvas,
  .chat-stage.glitch {
    animation: none !important;
  }
}
