:root {
  color-scheme: light dark;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  background: Canvas;
  color: CanvasText;
  --line: color-mix(in srgb, CanvasText 20%, transparent);
  --surface: color-mix(in srgb, Canvas 92%, CanvasText 8%);
  --accent: #2f6fed;
}

body {
  min-height: 100vh;
  margin: 0;
  display: grid;
  place-items: center;
}

#logan-bootstrap {
  box-sizing: border-box;
  width: min(34rem, calc(100% - 3rem));
  padding: 2rem;
  border: 1px solid color-mix(in srgb, CanvasText 24%, transparent);
  border-radius: 1rem;
}

#logan-bootstrap.logan-app {
  box-sizing: border-box;
  width: min(72rem, calc(100% - 2rem));
  min-height: min(48rem, calc(100vh - 2rem));
  padding: 0;
  overflow: hidden;
}

#logan-bootstrap[data-state="unsupported"] {
  border-color: #b42318;
}

#logan-bootstrap[data-state="ready"] {
  border-color: #16803c;
}

h1 {
  margin-block: 0 0.75rem;
  font-size: 1.4rem;
}

p {
  margin: 0;
  line-height: 1.5;
}

button,
input,
textarea {
  box-sizing: border-box;
  font: inherit;
}

button {
  min-height: 2.75rem;
  padding: 0.55rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 0.65rem;
  background: var(--accent);
  color: white;
  cursor: pointer;
}

button:disabled { cursor: wait; opacity: 0.65; }

input,
textarea {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 0.65rem;
  background: Canvas;
  color: CanvasText;
}

.app-header {
  overflow-wrap: anywhere;
  position: relative;
  padding: 1.25rem 1.4rem;
  border-bottom: 1px solid var(--line);
}

.app-header p,
.muted,
.message time,
.contact small { color: color-mix(in srgb, CanvasText 64%, transparent); }

.sync-button { position: absolute; top: 1.2rem; right: 1.2rem; }

.setup-card { max-width: 34rem; margin: auto; }
.setup-card .app-header { padding-inline: 0; }
.setup-form { display: grid; gap: 1rem; padding-block: 1.5rem; }
.setup-form label { display: grid; gap: 0.45rem; font-weight: 650; }
.actions { display: flex; flex-wrap: wrap; gap: 0.75rem; }
.status { min-height: 1.5rem; padding: 0.55rem 1.4rem; color: color-mix(in srgb, CanvasText 70%, transparent); }
.pairing-code { margin-block: 2rem 1rem; font: 700 1.7rem ui-monospace, monospace; letter-spacing: 0.08em; }
.fingerprint { margin-block: 0 1rem; font: 650 1rem ui-monospace, monospace; }

.messenger { min-height: inherit; display: grid; grid-template-rows: auto minmax(0, 1fr); }
.messenger .app-header h1 { padding-right: 3rem; }
.settings-toggle { position: absolute; top: 1rem; right: 1rem; font-size: 1.5rem; min-width: 44px; min-height: 44px; }
.chat-settings { margin-top: 1rem; padding: 1rem; border: 1px solid var(--line); border-radius: 0.65rem; }
.chat-settings[hidden] { display: none; }
.chat-settings .sync-button { position: static; margin: 0 0.5rem 0.5rem 0; }
.chat-settings .status, .chat-settings .draft-notice { padding-inline: 0; }
.self-identity { display: flex; align-items: center; gap: 0.8rem; margin-top: 0.75rem; }
.self-identity > div:last-child { min-width: 0; }
.self-identity strong { display: block; font-size: 1.25rem; overflow-wrap: anywhere; }
.self-identity .avatar { width: 4rem; }
.wipe-button { margin-right: 0.5rem; border-color: #c33; }
.draft-notice { padding: 0.15rem 1.4rem 0.8rem; font-size: 0.85rem; }
.messenger-body { min-height: 0; min-width: 0; display: grid; grid-template-columns: minmax(13rem, 19rem) minmax(0, 1fr); border-top: 1px solid var(--line); }
.contacts { padding: 0.65rem; border-right: 1px solid var(--line); overflow-y: auto; }
.contact {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.45rem;
  padding: 0.6rem;
  border-color: transparent;
  background: transparent;
  color: CanvasText;
  text-align: left;
}
.contact[aria-current="true"] { border-color: var(--line); background: var(--surface); }
.contact-copy { display: grid; gap: 0.15rem; min-width: 0; }
.contact-copy strong { overflow: hidden; text-overflow: ellipsis; }
.avatar {
  display: grid;
  flex: 0 0 auto;
  grid-template-columns: repeat(17, 1fr);
  width: 3rem;
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 0.4rem;
  image-rendering: pixelated;
}
.avatar-state-0 { background: #ffffff; }
.avatar-state-1 { background: #e53935; }
.avatar-state-2 { background: #fb8c00; }
.avatar-state-3 { background: #fdd835; }
.avatar-state-4 { background: #43a047; }
.avatar-state-5 { background: #1e88e5; }
.avatar-state-6 { background: #8e24aa; }
.chat { min-width: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto; }
.new-messages { justify-self: center; margin: 0.3rem; }
.new-messages[hidden] { display: none; }
.chat > h2 { margin: 0; padding: 0.85rem 1rem; font-size: 1.05rem; border-bottom: 1px solid var(--line); }
.chat-identity { display: flex; flex-wrap: wrap; align-items: center; gap: 0.8rem; padding: 0.85rem 1rem; border-bottom: 1px solid var(--line); }
.chat-identity h2 { min-width: 0; overflow-wrap: anywhere; margin: 0; font-size: 1.05rem; }
.messages { min-height: 14rem; max-height: calc(100vh - 19rem); margin: 0; padding: 1rem; overflow-y: auto; list-style: none; }
.message { width: fit-content; max-width: min(36rem, 85%); margin-bottom: 0.8rem; padding: 0.65rem 0.8rem; border-radius: 0.8rem; background: var(--surface); }
.message.own { margin-left: auto; background: color-mix(in srgb, var(--accent) 18%, Canvas); }
.message p { white-space: pre-wrap; overflow-wrap: anywhere; }
.message time { display: block; margin-top: 0.3rem; font-size: 0.75rem; }
.message-status { display: block; margin-top: 0.35rem; overflow-wrap: anywhere; }
.messenger-body[data-single-conversation] { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
.composer { display: grid; grid-template-columns: 1fr auto; gap: 0.7rem; padding: 0.9rem; border-top: 1px solid var(--line); }
.composer textarea { scroll-margin-block-end: 1rem; }
.empty { padding: 1rem; color: color-mix(in srgb, CanvasText 60%, transparent); }

@media (max-width: 42rem) {
  body { place-items: stretch; }
  #logan-bootstrap.logan-app { width: 100%; min-height: 100vh; border: 0; border-radius: 0; }
  .messenger-body { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .contacts { min-width: 0; display: flex; gap: 0.45rem; border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
  .contact { flex: 0 0 12rem; min-width: 0; margin: 0; }
  .messages { min-height: 8rem; max-height: 45vh; max-height: 45dvh; }
  .sync-button { position: static; margin-top: 0.8rem; }
}
