* { box-sizing:border-box; }
:root {
  color-scheme:dark;
  --base:#111916; --panel:#17231d; --surface:#1f2d25; --hover:#293b30;
  --line:#334438; --text:#f3f7f1; --muted:#aebeb3;
  --accent:#dcf985; --accent-text:#1c2b12; --out:#304530;
  --danger:#ffb0a6; --shadow:#060b0880; --pattern:#61785d19;
  --header-height:76px;
  font:15px/1.5 "Segoe UI", system-ui, sans-serif;
}
:root[data-theme="light"] {
  color-scheme:light;
  --base:#edf3ed; --panel:#fbfdf9; --surface:#edf3ec; --hover:#e0ebdf;
  --line:#cedbcf; --text:#1c2c22; --muted:#4d6355;
  --accent:#2c643e; --accent-text:#f7fff4; --out:#dceccb;
  --danger:#9a342d; --shadow:#24443721; --pattern:#55795815;
}
[hidden] { display:none !important; }
body { margin:0; background:var(--base); color:var(--text); }
button, input, textarea { font:inherit; }
button {
  color:inherit; cursor:pointer; border:0; background:none;
  transition:background .16s, color .16s, border-color .16s, box-shadow .16s;
}
button:disabled { cursor:default; opacity:.52; }
:where(button,input,textarea,summary):focus-visible {
  outline:2px solid var(--accent); outline-offset:3px;
}
input, textarea {
  width:100%; min-width:0; border:1px solid var(--line); border-radius:12px;
  background:var(--surface); color:var(--text); padding:.72rem .88rem;
}
input::placeholder, textarea::placeholder { color:var(--muted); }
.primary {
  border-radius:12px; background:var(--accent); color:var(--accent-text);
  font-weight:700; padding:.72rem 1rem; min-height:44px;
}
.primary:hover:not(:disabled) { box-shadow:inset 0 0 0 2px currentColor; }
.link { color:var(--accent); border-radius:10px; padding:.42rem .62rem; }
.link:hover, .theme:hover, .back:hover { background:var(--hover); }
.theme {
  position:fixed; z-index:2; top:17px; right:20px; width:42px; height:42px;
  display:grid; place-items:center; border:1px solid var(--line); border-radius:13px;
  color:var(--accent); background:var(--panel); font-size:20px;
}
.theme::before { content:"☀"; }
[data-theme="light"] .theme::before { content:"☾"; }
.brand {
  display:flex; align-items:center; gap:12px; font-size:1.6rem; line-height:1;
  font-weight:800; letter-spacing:-.06em;
}
.mark {
  flex:none; position:relative; display:block; inline-size:40px; aspect-ratio:1;
  border-radius:30%; color:#182612; background:#dcf985;
}
.mark::before {
  content:""; position:absolute; inset:24% 26% 27% 25%;
  border:.14em solid currentColor; border-radius:12% 58% 58% 12%;
  border-width:max(2px,.21em); font-size:1em;
}
.mark::after {
  content:""; position:absolute; inset:auto 22% 21% auto;
  inline-size:15%; aspect-ratio:1; border-radius:50%; background:currentColor;
  box-shadow:0 0 0 .11em #dcf985;
}
.gate {
  display:grid; place-items:center; min-height:100dvh; padding:72px 24px 32px;
  background:radial-gradient(ellipse at 28% 14%,var(--out),transparent 55%),var(--base);
}
.auth-layout {
  display:grid; grid-template-columns:1fr minmax(340px,440px); width:min(100%,880px);
  overflow:hidden; border:1px solid var(--line); border-radius:26px;
  background:var(--panel); box-shadow:0 25px 70px var(--shadow);
}
.auth-art {
  position:relative; isolation:isolate; display:grid; place-items:center; overflow:hidden;
  border-right:1px solid #78936a40;
  background:radial-gradient(circle at 50% 52%,#2e4c32,#192c24 72%);
}
.auth-art::before, .auth-art::after { content:""; z-index:-1; position:absolute; pointer-events:none; }
.auth-art::before {
  inset:0; opacity:.57;
  background-image:radial-gradient(#b2c99055 1px,transparent 1px);
  background-size:20px 20px;
  mask-image:linear-gradient(130deg,transparent 10%,black 48%,transparent 95%);
}
.auth-art::after {
  width:66%; aspect-ratio:1; border:1px solid #bdd89a4d;
  border-radius:50%; box-shadow:0 0 0 26px #98bf780e,0 0 0 54px #98bf780b,0 0 0 84px #98bf7808;
}
.auth-art .mark {
  inline-size:38%; min-inline-size:106px; font-size:clamp(38px,6vw,66px);
  transform:rotate(-9deg); box-shadow:0 20px 55px #0c1e1299;
}
.card { min-width:0; padding:clamp(28px,5vw,48px); }
.card h1 { margin:34px 0 22px; font-size:clamp(1.75rem,4vw,2.25rem); line-height:1.14; letter-spacing:-.04em; }
.card form, .card label { display:grid; gap:7px; }
.card form { gap:16px; }
.card label { font-weight:600; }
.card input, .card small { font-weight:400; }
.card .link { margin:11px 0 0 -.62rem; }
.error { color:var(--danger); }
.error:empty { display:none; }

.workspace { display:grid; grid-template-columns:minmax(265px,342px) minmax(0,1fr); height:100dvh; }
.sidebar {
  min-height:0; display:flex; flex-direction:column; background:var(--panel);
  border-right:1px solid var(--line);
}
.sidebar > .brand {
  min-height:var(--header-height); padding:14px 22px; border-bottom:1px solid var(--line);
}
.navigation { display:grid; gap:8px; padding:16px 16px 10px; }
.navigation h1 { margin:0 3px 6px; font-size:1.35rem; letter-spacing:-.045em; }
.navigation input { padding-block:.62rem; }
#results, .chats { min-height:0; overflow:auto; }
#results { max-height:205px; border:1px solid var(--line); border-radius:12px; }
.chats { flex:1; padding:0 10px 10px; }
.chat, .profile {
  display:flex; align-items:center; text-align:left; gap:11px; border-radius:12px; min-width:0;
}
.chat { width:100%; padding:10px; margin-bottom:3px; border:1px solid transparent; }
.chat:hover, .profile:hover { background:var(--surface); }
.chat.selected { border-color:var(--line); background:var(--hover); box-shadow:inset 3px 0 var(--accent); }
.unread-count {
  flex:none; margin-left:auto; min-width:1.65rem; padding:.12rem .4rem; border-radius:999px;
  background:var(--accent); color:var(--accent-text); font-size:.8rem; font-weight:700; text-align:center;
}
.profile { padding:4px; }
.avatar {
  flex:none; display:grid; place-items:center; width:41px; height:41px; border-radius:50%;
  border:1px solid var(--line); background:var(--out); color:var(--accent); font-weight:750;
}
.words { min-width:0; display:grid; }
.words strong, .words small { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.words small, .muted, .chats-empty { color:var(--muted); }
.chats-empty { padding:0 12px; }
.account {
  display:flex; justify-content:space-between; gap:5px; align-items:center;
  padding:11px 15px; border-top:1px solid var(--line);
}

.conversation {
  min-height:0; min-width:0; position:relative; display:flex; flex-direction:column;
  background:radial-gradient(var(--pattern) 1px,transparent 1px) 0 0 / 20px 20px,var(--base);
}
.peer {
  order:-2; display:flex; align-items:center; gap:9px; padding:10px 75px 10px 21px;
  border-bottom:1px solid var(--line); background:var(--panel); min-height:var(--header-height);
}
.connection { order:-1; color:var(--text); background:var(--out); padding:7px 16px; text-align:center; }
.empty { flex:1; display:grid; place-content:center; justify-items:center; text-align:center; padding:22px; }
.empty .mark { inline-size:64px; font-size:25px; box-shadow:0 0 0 9px var(--out); }
.empty h2 { margin:24px 0 0; font-size:1.65rem; letter-spacing:-.04em; }
.empty p { color:var(--muted); margin:6px 0; }
.history { flex:1; min-height:0; overflow:auto; overflow-anchor:none; padding:18px clamp(12px,4vw,64px); }
#messages { display:flex; flex-direction:column; gap:8px; max-width:880px; margin-inline:auto; }
.day {
  align-self:center; margin:8px 0; padding:3px 11px; border:1px solid var(--line);
  border-radius:99px; color:var(--muted); background:var(--panel); font-size:.8rem;
}
.bubble {
  align-self:flex-start; max-width:min(83%,620px); padding:9px 13px 6px;
  border:1px solid var(--line); border-radius:16px 16px 16px 5px;
  background:var(--panel); overflow-wrap:anywhere; white-space:pre-wrap;
}
.mine { align-self:flex-end; background:var(--out); border-radius:16px 16px 5px 16px; }
.bubble time { display:block; color:var(--muted); text-align:right; font-size:.73rem; margin-top:2px; }
.bubble .legacy { display:block; color:var(--muted); font-size:.75rem; }
.older { display:block; margin:0 auto 10px; background:var(--panel); }
.compose {
  display:flex; align-items:end; gap:9px; padding:12px clamp(12px,4vw,64px);
  border-top:1px solid var(--line); background:var(--panel);
}
.compose textarea { flex:1; resize:vertical; min-height:44px; max-height:140px; }
.chat-error { margin:0; padding:6px 18px; background:var(--panel); }
.send-status {
  margin:0; padding:0 clamp(12px,4vw,64px) 9px; background:var(--panel);
  color:var(--muted); font-size:.85rem;
}
.send-status.error, .security .error { color:var(--danger); }
.security {
  padding:8px clamp(12px,4vw,64px); border-bottom:1px solid var(--line);
  background:var(--panel); overflow-wrap:anywhere; font-size:.88rem;
}
.security p { margin:4px 0; color:var(--muted); }
.security summary { color:var(--accent); cursor:pointer; }
.security code { display:block; padding:8px 0; }
.security form { display:flex; gap:8px; flex-wrap:wrap; }
.security form input { flex:1 1 200px; }
.back { display:none; width:42px; height:42px; flex:none; border-radius:11px; font-size:21px; }
dialog {
  color:var(--text); background:var(--panel); border:1px solid var(--line); border-radius:18px;
  max-width:calc(100% - 28px); padding:24px; overflow-wrap:anywhere; box-shadow:0 14px 48px var(--shadow);
}
dialog::backdrop { background:#0a130bb0; }
dialog h2 { padding-right:20px; }
.close { float:right; font-size:23px; }
@media (max-width:720px) {
  .auth-layout { grid-template-columns:1fr; max-width:440px; }
  .auth-art { display:none; }
}
@media (max-width:680px) {
  :root { --header-height:66px; }
  .workspace { grid-template-columns:1fr; }
  .workspace:not(.opened) .conversation, .workspace.opened .sidebar { display:none; }
  .back { display:block; }
  .peer { padding-left:9px; }
  .sidebar { border-right:0; }
  .theme { top:12px; right:13px; }
  .compose button { padding-inline:.72rem; }
}
@media (max-width:400px) {
  .gate { padding-inline:14px; }
  .card { padding:25px 22px; }
}
@media (prefers-reduced-motion:reduce) { button { transition:none; } }
