/* Chat (js/ui/chat.js): its window, its place among the town's tools, and in
   the corridors its button beside Report. */

.chat-modal.game-modal {
  /* A name in its calling's colour: the roster's accents (roster.css), a
     step lighter so they read as text. Whispers are the one violet. */
  --chat-warrior:#d4aa72; --chat-mage:#a3bcdc; --chat-rogue:#b4c38e;
  --chat-whisper:#c9b6ee; --chat-whisper-edge:#9a82c8;
  --chat-field:#0c1210; --chat-field-edge:#786547;
  /* Text size, from Settings (data-size). Medium is a step above the rest of
     the window's text: chat is read fast, mid-game. */
  --chat-text:15px;
  width:min(560px,calc(var(--safe-vw) - 32px)); height:min(560px,calc(var(--safe-dvh) - 32px)); max-height:calc(var(--safe-dvh) - 32px);
  padding:22px 24px; display:flex; flex-direction:column; pointer-events:auto;
}
.chat-modal.game-modal[data-size="small"], .chat-feed[data-size="small"] { --chat-text:13px; }
.chat-modal.game-modal[data-size="large"], .chat-feed[data-size="large"] { --chat-text:17px; }
.chat-modal h2,.chat-modal p { margin:0; }
.chat-body { flex:1; min-height:0; display:flex; flex-direction:column; gap:10px; padding-top:14px; }

/* The room: one sunken well, inside the window's single frame. The wrapper
   holds the button to the newest over its foot. */
.chat-room { position:relative; flex:1; min-height:72px; display:flex; flex-direction:column; }
.chat-room:has(> .chat-log[hidden]), .chat-room:has(> .chat-log:empty) { display:none; }
.chat-log {
  position:relative; flex:1; min-height:72px; margin:0; padding:6px 0; list-style:none; overflow-y:auto; overscroll-behavior:contain;
  background:linear-gradient(180deg,#070a09c8,#0a0f0dc0); border:1px solid #74624355; border-radius:4px;
  box-shadow:inset 0 2px 14px #000a; scrollbar-width:thin; scrollbar-color:#746243 #1b241e;
}
.chat-log:focus-visible { outline:2px solid #e9ca8f; outline-offset:2px; }
.chat-log:empty { display:none; }
.chat-log[hidden] { display:none; }

/* A line: who and what flush left, the time small at the right edge, so a
   long message wraps under itself and the names make one straight column. */
.chat-line {
  display:grid; grid-template-columns:minmax(0,1fr) auto; column-gap:10px; align-items:baseline;
  margin:4px 6px 0; padding:4px 8px; border-radius:3px;
  font:400 var(--chat-text)/1.45 "Segoe UI",system-ui,sans-serif; color:#e0d6bf; overflow-wrap:anywhere;
}
.chat-line:first-child, .chat-new-marker:first-child + .chat-line { margin-top:0; }
/* The same voice again, soon after: closer, so a conversation reads as turns. */
.chat-line.chat-follow { margin-top:0; padding-top:1px; }
.chat-time { grid-column:2; grid-row:1; color:#8a8574; font-size:11px; font-variant-numeric:tabular-nums; white-space:nowrap; }
.chat-same-minute:not(:first-child) .chat-time { visibility:hidden; }
/* Below the New rule a line starts afresh: its time shown, its own space. */
.chat-new-marker + .chat-line .chat-time { visibility:visible; }
.chat-new-marker + .chat-line.chat-follow { padding-top:4px; }
@media (hover:hover) and (pointer:fine) {
  .chat-line:not(.chat-own):not(.chat-whisper):hover { background:#ffffff08; }
  .chat-line:hover .chat-time { visibility:visible; }
}
.chat-message { grid-column:1; grid-row:1; min-width:0; }
.chat-who { margin-right:6px; }
.chat-who::after { content:':'; color:#7c7464; }
.chat-text { color:inherit; }
/* What the server hid reads as hidden, not as something said. */
.chat-masked { color:#8c8273; letter-spacing:.04em; }

/* Your own lines carry a faint fill, so you can find what you said. */
.chat-own { background:#a58c5514; }

/* A whisper, to you or from you: violet, with a rule down its edge. */
.chat-whisper { background:#7d62b01a; box-shadow:inset 2px 0 var(--chat-whisper-edge); color:var(--chat-whisper); }
.chat-whisper .chat-who::after { color:#8a7aa8; }
.chat-tag { color:#a995d2; font-size:12px; font-style:italic; }

/* A name is a button that whispers them; it reads as a name, not a button.
   Reset from the window's own button look (windows.css), which is louder. */
#chat-log .chat-name {
  all:unset; display:inline; margin:0 -2px; border-radius:2px; cursor:pointer; color:var(--gold);
  /* windows.css makes every window button a 44px box, with !important. A name
     keeps its line's height; the To list beside the box is the full-size way. */
  min-width:0!important; min-height:0!important; padding:1px 2px!important;
  font:600 var(--chat-text)/1.45 "Segoe UI",system-ui,sans-serif!important;
}
#chat-log .chat-name[data-job="Warrior"] { color:var(--chat-warrior); }
#chat-log .chat-name[data-job="Mage"] { color:var(--chat-mage); }
#chat-log .chat-name[data-job="Rogue"] { color:var(--chat-rogue); }
#chat-log button.chat-name:hover { text-decoration:underline; text-underline-offset:2px; }
/* A line from someone else opens its row anywhere it is pressed. */
#chat-log .chat-line:has(button.chat-name) { cursor:pointer; }
@media (pointer:coarse) { #chat-log button.chat-name { text-decoration:underline dotted; text-underline-offset:3px; } }
#chat-log button.chat-name[aria-expanded="true"] { background:#ffffff12; }
#chat-log button.chat-name:focus-visible { outline:2px solid #e9ca8f; outline-offset:1px; }
#chat-log strong.chat-name { cursor:default; }

/* Where the unread begins, on opening: a rule with "New" on it. */
.chat-new-marker { display:flex; align-items:center; gap:8px; margin:8px 10px 4px; color:#e6b06a; font:700 11px "Segoe UI",system-ui,sans-serif; letter-spacing:.06em; text-transform:uppercase; }
.chat-new-marker::before, .chat-new-marker::after { content:""; flex:1; height:1px; background:#d9a05c88; }
/* More came in while the reader was scrolled up: a way down to it. */
.chat-modal .chat-jump {
  position:absolute; left:50%; bottom:10px; transform:translateX(-50%); z-index:2;
  border-color:#c7ab76; border-radius:22px; padding:8px 16px!important;
  background:linear-gradient(135deg,#4d4430,#2c3229); color:#f3e2bc; box-shadow:0 4px 14px #000a;
}
.chat-jump[hidden] { display:none; }

/* Whisper, Mute, Report: a small shelf under the line whose name was tapped. */
.chat-actions {
  grid-column:1 / -1; display:flex; flex-wrap:wrap; gap:6px; margin:6px 0 2px; padding:6px;
  background:#101814; border:1px solid #74624355; border-radius:3px; box-shadow:0 4px 12px #0007;
}
.chat-modal .chat-actions button[data-action="whisper"] { border-color:#7e6aa6; color:#e1d4f7; }

/* Nothing yet, or chat off: said in the room's place, quietly. */
.chat-empty {
  flex:1; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:4px; padding:16px;
  text-align:center; color:#d6cbb2; font-size:15px;
  background:linear-gradient(180deg,#070a0988,#0a0f0d80); border:1px solid #74624333; border-radius:4px;
}
.chat-empty[hidden] { display:none; }
.chat-empty-icon { width:34px; height:34px; margin-bottom:6px; color:#8c7a55; }

/* Sending: To, the box, Quick and Send as one bar, all one height. */
.chat-form { display:grid; grid-template-columns:auto minmax(0,1fr) auto auto; gap:8px; align-items:stretch; }
.chat-form[hidden] { display:none; }
.chat-form :disabled { opacity:.5; }
/* "To" sits inside its list's box, and the box takes the focus ring. */
.chat-to {
  display:flex; align-items:center; min-height:44px; padding-left:10px; border-radius:3px;
  /* Drawn inside, not as a border: the list fills the whole 44px. */
  box-shadow:inset 0 0 0 1px var(--chat-field-edge);
  background:var(--chat-field); color:#9a8f78; font:600 12px "Segoe UI",system-ui,sans-serif;
}
.chat-to:focus-within { box-shadow:inset 0 0 0 1px #e9ca8f,0 0 0 2px #e9ca8f55; }
.chat-to label { cursor:pointer; }
#chat-modal #chat-to-clear {
  flex:none; min-width:40px!important; min-height:44px!important; padding:0 10px!important; border:0; border-left:1px solid var(--chat-whisper-edge);
  border-radius:0 3px 3px 0; background:transparent; box-shadow:none; color:var(--chat-whisper); font:400 20px/1 "Segoe UI",system-ui,sans-serif!important;
}
#chat-modal #chat-to-clear[hidden] { display:none; }
@media (hover:hover) and (pointer:fine) { #chat-modal #chat-to-clear:hover { background:#7d62b033; } }
#chat-modal select {
  appearance:none; -webkit-appearance:none; cursor:pointer;
  background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23c8a86a' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat:no-repeat; background-position:right 10px center;
}
#chat-modal select option { color:#ead9b8; background:#141e18; }
#chat-modal #chat-to {
  max-width:150px; min-height:44px; padding:0 28px 0 6px; border:0; background-color:transparent;
  color:#f0e2c2; font:600 14px "Segoe UI",system-ui,sans-serif; outline:none!important;
}
#chat-input {
  min-width:0; min-height:44px; padding:0 12px; border:1px solid var(--chat-field-edge); border-radius:3px;
  background:var(--chat-field); color:#f4e8c9; font:400 15px "Segoe UI",system-ui,sans-serif;
}
#chat-input::placeholder { color:#8a8170; }
#chat-modal #chat-input:focus-visible { outline:none!important; border-color:#e9ca8f; box-shadow:0 0 0 2px #e9ca8f55; }
/* Whispering: the box and To turn violet, so nobody tells the room by mistake. */
.chat-form.is-whisper #chat-input { border-color:var(--chat-whisper-edge); }
.chat-form.is-whisper .chat-to { box-shadow:inset 0 0 0 1px var(--chat-whisper-edge); }
.chat-form.is-whisper #chat-input { background:#120f1c; }
.chat-form.is-whisper #chat-input::placeholder { color:#8d7fae; }
.chat-form.is-whisper #chat-to { color:var(--chat-whisper); }
#chat-modal .chat-form.is-whisper #chat-input:focus-visible { border-color:var(--chat-whisper); box-shadow:0 0 0 2px #9a82c866; }
.chat-form.is-whisper .chat-to:focus-within { box-shadow:inset 0 0 0 1px var(--chat-whisper),0 0 0 2px #9a82c866; }
/* Quick opens a row of ready phrases above the bar, and says when it is open. */
.chat-modal #chat-quick[aria-expanded="true"] { border-color:#c7ab76; background:linear-gradient(135deg,#4d4430,#2c3229); color:#f3e2bc; }
.chat-phrases { display:flex; gap:6px; overflow-x:auto; padding:2px; scrollbar-width:none; }
.chat-phrases::-webkit-scrollbar { display:none; }
/* More along the row: it fades at that edge (js/ui/chat.js, edgeFade). */
.chat-phrases.more-right { -webkit-mask-image:linear-gradient(90deg,#000 calc(100% - 40px),transparent); mask-image:linear-gradient(90deg,#000 calc(100% - 40px),transparent); }
.chat-phrases.more-left { -webkit-mask-image:linear-gradient(90deg,transparent,#000 40px); mask-image:linear-gradient(90deg,transparent,#000 40px); }
.chat-phrases.more-left.more-right { -webkit-mask-image:linear-gradient(90deg,transparent,#000 40px,#000 calc(100% - 40px),transparent); mask-image:linear-gradient(90deg,transparent,#000 40px,#000 calc(100% - 40px),transparent); }
.chat-phrases[hidden] { display:none; }
/* The column is tall and narrow: the phrases wrap rather than scroll. */
html.chat-docked .chat-phrases { flex-wrap:wrap; }
.chat-modal .chat-phrases button { flex:none; border-radius:22px; padding:8px 14px!important; font-weight:600!important; white-space:nowrap; }
#btn-send-chat { min-height:44px; min-width:84px; }

.chat-help { color:#8f8a78; font-size:12px; line-height:1.4; }
.chat-help[hidden] { display:none; }
/* What happened to the last thing sent: a short note under the bar. */
#chat-status { padding:6px 10px; border-radius:3px; font-size:13px; line-height:1.4; }
#chat-status:empty { display:none; }
#chat-status[data-tone="warn"] { color:#ebb48f; background:#d96a2b17; }
#chat-status[data-tone="ok"] { color:#b5d29b; background:#6f9e4f17; }

/* How many are online, under the title: the line the shop and the guild keep there. */
.chat-online { margin:4px 0 0; font:12px/1.3 "Segoe UI",system-ui,sans-serif; color:#aeb2a4; }
.chat-online[hidden], #chat-eyebrow[hidden] { display:none; }

/* Settings beside Close; the panel takes the room's and the bar's place while it is open. */
.chat-header-actions { display:flex; gap:8px; align-items:center; }
.chat-settings {
  flex:1; min-height:0; overflow-y:auto; display:flex; flex-direction:column; gap:4px; padding:2px;
  scrollbar-width:thin; scrollbar-color:#746243 #1b241e;
}
.chat-settings[hidden] { display:none; }
.chat-settings h3 { margin:14px 0 4px; padding-top:14px; border-top:1px solid #74624355; font-size:17px; }
/* A setting is a row: what it does on the left, its switch on the right. */
.chat-switch {
  display:flex; align-items:center; justify-content:space-between; gap:16px; min-height:52px; padding:8px 12px;
  border-radius:3px; background:var(--row); color:#ebdfc6; font:600 14px/1.3 "Segoe UI",system-ui,sans-serif; cursor:pointer;
}
@media (hover:hover) and (pointer:fine) { .chat-switch:hover { background:var(--row-hover); } }
.chat-switch small { display:block; margin-top:3px; color:#a39a85; font-weight:400; font-size:12px; }
.chat-switch:has(input:disabled) { cursor:default; }
.chat-switch:has(input:disabled) > span { opacity:.5; }
.chat-modal .chat-switch input[type="checkbox"] {
  appearance:none; -webkit-appearance:none; position:relative; flex:none; width:44px; height:24px; min-height:24px; margin:0; padding:0;
  border:1px solid var(--chat-field-edge); border-radius:12px; background:var(--chat-field); cursor:pointer;
  transition:background-color .16s ease,border-color .16s ease;
}
.chat-modal .chat-switch input[type="checkbox"]::before {
  content:""; position:absolute; top:3px; left:3px; width:16px; height:16px; border-radius:50%;
  background:#8d836d; transition:transform .16s cubic-bezier(.2,.8,.2,1),background-color .16s ease;
}
.chat-modal .chat-switch input[type="checkbox"]:checked { border-color:#c8a86a; background:#6a5530; }
.chat-modal .chat-switch input[type="checkbox"]:checked::before { transform:translateX(20px); background:#f3e0b0; }
.chat-modal .chat-switch input[type="checkbox"]:disabled { cursor:default; opacity:.5; }
@media (prefers-reduced-motion:reduce) {
  .chat-modal .chat-switch input[type="checkbox"], .chat-modal .chat-switch input[type="checkbox"]::before { transition:none; }
}
/* Text size: three choices side by side, each a full-size target. */
.chat-size { display:flex; align-items:center; justify-content:space-between; flex-wrap:nowrap; gap:10px 16px; padding:8px 12px; border-radius:3px; background:var(--row); color:#ebdfc6; font:600 14px/1.3 "Segoe UI",system-ui,sans-serif; }
.chat-size small { display:block; margin-top:3px; color:#a39a85; font-weight:400; font-size:12px; }
#chat-size-label { flex:1; min-width:0; }
html.chat-docked .chat-size { flex-direction:column; align-items:flex-start; }
.chat-size-options { display:flex; flex:none; border:1px solid var(--chat-field-edge); border-radius:4px; overflow:hidden; }
.chat-size-options label { position:relative; cursor:pointer; }
.chat-modal .chat-size-options input { position:absolute; inset:0; width:100%; height:100%; min-height:0; margin:0; padding:0; opacity:0; cursor:pointer; }
.chat-size-options span { display:grid; place-items:center; min-width:64px; min-height:44px; padding:0 12px; color:#d9ccb0; font-weight:600; }
.chat-size-options label + label span { border-left:1px solid var(--chat-field-edge); }
.chat-size-options input:checked + span { background:#6a5530; color:#fbeccb; }
@media (forced-colors:active) {
  .chat-modal .chat-switch input[type="checkbox"], .chat-modal .chat-switch input[type="checkbox"]::before, .chat-size-options span { forced-color-adjust:none; }
  .chat-modal .chat-switch input[type="checkbox"] { background:Canvas; border-color:ButtonText; }
  .chat-modal .chat-switch input[type="checkbox"]::before { background:GrayText; }
  .chat-modal .chat-switch input[type="checkbox"]:checked { background:Highlight; border-color:Highlight; }
  .chat-modal .chat-switch input[type="checkbox"]:checked::before { background:HighlightText; }
  .chat-size-options span { background:Canvas; color:ButtonText; }
  .chat-size-options input:checked + span { background:Highlight; color:HighlightText; }
}
.chat-size-options input:focus-visible + span { outline:2px solid #e9ca8f; outline-offset:-3px; }
.chat-size-options label:nth-child(1) span { font-size:12px; }
.chat-size-options label:nth-child(3) span { font-size:16px; }
.chat-muted { margin:0; padding:0; list-style:none; display:grid; gap:4px; }
.chat-muted li {
  display:flex; align-items:center; justify-content:space-between; gap:10px; padding:4px 4px 4px 12px;
  border-radius:3px; background:var(--row); color:#ddd2ba; font-size:14px;
}
.chat-settings > .chat-help { padding:0 2px; }

/* A short landscape phone: the room as tall as it can be. */
@media (max-height:440px) {
  .chat-modal.game-modal { padding:14px 16px; }
  .chat-body { gap:6px; padding-top:8px; }
  .chat-help { display:none; }
  /* Except where it is the only thing a section says. */
  .chat-settings > .chat-help:not([hidden]), .chat-empty > .chat-help { display:block; }
  /* And where it says why the bar is shut: chat opens at a level. */
  .chat-help.is-locked:not([hidden]) { display:block; }
  .chat-modal.game-modal { --chat-text:14px; }
  .chat-modal.game-modal[data-size="small"] { --chat-text:12px; }
  .chat-modal.game-modal[data-size="large"] { --chat-text:16px; }
  .chat-line { line-height:1.35; margin-top:2px; padding:3px 8px; }
  .chat-line.chat-follow { margin-top:0; padding-top:0; }
  #chat-log .chat-name { font:600 var(--chat-text)/1.35 "Segoe UI",system-ui,sans-serif!important; }
  .chat-room, .chat-log { min-height:56px; }
  .chat-switch { min-height:46px; padding:6px 10px; }
  .chat-settings h3 { margin-top:8px; padding-top:8px; }
  .chat-empty-icon { width:26px; height:26px; margin-bottom:2px; }
  #chat-status { padding:4px 8px; font-size:12px; }
}
/* Beside the game (html.chat-docked, set by js/ui/chat.js where the screen
   has room): a column down the right edge, and the game narrows to make way
   rather than being covered. Under the window backdrop, so a window opened
   over the game dims it with everything else. No ornamented frame: that
   belongs to what floats over the game. */
:root { --chat-dock-w:clamp(320px,24vw,380px); }
html.chat-docked.chat-dock-open #game-container { width:calc(100% - var(--chat-dock-w)); }
html.chat-docked #chat-modal.chat-modal.game-modal {
  top:0; right:0; bottom:0; left:auto; transform:none; z-index:60;
  width:var(--chat-dock-w); height:100dvh; max-height:none; padding:16px 18px 14px;
  border:0; border-left:1px solid #5d4f35; border-radius:0;
  box-shadow:inset 0 0 38px #0006,-10px 0 28px #0008;
}
html.chat-docked #chat-modal::before { display:none; }
html.chat-docked #btn-close-chat .kbd { display:none; }
/* With the column open, a window opens over the game, not over the column:
   centred on what the game has, no wider, and the dimming stops at the
   column, which can still be read and written in. The Guide, inside the
   game's own view, already stops there. */
html.chat-docked.chat-dock-open #modal-backdrop { right:var(--chat-dock-w); }
html.chat-docked.chat-dock-open .game-modal:not(#chat-modal):not(#character-modal):not(#talents-modal):not(#codex-modal):not(#forge-modal) { left:calc((100% - var(--chat-dock-w)) / 2); max-width:calc(100vw - var(--chat-dock-w) - 24px); }
/* Except the four whose own layouts are laid out for the whole screen - the
   hero, the skill tree, the Bestiary and the Forge cramp and overflow beside
   the column (their media queries read the window's width, not their own).
   Those open over everything, as before there was a column, and dim it. */
html.chat-docked.chat-dock-open:has(:is(#character-modal,#talents-modal,#codex-modal,#forge-modal):not(.hidden)) #modal-backdrop { right:0; }
/* The lost-connection notice is about the game: over the game's part. */
html.chat-docked.chat-dock-open #connection-banner { left:calc((100% - var(--chat-dock-w)) / 2); }
html.chat-docked #chat-modal .rpg-window-header { min-height:0; padding-bottom:10px; gap:10px; }
html.chat-docked #chat-modal h2 { font-size:24px; }
html.chat-docked #chat-modal .chat-body { padding-top:12px; }
/* Too narrow for one bar: who it is for and Quick above, the box and Send below. */
html.chat-docked .chat-form { grid-template-columns:minmax(0,1fr) auto; grid-template-areas:"to quick" "input send"; }
html.chat-docked .chat-to { grid-area:to; min-width:0; }
html.chat-docked #chat-input { grid-area:input; }
html.chat-docked #chat-quick { grid-area:quick; }
html.chat-docked #btn-send-chat { grid-area:send; }
html.chat-docked #chat-modal #chat-to { max-width:none; flex:1; min-width:0; }
/* The button that opens the column says when it is open. */
html.chat-docked #btn-chat[aria-expanded="true"], html.chat-docked #btn-chat-field[aria-expanded="true"] { color:#f3dfae; }
html.chat-docked #btn-chat[aria-expanded="true"] { border-color:#c7ab76; }

/* Upright and narrow: who it is for above the box. */
@media (max-width:480px) {
  .chat-form { grid-template-columns:minmax(0,1fr) auto auto; }
  .chat-to { grid-column:1 / -1; }
  #chat-modal #chat-to { max-width:none; flex:1; }
}
/* A tight landscape phone: To and Quick give the box some width back. */
@media (max-width:700px) and (orientation:landscape) {
  #chat-modal #chat-to { max-width:128px; }
  #chat-quick { padding:8px 10px!important; }
  #btn-send-chat { min-width:64px; }
}

/* A phone's keyboard is up (js/ui/chat.js, fitKeyboard): the window takes
   what is left above it - the room, To and the box - and gives the rest back
   when it goes. */
#chat-modal.chat-modal.game-modal.chat-keyboard {
  top:calc(var(--chat-vtop) + 4px); left:calc(var(--chat-vleft, 0px) + var(--chat-vw, 100vw) / 2); transform:translateX(-50%);
  height:calc(var(--chat-vh) - 8px); max-height:calc(var(--chat-vh) - 8px); padding:8px 12px;
}
#chat-modal.chat-keyboard::before { display:none; }
#chat-modal.chat-keyboard .rpg-window-header, #chat-modal.chat-keyboard .chat-help { display:none; }
#chat-modal.chat-keyboard .chat-body { padding-top:0; gap:6px; }
#chat-modal.chat-keyboard .chat-room, #chat-modal.chat-keyboard .chat-log { min-height:0; }
/* Under a thumb the box is 16px: smaller, and a phone zooms the page to type. */
@media (pointer:coarse) { #chat-input, #chat-modal #chat-to { font-size:16px; } }
/* Send waits for the answer without being disabled: a disabled button lets a
   tap through to what is behind it, and the box loses the keyboard. */
#chat-modal #btn-send-chat[aria-disabled="true"] { opacity:.5; cursor:default; }

/* Over the game while chat is shut: the newest lines, a few seconds each,
   bottom left above the controls. Read, never pressed - the game under it
   keeps every tap. Above the town (city.css, 50), under every window (80). */
.chat-feed {
  --chat-text:14px;
  position:absolute; left:18px; bottom:118px; z-index:55;
  width:min(440px,calc(50% - 18px)); display:flex; flex-direction:column; align-items:flex-start; gap:4px;
  pointer-events:none;
}
.chat-feed:empty { display:none; }
/* A window or the Guide over the game: the lines wait out their time unseen. */
body:has(#modal-backdrop:not(.hidden)) .chat-feed, body:has(#onboarding-overlay:not(.hidden)) .chat-feed { display:none; }
/* Heard, not seen: in the page, never display:none, so a screen reader hears each line. */
.chat-announce { position:absolute; width:1px; height:1px; margin:-1px; padding:0; overflow:hidden; clip:rect(0 0 0 0); clip-path:inset(50%); white-space:nowrap; border:0; }
.chat-feed-line {
  margin:0; max-width:100%; padding:5px 10px; border-radius:4px;
  background:#080b0ad9; box-shadow:0 2px 10px #0009; border-left:2px solid #74624399;
  color:#e6dcc4; font:400 var(--chat-text)/1.4 "Segoe UI",system-ui,sans-serif; letter-spacing:0;
  display:-webkit-box; -webkit-line-clamp:2; -webkit-box-orient:vertical; overflow:hidden; overflow-wrap:anywhere;
  animation:chat-feed-in .18s ease-out;
  transition:opacity .6s ease;
}
.chat-feed-line.is-fading { opacity:0; }
.chat-feed-line.chat-whisper { border-left-color:#9a82c8; background:#120f1cd9; color:#d6c6f2; box-shadow:0 2px 10px #0009; }
.chat-feed-who { margin-right:6px; font-weight:600; color:#c89948; }
.chat-feed-who::after { content:':'; color:#7c7464; }
.chat-feed-who[data-job="Warrior"] { color:#d4aa72; }
.chat-feed-who[data-job="Mage"] { color:#a3bcdc; }
.chat-feed-who[data-job="Rogue"] { color:#b4c38e; }
@keyframes chat-feed-in { from { opacity:0; transform:translateY(4px); } }
@media (prefers-reduced-motion:reduce) { .chat-feed-line { animation:none; transition:none; } }
@media (max-width:760px), (max-height:540px) {
  .chat-feed { left:12px; bottom:110px; width:min(360px,calc(50% - 12px)); --chat-text:13px; }
  /* A notice in the middle of the screen (#system-message) owns that band. */
  #viewport:has(#system-message.visible) .chat-feed { visibility:hidden; }
  /* Between the HUD and the controls there is room for two. */
  .chat-feed-line:nth-last-child(n+3) { display:none; }
  /* Town has no controls along its foot, and its labels sit higher: the line goes to the bottom edge. */
  #viewport:has(#city-ui:not(.hidden)) .chat-feed { bottom:12px; left:64px; width:min(360px,calc(50% - 64px)); }
}

@media (orientation:portrait) and (max-width:600px) {
  #viewport:has(#city-ui:not(.hidden)) .chat-feed { width:calc(100% - 76px); }
}
/* Where the town's Chat button shows its label, the count does not sit on it. */
#btn-chat:has(.chat-unread:not([hidden])) .city-control-label { margin-right:14px; }

/* How many came in while it was shut, on both its buttons. */
.chat-unread {
  position:absolute; top:-4px; right:-4px; min-width:18px; height:18px; padding:0 5px; border-radius:9px;
  display:grid; place-items:center; background:#b94343; color:#fff4e0; box-shadow:0 0 0 2px #0b0d10;
  font:700 11px/18px "Segoe UI",system-ui,sans-serif; letter-spacing:0; pointer-events:none;
}
.chat-unread[hidden] { display:none; }
#btn-chat { position:relative; }

/* In the corridors: Report's frame, 52px to its left (upright, under it), and
   shown exactly when it is. Each of Report's places (report.css) has its twin here. */
#btn-chat-field {
  position:absolute; top:18px; right:calc(18px + 52px); z-index:40;
  display:flex; align-items:center; justify-content:center;
  width:44px; min-width:44px; height:44px; min-height:44px; padding:0;
  border:0; border-radius:0; color:#d9c79f; pointer-events:auto;
  /* Report's cut frame, drawn by two layers rather than by clipping the
     button, so the unread count can sit on the corner, outside it. */
  --cut:polygon(6px 0,calc(100% - 6px) 0,100% 6px,100% calc(100% - 6px),calc(100% - 6px) 100%,6px 100%,0 calc(100% - 6px),0 6px);
  background:none; box-shadow:none; overflow:visible; isolation:isolate;
}
#btn-chat-field::after { content:""; position:absolute; inset:0; z-index:-2; clip-path:var(--cut); background:linear-gradient(140deg,#a38c60,#5e5947 50%,#8b7953); }
#btn-chat-field::before { content:""; position:absolute; inset:1px; z-index:-1; clip-path:var(--cut); background:linear-gradient(145deg,#25302c,#111a1a 48%,#0b1213); box-shadow:inset 0 1px #d2c09233,inset 0 -2px #0009; }
#btn-chat-field svg { width:24px; height:24px; pointer-events:none; }
#btn-chat-field:focus-visible { outline:0; }
#btn-chat-field:focus-visible::after { background:#f0d497; }
#btn-chat-field:focus-visible::before { inset:2px; }
/* On the corner, as in town, clear of the speech bubble. */
#btn-chat-field .chat-unread { top:-6px; right:-6px; }
@media (hover:hover) and (pointer:fine) { #btn-chat-field:hover::before { background:linear-gradient(145deg,#344039,#18221f); } }
@media (max-width:760px), (max-height:540px) {
  #btn-chat-field { top:12px; right:calc(12px + 52px); }
}
#viewport:has(#navigation-hud:not(.hidden)) #btn-chat-field { top:190px; }
@media (orientation:landscape) and (max-height:540px) {
  #viewport:has(#navigation-hud:not(.hidden)) #btn-chat-field { top:166px; right:calc(12px + 52px); }
}
@media (orientation:portrait) and (max-width:600px) {
  #viewport:has(#navigation-hud:not(.hidden)) #btn-chat-field { top:calc(12px + 44px + 8px); right:12px; }
}
