:root {
  --bg: #0f1b2d;
  --bg-raised: #16243a;
  --border: #24354f;
  --text: #d7e0ec;
  --dim: #7b8ca3;
  --accent: #22d3ee;
  --p1: #fbbf24;
  --p2: #22d3ee;
  --p3: #fb7185;
  --p4: #a3e635;
  --p5: #c4b5fd;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  /* Discord ships proprietary "gg sans"; this is their documented fallback
     stack, which system fonts approximate closely. */
  font: 16px/1.375 "gg sans", -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Noto Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  touch-action: manipulation;
  overscroll-behavior: none;
}

#topbar {
  display: flex;
  align-items: center;
  gap: 0.6em;
  padding: 0.55em 0.8em;
  padding-top: calc(0.55em + env(safe-area-inset-top));
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  flex: none;
  font-size: 0.86em;
  color: var(--dim);
}

.status-dot {
  width: 0.6em;
  height: 0.6em;
  border-radius: 50%;
  background: #e11d48;
  flex: none;
  transition: background 0.3s;
}
.status-dot.ok { background: #34d399; }
.status-dot.warn { background: var(--p1); }

#whoami { color: var(--text); }
#online { flex: 1; }

#copylink {
  background: none;
  border: 1px solid var(--border);
  color: var(--dim);
  font: inherit;
  padding: 0.25em 0.7em;
  border-radius: 4px;
  cursor: pointer;
}
#copylink:hover, #copylink:focus-visible { color: var(--text); border-color: var(--dim); }
#copylink.copied { color: #34d399; border-color: #34d399; }

#log {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-wrap: anywhere;
  padding: 0.7em 1em;
  scrollbar-color: var(--border) transparent;
}

/* Spacer so a young conversation hugs the composer instead of the top. */
#log::before {
  content: "";
  flex: 1 0 auto;
}

#log .line {
  white-space: pre-wrap;
  flex: none;
  padding: 0.1em 0;
}

#log .sys {
  color: var(--dim);
  font-style: italic;
}

#log .warn { color: var(--p1); font-style: italic; }

.who { font-weight: 600; }
.c0 { color: var(--p1); }
.c1 { color: var(--p2); }
.c2 { color: var(--p3); }
.c3 { color: var(--p4); }
.c4 { color: var(--p5); }

#newmsgs {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(5.2em + env(safe-area-inset-bottom));
  background: var(--accent);
  color: var(--bg);
  border: none;
  font: inherit;
  font-size: 0.82em;
  font-weight: 700;
  padding: 0.35em 0.9em;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

/* Small strip under the composer, Discord-style. min-height reserves the
   line so the layout doesn't jump when someone starts typing. */
#typing {
  flex: none;
  font-size: 0.78em;
  /* content-box + fixed height: exactly one text line is reserved whether or
     not anyone is typing, so the composer never shifts. */
  box-sizing: content-box;
  height: 1.375em;
  line-height: 1.375;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  /* 16px matches composer padding: flush with the input's left edge.
     Equal 6px breathing room above (to input) and below (to page edge). */
  padding: 6px 16px calc(6px + env(safe-area-inset-bottom));
  color: var(--dim);
}

/* Discord-style bar: the field is a raised, borderless rounded surface
   floating on the chat background rather than a bordered strip. */
#composer {
  display: flex;
  align-items: flex-end;
  gap: 0.5em;
  padding: 0 16px;
  background: var(--bg);
  flex: none;
}

#input {
  flex: 1;
  resize: none;
  background: var(--bg-raised);
  border: none;
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  font-size: 16px; /* ≥16px stops iOS Safari zooming in on focus */
  /* Integer pixels: 22px line + 11px x2 padding = 44px, matching #send
     exactly (em math lands on fractions that round differently per element). */
  line-height: 22px;
  padding: 11px 16px;
  min-height: 44px;
  max-height: 30dvh;
  /* JS flips this to auto only once max-height is hit. */
  overflow-y: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
#input::placeholder { color: var(--dim); }
#input:focus { outline: none; box-shadow: 0 0 0 1px var(--border); }

#send {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-raised);
  color: var(--accent);
  border: none;
  border-radius: 8px;
  width: 44px;
  height: 44px;
  flex: none;
  cursor: pointer;
  transition: color 0.15s;
}
/* Nothing to send yet — keep the icon quiet. */
#input:placeholder-shown + #send { color: var(--dim); }
#send:hover, #send:focus-visible { color: var(--accent); }
#send:active { filter: brightness(1.15); }
