/* ---------- tokens ---------- */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --text: #14171c;
  --muted: #6b7280;
  --faint: #9aa1ac;
  --border: #e3e6eb;
  --accent: #4f46e5;
  --accent-text: #ffffff;
  --bubble-in: #f1f3f6;
  --danger: #d64545;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 20, 28, .05), 0 8px 24px rgba(16, 20, 28, .06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1013;
    --surface: #16191e;
    --surface-2: #1d2127;
    --text: #e8eaed;
    --muted: #9199a5;
    --faint: #6b7280;
    --border: #262b33;
    --accent: #6d63f2;
    --bubble-in: #22262d;
    --danger: #ef6a6a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

button, textarea, input { font: inherit; color: inherit; }

/* ---------- landing ---------- */
.landing {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 24px;
}

.card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 32px 28px;
  text-align: center;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.brand h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 650;
  letter-spacing: -.02em;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
}

.tagline {
  margin: 8px 0 24px;
  color: var(--muted);
  font-size: 14px;
}

.btn {
  width: 100%;
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-weight: 550;
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s, transform .06s;
}

.btn:hover:not(:disabled) { border-color: var(--faint); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: default; }

.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-text);
}

.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 22px 0;
  color: var(--faint);
  font-size: 12px;
}

.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.code-input {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-bottom: 14px;
}

.code-box {
  width: 56px;
  height: 62px;
  text-align: center;
  font-size: 26px;
  font-weight: 600;
  text-transform: uppercase;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: var(--surface-2);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.code-box:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

.error {
  margin: 14px 0 0;
  color: var(--danger);
  font-size: 13px;
}

.footnote {
  max-width: 380px;
  margin: 0;
  text-align: center;
  color: var(--faint);
  font-size: 12px;
}

/* ---------- room ---------- */
.room {
  height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 760px;
  margin: 0 auto;
  background: var(--surface);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

.room-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  padding-top: max(12px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 2;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.icon-btn svg, .code-chip svg, .send svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.code-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-weight: 650;
  font-size: 16px;
  letter-spacing: .18em;
  cursor: pointer;
}

.code-chip:hover { border-color: var(--faint); }
.code-chip svg { width: 15px; height: 15px; color: var(--muted); letter-spacing: normal; }

.room-meta {
  margin-left: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
  font-size: 12px;
  color: var(--muted);
  min-width: 0;
}

.presence { display: inline-flex; align-items: center; gap: 6px; }

.pulse {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 0 rgba(34, 197, 94, .5);
  animation: pulse 2.4s infinite;
}

.pulse.off { background: var(--faint); animation: none; box-shadow: none; }

@keyframes pulse {
  70% { box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

.you-are {
  color: var(--faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 40vw;
}

/* ---------- messages ---------- */
.messages {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.empty {
  margin: auto;
  text-align: center;
  color: var(--muted);
}

.empty p { margin: 2px 0; }
.muted { color: var(--faint); font-size: 13px; }

.row {
  display: flex;
  flex-direction: column;
  max-width: 76%;
  margin-top: 2px;
}

.row.mine { align-self: flex-end; align-items: flex-end; }
.row.theirs { align-self: flex-start; align-items: flex-start; }
.row.first { margin-top: 14px; }

.author {
  font-size: 12px;
  font-weight: 600;
  margin: 0 4px 4px;
  color: var(--author, var(--muted));
}

.bubble {
  padding: 9px 13px;
  border-radius: 16px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  animation: rise .16s ease-out;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(3px); }
}

.mine .bubble {
  background: var(--accent);
  color: var(--accent-text);
  border-bottom-right-radius: 6px;
}

.theirs .bubble {
  background: var(--bubble-in);
  border-bottom-left-radius: 6px;
}

.row:not(.first).mine .bubble { border-top-right-radius: 6px; }
.row:not(.first).theirs .bubble { border-top-left-radius: 6px; }

.bubble a { color: inherit; text-underline-offset: 2px; }

.stamp {
  font-size: 11px;
  color: var(--faint);
  margin: 3px 6px 0;
  opacity: 0;
  transition: opacity .15s;
}

.row:hover .stamp, .row.last .stamp { opacity: 1; }

.system {
  align-self: center;
  margin: 12px 0;
  font-size: 12px;
  color: var(--faint);
}

.typing {
  min-height: 18px;
  padding: 0 20px 2px;
  font-size: 12px;
  color: var(--faint);
}

/* ---------- composer ---------- */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 14px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.composer textarea {
  flex: 1;
  resize: none;
  max-height: 140px;
  padding: 11px 14px;
  border-radius: 18px;
  border: 1.5px solid var(--border);
  background: var(--surface-2);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.composer textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

.send {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: none;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  transition: opacity .15s, transform .06s;
}

.send:disabled { opacity: .35; cursor: default; }
.send:active:not(:disabled) { transform: scale(.94); }
.send svg { transform: translateX(1px); }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: rise .18s ease-out;
  z-index: 10;
}

@media (max-width: 480px) {
  .row { max-width: 86%; }
  .code-box { width: 52px; height: 58px; }
  .room { border: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
