* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  color: #10245a;
  background: #dbeeff;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  margin: 0;
  padding: 0;
  border: 0;
  color: inherit;
  background: transparent;
}

img {
  display: block;
}

.page {
  width: 100%;
  max-width: 520px;
  height: 100dvh;
  min-height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: linear-gradient(180deg, #f8fbff 0%, #eef6ff 54%, #e7f3ff 100%);
  box-shadow: 0 0 40px rgba(16, 36, 90, .18);
}

.hidden,
main {
  display: none;
}

main.active-view,
.chat-wrap.active-view {
  display: flex;
}

.app-header {
  position: relative;
  min-height: 88px;
  padding: 0 14px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 9px;
  background: rgba(255, 255, 255, .97);
  box-shadow: 0 4px 12px rgba(16, 36, 90, .1);
  z-index: 5;
  padding-top: env(safe-area-inset-top);
}

.brand {
  position: absolute;
  left: 14px;
  top: calc(34px + env(safe-area-inset-top));
  color: #14275e;
  font-size: 14px;
  line-height: 1.05;
  font-weight: 900;
  letter-spacing: 1px;
  transform: rotate(-8deg);
  transform-origin: left center;
}

.title {
  position: absolute;
  left: 14px;
  bottom: 9px;
  max-width: 160px;
  overflow: hidden;
  color: #14275e;
  font-size: 21px;
  line-height: 1.08;
  font-weight: 500;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.head-actions {
  position: absolute;
  right: 16px;
  bottom: 9px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.head-icon {
  width: 31px;
  height: 31px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #fff;
}

.head-icon img {
  width: 21px;
  height: 21px;
}

.top-add {
  background: #fff2af;
}

.head-action {
  min-width: 95px;
  height: 29px;
  padding: 0 11px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #bfeeff;
  color: #14275e;
  font-size: 13px;
  font-weight: 650;
}

.content {
  flex: 1;
  height: 0;
  width: 100%;
  flex-direction: column;
  overflow-y: auto;
  padding: 0 14px 88px;
  -webkit-overflow-scrolling: touch;
}

.search-box {
  width: 100%;
  height: 38px;
  margin-top: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 11px;
  border-radius: 9px;
  background: #fff;
  border: 1px solid rgba(20, 39, 94, .08);
}

.mini-search {
  position: relative;
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
}

.mini-search::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  width: 9px;
  height: 9px;
  border: 2px solid #14275e;
  border-radius: 50%;
}

.mini-search::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 1px;
  width: 7px;
  height: 2px;
  border-radius: 999px;
  background: #14275e;
  transform: rotate(45deg);
}

.search-box input,
.form-row input,
.composer textarea {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  color: #14275e;
  background: transparent;
}

.section-label {
  margin: 16px 0 10px;
  color: #14275e;
  font-size: 14px;
  font-weight: 700;
}

.section-label.inner {
  margin: 14px 0 4px;
  font-size: 13px;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.friend,
.template-card,
.memory-item,
.letter,
.notice-card,
.settings-card,
.profile-card,
.setup-panel,
.avatar-picker {
  background: rgba(255, 255, 255, .94);
  border: 1px solid rgba(20, 39, 94, .06);
  box-shadow: 0 6px 18px rgba(20, 39, 94, .07);
}

.friend {
  min-height: 72px;
  padding: 10px;
  display: flex;
  align-items: center;
  gap: 11px;
  border-radius: 12px;
}

.avatar,
.mini-avatar,
.profile-avatar {
  border-radius: 50%;
  object-fit: cover;
  background: #e3f3ff;
}

.avatar {
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
}

.group-avatar,
.mini-group-avatar {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 2px;
  overflow: hidden;
  border-radius: 12px;
  background: #e0f4ff;
}

.group-avatar {
  width: 48px;
  height: 48px;
}

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

.friend-main {
  flex: 1;
  min-width: 0;
}

.name-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.friend-name,
.template-name,
.letter-title,
.memory-text,
.settings-title,
.profile-name {
  color: #14275e;
  font-size: 17px;
  font-weight: 760;
}

.friend-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag,
.chips span {
  padding: 2px 7px;
  border-radius: 999px;
  background: #d9f3ff;
  color: #14275e;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.tag.blue {
  background: #d8ecff;
}

.tag.coral,
.chips span:nth-child(2n) {
  background: #fff0b2;
}

.last-line,
.template-desc,
.letter-desc,
.memory-meta,
.notice-text,
.profile-desc {
  margin-top: 3px;
  color: rgba(20, 39, 94, .72);
  font-size: 13px;
  line-height: 1.45;
}

.friend-meta {
  min-width: 36px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
  color: rgba(20, 39, 94, .55);
  font-size: 12px;
}

.unread {
  min-width: 17px;
  height: 17px;
  display: grid;
  place-items: center;
  padding: 0 5px;
  border-radius: 999px;
  color: #fff;
  background: #ff746d;
  font-size: 10px;
}

.chat-wrap {
  flex: 1;
  height: 100%;
  min-height: 0;
  flex-direction: column;
  background: linear-gradient(180deg, #f8fbff 0%, #eef6ff 58%, #e7f3ff 100%);
}

.chat-head {
  min-height: 78px;
  padding: calc(18px + env(safe-area-inset-top)) 12px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, .97);
  box-shadow: 0 4px 12px rgba(16, 36, 90, .1);
  z-index: 2;
}

.back-btn,
.more-btn,
.mic-btn,
.send-btn {
  position: relative;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #fff;
}

.back-btn::before {
  content: "";
  position: absolute;
  left: 14px;
  top: 11px;
  width: 11px;
  height: 11px;
  border-left: 2px solid #14275e;
  border-bottom: 2px solid #14275e;
  transform: rotate(45deg);
}

.more-btn::before {
  content: "";
  position: absolute;
  left: 9px;
  top: 16px;
  width: 18px;
  height: 2px;
  border-radius: 999px;
  background: #14275e;
  box-shadow: 0 -6px 0 #14275e, 0 6px 0 #14275e;
}

.mini-avatar,
.mini-group-avatar {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
}

.chat-title {
  flex: 1;
  min-width: 0;
}

.chat-name {
  font-size: 18px;
  font-weight: 800;
}

.chat-state {
  margin-top: 2px;
  color: rgba(20, 39, 94, .55);
  font-size: 12px;
}

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

.day {
  align-self: center;
  padding: 3px 9px;
  border-radius: 999px;
  color: rgba(20, 39, 94, .5);
  background: rgba(255, 255, 255, .7);
  font-size: 12px;
}

.bubble {
  max-width: 82%;
  padding: 10px 12px;
  border-radius: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.55;
  font-size: 15px;
}

.bubble.ai {
  align-self: flex-start;
  border-top-left-radius: 5px;
  background: #fff;
  box-shadow: 0 4px 12px rgba(20, 39, 94, .06);
}

.bubble.me {
  align-self: flex-end;
  border-top-right-radius: 5px;
  color: #14275e;
  background: #bfeeff;
}

.sender {
  margin: 2px 0 4px 4px;
  color: rgba(20, 39, 94, .55);
  font-size: 12px;
}

.memory-toast,
.explain-card,
.failed-toast,
.typing {
  align-self: center;
  max-width: 92%;
  padding: 8px 10px;
  border-radius: 12px;
  color: rgba(20, 39, 94, .72);
  background: rgba(255, 255, 255, .75);
  font-size: 12px;
  line-height: 1.5;
}

.explain-card {
  align-self: stretch;
  background: rgba(255, 255, 255, .92);
  border: 1px solid rgba(20, 39, 94, .06);
}

.explain-title {
  margin-bottom: 4px;
  color: #14275e;
  font-weight: 800;
}

.view-link {
  margin-left: 8px;
  color: #0c6eb8;
  font-size: 12px;
}

.composer {
  position: relative;
  min-height: 72px;
  padding: 9px 10px calc(11px + env(safe-area-inset-bottom));
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: rgba(255, 255, 255, .97);
  box-shadow: 0 -4px 12px rgba(16, 36, 90, .08);
}

.composer textarea {
  min-height: 36px;
  max-height: 110px;
  padding: 8px 10px;
  resize: none;
  border-radius: 18px;
  background: #eef6ff;
  font-size: 15px;
}

.mic-btn::before {
  content: "";
  position: absolute;
  left: 14px;
  top: 9px;
  width: 8px;
  height: 15px;
  border: 2px solid #14275e;
  border-radius: 999px;
}

.mic-btn::after {
  content: "";
  position: absolute;
  left: 11px;
  top: 24px;
  width: 14px;
  height: 8px;
  border-bottom: 2px solid #14275e;
  border-radius: 0 0 999px 999px;
}

.send-btn {
  background: #fff2af;
}

.send-btn::before {
  content: "";
  position: absolute;
  left: 12px;
  top: 10px;
  width: 13px;
  height: 13px;
  border-top: 2px solid #14275e;
  border-right: 2px solid #14275e;
  transform: rotate(45deg);
}

.voice-status {
  position: absolute;
  left: 56px;
  bottom: 1px;
  color: rgba(20, 39, 94, .42);
  font-size: 10px;
}

.template-card {
  min-height: 88px;
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-radius: 8px;
}

.template-card.selected {
  border-color: #bfeeff;
  box-shadow: 0 0 0 2px rgba(191, 238, 255, .8);
}

.template-main {
  flex: 1;
  min-width: 0;
}

.chips {
  margin-top: 7px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.avatar-picker {
  margin-top: 14px;
  padding: 12px;
  display: flex;
  gap: 14px;
  border-radius: 12px;
}

.avatar-large {
  width: 82px;
  height: 82px;
  border-radius: 50%;
  object-fit: cover;
}

.avatar-info {
  flex: 1;
  min-width: 0;
}

.notice-title {
  display: flex;
  align-items: center;
  gap: 7px;
  color: #14275e;
  font-size: 15px;
  font-weight: 800;
}

.small-icon {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #bfeeff;
}

.preset-row,
.member-picker {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.preset-row button {
  width: 40px;
  height: 40px;
  overflow: hidden;
  border-radius: 50%;
  border: 2px solid transparent;
}

.preset-row button.active {
  border-color: #14275e;
}

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

.setup-panel,
.notice-card,
.settings-card,
.profile-card {
  margin-top: 12px;
  padding: 14px;
  border-radius: 12px;
}

.form-row {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(20, 39, 94, .08);
}

.form-row span,
.setup-row span,
.switch-line span:first-child,
.settings-line span:first-child {
  flex: 0 0 86px;
  color: rgba(20, 39, 94, .75);
  font-size: 13px;
}

.setup-row,
.switch-line,
.settings-line {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
  border-bottom: 1px solid rgba(20, 39, 94, .06);
}

.setup-row input[type="range"] {
  flex: 1;
  accent-color: #14275e;
}

.strong-word,
.setup-row b {
  width: 22px;
  text-align: right;
  color: #14275e;
}

.primary-btn,
.secondary-btn,
.logout-btn,
.memory-actions button,
.letter-actions button {
  height: 38px;
  padding: 0 16px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  color: #14275e;
  background: #bfeeff;
  font-size: 14px;
  font-weight: 750;
}

.primary-btn {
  width: 100%;
  margin-top: 14px;
}

.logout-btn {
  width: auto;
  height: 30px;
  background: #fff2af;
}

.member-chip {
  height: 38px;
  padding: 0 10px 0 5px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  background: #eef6ff;
  border: 1px solid transparent;
}

.member-chip.active {
  border-color: #14275e;
  background: #bfeeff;
}

.member-chip img {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
}

.letter,
.memory-item {
  margin-bottom: 10px;
  padding: 13px;
  border-radius: 12px;
}

.letter-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.letter-date,
.memory-group {
  color: rgba(20, 39, 94, .55);
  font-size: 12px;
}

.letter-actions,
.memory-actions {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.memory-actions button,
.letter-actions button {
  width: auto;
  height: 30px;
  padding: 0 10px;
  font-size: 12px;
  background: #eef6ff;
}

.profile-card {
  display: flex;
  align-items: center;
  gap: 12px;
}

.profile-avatar {
  width: 56px;
  height: 56px;
}

.profile-main {
  flex: 1;
  min-width: 0;
}

.switch input {
  display: none;
}

.switch i {
  position: relative;
  width: 46px;
  height: 26px;
  display: block;
  border-radius: 999px;
  background: #dbe7f4;
}

.switch i::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform .18s ease;
  box-shadow: 0 2px 5px rgba(20, 39, 94, .2);
}

.switch input:checked + i {
  background: #14275e;
}

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

.empty-state {
  margin-top: 40px;
  color: rgba(20, 39, 94, .55);
  text-align: center;
  line-height: 1.7;
}

.tabbar {
  min-height: 72px;
  padding: 6px 6px calc(8px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  background: rgba(255, 255, 255, .97);
  box-shadow: 0 -4px 12px rgba(16, 36, 90, .08);
  z-index: 5;
}

.tab {
  height: 54px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border-radius: 14px;
  color: rgba(20, 39, 94, .65);
  font-size: 12px;
  font-weight: 700;
}

.tab.active {
  color: #14275e;
  background: #bfeeff;
}

.tab-icon-img {
  width: 20px;
  height: 20px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 88px;
  z-index: 50;
  max-width: min(320px, calc(100vw - 36px));
  padding: 10px 14px;
  border-radius: 999px;
  color: #fff;
  background: rgba(20, 39, 94, .86);
  font-size: 13px;
  opacity: 0;
  transform: translate(-50%, 12px);
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (min-width: 680px) {
  body {
    background: #cfe8ff;
  }

  .page {
    margin-top: 18px;
    height: calc(100dvh - 36px);
    min-height: 720px;
    border-radius: 24px;
    overflow: hidden;
  }
}
