:root {
  --bg-outer: #eef3ec;
  --bg-app: #f4f7f3;
  --header-bg: #d6e4d8;
  --avatar-bg: #ffffff;
  --avatar-text: #4a5d54;
  --name-text: #4a5d54;
  --status-text: #93a89a;
  --bubble-friend-bg: #ffffff;
  --bubble-friend-border: #e0e8df;
  --bubble-friend-text: #2a3530;
  --bubble-user-bg: #7a98a8;
  --bubble-user-text: #ffffff;
  --input-wrap-bg: #ffffff;
  --input-wrap-border: #e0e8df;
  --input-text: #2a3530;
  --input-placeholder: #a8b5ac;
  --send-bg: #7a98a8;
  --send-disabled: #c8d5cc;
  --dot-color: #a3b5ab;
  --privacy-text: #93a89a;
  --intro-bg: #eef3ec;
  --intro-name: #4a5d54;
  --intro-line: #3a4a42;
  --intro-small: #8a9a90;
}

[data-theme="dark"] {
  --bg-outer: #141a17;
  --bg-app: #1a211e;
  --header-bg: #222b27;
  --avatar-bg: #2e3a34;
  --avatar-text: #c8d5cc;
  --name-text: #d8e4dc;
  --status-text: #7a8a80;
  --bubble-friend-bg: #252e2a;
  --bubble-friend-border: #2e3a34;
  --bubble-friend-text: #dde5e0;
  --bubble-user-bg: #6b8694;
  --bubble-user-text: #ffffff;
  --input-wrap-bg: #252e2a;
  --input-wrap-border: #2e3a34;
  --input-text: #dde5e0;
  --input-placeholder: #6a7a70;
  --send-bg: #6b8694;
  --send-disabled: #3a4a42;
  --dot-color: #5a6a60;
  --privacy-text: #6a7a70;
  --intro-bg: #141a17;
  --intro-name: #d8e4dc;
  --intro-line: #c8d5cc;
  --intro-small: #7a8a80;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  background: var(--bg-outer);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  color: var(--bubble-friend-text);
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s;
}

body {
  display: flex;
  justify-content: center;
}

#app {
  width: 100%;
  max-width: 640px;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg-app);
  box-shadow: 0 0 30px rgba(60, 90, 75, 0.06);
  transition: background 0.3s;
}

.header {
  padding: 0.85rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  background: var(--header-bg);
  border-bottom: none;
  box-shadow: 0 1px 4px rgba(60, 90, 75, 0.06);
  position: relative;
  z-index: 2;
  transition: background 0.3s;
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--avatar-bg);
  color: var(--avatar-text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 500;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}

.header-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.2;
}

.name {
  font-size: 15px;
  font-weight: 500;
  color: var(--name-text);
  letter-spacing: 0.3px;
}

.status {
  font-size: 11.5px;
  color: var(--status-text);
  font-weight: 400;
  margin-top: 2px;
  letter-spacing: 0.2px;
}

.header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--name-text);
  transition: background 0.2s;
}

.icon-btn:hover {
  background: rgba(0,0,0,0.06);
}

.messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1.5rem 1.25rem;
  background: transparent;
  scrollbar-width: thin;
  scrollbar-color: var(--send-disabled) transparent;
}

.bubble {
  max-width: 78%;
  padding: 9px 14px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.5;
  word-wrap: break-word;
  animation: fadeUp 0.25s ease;
}

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

.bubble.friend {
  background: var(--bubble-friend-bg);
  border: 1px solid var(--bubble-friend-border);
  color: var(--bubble-friend-text);
  align-self: flex-start;
  border-bottom-left-radius: 5px;
}

.bubble.user {
  background: var(--bubble-user-bg);
  color: var(--bubble-user-text);
  align-self: flex-end;
  border-bottom-right-radius: 5px;
}

.bubble.thinking {
  background: var(--bubble-friend-bg);
  border: 1px solid var(--bubble-friend-border);
  align-self: flex-start;
  border-bottom-left-radius: 5px;
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 13px 16px;
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--dot-color);
  animation: bounce 1.2s infinite ease;
}

.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40%           { transform: translateY(-4px); }
}

.input-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0.75rem 1rem 1rem;
  background: transparent;
  border-top: none;
}

.input-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--input-wrap-bg);
  border-radius: 26px;
  padding: 4px 6px 4px 4px;
  box-shadow: 0 2px 12px rgba(60, 90, 75, 0.08);
  border: 1px solid var(--input-wrap-border);
  transition: border-color 0.2s, box-shadow 0.2s, background 0.3s;
}

.input-wrap:focus-within {
  border-color: #b8c6cd;
  box-shadow: 0 2px 16px rgba(60, 90, 75, 0.12);
}

textarea {
  flex: 1;
  border: none;
  border-radius: 22px;
  padding: 10px 14px;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.4;
  color: var(--input-text);
  background: transparent;
  resize: none;
  outline: none;
  min-height: 38px;
  max-height: 120px;
  overflow-y: auto;
  scrollbar-width: none;
}

textarea::-webkit-scrollbar {
  display: none;
}

textarea::placeholder {
  color: var(--input-placeholder);
}

#sendBtn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--send-bg);
  color: #ffffff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.2s, transform 0.1s, background 0.3s;
}

#sendBtn svg {
  transform: translateX(-1px) translateY(1px);
}

#sendBtn:hover { opacity: 0.9; }
#sendBtn:active { transform: scale(0.95); }
#sendBtn:disabled {
  background: var(--send-disabled);
  cursor: not-allowed;
}

.privacy-note {
  width: 100%;
  text-align: center;
  font-size: 11px;
  color: var(--privacy-text);
  padding: 0 1.5rem 0.75rem;
  line-height: 1.5;
  letter-spacing: 0.2px;
}

.intro-screen {
  position: fixed;
  inset: 0;
  background: var(--intro-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
  z-index: 1000;
  transition: background 0.3s;
}

.intro-content {
  max-width: 420px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.intro-name {
  font-size: 26px;
  font-weight: 600;
  color: var(--intro-name);
  letter-spacing: 0.5px;
  margin-bottom: 0.5rem;
}

.intro-line {
  font-size: 16px;
  line-height: 1.6;
  color: var(--intro-line);
}

.intro-small {
  font-size: 13px;
  line-height: 1.55;
  color: var(--intro-small);
  margin-top: 0.3rem;
}

#introStart {
  margin-top: 1.2rem;
  align-self: center;
  background: var(--send-bg);
  color: #ffffff;
  border: none;
  border-radius: 24px;
  padding: 12px 40px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
}

#introStart:hover { opacity: 0.9; }
#introStart:active { transform: scale(0.97); }

.intro-theme-toggle {
  position: fixed;
  top: 1.25rem;
  right: 1.25rem;
}

.intro-screen.hidden {
  display: none;
}

@media (max-width: 500px) {
  #app {
    box-shadow: none;
  }
  .messages {
    padding: 1rem 0.9rem;
  }
  .bubble {
    max-width: 82%;
    font-size: 14.5px;
  }
  .input-area {
    padding: 0.6rem 0.75rem;
  }
  .privacy-note {
    font-size: 10.5px;
    padding: 0 1rem 0.6rem;
  }
}