:root {
  --bg: #0b1020;
  --bg-grad: radial-gradient(circle at top left, rgba(59, 130, 246, 0.22), transparent 55%),
             radial-gradient(circle at bottom right, rgba(139, 92, 246, 0.18), transparent 55%);
  --surface: rgba(18, 25, 45, 0.86);
  --surface-strong: rgba(24, 34, 60, 0.94);
  --border: rgba(148, 163, 184, 0.18);
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-strong: #3b82f6;
  --user-bubble: linear-gradient(135deg, #2563eb, #38bdf8);
  --partner-bubble: rgba(30, 41, 68, 0.9);
}

body[data-theme="bai"] {
  --bg: #120d1e;
  --bg-grad: radial-gradient(circle at top left, rgba(192, 132, 252, 0.22), transparent 55%),
             radial-gradient(circle at bottom right, rgba(226, 232, 240, 0.12), transparent 55%);
  --accent: #c084fc;
  --accent-strong: #a855f7;
  --user-bubble: linear-gradient(135deg, #7e22ce, #c084fc);
  --partner-bubble: rgba(38, 29, 58, 0.9);
}

body[data-theme="ling"] {
  --bg: #081822;
  --bg-grad: radial-gradient(circle at top left, rgba(34, 211, 238, 0.22), transparent 55%),
             radial-gradient(circle at bottom right, rgba(14, 165, 233, 0.16), transparent 55%);
  --accent: #22d3ee;
  --accent-strong: #06b6d4;
  --user-bubble: linear-gradient(135deg, #0284c7, #22d3ee);
  --partner-bubble: rgba(18, 42, 56, 0.9);
}

body[data-theme="group"] {
  --bg: #0d1024;
  --bg-grad: radial-gradient(circle at 15% 15%, rgba(56, 189, 248, 0.22), transparent 45%),
             radial-gradient(circle at 85% 20%, rgba(192, 132, 252, 0.2), transparent 45%),
             radial-gradient(circle at 50% 90%, rgba(34, 211, 238, 0.16), transparent 50%);
  --accent: #60a5fa;
  --accent-strong: #818cf8;
  --user-bubble: linear-gradient(135deg, #3b82f6, #a855f7);
  --partner-bubble: rgba(24, 32, 58, 0.92);
}

body[data-theme="study"] {
  --bg: #071916;
  --bg-grad: radial-gradient(circle at top left, rgba(16, 185, 129, 0.22), transparent 55%),
             radial-gradient(circle at bottom right, rgba(56, 189, 248, 0.14), transparent 55%);
  --accent: #34d399;
  --accent-strong: #10b981;
  --user-bubble: linear-gradient(135deg, #059669, #10b981);
  --partner-bubble: rgba(16, 40, 38, 0.92);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  background-image: var(--bg-grad);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

/* 登录页 */
.login-screen {
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface-strong);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px 22px;
  text-align: center;
  backdrop-filter: blur(16px);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

.login-badge {
  font-size: 32px;
  color: var(--accent);
  margin-bottom: 8px;
}

.login-card h1 {
  margin: 0 0 6px;
  font-size: 20px;
}

.login-sub {
  margin: 0 0 20px;
  font-size: 13px;
  color: var(--muted);
}

#login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#passcode-input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.8);
  color: var(--text);
  font-size: 15px;
  outline: none;
}

#passcode-input:focus {
  border-color: var(--accent);
}

#login-btn {
  padding: 12px;
  border-radius: 12px;
  border: none;
  background: var(--user-bubble);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.login-error {
  min-height: 18px;
  margin: 10px 0 0;
  font-size: 13px;
  color: #fb7185;
}

/* 主应用布局 */
.app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 780px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.partner-tabs {
  display: flex;
  gap: 6px;
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px 6px 6px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.tab.active {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  border-color: var(--accent);
  box-shadow: 0 0 12px color-mix(in srgb, var(--accent) 35%, transparent);
}

.tab-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  object-fit: cover;
  object-position: top;
}

.tab-avatar-badge {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
}

.tab-avatar-badge.bai {
  background: linear-gradient(135deg, #e2e8f0, #a855f7);
}

.tab-avatar-badge.ling {
  background: linear-gradient(135deg, #0284c7, #22d3ee);
}

.tab-avatar-badge.group {
  background: linear-gradient(135deg, #38bdf8, #a855f7, #22d3ee);
}

.tab-avatar-badge.study {
  background: linear-gradient(135deg, #059669, #34d399);
}

.topbar-right {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.logout-btn {
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}

.logout-btn:hover {
  color: #fff;
  border-color: var(--accent);
}

.partner-tabs {
  overflow-x: auto;
  scrollbar-width: none;
}
.partner-tabs::-webkit-scrollbar { display: none; }

/* 学习代码块与 SVG 电路图渲染 */
.code-block {
  margin: 8px 0;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(2, 6, 23, 0.85);
}

.code-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 10px;
  font-size: 11px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.05);
}

.code-copy-btn {
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 6px;
  cursor: pointer;
}

.code-block pre {
  margin: 0;
  padding: 10px;
  overflow-x: auto;
  font-size: 12.5px;
  line-height: 1.5;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.svg-diagram-box {
  margin: 8px 0;
  padding: 10px;
  border-radius: 12px;
  background: #0f172a;
  border: 1px solid rgba(52, 211, 153, 0.35);
  overflow-x: auto;
}

.svg-diagram-box svg {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
}

.sender-tag {
  font-size: 12px;
  font-weight: 700;
  margin: 0 0 4px 4px;
}

.sender-tag.xing { color: #38bdf8; }
.sender-tag.bai  { color: #c084fc; }
.sender-tag.ling { color: #22d3ee; }

.msg-row.partner.sender-xing .bubble { border-left: 3px solid #38bdf8; }
.msg-row.partner.sender-bai  .bubble { border-left: 3px solid #c084fc; }
.msg-row.partner.sender-ling .bubble { border-left: 3px solid #22d3ee; }

.group-mentions {
  display: inline-flex;
  gap: 6px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
}

.status-pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #f59e0b;
}

.status-pill.online .dot {
  background: #22c55e;
  box-shadow: 0 0 8px #22c55e;
}

.partner-banner {
  padding: 8px 14px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.45);
}

.partner-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
}

.partner-desc {
  font-size: 12px;
  color: var(--muted);
}

/* 消息列表 */
.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg-row {
  display: flex;
  flex-direction: column;
  max-width: 84%;
}

.msg-row.user {
  align-self: flex-end;
  align-items: flex-end;
}

.msg-row.partner {
  align-self: flex-start;
  align-items: flex-start;
}

.bubble {
  padding: 10px 13px;
  border-radius: 16px;
  line-height: 1.55;
  font-size: 15px;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-row.user .bubble {
  background: var(--user-bubble);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg-row.partner .bubble {
  background: var(--partner-bubble);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.msg-time {
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
  padding: 0 4px;
}

/* 文件与图片卡片 */
.file-preview-img {
  display: block;
  max-width: 240px;
  max-height: 260px;
  border-radius: 10px;
  margin-top: 8px;
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.16);
}

.file-card {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: #fff;
  text-decoration: none;
}

.file-card:hover {
  background: rgba(0, 0, 0, 0.42);
}

.file-icon {
  font-size: 22px;
}

.file-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.file-name {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 190px;
}

.file-size {
  font-size: 11px;
  opacity: 0.8;
}

/* 状态栏与快捷条 */
.typing-bar {
  padding: 4px 14px;
  font-size: 12px;
  color: var(--accent);
}

.quick-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 12px 2px;
}

.quick-chip {
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}

.quick-chip:active {
  transform: scale(0.97);
}

.upload-status {
  font-size: 12px;
  color: var(--accent);
}

/* 输入框 */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 10px calc(10px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.icon-btn {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.08);
  color: var(--accent);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

#msg-input {
  flex: 1;
  max-height: 120px;
  padding: 10px 12px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.82);
  color: var(--text);
  font-size: 15px;
  line-height: 1.4;
  resize: none;
  outline: none;
  font-family: inherit;
}

#msg-input:focus {
  border-color: var(--accent);
}

.send-btn {
  height: 40px;
  padding: 0 16px;
  flex-shrink: 0;
  border-radius: 14px;
  border: none;
  background: var(--user-bubble);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.send-btn:disabled {
  opacity: 0.5;
}

/* 全屏看图 */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99;
  padding: 16px;
}

.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 10px;
}

/* 共享记忆弹窗 */
.memory-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 95;
}

.memory-sheet {
  width: 100%;
  max-width: 640px;
  max-height: 80dvh;
  display: flex;
  flex-direction: column;
  background: var(--surface-strong);
  border: 1px solid var(--border);
  border-radius: 18px;
  overflow: hidden;
  backdrop-filter: blur(16px);
}

.memory-sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  border-bottom: 1px solid var(--border);
}

.memory-close {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
}

.memory-content {
  margin: 0;
  padding: 14px 16px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.65;
  color: var(--text);
}
