:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --bar: rgba(246, 246, 246, 0.86);
  --bar-border: rgba(0, 0, 0, 0.12);
  --text: #000000;
  --muted: #8a8a8e;
  --mine: #007aff;
  --theirs: #e9e9eb;
  --field: #ffffff;
  --field-border: #d1d1d6;
  --card: #f2f2f7;
  --danger: #ff3b30;
  --pill: rgba(255, 255, 255, 0.78);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bar: rgba(28, 28, 30, 0.86);
    --bar-border: rgba(255, 255, 255, 0.12);
    --text: #ffffff;
    --muted: #98989f;
    --mine: #0a84ff;
    --theirs: #26252a;
    --field: #1c1c1e;
    --field-border: #3a3a3c;
    --card: #1c1c1e;
    --danger: #ff453a;
    --pill: rgba(0, 0, 0, 0.6);
  }
}

* {
  box-sizing: border-box;
}

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

[hidden] {
  display: none !important;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

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

/* Sized to the visual viewport (set from JS) so the composer sits on top of the iOS keyboard. */
#app {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--vv-top, 0px);
  height: var(--vv-height, 100dvh);
}

/* MARK: Join */

.join {
  height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
}

.join-card {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
}

.join-icon {
  align-self: center;
  border-radius: 16px;
}

.join h1 {
  margin: 4px 0 0;
  font-size: 26px;
}

.join-card > p {
  margin: 0 0 6px;
}

.join label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
  font-size: 13px;
  color: var(--muted);
}

.join input {
  font: inherit;
  font-size: 17px;
  color: var(--text);
  background: var(--field);
  border: 1px solid var(--field-border);
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
}

.join input:focus {
  border-color: var(--mine);
}

.account-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 8px;
}

.account {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px 8px;
  border-radius: 16px;
  background: var(--card);
  font-size: 17px;
  font-weight: 500;
}

.account:active {
  opacity: 0.6;
}

.login-avatar {
  align-self: center;
}

#login-back {
  align-self: center;
  margin-top: 4px;
}

.primary {
  background: var(--mine);
  color: #fff;
  font-size: 17px;
  font-weight: 600;
  border-radius: 12px;
  padding: 13px;
  margin-top: 6px;
}

.primary:disabled {
  opacity: 0.5;
}

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

.install-hint {
  max-width: 360px;
  margin-top: 28px;
  font-size: 14px;
  line-height: 1.4;
  text-align: center;
  color: var(--muted);
}

/* MARK: Chat */

.chat {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.wallpaper {
  position: absolute;
  inset: 0;
  background: center / cover no-repeat;
  pointer-events: none;
}

.chat > :not(.wallpaper) {
  position: relative;
}

.chat-header {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(env(safe-area-inset-top) + 6px) 12px 8px;
  background: var(--bar);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--bar-border);
}

.chat-title {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  min-width: 0;
  max-width: calc(100% - 100px);
}

.avatar-stack {
  display: flex;
  margin-bottom: 3px;
}

.avatar-stack:empty {
  display: none;
}

.avatar-stack .avatar + .avatar {
  margin-left: -8px;
}

.avatar-stack .avatar {
  box-shadow: 0 0 0 2px var(--bar);
}

/* MARK: Avatars */

.avatar {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  overflow: hidden;
  color: #fff;
  font-weight: 600;
  line-height: 1;
  user-select: none;
  -webkit-user-select: none;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.chat-title h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}

.chat-title p {
  margin: 1px 0 0;
  font-size: 12px;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  color: var(--mine);
  flex: none;
}

#menu-button {
  position: absolute;
  right: 8px;
  bottom: 6px;
}

.banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  font-size: 14px;
  background: var(--card);
  border-bottom: 0.5px solid var(--bar-border);
}

.banner span {
  flex: 1;
}

.link {
  color: var(--mine);
  font-weight: 600;
}

.banner-close {
  font-size: 22px;
  line-height: 1;
  color: var(--muted);
  padding: 0 4px;
}

.thread {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 8px 12px 4px;
}

.older {
  display: flex;
  justify-content: center;
  padding: 12px;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--muted);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  margin-bottom: 2px;
}

.row.mine {
  align-items: flex-end;
}

/* Others' messages leave room on the left for the avatar beside the last bubble of a run. */
.row.theirs {
  position: relative;
  padding-left: 36px;
}

.row-avatar {
  position: absolute;
  left: 0;
  bottom: 0;
}

.row.event {
  align-items: center;
  margin: 10px 0;
}

.event-text {
  max-width: 85%;
  font-size: 12px;
  text-align: center;
  color: var(--muted);
}

.row.tail {
  margin-bottom: 8px;
}

.stamp {
  align-self: center;
  margin: 12px 0 6px;
  font-size: 11px;
  color: var(--muted);
}

.stamp b {
  font-weight: 600;
}

.sender {
  margin: 4px 0 0 12px;
  font-size: 12px;
}

.bubble {
  max-width: min(75%, 320px);
  padding: 7px 12px 8px;
  border-radius: 18px;
  font-size: 17px;
  line-height: 1.3;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: var(--theirs);
  color: var(--text);
  user-select: text;
  -webkit-user-select: text;
}

.mine .bubble {
  background: var(--mine);
  color: #fff;
}

.tail:not(.mine) .bubble:last-child {
  border-bottom-left-radius: 5px;
}

.tail.mine .bubble:last-of-type {
  border-bottom-right-radius: 5px;
}

.bubble a {
  color: inherit;
  text-decoration: underline;
}

.bubble.unknown {
  font-style: italic;
  opacity: 0.8;
}

.photo {
  position: relative;
  display: block;
  border-radius: 18px;
  overflow: hidden;
  background: var(--theirs);
  cursor: zoom-in;
}

.photo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo .spinner {
  position: absolute;
  inset: 0;
  margin: auto;
  border-color: #fff;
  border-top-color: transparent;
}

.row.pending .bubble,
.row.pending .photo {
  opacity: 0.6;
}

.status {
  font-size: 11px;
  color: var(--muted);
  margin-right: 4px;
}

.status.failed {
  color: var(--danger);
  font-weight: 500;
}

.typing {
  min-height: 18px;
  padding: 0 12px 4px;
  font-size: 12px;
  color: var(--muted);
}

/* Over a wallpaper, small gray text gets a frosted pill so it stays readable. */
.has-wallpaper .stamp,
.has-wallpaper .sender,
.has-wallpaper .event-text,
.has-wallpaper .status,
.has-wallpaper .typing:not(:empty) {
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--pill);
  color: var(--text);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.has-wallpaper .typing:not(:empty) {
  display: inline-block;
  margin-left: 12px;
}

.has-wallpaper .status.failed {
  color: var(--danger);
}

/* MARK: Proposals */

.proposal {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.proposal-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding-top: 8px;
  border-top: 0.5px solid var(--bar-border);
  font-size: 14px;
  color: var(--muted);
}

.proposal-note {
  font-size: 15px;
  white-space: pre-wrap;
}

.endorse {
  padding: 6px 14px;
  border-radius: 14px;
  background: var(--mine);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
}

.endorse:disabled {
  opacity: 0.5;
}

.proposal-status a {
  color: var(--mine);
}

.command-hint {
  padding: 8px 14px;
  font-size: 13px;
  color: var(--muted);
  background: var(--bar);
  border-top: 0.5px solid var(--bar-border);
}

.command-hint strong {
  color: var(--text);
}

/* MARK: Composer */

.composer {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 6px 10px max(8px, env(safe-area-inset-bottom));
  background: var(--bar);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--bar-border);
}

.keyboard-open .composer {
  padding-bottom: 8px;
}

.photo-button {
  color: var(--muted);
  cursor: pointer;
  margin-bottom: -2px;
}

#draft {
  flex: 1;
  min-height: 36px;
  max-height: 140px;
  resize: none;
  font: inherit;
  font-size: 17px;
  line-height: 1.25;
  padding: 7px 14px;
  color: var(--text);
  background: var(--field);
  border: 1px solid var(--field-border);
  border-radius: 18px;
  outline: none;
}

.send {
  flex: none;
  width: 32px;
  height: 32px;
  margin: 0 0 2px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--mine);
  color: #fff;
}

.send:disabled {
  opacity: 0.35;
}

/* MARK: Menu sheet */

.sheet {
  width: min(100% - 24px, 420px);
  margin: auto auto max(12px, env(safe-area-inset-bottom));
  padding: 0;
  border: 0;
  border-radius: 14px;
  background: var(--card);
  color: var(--text);
}

.sheet::backdrop {
  background: rgba(0, 0, 0, 0.35);
}

.sheet form {
  display: flex;
  flex-direction: column;
}

.sheet p {
  margin: 0;
  padding: 14px 16px;
  font-size: 13px;
  text-align: center;
}

.sheet-item {
  padding: 16px;
  font-size: 17px;
  color: var(--mine);
  border-top: 0.5px solid var(--bar-border);
}

.sheet-item.danger {
  color: var(--danger);
}

.sheet-item.cancel {
  font-weight: 600;
}

.sheet-item:disabled {
  color: var(--muted);
}

label.sheet-item {
  display: block;
  text-align: center;
  cursor: pointer;
}

.member-list {
  max-height: 55vh;
  overflow-y: auto;
}

.member {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 16px;
  font-size: 17px;
  text-align: left;
  border-top: 0.5px solid var(--bar-border);
}

.member .you {
  color: var(--muted);
}

.member-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 20px 16px 14px;
  font-size: 17px;
}

/* MARK: Photo viewer */

.viewer {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.viewer img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.viewer-close {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 8px);
  right: 12px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 26px;
  line-height: 1;
  color: #fff;
  background: rgba(255, 255, 255, 0.18);
}
