:root {
  color-scheme: dark;
  --bg: #050608;
  --panel: rgba(16, 18, 24, 0.92);
  --panel2: rgba(8, 10, 14, 0.96);
  --line: rgba(255,255,255,0.11);
  --text: #e9edf3;
  --muted: rgba(233,237,243,0.58);
  --good: #62ff9e;
  --warn: #ffca62;
  --bad: #ff6272;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; }
body {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 20%, rgba(255,255,255,0.06), transparent 34rem),
    var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app {
  width: min(92vw, 520px);
}

.panel,
.chat {
  position: relative;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: linear-gradient(180deg, var(--panel), var(--panel2));
  box-shadow: 0 24px 90px rgba(0,0,0,0.48);
  backdrop-filter: blur(16px);
}

.panel {
  padding: 18px;
  display: grid;
  gap: 10px;
  align-items: center;
}

.joinBox {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
}

.phrase,
.send input {
  width: 100%;
  min-width: 0;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(0,0,0,0.35);
  color: var(--text);
  outline: none;
  padding: 0 15px;
  font: inherit;
}

.phrase:focus,
.send input:focus {
  border-color: rgba(255,255,255,0.28);
}

.buttons {
  display: flex;
  gap: 8px;
}

button {
  height: 48px;
  min-width: 76px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255,255,255,0.075);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button:hover { background: rgba(255,255,255,0.12); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: default; transform: none; }

.passgen {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 48px;
  gap: 8px;
  align-items: center;
}

.password-box {
  width: 100%;
  min-width: 0;
  height: 38px;
  padding: 0 12px;
  border: 1px solid rgba(255,255,255,0.085);
  border-radius: 14px;
  background: rgba(0,0,0,0.22);
  color: rgba(233,237,243,0.82);
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.03em;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  text-align: center;
  transition: color 0.25s ease, border-color 0.25s ease, background 0.25s ease;
}

.password-box.copied {
  border-color: rgba(98,255,158,0.25);
  background: rgba(98,255,158,0.055);
}

.generate-btn {
  min-width: 48px;
  width: 48px;
  height: 38px;
  border-radius: 14px;
  font-size: 18px;
  line-height: 1;
  padding-bottom: 2px;
}

.password-popup {
  grid-column: 1 / -1;
  min-height: 12px;
  margin-top: -3px;
  text-align: center;
  font-size: 10px;
  line-height: 12px;
  color: var(--good);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}

.password-popup.show {
  opacity: 1;
}

.dot {
  position: absolute;
  top: 11px;
  right: 12px;
  width: 8px;
  height: 8px;
  border-radius: 99px;
  background: var(--muted);
  box-shadow: 0 0 0 transparent;
}

.dot.waiting { background: var(--warn); box-shadow: 0 0 16px rgba(255,202,98,0.55); }
.dot.good { background: var(--good); box-shadow: 0 0 16px rgba(98,255,158,0.55); }
.dot.bad { background: var(--bad); box-shadow: 0 0 16px rgba(255,98,114,0.55); }

.hidden { display: none; }

.chat {
  height: min(76dvh, 680px);
  padding: 14px;
  grid-template-rows: 1fr auto;
  gap: 12px;
}
.chat:not(.hidden) { display: grid; }

.disconnect {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 3;
  width: 34px;
  min-width: 34px;
  height: 34px;
  border-radius: 12px;
  padding: 0;
  font-size: 22px;
  line-height: 28px;
  color: rgba(233,237,243,0.74);
  background: rgba(255,255,255,0.055);
}

.disconnect:hover {
  color: var(--bad);
  border-color: rgba(255,98,114,0.28);
}

.messages {
  overflow: auto;
  padding: 28px 2px 2px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 8px;
  scrollbar-width: thin;
  overscroll-behavior: contain;
}

.messages.overflowing {
  justify-content: flex-start;
}

.msg {
  width: fit-content;
  max-width: min(82%, 420px);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255,255,255,0.075);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.35;
}

.msg.me {
  align-self: flex-end;
  background: rgba(255,255,255,0.12);
}

.msg.peer {
  align-self: flex-start;
}

.send {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.send button { min-width: 86px; }

@media (max-width: 520px) {
  .joinBox { grid-template-columns: 1fr; }
  .buttons { display: grid; grid-template-columns: 1fr 1fr; }
  button { width: 100%; }
  .app { width: min(94vw, 520px); }
  .password-box { font-size: 12px; }
}
