/* Looks like WhatsApp on the iPhone: beige doodle wallpaper, green bubbles with a tail on the last one of a
   group, time and ticks in the bubble's corner, pill-shaped bars. */
:root {
  color-scheme: light;
  --page:#dcdfe1; --bar:#f6f5f3; --pill:#fff; --pill-line:rgba(0,0,0,.09); --fg:#111b21; --muted:#667781;
  --wall:#efeae2; --doodle:.07; --in:#fff; --out:#d9fdd3; --accent:#1daa61; --on-accent:#fff; --link:#027eb5;
  --chip:#fff; --tick:#53bdeb; --meta:#667781; --line:rgba(0,0,0,.1); --card:#fff; --hover:rgba(0,0,0,.05);
  --quote:rgba(0,0,0,.05); --band:rgba(255,255,255,.55); --shadow:0 1px .5px rgba(11,20,26,.13);
}
/* theme.js sets data-theme from the system or the header switch */
:root[data-theme=dark] {
  color-scheme: dark;
  --page:#070c0f; --bar:#0b141a; --pill:#1f272a; --pill-line:rgba(255,255,255,.08); --fg:#e9edef; --muted:#8696a0;
  --wall:#0b141a; --doodle:.045; --in:#1f272a; --out:#144d37; --accent:#21c063; --on-accent:#0b141a; --link:#8fd3f7;
  --chip:#151c20; --tick:#53bdeb; --meta:rgba(233,237,239,.6); --line:rgba(255,255,255,.1); --card:#233138;
  --hover:rgba(255,255,255,.06); --quote:rgba(0,0,0,.18); --band:rgba(0,0,0,.35); --shadow:0 1px .5px rgba(0,0,0,.25);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
/* 15px instead of the browser's 16px: every size below is in rem, so this scales the whole app.
   No pull-to-refresh or rubber-band bounce; no grey tap flash or double-tap-zoom delay. */
html { font-size: 15px; overscroll-behavior: none; -webkit-tap-highlight-color: transparent; touch-action: manipulation; -webkit-text-size-adjust: 100%; }
body { background: var(--page); color: var(--fg); font: 1rem/1.4 -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", Roboto, sans-serif; }
input:focus, textarea:focus, select:focus { outline: none; }
/* iOS zooms into any text field under 16px when it gets focus. !important: rules like `form input { font: inherit }`
   would otherwise put the login and search fields back at 15px. */
@media (pointer: coarse) { input, textarea { font-size: max(16px, 1rem) !important; } }
button { padding: 10px 16px; border: 0; border-radius: 22px; background: var(--accent); color: var(--on-accent); font: inherit; cursor: pointer; }
button:disabled { opacity: .6; }
.icon-btn { flex: none; display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border-radius: 50%; background: none; color: var(--fg); }
.icon-btn:hover { background: var(--hover); }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* login */
.card { max-width: min(340px, calc(100% - 24px - env(safe-area-inset-left) - env(safe-area-inset-right))); margin: 16vh auto 0; padding: 28px 24px 20px; background: var(--card); border-radius: 18px; box-shadow: 0 2px 12px rgba(0,0,0,.08); }
.card h1 { margin: 0 0 18px; font-size: 1.35rem; font-weight: 600; text-align: center; }
.login-logo { display: block; margin: 0 auto 12px; border-radius: 50%; }
form input, form textarea { width: 100%; padding: 11px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--bar); color: inherit; font: inherit; }
.card input:focus { border-color: var(--accent); }
.card input + input, .card input + .pw-wrap { margin-top: 8px; }
.secret { -webkit-text-security: disc; }
.secret.shown { -webkit-text-security: none; }
.card button[type=submit] { width: 100%; margin-top: 14px; padding: 12px 16px; font-weight: 600; }
.error { color: #dc2626; min-height: 1.4em; margin: 8px 0 0; font-size: .9rem; }
[data-theme=dark] .error { color: #f87171; }
.pw-wrap { position: relative; margin-top: 8px; }
.pw-wrap input { padding-right: 46px; }
.pw-wrap .icon-btn { position: absolute; top: 50%; right: 2px; margin: 0; width: 40px; height: 40px; transform: translateY(-50%); color: var(--muted); }

/* Sized to the visual viewport (set from app.js), so the iOS keyboard doesn't cover the composer. */
#chat { position: fixed; left: 0; right: 0; top: var(--app-top, 0px); height: var(--app-h, 100dvh); display: flex; flex-direction: column; max-width: 760px; margin: 0 auto; background: var(--bar); }
@media (min-width: 761px) { #chat, #gallery { box-shadow: 0 0 24px rgba(0,0,0,.12); } }

/* header: the chat in one pill (picture, name, who's online or typing), the buttons in another */
header { position: relative; z-index: 3; display: flex; align-items: center; gap: 8px; padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 8px max(10px, env(safe-area-inset-left)); background: var(--bar); }
.hdr-chat, .hdr-pill { display: flex; align-items: center; min-height: 52px; border: 1px solid var(--pill-line); border-radius: 26px; background: var(--pill); box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.hdr-chat { flex: 1; min-width: 0; gap: 10px; padding: 5px 16px 5px 5px; }
.avatar { flex: none; width: 40px; height: 40px; border-radius: 50%; object-fit: cover; }
.hdr-title { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.hdr-title strong { font-size: 1.06rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hdr-title .sub { color: var(--muted); font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hdr-title #peer-typing { color: var(--accent); }
.hdr-title:has(#peer-typing:not([hidden])) #people, .hdr-title:has(#seen-note:not([hidden])) #people,
.hdr-title:has(#seen-note:not([hidden])) #peer-typing { display: none; }
.hdr-pill { flex: none; padding: 0 3px; }
header .hdr-btn { width: 42px; height: 42px; }
header #logout { color: #e5484d; }
/* the switch shows the theme it leads to */
[data-theme=dark] #theme-btn .moon, :root:not([data-theme=dark]) #theme-btn .sun { display: none; }
#people { display: flex; gap: 10px; }
.person { display: inline-flex; flex: none; align-items: center; gap: 4px; cursor: default; }
.dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: #9aa5ac; }
.dot.on { background: var(--accent); }
.dot.away { background: #f5a623; }
.conn { padding: 5px 16px; background: #f5c02f; color: #1a1c20; font-size: .85rem; text-align: center; }

/* messages over the doodle wallpaper */
.msgs-wrap { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; isolation: isolate; background: var(--wall); }
.msgs-wrap::before { content: ""; position: absolute; inset: 0; z-index: -1; background: url(wallpaper.svg) 0 0 / 300px repeat; opacity: var(--doodle); pointer-events: none; }
[data-theme=dark] .msgs-wrap::before { filter: invert(1); }
/* #spacer stands in for the history not loaded yet (app.js resizes it so the view never moves); #list sits at the
   bottom while it is shorter than the screen. The browser's own scroll anchoring is off: app.js does it. */
#messages { flex: 1; overflow-y: auto; overflow-anchor: none; overscroll-behavior: contain; padding: 10px max(14px, env(safe-area-inset-right)) 10px max(14px, env(safe-area-inset-left)); display: flex; flex-direction: column; }
#spacer { flex: none; }
/* Shown at the top of the screen while a fast fling outruns the loading. */
#spacer span { position: sticky; top: 8px; display: block; width: max-content; margin: 8px auto 0; padding: 4px 12px; border-radius: 12px; background: var(--card); color: var(--muted); font-size: .8rem; box-shadow: var(--shadow); }
#spacer:not(.on) span { display: none; }
#list { flex: none; margin-top: auto; display: flex; flex-direction: column; gap: 2px; padding-bottom: 8px; }
.msg { position: relative; max-width: min(80%, 520px); padding: 6px 10px 7px 12px; border-radius: 18px; background: var(--in); box-shadow: var(--shadow); font-size: 1rem; line-height: 1.35; align-self: flex-start; }
.msg.me { align-self: flex-end; background: var(--out); }
.msg:not(.cont) { margin-top: 8px; }
@media (pointer: coarse) { .msg { font-size: 1.0625rem; } }
/* The last message of a group gets the tail in its bottom corner. */
.msg:not(:has(+ .msg.cont))::before { content: ""; position: absolute; z-index: -1; bottom: 0; right: -6px; width: 20px; height: 20px; background: inherit; -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M0 0H14C14 9 15.5 16 20 19.6 13 20.4 7 19.6 0 20Z'/%3E%3C/svg%3E") 0 0 / 100% 100%; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M0 0H14C14 9 15.5 16 20 19.6 13 20.4 7 19.6 0 20Z'/%3E%3C/svg%3E") 0 0 / 100% 100%; }
.msg.other:not(:has(+ .msg.cont))::before { right: auto; left: -6px; transform: scaleX(-1); }
.msg.bad::before, .searching .msg::before { display: none; }
/* Name on the first message of someone else's group only */
.msg .who { margin-bottom: 1px; font-size: .82rem; font-weight: 600; line-height: 1.3; }
.msg .who .name { color: hsl(var(--u, 220) 62% 38%); text-transform: capitalize; }
.msg.me .who, .msg.cont .who { display: none; }
[data-theme=dark] .msg .who .name { color: oklch(82% 0.12 var(--u, 220)); }
.msg .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg .text a { color: var(--link); text-decoration: underline; text-underline-offset: 2px; }
/* Keeps room at the end of the last line for .meta (an invisible copy of it) */
.msg .text::after { content: attr(data-meta); display: inline-block; visibility: hidden; padding-left: 12px; font-size: .6875rem; line-height: 1; white-space: nowrap; }
.msg.me .text::after { padding-right: 20px; }
.msg .meta { position: relative; display: flex; align-items: center; justify-content: flex-end; gap: 3px; height: 15px; margin: -14px -3px -3px 0; color: var(--meta); font-size: .6875rem; line-height: 1; white-space: nowrap; pointer-events: none; }
.msg .meta .time { pointer-events: auto; }
/* A photo without text: time and ticks over its corner */
.msg .photo + .meta { margin: -26px 4px 4px 0; height: 20px; padding: 0 2px; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.6); }
.msg .photo + .meta .tick:not(.read) { background: #fff; }
.msg.bad { font-style: italic; opacity: .7; }
.msg.deleted .text { color: var(--meta); font-style: italic; }
/* A master's view of a deleted message: faded, with who deleted it */
.msg.removed { opacity: .55; }
.msg.removed > .mm-smile { display: none; }
.msg .removed-note { margin-top: 3px; color: var(--meta); font-size: .75rem; font-style: italic; }
.gthumb.removed { opacity: .45; }
/* ticks: grey = sent, blue = seen; a clock while waiting for the server */
.msg .tick { flex: none; width: 17px; height: 11px; background: var(--meta); transition: background-color .3s;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 17 11' fill='none' stroke='%23000' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1 6l3.3 3.3L11.5 1.2M8.2 8.6l.8.7L16 1.2'/%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 17 11' fill='none' stroke='%23000' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1 6l3.3 3.3L11.5 1.2M8.2 8.6l.8.7L16 1.2'/%3E%3C/svg%3E") center / contain no-repeat; }
.msg .tick.read { background: var(--tick); }
.msg .tick.wait { width: 12px; height: 12px;
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' fill='none' stroke='%23000' stroke-width='1.3' stroke-linecap='round'%3E%3Ccircle cx='6' cy='6' r='5'/%3E%3Cpath d='M6 3v3l2 1.3'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' fill='none' stroke='%23000' stroke-width='1.3' stroke-linecap='round'%3E%3Ccircle cx='6' cy='6' r='5'/%3E%3Cpath d='M6 3v3l2 1.3'/%3E%3C/svg%3E"); }

/* day chips and the unread band */
.sep { align-self: center; margin: 10px 0 4px; padding: 4px 12px; border-radius: 10px; background: var(--chip); color: var(--fg); box-shadow: var(--shadow); font-size: .8rem; font-weight: 600; }
.sep.new { align-self: stretch; margin: 10px calc(-1 * max(14px, env(safe-area-inset-right))) 2px calc(-1 * max(14px, env(safe-area-inset-left))); padding: 5px; border-radius: 0; background: var(--band); box-shadow: none; color: var(--muted); font-weight: 500; text-align: center; }
.jump { position: absolute; right: 14px; bottom: 12px; display: grid; place-items: center; width: 42px; height: 42px; padding: 0; border-radius: 50%; background: var(--pill); color: var(--muted); box-shadow: 0 1px 4px rgba(0,0,0,.2); }
.jump .n:empty { display: none; }
.jump .n { position: absolute; top: -8px; left: 50%; min-width: 22px; height: 22px; padding: 0 6px; transform: translateX(-50%); border-radius: 11px; background: var(--accent); color: var(--on-accent); font-size: .75rem; font-weight: 600; line-height: 22px; text-align: center; }

/* search: filters the messages on this page; matches are highlighted via the CSS highlight API */
.search-bar { display: flex; align-items: center; gap: 6px; padding: 0 max(10px, env(safe-area-inset-right)) 8px max(10px, env(safe-area-inset-left)); background: var(--bar); }
.search-bar input { flex: 1; min-width: 0; padding: 9px 14px; border: 1px solid var(--pill-line); border-radius: 20px; background: var(--pill); color: inherit; font: inherit; }
.search-count { flex: none; color: var(--muted); font-size: .85rem; white-space: nowrap; }
.search-bar .link { flex: none; padding: 6px 10px; background: none; color: var(--accent); font-size: .9rem; }
.search-bar .link:disabled { color: var(--muted); }
.search-bar .icon-btn { width: 38px; height: 38px; }
.searching .sep, .msg.hide { display: none !important; }
.searching .msg { margin-top: 6px; }
.searching .msg.other .who { display: block; }
::highlight(search) { background: #facc15; color: #1a1c20; }

/* Notes from the app (not someone typing: that shows in the header) */
.typing { padding: 4px max(16px, env(safe-area-inset-right)) 2px max(16px, env(safe-area-inset-left)); background: var(--bar); color: var(--muted); font-size: .85rem; }

/* message menu. Desktop: on hover an arrow in the bubble's top corner (the menu) and a smiley beside it (the
   reactions). Phones: a long press; the bubble stays lit in a dimmed screen. */
.msg { --bub: var(--in); }
.msg.me { --bub: var(--out); }
.mm-open, .mm-smile { display: none; }
@media (hover: hover) {
  .mm-open, .mm-smile { position: absolute; z-index: 1; display: block; padding: 0; opacity: 0; pointer-events: none; transition: opacity .12s; }
  .msg:hover > .mm-open, .msg:hover > .mm-smile, .msg.menu-src > .mm-open, .mm-open:focus-visible, .mm-smile:focus-visible { opacity: 1; pointer-events: auto; }
  .mm-open { top: 1px; right: 1px; width: 28px; height: 20px; border-radius: 0 16px 0 14px; background: radial-gradient(ellipse at 70% 30%, var(--bub) 55%, transparent 80%); color: var(--meta); }
  .msg:is(.me, .cont):has(> .who + .photo) > .mm-open { top: 4px; right: 4px; border-radius: 0 14px 0 14px; background: radial-gradient(ellipse at 70% 30%, rgba(0,0,0,.45), transparent 75%); color: #fff; }
  .mm-smile { top: 50%; left: 100%; box-sizing: content-box; width: 28px; height: 28px; border: 0 solid transparent; border-left-width: 8px; border-radius: 0; background: none; color: var(--muted); transform: translateY(-50%); }
  .msg.me > .mm-smile { left: auto; right: 100%; border-width: 0 8px 0 0; }
  .mm-open::before, .mm-smile::before { content: ""; display: block; width: 100%; height: 100%; background: currentColor; }
  .mm-open::before { -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9.5l6 6 6-6'/%3E%3C/svg%3E") 70% 35% / 16px no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9.5l6 6 6-6'/%3E%3C/svg%3E") 70% 35% / 16px no-repeat; }
  .mm-smile::before { border-radius: 50%; -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 20.5a8.5 8.5 0 1 0 0-17 8.5 8.5 0 0 0 0 17zM8.5 14a4 4 0 0 0 7 0M9.2 9.5v.6M14.8 9.5v.6'/%3E%3C/svg%3E") center / 22px no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 20.5a8.5 8.5 0 1 0 0-17 8.5 8.5 0 0 0 0 17zM8.5 14a4 4 0 0 0 7 0M9.2 9.5v.6M14.8 9.5v.6'/%3E%3C/svg%3E") center / 22px no-repeat; }
  .mm-smile:hover { color: var(--fg); }
}
@media (hover: none) and (pointer: coarse) {
  /* A tap or a long press opens the menu, so nothing in the chat selects; "Select text" in the menu does. */
  #messages { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
  .msg.selecting .text { -webkit-user-select: text; user-select: text; }
}
#msg-menu { position: fixed; inset: 0; z-index: 8; }
#mm-hole { position: fixed; border-radius: 18px; box-shadow: 0 0 0 200vmax rgba(0,0,0,.5); pointer-events: none; animation: fade-in .15s ease-out; }
#mm-bar, #mm-list { position: fixed; background: var(--card); box-shadow: 0 8px 28px rgba(0,0,0,.25); animation: pop-in .12s ease-out; }
#mm-bar { display: flex; gap: 2px; padding: 5px; border-radius: 26px; }
#mm-bar button { display: grid; place-items: center; width: 42px; height: 42px; padding: 0; border-radius: 50%; background: none; color: var(--muted); font-size: 1.65rem; line-height: 1; }
#mm-bar .mm-emoji { transition: transform .1s; }
#mm-bar .mm-emoji:hover, #mm-bar .mm-emoji:focus-visible { transform: scale(1.15); }
#mm-bar .mm-emoji.mine { background: color-mix(in srgb, var(--accent) 28%, transparent); }
#mm-bar .mm-more { background: var(--hover); }
#mm-list { display: flex; flex-direction: column; min-width: 210px; padding: 6px 0; border-radius: 16px; }
#mm-list button { display: flex; align-items: center; gap: 16px; padding: 10px 20px 10px 16px; border-radius: 0; background: none; color: var(--fg); font-size: .97rem; text-align: left; white-space: nowrap; }
#mm-list button svg { flex: none; color: var(--muted); }
#mm-list button:hover, #mm-list button:focus-visible { background: var(--hover); outline: none; }
#mm-list [data-act="delete"] { margin-top: 5px; border-top: 1px solid var(--line); padding-top: 13px; }
#mm-list [data-act="delete"], #mm-list [data-act="delete"] svg { color: #e5484d; }
@media (hover: none) and (pointer: coarse) { #mm-list button { min-height: 46px; } }
@keyframes fade-in { from { opacity: 0; } }
#toast { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 11; max-width: calc(100vw - 32px); padding: 8px 16px; border-radius: 18px; background: rgba(32,44,51,.94); color: #fff; font-size: .9rem; transform: translateX(-50%); pointer-events: none; animation: fade-in .15s ease-out; }
.msg { touch-action: pan-y; transition: transform .15s; }
.msg.flash { animation: flash 1.4s; }
@keyframes flash { 0%, 50% { box-shadow: 0 0 0 3px #facc15; } 100% { box-shadow: 0 0 0 3px transparent; } }
.msg.edit-src { outline: 2px solid var(--accent); outline-offset: 2px; }

/* quoted message: a tinted box with a bar in the author's colour */
.quote { display: block; width: 100%; margin: 2px 0 5px; padding: 5px 10px; text-align: left; border: 0; border-left: 4px solid hsl(var(--u, 150) 62% 42%); border-radius: 8px; background: var(--quote); color: inherit; font-size: .88rem; line-height: 1.3; }
.quote .q-who { display: block; color: hsl(var(--u, 150) 62% 38%); font-weight: 600; font-size: .82rem; text-transform: capitalize; }
[data-theme=dark] .quote { border-left-color: oklch(72% 0.13 var(--u, 150)); }
[data-theme=dark] .quote .q-who { color: oklch(82% 0.12 var(--u, 150)); }
.quote .q-text { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--muted); }
.quote.gone .q-text { font-style: italic; }
.quote.has-thumb { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 8px; align-items: center; }
.quote.has-thumb .q-who, .quote.has-thumb .q-text { grid-column: 1; }
.quote .q-thumb { grid-column: 2; grid-row: 1 / span 2; width: 42px; height: 42px; margin-right: -6px; object-fit: cover; border-radius: 5px; background: var(--line); }
/* Phones: replies to the text selected in a message */
#quote-sel { position: absolute; left: 50%; bottom: calc(100% + 8px); z-index: 2; transform: translateX(-50%); padding: 9px 18px; border-radius: 20px; background: var(--card); color: var(--accent); font-weight: 600; white-space: nowrap; box-shadow: 0 4px 14px rgba(0,0,0,.2); }
#quote-sel[hidden] { display: none; }

/* reactions: a small pill that overlaps the bubble's bottom edge by 4px; the bubble keeps room under it so the
   next message starts 6px below the pill (as in WhatsApp) */
.msg { --rx-h: 30px; }
@media (hover: none) and (pointer: coarse) { .msg { --rx-h: 36px; } }
.msg:has(> .reacts:not(:empty)) { margin-bottom: calc(var(--rx-h) - 4px + 6px); }
.msg .reacts { position: absolute; left: 10px; top: calc(100% - 4px); height: var(--rx-h); display: flex; align-items: center; gap: 0; padding: 1px 3px; border: 2px solid var(--wall); border-radius: 16px; background: var(--in); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.msg.me .reacts { left: auto; right: 10px; }
.msg .reacts:empty { display: none; }
.react-chip { padding: 1px 5px; border-radius: 12px; background: none; color: var(--muted); font-size: .85rem; line-height: 1.5; }
.react-chip.mine { background: var(--hover); }
@media (hover: none) and (pointer: coarse) { .react-chip { min-height: 30px; padding: 1px 7px; } }

/* composer: + on the left, the box in a pill (emoji inside), the round green send button */
#send-form { position: relative; display: flex; flex-direction: column; padding: 6px max(8px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); background: var(--bar); }
.kb #send-form { padding-bottom: 6px; }
#send-form .row { display: flex; align-items: flex-end; gap: 4px; }
#send-form #attach { width: 42px; height: 42px; }
.composer { flex: 1; min-width: 0; display: flex; align-items: flex-end; min-height: 42px; border: 1px solid var(--pill-line); border-radius: 21px; background: var(--pill); }
#send-form .composer textarea { flex: 1; display: block; min-width: 0; min-height: 40px; padding: 9px 2px 9px 15px; border: 0; border-radius: 0; background: none; line-height: 1.3; resize: none; }
.composer .side { flex: none; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; align-self: stretch; }
#send-form #emoji { width: 40px; height: 40px; color: var(--fg); }
#send-form .icon-btn.small { width: 32px; height: 32px; margin: 4px; color: var(--muted); }
#send-form #expand { margin-bottom: auto; }
#send-form .send { flex: none; display: grid; place-items: center; width: 42px; height: 42px; margin-left: 2px; padding: 0 0 0 3px; border-radius: 50%; }
#send-form .send:active { transform: scale(.94); }
#send-form.busy .send, #send-form.busy .icon-btn { opacity: .5; pointer-events: none; }
/* Typing on a phone: the + folds into a chevron so the box gets the width. */
#send-form #more { display: none; }
@media (hover: none) and (pointer: coarse) {
  #send-form.compact #attach { display: none; }
  #send-form.compact #more { display: grid; margin: 5px 0; color: var(--fg); }
}
#send-form.edit-mode #attach, #send-form.edit-mode #more { display: none !important; }
/* Expanded: the composer takes the whole chat area for long messages. */
#send-form.expanded { flex: 1; min-height: 0; padding-top: 8px; }
#send-form.expanded .row { flex: 1; min-height: 0; }
#send-form.expanded .composer { align-self: stretch; }
#send-form.expanded .composer textarea { align-self: stretch; height: auto !important; max-height: none; }
#send-form.expanded #expand { color: var(--accent); }
#chat:has(#send-form.expanded) .msgs-wrap, #chat:has(#send-form.expanded) #typing { display: none; }

/* reply and edit bars: above the composer, full width */
#reply-bar, #edit-bar { display: flex; align-items: center; gap: 8px; margin: -6px calc(-1 * max(8px, env(safe-area-inset-right))) 6px calc(-1 * max(8px, env(safe-area-inset-left))); padding: 6px max(8px, env(safe-area-inset-right)) 6px 0; border-bottom: 1px solid var(--line); animation: pop-in .15s ease-out; }
#reply-bar .quote { flex: 1; min-width: 0; margin: 0; padding: 4px 12px 4px 18px; border-left-width: 4px; border-radius: 0; background: none; }
#reply-bar .quote .q-thumb { width: 38px; height: 38px; margin-right: 0; }
#reply-bar .quote .q-text { -webkit-line-clamp: 1; white-space: nowrap; display: block; overflow: hidden; text-overflow: ellipsis; color: var(--fg); }
#edit-bar { padding-left: 18px; }
#edit-bar .edit-label { flex: 1; color: var(--accent); font-size: .9rem; font-weight: 600; }
#reply-cancel, #edit-cancel { flex: none; display: grid; place-items: center; width: 40px; height: 40px; padding: 0; border-radius: 50%; background: none; color: var(--fg); }
#reply-cancel:hover, #edit-cancel:hover { background: var(--hover); }
@keyframes pop-in { from { opacity: 0; transform: translateY(6px); } }

/* Photo menu (touch only; desktop goes straight to the file picker) */
#attach-menu { position: absolute; left: max(8px, env(safe-area-inset-left)); bottom: calc(100% + 6px); z-index: 2; display: flex; flex-direction: column; min-width: 210px; padding: 6px; border-radius: 16px; background: var(--card); box-shadow: 0 8px 28px rgba(0,0,0,.2); animation: pop-in .12s ease-out; }
#attach-menu button { display: flex; align-items: center; gap: 14px; padding: 9px 12px; border-radius: 10px; background: none; color: var(--fg); text-align: left; }
#attach-menu button:active, #attach-menu button:hover { background: var(--hover); }
#attach-menu .ic { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; color: #fff; }
#attach-menu .ic svg { width: 22px; height: 22px; }
#attach-menu .gal { background: #007bfc; }
#attach-menu .cam { background: #6b7c85; }
/* Emoji menu: the composer's emoji button and React on a message */
#emoji-menu { position: absolute; right: max(8px, env(safe-area-inset-right)); bottom: calc(100% + 6px); z-index: 2; display: flex; flex-direction: column; width: 352px; max-width: calc(100vw - 16px); height: 380px; max-height: calc(var(--app-h, 100dvh) - 180px); padding: 8px 4px 4px 8px; border-radius: 16px; background: var(--card); box-shadow: 0 8px 28px rgba(0,0,0,.2); animation: pop-in .12s ease-out; }
#emoji-menu[hidden] { display: none; }
#emoji-menu .em-search { flex: none; width: auto; margin: 0 4px 6px 0; padding: 8px 12px; border: 1px solid var(--pill-line); border-radius: 18px; background: var(--bar); font-size: .9rem; }
@media (pointer: coarse) { #emoji-menu .em-search { font-size: 16px; } }
#emoji-menu .em-tabs { flex: none; display: flex; gap: 4px; margin-right: 4px; padding-bottom: 4px; border-bottom: 1px solid var(--line); }
#emoji-menu .em-tabs button { width: 30px; height: 30px; padding: 0; border-radius: 8px; background: none; font-size: 1.05rem; line-height: 1; }
#emoji-menu .em-body { position: relative; flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
#emoji-menu h4 { position: sticky; top: 0; z-index: 1; margin: 0; padding: 8px 2px 4px; background: var(--card); color: var(--muted); font-size: .75rem; font-weight: 600; }
#emoji-menu .em-grid { display: grid; grid-template-columns: repeat(auto-fill, 36px); justify-content: start; }
#emoji-menu .em-grid button { width: 36px; height: 36px; padding: 0; border-radius: 8px; background: none; font-size: 1.4rem; line-height: 1; }
#emoji-menu .em-grid button.mine { background: color-mix(in srgb, var(--accent) 28%, transparent); }
#emoji-menu button:hover { background: var(--hover); }
@media (hover: none) and (pointer: coarse) {
  #emoji-menu .em-grid { grid-template-columns: repeat(auto-fill, 40px); }
  #emoji-menu .em-grid button { width: 40px; height: 40px; }
  #emoji-menu .em-tabs button { width: 40px; height: 36px; }
}

/* photos waiting to be sent */
#attach-bar { display: flex; gap: 8px; padding: 2px 2px 8px; overflow-x: auto; }
.att { position: relative; flex: none; width: 64px; height: 64px; }
.att img { width: 100%; height: 100%; object-fit: cover; border-radius: 12px; display: block; }
.att button { position: absolute; top: -4px; right: -4px; display: grid; place-items: center; width: 22px; height: 22px; padding: 0; border-radius: 50%; background: rgba(0,0,0,.7); color: #fff; font-size: .7rem; }
/* photos in messages */
.msg:has(> .photo) { padding: 4px 4px 6px; }
.msg:has(> .photo) > :not(.photo, .meta, .reacts, .mm-open, .mm-smile) { margin-left: 6px; margin-right: 6px; }
.msg:has(> .photo) > .meta { margin-right: 4px; }
.msg .photo { position: relative; display: block; width: 280px; max-width: 100%; max-height: 360px; margin: 0; padding: 0; border-radius: 14px; overflow: hidden; background: rgba(127,127,127,.2); cursor: zoom-in; }
.msg .who + .photo, .msg .quote + .photo { margin-top: 4px; }
.msg .photo img { display: block; width: 100%; height: 100%; object-fit: cover; }
.msg .photo.loading img { filter: blur(12px); transform: scale(1.1); }
.msg .photo.gone { cursor: default; }
.msg .photo.gone img { filter: blur(12px) grayscale(1); opacity: .5; }
.msg .photo.gone span { position: absolute; inset: 0; display: grid; place-items: center; padding: 8px; color: #fff; font-size: .8rem; text-shadow: 0 1px 3px rgba(0,0,0,.8); }
.msg .photo + .text { margin-top: 5px; }

/* gallery: every photo in the room, newest first, as a masonry of columns (see layoutGallery); a tap opens the lightbox */
#gallery { position: fixed; left: 0; right: 0; top: var(--app-top, 0px); height: var(--app-h, 100dvh); z-index: 9; display: flex; flex-direction: column; max-width: 760px; margin: 0 auto; background: var(--bar); }
#gallery header { gap: 10px; padding-left: max(18px, env(safe-area-inset-left)); }
#gallery header strong { font-size: 1.06rem; font-weight: 600; }
.gallery-count { flex: 1; color: var(--muted); font-size: .9rem; }
#gallery-grid { flex: 1; overflow-y: auto; overscroll-behavior: contain; display: flex; align-items: flex-start; gap: 2px; padding: 0 max(0px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(0px, env(safe-area-inset-left)); }
.gcol { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.gthumb { position: relative; display: block; width: 100%; padding: 0; border: 0; border-radius: 0; overflow: hidden; background: rgba(127,127,127,.2); cursor: zoom-in; }
.gthumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.gthumb.loading img { filter: blur(10px); transform: scale(1.1); }
.gthumb.gone { cursor: default; }
.gthumb.gone img { filter: blur(10px) grayscale(1); opacity: .5; }
.gallery-note { margin: 0; padding: 12px; text-align: center; color: var(--muted); font-size: .9rem; }
/* Flex, not grid: in an auto-sized grid row the image's max-height:100% doesn't apply and tall photos get cut.
   Follows the visual viewport like #chat; touch-action:none hands pinch and drag to app.js. */
#lightbox { position: fixed; left: 0; right: 0; top: var(--app-top, 0px); height: var(--app-h, 100dvh); z-index: 10; display: flex; align-items: center; justify-content: center; padding: 16px; overflow: hidden; background: #000; cursor: zoom-out; touch-action: none; -webkit-user-select: none; user-select: none; }
#lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; transform-origin: 0 0; cursor: zoom-in; -webkit-user-drag: none; }
#lightbox.zoomed img { cursor: grab; }
#lightbox-close { position: absolute; top: max(8px, env(safe-area-inset-top)); right: max(8px, env(safe-area-inset-right)); display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border-radius: 50%; background: rgba(255,255,255,.14); color: #fff; font-size: 1.2rem; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
