/* knot: calm paper-and-ink palette; one accent for "linked", amber for "relayed". */
:root {
  --paper: #f1f3ef; --surface: #fbfcfa; --rail: #e4e9e4; --ink: #17202a; --muted: #5d6b66; --line: #cdd5cf;
  --link: #0b6e5c; --link-ink: #fff; --relay: #a96a00; --danger: #b3261e; --own: #dcefe8;
  --sans: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root { --paper: #12181d; --surface: #182027; --rail: #0f1418; --ink: #e5eaec; --muted: #93a29d; --line: #2a353c;
    --link: #58c4ad; --link-ink: #08201a; --relay: #e0a53a; --danger: #ff8a80; --own: #1d3a34; }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 16px/1.5 var(--sans); background: var(--paper); color: var(--ink); }
#app { height: 100%; display: flex; flex-direction: column; }
button, .button, input, textarea, select { font: inherit; color: inherit; }
button, .button { border: 1px solid var(--line); background: var(--surface); padding: .45rem .9rem; border-radius: 8px; cursor: pointer; text-decoration: none; display: inline-block; }
button:hover:not(:disabled), .button:hover { border-color: var(--link); }
button:disabled { opacity: .55; cursor: default; }
button.primary { background: var(--link); border-color: var(--link); color: var(--link-ink); }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }
textarea, input[type=text], select { width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: .5rem .65rem; resize: vertical; }
textarea.code { font: .85rem/1.35 var(--mono); word-break: break-all; }

.shell { display: grid; grid-template-columns: 17rem 1fr; flex: 1; min-height: 0; }
.rail { background: var(--rail); display: flex; flex-direction: column; border-right: 1px solid var(--line); min-height: 0; }
.rail header, .stage-head { display: flex; align-items: center; gap: .5rem; padding: .75rem 1rem; }
.rail h1 { margin: 0; font-size: 1.35rem; letter-spacing: .02em; flex: 1; }
.rail .version { margin-left: .5rem; font-size: .7rem; font-weight: 400; letter-spacing: 0; color: var(--muted); }
.rooms { list-style: none; margin: 0; padding: 0 .5rem; flex: 1; overflow-y: auto; }
.room-item { width: 100%; display: flex; justify-content: space-between; align-items: center; border-color: transparent; background: transparent; text-align: left; }
.room-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-name.new { font-weight: 700; }
.unread { flex: none; margin-inline: .4rem; min-width: 1.4rem; padding: 0 .4rem; border-radius: 99px; text-align: center; font-size: .75rem; background: var(--ink); color: var(--paper); }
.room-item[aria-current=true] { background: var(--surface); border-color: var(--line); }
.dot { min-width: 1.4rem; text-align: center; border-radius: 99px; font-size: .75rem; color: var(--muted); }
.dot.on { background: var(--link); color: var(--link-ink); }
.rail footer { padding: .75rem 1rem; display: flex; gap: .5rem; }
.rail footer button { flex: 1; }

.stage { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.stage.dropping::after { content: attr(data-drop); position: absolute; inset: .5rem; z-index: 5; display: grid; place-items: center; border: 2px dashed var(--link); border-radius: 12px; background: var(--surface); opacity: .92; color: var(--link); font-size: 1.2rem; pointer-events: none; }
.stage-head h2 { margin: 0; font-size: 1.1rem; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stage-head .back { display: none; }
.brokers { color: var(--muted); font-size: .8rem; }
.peers { user-select: none; -webkit-touch-callout: none; list-style: none; margin: 0; padding: 0 1rem .5rem; display: flex; flex-wrap: wrap; gap: .4rem; }
.peer { font-size: .8rem; padding: .1rem .6rem; border-radius: 99px; border: 1.5px solid var(--line); color: var(--muted); }
.peer.p2p { border-style: solid; border-color: var(--link); color: var(--link); }
.peer.relay { border-style: dashed; border-color: var(--relay); color: var(--relay); }
.peer.connecting { border-style: dotted; }
.peer.online { border-color: var(--link); color: var(--link); }
.peer.offline { border-style: dotted; }
.peer.me { font-weight: 600; }
.peer.group { color: var(--ink); }
.peer .seg.p2p, .peer .seg.online { color: var(--link); }
.peer .seg.relay { color: var(--relay); }
.peer .seg.offline, .peer .seg.seen, .peer .seg.connecting { color: var(--muted); }
.log { list-style: none; margin: 0; padding: 1rem; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: .6rem; background: var(--surface); border-block: 1px solid var(--line); }
.msg { max-width: min(36rem, 85%); padding: .45rem .75rem; border-radius: 10px; background: var(--paper); border: 1px solid var(--line); }
.msg.own { align-self: flex-end; background: var(--own); border-color: transparent; }
.meta { display: flex; align-items: baseline; gap: .4rem; font-size: .75rem; color: var(--muted); }
.acts { margin-left: auto; display: inline-flex; gap: .1rem; opacity: 0; }
.msg:hover .acts, .msg:focus-within .acts { opacity: 1; }
@media (hover: none) { .acts { opacity: 1; } }
.acts button { padding: 0 .4rem; font-size: .75rem; border-radius: 6px; }
.quote { margin: .2rem 0 .3rem; padding: .15rem .6rem; border-left: 3px solid var(--link); border-radius: 4px; background: var(--rail); font-size: .85rem; color: var(--muted); cursor: pointer; overflow-wrap: anywhere; }
.quote.gone { font-style: italic; cursor: default; }
.msg.gone { align-self: center; background: transparent; border-style: dashed; color: var(--muted); font-style: italic; font-size: .85rem; }
.msg.gone .text { margin: 0; }
.msg.flash { outline: 2px solid var(--link); }
.quote-bar { display: flex; align-items: center; gap: .5rem; padding: .3rem 1rem; border-top: 1px solid var(--line); background: var(--rail); font-size: .85rem; }
.quote-bar[hidden], .conninfo[hidden] { display: none; }
.quote-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conninfo { padding: .4rem 1rem; font: .8rem/1.5 var(--mono); background: var(--rail); border-block: 1px solid var(--line); overflow-wrap: anywhere; }
.text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.file { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.file-name { font-weight: 600; overflow-wrap: anywhere; }
.file-size { color: var(--muted); font-size: .85rem; }
.composer { display: flex; gap: .5rem; padding: .75rem 1rem; align-items: flex-end; padding-bottom: max(.75rem, env(safe-area-inset-bottom)); }
.composer textarea { flex: 1; resize: none; max-height: min(9rem, 28vh); overflow-y: auto; }
.attachments { display: flex; flex-wrap: wrap; gap: .4rem; max-height: 6.5rem; overflow-y: auto; padding: .4rem 1rem 0; border-top: 1px solid var(--line); }
.attachments[hidden] { display: none; }
.chip { display: flex; align-items: center; gap: .4rem; max-width: 16rem; padding: .15rem .3rem .15rem .15rem; border: 1px solid var(--line); border-radius: 8px; background: var(--rail); font-size: .8rem; }
.chip-img, .chip-blank { flex: none; width: 2rem; height: 2rem; border-radius: 5px; object-fit: cover; background: var(--line); }
.chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button { padding: 0 .35rem; }
.empty { margin: auto; padding: 2rem; max-width: 28rem; text-align: center; color: var(--muted); }

.imgcard { margin: 0; width: fit-content; max-width: 70vw; } /* as wide as its image */
.imgbtn { position: relative; border: 1px solid var(--line); border-radius: 8px; display: block; width: 100%; padding: 0; overflow: hidden; background: var(--line); cursor: zoom-in; }
.imgbtn img { display: block; max-width: 100%; height: auto; } /* the width and height attributes give size and shape */
.imgbtn img.low { filter: blur(3px); transform: scale(1.05); }
.imgnote { position: absolute; inset: auto 0 0 0; padding: .2rem .5rem; font-size: .75rem; text-align: center; background: rgb(0 0 0 / .6); color: #fff; overflow-wrap: anywhere; }
.imgnote:empty { display: none; }
.imgcap { width: 0; min-width: 100%; display: flex; flex-wrap: wrap; align-items: center; gap: .25rem .6rem; margin-top: .3rem; font-size: .85rem; }
.imgcap .file-name { font-weight: 600; overflow-wrap: anywhere; }
.imgact button, .imgact .button { padding: .1rem .6rem; font-size: .8rem; }
.badge { border: 1px solid var(--line); border-radius: 99px; padding: 0 .5rem; font-size: .7rem; color: var(--muted); }

dialog { width: min(34rem, calc(100vw - 2rem)); max-height: calc(100vh - 2rem); overflow-y: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); color: var(--ink); padding: 1rem 1.25rem; }
dialog.wide { width: min(64rem, calc(100vw - 2rem)); }
dialog h2 { overflow-wrap: anywhere; }
.lightbox-img { display: block; width: 100%; max-height: 70vh; object-fit: contain; background: var(--surface); border-radius: 8px; }
dialog::backdrop { background: rgb(0 0 0 / .45); }
dialog header { display: flex; align-items: center; justify-content: space-between; }
dialog h2, dialog h3 { margin: .25rem 0; } dialog h3 { font-size: 1rem; }
dialog section { margin-block: 1rem; padding-top: .5rem; border-top: 1px solid var(--line); }
dialog p { color: var(--muted); margin: .25rem 0 .6rem; }
.copy-field, .code-input, .pair { display: flex; flex-direction: column; gap: .5rem; margin-block: .5rem; }
.copy-field button { align-self: flex-start; }
.field { display: flex; flex-direction: column; gap: .25rem; margin-block: .6rem; font-size: .9rem; color: var(--muted); }
.check { display: flex; gap: .5rem; align-items: center; margin-block: .4rem; }
.actions { display: flex; gap: .5rem; margin-top: 1rem; }
.qr { width: min(18rem, 100%); align-self: center; border-radius: 6px; image-rendering: pixelated; }
.scan { width: 100%; border-radius: 8px; background: #000; }
.sas { font: 1.4rem var(--mono); letter-spacing: .08em; color: var(--ink); }
.sas-line { color: var(--ink); }

.toast { position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: .5rem 1rem; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90vw; z-index: 10; }
.toast.show { opacity: 1; }

@media (max-width: 720px) {
  .stage-head { flex-wrap: wrap; }
  .shell { grid-template-columns: 1fr; }
  .shell[data-view=rooms] .stage, .shell[data-view=chat] .rail { display: none; }
  .stage-head .back { display: inline-block; }
}
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }

.members-list { list-style: none; margin: 0 0 .5rem; padding: 0; }
.member { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .6rem; padding: .35rem 0; border-bottom: 1px solid var(--line); }
.member-name { flex: 1; display: flex; align-items: center; gap: .4rem; overflow-wrap: anywhere; }
.request { padding: .5rem 0; border-bottom: 1px solid var(--line); }
.request .text { margin: .25rem 0; }

/* calls: a banner when others are in one, and a window of tiles (always dark, like a video call) */
button.icon { padding: .35rem .55rem; line-height: 1; }
.call-buttons { display: inline-flex; }
.call-banner { display: flex; align-items: center; gap: .6rem; padding: .4rem 1rem; background: var(--own); border-block: 1px solid var(--line); font-size: .9rem; }
.call-banner[hidden], .call[hidden] { display: none; }
.call-names { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.call { position: fixed; inset: 0; z-index: 8; display: flex; flex-direction: column; background: #0c1114; color: #e5eaec; padding-top: env(safe-area-inset-top); }
.call button { color: inherit; border-color: #2e3a41; background: #182027; }
.call button.ghost { background: transparent; border-color: transparent; }
.call .danger { background: #b3261e; border-color: #b3261e; color: #fff; }
.call-head { display: flex; align-items: center; gap: .5rem; padding: .5rem 1rem; }
.call-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.call-grid { flex: 1; min-height: 0; overflow-y: auto; display: grid; gap: .5rem; padding: .5rem; grid-template-columns: 1fr; grid-auto-rows: minmax(4rem, 1fr); }
.tile { position: relative; margin: 0; min-height: 0; border-radius: 12px; overflow: hidden; background: #182027; }
.tile video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
.tile.self video { transform: scaleX(-1); }
.tile.novideo video { opacity: 0; }
.avatar { position: absolute; inset: 0; display: none; place-items: center; font-size: 2.5rem; color: #93a29d; }
.tile.novideo .avatar { display: grid; }
.tile figcaption { position: absolute; inset: auto 0 0 0; display: flex; gap: .4rem; padding: .25rem .6rem; background: rgb(0 0 0 / .55); font-size: .85rem; }
.tile-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-status { flex: none; color: #cbd5d9; }
.call-bar { display: flex; flex-wrap: wrap; justify-content: center; gap: .6rem; padding: .75rem 1rem max(.75rem, env(safe-area-inset-bottom)); }
.call-bar .round { width: 3rem; height: 3rem; padding: 0; border-radius: 50%; font-size: 1.2rem; }
.call-bar .danger { white-space: nowrap; }

/* reactions, edits, search, updates */
.edited { color: var(--muted); font-size: .8rem; }
.reactions { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem; margin-top: .3rem; }
.palette { display: inline-flex; flex-wrap: wrap; gap: .15rem; }
.rx { padding: 0 .5rem; border-radius: 99px; font-size: .85rem; line-height: 1.5; }
.rx.mine { border-color: var(--link); background: var(--own); }
.rx.pick { border-color: transparent; background: transparent; font-size: 1.1rem; padding: 0 .3rem; }
.searchbar { display: flex; align-items: center; gap: .5rem; padding: .3rem 1rem; border-block: 1px solid var(--line); background: var(--rail); }
.searchbar[hidden] { display: none; }
.searchbar input { flex: 1; min-width: 0; }
.search-count { flex: none; font-size: .8rem; color: var(--muted); }
.update-bar { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: .5rem; padding: .35rem 1rem; background: var(--link); color: var(--link-ink); font-size: .9rem; }
.update-bar[hidden] { display: none; }
.update-bar button { padding: .1rem .7rem; }
.update-bar button.primary { background: var(--link-ink); color: var(--link); border-color: var(--link-ink); }
.update-bar button.ghost { color: inherit; }
/* a shared screen is shown whole, not cropped, and never mirrored */
.tile.sharing video { object-fit: contain; }
.tile.self.sharing video { transform: none; }
.call-bar button[hidden] { display: none; }
.text a.link { color: var(--link); text-decoration: underline; text-underline-offset: 2px; }

/* more reactions: a quick row, then "+" opens every emoji and a box for any other */
.rx.more { border-color: transparent; background: transparent; padding: 0 .4rem; }
.palette-grid { flex: none; width: 20rem; max-width: 100%; display: grid; grid-template-columns: repeat(auto-fill, minmax(2rem, 1fr)); gap: .1rem; max-height: 10rem; overflow-y: auto; margin-top: .25rem; }
.palette-grid .rx.pick { padding: 0; text-align: center; }
.rx-any { grid-column: 1 / -1; margin-top: .2rem; padding: .15rem .5rem; font-size: .85rem; }

/* call layouts: full screen (default), chat (call beside or above the conversation), mini (a
   bar below the conversation). In chat and mini the conversation stays usable: text, files. */
:root { --call-w: min(24rem, 36vw); --call-h: 40vh; }
.call-bar .round { position: relative; }
.call-bar .count { position: absolute; top: -.25rem; right: -.25rem; min-width: 1.2rem; padding: 0 .3rem; border-radius: 99px; background: #58c4ad; color: #08201a; font-size: .7rem; line-height: 1.2rem; text-align: center; }
.call-bar .count[hidden] { display: none; }
.call[data-mode=mini] { position: relative; inset: auto; z-index: auto; flex: none; flex-direction: row; flex-wrap: wrap; align-items: center; padding-top: 0; }
.call[data-mode=mini] .call-head { flex: 1; min-width: 0; }
.call[data-mode=mini] .call-bar { padding-block: .5rem; }
.call[data-mode=mini] .call-grid { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); } /* still plays, just not seen */
.call[data-mode=chat] { inset: 0 0 0 auto; width: var(--call-w); border-left: 1px solid #2e3a41; }
.shell[data-call=chat] { margin-right: var(--call-w); }
.shell[data-call=chat] .stage-head { flex-wrap: wrap; }
@media (max-width: 1280px) { .shell[data-call=chat] { grid-template-columns: 1fr; } .shell[data-call=chat] .rail { display: none; } }
@media (max-width: 720px) {
  .call[data-mode=chat] { inset: 0 0 auto 0; width: auto; height: var(--call-h); border-left: 0; border-bottom: 1px solid #2e3a41; }
  .shell[data-call=chat] { margin-right: 0; margin-top: var(--call-h); }
  .shell[data-call=chat][data-view=rooms] .rail { display: flex; }
  .call[data-mode=chat] .call-grid { grid-auto-rows: minmax(5.5rem, 1fr); }
  .call[data-mode=chat] .call-head { padding-block: .1rem; }
  .call[data-mode=chat] .call-bar { padding-block: .35rem; gap: .4rem; }
}

/* everyone in the call is shown, camera or not: the grid splits its space by head count */
.call-grid[data-count="2"], .call-grid[data-count="3"], .call-grid[data-count="4"] { grid-template-columns: repeat(2, 1fr); }
.call-grid[data-count="5"], .call-grid[data-count="6"], .call-grid[data-count="7"], .call-grid[data-count="8"], .call-grid[data-count="9"] { grid-template-columns: repeat(3, 1fr); }
.call-roster { display: none; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .85rem; color: #cbd5d9; }
.call[data-mode=mini] .call-roster { display: block; }
.call[data-mode=mini] .call-title { flex: none; max-width: 40%; }
.call[data-mode=chat] .call-grid[data-count="2"] { grid-template-columns: 1fr; }
.call[data-mode=chat] .call-grid[data-count="5"], .call[data-mode=chat] .call-grid[data-count="6"] { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 720px) {
  .call-grid[data-count="2"] { grid-template-columns: 1fr; }
  .call-grid[data-count="5"], .call-grid[data-count="6"] { grid-template-columns: repeat(2, 1fr); }
  .call[data-mode=chat] .call-grid[data-count="2"] { grid-template-columns: repeat(2, 1fr); }
  .call[data-mode=chat] .call-grid[data-count="3"], .call[data-mode=chat] .call-grid[data-count="4"], .call[data-mode=chat] .call-grid[data-count="5"], .call[data-mode=chat] .call-grid[data-count="6"] { grid-template-columns: repeat(3, 1fr); }
}
.broker-health { list-style: none; margin: 0 0 .4rem; padding: 0; font: .8rem/1.5 var(--mono); overflow-wrap: anywhere; }
.broker-health .up { color: var(--link); }
.broker-health .down { color: var(--danger); }
.storage { margin: 0 0 .4rem; }
.tile.speaking { outline: 3px solid #58c4ad; outline-offset: -3px; }
.instance-open { max-width: 32rem; margin: 4rem auto; padding: 0 1.25rem; }
.devices-list { list-style: none; padding: 0; display: grid; gap: .4rem; }
.devices-list li { display: flex; align-items: center; gap: .5rem; }
.device-alias { flex: 1 1 8rem; min-width: 0; }
