:root {
  --bg: #fafaf9;
  --fg: #111111;
  --muted: #8c8c8a;
  --faint: #c9c9c6;
  --line: #e8e8e5;
  --soft: #efefec;
  --on-fg: #fafaf9;
  --ok: #3fb56b;
  --warn: #d99a2b;
  --danger: #cf4a4a;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", "Helvetica Neue", sans-serif;
  font-size: 15px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0b0c;
    --fg: #f1f1ef;
    --muted: #78787b;
    --faint: #3a3a3e;
    --line: #1d1d20;
    --soft: #18181b;
    --on-fg: #0b0b0c;
    --ok: #4cc47b;
    --warn: #e0a640;
    --danger: #ef6b6b;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
}

body {
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

[hidden] {
  display: none !important;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

::selection {
  background: var(--fg);
  color: var(--bg);
}

.app {
  height: 100dvh;
  max-width: 680px;
  margin: 0 auto;
}

.screen {
  height: 100%;
}

.screen--center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 32px;
}

/* Typography */

.title {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1.15;
}

.lead {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.6;
}

.nowrap {
  white-space: nowrap;
}

/* Pages (wait / end) */

.screen--page {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 32px 28px;
  padding-bottom: max(28px, env(safe-area-inset-bottom));
}

.page {
  width: 100%;
  max-width: 400px;
  margin: auto auto 0;
}

.page--center {
  margin: 0;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.page-footer {
  width: 100%;
  max-width: 400px;
  margin: auto auto 0;
  padding-top: 40px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 14px;
}

/* Share link */

.link {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 36px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.link__input {
  flex: 1;
  min-width: 0;
  border: 0;
  padding: 0;
  background: transparent;
  font: 0.82rem ui-monospace, "Cascadia Mono", "SF Mono", Menlo, monospace;
  color: var(--muted);
  text-overflow: ellipsis;
  outline: none;
}

.link__action {
  border: 0;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--fg);
  color: var(--on-fg);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
}

.link__action:hover {
  opacity: 0.85;
}

.waiting {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 28px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

/* Buttons */

.text-btn {
  border: 0;
  padding: 6px 0;
  background: none;
  color: var(--muted);
  font-size: 0.88rem;
  cursor: pointer;
  transition: color 0.15s;
}

.text-btn:hover {
  color: var(--fg);
}

.text-btn--danger:hover {
  color: var(--danger);
}

#share-btn {
  margin-top: 8px;
}

.pill-btn {
  margin-top: 32px;
  padding: 12px 24px;
  border-radius: 999px;
  background: var(--fg);
  color: var(--on-fg);
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
  transition: opacity 0.15s;
}

.pill-btn:hover {
  opacity: 0.85;
}

/* Status dots */

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok);
  flex-shrink: 0;
}

.dot--pulse {
  background: var(--faint);
  animation: pulse 1.6s ease-in-out infinite;
}

.dot--warn {
  background: var(--warn);
  animation: pulse 1s ease-in-out infinite;
}

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

/* Chat */

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  padding-top: max(14px, env(safe-area-inset-top));
}

.topbar__status {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.banner {
  margin: 0;
  padding: 0 20px 10px;
  text-align: center;
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--warn);
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--faint) transparent;
}

.system {
  align-self: center;
  margin: 10px 0;
  max-width: 320px;
  text-align: center;
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--muted);
}

.msg {
  max-width: min(80%, 480px);
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-top: 4px;
  animation: appear 0.2s ease-out;
}

.msg--me {
  align-self: flex-end;
  align-items: flex-end;
}

.msg--them {
  align-self: flex-start;
  align-items: flex-start;
}

.msg__bubble {
  padding: 9px 15px;
  border-radius: 20px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  animation: fade linear forwards;
}

.msg--me .msg__bubble {
  background: var(--fg);
  color: var(--on-fg);
}

.msg--them .msg__bubble {
  background: var(--soft);
}

.msg--pending .msg__bubble {
  filter: opacity(0.5);
}

.msg--failed .msg__bubble {
  background: transparent;
  color: var(--danger);
  box-shadow: inset 0 0 0 1px var(--danger);
}

.msg__meta {
  display: flex;
  gap: 6px;
  max-height: 0;
  overflow: hidden;
  padding: 0 6px;
  font-size: 0.68rem;
  line-height: 1.4;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
  opacity: 0;
  transition: opacity 0.2s, max-height 0.2s;
}

.msg:hover .msg__meta,
.msg:active .msg__meta,
.msg--pending .msg__meta,
.msg--failed .msg__meta,
.msg:last-child .msg__meta {
  max-height: 16px;
  opacity: 1;
}

@keyframes fade {
  0%,
  85% {
    opacity: 1;
  }
  100% {
    opacity: 0.25;
  }
}

@keyframes appear {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
}

.msg--leaving {
  transition: opacity 0.4s, transform 0.4s;
  opacity: 0;
  transform: scale(0.97);
}

/* Composer */

.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 10px 16px;
  padding-bottom: max(14px, env(safe-area-inset-bottom));
}

.composer__input {
  flex: 1;
  resize: none;
  max-height: 160px;
  border: 0;
  border-radius: 22px;
  background: var(--soft);
  padding: 11px 18px;
  line-height: 1.4;
  outline: none;
}

.composer__input::placeholder {
  color: var(--muted);
}

.composer__send {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  border: 0;
  border-radius: 50%;
  background: var(--fg);
  color: var(--on-fg);
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

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

.composer__send:disabled {
  opacity: 0.2;
  cursor: default;
}

:focus-visible {
  outline: 1.5px solid var(--fg);
  outline-offset: 3px;
}

.composer__input:focus-visible,
.link__input:focus-visible {
  outline: none;
}

@media (min-width: 700px) {
  .topbar,
  .messages {
    padding-left: 28px;
    padding-right: 28px;
  }

  .composer {
    padding: 12px 24px 24px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
