.workspace:has(.communityChat) {
  height: 100dvh;
  min-height: 0;
}
.workspace:has(.communityChat) > .globalHeader,
#main:has(.communityChat) > .sectionMast { flex: none }
.workspace:has(.communityChat) > .journalFoot { display: none }
#main:has(.communityChat) {
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  min-height: 0;
  padding-block: 0 16px;
}
.communityChat {
  display: grid;
  grid-template-columns: clamp(202px, 23%, 280px) minmax(0, 1fr);
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
  margin-top: 16px;
}
.chatRail {
  min-width: 0;
  padding: 0 10px 12px;
  overflow-y: auto;
  background: var(--sidebar);
  border-inline-end: 1px solid var(--line);
}
.chatRail p { margin: 0 8px; overflow-wrap: anywhere }
.chatRail .chatRailTitle {
  display: flex;
  align-items: end;
  height: clamp(86px, 10vh, 120px);
  margin: 0 -10px 12px;
  padding: 14px 18px;
  color: #f6f8f5;
  background: linear-gradient(0deg, rgba(12,19,20,.94), rgba(12,19,20,.12)), var(--image) center 55% / cover;
  font: 600 18px/1.2 var(--sans);
}
.chatRail .chatRailGroup {
  margin: 18px 8px 4px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  font-size: 13px;
  color: var(--muted);
}
.chatChannel {
  display: flex;
  gap: 9px;
  min-height: 44px;
  align-items: center;
  padding: 7px 10px;
  color: var(--muted);
  border-radius: var(--radius-control);
  line-height: 1.2;
}
.chatChannel strong { font-size: 14px; font-weight: 500; overflow-wrap: anywhere }
.chatChannel > svg { width: 17px; height: 17px; color: var(--muted) }
.chatChannel:hover { background: var(--soft); color: var(--ink) }
.chatChannel[aria-current] { color: var(--pale); background: var(--tint) }
.chatChannel[aria-current] > svg { color: inherit }
.chatRail .chatChannel[aria-current] { box-shadow: inset 3px 0 var(--accent) }

.chatRoom {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.chatHeading {
  flex: none;
  min-width: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.chatHeading h1 { margin: 0; font: 600 clamp(17px,2.1vw,25px)/1.16 var(--sans); overflow-wrap: anywhere }
.chatHeading label { display: flex; align-items: center; gap: 8px; margin: 0; flex: none; max-width: 52%; font-size: 12px }
.chatHeadingLabel { white-space: nowrap }
.chatHeading select { min-width: 0; width: auto; max-width: 100%; padding-inline: 8px; font-size: 13px }
.chatLog {
  flex: 1 1 0;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  overscroll-behavior: contain;
  list-style: none;
  margin: 0;
  padding: 12px 0;
}
.chatMessage {
  position: relative;
  display:flex;
  align-items:flex-start;
  gap:6px;
  padding:3px 14px;
}
.chatAvatar {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex:none;
  margin-top: 2px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  color: var(--pale);
  background: var(--tint);
}
.chatAvatar[data-player="0"] { background: #443343; color: #f0c4e1 }
.chatAvatar[data-player="1"] { background: #443824; color: #f4d0a0 }
.chatAvatar[data-player="2"] { background: #2e3b52; color: #d7e3ff }
.chatByline { display: flex; align-items: baseline; flex-wrap: wrap; gap: 3px 9px }
.chatByline b { font-size: 15px }
.chatMessage:has(.chatAvatar[data-player="self"]) .chatByline b { color: var(--pale) }
.chatStamp, .chatSource, .chatEdited { color: var(--muted); font-size: 12px }
.chatSource { color: var(--pale) }
.chatMessage p { margin:0; color:var(--ink); font:400 16px/1.43 var(--sans); white-space:pre-wrap; overflow-wrap:anywhere }
.chatMessageContent {
  min-width:0; max-width:64ch; padding:6px 9px;
  background:var(--sidebar); border:1px solid var(--chrome-line); border-radius:16px 16px 16px 4px;
}
.chatBody { display:flex; flex-wrap:wrap; align-items:baseline; gap:0 10px }
.chatBody p { min-width:0 }
.chatStamp { display:inline-flex; gap:5px; margin-inline-start:auto; white-space:nowrap; font-variant-numeric:tabular-nums }
.chatMessage .chatDeleted { color: var(--muted) }
.chatGrouped { padding-top:1px }
.chatGrouped .chatAvatar { visibility: hidden }
.chatGrouped .chatByline:has(b:only-child), [data-chat-scope^="direct:"] :is(.chatAvatar,.chatByline) { display:none }
.chatGrouped .chatByline b { position:absolute; clip-path:inset(50%); width:1px; height:1px; overflow:hidden }
.chatQuoted {
  display: flex;
  gap: 7px;
  align-items: center;
  min-height: 30px;
  max-width: 100%;
  margin-bottom: 3px;
  padding: 3px 8px;
  border: 0;
  border-inline-start: 2px solid var(--rule);
  border-radius: 4px;
  color: var(--muted);
  font-size: 12px;
}
.chatQuoted span, .chatComposeContext small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap }
.chatMobileBar { display:none }
.chatMessage .chatActionMenu {
  align-self:center; padding:0; flex:none;
  min-width:44px; min-height:44px; width:44px; display:grid; place-items:center;
  color:var(--muted); background:none; border:0; border-radius:var(--radius-control)
}
.chatMessage .chatActionMenu:is(:hover,[aria-expanded=true]) { color:var(--ink); background:var(--soft) }
.chatServerMenu summary::-webkit-details-marker { display:none }
.chatActionMenu svg { width:18px; height:18px; stroke-width:2.5 }
@media (hover:hover) and (pointer:fine) {
  .chatMessage:not(:hover):not(:focus-within) .chatActionMenu[aria-expanded=false] { opacity:.58 }
}
.chatMessage[data-own=true] {
  justify-content:flex-end;
}
.chatMessage[data-own=true] .chatAvatar { display:none }
.chatMessage[data-own=true] .chatMessageContent {
  order:1; background:color-mix(in srgb,var(--accent) 15%,var(--tint));
  border-color:color-mix(in srgb,var(--accent) 48%,var(--line)); border-radius:16px 16px 4px 16px;
}
.chatMessage[data-own=true] .chatByline { justify-content:flex-end }
.chatMessage[data-own=true] .chatStamp { color:var(--ink) }
.chatTools {
  position:absolute; z-index:6; width:min(270px,calc(100% - 12px)); display:grid; gap:2px; padding:6px;
  overflow:auto; overscroll-behavior:contain; background:var(--panel); border:1px solid var(--rule);
  border-radius:var(--radius-control); box-shadow:0 6px 24px #0005;
}
.chatTools[hidden] { display:none }
.chatTools button, .chatReaction {
  display:inline-flex; align-items:center; justify-content:center; gap:4px; font-size:13px; padding:3px 6px;
}
.chatTools button { min-height:44px; background:none; border-color:transparent }
.chatTools button:hover { background:var(--soft) }
.chatTools button svg { width:14px; height:14px }
.chatToolsActions { display:flex; flex-wrap:wrap; gap:1px; border-top:1px solid var(--line); padding-top:2px }
.chatTools .chatMoreReactions { justify-self:start; min-height:36px; color:var(--pale) }
.chatReactionMenu { display:grid; grid-template-columns:repeat(5,minmax(0,1fr)); gap:2px }
.chatReactions { display:flex; align-items:center; flex-wrap:wrap; gap:3px; align-self:center }
.chatReaction { border-radius:7px; font-variant-numeric:tabular-nums }
.chatReactions .chatReaction { min-width:30px; min-height:27px; padding:1px 5px }
.chatReaction[aria-pressed=true] { border-color:var(--accent); background:var(--tint) }
.chatReactionCount { color:var(--muted) }
.chatEmpty { color: var(--muted); padding: 14px 18px }
.chatJump {
  align-self: center;
  margin-block: 4px;
  border-color: var(--rule);
  padding: 4px 14px;
  font-size: 13px;
}
.chatJump[hidden], .chatComposeContext[hidden] { display: none }
#communityCompose, .chatReadOnly {
  flex: none;
  margin: 0;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}
.chatComposeRow, .chatComposeContext, .chatReadOnly { display: flex; gap: 7px; align-items: center }
#communityCompose { position: relative }
.chatComposeRow { align-items: end }
.chatComposeRow textarea, textarea[name=gameText] {
  flex: 1;
  width: 100%;
  min-width: 0;
  min-height: 44px;
  max-height: min(112px, 22dvh);
  color: var(--ink);
  background: var(--sidebar);
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  padding: 10px 12px;
  font: 16px/1.35 var(--sans);
  resize: none;
  field-sizing: content;
}
.chatComposeRow button { display: inline-flex; gap: 8px; align-items: center }
.chatComposeRow .chatComposeIcon {
  flex: none;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 6px;
  border-radius: var(--radius-control);
  color: var(--muted);
}
.chatComposeRow .chatComposeIcon[aria-expanded="true"] { color: var(--pale) }
.chatComposeRow button svg, .chatReadOnly svg { width: 17px; height: 17px }
.chatComposeContext { color: var(--muted); justify-content: space-between; margin-bottom: 7px; font-size: 13px }
.chatComposeContext > span { display: grid; min-width: 0 }
.chatReadOnly { color: var(--muted); font-size: 13px }
@media (max-width:860px) {
  #main:has(.communityChat) { padding-bottom:calc(58px + max(8px,env(safe-area-inset-bottom))) }
  .communityChat { grid-template-columns:minmax(0,1fr); grid-template-rows:auto minmax(0,1fr); margin-top:8px }
  .communityChat > .chatRail { display:none }
  .chatMobileBar {
    display:grid; grid-template-columns:1fr 1fr; gap:6px; padding:5px 6px;
    background:var(--sidebar); border-bottom:1px solid var(--chrome-line); z-index:3; position:relative
  }
  .chatMobileBar > .chatChannel, .chatServerMenu > summary { justify-content:center; min-height:44px }
  .chatServerMenu { margin:0; min-width:0 }
  .chatServerMenu > summary {
    display:flex; align-items:center; gap:6px; list-style:none; color:var(--muted);
    font-size:14px; border-radius:var(--radius-control)
  }
  .chatServerMenu > summary:is(:hover,.gameSelected), .chatServerMenu[open] > summary { background:var(--tint); color:var(--pale) }
  .chatServerMenu > summary svg { width:16px; height:16px }
  .chatServerMenu nav {
    position:absolute; inset-inline:6px; top:100%; overflow:auto; max-height:min(50dvh,340px);
    padding:6px; background:var(--panel); border:1px solid var(--rule); border-radius:var(--radius-control)
  }
}
@media (max-width:560px) {
  #main:has(.communityChat) { padding-inline:8px }
  #main:has(.communityChat) > .sectionMast { padding-inline:6px }
  .chatHeading { padding:4px 10px; gap:6px }
  .chatHeading label { line-height:1.2 }
  .chatHeadingLabel { position:absolute; width:1px; height:1px; overflow:hidden; clip-path:inset(50%); white-space:nowrap }
  .chatHeading select { padding-inline:8px }
  .chatLog { padding-block:8px }
  .chatMessage { padding-inline:8px; gap:5px }
  .chatAvatar { width:26px; height:26px; border-radius:9px; font-size:13px }
  .chatComposeRow button span { position:absolute; clip-path:inset(50%); width:1px; height:1px; overflow:hidden }
}
@media (max-height:520px) and (max-width:860px) {
  .workspace:has(#communityCompose textarea:focus) > .globalHeader,
  #main:has(#communityCompose textarea:focus) > .sectionMast { display:none }
}
@media (max-height:410px) and (max-width:860px) {
  .workspace:has(#communityCompose:focus-within) > .bottom { display:none }
  #main:has(#communityCompose:focus-within) { padding-bottom:5px }
}
