:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #12141a;
  --muted: #5c6270;
  --line: #dfe2e8;
  --accent: #1f7a5a;
  --accent-text: #ffffff;
  --mine: #d9f2e6;
  --theirs: #ffffff;
  --danger: #a4243b;
  --warn: #8a5a00;
  --warn-bg: #fff6e0;
  --danger-bg: #fdeaee;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101216;
    --surface: #181b21;
    --text: #e8eaee;
    --muted: #9aa1ad;
    --line: #2a2e37;
    --accent: #3fae86;
    --accent-text: #06110d;
    --mine: #1d3a30;
    --theirs: #21252d;
    --danger: #ff8fa3;
    --warn: #ffcf70;
    --warn-bg: #2c2313;
    --danger-bg: #2b161c;
  }
}

* {
  box-sizing: border-box;
}

/*
 * The browser hides [hidden] elements with `display: none`, but that rule lives
 * in the UA stylesheet, which any author rule beats. `.screen { display: flex }`
 * below would therefore un-hide the chat screen. Restore the intent explicitly.
 */
[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.screen {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.screen--centred {
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

/* ------------------------------------------------------------------ login */

.card {
  width: 100%;
  max-width: 26rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.brand {
  margin: 0;
  font-size: 1.75rem;
  letter-spacing: -0.02em;
}

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

label {
  font-size: 0.85rem;
  font-weight: 600;
  margin-top: 0.5rem;
}

input[type='text'],
input[type='password'] {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.65rem 0.8rem;
  width: 100%;
}

input:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button {
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  border: none;
  border-radius: 10px;
  padding: 0.7rem 1rem;
  background: var(--accent);
  color: var(--accent-text);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 0.4rem 0.7rem;
  font-size: 0.85rem;
}

button.link {
  background: none;
  border: none;
  color: inherit;
  text-decoration: underline;
  padding: 0;
  font-size: inherit;
}

#login-button {
  margin-top: 1rem;
}

.error {
  color: var(--danger);
  font-size: 0.9rem;
  margin: 0.75rem 0 0;
}

/* ------------------------------------------------------------------- chat */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding-top: max(0.75rem, env(safe-area-inset-top));
}

.topbar__who {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
}

.topbar__actions {
  display: flex;
  gap: 0.5rem;
}

.pill {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
}

.pill--online {
  color: var(--accent);
  border-color: var(--accent);
}

.banner {
  margin: 0;
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--line);
}

.banner--danger {
  background: var(--danger-bg);
  color: var(--danger);
}

.banner--warn {
  background: var(--warn-bg);
  color: var(--warn);
}

.messages {
  flex: 1;
  overflow-y: auto;
  list-style: none;
  margin: 0;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.message {
  max-width: min(75%, 34rem);
  padding: 0.55rem 0.8rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--theirs);
  align-self: flex-start;
  overflow-wrap: anywhere;
}

.message--mine {
  align-self: flex-end;
  background: var(--mine);
}

.message--pending {
  opacity: 0.55;
}

.message__time {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.7rem;
  color: var(--muted);
}

/* Stickers are drawn large and without a bubble: they are the message. */
.message--sticker {
  background: none;
  border: none;
  padding: 0;
}

.sticker {
  display: block;
  width: 120px;
  height: 120px;
}

.message--image {
  padding: 0.35rem;
}

.photo {
  margin: 0;
  cursor: pointer;
}

.photo__thumb {
  display: block;
  max-width: 100%;
  height: auto;
  max-height: 320px;
  width: auto;
  border-radius: 10px;
  background: var(--bg);
}

.photo__hint {
  margin-top: 0.3rem;
  font-size: 0.72rem;
  color: var(--muted);
  text-align: center;
}

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

.composer-status {
  margin: 0;
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
  color: var(--muted);
  background: var(--surface);
  border-top: 1px solid var(--line);
}

.composer {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
}

.composer input[type='text'] {
  flex: 1;
}

.icon-button {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 2.6rem;
  height: 2.6rem;
  padding: 0;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}

.icon-button:hover:not(:disabled) {
  color: var(--accent);
  border-color: var(--accent);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.photo-dialog {
  max-width: min(92vw, 60rem);
  max-height: 92vh;
  padding: 0.75rem;
}

.photo-dialog img {
  display: block;
  max-width: 100%;
  max-height: 80vh;
  height: auto;
  border-radius: 10px;
}

.sticker-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  margin: 1rem 0;
}

.sticker-choice {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  padding: 0.35rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.sticker-choice:hover {
  border-color: var(--accent);
}

.sticker-choice img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* --------------------------------------------------------------- dialog */

dialog {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  max-width: 30rem;
  padding: 1.5rem;
}

dialog::backdrop {
  background: rgb(0 0 0 / 0.5);
}

.safety-number {
  display: block;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 1.05rem;
  letter-spacing: 0.06em;
  line-height: 2;
  text-align: center;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1rem;
  margin: 1rem 0;
  overflow-wrap: anywhere;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}
