.chat-button { position: relative; }
.chat-button.has-unread { color: #9be7ff; border-color: rgba(79, 210, 255, .75); }
.chat-badge { color: #001826; background: var(--accent); }

.chat-panel {
  --chat-edge: rgba(79, 210, 255, .5);
  position: absolute; top: 3.6rem; left: .75rem; z-index: 12;
  width: min(820px, calc(100% - 1.5rem)); height: min(620px, calc(100% - 7.6rem));
  min-width: 320px; min-height: 300px; max-width: calc(100% - 1.5rem); max-height: calc(100% - 4.5rem);
  display: grid; grid-template-columns: 250px minmax(0, 1fr); overflow: hidden; resize: both;
  background: linear-gradient(180deg, rgba(14, 22, 40, .98), rgba(7, 11, 24, .98));
  border: 1px solid var(--chat-edge); border-top: 3px solid var(--accent); box-shadow: 0 18px 44px rgba(0, 0, 0, .6);
  clip-path: polygon(0 0, calc(100% - 14px) 0, 100% 14px, 100% 100%, 0 100%); animation: rise .18s ease-out both;
}
.chat-panel[hidden] { display: none; }
.chat-panel .rename-eyebrow { color: #8fe3ff; }

.ch-list { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--panel-edge); background: rgba(4, 8, 18, .45); }
.ch-list-head { display: flex; justify-content: space-between; align-items: flex-start; padding: .7rem .8rem .35rem; }
.ch-title { margin: .05rem 0 0; font-family: "Orbitron", sans-serif; font-size: .95rem; letter-spacing: .06em; }
.ch-close { font-size: 1.3rem; line-height: 1; }
.ch-search {
  margin: 0 .7rem .45rem; padding: .35rem .5rem; font: inherit; color: var(--text);
  background: rgba(4, 8, 18, .75); border: 1px solid var(--panel-edge); border-radius: 3px;
}
.ch-search:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; }
.ch-access { position: relative; display: flex; align-items: center; gap: .45rem; margin: 0 .8rem .5rem; font-size: .85rem; color: var(--muted); cursor: pointer; }
.ch-access input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.ch-access .admin-track { flex: none; }
.ch-access input:checked + .admin-track { background: rgba(79, 210, 255, .35); border-color: var(--accent); }
.ch-access input:checked + .admin-track::after { transform: translateX(16px); background: var(--accent); }
.ch-access input:focus-visible + .admin-track { outline: 2px solid var(--accent); outline-offset: 2px; }
.ch-list-body { flex: 1; min-height: 0; overflow-y: auto; padding: 0 .35rem .6rem; }
.ch-group { margin-top: .35rem; }
.ch-group-head { display: flex; align-items: center; gap: .25rem; }
.ch-group-toggle, .ch-system-head {
  flex: 1; display: flex; align-items: center; gap: .35rem; padding: .3rem .4rem; font: inherit; text-align: left;
  color: var(--muted); background: none; border: 0; border-radius: 3px; cursor: pointer;
}
.ch-group-toggle { font-family: "Orbitron", sans-serif; font-size: .68rem; letter-spacing: .12em; text-transform: uppercase; }
.ch-group-toggle:hover, .ch-system-head:hover { color: var(--text); background: rgba(79, 210, 255, .06); }
.ch-caret { width: .8rem; font-size: .75rem; }
.ch-add { width: 22px; height: 22px; padding: 0; font: inherit; font-weight: 700; color: var(--accent); background: none; border: 1px solid var(--panel-edge); border-radius: 3px; cursor: pointer; }
.ch-add:hover { border-color: var(--accent); }
.ch-system-head { font-weight: 600; font-size: .9rem; color: #b7c7dc; }
.ch-system-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-system.locked .ch-system-head { color: var(--muted); opacity: .75; }
.ch-system .ch-entry { margin-left: .8rem; }
.ch-lock { font-size: .7rem; opacity: .7; }
.ch-entry { display: flex; align-items: center; border-radius: 3px; }
.ch-entry:hover { background: rgba(79, 210, 255, .07); }
.ch-merge-bar { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin: 0 .8rem .6rem; padding: .4rem .55rem; font-size: .85rem; color: var(--accent); border: 1px solid var(--accent); border-radius: 3px; background: rgba(79, 210, 255, .08); }
.ch-merge-bar[hidden] { display: none; }
.ch-merge-bar .wp-btn { flex: none; }
.ch-entry.merge-source .ch-entry-main { cursor: default; opacity: .55; }
.ch-entry.merge-pick .ch-entry-main { opacity: 1; cursor: copy; }
.ch-entry.merge-pick:hover { box-shadow: inset 0 0 0 1px var(--accent); }
.ch-entry.active { background: rgba(79, 210, 255, .16); box-shadow: inset 2px 0 0 var(--accent); }
.ch-entry-main {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: .4rem; padding: .28rem .4rem; font: inherit; font-size: .92rem;
  text-align: left; color: #b9c8dc; background: none; border: 0; cursor: pointer;
}
.ch-entry.unread .ch-entry-main { color: var(--text); font-weight: 700; }
.ch-entry.locked .ch-entry-main { color: var(--muted); opacity: .6; }
.ch-entry.muted .ch-entry-main { opacity: .55; }
.ch-entry-icon { flex: none; width: 1rem; font-size: .75rem; text-align: center; color: var(--accent); }
.ch-entry-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.ch-count { min-width: 18px; padding: 0 5px; font-size: .7rem; font-weight: 700; line-height: 16px; text-align: center; color: #001826; background: var(--accent); border-radius: 999px; }
.ch-tag { flex: none; padding: 0 .3rem; font-size: .66rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: #8fe3ff; border: 1px solid rgba(79, 210, 255, .4); border-radius: 2px; }
.ch-tag.ooc { color: var(--warn); border-color: rgba(247, 207, 127, .45); }
.ch-mute { flex: none; display: grid; place-items: center; width: 26px; height: 26px; padding: 0; color: var(--muted); background: none; border: 0; border-radius: 3px; cursor: pointer; opacity: 0; }
.ch-entry:hover .ch-mute, .ch-mute:focus-visible, .ch-mute.on { opacity: 1; }
.ch-mute.on { color: var(--warn); }
.ch-mute:hover { color: var(--text); }
.ch-bell svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; stroke-linecap: round; }
.ch-empty { margin: .2rem .8rem .4rem; font-size: .85rem; color: var(--muted); }

.ch-conversation { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; min-height: 0; min-width: 0; }
.ch-head { display: grid; gap: .35rem; padding: .7rem 1rem .55rem; border-bottom: 1px solid var(--panel-edge); }
.ch-head-main { display: flex; align-items: center; gap: .6rem; min-width: 0; }
.ch-head-text { display: grid; min-width: 0; }
.ch-name { margin: 0; font-size: 1.15rem; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-subtitle { color: var(--muted); font-size: .82rem; }
.ch-back { display: none; padding: .2rem .45rem; font: inherit; color: var(--accent); background: none; border: 1px solid var(--panel-edge); border-radius: 3px; cursor: pointer; }
.ch-actions { display: flex; flex-wrap: wrap; gap: .35rem; }
.ch-actions .wp-btn { padding: .2rem .6rem; font-size: .82rem; }
.ch-rename { display: flex; gap: .35rem; align-items: center; }
.ch-rename input { min-width: 0; padding: .25rem .45rem; font: inherit; color: var(--text); background: rgba(4, 8, 18, .75); border: 1px solid var(--panel-edge); border-radius: 3px; }
.ch-notice { margin: 0; padding: .25rem .5rem; font-size: .84rem; color: #d8f7e6; border-left: 2px solid var(--good); background: rgba(108, 240, 176, .07); }
.ch-notice.bad { color: #ffc2ca; border-color: var(--bad); background: rgba(255, 107, 125, .08); }

.ch-messages { overflow-y: auto; padding: .4rem 0 .6rem; overscroll-behavior: contain; }
.ch-placeholder { display: grid; place-content: center; gap: .3rem; height: 100%; padding: 1.5rem; text-align: center; color: var(--muted); }
.ch-placeholder p { margin: 0; }
.ch-placeholder p:first-of-type { font-size: 1.05rem; color: var(--text); }
.ch-lock-big { font-size: 2rem; opacity: .7; }
.ch-hint { max-width: 34ch; margin: 0 auto !important; font-size: .88rem; }
.ch-loading, .ch-empty-chat { padding: 1rem; text-align: center; color: var(--muted); }
.ch-older { display: block; margin: .3rem auto .6rem; }
.ch-day { display: flex; align-items: center; gap: .6rem; margin: .7rem 1rem .3rem; font-size: .74rem; font-weight: 600; letter-spacing: .06em; color: var(--muted); }
.ch-day::before, .ch-day::after { content: ""; flex: 1; height: 1px; background: var(--panel-edge); }
.ch-message { position: relative; display: grid; grid-template-columns: 40px minmax(0, 1fr); column-gap: .65rem; padding: .3rem 1rem .15rem; }
.ch-message.grouped { padding-top: .05rem; }
.ch-message:hover { background: rgba(79, 210, 255, .045); }
.ch-message.ooc .ch-text { color: #b7c3d3; font-style: italic; }
.ch-avatar { grid-row: span 2; width: 36px; height: 36px; margin-top: .1rem; object-fit: cover; border-radius: 50%; background: rgba(4, 8, 18, .8); border: 1px solid var(--panel-edge); }
.ch-avatar-blank { display: grid; place-items: center; font-weight: 700; color: var(--owner); }
.ch-side-time { align-self: center; font-size: .66rem; text-align: right; color: transparent; }
.ch-message.grouped:hover .ch-side-time { color: var(--muted); }
.ch-body { min-width: 0; }
.ch-meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: .4rem; }
.ch-author { font-weight: 700; font-size: .98rem; color: var(--text); }
.ch-meta time { font-size: .74rem; color: var(--muted); }
.ch-text { font-size: .98rem; line-height: 1.38; overflow-wrap: anywhere; color: #dbe6f4; }
.ch-text .ch-line { display: block; min-height: 1.38em; white-space: pre-wrap; }
.ch-text strong { color: #f1f6fd; }
.ch-text a { color: #6fc9ff; }
.ch-text code { padding: 0 .25rem; font-family: ui-monospace, Consolas, monospace; font-size: .86em; background: rgba(4, 8, 18, .85); border: 1px solid var(--panel-edge); border-radius: 3px; }
.ch-code { margin: .25rem 0; padding: .45rem .6rem; font-family: ui-monospace, Consolas, monospace; font-size: .84rem; white-space: pre-wrap; background: rgba(4, 8, 18, .85); border: 1px solid var(--panel-edge); border-radius: 3px; }
.ch-text blockquote { margin: .15rem 0; padding-left: .6rem; border-left: 3px solid #3d5677; }
.ch-text ul { margin: .15rem 0; padding-left: 1.2rem; }
.ch-text .ch-sub { display: block; font-size: .78rem; color: var(--muted); }
.ch-text .ch-h1, .ch-text .ch-h2, .ch-text .ch-h3 { display: block; margin: .2rem 0; font-weight: 700; }
.ch-text .ch-h1 { font-size: 1.35rem; }
.ch-text .ch-h2 { font-size: 1.18rem; }
.ch-text .ch-h3 { font-size: 1.05rem; }
.ch-spoiler { padding: 0 .15rem; color: transparent; background: #1c2638; border-radius: 3px; cursor: pointer; }
.ch-spoiler.shown { color: inherit; background: rgba(255, 255, 255, .08); }
.ch-mention { padding: 0 .15rem; font-weight: 600; color: #c9d7ff; background: rgba(88, 101, 242, .25); border-radius: 3px; }
.ch-emoji { width: 1.35em; height: 1.35em; vertical-align: -.3em; object-fit: contain; }
.ch-time { padding: 0 .2rem; background: rgba(255, 255, 255, .06); border-radius: 3px; }
.ch-edited { margin-left: .2rem; font-size: .72rem; color: var(--muted); }
.ch-reply-chip {
  display: block; max-width: 100%; margin-bottom: .1rem; padding: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font: inherit; font-size: .8rem; text-align: left; color: var(--muted); background: none; border: 0; cursor: pointer;
}
.ch-reply-chip:hover { color: var(--text); }
.ch-files { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .25rem; }
.ch-image img { display: block; max-width: min(320px, 100%); max-height: 240px; border-radius: 4px; border: 1px solid var(--panel-edge); }
.ch-image.spoiler img { filter: blur(18px); }
.ch-image.spoiler:hover img { filter: none; }
.ch-file { padding: .3rem .55rem; font-size: .88rem; color: #6fc9ff; background: rgba(4, 8, 18, .7); border: 1px solid var(--panel-edge); border-radius: 3px; }
.ch-tools {
  position: absolute; top: -.6rem; right: 1rem; display: none; gap: 1px; padding: 1px;
  background: rgba(8, 14, 28, .98); border: 1px solid var(--panel-edge); border-radius: 4px; box-shadow: 0 4px 12px rgba(0, 0, 0, .45);
}
.ch-message:hover .ch-tools, .ch-tools:focus-within { display: flex; }
.ch-tools button { width: 28px; height: 26px; padding: 0; font: inherit; color: var(--muted); background: none; border: 0; border-radius: 3px; cursor: pointer; }
.ch-tools button:hover { color: var(--text); background: rgba(79, 210, 255, .12); }
.ch-tools button.danger:hover { color: var(--bad); background: rgba(255, 107, 125, .12); }

.ch-composer { display: grid; gap: .25rem; padding: .5rem 1rem .6rem; border-top: 1px solid var(--panel-edge); }
.ch-banner { display: flex; justify-content: space-between; align-items: center; padding: .2rem .5rem; font-size: .84rem; color: var(--muted); background: rgba(79, 210, 255, .07); border-radius: 3px; }
.ch-banner-close { padding: 0 .3rem; font: inherit; font-size: 1.1rem; line-height: 1; color: var(--muted); background: none; border: 0; cursor: pointer; }
.ch-form { position: relative; display: flex; gap: .5rem; align-items: flex-end; }
.ch-form textarea {
  flex: 1; min-width: 0; max-height: 180px; padding: .5rem .65rem; font: inherit; font-size: .98rem; line-height: 1.35; resize: none;
  color: var(--text); background: rgba(4, 8, 18, .8); border: 1px solid var(--panel-edge); border-radius: 4px;
}
.ch-form textarea:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent-dim); }
.ch-counter { position: absolute; right: 5.4rem; bottom: .3rem; font-size: .72rem; color: var(--muted); pointer-events: none; }
.ch-counter.low { color: var(--bad); }
.ch-help { font-size: .72rem; color: var(--muted); }
.ch-readonly { margin: 0; padding: .45rem .6rem; font-size: .9rem; color: var(--muted); text-align: center; background: rgba(4, 8, 18, .5); border: 1px dashed var(--panel-edge); border-radius: 4px; }

.ch-tag.persona { color: #c9f0b8; border-color: rgba(108, 240, 176, .4); }
.ch-fresh { color: #8fe3ff; }
.ch-fresh::before, .ch-fresh::after { background: rgba(79, 210, 255, .35); }
.ch-composer { position: relative; }
.ch-form textarea { overflow-y: hidden; }
.ch-as {
  flex: none; display: flex; align-items: center; gap: .4rem; max-width: 12rem; height: 2.4rem; padding: 0 .5rem 0 .3rem; font: inherit; font-size: .85rem;
  color: var(--muted); background: rgba(4, 8, 18, .8); border: 1px solid var(--panel-edge); border-radius: 4px; cursor: pointer;
}
.ch-as:hover, .ch-as.open { color: var(--text); border-color: var(--accent-dim); }
.ch-as.on { color: #c9f0b8; border-color: rgba(108, 240, 176, .45); }
.ch-as-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-as .ch-caret { font-size: .7rem; }
.ch-as-art { flex: none; width: var(--size, 22px); height: var(--size, 22px); object-fit: cover; border-radius: 50%; background: rgba(4, 8, 18, .8); border: 1px solid var(--panel-edge); }
.ch-as-glyph { display: grid; place-items: center; font-size: calc(var(--size, 22px) * .48); color: var(--owner); }
.ch-as-menu {
  position: absolute; z-index: 5; left: 1rem; bottom: calc(100% - .2rem); display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; gap: .4rem;
  width: min(380px, calc(100% - 2rem)); max-height: min(440px, 60vh); padding: .6rem; background: rgba(8, 14, 28, .98);
  border: 1px solid var(--panel-edge); border-radius: 6px; box-shadow: 0 10px 28px rgba(0, 0, 0, .55);
}
.ch-as-head { display: flex; justify-content: space-between; align-items: center; }
.ch-as-menu .ch-search { margin: 0; width: 100%; }
.ch-as-list { overflow-y: auto; overscroll-behavior: contain; margin: 0 -.3rem; padding: 0 .3rem; }
.ch-as-group h5 {
  display: flex; align-items: center; gap: .4rem; margin: .55rem .2rem .2rem; font-size: .72rem; font-weight: 700; letter-spacing: .07em;
  text-transform: uppercase; color: var(--muted);
}
.ch-as-row {
  display: flex; align-items: center; gap: .55rem; width: 100%; padding: .3rem .4rem; font: inherit; text-align: left; color: var(--text);
  background: none; border: 0; border-radius: 4px; cursor: pointer;
}
.ch-as-row:hover, .ch-as-row:focus-visible { background: rgba(79, 210, 255, .1); outline: none; }
.ch-as-row.picked { background: rgba(108, 240, 176, .1); }
.ch-as-text { display: grid; flex: 1; min-width: 0; }
.ch-as-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .93rem; }
.ch-as-text small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .76rem; color: var(--muted); }
.ch-as-check { flex: none; color: var(--good); font-weight: 700; }
.ch-as-foot { font-size: .72rem; color: var(--muted); }

.ch-list-tools { display: flex; align-items: center; justify-content: space-between; gap: .4rem; margin: 0 .8rem .5rem 0; }
.ch-list-tools .ch-access { margin-bottom: 0; min-width: 0; }
.ch-collapse {
  flex: none; padding: .12rem .4rem; font: inherit; font-size: .74rem; color: var(--muted); background: none;
  border: 1px solid var(--panel-edge); border-radius: 3px; cursor: pointer; white-space: nowrap;
}
.ch-collapse:hover:not(:disabled) { color: var(--text); border-color: var(--accent-dim); }
.ch-collapse:disabled { opacity: .45; cursor: default; }
.ch-gif { display: block; line-height: 0; }
.ch-gif img, .ch-gif video {
  display: block; max-width: min(320px, 100%); height: auto; max-height: 240px; border-radius: 4px; border: 1px solid var(--panel-edge);
  background: rgba(4, 8, 18, .6);
}
.ch-gif-btn {
  flex: none; height: 2.4rem; padding: 0 .55rem; font: inherit; font-size: .78rem; font-weight: 800; letter-spacing: .06em; color: var(--muted);
  background: rgba(4, 8, 18, .8); border: 1px solid var(--panel-edge); border-radius: 4px; cursor: pointer;
}
.ch-gif-btn:hover, .ch-gif-btn.open { color: var(--text); border-color: var(--accent-dim); }
.ch-dice-btn {
  flex: none; height: 2.4rem; padding: 0 .5rem; font: inherit; font-size: 1rem; line-height: 1; color: var(--muted);
  background: rgba(4, 8, 18, .8); border: 1px solid var(--panel-edge); border-radius: 4px; cursor: pointer;
}
.ch-dice-btn:hover { color: var(--text); border-color: var(--accent-dim); }
.ch-roll {
  display: inline-grid; gap: .3rem; max-width: 100%; margin: .15rem 0; padding: .4rem .6rem; border: 1px solid var(--panel-edge);
  border-left: 3px solid var(--accent); border-radius: 4px; background: rgba(4, 8, 18, .55);
}
.ch-roll-head { display: flex; align-items: baseline; gap: .45rem; flex-wrap: wrap; }
.ch-roll-formula { font-weight: 700; color: var(--text); }
.ch-roll-total { margin-left: auto; font-size: 1.25rem; font-variant-numeric: tabular-nums; color: var(--accent); }
.ch-roll-dice { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem; }
.ch-roll-die, .ch-roll-flat {
  display: inline-flex; align-items: baseline; gap: .2rem; padding: .05rem .35rem; border: 1px solid var(--panel-edge); border-radius: 3px;
  font-variant-numeric: tabular-nums; font-weight: 700;
}
.ch-roll-die small { font-size: .65rem; font-weight: 600; color: var(--muted); }
.ch-roll-die.high { border-color: var(--good); color: var(--good); }
.ch-roll-die.low { border-color: var(--bad); color: var(--bad); }
.ch-roll-op { color: var(--muted); font-weight: 700; }
.ch-gif-menu { left: auto; right: 1rem; width: min(420px, calc(100% - 2rem)); }
.ch-gif-grid { columns: 2 140px; column-gap: .35rem; }
.ch-gif-pick {
  display: block; width: 100%; margin: 0 0 .35rem; padding: 0; line-height: 0; background: rgba(4, 8, 18, .6);
  border: 1px solid var(--panel-edge); border-radius: 4px; cursor: pointer; overflow: hidden; break-inside: avoid;
}
.ch-gif-pick:hover, .ch-gif-pick:focus-visible { border-color: var(--accent); outline: none; }
.ch-gif-pick img { display: block; width: 100%; min-height: 60px; object-fit: cover; }
.ch-gif-more { display: block; margin: .3rem auto; }
.ch-gif-menu .ch-empty.bad { color: var(--bad); }

.ch-mention-menu { grid-template-rows: minmax(0, 1fr) auto; max-height: min(320px, 50vh); }
.ch-mention-menu .ch-as-group h5, .ch-mention-menu h5 {
  margin: .45rem .2rem .15rem; font-size: .7rem; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--muted);
}
.ch-mention-menu .ch-as-row.picked { background: rgba(79, 210, 255, .16); }
.ch-message.mentioned { background: rgba(247, 207, 127, .07); box-shadow: inset 2px 0 0 var(--warn); }
.ch-message.mentioned:hover { background: rgba(247, 207, 127, .11); }

.chat-panel.narrow { grid-template-columns: minmax(0, 1fr); }
.chat-panel.narrow[data-pane="list"] .ch-conversation, .chat-panel.narrow[data-pane="chat"] .ch-list { display: none; }
.chat-panel.narrow .ch-back { display: inline-block; }
.chat-panel.narrow .ch-list { border-right: 0; }
@media (max-width: 760px) {
  .chat-panel { top: .75rem; height: calc(100% - 4.8rem); resize: none; }
  .ch-help { display: none; }
  .ch-as { max-width: 2.6rem; }
  .ch-as-name, .ch-as .ch-caret { display: none; }
  .ch-gif-btn, .ch-dice-btn { padding: 0 .4rem; }
}
