/* Session chat, faction picker and the horizontal match-tools disclosure. */
.gm__corner.gm__corner--tools {
  --team-control-h: max(.56rem, 24px);
  --team-control-gap: max(.035rem, 2px);
  --emote-control-w: max(1.51rem, 72px);
  flex-wrap: nowrap;
  width: auto;
  gap: var(--team-control-gap);
}
.team-chat, .gm__tools { position: relative; flex: 0 0 auto; }
/* Gray plate y=6..45: include the upper edge, leaving the face and lower shadow outside the adjacent controls. */
.gm__corner.gm__corner--tools.has-emote-sprite,
.gm__corner--tools > .has-emote-sprite {
  --team-control-h: calc(var(--emote-control-w) * 39 / 151);
  --team-control-lift: calc(var(--emote-control-w) * 10 / 151);
}
.gm__corner--tools > .team-chat,
.gm__corner--tools > .gm__metrics,
.gm__corner--tools > .gm__tools { margin-bottom: var(--team-control-lift, 0px); }
.team-chat__toggle,
.gm__corner .gm__tools-toggle {
  box-sizing: border-box;
  height: var(--team-control-h, max(.55rem, 26px));
  padding: 0;
  background: transparent;
  border: 1px solid var(--line-2);
  color: var(--text-md);
  transition: color var(--t-fast), border-color var(--t-fast), background-color var(--t-fast);
}
.team-chat__toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: max(.07rem, 5px);
  width: max(.98rem, 64px);
  padding: 0 max(.09rem, 6px);
  font-size: max(.16rem, 12px);
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}
.team-chat__toggle .icon {
  display: block;
  flex: 0 0 auto;
  width: max(.28rem, 20px);
  height: max(.28rem, 20px);
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linejoin: round;
}
.team-chat__icon circle { fill: currentColor; stroke: none; }
.team-chat__label { display: block; line-height: 1; }
.team-chat__toggle:focus-visible { outline: none; box-shadow: none; }
/* Match chat stays beside the tools disclosure; the narrower button moves the menu with the flex row. */
.gm__corner--tools > .team-chat .team-chat__toggle { width: var(--team-control-h); padding: 0; gap: 0; }
.gm__corner--tools > .team-chat .team-chat__label { display: none; }
.gm__corner--tools > .team-chat .team-chat__icon {
  width: calc(var(--team-control-h) * .78);
  height: calc(var(--team-control-h) * .78);
}
.sp-coarse .gm__corner--tools .gm__tools .gm__gear::before { width: 100%; }
.team-chat__toggle:hover,
.team-chat__toggle:focus-visible,
.team-chat.is-open .team-chat__toggle,
.gm__corner .gm__tools-toggle:hover,
.gm__corner .gm__tools-toggle:focus-visible,
.gm__tools.is-open .gm__tools-toggle {
  color: var(--mint-400);
  border-color: var(--mint-500);
  background: transparent;
}

.team-chat__panel {
  position: absolute;
  left: calc(-1 * var(--emote-control-w, 0px) - var(--team-control-gap, 0px));
  bottom: calc(100% + max(.1rem, 7px));
  z-index: 16;
  display: flex;
  flex-direction: column;
  width: min(max(4.8rem, 330px), calc(100vw - max(.48rem, 30px)));
  max-height: calc(100dvh - max(1.35rem, 88px));
  padding: max(.14rem, 10px);
  overflow: visible;
  background: rgba(3, 12, 8, .98);
  box-shadow: 0 7px 28px #0009;
  color: var(--text-hi);
  font-size: max(.16rem, 13px);
  line-height: 1.45;
}
.team-chat__panel.is-feed-only {
  padding: max(.1rem, 7px) max(.13rem, 9px);
  background: linear-gradient(90deg, rgba(3, 12, 8, .42), rgba(3, 12, 8, .12) 76%, transparent);
  box-shadow: none;
  text-shadow: 0 1px 3px #000, 0 0 5px #0009;
  pointer-events: none;
}
.team-chat__feed {
  display: flex;
  flex: 0 1 auto;
  flex-direction: column;
  gap: max(.075rem, 5px);
  max-height: 50dvh;
  min-height: 0;
  /* Leave room for rotated system markers and their glow inside the scroll clip. */
  padding: max(.05rem, 3px) max(.07rem, 5px);
  overflow: auto;
  overflow-wrap: anywhere;
  scrollbar-width: thin;
  scrollbar-color: var(--mint-800) transparent;
}
.team-chat__message { display: flex; align-items: baseline; gap: max(.11rem, 7px); min-width: 0; }
.team-chat__author { display: inline-flex; flex: 0 1 auto; align-items: baseline; gap: max(.045rem, 3px); max-width: 46%; min-width: 0; }
.team-chat__name { overflow: hidden; color: var(--mint-400); font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.team-chat__message.is-self .team-chat__name { color: var(--text-md); }
.team-chat__faction {
  flex: 0 0 auto;
  color: var(--faction-color);
  font-size: .9em;
  font-weight: 800;
  text-shadow: 0 0 8px var(--faction-color);
  text-shadow: 0 0 8px color-mix(in srgb, var(--faction-color) 34%, transparent);
}
.team-chat__text { min-width: 0; white-space: pre-wrap; }
.team-chat__message.is-system {
  align-items: center;
  gap: max(.08rem, 5px);
  color: var(--faction-color);
  color: color-mix(in srgb, var(--faction-color) 76%, white);
  font-size: .94em;
}
.team-chat__system-dot {
  flex: 0 0 auto;
  width: max(.07rem, 5px);
  height: max(.07rem, 5px);
  background: var(--faction-color);
  box-shadow: 0 0 7px var(--faction-color);
  transform: rotate(45deg);
}
.team-chat__message.is-restart { color: var(--mint-500); font-weight: 600; }

.team-chat__form { position: relative; flex: 0 0 auto; margin-top: max(.14rem, 9px); }
.team-chat__compose { display: flex; align-items: stretch; gap: max(.07rem, 5px); }
.team-chat__input {
  flex: 1 1 0;
  min-width: 0;
  width: 0;
  height: max(.42rem, 36px);
  padding: 0 max(.11rem, 8px);
  background: rgba(2, 8, 5, .88);
  border: 0;
  outline: 0;
  box-shadow: none;
  color: var(--text-hi);
  font: inherit;
  font-size: max(.16rem, 13px);
}
.team-chat__input:focus,
.team-chat__input:focus-visible { border: 0; outline: 0; box-shadow: none; }
.team-chat__input::placeholder { color: var(--text-lo); }
.team-chat__picker-wrap { position: relative; display: flex; flex: 0 0 auto; }
.team-chat__picker-toggle {
  display: grid;
  place-items: center;
  width: max(.42rem, 36px);
  padding: 0;
  background: rgba(3, 12, 8, .92);
  border: 1px solid var(--line-2);
  color: var(--text-md);
}
.team-chat__picker-toggle:hover,
.team-chat__picker-toggle:focus-visible,
.team-chat__picker-toggle.is-open { border-color: var(--mint-500); color: var(--mint-400); }
.team-chat__picker-toggle svg { width: max(.22rem, 18px); height: max(.22rem, 18px); fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; }
.team-chat__picker {
  position: absolute;
  right: 0;
  bottom: calc(100% + max(.08rem, 6px));
  z-index: 2;
  width: min(max(3.45rem, 270px), calc(100vw - max(.72rem, 46px)));
  padding: max(.12rem, 8px);
  background: rgba(3, 12, 8, .99);
  border: 1px solid var(--mint-900, #225844);
  box-shadow: 0 6px 22px #000b;
}
.team-chat__picker-head { display: flex; align-items: baseline; justify-content: space-between; gap: .12rem; margin-bottom: max(.1rem, 7px); }
.team-chat__picker-head strong { color: var(--text-hi); font-size: max(.15rem, 12px); }
.team-chat__picker-head span { color: var(--text-dim); font-size: max(.11rem, 10px); }
.team-chat__factions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: max(.06rem, 4px); }
.team-chat__faction-option {
  display: flex;
  align-items: center;
  gap: max(.07rem, 5px);
  min-width: 0;
  min-height: max(.34rem, 29px);
  padding: 0 max(.09rem, 6px);
  overflow: hidden;
  background: rgba(255, 255, 255, .025);
  border: 1px solid var(--line);
  color: var(--text-md);
  font: inherit;
  font-size: max(.14rem, 11px);
  text-align: left;
  white-space: nowrap;
}
.team-chat__faction-option:hover:not(:disabled),
.team-chat__faction-option:focus-visible,
.team-chat__faction-option.is-selected {
  border-color: var(--faction-color);
  color: var(--faction-color);
  background: rgba(255, 255, 255, .06);
  background: color-mix(in srgb, var(--faction-color) 10%, transparent);
}
.team-chat__faction-option:disabled { opacity: .72; cursor: default; }
.team-chat__faction-swatch { width: max(.08rem, 6px); height: max(.08rem, 6px); flex: 0 0 auto; background: var(--faction-color); box-shadow: 0 0 6px var(--faction-color); transform: rotate(45deg); }
.team-chat__send {
  flex: 0 0 auto;
  min-width: max(.58rem, 48px);
  padding: 0 max(.12rem, 9px);
  background: var(--mint-700);
  border: 0;
  color: var(--text-hi);
  font: inherit;
  font-weight: 700;
}
.team-chat__send:hover:not(:disabled) { background: var(--mint-500); color: #071910; }
.team-chat__send:disabled { background: #20332a; color: var(--text-dim); cursor: default; }
.team-chat__meta { display: flex; justify-content: space-between; gap: 8px; min-height: 1.35em; margin-top: max(.055rem, 4px); color: var(--text-lo); font-size: max(.11rem, 10px); }
.team-chat__note { min-width: 0; }
.team-chat__count { flex: 0 0 auto; margin-left: auto; font-variant-numeric: tabular-nums; }
.team-chat__count.is-long { color: var(--red-400, #ff8d8d); }

.gm__corner .gm__tools-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: max(.2rem, 18px);
  line-height: 1;
}
.gm__corner .gm__tools-toggle.gm__gear .icon {
  display: block;
  flex: 0 0 auto;
  width: max(.13rem, 11px);
  height: max(.13rem, 11px);
  margin: 0;
  transform-origin: center;
  transition: transform var(--t-fast);
}
.gm__tools.is-open .gm__tools-toggle .icon { transform: rotate(180deg); }
.gm__tools { display: flex; align-items: center; }
.gm__tools-reveal {
  flex: none; width: 0; visibility: hidden;
  /* Clip the moving right edge, preserving the emote sprite's ten-pixel shadow below a 39px plate. */
  clip-path: inset(-6px 0 calc(var(--team-control-h) * -.3) -6px);
  transition: width var(--t-med) var(--ease-out), visibility 0s var(--t-med);
}
.gm__tools.is-open .gm__tools-reveal {
  width: calc(var(--tools-menu-width, 0px) + var(--team-control-gap, 2px));
  visibility: visible; transition-delay: 0s;
}
.gm__tools-menu {
  position: relative; z-index: 17;
  display: flex; flex-direction: row; align-items: center;
  width: max-content; gap: var(--team-control-gap, max(.07rem, 4px));
  padding: 0; background: transparent; box-shadow: none;
}
.gm__tools-menu .gm__gear {
  box-sizing: border-box;
  width: var(--team-control-h, max(.55rem, 26px));
  height: var(--team-control-h, max(.55rem, 26px));
  background: transparent;
  border: 1px solid var(--line-2);
}
.gm__tools-menu .gm__gear:hover,
.gm__tools-menu .gm__gear:focus-visible { border-color: var(--mint-500); background: transparent; }

/* Waiting-room entry point: above the fixed action bar and clear of its controls. */
.room-chat {
  --team-control-h: max(.55rem, 30px);
  position: absolute;
  left: max(.22rem, 14px);
  bottom: calc(1.5rem + max(.16rem, 10px));
  z-index: 14;
}
.room-chat .team-chat__panel { left: 0; }
.room-chat .team-chat__toggle { background: rgba(3, 12, 8, .58); }
.phase-chat {
  --team-control-h: max(.44rem, 30px);
  position: absolute;
  left: max(.22rem, 14px);
  bottom: max(.18rem, 12px);
  z-index: 14;
}
.phase-chat .team-chat__panel { left: 0; }
.phase-chat--brief { bottom: max(.2rem, 14px); }
.brief__foot { flex-wrap: wrap; gap: max(.2rem, 12px); padding-left: max(1.45rem, 112px); }
.brief__left { overflow-y: auto; overscroll-behavior: contain; }
.brief__left > * { flex-shrink: 0; }
.brief-restart { white-space: nowrap; }
.restart-transition { position: fixed; inset: 0; z-index: 10000; background: #000; pointer-events: auto; animation: restart-cover .18s ease-out both; }
.restart-transition.is-revealing { animation: restart-reveal .18s ease-in both; }
@keyframes restart-cover { from { opacity: 0; } to { opacity: 1; } }
@keyframes restart-reveal { from { opacity: 1; } to { opacity: 0; } }
.draft .phase-chat--draft { position: relative; left: auto; bottom: auto; align-self: flex-start; }
.draft .draft-order { min-width: 0; }
.draft .draft-order > :not(.draft-order__scroll) { flex-shrink: 0; }
.draft-order__scroll {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: .1rem;
  min-width: 0;
  min-height: 0;
  padding: .04rem .04rem .08rem;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--mint-800) transparent;
}
.draft-order__scroll > * { flex-shrink: 0; }
.seat__who .team-chat__faction {
  flex: 0 0 auto;
  color: var(--faction-color);
  font-size: max(.13rem, 11px);
  font-weight: 800;
  white-space: nowrap;
}

@media (pointer: coarse) {
  .gm__corner.gm__corner--tools {
    --team-control-h: max(.56rem, 26px);
    --emote-control-w: max(1.51rem, 96px);
  }
  .gm__corner .gm__tools-toggle { width: max(.2rem, 20px); }
  .room-chat { --team-control-h: max(.55rem, 36px); }
}
@media (max-width: 767px), (pointer: coarse) {
  .team-chat__panel {
    width: min(390px, calc(100vw - max(.42rem, 26px)));
    max-height: calc(100dvh - max(.95rem, 64px));
  }
  .team-chat__feed { max-height: calc(100dvh - max(1.75rem, 118px)); }
  .team-chat__picker { width: min(330px, calc(100vw - max(.62rem, 40px))); }
  .room-chat { left: max(.16rem, 10px); bottom: calc(1.5rem + max(.1rem, 7px)); }
}
@media (prefers-reduced-motion: reduce) {
  .gm__tools-reveal { transition: none; }
  .gm__tools-toggle .icon { transition: none; }
  .restart-transition { animation-duration: .001s; }
}

/* The footer reserves its actual height, including wrapped copyright and touch-sized tools. */
.title-screen { justify-content: flex-start; }
.title-main {
  flex: 1 1 0; min-height: 0; width: 100%; margin-top: 0; flex-direction: column-reverse;
  padding: max(.5rem, 24px) .44rem max(.12rem, 8px);
  overflow-y: auto; overflow-x: hidden;
}
/* Preserve the visual order. The reverse flow shows the login first when a short window needs scrolling. */
.title-main > * { flex-shrink: 0; }
.title-main > .emblem { order: 4; }
.title-main > .title-en { order: 3; }
.title-main > .title-cn { order: 2; }
.title-main > .title-tag { order: 1; }
.title-main > .title-login { order: 0; }
.title-main > :first-child { margin-top: auto; }
.title-main > :last-child { margin-bottom: auto; }
.title-conn { flex-wrap: wrap; gap: max(.1rem, 8px); }
.title-conn__status { display: inline-flex; align-items: center; justify-content: center; gap: max(.1rem, 6px); white-space: nowrap; }
.title-guide { white-space: nowrap; }
.title-foot {
  position: relative; left: auto; right: auto; bottom: auto; flex: 0 0 auto; align-self: stretch;
  margin: 0 .44rem .3rem; display: grid; grid-template-columns: minmax(0, 1fr) max-content;
  gap: max(.12rem, 9px) max(.18rem, 12px);
}
.title-foot__left, .title-foot__right { display: contents; }
.title-foot__actions { display: flex; flex-wrap: wrap; gap: max(.1rem, 8px); }
.title-foot__actions { grid-column: 1; grid-row: 1; align-self: end; }
.title-foot__copyright { grid-column: 1; grid-row: 2; min-width: 0; overflow-wrap: anywhere; }
.title-foot__right > .micro { grid-column: 2; grid-row: 2; align-self: end; text-align: right; }
.title-dev { grid-column: 1 / -1; }
.title-tools { grid-column: 2; grid-row: 1; justify-self: end; display: flex; flex-wrap: nowrap; align-items: center; justify-content: flex-end; gap: max(.1rem, 8px); }
.title-tools .title-settings,
.title-tools .title-fs { flex: 0 0 auto; width: max(.4rem, 36px); height: max(.4rem, 36px); margin-left: 0; }
.title-tools .fsbtn { display: flex; align-items: center; justify-content: center; padding: 0; line-height: 1; }
.title-tools .fsbtn .icon { display: block; flex: 0 0 auto; margin: 0; }
.title-tools .title-stats {
  flex: 0 0 auto;
  height: max(.4rem, 36px);
  min-width: max(.72rem, 60px);
  padding: 0 max(.07rem, 5px);
  gap: max(.05rem, 4px);
  font-size: max(calc(.14 * var(--t)), 12px);
  line-height: 1;
  white-space: nowrap;
}
.title-tools .title-stats .btn__icon { width: max(.2rem, 16px); height: max(.2rem, 16px); }
.sp-coarse .title-tools .title-stats { height: max(.4rem, var(--tap-min)); }
.sp-coarse .title-settings,
.sp-coarse .title-fs {
  flex: 0 0 auto;
  width: max(.4rem, var(--tap-min));
  height: max(.4rem, var(--tap-min));
}
.sp-coarse .title-guide { min-height: var(--tap-min); }
@media (max-height: 360px) {
  .title-main { margin-top: 0; }
  .title-screen .emblem { margin-bottom: .12rem; }
  .title-screen .emblem__svg { width: .75rem; height: .8rem; }
  .title-screen .emblem__bracket { height: .9rem; }
  .title-login { margin-top: .2rem; gap: .1rem; padding-top: .16rem; padding-bottom: .1rem; }
}
/* Keep the language control above the scrollable content on short windows. */
@media (max-height: 460px) {
  .title-main { margin-top: max(.9rem, 40px); padding-block: max(.05rem, 2px); }
  .title-corner .micro { display: none; }
}

/* Explicit label boxes keep the voice selector centered instead of relying on native button baselines. */
.set-voice button { display: flex; align-items: center; justify-content: center; padding: 0 .1rem; line-height: 1; }
.set-voice__label { display: block; line-height: 1; }
.set-voice [data-voice-lang="jp"] .set-voice__label { transform: translateX(-.1em); }

/* Give the new stats/settings controls room without crossing the centered screen heading. */
@media (max-width: 767px) {
  .lobby-screen .topbar,
  .room-screen .topbar {
    height: auto;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas: 'heading heading' 'left right';
    gap: max(.12rem, 6px) max(.2rem, 10px);
    padding-top: max(.15rem, 8px);
    padding-bottom: max(.15rem, 8px);
  }
  .lobby-screen .topbar__center,
  .room-screen .topbar__center { grid-area: heading; min-width: 0; }
  .lobby-screen .topbar__left,
  .room-screen .topbar__left { grid-area: left; flex-wrap: wrap; gap: max(.12rem, 6px); }
  .lobby-screen .topbar__right,
  .room-screen .topbar__right { grid-area: right; flex-wrap: wrap; justify-content: flex-end; max-width: 100%; gap: max(.12rem, 6px); }
  /* Both menu groups start on the same row if large text or optional controls require wrapping. */
  .lobby-screen .topbar__left,
  .lobby-screen .topbar__right { align-self: start; row-gap: max(.16rem, 12px); }
  .lobby-screen .topbar :is(.stats-entry, .settings-btn, .guide-btn, .lobby-loadout),
  .room-screen .topbar :is(.stats-entry, .settings-btn, .guide-btn) {
    min-width: 44px;
    min-height: 32px;
    font-size: max(calc(.14 * var(--t)), 12px);
    white-space: nowrap;
  }
}

.gm__tools-menu .gm__gear.control-frame { padding: 0; border: 0; background: transparent; --control-bg: transparent; }

/* The emote's gray body is y=6..45 of its 151×55 sprite. Combat tools follow this plate;
   room/phase chat keeps its text button. One SVG contains both plate and glyph, including at the smallest root. */
.gm__corner.gm__corner--tools .combat-control {
  position: relative; display: block; flex: none; width: var(--team-control-h); height: var(--team-control-h);
  min-width: 0; min-height: 0; padding: 0; border: 0; border-radius: calc(var(--team-control-h) * .0875);
  background: transparent; color: #f2f2f2; line-height: 1;
  /* Match the baked-in sprite shadow's offset, blur and gray tint at the same body height. */
  box-shadow: 0 calc(var(--team-control-h) * 5.5 / 39) calc(var(--team-control-h) * 3.5 / 39) rgba(54, 54, 54, .32);
  transition: filter var(--t-fast);
}
.gm__corner.gm__corner--tools .combat-control::after {
  content: ''; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: transparent;
  box-shadow: inset 0 0 calc(var(--team-control-h) * 6 / 39) rgba(255, 255, 255, .22);
}
.gm__corner.gm__corner--tools .gm__tools-toggle { width: calc(var(--team-control-h) * .5); }
.combat-control__svg { display: block; width: 100%; height: 100%; pointer-events: none; }
.combat-control__plate { fill: #626262; stroke: none; }
.combat-control__glyph { fill: #f2f2f2; }
.combat-control__cutout { fill: #626262; }
.combat-control__more { fill: none; stroke: #f2f2f2; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; transform-box: fill-box; transform-origin: center; transition: transform var(--t-fast); }
.gm__corner.gm__corner--tools .combat-control:hover,
.gm__corner.gm__corner--tools .combat-control:focus-visible,
.gm__corner.gm__corner--tools .combat-control[aria-expanded="true"] { outline: none; background: transparent; filter: brightness(1.18); }
.sp-coarse .gm__corner--tools .combat-control::before { width: 100%; }
.gm__tools.is-open .combat-control__more { transform: scaleX(-1); }
@media (prefers-reduced-motion: reduce) { .combat-control__more { transition: none; } }
