/* Zai — ChatGPT-inspired mobile UI */

*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #000000;
  --text: #ffffff;
  --composer-bg: #1a1a1a;
  --bubble-user: #1a3a5c;
  --bubble-zai: #1e1e1e;
  --border-zai: rgba(255, 255, 255, 0.12);
  --muted: rgba(255, 255, 255, 0.45);
  --input-bg: #0d0d0d;
  --error-border: rgba(248, 113, 113, 0.45);
  --record: #ef4444;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --duration: 0.28s;
}

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.app {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  min-height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  background: var(--bg);
}

/* —— Header —— */
.app-header {
  flex-shrink: 0;
  padding: calc(0.65rem + env(safe-area-inset-top, 0px)) 1rem 0.5rem;
  text-align: center;
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
}

.brand__name {
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: rgba(255, 255, 255, 0.88);
}

.brand__full {
  font-size: 0.7rem;
  font-weight: 400;
  color: var(--muted);
  letter-spacing: 0.02em;
}

/* —— Chat area —— */
.chat-main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.welcome {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
  text-align: center;
  pointer-events: none;
  opacity: 1;
  transition: opacity var(--duration) var(--ease-out), transform var(--duration) var(--ease-out);
}

.welcome.is-hidden {
  opacity: 0;
  transform: translateY(-8px);
  visibility: hidden;
}

.welcome__logo {
  font-size: clamp(2.5rem, 10vw, 3.25rem);
  font-weight: 700;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.08);
  user-select: none;
}

.welcome__subtitle {
  margin: 0.35rem 0 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.welcome__hint {
  margin: 1.75rem 0 0;
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.35);
  max-width: 260px;
  line-height: 1.4;
}

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.5rem 0.75rem 0.75rem;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

.messages::-webkit-scrollbar {
  width: 4px;
}

.messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 4px;
}

/* —— Message rows —— */
.msg-row {
  display: flex;
  gap: 0.55rem;
  margin-bottom: 1rem;
  opacity: 0;
  animation: msg-in 0.38s var(--ease-out) forwards;
}

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

.msg-row--user {
  flex-direction: row;
  justify-content: flex-end;
}

.msg-row--zai,
.msg-row--error {
  flex-direction: row;
  justify-content: flex-start;
  align-items: flex-end;
}

.msg-row__content {
  display: flex;
  flex-direction: column;
  max-width: min(85%, 520px);
}

.msg-row--user .msg-row__content {
  align-items: flex-end;
}

.msg-row--zai .msg-row__content,
.msg-row--error .msg-row__content {
  align-items: flex-start;
}

/* Zai avatar */
.zai-avatar {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bubble-zai);
  border: 1px solid var(--border-zai);
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
  transition: border-color var(--duration) var(--ease-out), box-shadow var(--duration) var(--ease-out);
}

.zai-avatar__initial {
  font-size: 0.72rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.85);
  z-index: 1;
  transition: opacity 0.2s ease;
}

.zai-avatar__eq {
  position: absolute;
  inset: 0;
  display: none;
  align-items: flex-end;
  justify-content: center;
  gap: 2px;
  padding: 0 6px 7px;
  background: linear-gradient(180deg, transparent 0%, rgba(0, 0, 0, 0.35) 100%);
}

.zai-avatar__eq span {
  width: 3px;
  border-radius: 1px;
  background: rgba(255, 255, 255, 0.85);
  transform-origin: bottom;
  animation: eq-bar 0.55s ease-in-out infinite alternate;
}

.zai-avatar__eq span:nth-child(1) {
  height: 8px;
  animation-delay: 0s;
}

.zai-avatar__eq span:nth-child(2) {
  height: 14px;
  animation-delay: 0.12s;
}

.zai-avatar__eq span:nth-child(3) {
  height: 10px;
  animation-delay: 0.24s;
}

@keyframes eq-bar {
  from {
    transform: scaleY(0.35);
    opacity: 0.6;
  }
  to {
    transform: scaleY(1);
    opacity: 1;
  }
}

.zai-avatar.is-speaking .zai-avatar__initial {
  opacity: 0.25;
}

.zai-avatar.is-speaking .zai-avatar__eq {
  display: flex;
}

.zai-avatar.is-speaking {
  border-color: rgba(255, 255, 255, 0.22);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.06);
}

/* Bubbles */
.bubble {
  padding: 0.65rem 0.85rem;
  border-radius: 18px;
  font-size: 0.94rem;
  line-height: 1.45;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.bubble--user {
  background: var(--bubble-user);
  color: var(--text);
  border-bottom-right-radius: 6px;
}

.bubble--zai {
  background: var(--bubble-zai);
  color: var(--text);
  border: 1px solid var(--border-zai);
  border-bottom-left-radius: 6px;
}

.bubble--thinking {
  min-width: 4.5rem;
  padding: 0.75rem 1rem;
}

.bubble--error {
  background: #1a1010;
  color: #fecaca;
  border: 1px solid var(--error-border);
  border-bottom-left-radius: 6px;
}

.msg-row--error .msg-row__content {
  max-width: min(90%, 540px);
  margin-left: 40px;
}

.thinking-dots {
  display: inline-flex;
  gap: 0.15rem;
  align-items: center;
  color: var(--muted);
  font-weight: 700;
  letter-spacing: 0.05em;
}

.thinking-dots span {
  animation: dot-pulse 1.1s ease-in-out infinite;
}

.thinking-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.thinking-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes dot-pulse {
  0%,
  60%,
  100% {
    opacity: 0.25;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

.msg-time {
  font-size: 0.65rem;
  color: var(--muted);
  margin-top: 0.35rem;
  padding: 0 0.2rem;
}

/* —— Status strip —— */
.status-strip {
  flex-shrink: 0;
  min-height: 1.25rem;
  padding: 0 1rem 0.35rem;
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
  transition: color var(--duration) var(--ease-out), opacity var(--duration) var(--ease-out);
}

.status-strip.is-active {
  color: rgba(255, 255, 255, 0.75);
}

.status-strip.is-listening {
  color: var(--record);
}

/* —— Composer —— */
.composer {
  flex-shrink: 0;
  background: var(--composer-bg);
  padding: 0.55rem 0.65rem calc(0.55rem + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.composer__form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.composer__field {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--input-bg);
  border-radius: 22px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 0 0.35rem 0 0.85rem;
  min-height: 44px;
  transition: border-color var(--duration) var(--ease-out), box-shadow var(--duration) var(--ease-out);
}

.composer__field:focus-within {
  border-color: rgba(255, 255, 255, 0.18);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.composer__input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 0.95rem;
  padding: 0.5rem 0;
  outline: none;
}

.composer__input::placeholder {
  color: rgba(255, 255, 255, 0.35);
}

.composer__send {
  flex-shrink: 0;
  width: 0;
  min-width: 0;
  height: 36px;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transform: scale(0.9);
  pointer-events: none;
  overflow: hidden;
  transition: opacity var(--duration) var(--ease-out), transform var(--duration) var(--ease-out),
    width var(--duration) var(--ease-out), min-width var(--duration) var(--ease-out),
    margin var(--duration) var(--ease-out), background 0.2s ease;
}

.composer__send.is-visible {
  width: 36px;
  min-width: 36px;
  margin-left: 2px;
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
}

.composer__send:hover {
  background: rgba(255, 255, 255, 0.2);
}

.composer__send:active {
  transform: scale(0.94);
}

.composer__send:disabled {
  opacity: 0.35;
  pointer-events: none;
}

.composer__send .icon {
  width: 18px;
  height: 18px;
  margin-left: 2px;
}

.composer__mic {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--duration) var(--ease-out), color var(--duration) var(--ease-out),
    transform 0.15s ease, box-shadow var(--duration) var(--ease-out);
}

.composer__mic:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.14);
}

.composer__mic:active:not(:disabled) {
  transform: scale(0.94);
}

.composer__mic .icon {
  width: 22px;
  height: 22px;
}

.composer__mic.is-recording {
  background: rgba(239, 68, 68, 0.2);
  color: var(--record);
  animation: mic-pulse 1.25s ease-in-out infinite;
}

@keyframes mic-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.35);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(239, 68, 68, 0);
  }
}

.composer__mic:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  animation: none;
}

@media (min-width: 600px) {
  .messages {
    padding-left: 1.25rem;
    padding-right: 1.25rem;
  }

  .composer {
    padding-left: 1rem;
    padding-right: 1rem;
  }
}
