:root {
  color-scheme: light;
  --bg-chat: #efeae2;
  --bg-app: #f0f2f5;
  --teal: #0b7c6f;
  --teal-dark: #075e54;
  --bubble-in: #ffffff;
  --bubble-out: #d9fdd3;
  --text: #111b21;
  --text-soft: #667781;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg-app);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 640px;
  margin: 0 auto;
  background: var(--bg-chat);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(10px + var(--safe-top)) 14px 10px;
  background: var(--teal-dark);
  color: #fff;
  flex: none;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--teal);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 15px;
  flex: none;
}

.topbar-name {
  font-weight: 600;
  font-size: 16px;
  line-height: 1.2;
}

.topbar-sub {
  font-size: 12.5px;
  opacity: 0.85;
}

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  -webkit-overflow-scrolling: touch;
}

.bubble {
  max-width: 78%;
  padding: 7px 10px 8px;
  border-radius: 9px;
  font-size: 15px;
  line-height: 1.4;
  box-shadow: 0 1px 0.5px rgba(0,0,0,0.13);
  white-space: pre-wrap;
  word-wrap: break-word;
  position: relative;
}

.bubble.in {
  align-self: flex-start;
  background: var(--bubble-in);
  border-top-left-radius: 2px;
}

.bubble.out {
  align-self: flex-end;
  background: var(--bubble-out);
  border-top-right-radius: 2px;
}

.bubble .time {
  display: block;
  text-align: right;
  font-size: 10.5px;
  color: var(--text-soft);
  margin-top: 2px;
}

.bubble.typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 14px;
}

.bubble.typing .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-soft);
  animation: blink 1.2s infinite ease-in-out;
}
.bubble.typing .dot:nth-child(2) { animation-delay: 0.2s; }
.bubble.typing .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
  0%, 80%, 100% { opacity: 0.25; }
  40% { opacity: 1; }
}

.composer {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 10px calc(8px + var(--safe-bottom));
  background: var(--bg-app);
}

.composer-input {
  flex: 1;
  resize: none;
  max-height: 120px;
  border: none;
  border-radius: 20px;
  padding: 10px 14px;
  font-size: 15px;
  font-family: inherit;
  background: #fff;
  outline: none;
  line-height: 1.35;
}

.send-btn {
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--teal);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.send-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.gate {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px;
  gap: 14px;
  background: var(--bg-app);
}

.gate h1 { font-size: 19px; margin: 0; }
.gate p { color: var(--text-soft); font-size: 14.5px; margin: 0; max-width: 320px; }
