:root {
  color-scheme: light;
  --wechat-bg: #ededed;
  --wechat-bar: #f7f7f7;
  --wechat-border: #d8d8d8;
  --wechat-green: #95ec69;
  --wechat-text: #111;
  --wechat-name: #888;
  --avatar-size: 40px;
  --composer-height: 58px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #d6d6d6;
  color: var(--wechat-text);
}

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

#app {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  width: 100%;
  max-width: 430px;
  height: 100dvh;
  margin-inline: auto;
  overflow: hidden;
  background: var(--wechat-bg);
  box-shadow: 0 0 22px rgb(0 0 0 / 8%);
}

.chat-header {
  position: relative;
  z-index: 10;
  grid-row: 1;
  grid-column: 1;
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) 56px;
  align-items: end;
  min-height: calc(54px + var(--safe-top));
  padding-top: var(--safe-top);
  border-bottom: 0.5px solid var(--wechat-border);
  background: rgb(247 247 247 / 96%);
}

.header-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 54px;
  padding: 0;
  border: 0;
  background: transparent;
}

.back-button {
  padding: 0 10px 0 0;
}

.menu-button {
  padding: 0 0 0 8px;
}

.lucide {
  width: 24px;
  height: 24px;
  stroke-width: 2;
}

.header-title-block {
  align-self: stretch;
  display: flex;
  min-width: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-top: 3px;
}

#group-title {
  max-width: 100%;
  margin: 0;
  overflow: hidden;
  font-size: 17px;
  font-weight: 500;
  line-height: 22px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#typing-status {
  min-height: 14px;
  margin: -1px 0 0;
  color: #8a8a8a;
  font-size: 10px;
  line-height: 14px;
}

#typing-status:empty { display: none; }

.message-list {
  grid-row: 2;
  grid-column: 1;
  min-width: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 18px 12px 24px;
  overscroll-behavior: contain;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.message-list::-webkit-scrollbar { display: none; }

.message-row {
  display: flex;
  width: 100%;
  gap: 9px;
  margin: 0 0 17px;
  animation: message-in 160ms ease-out both;
}

.message-row.outgoing { flex-direction: row-reverse; }

.message-avatar {
  width: var(--avatar-size);
  height: var(--avatar-size);
  flex: 0 0 var(--avatar-size);
  border-radius: 4px;
  object-fit: cover;
  background: #ddd;
}

.message-stack {
  display: flex;
  min-width: 0;
  max-width: calc(100% - var(--avatar-size) - 30px);
  flex-direction: column;
  align-items: flex-start;
}

.outgoing .message-stack { align-items: flex-end; }

.message-name {
  min-height: 16px;
  margin: -2px 0 3px 1px;
  color: var(--wechat-name);
  font-size: 12px;
  line-height: 16px;
}

.outgoing .message-name { display: none; }

.message-bubble {
  position: relative;
  max-width: 100%;
  padding: 9px 11px;
  border-radius: 5px;
  background: #fff;
  font-size: 16px;
  line-height: 1.38;
  overflow-wrap: anywhere;
  box-shadow: 0 0 0 0.5px rgb(0 0 0 / 3%);
}

.incoming .message-bubble::before,
.outgoing .message-bubble::before {
  position: absolute;
  top: 12px;
  width: 0;
  height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  content: "";
}

.incoming .message-bubble::before {
  left: -6px;
  border-right: 7px solid #fff;
}

.outgoing .message-bubble {
  background: var(--wechat-green);
}

.outgoing .message-bubble::before {
  right: -6px;
  border-left: 7px solid var(--wechat-green);
}

.message-bubble.image-bubble {
  overflow: hidden;
  padding: 0;
  background: transparent;
  box-shadow: none;
}

.message-bubble.image-bubble::before { display: none; }

.chat-image {
  display: block;
  width: min(180px, 52vw);
  height: auto;
  max-width: min(180px, 52vw);
  max-height: 240px;
  aspect-ratio: var(--media-aspect-ratio);
  border-radius: 5px;
  object-fit: cover;
}

.message-bubble.image-error {
  padding: 9px 11px;
  background: #fff;
  color: #777;
  font-size: 13px;
}

.system-message {
  width: 100%;
  margin: 4px 0 18px;
  color: #aaa;
  font-size: 12px;
  line-height: 18px;
  text-align: center;
}

.chat-timestamp {
  width: 100%;
  margin: 2px 0 18px;
  color: #aaa;
  font-size: 12px;
  line-height: 18px;
  text-align: center;
}

.ending-card-inline {
  width: 100%;
  margin: 8px 0 22px;
  overflow: hidden;
  border: 0.5px solid #d5d5d5;
  border-radius: 7px;
  background: #fff;
  box-shadow: 0 1px 3px rgb(0 0 0 / 4%);
  animation: message-in 160ms ease-out both;
}

.ending-card-title {
  margin: 0;
  padding: 19px 18px 11px;
  font-size: 18px;
  font-weight: 600;
  line-height: 25px;
  text-align: center;
}

.ending-card-copy {
  margin: 0;
  padding: 0 18px 20px;
  color: #333;
  font-size: 14px;
  line-height: 1.75;
  white-space: pre-line;
}

.choice-panel {
  z-index: 15;
  grid-row: 3;
  grid-column: 1;
  padding: 8px 12px;
  border-top: 0.5px solid var(--wechat-border);
  background: rgb(237 237 237 / 97%);
}

.choice-panel[hidden] { display: none; }

.choice-button {
  display: block;
  width: 100%;
  min-height: 44px;
  margin: 0 0 7px;
  padding: 10px 13px;
  border: 0;
  border-radius: 5px;
  background: #fff;
  font-size: 15px;
  line-height: 20px;
  text-align: left;
}

.choice-button:last-child { margin-bottom: 0; }
.choice-button:active { background: #e5e5e5; }
.choice-button:disabled { opacity: 0.55; }

.composer {
  z-index: 20;
  grid-row: 4;
  grid-column: 1;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 39px 39px;
  align-items: center;
  min-height: calc(var(--composer-height) + var(--safe-bottom));
  padding: 7px 7px calc(7px + var(--safe-bottom));
  border-top: 0.5px solid var(--wechat-border);
  background: var(--wechat-bar);
}

.composer-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 42px;
  padding: 0;
  border: 0;
  background: transparent;
}

#composer-input {
  width: 100%;
  height: 40px;
  min-width: 0;
  padding: 0 10px;
  border: 0;
  border-radius: 5px;
  outline: 0;
  background: #fff;
  color: #222;
  font-size: 16px;
  caret-color: transparent;
}

#composer-input:focus { box-shadow: inset 0 0 0 1px rgb(0 0 0 / 4%); }

.scroll-to-bottom {
  z-index: 12;
  grid-row: 2;
  grid-column: 1;
  align-self: end;
  justify-self: end;
  width: 34px;
  height: 34px;
  margin: 0 13px 14px 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgb(255 255 255 / 95%);
  box-shadow: 0 2px 9px rgb(0 0 0 / 14%);
  color: #777;
  font-size: 19px;
}

.topic-sheet {
  position: absolute;
  z-index: 40;
  inset: 0;
}

.topic-sheet[hidden] { display: none; }

.topic-backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  border: 0;
  background: rgb(0 0 0 / 26%);
}

.topic-dialog {
  position: absolute;
  right: 0;
  bottom: calc(var(--composer-height) + var(--safe-bottom));
  left: 0;
  padding: 8px 12px;
  border-top: 0.5px solid var(--wechat-border);
  background: var(--wechat-bar);
}

.topic-list {
  --topic-row-height: 46px;
  height: calc(var(--topic-row-height) * 3);
  overflow-y: auto;
  border-radius: 5px;
  background: #fff;
  overscroll-behavior: contain;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.topic-list::-webkit-scrollbar { display: none; }

.topic-item,
.topic-row-reserve {
  display: block;
  width: 100%;
  height: var(--topic-row-height);
  border: 0;
  border-bottom: 0.5px solid #e5e5e5;
  background: #fff;
}

.topic-item {
  padding: 0 15px;
  overflow: hidden;
  font-size: 15px;
  line-height: var(--topic-row-height);
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topic-item:active { background: #ececec; }
.topic-item[aria-disabled="true"] { color: #999; }
.topic-row-reserve { border-bottom: 0; }

.notice {
  position: absolute;
  z-index: 50;
  top: calc(72px + var(--safe-top));
  left: 50%;
  max-width: calc(100% - 48px);
  padding: 8px 13px;
  border-radius: 4px;
  transform: translateX(-50%);
  background: rgb(0 0 0 / 68%);
  color: #fff;
  font-size: 13px;
  white-space: nowrap;
}

.unlock-toast {
  position: absolute;
  z-index: 70;
  top: 42%;
  left: 50%;
  max-width: calc(100% - 48px);
  padding: 11px 17px;
  border-radius: 7px;
  transform: translate(-50%, -50%);
  background: rgb(35 35 35 / 88%);
  box-shadow: 0 5px 18px rgb(0 0 0 / 18%);
  color: #fff;
  font-size: 14px;
  line-height: 20px;
  text-align: center;
  white-space: nowrap;
  animation: unlock-in 160ms ease-out both;
}

.unlock-toast[hidden] { display: none; }

@keyframes message-in {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes unlock-in {
  from { opacity: 0; transform: translate(-50%, calc(-50% + 5px)); }
  to { opacity: 1; transform: translate(-50%, -50%); }
}

@media (max-width: 360px) {
  .message-list { padding-inline: 10px; }
  .message-row { gap: 8px; }
  .message-bubble { font-size: 15px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
