* {
  box-sizing: border-box;
}
:root {
  color-scheme: light dark;
  --accent: #2563eb;
  --muted: #6b7280;
  --bubble: #e5e7eb;
  --bg: #fff;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bubble: #374151;
    --bg: #111827;
  }
}
html,
body {
  height: 100%;
  margin: 0;
}
body {
  font: 16px/1.4 system-ui, sans-serif;
  background: var(--bg);
}
[hidden] {
  display: none !important;
}
button {
  font: inherit;
  padding: 0.5rem 1rem;
  border: 0;
  border-radius: 0.5rem;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
button.link {
  background: none;
  color: var(--accent);
  padding: 0.25rem;
}
input {
  font: inherit;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--muted);
  border-radius: 0.5rem;
  background: transparent;
  min-width: 0;
}

#join {
  max-width: 22rem;
  margin: 15vh auto 0;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
#join h1 {
  margin: 0 0 1rem;
}
.hint {
  color: var(--muted);
  font-size: 0.875rem;
}

#chat {
  height: 100%;
  max-width: 48rem;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}
header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.5rem;
  padding: max(0.5rem, env(safe-area-inset-top)) max(0.5rem, env(safe-area-inset-right)) 0.5rem
    max(0.5rem, env(safe-area-inset-left));
  border-bottom: 1px solid var(--bubble);
}
#online {
  justify-self: start;
}
#nick {
  font-weight: 600;
  max-width: 50vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#menu-button {
  justify-self: end;
}
header {
  position: relative;
}
button.icon {
  display: flex;
  padding: 0.25rem;
}
.popup {
  position: absolute;
  top: 100%;
  z-index: 10;
  min-width: 10rem;
  max-height: 60vh;
  overflow-y: auto;
  margin: 0;
  padding: 0.25rem 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--bubble);
  border-radius: 0.5rem;
  box-shadow: 0 4px 16px rgb(0 0 0 / 0.15);
}
#menu {
  right: max(0.5rem, env(safe-area-inset-right));
}
#users {
  left: max(0.5rem, env(safe-area-inset-left));
}
#users li {
  padding: 0.5rem 1rem;
}
#menu button {
  background: none;
  color: inherit;
  border-radius: 0;
  text-align: left;
  padding: 0.625rem 1rem;
}
#menu button:hover {
  background: var(--bubble);
}
#menu button.danger {
  color: #dc2626;
}
#status {
  margin: 0;
  padding: 0.25rem 0.5rem;
  background: #fef3c7;
  color: #92400e;
  font-size: 0.875rem;
  text-align: center;
}
#messages {
  flex: 1;
  overflow-y: auto;
  list-style: none;
  margin: 0;
  padding: 0.5rem max(0.5rem, env(safe-area-inset-right)) 0.5rem max(0.5rem, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
#messages li {
  max-width: 80%;
  align-self: flex-start;
}
#messages li.mine {
  align-self: flex-end;
  text-align: right;
}
#messages .meta {
  font-size: 0.75rem;
  color: var(--muted);
}
#messages .text {
  display: inline-block;
  text-align: left;
  padding: 0.375rem 0.75rem;
  border-radius: 1rem;
  background: var(--bubble);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
#messages li.mine .text {
  background: var(--accent);
  color: #fff;
}
#send {
  display: flex;
  gap: 0.5rem;
  /* keep clear of the rounded corners and home indicator on iPhone */
  padding: 0.5rem max(0.75rem, env(safe-area-inset-right)) max(0.75rem, env(safe-area-inset-bottom))
    max(0.75rem, env(safe-area-inset-left));
  border-top: 1px solid var(--bubble);
}
#text {
  flex: 1;
}
