:root {
  --wechat-bg: #ededed;
  --wechat-green: #95ec69;
  --wechat-green-active: #89d961;
  --wechat-text: #1a1a1a;
  --wechat-text-light: #999;
  --bubble-radius: 12px;
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body, html {
  height: 100%;
  width: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Helvetica, Arial, sans-serif;
  background-color: var(--wechat-bg);
  overflow: hidden;
  overscroll-behavior-y: none;
}

/* Screens */
.screen {
  display: none;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* Auth Screen (Rich Aesthetics) */
#auth-screen {
  background: linear-gradient(135deg, #1e1e1e, #121212);
  color: white;
  justify-content: center;
  align-items: center;
}

.auth-container {
  background: rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  padding: 40px;
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  text-align: center;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
  width: 90%;
  max-width: 400px;
  transform: translateY(-20px);
  animation: authFadeIn 0.8s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  opacity: 0;
}

@keyframes authFadeIn {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.auth-logo {
  font-size: 64px;
  margin-bottom: 16px;
}

.auth-title {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 8px;
  letter-spacing: 1px;
}

.auth-subtitle {
  font-size: 14px;
  color: #aaa;
  margin-bottom: 32px;
}

.auth-input {
  width: 100%;
  padding: 16px 20px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.2);
  color: white;
  font-size: 16px;
  outline: none;
  transition: all 0.3s ease;
  margin-bottom: 24px;
  text-align: center;
}

.auth-input:focus {
  border-color: var(--wechat-green);
  box-shadow: 0 0 0 3px rgba(149, 236, 105, 0.2);
}

.auth-btn {
  width: 100%;
  padding: 16px;
  border-radius: 12px;
  border: none;
  background: var(--wechat-green);
  color: #111;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease;
}

.auth-btn:active {
  transform: scale(0.98);
  background: var(--wechat-green-active);
}

.auth-btn.loading {
  opacity: 0.8;
  pointer-events: none;
}

.auth-error {
  color: #ff4d4f;
  margin-top: 16px;
  font-size: 14px;
  height: 20px;
}

/* Chat Screen */
#chat-screen {
  background-color: var(--wechat-bg);
}

/* Header */
.chat-header {
  height: calc(44px + var(--safe-area-top));
  padding-top: var(--safe-area-top);
  background: #ededed;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 16px;
  padding-right: 16px;
  border-bottom: 0.5px solid rgba(0,0,0,0.1);
  position: relative;
  z-index: 10;
}

/* Glassmorphism for header to look iOS native */
@supports (backdrop-filter: blur(20px)) {
  .chat-header {
    background: rgba(237, 237, 237, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
  }
}

.header-left, .header-right {
  width: 60px;
  font-size: 28px;
  color: #1a1a1a;
  display: flex;
  align-items: center;
  cursor: pointer;
}

.header-right {
  justify-content: flex-end;
  font-size: 20px;
  letter-spacing: 2px;
}

.header-center {
  flex: 1;
  text-align: center;
}

.header-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--wechat-text);
}

/* Chat Area */
.chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  -webkit-overflow-scrolling: touch;
}

.chat-message {
  display: flex;
  max-width: 85%;
  animation: messageSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes messageSlideIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-message.received {
  align-self: flex-start;
  flex-direction: row;
}

.chat-message.sent {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  flex-shrink: 0;
}

.chat-message.received .avatar {
  margin-right: 12px;
}

.chat-message.sent .avatar {
  margin-left: 12px;
}

.bubble {
  padding: 12px 16px;
  font-size: 16px;
  line-height: 1.5;
  color: var(--wechat-text);
  word-wrap: break-word;
  white-space: pre-wrap;
  position: relative;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.chat-message.received .bubble {
  background-color: #fff;
  border-radius: 0 var(--bubble-radius) var(--bubble-radius) var(--bubble-radius);
}

.chat-message.sent .bubble {
  background-color: var(--wechat-green);
  border-radius: var(--bubble-radius) 0 var(--bubble-radius) var(--bubble-radius);
}

/* Typing Indicator Bubble */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 24px;
}

.typing-dot {
  width: 6px;
  height: 6px;
  background-color: #999;
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}


/* Footer Input */
.chat-footer {
  padding: 10px 16px calc(10px + var(--safe-area-bottom));
  background-color: #f7f7f7;
  border-top: 0.5px solid rgba(0,0,0,0.1);
  display: flex;
  align-items: flex-end;
  gap: 12px;
}

.input-wrapper {
  flex: 1;
  background: #fff;
  border-radius: 8px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
}

#message-input {
  width: 100%;
  max-height: 100px;
  border: none;
  outline: none;
  font-size: 16px;
  resize: none;
  font-family: inherit;
  line-height: 1.4;
  background: transparent;
  padding: 0;
}

.send-btn {
  background: var(--wechat-green);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  height: 40px; /* match single line textarea approx */
  transition: background 0.2s ease, opacity 0.2s ease;
}

.send-btn:active {
  background: var(--wechat-green-active);
}

.send-btn.disabled {
  background: #e0e0e0;
  color: #a0a0a0;
  pointer-events: none;
}
