:root {
  --bg: #0e1116;
  --panel: #151a21;
  --panel-2: #1b212b;
  --line: #242b36;
  --text: #e6edf3;
  --muted: #8b949e;
  --dim: #5b6572;
  --me: #4f7cf0;
  --edith: #d9a066;
  --danger: #e06c75;
  --ok: #57ab5a;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.65 system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; cursor: pointer; }

/* ---------------- 进门 ---------------- */

.gate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
  z-index: 50;
}
.gate.hide { display: none; }

/* 认过人的浏览器自动进门时，先别让人看见输入框，免得闪一下 */
.gate.booting .gate-card { display: none; }
.gate.booting::after {
  content: "正在进去…";
  color: var(--muted);
  font-size: 14px;
  letter-spacing: 0.08em;
  animation: bootingPulse 1.2s ease-in-out infinite;
}
@keyframes bootingPulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

.gate-card {
  width: 340px;
  padding: 32px 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.gate-card h1 {
  margin: 0 0 6px;
  font-size: 19px;
  font-weight: 500;
  letter-spacing: .2px;
}
.gate-sub {
  margin: 0 0 22px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.6;
}
.gate-card input {
  width: 100%;
  padding: 11px 13px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--text);
  font: inherit;
  outline: none;
}
.gate-card input:focus { border-color: var(--me); }
.gate-card button {
  width: 100%;
  margin-top: 12px;
  padding: 11px;
  background: var(--me);
  border: 0;
  border-radius: 9px;
  color: #fff;
  font-weight: 500;
}
.gate-card button:hover { filter: brightness(1.1); }
.gate-err {
  min-height: 18px;
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--danger);
}

/* ---------------- 主区 ---------------- */

.app {
  display: grid;
  grid-template-rows: 52px 1fr auto;
  height: 100%;
  max-width: 860px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}
.dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--ok);
}
.members {
  display: flex;
  gap: 6px;
  flex: 1;
  overflow: hidden;
}
.member {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px 2px 6px;
  border-radius: 20px;
  font-size: 12px;
  background: var(--panel-2);
  color: var(--muted);
  white-space: nowrap;
}
.member.ai { color: var(--edith); }
.m-dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  flex: none;
  background: var(--dim);
  background-size: cover;
  background-position: center;
  display: inline-block;
}
.member.ai .m-dot { background: var(--edith); }

.ghost {
  padding: 5px 11px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--muted);
  font-size: 12.5px;
}
.ghost:hover { border-color: var(--dim); color: var(--text); }

/* ---------------- 消息流 ---------------- */

.stream {
  overflow-y: auto;
  padding: 20px 18px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.stream::-webkit-scrollbar { width: 8px; }
.stream::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }

.row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  max-width: 100%;
}
.row.mine { flex-direction: row-reverse; }

.avatar {
  flex: 0 0 30px;
  width: 30px; height: 30px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 500;
  color: #0e1116;
  user-select: none;
  overflow: hidden;
}
.avatar img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}

.body { min-width: 0; max-width: 72%; }
.row.mine .body { display: flex; flex-direction: column; align-items: flex-end; }

.who {
  font-size: 11.5px;
  color: var(--dim);
  margin-bottom: 3px;
  display: flex;
  gap: 7px;
  align-items: baseline;
}
.who .time { color: #3d4551; font-variant-numeric: tabular-nums; }

.bubble {
  padding: 8px 13px;
  border-radius: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  white-space: pre-wrap;
  word-break: break-word;
}
.row.mine .bubble {
  background: var(--me);
  border-color: transparent;
  color: #fff;
  border-bottom-right-radius: 4px;
}
.row.ai .bubble {
  background: #221b12;
  border-color: #3a2d1c;
  color: #f0e0c8;
  border-bottom-left-radius: 4px;
}
.row.ai .avatar { background: var(--edith); }

.streaming .bubble::after {
  content: "";
  display: inline-block;
  width: 7px; height: 15px;
  margin-left: 2px;
  vertical-align: -2px;
  background: var(--edith);
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.sysline {
  align-self: center;
  font-size: 12px;
  color: var(--dim);
  padding: 1px 0;
}
.sysline.err { color: var(--danger); }

.empty {
  margin: auto;
  text-align: center;
}
.empty-title {
  font-size: 15px;
  color: var(--muted);
  margin-bottom: 6px;
}
.empty-sub {
  font-size: 13px;
  color: var(--dim);
}

/* ---------------- 输入 ---------------- */

.composer {
  position: relative;
  display: flex;
  gap: 9px;
  padding: 12px 18px 16px;
  border-top: 1px solid var(--line);
}
.composer input {
  flex: 1;
  padding: 11px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  font: inherit;
  outline: none;
}
.composer input:focus { border-color: var(--dim); }
.send {
  padding: 0 20px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
}
.send:hover { border-color: var(--dim); }

/* @ 选人：贴在输入框上沿 */
.mentions {
  position: absolute;
  left: 18px;
  bottom: 64px;
  min-width: 190px;
  max-height: 214px;
  overflow-y: auto;
  padding: 5px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 11px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.32);
  z-index: 30;
}
.mentions.hide { display: none; }
.mention-item {
  display: block;
  width: 100%;
  padding: 8px 11px;
  background: none;
  border: 0;
  border-radius: 7px;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.mention-item.on,
.mention-item:hover { background: var(--panel-2); }

/* ---------------- 我的档案 ---------------- */

.sheet {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 14, .62);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
  z-index: 60;
  padding: 20px;
}
.sheet-card {
  position: relative;
  width: 100%;
  max-width: 400px;
  max-height: 86vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 24px 22px 18px;
}
.sheet-x {
  position: absolute;
  top: 10px; right: 12px;
  width: 28px; height: 28px;
  display: grid;
  place-items: center;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--dim);
  font-size: 20px;
  line-height: 1;
}
.sheet-x:hover { background: var(--panel-2); color: var(--text); }

.sheet-head {
  display: flex;
  gap: 14px;
  align-items: center;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}
.sheet-avatar {
  position: relative;
  flex: 0 0 56px;
  width: 56px;
  height: 56px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  overflow: hidden;
}
.sheet-avatar .avatar {
  width: 56px; height: 56px;
  flex: 0 0 56px;
  border-radius: 50%;
  font-size: 20px;
}
.sheet-avatar-hint {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 3px 0 4px;
  background: rgba(8, 10, 14, .74);
  color: #fff;
  font-size: 10px;
  line-height: 1;
  text-align: center;
  opacity: 0;
  transition: opacity .15s ease;
}
.sheet-avatar:hover .sheet-avatar-hint { opacity: 1; }
/* 编辑态常显「换」，不然没人知道头像能点 */
#sheet.editing .sheet-avatar-hint { opacity: 1; }
.sheet-id { min-width: 0; flex: 1; }
.sheet-idrow {
  display: flex;
  align-items: center;
  gap: 8px;
}
.mini {
  padding: 1px 8px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--dim);
  font-size: 11.5px;
  line-height: 1.7;
}
.mini:hover { color: var(--text); border-color: var(--dim); }
.sheet-nick {
  font-size: 17px;
  font-weight: 500;
  color: var(--text);
}
.sheet-phone {
  margin-top: 3px;
  font-size: 12.5px;
  color: var(--dim);
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  letter-spacing: .5px;
}
.sheet-note {
  margin-top: 5px;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.5;
}

/* ---------------- 档案编辑 ---------------- */

.edit-form {
  display: grid;
  gap: 9px;
  padding-top: 15px;
}
.edit-row {
  display: grid;
  grid-template-columns: 46px 1fr;
  align-items: center;
  gap: 8px;
}
.edit-row > span {
  font-size: 12px;
  color: var(--dim);
}
.edit-row input {
  width: 100%;
  padding: 7px 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color .15s ease;
}
.edit-row input:focus { border-color: var(--me); }
.edit-tip {
  margin: 1px 0 0;
  padding-left: 54px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--dim);
}
.edit-foot {
  display: flex;
  gap: 8px;
  margin-top: 3px;
  padding-left: 54px;
}
.primary {
  padding: 6px 16px;
  background: var(--me);
  border: 1px solid var(--me);
  border-radius: 8px;
  color: #fff;
  font-size: 12.5px;
}
.primary:hover { filter: brightness(1.1); }

.sheet-sec {
  padding: 16px 0 4px;
}
.sheet-label {
  font-size: 12px;
  color: var(--dim);
  margin-bottom: 9px;
}

.sheet-foot {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.sheet-hint {
  font-size: 11px;
  color: var(--dim);
  line-height: 1.45;
}
.danger {
  flex: none;
  padding: 6px 12px;
  background: transparent;
  border: 1px solid #4a2b2e;
  border-radius: 8px;
  color: var(--danger);
  font-size: 12.5px;
  white-space: nowrap;
}
.danger:hover { background: #2a181a; border-color: var(--danger); }

.hide { display: none !important; }

/* ---------------- 头像选择 ---------------- */

.avatar-pick {
  display: grid;
  place-items: center;
  margin-bottom: 16px;
}
.avatar-slot {
  width: 76px; height: 76px;
  border-radius: 50%;
  border: 1px dashed #39414f;
  display: grid;
  place-items: center;
  font-size: 12px;
  color: var(--dim);
  cursor: pointer;
  background-size: cover;
  background-position: center;
  overflow: hidden;
  transition: border-color .15s ease;
}
.avatar-slot:hover { border-color: var(--dim); color: var(--muted); }
.avatar-slot.has-img { border-style: solid; border-color: var(--line); }

/* ---------------- 顶栏「我」 ---------------- */

.me {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 3px 9px 3px 3px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 20px;
  color: var(--muted);
  font-size: 12.5px;
  max-width: 140px;
}
.me:hover { border-color: var(--dim); color: var(--text); }
.me .avatar {
  flex: 0 0 22px;
  width: 22px; height: 22px;
  border-radius: 50%;
  font-size: 11px;
}
.me-nick {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------------- 记忆内容 ---------------- */

.mem-body { font-size: 12.5px; line-height: 1.75; color: var(--muted); }
.mem-empty { color: var(--dim); }
.mem-sum { color: var(--text); margin-bottom: 5px; }
.mem-style { color: var(--dim); margin-bottom: 6px; }
.mem-facts {
  margin: 6px 0 0;
  padding-left: 16px;
  display: grid;
  gap: 4px;
  color: var(--muted);
}
.mem-facts li { font-size: 12px; }
.mem-meta {
  margin-top: 10px;
  font-size: 11px;
  color: #3d4551;
}

@media (max-width: 640px) {
  .sheet-card { max-width: none; max-height: 92vh; padding: 20px 16px 16px; }
  .sheet-foot { flex-wrap: wrap; }
}
