:root {
  --bg: #0b141a;
  --panel: #111b21;
  --panel-2: #202c33;
  --accent: #00a884;
  --accent-2: #005c4b;
  --mine: #005c4b;
  --theirs: #202c33;
  --text: #e9edef;
  --muted: #8696a0;
  --danger: #f15c6d;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }

/* ---------- screens ---------- */
.screen { height: 100dvh; display: flex; flex-direction: column; }
#login-screen, #unlock-screen { align-items: center; justify-content: center; padding: 20px; }
.card {
  background: var(--panel);
  border: 1px solid var(--panel-2);
  border-radius: 14px;
  padding: 26px 22px;
  width: 100%; max-width: 380px;
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 10px 40px rgba(0,0,0,.4);
}
.card h1 { margin: 0; font-size: 22px; text-align: center; }
.card .sub { margin: 0 0 6px; color: var(--muted); font-size: 13px; text-align: center; }
.card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.card label.row { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.card input[type=text], .card input[type=password] {
  background: var(--panel-2); border: 1px solid #2a3942; color: var(--text);
  border-radius: 8px; padding: 11px 12px; font-size: 15px; outline: none;
}
.card input:focus { border-color: var(--accent); }
.card .hint { font-size: 11px; color: var(--muted); }
.card button {
  background: var(--accent); color: #05231d; border: none; border-radius: 8px;
  padding: 12px; font-size: 15px; font-weight: 600; cursor: pointer; margin-top: 4px;
}
.card button:hover { filter: brightness(1.05); }
.card button.link { background: none; color: var(--muted); font-weight: 400; margin: 0; }
.error { color: var(--danger); font-size: 13px; margin: 0; text-align: center; }
.status { color: var(--muted); font-size: 13px; margin: 0; text-align: center; }

/* ---------- chat ---------- */
#chat-header {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--panel); padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--panel-2);
}
.peer { display: flex; align-items: center; gap: 10px; min-width: 0; }
.peer-meta { display: flex; flex-direction: column; min-width: 0; }
#peer-name { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.presence-text { font-size: 12px; color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.dot.online { background: #06d6a0; box-shadow: 0 0 8px #06d6a0; }
.dot.offline { background: #5a6b73; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.ttl { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 4px; }
.ttl select {
  background: var(--panel-2); color: var(--text); border: 1px solid #2a3942;
  border-radius: 6px; padding: 5px; font-size: 13px;
}
#logout-btn { background: var(--panel-2); color: var(--text); border: none; border-radius: 6px; padding: 6px 10px; font-size: 16px; cursor: pointer; }

.conn { background: var(--accent-2); color: #fff; text-align: center; font-size: 12px; padding: 4px; }

#messages {
  flex: 1; overflow-y: auto; padding: 14px;
  display: flex; flex-direction: column; gap: 6px;
  background-image: radial-gradient(circle at 50% 0, #14202a 0, var(--bg) 60%);
}
.msg { display: flex; }
.msg.mine { justify-content: flex-end; }
.msg.theirs { justify-content: flex-start; }
.bubble {
  max-width: 78%; padding: 7px 10px 4px; border-radius: 10px;
  background: var(--theirs); position: relative; word-wrap: break-word;
}
.msg.mine .bubble { background: var(--mine); }
.text { white-space: pre-wrap; font-size: 15px; line-height: 1.35; }
.text.undecryptable { color: var(--danger); font-style: italic; }
.meta { font-size: 10px; color: var(--muted); margin-top: 2px; display: flex; align-items: center; justify-content: flex-end; gap: 5px; }
.del-btn {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 11px; padding: 0; line-height: 1; opacity: 0; transition: opacity .15s;
}
.bubble:hover .del-btn { opacity: .65; }
.del-btn:hover { opacity: 1 !important; }
@media (hover: none) { .del-btn { opacity: .5; } }
.media { display: flex; flex-direction: column; gap: 6px; }
.media-name { font-size: 12px; color: var(--muted); }
.media img, .media video { max-width: 100%; max-height: 380px; border-radius: 8px; cursor: pointer; }
.media-load, .media .dl {
  background: var(--panel-2); color: var(--text); border: none; border-radius: 6px;
  padding: 8px 12px; cursor: pointer; text-decoration: none; display: inline-block; font-size: 14px;
}
.media-loading { font-size: 12px; color: var(--muted); }
.sysnote { align-self: center; background: var(--panel-2); color: var(--muted); font-size: 12px; padding: 4px 12px; border-radius: 10px; margin: 6px 0; }

.typing { font-size: 12px; color: var(--accent); padding: 2px 16px; }

.upload { display: flex; align-items: center; gap: 10px; padding: 6px 14px; font-size: 12px; color: var(--muted); }
.upload .bar { flex: 1; height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; }
.upload .bar > div { height: 100%; width: 0; background: var(--accent); transition: width .15s; }

#composer {
  display: flex; align-items: flex-end; gap: 8px; padding: 8px 10px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  background: var(--panel); border-top: 1px solid var(--panel-2);
}
#attach-btn { font-size: 22px; cursor: pointer; padding: 6px; line-height: 1; }
#msg-input {
  flex: 1; resize: none; background: var(--panel-2); color: var(--text);
  border: 1px solid #2a3942; border-radius: 18px; padding: 10px 14px;
  font-size: 15px; font-family: inherit; outline: none; max-height: 140px; line-height: 1.3;
}
#msg-input:focus { border-color: var(--accent); }
#send-btn {
  background: var(--accent); color: #05231d; border: none; border-radius: 50%;
  width: 42px; height: 42px; font-size: 18px; cursor: pointer; flex: none;
}
