:root {
  color-scheme: dark;
  --bg: #0b0d12;
  --panel: #121620;
  --panel2: #171c29;
  --text: #eef2ff;
  --muted: #8d97ad;
  --line: #242b3d;
  --accent: #7c5cff;
  --accent2: #46d6a7;
  --danger: #ff657a;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: radial-gradient(circle at top, #182037 0, var(--bg) 42%);
  color: var(--text);
}
.app {
  height: 100dvh;
  max-width: 900px;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  border-left: 1px solid rgba(255,255,255,.04);
  border-right: 1px solid rgba(255,255,255,.04);
}
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: rgba(18, 22, 32, .78);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 2;
}
h1 { margin: 0; font-size: 20px; letter-spacing: .5px; }
p { margin: 0; }
#status { margin-top: 4px; font-size: 12px; color: var(--muted); }
button {
  border: 0;
  background: var(--panel2);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
}
button:disabled { opacity: .55; cursor: wait; }
#memoryBtn { border: 1px solid var(--line); }
main {
  overflow-y: auto;
  padding: 18px 14px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.msg {
  max-width: 86%;
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.55;
  border-radius: 18px;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: 0 10px 26px rgba(0,0,0,.12);
}
.msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--accent), #5e8cff);
  border-bottom-right-radius: 5px;
}
.msg.assistant {
  align-self: flex-start;
  background: rgba(23, 28, 41, .95);
  border: 1px solid rgba(255,255,255,.06);
  border-bottom-left-radius: 5px;
}
.msg.error { background: rgba(255, 101, 122, .15); border: 1px solid rgba(255,101,122,.35); }
.empty {
  color: var(--muted);
  text-align: center;
  margin: auto;
  line-height: 1.8;
}
#attachments {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 12px;
  background: rgba(18, 22, 32, .88);
}
.attachment {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 260px;
  border: 1px solid var(--line);
  background: #0f1420;
  border-radius: 12px;
  padding: 6px;
  margin-top: 8px;
}
.attachment img {
  width: 42px;
  height: 42px;
  object-fit: cover;
  border-radius: 9px;
}
.attachment span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 12px;
}
.attachment button {
  padding: 4px 8px;
  border-radius: 8px;
  color: var(--danger);
}
form {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  padding: 12px;
  background: rgba(18, 22, 32, .88);
  border-top: 1px solid var(--line);
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
}
#attachBtn {
  width: 44px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
  border: 1px solid var(--line);
}
textarea {
  width: 100%;
  resize: none;
  border: 1px solid var(--line);
  outline: none;
  border-radius: 16px;
  padding: 12px 14px;
  max-height: 150px;
  background: #0f1420;
  color: var(--text);
  font: inherit;
  line-height: 1.45;
}
#send {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: white;
  min-width: 68px;
}
dialog {
  width: min(720px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  color: var(--text);
  padding: 18px;
}
dialog::backdrop { background: rgba(0,0,0,.55); backdrop-filter: blur(3px); }
dialog h2 { margin: 0 0 8px; }
dialog p { color: var(--muted); font-size: 14px; margin-bottom: 12px; }
#memoryText { min-height: 45dvh; }
.dialogActions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 12px; }
#saveMemory { background: var(--accent); }
@media (max-width: 600px) {
  .msg { max-width: 94%; }
  header { padding: 12px; }
  main { padding: 14px 10px 20px; }
  form { grid-template-columns: auto 1fr auto; gap: 8px; padding: 10px; }
  #send { min-width: 58px; padding: 10px 12px; }
}
