:root {
  color-scheme: light dark;
  --tissue: #d6e2ef;
  --paper: #f8fafd;
  --mine: #e6edf7;
  --ink: #16233f;
  --ink-soft: #4b5a78;
  --line: #a9bbd1;
  --airmail-red: #c72c35;
  --airmail-blue: #1d3f94;
  --action: #1d3f94;
  --action-ink: #ffffff;
  --link: #1d3f94;
  --error: #a81f29;
  --band-gap: #f8fafd;
  --serif: "Alegreya Variable", Georgia, "Noto Serif", serif;
  --sans: "Alegreya Sans", system-ui, -apple-system, "Segoe UI", "Noto Sans", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --tissue: #121a2e;
    --paper: #1c2742;
    --mine: #263457;
    --ink: #e9eef8;
    --ink-soft: #aab7d0;
    --line: #3a4a70;
    --action: #8fb0f5;
    --action-ink: #101a33;
    --link: #a9c3f8;
    --error: #ff9fa5;
    --band-gap: #e9eef8;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--tissue);
  color: var(--ink);
  font: 400 1.0625rem/1.45 var(--sans);
}

/* The striped airmail edge is the one flourish. Everything else stays plain stationery. */
.envelope, .topbar::before {
  background: repeating-linear-gradient(
    -45deg,
    var(--airmail-red) 0 18px,
    var(--band-gap) 18px 30px,
    var(--airmail-blue) 30px 48px,
    var(--band-gap) 48px 60px
  );
}

button, input, select, textarea { font: inherit; color: inherit; }

a { color: var(--link); text-underline-offset: 0.15em; }

:focus-visible { outline: 3px solid var(--airmail-red); outline-offset: 2px; }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--paper);
  padding: 0.55rem 0.7rem;
}

.primary {
  border: 0;
  border-radius: 3px;
  background: var(--action);
  color: var(--action-ink);
  font-weight: 700;
  padding: 0.6rem 1.15rem;
  cursor: pointer;
}

.primary:disabled { opacity: 0.6; cursor: default; }

.quiet, .inline-action {
  border: 0;
  background: none;
  color: var(--link);
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 0.15em;
}

.error { color: var(--error); margin: 0; font-weight: 500; }

/* Join */
.join {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.envelope {
  width: min(100%, 27rem);
  padding: 12px;
  border-radius: 4px;
}

.letter {
  display: grid;
  gap: 0.35rem;
  background: var(--paper);
  padding: 1.75rem 1.5rem 1.5rem;
}

.letter h1 {
  margin: 0;
  font: 800 2.5rem/1 var(--serif);
  letter-spacing: -0.01em;
  color: var(--airmail-blue);
}

@media (prefers-color-scheme: dark) {
  .letter h1 { color: var(--ink); }
}

.tagline {
  margin: 0.4rem 0 0.9rem;
  font: italic 400 1.2rem/1.3 var(--serif);
  color: var(--ink-soft);
}

.letter label { margin-top: 0.6rem; font-weight: 500; }

.letter .error { margin-top: 0.75rem; }

.letter .primary { margin-top: 1.1rem; justify-self: start; }

/* Chat */
.chat {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

.topbar::before {
  content: "";
  display: block;
  height: 8px;
}

.topbar-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 1.1rem;
  max-width: calc(50rem + 32px);
  margin: 0 auto;
  padding: 0.6rem 16px 0;
}

.wordmark {
  margin-inline-end: auto;
  font: 800 1.35rem/1.2 var(--serif);
}

.language-switch {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.language-switch span { color: var(--ink-soft); }

.language-switch select { width: auto; padding: 0.2rem 0.4rem; }

.presence {
  max-width: calc(50rem + 32px);
  margin: 0 auto;
  padding: 0.2rem 16px 0.55rem;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

.connection {
  margin: 0;
  padding: 0.3rem 16px;
  text-align: center;
  background: var(--airmail-red);
  color: #fff;
  font-weight: 500;
}

.scroller {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1rem 16px;
}

.empty {
  margin: 3rem auto 0;
  max-width: 24rem;
  text-align: center;
  font: italic 400 1.25rem/1.35 var(--serif);
  color: var(--ink-soft);
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  list-style: none;
  max-width: 50rem;
  margin: 0 auto;
  padding: 0;
}

.message {
  width: fit-content;
  max-width: min(85%, 36rem);
  background: var(--paper);
  border-radius: 3px;
  padding: 0.5rem 0.8rem 0.55rem;
  box-shadow: 0 1px 0 var(--line);
  overflow-wrap: anywhere;
}

.message.mine {
  align-self: flex-end;
  background: var(--mine);
}

.message-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 0.6rem;
  font-size: 0.92rem;
  color: var(--ink-soft);
}

.message-head strong { color: var(--ink); font-weight: 700; }

.message-body {
  margin: 0.1rem 0 0;
  font: 400 1.2rem/1.42 var(--serif);
  white-space: pre-wrap;
}

.message-body.waiting { color: var(--ink-soft); font-style: italic; }

.message-note {
  margin: 0.25rem 0 0;
  font-size: 0.92rem;
  color: var(--ink-soft);
}

.message-note span { margin-inline-end: 0.4rem; }

.alternate {
  margin: 0.45rem 0 0;
  border-inline-start: 3px solid var(--airmail-red);
  padding-inline-start: 0.65rem;
}

.alternate-label {
  display: block;
  font-size: 0.92rem;
  color: var(--ink-soft);
}

.alternate-text {
  display: block;
  font: 400 1.1rem/1.4 var(--serif);
  white-space: pre-wrap;
}

.composer {
  background: var(--paper);
  border-top: 1px solid var(--line);
  padding: 0.65rem 16px calc(0.65rem + env(safe-area-inset-bottom));
}

.composer .error { max-width: 50rem; margin: 0 auto 0.4rem; }

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 0.6rem;
  max-width: 50rem;
  margin: 0 auto;
}

.composer textarea {
  flex: 1;
  min-width: 0;
  max-height: 9rem;
  resize: none;
  font: 400 1.15rem/1.35 var(--serif);
  background: var(--tissue);
}

@media (max-width: 34rem) {
  .message { max-width: 94%; }
  .language-switch span { display: none; }
}
