/* G8L-211 P1-E chat dock (chat-dock.mjs). Every rule needs [data-dock], which only the script sets, so a page
   without it keeps the in-flow chat window. The window itself stays the shared glass .window; the collapsed
   icon is the shared .glass-pane. Positions follow DESIGN 6.4 through the P1-0 variables. */
#game {
  /* Top edge of the bottom bar; the dock rests on it. */
  --chat-dock-base: calc(var(--bottom-bar-h) + var(--bottom-edge));
}

/* The document remains the page scroller. Only its active panel gets trailing space, so all pages (including
   data-driven services) inherit the actual observed sheet height without a second layout or a scroll trap. */
#game > .panel.active { padding-bottom: var(--chat-dock-height, 0px); }

.chat-dock-toggle[hidden], .chat-dock-dot[hidden] { display: none; }
.chat-dock-minimize { display: none; }

/* Collapsed: a 32px glass disc inside a 44px touch target, 8px above the bottom bar. The disc look is the top bar icons' (top-bar.css). */
.chat-dock-toggle {
  position: fixed;
  z-index: 18;
  left: max(4px, env(safe-area-inset-left));
  bottom: calc(var(--chat-dock-base) + 8px);
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--glass-icon-ink);
  cursor: pointer;
}
.chat-dock-icon {
  display: grid;
  place-items: center;
  margin: 6px;
}
.chat-dock-icon svg { width: 18px; height: 18px; }
/* The collapsed toggle has nothing behind it (r4 lobby-glass): no disc, ring or shadow (top-bar.css keeps its disc for the top bar). The bubble is a solid
 * glass silhouette like the lobby keys (mobile-nav.css): white about 75%, lighter on top (#uiGlassSolidAChat); ::before is the bubble's own shape letting the art tint through. */
.chat-dock-toggle .chat-dock-icon { border: 0; background: none; -webkit-backdrop-filter: none; backdrop-filter: none; box-shadow: none; }
.chat-dock-toggle .chat-dock-icon svg { grid-area: 1 / 1; width: 30px; height: 30px; overflow: visible; fill: url(#uiGlassSolidAChat); stroke: none; filter: drop-shadow(0 0 1px rgb(0 0 0 / 55%)) drop-shadow(0 1px 1px rgb(0 0 0 / 40%)); }
.chat-dock-toggle .chat-dock-icon::before {
  content: '';
  grid-area: 1 / 1;
  width: 30px;
  height: 30px;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M4 5h16v11H9l-5 4z'/%3E%3C/svg%3E") center / 100% 100% no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M4 5h16v11H9l-5 4z'/%3E%3C/svg%3E") center / 100% 100% no-repeat;
  -webkit-backdrop-filter: blur(2px) saturate(190%) brightness(1.2);
  backdrop-filter: blur(2px) saturate(190%) brightness(1.2);
}
.chat-dock-dot {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #e0312f;
  box-shadow: 0 0 0 2px #fff;
}

/* Open: the chat window leaves the page flow. */
#game > .social-window[data-dock='closed'] { display: none !important; }
#game > .social-window[data-dock='open'] {
  position: fixed;
  z-index: 18;
  left: 0;
  right: 0;
  bottom: var(--chat-dock-base);
  display: flex;
  flex-direction: column;
  max-height: min(60dvh, calc(100dvh - var(--chat-dock-base) - var(--chat-dock-top, 0px)));
  border-radius: 12px 12px 0 0;
}
/* While typing on a phone the bottom bar is hidden (mobile-nav.css), so the sheet drops to the Home bar or
   sits on the keyboard, whichever is higher. */
body.chat-typing #game > .social-window[data-dock='open'] {
  bottom: max(var(--chat-dock-kb, 0px), env(safe-area-inset-bottom));
  max-height: min(60dvh, calc(var(--chat-dock-view-height, 100dvh) - var(--chat-dock-top, 0px) - max(0px, env(safe-area-inset-bottom) - var(--chat-dock-kb, 0px))));
}
#game > .social-window[data-dock='open'] .chat-feed { flex: 1 1 138px; height: auto; min-height: 0; }
#game > .social-window[data-dock='open'] > .titlebar { flex: 0 0 auto; }
#game > .social-window[data-dock='open'] > :not(.titlebar, .chat-feed) { flex: 0 0 auto; }
#game > .social-window[data-dock] > .titlebar { min-height: 44px; }
#game > .social-window[data-dock] .chat-dock-minimize {
  display: grid;
  place-items: center;
  align-self: stretch;
  min-width: 44px;
  min-height: 44px;
  margin: 0 0 0 7px;
  padding: 0 8px;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

/* r3e §9: use only the shared glass fill; no separate frosting recipe. The pale fill keeps chat readable
   over the lobby film. Legacy window chrome is excluded by ro-ui-primitive in mountChatDock. */
#game > .social-window[data-dock] {
  --glass-pane-fill: rgb(255 255 255 / 92%);
  color: #1c2a3a;
  font-family: var(--glass-font);
}
#game > .social-window[data-dock] > .titlebar {
  background: transparent;
  color: #1c2a3a;
  text-shadow: none;
  border-bottom: 1px solid rgb(28 42 58 / 12%);
}
#game > .social-window[data-dock] .chat-dock-minimize {
  align-self: center;
  border-radius: 50%;
  padding: 0;
  background: var(--glass-pane-fill);
  font-size: 22px;
}
#game > .social-window[data-dock] .chat-channels {
  gap: 5px;
  padding: 5px 6px;
  background: transparent;
  border: 0;
}
#game > .social-window[data-dock] .chat-channels button {
  border: 1px solid rgb(28 42 58 / 15%);
  border-radius: 18px;
  background: rgb(255 255 255 / 65%);
  color: #1c2a3a;
}
#game > .social-window[data-dock] :is(.chat-channels button.active, #chatSend) {
  background: #1f548f !important;
  color: #fff !important;
  text-shadow: none;
}
#game > .social-window[data-dock] :is(.chat-toolbar, .chat-compose, .chat-recipient, .chat-status) {
  background: transparent;
  color: #1c2a3a;
}
#game > .social-window[data-dock] .chat-feed {
  margin: 4px 6px;
  border: 1px solid rgb(28 42 58 / 15%);
  border-radius: 8px;
  background: rgb(255 255 255 / 40%);
}
#game > .social-window[data-dock] :is(.chat-line time, .chat-empty) { color: #42536a; }
/* The full-width colon after a name is body text: it hangs on the message span so it always has the message's own
   colour (one source; the old grey #778089 was 3.7:1). Voice lines have no text body and keep the name colour. */
#game > .social-window[data-dock] .chat-line b:not(:empty)::after { content: none; }
#game > .social-window[data-dock] .chat-line b:not(:empty) + span::before { content: '：'; font-weight: normal; }
#game > .social-window[data-dock] .chat-line.voice b:not(:empty)::after { content: '：'; color: inherit; font-weight: normal; }
#game > .social-window[data-dock] .chat-line.voice b:not(:empty) + span::before { content: none; }
#game > .social-window[data-dock] .chat-line.system :is(b, span) { color: #79500f; }
#game > .social-window[data-dock] .chat-line.ally .chat-channel-badge { background: #286439; }
#game > .social-window[data-dock] #chatInput { color: #1c2a3a; background: rgb(255 255 255 / 65%); }
#game > .social-window[data-dock] #chatInput::placeholder { color: #42536a; opacity: 1; }

/* On short layout viewports, remove vertical chrome spacing rather than hide controls or scroll the
   whole dock. Fixed rows keep their content/touch sizes; only the message feed gives up its height. */
@media (max-height: 400px) {
  #game > .social-window[data-dock='open'] > :is(.titlebar, .chat-channels, .chat-toolbar, .chat-compose, .chat-status) { padding-block: 0; }
  #game > .social-window[data-dock='open'] .chat-feed { margin-block: 0; padding-block: 0; }
}

@media (min-width: 721px) {
  #game { --chat-dock-base: calc(var(--bottom-bar-h) + 8px); }
  .chat-dock-toggle { left: 16px; bottom: var(--chat-dock-base); }
  #game > .social-window[data-dock='open'] {
    left: 16px;
    right: auto;
    width: min(440px, calc(100vw - 32px));
    border-radius: 12px;
  }
}
