:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #16181d;
  --muted: #8a9099;
  --border: #e5e7eb;
  --accent: #2f6bff;
  --accent-text: #ffffff;
  --pending: #d97706;
  --consumed: #9aa1ab;
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #16181d;
    --text: #eceff4;
    --muted: #7c828c;
    --border: #262a31;
    --accent: #3b78ff;
    --accent-text: #ffffff;
    --pending: #f0a92b;
    --consumed: #6b7280;
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

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

.login-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 340px;
}

.login-card h1 {
  margin: 0 0 6px;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.login-card p.hint {
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 13px;
}

.field {
  display: flex;
  gap: 8px;
}

.field input {
  flex: 1;
  min-width: 0;
  padding: 11px 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 107, 255, 0.14);
}

.field button {
  flex: none;
  padding: 11px 18px;
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.field button:hover {
  opacity: 0.9;
}

.field button:disabled {
  opacity: 0.55;
  cursor: default;
}

.error {
  margin: 12px 0 0;
  min-height: 18px;
  color: #e0483d;
  font-size: 13px;
}

/* ---------- 聊天页 ---------- */

.chat-page {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  flex: none;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 680px;
  margin: 0 auto;
  height: 54px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.pending-badge {
  font-size: 12px;
  color: var(--pending);
  background: color-mix(in srgb, var(--pending) 12%, transparent);
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
}

.pending-badge[hidden] {
  display: none;
}

.link-btn {
  background: none;
  border: none;
  padding: 4px;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}

.link-btn:hover {
  color: var(--text);
}

.stream {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  position: relative;
  display: flex;
  flex-direction: column;
}

.stream-inner {
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  margin-top: auto; /* 消息少时贴着输入框，多了自然滚动 */
  padding: 20px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.empty {
  position: absolute;
  top: 40%;
  left: 0;
  right: 0;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  pointer-events: none;
}

.empty[hidden] {
  display: none;
}

.msg {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  animation: rise 0.18s ease-out;
}

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

.bubble {
  max-width: 78%;
  padding: 9px 13px;
  background: var(--accent);
  color: var(--accent-text);
  border-radius: var(--radius);
  border-bottom-right-radius: 5px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 5px;
  padding-right: 2px;
  font-size: 12px;
  color: var(--muted);
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.status::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
}

.status.is-pending {
  color: var(--pending);
}

.status.is-consumed {
  color: var(--consumed);
}

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

.composer {
  flex: none;
  border-top: 1px solid var(--border);
  background: var(--bg);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.composer-inner {
  max-width: 680px;
  margin: 0 auto;
  padding: 10px 16px 12px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.composer textarea {
  flex: 1;
  min-width: 0;
  max-height: 132px;
  padding: 10px 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  resize: none;
  outline: none;
  line-height: 1.5;
  transition: border-color 0.15s ease;
}

.composer textarea:focus {
  border-color: var(--accent);
}

.composer button {
  flex: none;
  padding: 10px 18px;
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.composer button:disabled {
  opacity: 0.55;
  cursor: default;
}

@media (max-width: 480px) {
  .stream-inner {
    padding: 16px 12px 6px;
  }
  .composer-inner {
    padding: 8px 12px 10px;
  }
  .bubble {
    max-width: 84%;
  }
}
