/* Lobby and waiting-room chat: a compact, collapsible overlay that leaves the screen actions visible. */
.sp-chat {
  position: fixed;
  z-index: 95;
  --chat-cap: 360px;
  bottom: calc(var(--sp-vv-bottomGap) + max(12px, var(--sa-b)));
  left: calc(var(--sp-vv-left) + max(12px, var(--sa-l)));
  width: max-content;
  max-width: calc(100vw - 24px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
  pointer-events: none;
  color: var(--text-hi);
  font-size: clamp(14px, .16rem, 18px);
}
.sp-chat.is-open { width: min(380px, calc(100vw - 24px)); }
.sp-chat:not(.sp-chat--match) { bottom: calc(var(--sp-vv-bottomGap) + max(12px, var(--sa-b)) + 30px); }
.sp-chat--match { --chat-cap: 240px; top: auto; transform: none; }
/* Exploration owns an empty header slot; never float its launcher over map nodes. */
.mz-chat-slot { display:block; flex:none; width:32px; height:32px; }
.sp-chat.sp-chat--docked .sp-chat__toggle { width:32px; min-width:32px; height:32px; min-height:32px; padding:5px; justify-content:center; gap:0; }
.sp-chat.sp-chat--docked .sp-chat__toggle .sp-chat__compact-icon { display:block; width:18px; height:18px; }
.sp-chat.sp-chat--docked .sp-chat__label,.sp-chat.sp-chat--docked .sp-chat__state { display:none; }
.sp-chat.sp-chat--docked .sp-chat__count { position:absolute; top:-6px; right:-6px; min-width:15px; padding:1px 3px; font-size:9px; pointer-events:none; }
/* 避让高度由组件测量工具栏/房间操作区，不再猜测 rem 行数。 */
.gm__corner { bottom: 12px; left: 12px; }
.gm__corner .gm__chat-slot {
  flex: none;
  width: var(--sp-chat-launcher-width, .56rem);
  height: var(--sp-chat-launcher-height, .56rem);
  pointer-events: none;
}
.sp-chat--match.is-open { display: flex; flex-direction: column-reverse; align-items: flex-start; }
.sp-chat--match .sp-chat__panel { margin-top: 0; margin-bottom: 4px; }
.sp-chat__close { flex: none; min-height: 32px; background: transparent; border: 0; color: var(--mint-400); }
.sp-chat.has-keyboard { top: auto; }
.sp-chat.has-keyboard .sp-chat__toggle { display: none; }
.sp-chat--match .sp-chat__toggle { margin-left: 0; margin-right: auto; }
.sp-chat--match.has-keyboard { display: flex; flex-direction: column; }
.sp-chat--match.has-keyboard .sp-chat__panel { margin-top: 4px; margin-bottom: 0; }
.sp-chat button, .sp-chat__panel { pointer-events: auto; }
.sp-chat button { font: inherit; cursor: pointer; }
.sp-chat button:disabled { opacity: .45; cursor: not-allowed; }
.sp-chat__toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .14rem;
  min-height: 36px;
  padding: .06rem .14rem;
  background: rgba(17, 27, 22, .96);
  border: 1px solid var(--mint-700);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .45);
  color: var(--mint-400);
  font-weight: 700;
}
.sp-chat__compact-icon { display: none; }
.sp-chat__toggle:hover { border-color: var(--mint-400); }
.sp-chat__count {
  min-width: 1.5em;
  padding: 0 .25em;
  border-radius: 2px;
  background: #dc2626;
  color: #fff;
  font-size: .85em;
  text-align: center;
}
.sp-chat__panel {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: min(var(--chat-cap), var(--chat-available, calc(var(--sp-vv-height) - 100px)));
  max-height: var(--chat-available, calc(var(--sp-vv-height) - 100px));
  min-height: 0;
  margin-top: 4px;
  overflow: hidden;
  border: 1px solid var(--line-2);
  background: rgba(12, 17, 15, .97);
  box-shadow: 0 12px 30px rgba(0, 0, 0, .6);
}
.sp-chat__heading {
  display: flex;
  justify-content: space-between;
  flex: none;
  gap: 10px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--mint-400);
  font-weight: 700;
}
.sp-chat__heading span { color: var(--text-lo); font-size: .83em; font-weight: 400; }
.sp-chat__list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px 10px;
  touch-action: pan-y;
}
.sp-chat__message { padding: 9px 8px; border-bottom: 1px solid var(--line); }
.sp-chat__message.is-mine { border-left: 2px solid var(--mint-700); }
.sp-chat__meta { display: flex; justify-content: space-between; gap: 10px; color: var(--text-md); font-size: .88em; }
.sp-chat__meta strong { min-width: 0; overflow-wrap: anywhere; }
.sp-chat__meta time { flex: none; color: var(--text-lo); }
.sp-chat__text { margin: 5px 0 0; overflow-wrap: anywhere; white-space: pre-wrap; user-select: text; }
.sp-chat__invite {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
  padding: 9px;
  border: 1px solid var(--mint-700);
  background: var(--mint-a10);
}
.sp-chat__invite b { color: var(--mint-400); letter-spacing: .08em; }
.sp-chat__invite button, .sp-chat__compose button, .sp-chat__share {
  min-height: 32px;
  padding: 4px 10px;
  border: 1px solid var(--mint-700);
  background: var(--mint-800);
  color: var(--text-hi);
}
.sp-chat__invite button:hover:not(:disabled), .sp-chat__compose button:hover:not(:disabled), .sp-chat__share:hover:not(:disabled) {
  border-color: var(--mint-400);
  color: var(--mint-400);
}
.sp-chat__empty { margin: 20px 4px; color: var(--text-lo); text-align: center; }
.sp-chat__compose { display: flex; flex: none; gap: 6px; padding: 10px; border-top: 1px solid var(--line); }
.sp-chat__compose input {
  flex: 1;
  min-width: 0;
  min-height: 36px;
  padding: 6px 8px;
  border: 1px solid var(--line-2);
  border-radius: 0;
  background: var(--bg-0);
  color: var(--text-hi);
  font-size: max(16px, 1em);
}
.sp-chat__compose input:focus { border-color: var(--mint-500); }
.sp-chat__share { flex: none; margin: 0 10px 10px; }
@media (max-height: 500px) {
  .sp-chat { --chat-cap: 240px; }
  .sp-chat--match { top: auto; }
  .sp-chat__heading, .sp-chat__compose { padding: 4px 8px; }
}
@media (max-width: 700px) {
  .sp-chat.is-open { width: min(340px, calc(100vw - 24px)); }
  .sp-chat__toggle { min-height: 44px; }
  .sp-chat__compose button, .sp-chat__close { min-height: 36px; }
}
.sp-chat.has-keyboard .sp-chat__panel { margin: 0; }
.sp-chat.has-keyboard .sp-chat__share { display: none; }
/* 极低空间保留关闭、输入和分享操作；只让消息区收缩，不裁切底部按钮。 */
.sp-chat.is-tight .sp-chat__toggle { display: none; }
.sp-chat.is-tight .sp-chat__heading > span { display: none; }
.sp-chat.is-tight .sp-chat__heading { position: absolute; top: 0; right: 0; z-index: 2; border: 0; padding: 0; }
.sp-chat.is-tight .sp-chat__close { min-height: 40px; background: var(--bg-0); }
.sp-chat.is-tight .sp-chat__compose { padding-right: 68px; }
.sp-chat.is-tight .sp-chat__panel { margin: 0; }
.sp-chat.is-tight .sp-chat__list { padding-block: 0; overflow: auto; }
.sp-chat.is-tight .sp-chat__compose { min-height: 44px; padding-block: 2px; }
.sp-chat.is-tight .sp-chat__share { margin-bottom: 0; }
.sp-chat.is-tight .sp-chat__list:empty { display: none; }
.sp-chat__compose, .sp-chat__share { position: relative; z-index: 1; }

/* 手机横屏使用紧凑面板；保留桌面尺寸和局内工具栏的动态避让。 */
@media (orientation: landscape) and (max-height: 500px) and (pointer: coarse) {
  .sp-chat { font-size: 14px; line-height: 1.25; }
  .sp-chat.is-open { width: min(300px, calc(100vw - 24px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px))); }
  .sp-chat__toggle { min-height: 30px; height: 30px; gap: 5px; padding: 3px 7px; }
  .sp-chat__label, .sp-chat__state { display: none; }
  .sp-chat__toggle .sp-chat__compact-icon { display: block; width: 18px; height: 18px; }
  .sp-chat { --chat-cap: 170px; }
  .sp-chat__heading { align-items: center; gap: 6px; padding: 0 6px; }
  .sp-chat__heading span { min-width: 0; overflow-wrap: anywhere; }
  .sp-chat__close { min-width: 60px; min-height: 36px; padding: 4px; }
  .sp-chat__list { padding: 3px 6px; }
  .sp-chat__message { padding: 5px 4px; }
  .sp-chat__text { margin-top: 3px; }
  .sp-chat__empty { margin: 8px 4px; }
  /* 固定单行控件高度，避免 min-height 与紧凑模式下限挤占消息区。 */
  .sp-chat__compose { align-items: center; gap: 6px; padding: 4px 6px; border-top: 0; box-shadow: inset 0 1px var(--line); }
  .sp-chat.is-tight .sp-chat__compose { min-height: 0; padding-block: 4px; }
  .sp-chat__compose input { height: 30px; min-height: 0; padding: 4px 6px; line-height: 20px; }
  .sp-chat__compose button { flex: none; min-width: 52px; height: 30px; min-height: 30px; padding: 4px 8px; }
  .sp-chat__share { min-height: 36px; margin: 0 6px 4px; padding: 4px 8px; }
  .sp-chat.has-keyboard { --chat-cap: 170px; }
}

.spectator-hall { display: flex; flex-direction: column; padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px)); font-size: 16px; }
.spectator-hall__header { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding-bottom: 16px; }
.spectator-hall__header h1 { font-size: 24px; margin: 0; }
.spectator-hall__header span { color: var(--text-lo); }
.spectator-hall__list { flex: 1; min-height: 0; overflow-y: auto; display: grid; align-content: start; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); gap: 16px; }
.spectator-hall__card { padding: 16px; border: 1px solid var(--mint-700); background: rgba(12, 17, 15, .94); overflow-wrap: anywhere; }
.spectator-hall__card h2 { font-size: 20px; margin: 0 0 10px; }
.spectator-hall__card p { color: var(--text-md); }
.spectator-hall__players { display: flex; flex-direction: column; gap: 8px; margin: 14px 0; }
.spectator-hall button, .spectator-hall__entry button, .spectator-bar button, .spectator-bar select { min-height: 40px; padding: 8px 12px; border: 1px solid var(--mint-700); background: var(--mint-800); color: var(--text-hi); font: inherit; cursor: pointer; }
.spectator-hall button:disabled { opacity: .5; cursor: not-allowed; }
.spectator-hall__entry { margin: 12px 0; font-size: max(14px, .16rem); }
.spectator-hall__entry button { width: 100%; }
.spectator-bar { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 8px; pointer-events: auto; background: rgba(12, 17, 15, .94); font-size: 14px; z-index: 30; }
.spectator-bar b { color: var(--mint-400); }
.spectator-bar select { min-width: 0; max-width: 180px; }
@media (max-width: 500px) { .spectator-bar span { display: none; } .spectator-bar { font-size: 12px; } .spectator-bar select { max-width: 135px; } }

/* 保留桌面窄窗社交布局；手机竖屏由全局遮罩阻断。 */
@media (orientation: portrait) and (max-width: 700px) {
  .sp-social-portrait .lobby-body { grid-template-columns: 1fr; padding: 16px 16px 76px; gap: 20px; }
  .sp-social-portrait .lobby-screen .topbar, .sp-social-portrait .room-screen .topbar { height: auto; min-height: 90px; display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 12px; }
  .sp-social-portrait .topbar__center { order: -1; width: 100%; }
  .sp-social-portrait .topbar__right { flex: 1; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
  .sp-social-portrait .topbar__title { font-size: 18px; }
  .sp-social-portrait .topbar .micro, .sp-social-portrait .me-chip { display: none; }
  .sp-social-portrait .topbar .btn { font-size: 12px; min-height: 32px; }
  .sp-social-portrait .mode-card { min-height: 155px; padding: 12px; }
  .sp-social-portrait .mode-card__desc, .sp-social-portrait .mode-card__points { font-size: 12px; }
  .sp-social-portrait .diff-card__desc, .sp-social-portrait .diff-card__effects, .sp-social-portrait .ranked-toggle__text { font-size: 12px; }
  .sp-social-portrait .join-row { flex-wrap: wrap; }
  .sp-social-portrait .join-row .field { flex-basis: 100%; }
  .sp-social-portrait .room-main { overflow-y: auto; padding-bottom: 76px; }
  .sp-chat--match { top: auto; }
  .gm--spectator .team { top: 112px; }
  .gm--spectator .gm__bonds { top: 70px; left: 12px; right: 12px; }
}




/* Public chat stays clear of the tutorial; keep home entries
   inside their own scroll viewport above that floating control. */
@media (max-width:1100px) and (any-pointer:coarse) {
  .east-hub .hub-stage .hub-side { max-height:var(--public-chat-side-height, calc(100% - 106px)); }
  .room-screen.east-room .rs-seats { padding-left:56px; justify-content:flex-start; }
}

/* Spectator mobile compact layout */
@media (max-width: 600px), (max-height: 600px) and (pointer: coarse), (max-height: 600px) and (any-pointer: coarse) {
  .sp-overlay-layer .modal__box.spectator-modal {
    width: min(640px, calc(var(--sp-vv-width, 100vw) - var(--sa-l, 0px) - var(--sa-r, 0px) - 24px)) !important;
    height: calc(var(--sp-ui-height, 100dvh) - 16px);
    max-height: calc(var(--sp-ui-height, 100dvh) - 16px);
    min-width: 0;
    overflow: hidden;
  }
  .sp-overlay-layer .modal__box.spectator-modal > .modal__head {
    flex-direction: row; align-items: center; gap: 6px; min-height: 34px; padding: 5px 42px 5px 10px;
  }
  .spectator-modal .modal__title { font-size: 15px; line-height: 1.3; letter-spacing: .02em; }
  .sp-overlay-layer .spectator-modal button.sp-overlay-close {
    top: 2px; right: 4px; width: 30px; height: 30px; min-width: 30px; min-height: 30px; padding: 5px;
  }
  .sp-overlay-layer .spectator-modal > .modal__body { min-width: 0; min-height: 0; padding: 0; overflow: hidden; }
  .sp-overlay-layer .spectator-modal > .modal__body > .spectator-hall {
    min-width: 0; min-height: 0; height: 100%; padding: 5px 10px 10px; overflow: hidden;
    font-size: 12px; line-height: 1.35;
  }
  .spectator-modal .spectator-hall__header {
    flex: none; gap: 6px 8px; padding-bottom: 7px; min-width: 0;
  }
  .spectator-modal .spectator-hall__header h1 { display: none; }
  .spectator-modal .spectator-hall__header span { flex: 1; min-width: 0; font-size: 11px; line-height: 1.35; }
  .spectator-modal .spectator-hall button {
    min-width: 0; min-height: 32px; padding: 5px 8px; font-size: 12px; line-height: 1.35;
    touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  }
  .sp-coarse .spectator-modal button::before { content: none; }
  .spectator-modal .spectator-hall > p { flex: none; margin: 0 0 6px; font-size: 11px; line-height: 1.4; }
  .spectator-modal .spectator-hall__list {
    flex: 1 1 0; min-width: 0; min-height: 0;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr));
    gap: 8px; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y;
    -webkit-overflow-scrolling: touch; scrollbar-gutter: stable;
  }
  .spectator-modal .spectator-hall__card { min-width: 0; padding: 8px; }
  .spectator-modal .spectator-hall__card h2 { margin: 0 0 4px; font-size: 13px; line-height: 1.35; }
  .spectator-modal .spectator-hall__card p { margin: 4px 0; font-size: 11px; line-height: 1.4; }
  .spectator-modal .spectator-hall__players {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 8px; margin: 7px 0;
    font-size: 11px; line-height: 1.35;
  }
  .spectator-modal .spectator-hall__players > span { min-width: 0; overflow-wrap: anywhere; }
  .spectator-modal .spectator-hall__card > button { min-width: 80px; }
  .spectator-modal .spectator-hall__empty { grid-column: 1 / -1; margin: 0; padding: 10px 4px; font-size: 12px; line-height: 1.4; }
}
/* End spectator mobile compact layout */
