:root{color-scheme:light;--bg:#f7f4ee;--card:#fffdf8;--text:#283d36;--muted:#697c72;--accent:#315e4c;--line:#dbe3d9;--bubble:#e5eee4}*{box-sizing:border-box}body{margin:0;background:var(--bg);color:var(--text);font:16px/1.5 system-ui,sans-serif}main{max-width:620px;margin:auto;min-height:100svh;background:var(--card);padding:16px;padding-bottom:max(16px,env(safe-area-inset-bottom))}button,input,textarea,select{font:inherit;border:1px solid var(--line);border-radius:10px;padding:10px;background:var(--bg);color:var(--text)}button{cursor:pointer}button:disabled{opacity:.5;cursor:wait}input,textarea{max-width:100%;min-width:0}label{display:grid;gap:6px;margin:18px 0}.brand{text-align:center;margin:8vh 0 32px;font-size:48px}h1{font:32px Georgia,serif;margin:16px 0}.brand p{font:italic 20px Georgia,serif}#login-form{max-width:360px;margin:auto}#login-form button,#send{background:var(--accent);color:white}header{display:flex;gap:8px;align-items:center;margin-bottom:12px}h2{font-size:19px;margin:0;flex:1}#friend-form{display:flex;gap:8px}#friend-name{flex:1}.friend{display:block;width:100%;text-align:left;margin-top:12px;padding:16px}#pair{padding-top:10vh}output{display:block;overflow-wrap:anywhere;background:var(--bg);padding:16px;border-radius:10px;font-family:monospace}#pair-code{font-size:20px}#chat{height:calc(100dvh - 64px);display:flex;flex-direction:column}#messages{flex:1;overflow:auto;overscroll-behavior:contain;padding:8px 0;min-height:80px}.message{margin:10px 0;max-width:90%;padding:12px;border-radius:14px;background:var(--bg);white-space:pre-wrap;overflow-wrap:anywhere;user-select:text}.message.mine{margin-left:auto;background:var(--bubble)}.message small{display:block;color:var(--muted);font-size:11px;margin-top:6px}.message img{max-width:100%;max-height:260px;display:block;border-radius:8px}#text{width:100%;resize:vertical;max-height:160px}.tools{display:flex;gap:8px;margin-top:6px}#send{margin-left:auto}#draft{display:flex;align-items:center;gap:8px;padding:8px}#draft-name{overflow-wrap:anywhere;flex:1}#preview{max-width:90px;max-height:70px}#status{font-size:13px;color:var(--muted);margin:8px 0;overflow-wrap:anywhere}dialog{width:min(94vw,560px);max-height:80svh;border:1px solid var(--line);border-radius:16px;background:var(--card);color:var(--text)}dialog::backdrop{background:#0006}#emoji-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(45px,1fr));gap:4px;margin-top:12px;max-height:45svh;overflow:auto}#emoji-grid button{font-size:26px;padding:4px}#emoji-search{width:100%;margin-bottom:8px}[hidden]{display:none!important}body.dark{color-scheme:dark;--bg:#131c18;--card:#1b2821;--text:#e9eee8;--muted:#a6b7aa;--accent:#416e58;--line:#33483b;--bubble:#294638}button:focus-visible,input:focus-visible,textarea:focus-visible{outline:2px solid var(--accent);outline-offset:2px}

#chat header h2{min-width:0;overflow-wrap:anywhere}#chat header button{flex-shrink:0}
.monitor-brand{
 display:inline-grid;place-items:center;flex:none;width:32px;height:32px;border-radius:8px;
 background:#2563eb;color:#fff;font-weight:700;text-decoration:none;
}
.monitor-brand-large{width:40px;height:40px;font-size:20px}
.compose-entry{display:grid;grid-template-columns:auto minmax(0,1fr);gap:6px;align-items:start}
.compose-monitor{display:grid;grid-template-rows:32px 10px;justify-items:center}
#peer-typing{color:var(--muted);font:12px/10px monospace}
#peer-typing>span{display:block;animation:typing-dots 1.75s step-end infinite}
@keyframes typing-dots{
 0%{clip-path:inset(0 66.67% 0 0)}
 20%{clip-path:inset(0 33.33% 0 0)}
 40%{clip-path:inset(0)}
 60%{clip-path:inset(0 0 0 33.33%)}
 80%{clip-path:inset(0 0 0 66.67%)}
}
@media(prefers-reduced-motion:reduce){#peer-typing>span{animation:none}}
#login-language-slot:empty{display:none}
#messenger :is(#password,#pair-password){-webkit-text-security:disc}
.toolbar-menu{position:relative;flex:none}
.toolbar-menu>summary{
 display:grid;place-items:center;width:34px;height:34px;list-style:none;cursor:pointer;
 border:1px solid var(--line);border-radius:6px;background:var(--card);
}
.toolbar-menu>summary::-webkit-details-marker{display:none}
.menu-glyph{position:relative;width:16px;height:12px;border-block:2px solid currentColor}
.menu-glyph::after{content:"";position:absolute;inset:3px 0 auto;border-top:2px solid currentColor}
.toolbar-popover{
 position:absolute;z-index:10;inset-inline-end:0;top:calc(100% + 6px);
 display:grid;gap:6px;width:min(200px,75vw);max-height:55dvh;overflow:auto;
 padding:10px;background:var(--card);border:1px solid var(--line);border-radius:8px;
 box-shadow:0 6px 18px rgb(0 0 0 / .15);
}
.toolbar-popover label{margin:0}
.toolbar-popover select{width:100%}
#history-search-open{display:grid;place-items:center;width:37px;height:34px;padding:0}
.search-glyph{position:relative;width:15px;height:15px;margin:-3px 3px 0 0;border:2px solid currentColor;border-radius:50%}
.search-glyph::after{
 content:"";position:absolute;width:7px;height:2px;left:10px;top:10px;
 background:currentColor;border-radius:1px;transform:rotate(45deg);transform-origin:left center;
}
#messenger [data-presence="online"]{--presence-surface:#e0f2fe}
#messenger [data-presence="hidden"]{--presence-surface:#e5e7eb}
body.dark #messenger [data-presence="online"]{--presence-surface:#203a50}
body.dark #messenger [data-presence="hidden"]{--presence-surface:#303a48}
#messenger #friend-list .friend,#messenger #chat-header{background:var(--presence-surface,var(--card))}
#messenger #login-form #login-keyboard{
 width:auto;height:auto;min-height:28px;justify-self:start;margin:0;
 color:var(--text);background:var(--card);border:1px solid var(--line);font-size:12px;
}

.presence{display:inline-block;width:.65em;height:.65em;border:1px solid currentColor;border-radius:50%;flex:none;vertical-align:middle}
.presence.online{background:currentColor}
.presence.signed-in-hidden{background:#808080;opacity:.5}
.message audio,.message video,#recording-body audio,#recording-body video{display:block;width:100%;max-width:320px;max-height:50dvh;margin:6px 0}
#recording-body .tools{flex-wrap:wrap}
.friend{display:flex;align-items:center;gap:.5rem}
.friend-name{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.friend-last-online{flex:none;color:var(--muted);font-size:.75rem;white-space:nowrap}
.auto-logout{display:flex;align-items:center;gap:.5rem;margin:.5rem 0;font-size:.875rem}
.message small.unread{color:#78601c;font-weight:800;-webkit-text-stroke:.15px currentColor}
body.dark .message small.unread{color:#e3cc82}
#friends>header{display:grid;grid-template-columns:auto minmax(0,1fr) auto auto}
.friend-actions{display:flex;gap:6px;flex-wrap:wrap}
.friend-actions button{white-space:nowrap}
@media(max-width:480px){
 #friends>header{grid-template-columns:auto minmax(0,1fr) auto}
 .friend-actions{grid-row:2;grid-column:1/-1}
 #friends-menu{grid-row:1;grid-column:3}
}
.edit-message{line-height:1.4;margin-inline-start:.35rem}
#notification-options label{display:block;margin:.45rem 0}
#edit-text{width:100%;box-sizing:border-box}

.message{margin:1px 0;padding:0 8px;border-radius:9px;line-height:1.05;touch-action:pan-y pinch-zoom}
.message small{display:inline-block;margin:0 0 0 .45em;white-space:nowrap;font-size:.8em}
.chat-size-small{font-size:.8em}
.chat-size-large{font-size:1.25em}
.message-code{margin:.25rem 0;padding:.5rem .65rem;border:1px solid var(--line);border-radius:6px;background:var(--card)}
.message-code pre,#code-text{font:.875rem/1.4 ui-monospace,monospace;tab-size:4}
.message-code pre{margin:.3rem 0 0;white-space:pre-wrap;overflow-wrap:anywhere}
.code-language{font-size:.75rem;color:var(--muted)}
#code-text{width:100%;resize:vertical}
.code-keyword{color:#65369a;font-weight:650}
.code-string{color:#a03239}
.code-number{color:#315e9d}
.code-comment{color:var(--muted)}
body.dark .code-keyword{color:#d6afff}
body.dark .code-string{color:#ffa5a5}
body.dark .code-number{color:#9cc4ff}
#message-history{position:relative;flex:1;min-height:80px;display:flex;flex-direction:column}
#messages{min-height:0;overflow-anchor:none}
#new-messages{position:absolute;right:12px;bottom:8px;background:var(--accent);color:#fff}
.message-day{text-align:center;font-size:.75rem;color:var(--muted);margin:.4rem 0 .2rem}
.message .edit-message,.pask-chat #messenger .message .edit-message{
 min-height:0;padding:0 .25rem;border:0;font-size:.8em;line-height:1;vertical-align:baseline;
}
.reply-quote,#reply-draft{border-inline-start:2px solid var(--accent);padding-inline-start:.4rem;color:var(--muted);font-size:.8em}
#reply-draft{display:flex;align-items:center;gap:.3rem;margin-bottom:.25rem}
#reply-preview{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
#cancel-reply{padding:0 .35rem}

.reaction-badge{margin-inline-start:.35em}
.reaction-by{margin-inline-start:.3em;font-size:.75em;opacity:.5}
#reaction-dialog{width:max-content;max-width:94vw}
#reaction-options{display:flex;flex-wrap:wrap;gap:4px;margin-bottom:8px}
#reaction-options button,#reaction-more,#reaction-remove{padding:4px 8px}
#chat,#messages,#text{font-size:var(--chat-font-size,16px)}
#messenger.chat-open{position:fixed;inset-inline:0;top:var(--chat-viewport-top,0px);height:var(--chat-viewport-height,100dvh);min-height:0;display:flex;flex-direction:column;overflow:hidden}
#messenger.chat-open #chat{flex:1;min-height:0;height:auto}
#chat>header,#chat>#compose,#chat>#draft{flex-shrink:0}
#chat>#message-history{min-height:0}
#chat>header h2{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
#status:empty,#attachments-status:empty,#edit-status:empty{display:none}
#emoji-recents h3{margin:.6rem 0 .25rem;font-size:.85rem;font-weight:600}
#emoji-recent-list{display:flex;gap:4px;overflow-x:auto}
#emoji-recent-list button{flex:none;font-size:24px;padding:4px}
.attachment-entry{display:grid;justify-items:start;gap:5px;padding:8px 0;border-bottom:1px solid var(--line)}
.attachment-entry small{color:var(--muted)}
#media-dialog{width:max-content;min-width:min(240px,94vw);max-width:94vw;max-height:90dvh;overflow:hidden}
#media-dialog[open]{display:flex;flex-direction:column}
#media-dialog header{flex:none;flex-wrap:wrap}
#media-preview{min-height:0;overflow:auto}
#media-preview img{display:block;max-width:none}
#media-preview audio,#media-preview video{display:block;width:min(72vw,520px);max-height:65dvh}
#media-status:empty{display:none}
#media-save{margin-top:.5rem;align-self:start}
#history-search{display:flex;flex:0 0 auto;min-height:0;max-height:min(35dvh,210px);max-height:min(calc(var(--chat-viewport-height,100dvh) / 2),210px);flex-direction:column;gap:4px;margin-bottom:6px}
#history-search-form{display:flex;gap:4px}
#history-search-form input{flex:1;font-size:16px}
#history-search-status{margin:0;font-size:.8rem}
#history-search-status:empty{display:none}
#history-search-results{overflow:auto;min-height:0;overscroll-behavior:contain}
.history-result{display:block;width:100%;text-align:start;padding:4px 8px;margin-block:2px;overflow-wrap:anywhere}
.history-result small{display:block;color:var(--muted)}
.message.history-match{outline:2px solid var(--accent);outline-offset:-2px}
@media(max-width:420px){#chat>header{gap:4px}#chat>header button{padding-inline:7px}}
#admin-dialog details{border-top:1px solid var(--line);padding:.6rem 0}
#admin-dialog summary{cursor:pointer;font-weight:650}
#admin-dialog label{margin:.55rem 0}
#admin-dialog textarea,#admin-dialog select{width:100%}
#admin-text-fields{max-height:240px;overflow:auto;padding-inline:4px}
#admin-color-fields fieldset{margin:.65rem 0}
#admin-color-fields label{display:flex;align-items:center;gap:.55rem;flex-wrap:wrap}
#admin-color-fields input[type=color]{padding:2px;width:40px;height:32px}
