:root {
  --bg: #f6f2ec;
  --bg-soft: #fbf8f4;
  --ink: #2b2622;
  --muted: #9c9187;
  --line: #eae2d8;
  --card: #ffffff;
  --coral-1: #f4a798;
  --coral-2: #e8746a;
  --shadow: 0 8px 30px rgba(74, 52, 40, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(120% 60% at 50% 0%, #fffdfa 0%, rgba(255, 253, 250, 0) 70%);
}

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  z-index: 1;
}

/* ---------------- 登录 ---------------- */

.login {
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 34px 26px 28px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow);
}

.login-logo {
  width: 84px;
  height: 84px;
  border-radius: 22px;
  margin-bottom: 4px;
}

.login-card h1 {
  margin: 0;
  font-size: 24px;
  letter-spacing: 2px;
  font-weight: 600;
}

.login-sub {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 13.5px;
  letter-spacing: 0.5px;
}

.secret-input {
  width: 100%;
  padding: 13px 16px;
  font: inherit;
  font-size: 15px;
  text-align: center;
  letter-spacing: 1px;
  color: var(--ink);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 16px;
  outline: none;
  transition: border-color 0.18s, box-shadow 0.18s;
}

.secret-input:focus {
  border-color: var(--coral-1);
  box-shadow: 0 0 0 4px rgba(244, 167, 152, 0.18);
}

button {
  font: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

.primary {
  width: 100%;
  margin-top: 6px;
  padding: 13px 16px;
  font-size: 15.5px;
  font-weight: 600;
  letter-spacing: 1px;
  color: #fff;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--coral-1), var(--coral-2));
  box-shadow: 0 6px 16px rgba(232, 116, 106, 0.28);
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
}

.primary:active {
  transform: scale(0.98);
  box-shadow: 0 3px 10px rgba(232, 116, 106, 0.24);
}

.primary[disabled] {
  opacity: 0.6;
  pointer-events: none;
}

.error {
  margin: 4px 0 0;
  color: #d0503f;
  font-size: 13px;
}

/* ---------------- 顶部栏 ---------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: rgba(251, 248, 244, 0.86);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(234, 226, 216, 0.7);
  z-index: 3;
}

.avatar {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, #f6b6a8, #e8746a);
  letter-spacing: 0;
}

.peer {
  flex: 1;
  min-width: 0;
}

.peer-name {
  font-size: 15.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.peer-status {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 5px;
}

.peer-status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #c9c0b6;
  transition: background 0.2s;
}

.peer-status.online::before {
  background: #62c98d;
  box-shadow: 0 0 0 3px rgba(98, 201, 141, 0.18);
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
  color: var(--muted);
  display: grid;
  place-items: center;
  transition: background 0.15s;
}

.icon-btn:active {
  background: rgba(0, 0, 0, 0.05);
}

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

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 0 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scrollbar-width: thin;
}

.messages::-webkit-scrollbar {
  width: 6px;
}

.messages::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.1);
  border-radius: 3px;
}

.day {
  align-self: center;
  margin: 14px 0 10px;
  padding: 4px 12px;
  font-size: 11.5px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(234, 226, 216, 0.8);
  border-radius: 999px;
}

.msg {
  display: flex;
  padding: 0 16px;
  margin: 3px 0;
}

.msg.new {
  animation: rise 0.22s ease-out;
}

.msg.mine {
  justify-content: flex-end;
}

.msg-body {
  display: flex;
  flex-direction: column;
  max-width: min(78%, 460px);
  gap: 3px;
}

.msg.mine .msg-body {
  align-items: flex-end;
}

.bubble {
  padding: 9px 14px;
  font-size: 15.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border-radius: 19px;
  box-shadow: 0 1px 2px rgba(74, 52, 40, 0.05);
}

.msg.theirs .bubble {
  background: var(--card);
  border: 1px solid var(--line);
  border-bottom-left-radius: 7px;
}

.msg.mine .bubble {
  color: #fff;
  background: linear-gradient(135deg, var(--coral-1), var(--coral-2));
  border-bottom-right-radius: 7px;
  box-shadow: 0 4px 14px rgba(232, 116, 106, 0.22);
}

.msg.pending .bubble {
  opacity: 0.62;
}

.time {
  font-size: 10.5px;
  color: #bdb3a9;
  padding: 0 4px;
  opacity: 0;
  transition: opacity 0.2s;
}

.time.show {
  opacity: 1;
}

.empty {
  margin: auto;
  padding: 40px 32px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  line-height: 2;
}

.empty strong {
  display: block;
  font-size: 22px;
  margin-bottom: 10px;
  color: #cbbfb3;
  font-weight: 500;
}

/* ---------------- 正在输入 ---------------- */

.typing {
  padding: 0 26px 4px;
  display: flex;
  gap: 4px;
  align-items: center;
  height: 18px;
}

.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #cfc3b6;
  animation: blink 1.3s infinite ease-in-out;
}

.typing span:nth-child(2) {
  animation-delay: 0.18s;
}

.typing span:nth-child(3) {
  animation-delay: 0.36s;
}

/* ---------------- 通知提示条 ---------------- */

.banner {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 12px 8px;
  padding: 10px 12px 10px 14px;
  font-size: 13px;
  color: #6b5e52;
  background: #fff5ee;
  border: 1px solid #f4dccf;
  border-radius: 16px;
  animation: rise 0.25s ease-out;
}

.banner span {
  flex: 1;
  line-height: 1.4;
}

.banner button {
  flex: 0 0 auto;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--coral-1), var(--coral-2));
}

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

.composer {
  display: flex;
  align-items: flex-end;
  gap: 9px;
  padding: 9px 12px calc(9px + env(safe-area-inset-bottom));
  background: rgba(251, 248, 244, 0.9);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid rgba(234, 226, 216, 0.7);
}

.composer textarea {
  flex: 1;
  min-height: 44px;
  max-height: 132px;
  padding: 11px 16px;
  font: inherit;
  font-size: 15.5px;
  line-height: 1.4;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 22px;
  outline: none;
  resize: none;
  transition: border-color 0.18s, box-shadow 0.18s;
}

.composer textarea:focus {
  border-color: #f0c4b8;
  box-shadow: 0 0 0 4px rgba(244, 167, 152, 0.13);
}

.composer textarea::placeholder {
  color: #c0b5aa;
}

.send {
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  color: #fff;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--coral-1), var(--coral-2));
  box-shadow: 0 5px 14px rgba(232, 116, 106, 0.3);
  transition: transform 0.14s, opacity 0.14s;
}

.send:active {
  transform: scale(0.92);
}

.send:disabled {
  opacity: 0.45;
  box-shadow: none;
}

/* ---------------- 弹出菜单 ---------------- */

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(43, 38, 34, 0.22);
  z-index: 8;
  animation: fade 0.18s ease-out;
}

.sheet {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 9;
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: rise 0.22s ease-out;
}

.sheet button {
  padding: 15px;
  font-size: 15.5px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.97);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.sheet button.danger {
  color: #d0503f;
}

.sheet button.cancel {
  margin-top: 2px;
  color: var(--muted);
}

/* ---------------- 图片 ---------------- */

.attach {
  flex: 0 0 40px;
  width: 40px;
  height: 44px;
  display: grid;
  place-items: center;
  color: var(--muted);
  border-radius: 14px;
  transition: color 0.15s, background 0.15s;
}

.attach:active {
  color: var(--coral-2);
  background: rgba(232, 116, 106, 0.1);
}

.bubble.photo-bubble {
  padding: 0;
  line-height: 0;
  background: none !important;
  border: none !important;
  box-shadow: none !important;
}

.photo {
  display: block;
  max-width: min(62vw, 300px);
  max-height: 380px;
  width: auto;
  height: auto;
  border-radius: 16px;
  border: 1px solid rgba(234, 226, 216, 0.9);
  background: #ece4db;
  cursor: zoom-in;
}

.msg.pending .photo {
  opacity: 0.7;
  filter: saturate(0.85);
}

.viewer {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 14px;
  background: rgba(24, 20, 18, 0.94);
  animation: fade 0.18s ease-out;
  cursor: zoom-out;
}

.viewer img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 10px;
  object-fit: contain;
}

/* ---------------- 动画 ---------------- */

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes blink {
  0%,
  60%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

/* 桌面/平板：收成一个居中的窄栏 */
@media (min-width: 760px) {
  .chat {
    max-width: 720px;
    margin: 0 auto;
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
    background: var(--bg);
  }
  .sheet {
    left: 50%;
    right: auto;
    width: 340px;
    margin-left: -170px;
  }
}
