:root {
  --bg: #0f0c1d;
  --panel: #1b1631;
  --mine: #7b3fe4;
  --theirs: #2a2442;
  --text: #f2eefc;
  --muted: #9c93b8;
  --accent: #ff7a3d;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
/* `hidden` must always win: a class that sets display (flex, grid) otherwise overrides it,
   which left the invite sheet and the sign-in screen covering the whole app. */
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", sans-serif;
  display: flex; flex-direction: column; height: 100dvh; overflow: hidden;
  -webkit-text-size-adjust: 100%;
}
header {
  padding: calc(var(--safe-top) + 10px) 16px 10px;
  background: linear-gradient(135deg, #2b1055, #6b1f6e);
  display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; align-items: center;
  box-shadow: 0 1px 0 rgba(255,255,255,.06);
}
.title { font-weight: 800; font-size: 20px; letter-spacing: .2px; }
.right { display: flex; gap: 10px; align-items: center; justify-self: end; }
.status { font-size: 12px; color: var(--muted); }
.invite { background: rgba(255,255,255,.14); color: var(--text); border: 0; border-radius: 14px;
  padding: 5px 12px; font: inherit; font-size: 13px; font-weight: 600; }
.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; z-index: 10; }
.sheet-card { width: 100%; background: var(--panel); border-radius: 18px 18px 0 0;
  padding: 20px 18px calc(var(--safe-bottom) + 20px); }
.sheet-card h2 { margin: 0 0 6px; font-size: 18px; }
.sheet-card p { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
.sheet-card input { width: 100%; font: inherit; font-size: 14px; padding: 10px 12px; border-radius: 10px;
  border: 0; background: var(--bg); color: var(--text); }
.sheet-actions { display: flex; gap: 8px; margin-top: 12px; }
.sheet-actions button { flex: 1; border: 0; border-radius: 12px; padding: 12px; font: inherit; font-weight: 600;
  background: var(--accent); color: #fff; }
.sheet-actions button.ghost { background: rgba(255,255,255,.1); }
.status.live { color: #6ee7a8; }
.status.connecting { color: #f5c06b; }
.online { grid-column: 1 / -1; font-size: 12px; color: var(--muted); min-height: 15px; }

main {
  flex: 1; overflow-y: auto; padding: 12px 10px 6px; -webkit-overflow-scrolling: touch;
  display: flex; flex-direction: column; gap: 2px;
}
.older { align-self: center; margin: 4px 0 10px; background: var(--panel); color: var(--muted);
  border: 0; border-radius: 14px; padding: 6px 12px; font-size: 13px; }
.day { align-self: center; font-size: 11px; color: var(--muted); margin: 12px 0 6px;
  text-transform: uppercase; letter-spacing: .6px; }
.row { display: flex; flex-direction: column; max-width: 80%; }
.row.mine { align-self: flex-end; align-items: flex-end; }
.row.theirs { align-self: flex-start; align-items: flex-start; }
.row.gap { margin-top: 8px; }
.who { font-size: 12px; color: var(--muted); margin: 0 10px 2px; }
.bubble {
  padding: 8px 12px; border-radius: 18px; white-space: pre-wrap; word-wrap: break-word;
  overflow-wrap: anywhere;
}
.mine .bubble { background: var(--mine); border-bottom-right-radius: 6px; }
.theirs .bubble { background: var(--theirs); border-bottom-left-radius: 6px; }
.row.pending .bubble { opacity: .55; }
.row.failed .bubble { outline: 1px solid #ff6b6b; }
.meta { font-size: 10.5px; color: var(--muted); margin: 2px 10px 0; }
.bubble a { color: inherit; text-decoration: underline; }

.typing { font-size: 12px; color: var(--muted); padding: 0 18px 4px; height: 18px; }

form {
  display: flex; gap: 8px; align-items: flex-end;
  padding: 8px 10px calc(var(--safe-bottom) + 8px);
  background: var(--panel); border-top: 1px solid rgba(255,255,255,.06);
}
textarea {
  flex: 1; resize: none; max-height: 140px; border: 0; outline: none;
  background: #0f0c1d; color: var(--text); border-radius: 20px; padding: 10px 14px;
  font: inherit; font-size: 16px;   /* 16px stops iOS zooming into the field */
}
button#send {
  width: 40px; height: 40px; border-radius: 50%; border: 0; flex: none;
  background: var(--accent); color: #fff; font-size: 20px; font-weight: 700;
}
button#send:disabled { opacity: .35; }

.blocked {
  position: fixed; inset: 0; background: var(--bg); display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; padding: 32px;
}
.blocked h1 { margin: 0 0 12px; }
.blocked p { color: var(--muted); max-width: 320px; }
