[hidden] { display:none !important; }   /* "hidden" must win over any display rule below */
:root { --bg:#f6f6f4; --panel:#fff; --ink:#1d1d1f; --muted:#6b6b70; --line:#e3e3e0; --accent:#2f6f5e; --mine:#e3f0eb; --err:#b3261e; }
@media (prefers-color-scheme: dark) { :root { --bg:#151517; --panel:#1f1f22; --ink:#ececec; --muted:#9a9aa0; --line:#333338; --accent:#6cc0a6; --mine:#22382f; --err:#ff8a80; } }
* { box-sizing: border-box; }
body { margin:0; font:15px/1.45 system-ui, sans-serif; background:var(--bg); color:var(--ink); }
main { max-width:1000px; margin:0 auto; height:100vh; height:100dvh; padding:16px; }
#setup { max-width:420px; margin:12vh auto; }
#app:not([hidden]) { display:grid; grid-template-columns:260px 1fr; gap:16px; height:100%; }
aside, .chat { background:var(--panel); border:1px solid var(--line); border-radius:10px; padding:12px; min-height:0; }
.chat { display:flex; flex-direction:column; }
form { display:flex; gap:8px; }
input { flex:1; padding:8px 10px; border:1px solid var(--line); border-radius:6px; background:var(--bg); color:var(--ink); font:inherit; }
button { padding:8px 14px; border:0; border-radius:6px; background:var(--accent); color:#fff; font:inherit; cursor:pointer; }
.muted { color:var(--muted); } .error { color:var(--err); min-height:1.2em; font-size:13px; }
.me { margin-bottom:10px; }
#contacts { list-style:none; padding:0; margin:0; }
#contacts li { padding:8px; border-radius:6px; cursor:pointer; display:flex; justify-content:space-between; }
#contacts li.active { background:var(--mine); }
#contacts .badge { background:var(--accent); color:#fff; border-radius:9px; padding:0 7px; font-size:12px; }
#chat-header { font-weight:600; padding-bottom:8px; border-bottom:1px solid var(--line); display:flex; align-items:center; gap:8px; min-height:36px; }
#chat-title { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.back { display:none; position:relative; background:none; color:var(--accent); font-size:30px; line-height:1; padding:0 10px 4px 2px; }
.back .badge { position:absolute; top:-2px; left:18px; font-size:11px; line-height:16px; }
.safety { font-size:12px; color:var(--muted); padding:6px 0; border-bottom:1px solid var(--line); }
.safety summary { cursor:pointer; padding:2px 0; }
#safety-num { font-family:ui-monospace, monospace; color:var(--ink); letter-spacing:.5px; }
.safety p { margin:6px 0 2px; line-height:1.4; }
#messages { list-style:none; overscroll-behavior:contain; flex:1; overflow-y:auto; padding:8px 0; margin:0; display:flex; flex-direction:column; gap:6px; }
#messages li { max-width:75%; overflow-wrap:anywhere; padding:7px 11px; border-radius:10px; background:var(--bg); align-self:flex-start; white-space:pre-wrap; word-wrap:break-word; }
#messages li.mine { background:var(--mine); align-self:flex-end; }
#messages li.bad { color:var(--err); font-style:italic; }
#messages time { display:block; font-size:11px; color:var(--muted); }
.small { font-size:13px; margin:6px 0 0; }

/* ---- phones / narrow portrait: one pane at a time (list, or the open chat) ---- */
@media (max-width: 700px) {
  main { padding:0; }
  #setup { margin:8vh auto; padding:0 16px; }
  #app:not([hidden]) { grid-template-columns:1fr; gap:0; }
  #app:not(.in-chat) .chat, #app.in-chat aside { display:none; }
  aside, .chat { border:0; border-radius:0; padding:12px max(12px, env(safe-area-inset-right)) 12px max(12px, env(safe-area-inset-left)); }
  aside { overflow-y:auto; padding-top:max(12px, env(safe-area-inset-top)); }
  .chat { padding-top:max(8px, env(safe-area-inset-top)); padding-bottom:max(10px, env(safe-area-inset-bottom)); }
  .back { display:inline-block; }
  input { font-size:16px; padding:10px 12px; }          /* 16px stops iOS zooming in on focus */
  button { padding:10px 16px; }
  #contacts li { padding:14px 10px; border-bottom:1px solid var(--line); border-radius:0; }
  #messages li { max-width:85%; }
  #send-form { padding-top:8px; }
}

/* ---- v0.3 accounts ---- */
form.stack, .stack { display:flex; flex-direction:column; gap:10px; }
.stack.small-gap { gap:6px; margin-bottom:10px; }
.stack p { margin:0; }
.row { display:flex; gap:8px; }
.tabs { display:flex; gap:4px; margin-bottom:14px; border-bottom:1px solid var(--line); }
.tab { background:none; color:var(--muted); border-radius:6px 6px 0 0; border-bottom:2px solid transparent; }
.tab.on { color:var(--ink); border-bottom-color:var(--accent); font-weight:600; }
button.link { background:none; color:var(--accent); padding:2px 0; font-size:13px; text-align:left; }
button.alt { background:var(--bg); color:var(--ink); border:1px solid var(--line); }
button:disabled { opacity:.55; cursor:default; }
#rc-show { max-width:460px; margin:10vh auto; }
.rc { display:block; font:600 18px/1.6 ui-monospace, monospace; letter-spacing:1px; word-spacing:4px; padding:14px;
      margin:14px 0; background:var(--panel); border:1px solid var(--line); border-radius:8px; user-select:all; overflow-wrap:anywhere; }
.check { display:flex; gap:8px; align-items:center; }
.check input { flex:0 0 auto; width:18px; height:18px; }
.acct { display:flex; flex-wrap:wrap; justify-content:space-between; gap:4px 10px; margin:-4px 0 10px; }
.note { background:var(--bg); border:1px solid var(--line); border-radius:6px; padding:8px; color:var(--muted); }
@media (max-width: 700px) { #rc-show { margin:6vh auto; padding:0 16px; } }

/* ---- v0.4 invites ---- */
button.wide { width:100%; margin-bottom:10px; }
.panel { background:var(--bg); border:1px solid var(--line); border-radius:8px; padding:10px; }
.panel p { margin:0; }
.invite-pane { padding:14px 2px; display:flex; flex-direction:column; gap:10px; }
.invite-pane p { margin:0; }
.linkbox { font-size:13px; font-weight:400; letter-spacing:0; word-spacing:0; margin:0; }
.small-tag { font-size:12px; margin-left:auto; padding-left:8px; }
#contacts li span:first-child { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
#messages li.sys { align-self:center; background:none; color:var(--muted); font-size:13px; text-align:center; max-width:90%; }

/* ---- sign-up / sign-in progress panel ---- */
.prog { margin-top:16px; padding:14px 16px; background:var(--panel); border:1px solid var(--line); border-radius:10px; }
.prog-head { display:flex; align-items:center; gap:10px; margin-bottom:10px; }
.prog-shield { width:26px; height:30px; flex:0 0 auto; background:var(--accent); animation:sc-pulse 1.6s ease-in-out infinite;
  -webkit-mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 28'%3E%3Cpath d='M12 1 2 5v8c0 6.6 4.3 11.9 10 14 5.7-2.1 10-7.4 10-14V5L12 1Zm-1.6 18.2-4.6-4.6 1.8-1.8 2.8 2.8 6.6-6.6 1.8 1.8-8.4 8.4Z'/%3E%3C/svg%3E") center/contain no-repeat;
          mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 28'%3E%3Cpath d='M12 1 2 5v8c0 6.6 4.3 11.9 10 14 5.7-2.1 10-7.4 10-14V5L12 1Zm-1.6 18.2-4.6-4.6 1.8-1.8 2.8 2.8 6.6-6.6 1.8 1.8-8.4 8.4Z'/%3E%3C/svg%3E") center/contain no-repeat; }
#prog-steps { list-style:none; margin:0; padding:0; display:flex; flex-direction:column; gap:8px; }
#prog-steps li { display:grid; grid-template-columns:20px 1fr; column-gap:10px; align-items:center; color:var(--muted); font-size:14px; }
#prog-steps li.on { color:var(--ink); font-weight:600; }
#prog-steps li.done { color:var(--ink); }
#prog-steps .dot { width:18px; height:18px; border-radius:50%; border:2px solid var(--line); box-sizing:border-box; position:relative; }
#prog-steps li.on .dot { border-color:var(--line); border-top-color:var(--accent); animation:sc-spin .8s linear infinite; }
#prog-steps li.done .dot { background:var(--accent); border-color:var(--accent); }
#prog-steps li.done .dot::after { content:""; position:absolute; left:4px; top:1px; width:4px; height:8px;
  border:solid #fff; border-width:0 2px 2px 0; transform:rotate(45deg); }
#prog-steps .bar { grid-column:2; display:block; height:6px; margin-top:6px; background:var(--bg); border:1px solid var(--line);
  border-radius:4px; overflow:hidden; }
#prog-steps li:not(.on) .bar, #prog-steps li:not(.on) .note-sm { display:none; }
#prog-steps .fill { display:block; height:100%; width:0; background:var(--accent); border-radius:4px; transition:width .25s ease-out; }
#prog-steps .note-sm { grid-column:2; font-size:12px; font-weight:400; color:var(--muted); margin-top:4px; }
@keyframes sc-spin { to { transform:rotate(360deg); } }
@keyframes sc-pulse { 50% { opacity:.55; transform:scale(.94); } }
@media (prefers-reduced-motion: reduce) { .prog-shield, #prog-steps li.on .dot { animation:none; } #prog-steps .fill { transition:none; } }
/* phones: the panel would sit below the form, under the keyboard; show it as a card over the page */
@media (max-width: 700px) {
  .prog { position:fixed; inset:0; z-index:50; margin:0; border:0; border-radius:0; background:rgba(0,0,0,.45);
          display:flex; align-items:center; justify-content:center;
          padding:max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
  .prog[hidden] { display:none !important; }
  .prog > * { width:100%; max-width:360px; }
  .prog-wrap { background:var(--panel); border:1px solid var(--line); border-radius:14px; padding:18px 18px 20px; box-shadow:0 10px 30px rgba(0,0,0,.25); }
  #prog-steps li { font-size:15px; }
  #prog-steps .bar { height:8px; }
}
