:root {
  color-scheme: light;
  --bg0: #0b1220;
  --bg1: #0f1b34;
  --card: rgba(255, 255, 255, 0.92);
  --card-solid: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: rgba(15, 23, 42, 0.10);
  --shadow: 0 18px 48px rgba(15, 23, 42, 0.12);
  --shadow-soft: 0 10px 22px rgba(15, 23, 42, 0.08);
  --radius: 16px;
  --accent: #2b6cff;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(1200px 700px at 20% -10%, rgba(43,108,255,.35) 0%, rgba(43,108,255,0) 60%),
    radial-gradient(1000px 600px at 90% 10%, rgba(52,211,153,.28) 0%, rgba(52,211,153,0) 55%),
    linear-gradient(180deg, var(--bg0) 0%, var(--bg1) 60%, #0b1220 100%);
}

.wrap {
  max-width: 980px;
  margin: 0 auto;
  padding: 24px;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card {
  width: 100%;
  background: var(--card);
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  /* 桌面端固定窗口尺寸，不随消息数量无限撑高 */
  height: clamp(560px, 82dvh, 780px);
  max-height: calc(100dvh - 32px);
}

header {
  padding: 16px 18px;
  border-bottom: 1px solid rgba(15, 23, 42, 0.08);
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(180deg, rgba(255,255,255,0.65), rgba(255,255,255,0.42));
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

header .title {
  font-weight: 800;
  letter-spacing: .2px;
  font-size: 16px;
}

header .meta { color: var(--muted); font-size: 12px; }

#log {
  padding: 16px 18px;
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: rgba(255,255,255,0.55);
}

.time-divider {
  display: flex;
  justify-content: center;
  margin: 14px 0 8px;
}
.time-divider span {
  font-size: 11px;
  color: rgba(100,116,139,.92);
  background: rgba(255,255,255,.78);
  border: 1px solid rgba(15,23,42,.08);
  border-radius: 999px;
  padding: 3px 10px;
  letter-spacing: .1px;
  box-shadow: 0 4px 10px rgba(15,23,42,.05);
}

.msg {
  display: flex;
  gap: 10px;
  margin: 12px 0;
  align-items: flex-end;
  width: 100%;
  flex-direction: row;
}
.msg.user { justify-content: flex-end; }
.msg.agent { justify-content: flex-start; }

.bubble {
  max-width: 78%;
  padding: 10px 12px;
  border-radius: 16px;
  border: 1px solid rgba(15, 23, 42, 0.10);
  background: rgba(255,255,255,0.9);
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: var(--shadow-soft);
  line-height: 1.35;
  font-size: 14px;
  animation: popIn .18s ease-out;
}
.msg.user .bubble {
  background: linear-gradient(180deg, rgba(238,246,255,0.95), rgba(238,246,255,0.78));
  border-color: rgba(43,108,255,0.18);
  border-bottom-right-radius: 8px;
}
.msg.agent .bubble {
  background: linear-gradient(180deg, rgba(243,244,246,0.95), rgba(243,244,246,0.78));
  border-color: rgba(15,23,42,0.10);
  border-bottom-left-radius: 8px;
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  flex: 0 0 auto;
  position: relative;
  box-shadow: 0 10px 22px rgba(15,23,42,.18);
  overflow: hidden;
  background: #fff;
}
.avatar::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 999px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.35);
}
.avatar img { width: 100%; height: 100%; display: block; }

.file { display: inline-flex; gap: 10px; align-items: center; }
.thumb {
  width: 140px;
  height: 140px;
  border-radius: 12px;
  object-fit: cover;
  border: 1px solid rgba(15, 23, 42, 0.10);
  background: #fff;
}
.file a { color: var(--accent); text-decoration: none; font-weight: 700; }
.file small { color: var(--muted); display: block; margin-top: 4px; }

.bar {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border-top: 1px solid rgba(15, 23, 42, 0.08);
  background: linear-gradient(180deg, rgba(255,255,255,0.55), rgba(255,255,255,0.40));
  position: sticky;
  bottom: 0;
  z-index: 18;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

#text {
  flex: 1;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  outline: none;
  background: rgba(255,255,255,0.9);
  font-size: 16px; /* iOS 防止输入框自动放大 */
}
#text::placeholder { color: rgba(100,116,139,0.9); }
#text:focus { border-color: rgba(43,108,255,0.45); box-shadow: 0 0 0 4px rgba(43,108,255,0.12); }

button {
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid rgba(43,108,255,0.45);
  background: linear-gradient(180deg, rgba(43,108,255,1), rgba(27,90,235,1));
  color: white;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 10px 20px rgba(43,108,255,0.18);
}
button:disabled { opacity: .55; cursor: not-allowed; box-shadow: none; }

.hint {
  padding: 10px 14px calc(12px + env(safe-area-inset-bottom));
  color: rgba(100,116,139,0.95);
  font-size: 12px;
  background: rgba(255,255,255,0.35);
}

.jump-bottom {
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 35;
  border: 0;
  border-radius: 999px;
  background: rgba(15,23,42,.92);
  color: #fff;
  padding: 10px 12px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .1px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 12px 24px rgba(15,23,42,.28);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity .2s ease, transform .2s ease;
}
.jump-bottom.show {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}
.jump-count {
  min-width: 18px;
  height: 18px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  padding: 0 5px;
}
.jump-count[hidden] {
  display: none !important;
}

@keyframes popIn {
  from { opacity: 0; transform: translateY(4px) scale(.99); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 640px) {
  html, body { overflow: hidden; }
  .wrap {
    padding: 0;
    min-height: 100dvh;
    align-items: stretch;
    justify-content: stretch;
  }
  .card {
    border-radius: 0;
    height: 100dvh;
    max-height: 100dvh;
    border-left: 0;
    border-right: 0;
    box-shadow: none;
  }
  header {
    padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  }
  #log {
    padding: 12px 12px;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
  .bar {
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    gap: 8px;
  }
  button { padding: 10px 12px; }
  .thumb { width: 160px; height: 160px; }
  .bubble { max-width: 82%; }
  .jump-bottom {
    right: 12px;
    bottom: calc(82px + env(safe-area-inset-bottom));
    padding: 9px 11px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}

