/* The chat box (chat-box.js; chat-plan.js decides what it holds). Everything here is under .chat or .chat-set, so it
   collides with nothing in the other sheets. The classic chat box look, made with plain fills and lines: a pale box
   with dark ink, or the game showing through with light ink. Transparent is a plain see-through fill, never a blur.
   A state is always a word as well as a color: a tab says On, Filtered or Off under its name. */

.chat {
  position: absolute; z-index: 1; display: flex; flex-direction: column; justify-content: flex-end; pointer-events: none;
  --chat-fill: #d1c1a0; --chat-edge: #3d3324; --chat-line: #8f7f5f; --chat-tab: #3a3226; --chat-tab-text: #f1e7c9;
  font-size: calc(var(--chat-text, 14px) * var(--ts, 1)); line-height: 1.3; color: var(--chat-game, #000);
  -webkit-user-select: none; user-select: none;
}
.chat-probe { position: fixed; left: 0; top: 0; width: 0; height: 0; visibility: hidden; pointer-events: none; padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l); }

/* ---------------- the pane ---------------- */
.chat-pane { position: relative; flex: 1 1 auto; min-height: 0; display: flex; pointer-events: auto; background: var(--chat-fill); border: 2px solid var(--chat-edge); border-bottom: 0; box-shadow: inset 0 0 0 1px var(--chat-line); }
.chat-pane[hidden] { display: none; }
.chat-lines { flex: 1 1 auto; min-width: 0; overflow-x: hidden; overflow-y: auto; padding: 4px 8px; touch-action: pan-y; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: #6b5d47 transparent; cursor: default; }
.chat-lines:focus-visible { outline: 2px solid #f0c27a; outline-offset: -2px; }
.chat-line { margin: 0; padding: 0 0 1px; overflow-wrap: anywhere; font-weight: 500; color: var(--chat-game); }
.chat-line[data-cat="combat"] { color: var(--chat-combat); }
.chat-line[data-cat="loot"] { color: var(--chat-loot); }
.chat-line[data-cat="skills"] { color: var(--chat-skills); }
.chat-line[data-cat="story"] { color: var(--chat-story); }
.chat-line[data-cat="system"] { color: var(--chat-system); }
.chat-line .chat-who, .chat-line .chat-tag { font-weight: 700; }
.chat-line .chat-time { font-variant-numeric: tabular-nums; }
.chat-line.chat-empty { font-style: italic; opacity: 0.85; }
.chat-latest { position: absolute; right: 12px; bottom: 4px; min-height: 28px; padding: 2px 10px; border: 1px solid #f0c27a; border-radius: 3px; background: #2a251d; color: #f1e7c9; font-size: 12px; font-weight: 700; cursor: pointer; }
.chat-latest[hidden] { display: none; }

/* ---------------- the tabs ---------------- */
.chat-tabs { flex: none; display: flex; gap: 2px; padding: 2px; pointer-events: auto; background: #241f17; border: 2px solid var(--chat-edge); }
.chat-tab, .chat-cog { min-width: 0; min-height: 26px; padding: 1px 2px; border: 1px solid #6b5d47; border-radius: 2px; background: var(--chat-tab); color: var(--chat-tab-text); cursor: pointer; }
.chat-tab { flex: 1 1 0; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; overflow: hidden; }
.chat-tab b { font-size: 12px; font-weight: 700; white-space: nowrap; }
.chat-tab small { font-size: 10px; font-weight: 700; white-space: nowrap; min-height: 11px; }
.chat-tab[data-state="on"] small { color: #7be07b; }
.chat-tab[data-state="filtered"] small { color: #f2d54a; }
.chat-tab[data-state="off"] small { color: #ff8f80; text-decoration: line-through; }
.chat-tab.on { background: #5a4c35; border-color: #f0c27a; box-shadow: inset 0 -3px 0 #f0c27a; }
.chat-cog { flex: none; width: 30px; display: grid; place-items: center; }
/* Made narrow to stand beside the health globe (chat-plan.js placeBox): the tabs' words still fit. */
.chat.narrow .chat-tabs { gap: 1px; padding: 2px 1px; }
.chat.narrow .chat-tab { padding: 1px 0; }
.chat.narrow .chat-tab b { font-size: 11px; letter-spacing: -0.01em; }
.chat.narrow .chat-tab small { font-size: 9px; }
.chat.narrow .chat-cog { width: 24px; }
.chat-cog svg, .chat-open svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.chat-tab:focus-visible, .chat-cog:focus-visible, .chat-latest:focus-visible, .chat-open:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }
/* Touch: every tab is at least 44px each way. Where the row is too narrow for that it scrolls sideways; it never shrinks a tab. */
@media (pointer: coarse) { .chat-tab, .chat-cog { min-height: 44px; } .chat-tab { flex: 1 0 auto; min-width: 44px; padding: 1px 6px; } .chat-cog { flex: 0 0 44px; width: 44px; } .chat-latest { min-height: 44px; }
  .chat-tabs { overflow-x: auto; overflow-y: hidden; touch-action: pan-x; overscroll-behavior: contain; scrollbar-width: none; } }

/* ---------------- transparent: the game shows through a plain, lightly darkened fill ---------------- */
.chat[data-mode="transparent"] .chat-pane { background: rgba(8, 7, 5, 0.34); border-color: transparent; box-shadow: none; }
.chat[data-mode="transparent"] .chat-tabs { background: rgba(8, 7, 5, 0.5); border-color: transparent; }
.chat[data-mode="transparent"] .chat-tab, .chat[data-mode="transparent"] .chat-cog { background: rgba(40, 34, 26, 0.72); }
.chat[data-mode="transparent"] .chat-tab.on { background: rgba(90, 76, 53, 0.9); }
.chat.shadow .chat-line { text-shadow: 1px 1px 0 #000, 0 0 2px #000; }
/* (on a phone, click through is for the passing lines only, which never take a touch: the open box must still scroll by finger) */
.chat.through:not(.compact) .chat-pane { pointer-events: none; }
.chat.through .chat-latest { pointer-events: auto; }
.chat.fade .chat-lines, .chat.fade .chat-tabs { transition: opacity 0.6s linear; }
.chat.fade.idle .chat-lines { opacity: 0; }
.chat.fade.idle .chat-pane { background: transparent; }
.chat.fade.idle .chat-tabs { opacity: 0.55; }
@media (prefers-reduced-motion: reduce) { .chat.fade .chat-lines, .chat.fade .chat-tabs { transition: none; } }

/* ---------------- high contrast (the game's own setting): bright ink on black, and every line names its category ---------------- */
.chat.contrast { --chat-fill: #000; --chat-edge: #fff; --chat-line: #000; --chat-tab: #000; --chat-tab-text: #fff; }
.chat.contrast[data-mode="transparent"] .chat-pane { background: rgba(0, 0, 0, 0.82); }
.chat.contrast .chat-line { font-weight: 700; }
.chat.contrast .chat-tab, .chat.contrast .chat-cog { border-color: #fff; }
.chat.contrast .chat-tab.on { background: #000; border-color: #ff0; box-shadow: inset 0 -4px 0 #ff0; }

/* ---------------- story lines split off: over the box for a while ---------------- */
.chat-split { flex: none; padding: 0 8px 3px; pointer-events: none; }
.chat-split:empty { display: none; }
.chat-split .chat-line { color: #7df9ff; font-weight: 700; text-shadow: 1px 1px 0 #000, 0 0 2px #000; }
.chat.contrast .chat-split .chat-line { color: #9cff9c; }
/* An important line while the pane is put away: a plain dark plate, its category in words, in the pane's place. */
.chat-split .chat-line.chat-pass { width: fit-content; max-width: 100%; margin-top: 2px; padding: 3px 8px; border: 1px solid #f0c27a; background: #1a1712; color: #fff; text-shadow: none; }
.chat.contrast .chat-split .chat-line.chat-pass { border-color: #ff0; background: #000; color: #fff; }

/* ---------------- the phone form: a few passing lines and one button; the button opens the whole box ---------------- */
.chat-open { display: none; }
.chat.compact { flex-direction: row; align-items: flex-start; justify-content: flex-start; gap: 6px; }
.chat.compact .chat-open { order: -1; flex: none; position: relative; display: grid; place-items: center; width: 44px; height: 44px; pointer-events: auto; border: 1px solid #6b5d47; border-radius: 6px; background: rgba(30, 26, 18, 0.72); color: #f1e7c9; }
.chat.compact .chat-open[hidden] { display: none; }
.chat-count { position: absolute; right: -4px; top: -4px; min-width: 18px; padding: 0 4px; border-radius: 9px; background: #f0c27a; color: #1a140c; font-size: 11px; font-weight: 800; line-height: 18px; text-align: center; }
.chat-count:empty { display: none; }
.chat.compact:not(.open) .chat-tabs, .chat.compact:not(.open) .chat-split, .chat.compact:not(.open) .chat-latest { display: none; }
.chat.compact:not(.open) .chat-pane { flex: 1 1 auto; align-self: stretch; pointer-events: none; background: none; border: 0; box-shadow: none; }
.chat.compact:not(.open) .chat-lines { overflow: hidden; padding: 0; display: flex; flex-direction: column; justify-content: flex-start; }
.chat.compact:not(.open) .chat-line { width: fit-content; max-width: 100%; padding: 1px 6px; background: rgba(8, 7, 5, 0.5); text-shadow: 1px 1px 0 #000; }
.chat.compact:not(.open) .chat-line.chat-old, .chat.compact:not(.open) .chat-empty { display: none; }
.chat.compact:not(.open).idle .chat-lines { visibility: hidden; }
.chat.compact:not(.open)[data-mode="opaque"] .chat-line { background: var(--chat-fill); text-shadow: none; }
.chat.compact.open { flex-direction: column; align-items: stretch; justify-content: flex-end; }
.chat.compact.open .chat-open { order: 3; align-self: flex-start; margin-top: 4px; }

/* ---------------- the settings sheet ---------------- */
.chat-set h2 { margin: 0 0 4px; }
.chat-set h3 { margin: 14px 0 6px; font-size: calc(15px * var(--ts, 1)); color: var(--text); }
.chat-opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 17rem), 1fr)); gap: 6px; }
.chat-opt { width: 100%; min-height: 48px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 6px 10px; text-align: left; cursor: pointer; }
.chat-opt span b { display: block; }
.chat-opt small { display: block; color: var(--muted); font-size: calc(12px * var(--ts, 1)); line-height: 1.3; }
.chat-opt-state { min-width: 84px; padding: 4px 8px; border: 1px solid var(--line); text-align: center; color: var(--accent); }
.chat-opt[aria-disabled="true"] { opacity: 0.6; }
.chat-opt[aria-disabled="true"] .chat-opt-state { color: var(--muted); }
.chat-opt:focus-visible { outline: 2px solid #f0c27a; outline-offset: 2px; }
.chat-sample { width: fit-content; margin-top: 3px; padding: 1px 6px; font-weight: 600; }
.chat-sample[data-mode="opaque"] { background: #d1c1a0; }
.chat-sample[data-mode="transparent"] { background: #26221c; }
.chat-set .chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* The line under the health bars is in the box now. It stays on the page as the one polite status line a screen reader
   hears, and as what the menu shows over itself, so it is put out of sight and not removed. Only while the box is alive
   (chat-box.js sets body.chat-live): if the box could not be made, or failed, the line shows where it always did. */
body.chat-live #hudStack #toast { position: fixed !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }

/* Touch (chat-plan.js touchHome): closed, the button stands in the first row of the top left (a fixed place of its
   own, apart from the lines) and the passing lines stand over their seat (#chatSeat, an empty element that is the
   last thing of the top left's flow), each message wrapped whole and none of them taking a press; the open box is
   docked to the top left corner over them, and its button reads Close. With the top left put away, or the unlocked
   skill bar's panel in its place on a short screen, the closed box is not drawn. */
#hudStack > .chat-seat { width: 100%; pointer-events: none; }
.chat.compact.unseated:not(.open), body.hud-arranging .chat.compact:not(.open) { visibility: hidden; }
.chat.compact.apart:not(.open) .chat-open { position: fixed; }
.chat.compact.apart:not(.open) .chat-line { white-space: normal; overflow-wrap: anywhere; }
.chat.compact.open { z-index: 9; }
.chat.compact.open .chat-open { width: auto; min-width: 44px; padding: 0 12px; display: inline-flex; align-items: center; gap: 8px; font: inherit; font-weight: 700; }
.chat.compact .chat-open svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
/* A log with nothing in it yet (chat-box.js sets .empty) draws no pane at all, in either look and on every device: no
   backing, and no line that says there is nothing. The tabs stay (with a mouse), and the button (on touch). A tab
   that is empty while the log is not still says so. */
.chat.empty:not(.open) .chat-pane { visibility: hidden; }
