:root {
  --bg: #0e0e14;
  --bg-raised: #16161f;
  --bg-input: #1d1d29;
  --line: #272736;
  --text: #ecebf1;
  --text-dim: #9a99ab;
  --accent: #8b7cf6;
  --accent-ink: #ffffff;
  --bubble-user: #6f5fe8;
  --bubble-assistant: #1c1c27;
  --danger: #f2777a;
  --radius: 18px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overscroll-behavior-y: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Buttons ------------------------------------------------------------ */

.button {
  border: 0;
  border-radius: 12px;
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  background: var(--bg-input);
  cursor: pointer;
}

.button--primary {
  background: var(--accent);
  color: var(--accent-ink);
  width: 100%;
}

.button--small {
  padding: 7px 13px;
  font-size: 14px;
}

.button--ghost {
  background: transparent;
  color: var(--text-dim);
  text-align: left;
  padding-inline: 6px;
}

.button:disabled {
  opacity: 0.5;
  cursor: default;
}

.icon-button {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
}

.icon-button:active {
  background: var(--bg-input);
}

.icon-button--send {
  background: var(--accent);
  color: var(--accent-ink);
}

.icon-button--send:disabled {
  background: var(--bg-input);
  color: var(--text-dim);
}

.icon-button[aria-pressed='true'] {
  color: var(--accent);
}

.icon-button[aria-pressed='false'] .icon-wave {
  display: none;
}

.icon-button--mic.is-listening {
  color: var(--danger);
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.45;
  }
}

/* Login -------------------------------------------------------------- */

.login {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 24px;
}

.login[hidden] {
  display: none;
}

.login__card {
  width: min(360px, 100%);
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
}

.login__title {
  margin: 0;
  font-size: 34px;
  letter-spacing: -0.02em;
}

.login__subtitle {
  margin: 0 0 8px;
  color: var(--text-dim);
  font-size: 15px;
}

.login__input {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-input);
  color: var(--text);
  font-size: 16px;
}

.login__input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.login__error {
  margin: 0;
  color: var(--danger);
  font-size: 14px;
}

/* Chat shell --------------------------------------------------------- */

.app {
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  height: 100dvh;
}

.app[hidden] {
  display: none;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: calc(var(--safe-top) + 6px) 8px 6px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-raised);
}

.topbar__title {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 14px 8px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.message {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 84%;
}

.message--user {
  align-self: flex-end;
  align-items: flex-end;
}

.message--assistant {
  align-self: flex-start;
}

.bubble {
  padding: 11px 15px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

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

.message--assistant .bubble {
  background: var(--bubble-assistant);
  border-bottom-left-radius: 6px;
}

.message__speak {
  width: 32px;
  height: 32px;
}

.message__speak svg {
  width: 17px;
  height: 17px;
}

.empty {
  margin: auto;
  padding: 32px 16px;
  color: var(--text-dim);
  text-align: center;
}

.typing {
  display: flex;
  gap: 5px;
  padding: 15px;
}

.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: bounce 1.2s ease-in-out infinite;
}

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

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

@keyframes bounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

.status {
  padding: 8px 16px;
  color: var(--danger);
  font-size: 14px;
  text-align: center;
}

/* Composer ----------------------------------------------------------- */

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 10px calc(var(--safe-bottom) + 10px);
  border-top: 1px solid var(--line);
  background: var(--bg-raised);
}

.composer__input {
  flex: 1;
  max-height: 140px;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--bg-input);
  color: var(--text);
  font: inherit;
  resize: none;
}

.composer__input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

/* Drawer ------------------------------------------------------------- */

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.drawer {
  position: fixed;
  inset-block: 0;
  inset-inline-start: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(300px, 82vw);
  padding: calc(var(--safe-top) + 16px) 14px calc(var(--safe-bottom) + 16px);
  background: var(--bg-raised);
  border-inline-end: 1px solid var(--line);
}

.drawer[hidden] {
  display: none;
}

.drawer__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.drawer__heading {
  font-size: 18px;
  font-weight: 700;
}

.conversations {
  flex: 1;
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
}

.conversation {
  display: flex;
  align-items: center;
  gap: 4px;
  border-radius: 10px;
}

.conversation:hover {
  background: var(--bg-input);
}

.conversation__open {
  flex: 1;
  min-width: 0;
  padding: 11px 10px;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

.conversation--active .conversation__open {
  color: var(--accent);
  font-weight: 600;
}

.conversation__delete {
  width: 34px;
  height: 34px;
}

.conversation__delete svg {
  width: 16px;
  height: 16px;
}
