/* Mate Mobile — 手机优先样式
   桌面版的配色与纸感沿用，但布局是单列 + 底部输入。 */

:root {
  --accent: #c45d3c;
  --accent-soft: color-mix(in srgb, var(--accent) 12%, transparent);
  --ink: #20251f;
  --ink-soft: #4d544b;
  --muted: #82857b;
  --faint: #a3a498;
  --paper: #fffdf8;
  --cream: #f6f2ea;
  --cream-deep: #eee8dd;
  --line: rgba(32, 37, 31, 0.09);
  --line-strong: rgba(32, 37, 31, 0.16);
  --danger: #b44b3f;
  --ok: #4f7a52;
  --radius: 18px;
  --shadow: 0 10px 34px rgba(24, 28, 23, 0.1);
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-display: "Songti SC", "STSong", "Iowan Old Style", Georgia, serif;
}

html[data-theme='dark'] {
  --ink: #f2eee4;
  --ink-soft: #c3c0b4;
  --muted: #96948a;
  --faint: #6f6f67;
  --paper: #191e19;
  --cream: #101410;
  --cream-deep: #0b0e0b;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

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

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  position: fixed;
  inset: 0;
  color: var(--ink);
  background: var(--cream-deep);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

button {
  border: 0;
  background: none;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

a {
  color: var(--accent);
}

.icon {
  display: block;
}

/* ---------- 外壳 ---------- */

#app {
  position: absolute;
  inset: 0;
  height: var(--app-height, 100dvh);
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--cream);
  overflow: hidden;
}

@media (min-width: 700px) {
  #app {
    box-shadow: 0 0 90px rgba(0, 0, 0, 0.35);
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
  }
}

.view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- 列表页 ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) 18px 8px;
  min-height: 56px;
}

.brand {
  font-family: var(--font-display);
  font-size: 28px;
  letter-spacing: 0.02em;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  margin-top: 8px;
}

.topbar-title {
  flex: 1;
  text-align: center;
  font-weight: 600;
  font-size: 16px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--ink-soft);
  transition: background 0.16s ease;
}

.icon-btn:active {
  background: var(--line);
}

.icon-btn.is-ghost {
  visibility: hidden;
}

.search-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 16px 10px;
  padding: 0 12px;
  height: 40px;
  border-radius: 13px;
  background: color-mix(in srgb, var(--ink) 5%, transparent);
  color: var(--muted);
}

.search-row input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: none;
  color: var(--ink);
  font-size: 15px;
}

.search-row input::placeholder {
  color: var(--faint);
}

.list-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 8px calc(env(safe-area-inset-bottom) + 18px);
}

.friend-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 10px;
  border-radius: 15px;
  text-align: left;
  transition: background 0.14s ease;
}

.friend-row:active {
  background: color-mix(in srgb, var(--ink) 6%, transparent);
}

.friend-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.friend-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.friend-line strong {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.friend-line time {
  margin-left: auto;
  font-size: 11px;
  color: var(--faint);
  flex: none;
}

.friend-preview {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- 头像 ---------- */

.avatar {
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 32%;
  background: var(--avatar-color, #73866d);
  color: #fff;
  overflow: hidden;
  font-weight: 600;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-xs {
  width: 28px;
  height: 28px;
  font-size: 13px;
}

.avatar-sm {
  width: 34px;
  height: 34px;
  font-size: 15px;
}

.avatar-md {
  width: 48px;
  height: 48px;
  font-size: 20px;
}

/* ---------- 空状态 ---------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  padding: 64px 34px 40px;
  color: var(--muted);
}

.empty-mark {
  width: 64px;
  height: 64px;
  border-radius: 22px;
  display: grid;
  place-items: center;
  background: linear-gradient(150deg, #2b3129, #1e231e);
  color: #e8c8a7;
  font-family: var(--font-display);
  font-size: 30px;
  margin-bottom: 6px;
}

.empty strong {
  color: var(--ink);
  font-size: 17px;
}

.empty p {
  margin: 0;
  font-size: 14px;
  line-height: 1.65;
}

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

.chatbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(env(safe-area-inset-top) + 6px) 6px 6px;
  min-height: 56px;
  background: color-mix(in srgb, var(--cream) 86%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.chat-person {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.chat-person strong {
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-person small {
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.messages {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 14px 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--cream);
}

.messages::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: var(--wallpaper, none);
  background-size: var(--wallpaper-fit, cover);
  background-position: center;
  opacity: 0.9;
  pointer-events: none;
  z-index: 0;
}

.messages::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--cream);
  opacity: var(--wallpaper-dim, 0);
  pointer-events: none;
  z-index: 0;
}

.messages.no-wallpaper::before {
  display: none;
}

.messages > * {
  position: relative;
  z-index: 1;
}

.load-more {
  align-self: center;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
  background: color-mix(in srgb, var(--ink) 6%, transparent);
}

.day-divider {
  align-self: center;
  margin: 8px 0 2px;
  font-size: 11px;
  color: var(--muted);
  padding: 3px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--ink) 5%, transparent);
}

.chat-empty {
  margin: auto;
  text-align: center;
  color: var(--muted);
  padding: 24px;
  max-width: 320px;
}

.chat-empty strong {
  display: block;
  color: var(--ink-soft);
  font-weight: 500;
  font-family: var(--font-display);
  font-size: 17px;
  line-height: 1.6;
  margin-bottom: 8px;
}

.msg {
  display: flex;
  max-width: 100%;
}

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

.msg-friend {
  justify-content: flex-start;
}

.bubble {
  max-width: 82%;
  padding: 9px 13px 7px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.55;
  word-break: break-word;
  overflow-wrap: anywhere;
  animation: bubble-in 0.18s ease both;
}

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

.msg-friend .bubble {
  background: var(--paper);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
  box-shadow: 0 1px 2px rgba(20, 24, 20, 0.04);
}

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

.bubble p {
  margin: 0 0 2px;
}

.bubble p:last-child {
  margin-bottom: 0;
}

.bubble .code-block {
  margin: 6px 0;
  padding: 9px 11px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--ink) 7%, transparent);
  font-size: 12.5px;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.bubble .inline-code {
  padding: 1px 5px;
  border-radius: 5px;
  background: color-mix(in srgb, var(--ink) 8%, transparent);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.92em;
}

.msg-user .inline-code,
.msg-user .code-block {
  background: rgba(255, 255, 255, 0.18);
}

.bubble a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.bubble-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10.5px;
  opacity: 0.62;
  margin-top: 3px;
}

.msg-user .bubble-meta {
  justify-content: flex-end;
}

.msg-note {
  padding: 0 5px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.14);
}

.bubble.is-pending .bubble-text:empty::after,
.typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  height: 18px;
}

.typing i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.45;
  animation: typing 1s infinite ease-in-out;
}

.typing i:nth-child(2) {
  animation-delay: 0.15s;
}

.typing i:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes typing {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.35;
  }
  30% {
    transform: translateY(-3px);
    opacity: 0.9;
  }
}

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

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 9px 12px calc(env(safe-area-inset-bottom) + 9px);
  background: color-mix(in srgb, var(--cream) 92%, transparent);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}

.composer textarea {
  flex: 1;
  min-width: 0;
  max-height: 132px;
  padding: 10px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  background: var(--paper);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
  resize: none;
  outline: none;
}

.composer textarea:focus {
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
}

.composer textarea:disabled {
  opacity: 0.55;
}

.send {
  flex: none;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  transition: transform 0.12s ease, opacity 0.12s ease;
}

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

.send:disabled {
  opacity: 0.35;
}

.send.is-stop {
  background: color-mix(in srgb, var(--ink) 12%, transparent);
  color: var(--ink);
  font-size: 13px;
}

/* ---------- 设置 ---------- */

.settings-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 16px calc(env(safe-area-inset-bottom) + 30px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.card.is-ok {
  border-color: color-mix(in srgb, var(--ok) 40%, transparent);
}

.card.is-bad {
  border-color: color-mix(in srgb, var(--danger) 40%, transparent);
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.bullets {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.bullets strong {
  color: var(--ink-soft);
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px;
  color: var(--faint);
  word-break: break-all;
}

.btn-row {
  display: flex;
  gap: 8px;
}

.btn {
  flex: 1;
  min-height: 42px;
  padding: 0 14px;
  border-radius: 13px;
  border: 1px solid var(--line-strong);
  background: var(--paper);
  color: var(--ink);
  font-size: 14.5px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform 0.12s ease, background 0.16s ease;
}

.btn:active {
  transform: scale(0.985);
}

.btn-primary {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}

.btn-soft {
  background: color-mix(in srgb, var(--ink) 6%, transparent);
  border-color: transparent;
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn-danger-ghost {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 30%, transparent);
  background: transparent;
}

.btn:disabled {
  opacity: 0.5;
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
}

.switch-row span:first-child {
  display: flex;
  flex-direction: column;
}

.switch-row strong {
  font-size: 14px;
  font-weight: 500;
}

.switch-row small {
  color: var(--muted);
  font-size: 12px;
}

.switch {
  position: relative;
  width: 48px;
  height: 28px;
  flex: none;
}

.switch input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
}

.switch i {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: color-mix(in srgb, var(--ink) 14%, transparent);
  transition: background 0.18s ease;
}

.switch i::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.18s ease;
}

.switch input:checked + i {
  background: var(--accent);
}

.switch input:checked + i::after {
  transform: translateX(20px);
}

.stats {
  margin: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 14px;
}

.stats > div {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.stats dt {
  font-size: 11.5px;
  color: var(--muted);
}

.stats dd {
  margin: 0;
  font-size: 14px;
  color: var(--ink);
}

.stats dd.mono {
  font-size: 11px;
}

.conn-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
}

.conn-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.35;
}

.conn-main small {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.text-btn {
  color: var(--accent);
  font-size: 13.5px;
  padding: 6px 4px;
}

.diag-ok {
  margin: 0;
  color: var(--ok);
  font-weight: 600;
  font-size: 14px;
}

.diag-bad {
  margin: 0;
  color: var(--danger);
  font-weight: 600;
  font-size: 14px;
  line-height: 1.5;
}

.detail {
  margin: 0;
  padding: 10px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--ink) 5%, transparent);
  font-size: 11.5px;
  color: var(--ink-soft);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 180px;
  overflow: auto;
}

/* ---------- 弹层 ---------- */

#sheetRoot {
  position: fixed;
  inset: 0;
  z-index: 40;
  pointer-events: none;
}

#sheetRoot.is-open {
  pointer-events: auto;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(12, 15, 12, 0.42);
  opacity: 0;
  transition: opacity 0.2s ease;
  backdrop-filter: blur(2px);
}

#sheetRoot.is-open .sheet-backdrop {
  opacity: 1;
}

.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: 640px;
  margin: 0 auto;
  max-height: 86vh;
  overflow-y: auto;
  padding: 10px 18px calc(env(safe-area-inset-bottom) + 20px);
  background: var(--paper);
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -16px 60px rgba(0, 0, 0, 0.25);
  transform: translateY(14px);
  opacity: 0;
  transition: transform 0.24s var(--ease, cubic-bezier(0.22, 1, 0.36, 1)), opacity 0.2s ease;
}

#sheetRoot.is-open .sheet {
  transform: none;
  opacity: 1;
}

.sheet-tall {
  max-height: 92vh;
}

.sheet-grab {
  width: 38px;
  height: 4px;
  border-radius: 999px;
  background: var(--line-strong);
  margin: 4px auto 12px;
}

.sheet h2 {
  margin: 0 0 10px;
  font-size: 18px;
  font-weight: 600;
}

.sheet p {
  margin: 0 0 14px;
}

.menu-list {
  display: flex;
  flex-direction: column;
  margin: 4px -6px 0;
}

.menu-list button {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 8px;
  border-radius: 12px;
  text-align: left;
  color: var(--ink);
}

.menu-list button:active {
  background: color-mix(in srgb, var(--ink) 6%, transparent);
}

.menu-list button span {
  flex: 1;
  font-size: 15px;
}

.menu-list button small {
  color: var(--muted);
  font-size: 12px;
}

.menu-list button.danger {
  color: var(--danger);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.field > span {
  font-size: 12.5px;
  color: var(--muted);
}

.field small {
  color: var(--faint);
  font-size: 11.5px;
}

.input {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: color-mix(in srgb, var(--ink) 3%, var(--paper));
  color: var(--ink);
  font-size: 14.5px;
  outline: none;
  -webkit-appearance: none;
}

.input:focus {
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
}

textarea.input {
  resize: vertical;
  line-height: 1.55;
  font-size: 14px;
}

.persona-rows {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.persona-rows > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.persona-rows dt {
  font-size: 11.5px;
  color: var(--muted);
}

.persona-rows dd {
  margin: 0;
  font-size: 14px;
  color: var(--ink-soft);
  line-height: 1.6;
}

/* ---------- Toast ---------- */

#toastRoot {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 10px);
  left: 0;
  right: 0;
  z-index: 60;
  display: flex;
  justify-content: center;
  padding: 0 16px;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

#toastRoot.is-on {
  opacity: 1;
  transform: none;
}

.toast {
  max-width: 460px;
  padding: 10px 15px;
  border-radius: 14px;
  background: rgba(28, 33, 28, 0.94);
  color: #f6f2ea;
  font-size: 13.5px;
  line-height: 1.5;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.toast span {
  opacity: 0.75;
  font-size: 12px;
}

.toast-error {
  background: rgba(120, 43, 36, 0.96);
}

.toast-success {
  background: rgba(43, 74, 47, 0.96);
}

/* ---------- 启动屏 ---------- */

#boot {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  background: #1c211c;
  color: #f3ece0;
}

.boot-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.boot-mark {
  width: 66px;
  height: 66px;
  border-radius: 22px;
  display: grid;
  place-items: center;
  background: linear-gradient(150deg, #3a4438, #232923);
  font-family: var(--font-display);
  font-size: 32px;
  color: #e8c8a7;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.boot-inner strong {
  font-size: 17px;
  letter-spacing: 0.08em;
}

.boot-inner .dots {
  display: inline-flex;
  gap: 5px;
}

.boot-inner .dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #cfc7b8;
  opacity: 0.4;
  animation: typing 1.1s infinite ease-in-out;
}

.boot-inner .dots i:nth-child(2) {
  animation-delay: 0.15s;
}

.boot-inner .dots i:nth-child(3) {
  animation-delay: 0.3s;
}

.boot-error {
  max-width: 340px;
  text-align: center;
  padding: 24px;
}

.boot-error strong {
  display: block;
  font-size: 17px;
  margin-bottom: 8px;
}

.boot-error p {
  margin: 0 0 8px;
  color: #c9c2b4;
  font-size: 13.5px;
  line-height: 1.6;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
