:root {
  --bg: #f4f5f8;
  --panel: #ffffff;
  --panel-2: #fbfbfd;
  --ink: #101322;
  --ink-2: #59607a;
  --ink-3: #8b93ab;
  --line: #e6e8ef;
  --accent: #4f46e5;
  --accent-2: #7c5cf5;
  --accent-soft: #eef0ff;
  --warn: #e07b0a;
  --warn-soft: #fff4e2;
  --danger: #dc2626;
  --bubble-in: #ffffff;
  --radius: 18px;
  --shadow-sm: 0 1px 2px rgba(16, 19, 34, .05);
  --shadow-md: 0 8px 30px rgba(16, 19, 34, .09);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0d14;
    --panel: #141824;
    --panel-2: #171b28;
    --ink: #eef1f8;
    --ink-2: #a5adc2;
    --ink-3: #6f7891;
    --line: #242a3a;
    --accent: #6c63f0;
    --accent-2: #8f77ff;
    --accent-soft: #1e2233;
    --warn: #f0a13c;
    --warn-soft: #2a2216;
    --bubble-in: #1b2030;
    --shadow-md: 0 8px 30px rgba(0, 0, 0, .5);
  }
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro SC", "PingFang SC",
    "Microsoft YaHei", "Helvetica Neue", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body { height: 100dvh; overflow: hidden; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }

.view {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

/* ---------------- 登录 / 注册 ---------------- */
#view-auth { overflow-y: auto; display: block; }

/* ---------------- 闲置锁定 ---------------- */
#view-lock {
  z-index: 60;
  display: block;
  overflow-y: auto;
  background: var(--bg);
}
.lock-wrap {
  min-height: 100%;
  max-width: 460px;
  margin: 0 auto;
  padding: calc(64px + var(--safe-t)) 22px calc(28px + var(--safe-b));
  display: flex;
  flex-direction: column;
}
.lock-badge {
  width: 58px; height: 58px;
  margin: 0 auto 16px;
  border-radius: 20px;
  display: grid; place-items: center;
  font-size: 26px;
  background: var(--accent-soft);
}
.lock-wrap h2 {
  margin: 0 0 6px;
  text-align: center;
  font-size: 20px;
  font-weight: 600;
}
.lock-sub {
  margin: 0 auto 22px;
  text-align: center;
  font-size: 13px;
  line-height: 1.7;
  color: var(--ink-3);
  max-width: 300px;
}
.lock-wrap .card { margin-bottom: 12px; }
.lock-wrap #btn-switch-account { margin-top: 2px; }

/* ============ 4 位短密码 ============ */
.pin-wrap {
  min-height: 100%;
  max-width: 460px;
  margin: 0 auto;
  padding: calc(52px + var(--safe-t)) 22px calc(24px + var(--safe-b));
  display: flex;
  flex-direction: column;
}
.pin-badge {
  width: 58px; height: 58px;
  margin: 0 auto 16px;
  border-radius: 20px;
  display: grid; place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
}
.pin-wrap h2 {
  margin: 0 0 6px;
  text-align: center;
  font-size: 20px;
  font-weight: 600;
  color: var(--ink);
}
.pin-sub {
  margin: 0 auto 18px;
  text-align: center;
  font-size: 13px;
  line-height: 1.7;
  color: var(--ink-3);
  max-width: 300px;
}
.pin-dots {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin: 6px 0 2px;
  height: 16px;
}
.pin-dots i {
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  background: transparent;
  transition: background .12s, border-color .12s, transform .12s;
}
.pin-dots i.on {
  background: var(--accent);
  border-color: var(--accent);
  transform: scale(1.06);
}
.pin-err {
  margin: 0 0 2px;
  min-height: 20px;
  text-align: center;
  font-size: 13px;
  color: var(--danger);
}
.pin-pad {
  margin: 8px auto 0;
  width: 100%;
  max-width: 300px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.pin-pad button {
  height: 56px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  color: var(--ink);
  font-size: 22px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform .08s, background .12s;
}
.pin-pad button:active { transform: scale(.96); background: var(--accent-soft); }
.pin-pad button.fn { font-size: 17px; color: var(--ink-2); }
.pin-pad button.blank { visibility: hidden; pointer-events: none; }
.pin-hint {
  margin: 16px auto 8px;
  text-align: center;
  font-size: 12px;
  line-height: 1.6;
  color: var(--ink-3);
  max-width: 290px;
}
.pin-wrap #btn-pin-password { margin-top: auto; }

.auth-wrap {
  min-height: 100%;
  max-width: 460px;
  margin: 0 auto;
  padding: calc(48px + var(--safe-t)) 22px calc(28px + var(--safe-b));
  display: flex;
  flex-direction: column;
}

.brand { text-align: center; margin-bottom: 26px; }

.brand-mark {
  width: 58px; height: 58px;
  margin: 0 auto 14px;
  border-radius: 20px;
  display: grid; place-items: center;
  color: #fff;
  background: linear-gradient(150deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 24px rgba(79, 70, 229, .28);
}

.brand h1 {
  margin: 0;
  font-size: 26px;
  letter-spacing: .08em;
  font-weight: 650;
}

.tagline {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--ink-3);
  letter-spacing: .02em;
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  margin-bottom: 14px;
}

.tab {
  flex: 1;
  border: 0;
  background: transparent;
  padding: 10px 0;
  border-radius: 10px;
  font-size: 14px;
  color: var(--ink-2);
  transition: .16s;
}

.tab.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 18px;
  box-shadow: var(--shadow-sm);
}

.form { display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 12.5px; color: var(--ink-3); letter-spacing: .03em; }

.field input, .inline-form input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--ink);
  font-size: 16px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.field input:focus, .inline-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, .12);
}

.btn {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 550;
  transition: .15s;
}
.btn:active { transform: scale(.985); }
.btn.primary {
  border: 0;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 20px rgba(79, 70, 229, .24);
}
.btn.ghost { background: transparent; }
.btn.small { padding: 7px 13px; font-size: 13.5px; border-radius: 10px; }
.btn.block { width: 100%; margin-top: 6px; }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.btn:disabled { opacity: .55; }

.error {
  margin: 0;
  min-height: 18px;
  font-size: 13px;
  color: var(--danger);
}

.fineprint {
  margin: 18px 0 0;
  text-align: center;
  font-size: 12px;
  color: var(--ink-3);
  line-height: 1.7;
}

/* ---------------- 顶栏 ---------------- */
.topbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + var(--safe-t)) 14px 10px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
}

.topbar-title { flex: 1; display: flex; align-items: baseline; gap: 8px; }
.topbar-title h2 { margin: 0; font-size: 19px; font-weight: 650; letter-spacing: .02em; }
.slots { font-size: 12px; color: var(--ink-3); }
.topbar-actions { display: flex; gap: 4px; }

.icon-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border: 0; border-radius: 11px;
  background: transparent;
  color: var(--ink-2);
}
.icon-btn:active { background: var(--accent-soft); }

.chat-topbar { gap: 6px; }
.peer { flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0; }

.avatar {
  width: 36px; height: 36px;
  flex: none;
  border-radius: 12px;
  display: grid; place-items: center;
  font-size: 15px; font-weight: 600; color: #fff;
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
}

.peer-meta { min-width: 0; display: flex; flex-direction: column; }
.peer-meta strong {
  font-size: 15.5px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.peer-status { font-size: 11.5px; color: var(--ink-3); }
.peer-status.online { color: #16a34a; }

/* ---------------- 会话列表 ---------------- */
.list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }

.contact {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.contact:active { background: var(--panel-2); }
.contact-main { flex: 1; min-width: 0; }
.contact-name { display: flex; align-items: center; gap: 6px; font-weight: 560; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: #16a34a; }
.contact-sub { font-size: 12.5px; color: var(--ink-3); margin-top: 2px; }

.badge {
  min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff; font-size: 11.5px; font-weight: 600;
  display: grid; place-items: center;
}

.empty {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; color: var(--ink-3); font-size: 14px;
}

/* 管理员在访客通讯录里的标识 */
.avatar.admin { background: linear-gradient(140deg, #1e293b, #475569); }
.tag {
  font-size: 10.5px; font-weight: 500; line-height: 1;
  padding: 3px 6px; border-radius: 6px;
  background: var(--accent-soft); color: var(--accent);
}

/* ---------------- 好友面板 ---------------- */
.my-code {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel-2);
}
.my-code code {
  flex: 1;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 19px; font-weight: 700; letter-spacing: 3px;
  color: var(--accent);
  user-select: all;
  -webkit-user-select: all;
}
.hint {
  margin: 8px 0 0;
  font-size: 11.5px; line-height: 1.6;
  color: var(--ink-3);
}
.pending-list { display: flex; flex-direction: column; gap: 8px; }
.pending-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 11px;
  border-radius: 10px;
  background: var(--panel-2);
}
.pending-who { flex: 1; min-width: 0; font-size: 14px; font-weight: 550; }
.pending-note { font-size: 12px; color: var(--ink-3); }
.pending-row .ops { display: flex; gap: 6px; }

/* ---------------- 聊天区 ---------------- */
.notice {
  flex: none;
  padding: 7px 16px;
  font-size: 11.5px;
  color: var(--warn);
  background: var(--warn-soft);
  border-bottom: 1px solid color-mix(in srgb, var(--warn) 18%, transparent);
  text-align: center;
  letter-spacing: .01em;
}

.messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg { display: flex; flex-direction: column; max-width: 82%; }
.msg.me { align-self: flex-end; align-items: flex-end; }
.msg.other { align-self: flex-start; align-items: flex-start; }

.bubble {
  padding: 9px 13px;
  border-radius: 18px 18px 18px 5px;
  background: var(--bubble-in);
  border: 1px solid var(--line);
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 15.5px;
  animation: pop .18s ease-out;
}

.msg.me .bubble {
  border: 0;
  color: #fff;
  border-radius: 18px 18px 5px 18px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

@keyframes pop {
  from { opacity: 0; transform: translateY(6px) scale(.97); }
  to { opacity: 1; transform: none; }
}

.stamp {
  margin-top: 4px;
  font-size: 10.5px;
  color: var(--ink-3);
  display: flex;
  align-items: center;
  gap: 5px;
  font-variant-numeric: tabular-nums;
}

.stamp .flame { color: var(--warn); font-size: 10px; }

.msg.burning .bubble { box-shadow: 0 0 0 1.5px color-mix(in srgb, var(--warn) 45%, transparent); }

.composer {
  flex: none;
  display: flex; align-items: flex-end; gap: 9px;
  padding: 9px 12px calc(9px + var(--safe-b));
  background: var(--panel);
  border-top: 1px solid var(--line);
}

.composer textarea {
  flex: 1;
  resize: none;
  max-height: 132px;
  padding: 10px 14px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  line-height: 1.45;
  outline: none;
}
.composer textarea:focus { border-color: var(--accent); }

.send {
  flex: none;
  width: 42px; height: 42px;
  border: 0; border-radius: 50%;
  display: grid; place-items: center;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 16px rgba(79, 70, 229, .28);
}
.send:disabled { opacity: .45; box-shadow: none; }

.attach {
  flex: none;
  width: 42px; height: 42px;
  border: 1px solid var(--line);
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--panel-2);
  color: var(--ink-2);
}
.attach:active { transform: scale(.94); }
.attach:disabled { opacity: .45; }

/* 聊天里的图片气泡 */
.bubble.has-img { padding: 4px; }
.msg-img {
  display: block;
  max-width: min(62vw, 300px);
  max-height: 320px;
  border-radius: 14px;
  cursor: zoom-in;
  background: rgba(0, 0, 0, .06);
}

/* 全屏看图 */
.img-view {
  position: fixed; inset: 0; z-index: 80;
  display: grid; place-items: center;
  padding: 18px;
  background: rgba(10, 8, 24, .92);
  cursor: zoom-out;
}
.img-view img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 10px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, .5);
}

/* ---------------- 管理面板 ---------------- */
.sheet-mask {
  position: fixed; inset: 0;
  background: rgba(10, 12, 20, .38);
  backdrop-filter: blur(2px);
  z-index: 20;
}

.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 21;
  max-height: 86dvh;
  overflow-y: auto;
  max-width: 520px;
  margin: 0 auto;
  padding: 8px 18px calc(20px + var(--safe-b));
  background: var(--panel);
  border-radius: 22px 22px 0 0;
  box-shadow: var(--shadow-md);
  animation: up .2s ease-out;
}

@keyframes up { from { transform: translateY(26px); opacity: .6; } to { transform: none; opacity: 1; } }

.sheet-handle {
  width: 38px; height: 4px; border-radius: 2px;
  background: var(--line);
  margin: 6px auto 12px;
}

.sheet h3 { margin: 0 0 14px; font-size: 17px; font-weight: 650; }

.sheet-block { border-top: 1px solid var(--line); padding: 14px 0; }
.sheet-block:first-of-type { border-top: 0; }
.sheet-block-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 13px; color: var(--ink-2); margin-bottom: 9px;
}

.invite-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 22px;
  letter-spacing: .18em;
  padding: 12px;
  text-align: center;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  margin-bottom: 9px;
  user-select: all;
}

.invites { display: flex; flex-direction: column; gap: 6px; }
.invite-row {
  display: flex; align-items: center; gap: 10px;
  font-size: 13px; color: var(--ink-2);
  padding: 7px 10px;
  border-radius: 10px;
  background: var(--panel-2);
}
.invite-row code { font-size: 14px; letter-spacing: .1em; color: var(--ink); }

.inline-form { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.inline-form input { font-size: 14px; padding: 10px 12px; }
.inline-form button { grid-column: span 2; }

/* 只有一个输入框的表单（好友码）：让按钮和输入框并排 */
.inline-form.single { grid-template-columns: 1fr auto; }
.inline-form.single input { letter-spacing: 2px; text-transform: uppercase; font-weight: 600; }
.inline-form.single button { grid-column: auto; padding-left: 18px; padding-right: 18px; }

.guest-admin-list { display: flex; flex-direction: column; gap: 8px; }
.guest-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.guest-row .grow { flex: 1; min-width: 0; }
.guest-row .gname { font-weight: 550; font-size: 14px; }
.guest-row .guser { font-size: 12px; color: var(--ink-3); }
.guest-row .ops { display: flex; gap: 6px; }

/* ---------------- Toast ---------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + var(--safe-b));
  transform: translate(-50%, 12px);
  padding: 9px 16px;
  border-radius: 12px;
  background: rgba(16, 19, 34, .9);
  color: #fff;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: .22s;
  z-index: 40;
  max-width: 86vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------- 桌面端 ---------------- */
@media (min-width: 720px) {
  #view-list, #view-chat {
    max-width: 520px;
    margin: 0 auto;
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
  }
  .auth-wrap { max-width: 420px; }
}
