* { margin: 0; padding: 0; box-sizing: border-box; }

/* 默认：大厅可整页滚动（兼容不支持 dvh / 内层 overflow 失效的安卓机） */
html, body {
  background: #000;
  color: #eee;
  font-family: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
html {
  height: 100%;
  height: -webkit-fill-available;
}
body {
  background: #111;
  min-height: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  height: auto;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

/* 对局中锁滚动，避免拖动画布 / 误触浏览器手势 */
body.in-game,
body.ios-immersive {
  height: 100%;
  height: 100vh;
  height: 100dvh;
  height: -webkit-fill-available;
  min-height: -webkit-fill-available;
  overflow: hidden;
  overscroll-behavior: none;
  padding-left: 0;
  padding-right: 0;
  background: #000;
}

#game, #vp, #stage, #screen {
  touch-action: none;
}

#lobby input,
#lobby textarea,
#lobby select,
#joinModal input,
#joinModal textarea,
#joinModal select {
  -webkit-user-select: text;
  user-select: text;
  touch-action: manipulation;
}
#lobby input:not([type="range"]),
#joinModal input:not([type="range"]) {
  font-size: 16px; /* 避免 iOS 聚焦时强制放大 */
}

#lobby.panel {
  max-width: 440px;
  width: calc(100% - 24px);
  margin: 12px auto 24px;
  margin-top: max(12px, env(safe-area-inset-top, 0px));
  margin-bottom: max(24px, env(safe-area-inset-bottom, 0px));
  /* 内容高度交给 body 滚动，避免依赖脆弱的内层 max-height */
  max-height: none;
  overflow: visible;
  background: #1b1b1b;
  border-radius: 12px;
  padding: 22px;
  box-shadow: 0 0 20px rgba(0,0,0,.6);
}
#lobby h1 { font-size: 22px; margin-bottom: 4px; color: #ffd000; text-align: center; }
#lobby .sub { text-align: center; color: #888; font-size: 12px; margin-bottom: 14px; }
.row {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  align-items: center;
  column-gap: 12px;
  row-gap: 6px;
  margin-bottom: 12px;
}
.row label {
  width: auto;
  color: #aaa;
  font-size: 14px;
  line-height: 1.3;
}
.row.row-stack {
  grid-template-columns: minmax(0, 1fr);
}
.row.row-stack .row-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}
.row.row-stack .row-head label {
  flex: 0 0 auto;
}
.row input, .row select {
  width: 100%;
  min-width: 0;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid #333;
  background: #262626;
  color: #eee;
  font-size: 15px;
  outline: none;
}
.row input:focus, .row select:focus { border-color: #ffd000; }
.btns { display: flex; gap: 10px; margin: 16px 0 8px; }
.btns > button { flex: 1; min-width: 0; }
button {
  flex: 1; padding: 11px; border: none; border-radius: 8px; cursor: pointer;
  font-size: 15px; background: #ffd000; color: #111; font-weight: 600;
}
button:disabled { background: #444; color: #888; cursor: not-allowed; }
button.secondary { background: #333; color: #eee; }
button.danger, #btnLeave {
  background: #5a1a1a; color: #ffc0c0; border: 1px solid #883333;
}
button.danger:hover, #btnLeave:hover { background: #6e2222; }

#roomStatus { margin: 6px 0; font-size: 15px; color: #8ef; text-align: center; }
#shareBlock { margin: 8px 0 4px; }
.share-tabs { display: flex; gap: 6px; margin-bottom: 8px; }
.share-tab {
  flex: 1; min-width: 0; padding: 7px 6px; font-size: 12px; background: #2a2a2a; color: #bbb;
  border-radius: 8px;
}
.share-tab.active { background: #ffd000; color: #111; }
#shareRow { display: flex; gap: 8px; align-items: stretch; }
#shareLink {
  flex: 1; min-width: 0; padding: 8px 10px; border-radius: 8px; background: #262626;
  font-size: 11px; color: #8ef; word-break: break-all; border: 1px solid #333;
  display: flex; align-items: center;
}
#shareRow button { flex: 0 0 auto; padding: 8px 12px; font-size: 13px; width: auto; }
#players, #audienceBox { margin: 8px 0; }
.player, .aud-item {
  padding: 8px 12px; border-radius: 8px; background: #262626; margin-bottom: 6px; font-size: 14px;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.player .tag, .aud-item .tag { display: inline-block; min-width: 34px; color: #ffd000; }
.player .ok { color: #4caf50; }
.player .wait { color: #888; }
.aud-item .mini {
  margin-left: auto; flex: 0 0 auto; padding: 4px 10px; font-size: 12px; background: #444; color: #eee;
}
.host-tools {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 8px 0 12px;
}
.host-tools button { width: 100%; padding: 8px; font-size: 13px; }
#hostBtns { margin-top: 4px; }
#hostStartHint { margin-top: 2px; }
.room-actions { margin-top: 10px; }
.room-actions button { width: 100%; }
#log { margin-top: 10px; font-size: 13px; color: #f66; min-height: 18px; word-break: break-word; }

/* 游戏区 */
#game {
  height: 100vh; height: 100dvh;
  display: flex; flex-direction: column; align-items: stretch;
  position: relative; background: #000;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  box-sizing: border-box;
}
#topbar {
  width: 100%; display: flex; justify-content: space-between;
  align-items: center; padding: 8px 12px; font-size: 13px; color: #eee;
  flex-shrink: 0; gap: 8px; z-index: 30;
}
#topbar #gameStatus { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#topbar .topbtns { display: flex; gap: 6px; flex-shrink: 0; }
#topbar button { flex: 0 0 auto; padding: 6px 10px; font-size: 12px; background: #333; color: #eee; }
#topbar button.top-leave {
  background: #4a1818; color: #ffb0b0; border: 1px solid #663333;
}

#stage {
  width: 100%; flex: 1; min-height: 0;
  display: flex; align-items: center; justify-content: center;
  background: #000; overflow: hidden; position: relative;
}
#screen {
  display: block;
  flex-shrink: 0;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
#roleBadge {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.55); color: #ffd000; padding: 4px 12px;
  border-radius: 999px; font-size: 12px; pointer-events: none; z-index: 3;
}

.pause-overlay {
  position: absolute; inset: 0; z-index: 8;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.55);
}
.pause-card {
  text-align: center; padding: 22px 28px; border-radius: 14px;
  background: rgba(22,22,22,.92); border: 1px solid #444;
  box-shadow: 0 10px 30px rgba(0,0,0,.45);
}
.pause-title { color: #ffd000; font-size: 18px; margin-bottom: 14px; font-weight: 700; }
.pause-card button { min-width: 140px; padding: 12px 18px; font-size: 15px; }

#btnGamePause.is-paused { background: #ffd000; color: #111; }

/* 触控对局：顶栏悬浮，画面占满整屏 */
body.touch-play #game { display: block; }
body.touch-play #topbar {
  position: absolute; top: 0; left: 0; right: 0; max-width: none;
  padding: 6px 10px;
  background: linear-gradient(rgba(0,0,0,.55), transparent);
  pointer-events: none;
}
body.touch-play #topbar .topbtns,
body.touch-play #topbar button { pointer-events: auto; }
body.touch-play #stage {
  position: absolute; inset: 0; flex: none; border-radius: 0; max-width: none;
}
body.touch-play #kbHint { display: none !important; }

/* 虚拟键 overlay：按键浮在画面上，画布居中缩放 */
body.pad-overlay #stage,
body.touch-play #stage {
  align-items: center;
  justify-content: center;
}
/* 虚拟键 overlay：按键浮在画面上，画布仍按整屏居中缩放 */
body.pad-overlay #vp {
  position: absolute !important;
  inset: 0 !important;
  flex: none !important;
  max-width: none !important;
  width: auto !important;
  padding: 0 !important;
  display: block !important;
  pointer-events: none;
  z-index: 2;
}
body.pad-overlay .face-a,
body.pad-overlay .face-b {
  display: block;
  position: absolute;
  pointer-events: auto;
  z-index: 5;
}
body.pad-overlay .face-a {
  right: calc(var(--pad-a-x, 7vw) + env(safe-area-inset-right, 0px));
  bottom: calc(var(--pad-a-y, 22vh) + env(safe-area-inset-bottom, 0px));
}
body.pad-overlay .face-b {
  right: calc(var(--pad-b-x, 7vw) + env(safe-area-inset-right, 0px));
  bottom: calc(var(--pad-b-y, 10vh) + env(safe-area-inset-bottom, 0px));
}
/* SE/ST 挂在 #vp 下，可独立调位置 */
body.pad-overlay .face-meta {
  position: absolute;
  top: calc(var(--pad-meta-y, 6vh) + env(safe-area-inset-top, 0px));
  right: calc(var(--pad-meta-x, 7vw) + env(safe-area-inset-right, 0px));
  bottom: auto;
  left: auto;
  display: flex;
  gap: 8px;
  padding: 0;
  z-index: 6;
  pointer-events: auto;
}
body.pad-overlay .face-meta .vbtn.meta {
  width: calc(46px * var(--pad-meta-scale, 1));
  height: calc(30px * var(--pad-meta-scale, 1));
  font-size: calc(10px * var(--pad-meta-scale, 1));
  opacity: calc(var(--pad-opacity, .28) + 0.18);
}
body.pad-overlay #vp.lefty .face-meta {
  right: auto;
  left: calc(var(--pad-meta-x, 7vw) + env(safe-area-inset-left, 0px));
}
body.pad-overlay #vp.lefty .face-a {
  right: auto;
  left: calc(var(--pad-a-x, 7vw) + env(safe-area-inset-left, 0px));
}
body.pad-overlay #vp.lefty .face-b {
  right: auto;
  left: calc(var(--pad-b-x, 7vw) + env(safe-area-inset-left, 0px));
}

body.stream #gameStats,
body.stream #kbHint { display: none !important; }
body.stream #topbar {
  padding: 6px 10px; font-size: 12px;
  background: linear-gradient(rgba(0,0,0,.45), transparent);
}
body.stream #topbar button { padding: 4px 8px; font-size: 11px; opacity: .75; }
body.stream #stage { border-radius: 0; }

@media (pointer: fine) {
  #vp { display: none; }
  #kbHint { display: block; }
  body.force-pad #vp,
  body.in-game.has-touch-pad #vp,
  body.pad-applied-preview #vp {
    display: block !important; position: absolute; inset: 0; max-width: none; z-index: 2;
  }
  body.force-pad #kbHint,
  body.in-game.has-touch-pad #kbHint,
  body.pad-applied-preview #kbHint { display: none; }
  body.touch-play #vp { display: block !important; }
}

#vp {
  width: 100%; max-width: 900px; flex: 1; display: flex;
  justify-content: space-between; align-items: center; padding: 16px 20px;
  position: relative;
}
.vbtn {
  background: rgba(255,255,255,.14); color: #fff; border: 1px solid rgba(255,255,255,.25);
  border-radius: 12px; font-size: 22px; font-weight: 700;
  touch-action: none; -webkit-tap-highlight-color: transparent;
}
.vbtn:active, .vbtn.pressed { background: rgba(255,208,0,.5); }

/* 圆环方向盘 */
.dpad.stick {
  position: relative;
  width: 132px; height: 132px;
  border-radius: 50%;
  touch-action: none;
  flex-shrink: 0;
}
.stick-ring {
  position: absolute; inset: 0;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.28);
  background:
    radial-gradient(circle at center, rgba(255,255,255,.04) 0 28%, transparent 29%),
    rgba(255,255,255,.07);
  box-shadow: inset 0 0 0 14px rgba(0,0,0,.12);
}
.stick-cross {
  position: absolute; inset: 18%;
  border-radius: 50%;
  background:
    linear-gradient(rgba(255,255,255,.14), rgba(255,255,255,.14)) center/2px 56% no-repeat,
    linear-gradient(rgba(255,255,255,.14), rgba(255,255,255,.14)) center/56% 2px no-repeat;
  pointer-events: none; opacity: .55;
}
.stick-knob {
  position: absolute; left: 50%; top: 50%;
  width: 42px; height: 42px; margin: -21px 0 0 -21px;
  border-radius: 50%;
  background: rgba(255,255,255,.28);
  border: 1px solid rgba(255,255,255,.4);
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
  pointer-events: none;
  transition: background .12s;
}
.dpad.stick.active .stick-knob {
  background: rgba(255,208,0,.55);
  border-color: rgba(255,208,0,.7);
}
.dpad.stick.active .stick-ring {
  border-color: rgba(255,208,0,.45);
}
.dpad.stick.mode-4way .stick-cross {
  /* 四向提示：斜向十字淡一点 */
  opacity: .35;
}

/* 十字分键 */
.dpad.cross {
  position: relative;
  width: 132px; height: 132px;
  flex-shrink: 0;
  touch-action: none;
}
.dpad.cross .cross-btn {
  position: absolute;
  width: 44px; height: 44px;
  padding: 0;
  font-size: 16px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
}
.dpad.cross .cross-btn.up { left: 50%; top: 0; transform: translateX(-50%); }
.dpad.cross .cross-btn.down { left: 50%; bottom: 0; transform: translateX(-50%); }
.dpad.cross .cross-btn.left { left: 0; top: 50%; transform: translateY(-50%); }
.dpad.cross .cross-btn.right { right: 0; top: 50%; transform: translateY(-50%); }
.dpad.cross .cross-center {
  position: absolute; left: 50%; top: 50%;
  width: 28px; height: 28px; margin: -14px 0 0 -14px;
  border-radius: 6px;
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.18);
  pointer-events: none;
}

/* 游戏内设置菜单：固定全屏层，不被 #vp 挡住 */
.game-menu {
  position: fixed; inset: 0; z-index: 40000;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.68);
  padding: 12px;
  box-sizing: border-box;
  pointer-events: auto;
  touch-action: manipulation;
}
.game-menu-card {
  position: relative; z-index: 1;
  width: min(360px, 94vw);
  max-height: min(88vh, 680px);
  max-height: min(88dvh, 680px);
  overflow-y: auto;
  overflow-x: hidden;
  background: linear-gradient(165deg, #222 0%, #141414 100%);
  border: 1px solid #3d3d3d;
  border-radius: 16px;
  padding: 0;
  display: flex; flex-direction: column;
  box-shadow: 0 16px 48px rgba(0,0,0,.55);
  touch-action: pan-y;
  pointer-events: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.game-menu-header {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px 16px 10px;
  border-bottom: 1px solid #2e2e2e;
  flex-shrink: 0;
}
.game-menu-title {
  color: #ffd000; font-size: 16px; font-weight: 700;
  letter-spacing: .06em;
}
.game-menu-title .menu-ver,
.game-menu-header .menu-ver {
  color: #555; font-size: 10px; font-weight: 500;
}
.menu-section {
  padding: 12px 14px;
  border-bottom: 1px solid #2a2a2a;
  display: flex; flex-direction: column; gap: 8px;
}
.menu-section:last-child { border-bottom: none; }
.menu-subsection {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid #333;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.menu-subsection-title {
  color: #888;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
}
.menu-exit-hint {
  margin: -4px 0 6px;
  text-align: center;
  font-size: 11px;
}

/* 键盘改键（电脑） */
.kb-profile-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}
.kb-profile-label {
  color: #aaa;
  font-size: 13px;
  flex-shrink: 0;
}
.kb-profile-sel {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid #333;
  background: #262626;
  color: #eee;
  font-size: 14px;
}
.kb-bind-layout {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 4px;
}
.kb-bind-dpad {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.kb-bind-dpad-mid {
  display: flex;
  align-items: center;
  gap: 4px;
}
.kb-bind-center {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: rgba(255,255,255,.06);
  border: 1px dashed rgba(255,255,255,.12);
}
.kb-bind-side {
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
  min-width: 0;
}
.kb-bind-meta,
.kb-bind-face {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.kb-bind-tag {
  font-size: 10px;
  color: #777;
  min-width: 28px;
}
.kb-bind-cell {
  min-width: 44px;
  height: 36px;
  padding: 0 8px;
  border-radius: 8px;
  border: 1px solid #444;
  background: #2a2a2a;
  color: #ffd000;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
}
.kb-bind-cell.kb-bind-round {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  padding: 0;
}
.kb-bind-cell.kb-bind-round-a {
  width: 50px;
  height: 50px;
}
.kb-bind-cell.kb-bind-empty { color: #666; font-weight: 400; }
.kb-bind-cell.kb-bind-wait {
  border-color: #ffd000;
  background: #3a3200;
  box-shadow: 0 0 0 2px rgba(255,208,0,.25);
  animation: kb-bind-pulse 0.9s ease-in-out infinite;
}
@keyframes kb-bind-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .65; }
}

body.desktop-layout #vp { display: none !important; }
body.desktop-layout.in-game #kbHint { display: block; }
body.desktop-layout.in-game.has-touch-pad #vp { display: none !important; }

.menu-section-foot {
  padding-bottom: 14px;
  background: rgba(0,0,0,.18);
  border-radius: 0 0 16px 16px;
}
.menu-section-host {
  background: rgba(255,208,0,.04);
  border-top: 1px solid rgba(255,208,0,.12);
  border-bottom: 1px solid rgba(255,208,0,.12);
}
.menu-section-title {
  color: #888;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  padding-left: 2px;
}
.menu-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.menu-fit-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
}
.menu-fit-opt {
  padding: 10px 6px;
  font-size: 13px;
}
.menu-fit-opt.active {
  background: #3a3200;
  border-color: #886600;
  color: #ffd000;
  box-shadow: inset 0 0 0 1px rgba(255,208,0,.25);
}
.menu-btn {
  display: block;
  width: 100%;
  min-width: 0;
  padding: 11px 12px;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  border-radius: 10px;
  background: #2a2a2a;
  color: #eee;
  border: 1px solid #444;
  cursor: pointer;
  touch-action: manipulation;
  flex: 0 0 auto;
  line-height: 1.25;
}
.menu-btn:hover { background: #333; border-color: #555; }
.menu-btn:disabled { opacity: .45; cursor: not-allowed; }
.menu-btn-block { width: 100%; }
.menu-btn-primary {
  background: linear-gradient(180deg, #ffe033 0%, #ffd000 100%);
  color: #1a1a1a;
  border-color: #c9a800;
  font-size: 15px;
  padding: 13px 12px;
}
.menu-btn-primary:hover { background: linear-gradient(180deg, #fff0a0 0%, #ffe033 100%); }
.menu-btn-primary.is-paused {
  background: linear-gradient(180deg, #6ecf8a 0%, #4caf6e 100%);
  border-color: #3d8f58;
  color: #102018;
}
.menu-btn-accent {
  background: #3a3200;
  border-color: #886600;
  color: #ffd000;
}
.menu-btn-danger {
  background: #4a1818;
  border-color: #773333;
  color: #ffb8b8;
}
.menu-btn-danger:hover { background: #5c2020; }
.menu-btn-ghost {
  background: transparent;
  border-color: #444;
  color: #999;
  font-weight: 500;
}
.menu-btn-ghost:hover { background: #222; color: #ccc; }
.menu-toggle.on {
  background: #1a3a28;
  border-color: #3a7a52;
  color: #9f9;
}
.menu-btn.player-voice-only:disabled {
  opacity: .4;
  cursor: not-allowed;
}
.menu-slider-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 2px 0;
}
.menu-slider-label {
  font-size: 12px;
  color: #888;
  white-space: nowrap;
}
.menu-slider {
  width: 100%;
  min-width: 0;
  accent-color: #ffd000;
}
.menu-slider-tip {
  font-size: 12px;
  color: #aaa;
  min-width: 2.5em;
  text-align: right;
}
.menu-hint {
  color: #666;
  font-size: 11px;
  line-height: 1.45;
  margin: 0;
  padding: 0 2px;
}
/* 兼容旧 class */
.game-menu-item {
  width: 100%; padding: 11px 12px; font-size: 14px;
  text-align: left; border-radius: 10px;
  background: #2a2a2a; color: #eee; border: 1px solid #444;
  touch-action: manipulation;
  flex: 0 0 auto;
}
.game-menu-item:hover { background: #333; border-color: #666; }
.game-menu-item.secondary { background: #222; color: #bbb; }
.game-menu-item.danger { background: #3a1515; border-color: #662222; color: #ffb0b0; }
.game-menu-item.host-only { background: #2a2400; border-color: #665500; color: #ffd000; }
.game-menu-label {
  color: #aaa; font-size: 12px; margin: 4px 0 0; padding-left: 2px;
}
.game-menu-item.player-voice-only:disabled {
  opacity: .5;
  cursor: not-allowed;
}
.pad-mode-row {
  display: flex; flex-direction: column; gap: 6px;
  position: relative; z-index: 2;
}
.pad-mode-opt {
  display: block;
  width: 100%; padding: 10px 12px;
  border-radius: 8px;
  background: #252525; color: #ccc; border: 1px solid #3a3a3a;
  font-size: 13px; font-weight: 600;
  text-align: center;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none; user-select: none;
  box-sizing: border-box;
  flex: 0 0 auto;
}
.pad-mode-opt.active {
  background: #3a3200; border-color: #886600; color: #ffd000;
  box-shadow: inset 3px 0 0 #ffd000;
}
.pad-mini {
  height: 80px;
  position: relative;
  border-radius: 10px;
  background: #101010;
  border: 1px solid #333;
  margin: 0;
}
.pad-mini-stick {
  position: absolute; left: 50%; top: 50%;
  width: 64px; height: 64px; margin: -32px 0 0 -32px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.35);
  background: radial-gradient(circle at center, rgba(255,255,255,.12), transparent 55%);
}
.pad-mini-stick i {
  position: absolute; left: 50%; top: 50%;
  width: 22px; height: 22px; margin: -11px 0 0 -11px;
  border-radius: 50%; background: rgba(255,255,255,.35);
}
.pad-mini[data-mode="stick4"] .pad-mini-stick { border-color: #ffd000; }
.pad-mini-cross { display: none; position: absolute; inset: 10px 28px; }
.pad-mini-cross b {
  position: absolute; width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 6px; background: rgba(255,208,0,.4); color: #fff; font-size: 12px;
  font-weight: 700;
}
.pad-mini-cross .u { left: 50%; top: 0; transform: translateX(-50%); }
.pad-mini-cross .d { left: 50%; bottom: 0; transform: translateX(-50%); }
.pad-mini-cross .l { left: 0; top: 50%; transform: translateY(-50%); }
.pad-mini-cross .r { right: 0; top: 50%; transform: translateY(-50%); }
.pad-mini[data-mode="cross"] .pad-mini-stick { display: none; }
.pad-mini[data-mode="cross"] .pad-mini-cross { display: block; }
.pad-mini[data-mode="stick4"] .pad-mini-stick,
.pad-mini[data-mode="stick8"] .pad-mini-stick { display: block; }
.pad-mini[data-mode="stick4"] .pad-mini-cross,
.pad-mini[data-mode="stick8"] .pad-mini-cross { display: none; }
.pad-mini-flash {
  animation: padMiniFlash .45s ease;
}
@keyframes padMiniFlash {
  0% { box-shadow: 0 0 0 0 rgba(255,208,0,.65); border-color: #ffd000; }
  100% { box-shadow: 0 0 0 10px rgba(255,208,0,0); border-color: #333; }
}
.pad-mode-hint {
  color: #666;
  font-size: 11px;
  margin: 0;
  line-height: 1.4;
  padding-left: 2px;
}
.pad-apply-btn { margin-top: 2px; }
/* 设置打开时隐藏虚拟手柄，避免挡住/误触 */
body.game-menu-open #vp {
  visibility: hidden !important;
  pointer-events: none !important;
}
/* class + 默认隐藏十字，避免未切换时叠在一起 */
#crossPad { display: none; }
#vp.pad-mode-cross #stickPad,
body.pad-mode-cross #stickPad { display: none !important; visibility: hidden !important; }
#vp.pad-mode-cross #crossPad,
body.pad-mode-cross #crossPad { display: block !important; visibility: visible !important; }
#vp.pad-mode-stick8 #crossPad,
#vp.pad-mode-stick4 #crossPad,
body.pad-mode-stick8 #crossPad,
body.pad-mode-stick4 #crossPad { display: none !important; visibility: hidden !important; }
#vp.pad-mode-stick8 #stickPad,
#vp.pad-mode-stick4 #stickPad,
body.pad-mode-stick8 #stickPad,
body.pad-mode-stick4 #stickPad { display: block !important; visibility: visible !important; }
/* 十字键加亮，避免半透明看起来像「没切换」 */
#vp.pad-mode-cross .dpad.cross .cross-btn,
body.pad-mode-cross .dpad.cross .cross-btn {
  opacity: .92 !important;
  background: rgba(255,208,0,.28) !important;
  border-color: rgba(255,208,0,.65) !important;
  color: #fff !important;
}
#vp.pad-mode-stick4 .stick-ring,
body.pad-mode-stick4 .stick-ring {
  border-color: rgba(255,208,0,.55);
}
.stick-mode-tag {
  position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%);
  font-size: 10px; color: rgba(255,255,255,.55); pointer-events: none;
  letter-spacing: 1px;
}
.dpad.stick.mode-4way .stick-mode-tag { color: rgba(255,208,0,.75); }

/* 右侧 A/B（独立定位，见触控 media） */
.face-a,
.face-b {
  display: none;
}
.face-meta {
  display: flex; gap: 8px;
}
.face-a.vbtn.round,
.face-b.vbtn.round {
  width: calc(68px * var(--pad-btn-scale, 1));
  height: calc(68px * var(--pad-btn-scale, 1));
  border-radius: 50%;
  font-size: calc(17px * var(--pad-btn-scale, 1));
  pointer-events: auto;
  z-index: 5;
}
.face-a.vbtn.round.big {
  width: calc(78px * var(--pad-btn-scale, 1));
  height: calc(78px * var(--pad-btn-scale, 1));
  font-size: calc(18px * var(--pad-btn-scale, 1));
}
.face-a.vbtn small,
.face-b.vbtn small {
  display: block; font-size: calc(10px * var(--pad-btn-scale, 1)); font-weight: 400; color: #ddd;
}
.face-meta .vbtn.meta {
  width: calc(42px * var(--pad-meta-scale, 1));
  height: calc(30px * var(--pad-meta-scale, 1));
  font-size: calc(11px * var(--pad-meta-scale, 1));
  border-radius: 8px;
  opacity: .72; letter-spacing: .5px;
}

#vp.lefty .dpad { order: 2; }

.hand-toggle, .pad-opacity {
  position: absolute; z-index: 4; pointer-events: auto;
}
.hand-toggle {
  left: 50%; bottom: 8px; transform: translateX(-50%);
  width: auto; flex: 0; padding: 6px 12px; font-size: 14px;
  background: rgba(0,0,0,.45); color: #fff; border-radius: 8px;
}
.vol-box {
  position: absolute; left: 10px; top: 48px; z-index: 8;
  display: flex; align-items: center; gap: 6px;
  pointer-events: auto;
  background: rgba(0,0,0,.35); border-radius: 999px;
  padding: 4px 10px 4px 8px;
}
.vol-label { font-size: 11px; color: rgba(255,255,255,.75); flex-shrink: 0; }
.vol-tip { font-size: 11px; color: #ffd000; min-width: 28px; text-align: right; }
.pad-opacity {
  position: static; left: auto; top: auto; right: auto; bottom: auto;
  width: 88px; accent-color: #ffd000; margin: 0;
}

.hint { color: #666; font-size: 12px; margin-bottom: 8px; text-align: center; }

.modal-mask {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.65);
  display: flex; align-items: flex-start; justify-content: center;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 24px 12px;
  padding-top: max(24px, env(safe-area-inset-top, 0px));
  padding-bottom: max(24px, env(safe-area-inset-bottom, 0px));
  box-sizing: border-box;
  touch-action: manipulation;
}
.modal {
  width: min(86vw, 360px); background: #1b1b1b; border-radius: 12px;
  padding: 20px; box-shadow: 0 8px 30px rgba(0,0,0,.6);
  margin: auto;
  flex-shrink: 0;
}
.modal-title { font-size: 17px; color: #ffd000; margin-bottom: 14px; text-align: center; }
.modal input[type="text"], .modal input:not([type]), .modal #joinRoomInput {
  width: 100%; padding: 12px; border-radius: 8px; border: 1px solid #333;
  background: #262626; color: #eee; font-size: 18px; letter-spacing: 3px;
  text-align: center; outline: none;
}
.modal input:focus { border-color: #ffd000; }
.mode-row {
  display: flex; justify-content: space-between; gap: 6px;
  margin-top: 12px; font-size: 13px; color: #ccc;
}
.mode-row label { display: flex; align-items: center; gap: 4px; }
.modal-btns { display: flex; gap: 10px; margin-top: 16px; }

.modal.qr-modal { text-align: center; }
.qr-box { display: inline-block; background: #fff; border-radius: 8px; padding: 10px; }
.qr-box img { display: block; width: min(62vw, 280px); height: auto; image-rendering: pixelated; }
.qr-note { color: #aaa; font-size: 13px; margin: 12px 6px; }

.audio-banner {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%);
  z-index: 60; display: flex; align-items: center; gap: 12px;
  background: rgba(20,20,20,.92); border: 1px solid #444; border-radius: 999px;
  padding: 10px 14px 10px 18px; color: #eee; font-size: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,.45);
}
.audio-banner button { flex: 0 0 auto; padding: 8px 14px; font-size: 13px; }

.host-panel {
  position: absolute; right: 10px; top: 52px; z-index: 20;
  width: min(92vw, 320px); max-height: 70vh; overflow: auto;
  background: rgba(22,22,22,.94); border: 1px solid #333; border-radius: 12px;
  padding: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
.host-panel-title { color: #ffd000; font-size: 14px; margin-bottom: 8px; }
.host-panel-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.host-panel-actions button { flex: 1 1 40%; padding: 8px; font-size: 12px; }
#hostPanelBody { font-size: 13px; color: #ccc; }
#hostPanelBody .row-item {
  display: flex; align-items: center; gap: 6px; padding: 6px 0;
  border-bottom: 1px solid #2a2a2a;
}
#hostPanelBody .row-item button { flex: 0 0 auto; padding: 4px 8px; font-size: 11px; }
#hostPanelBody .turn-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  margin: 8px 0; padding: 8px 0; border-top: 1px solid #2a2a2a; border-bottom: 1px solid #2a2a2a;
}
#hostPanelBody .turn-row select {
  flex: 1 1 auto; min-width: 120px; padding: 6px 8px;
  border-radius: 6px; border: 1px solid #444; background: #222; color: #eee;
}
.rom-lock-tip {
  color: #888;
  font-weight: normal;
  font-size: 12px;
  margin-left: 0;
  text-align: right;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rom-select-native {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  border: 0 !important;
  opacity: 0 !important;
  pointer-events: none !important;
}
.rom-picker { position: relative; width: 100%; }
.rom-picker-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid #3a3a3a;
  background: linear-gradient(180deg, #2c2c2c 0%, #232323 100%);
  color: #eee;
  font-size: 15px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.04);
}
.rom-picker-btn:hover { border-color: #555; }
.rom-picker.open .rom-picker-btn,
.rom-picker-btn:focus {
  border-color: #ffd000;
  outline: none;
  box-shadow: 0 0 0 2px rgba(255,208,0,.18);
}
.rom-picker-btn:disabled {
  opacity: .65;
  cursor: not-allowed;
  background: #262626;
}
.rom-picker-text {
  display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1;
}
.rom-picker-caption {
  font-size: 11px; color: #888; font-weight: 400; letter-spacing: .02em;
}
.rom-picker-value {
  color: #ffd000; font-weight: 600; font-size: 15px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.rom-picker-caret {
  flex: 0 0 auto;
  width: 10px; height: 10px;
  border-right: 2px solid #aaa;
  border-bottom: 2px solid #aaa;
  transform: rotate(45deg);
  margin-top: -4px;
  transition: transform .15s ease;
}
.rom-picker.open .rom-picker-caret {
  transform: rotate(225deg);
  margin-top: 4px;
  border-color: #ffd000;
}
.rom-picker-panel {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px);
  z-index: 40;
  display: flex;
  flex-direction: column;
  max-height: min(48vh, 320px);
  max-height: min(48dvh, 320px);
  background: #1f1f1f;
  border: 1px solid #444;
  border-radius: 10px;
  box-shadow: 0 12px 28px rgba(0,0,0,.45);
  overflow: hidden;
}
.rom-picker-search-wrap {
  flex-shrink: 0;
  padding: 8px 8px 6px;
  border-bottom: 1px solid #333;
  background: #1a1a1a;
}
.rom-picker-search {
  width: 100%;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid #3a3a3a;
  background: #262626;
  color: #eee;
  font-size: 16px;
  outline: none;
  -webkit-user-select: text;
  user-select: text;
  touch-action: manipulation;
  -webkit-touch-callout: default;
}
.rom-picker-search:focus {
  border-color: #ffd000;
  box-shadow: 0 0 0 2px rgba(255,208,0,.15);
}
.rom-picker-search::placeholder { color: #666; }
.rom-picker-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding: 6px;
}
.rom-picker-option {
  width: 100%;
  display: block;
  text-align: left;
  padding: 11px 12px;
  margin: 0 0 4px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: #ddd;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.rom-picker-option:last-child { margin-bottom: 0; }
.rom-picker-option:hover,
.rom-picker-option:focus {
  background: #2a2a2a; color: #fff; outline: none;
}
.rom-picker-option.active {
  background: #3a3200; color: #ffd000;
  box-shadow: inset 3px 0 0 #ffd000;
}
.rom-picker-empty {
  padding: 14px 12px; color: #888; font-size: 13px; text-align: center;
}
#romSelect:disabled { opacity: .65; cursor: not-allowed; }

.live-bar {
  color: #bbb; font-size: 12px; margin: 0 8px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.live-bar .turn-warn { color: #ffb020; }
.live-bar .lag-warn { color: #ff6b6b; font-weight: 600; }

.voice-bar {
  color: #8fd;
  font-size: 11px;
  margin: 0 6px;
  white-space: nowrap;
  max-width: 28vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
.voice-bar:empty { display: none; }
.voice-bar .voice-muted { color: #666; }
.voice-bar .voice-live { color: #6f6; font-weight: 600; }

.voice-panel {
  margin: 12px 0 4px;
  padding: 12px;
  border-radius: 10px;
  background: #151515;
  border: 1px solid #2a2a2a;
}
.voice-panel-title {
  font-size: 13px;
  color: #aaa;
  margin-bottom: 8px;
}
.voice-row {
  display: flex;
  gap: 8px;
}
.voice-btn {
  flex: 1;
  min-width: 0;
  padding: 9px 8px;
  font-size: 13px;
  background: #2a2a2a;
  color: #ddd;
  border: 1px solid #3a3a3a;
}
.voice-btn.on {
  background: #1a3a2a;
  border-color: #3a6a4a;
  color: #9f9;
}
.voice-btn:disabled {
  opacity: .45;
  cursor: not-allowed;
}
.voice-hint { margin-top: 8px; margin-bottom: 0; font-size: 11px; }
.voice-vol-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 4px 2px 8px;
}
.voice-vol-label {
  font-size: 12px;
  color: #888;
}
.game-menu-item.player-voice-only:disabled {
  opacity: .5;
  cursor: not-allowed;
}

.guide-mask {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(0,0,0,.72);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.guide-card {
  width: min(92vw, 360px); background: #1a1a1a; border: 1px solid #333;
  border-radius: 14px; padding: 20px 18px 16px;
  box-shadow: 0 12px 36px rgba(0,0,0,.55);
}
.guide-title { color: #ffd000; font-size: 17px; text-align: center; margin-bottom: 12px; }
.guide-list {
  margin: 0 0 16px; padding-left: 1.2em; color: #ddd; font-size: 14px; line-height: 1.7;
}
.guide-list strong { color: #ffd000; font-weight: 600; }
.guide-card button { width: 100%; padding: 10px; font-size: 15px; }

#btnForceTop { background: #3a2a00; border-color: #886600; color: #ffd000; }
#btnForceTop:hover { background: #4a3800; }

body.spectator #vp,
body.spectator #kbHint { display: none !important; }

/* 触控：透明玻璃键叠在画面上（参考手游，略离边缘方便大拇指） */
@media (pointer: coarse), (hover: none) {
  :root {
    --pad-opacity: 0.28;
    --pad-stick-x: 7vw;
    --pad-stick-y: 10vh;
    --pad-a-x: 7vw;
    --pad-a-y: 22vh;
    --pad-b-x: 7vw;
    --pad-b-y: 10vh;
    --pad-meta-x: 7vw;
    --pad-meta-y: 6vh;
    --pad-stick-size: 128px;
    --pad-stick-scale: 1;
    --pad-btn-scale: 1;
    --pad-meta-scale: 1;
  }
  #kbHint { display: none; }
  #vp,
  body.touch-play #vp {
    position: absolute; inset: 0; max-width: none; padding: 0;
    pointer-events: none; z-index: 2; flex: none; display: block !important;
  }
  #stage { max-width: none; border-radius: 0; }
  #topbar { max-width: none; background: linear-gradient(rgba(0,0,0,.55), transparent); }

  .dpad.stick,
  .dpad.cross {
    position: absolute;
    left: calc(var(--pad-stick-x, 7vw) + env(safe-area-inset-left, 0px));
    bottom: calc(var(--pad-stick-y, 10vh) + env(safe-area-inset-bottom, 0px));
    width: calc(var(--pad-stick-size, 128px) * var(--pad-stick-scale, 1));
    height: calc(var(--pad-stick-size, 128px) * var(--pad-stick-scale, 1));
    pointer-events: auto;
    opacity: var(--pad-opacity, .28);
  }
  .dpad.stick {
    padding: 10px;
    box-sizing: content-box;
  }
  .dpad.cross .cross-btn {
    width: 44px; height: 44px; font-size: 17px;
    opacity: var(--pad-opacity, .28);
  }
  .stick-knob {
    width: 36px; height: 36px; margin: -18px 0 0 -18px;
  }
  .face-a,
  .face-b {
    display: block;
    position: absolute;
    pointer-events: auto;
    z-index: 5;
  }
  .face-a {
    right: calc(var(--pad-a-x, 7vw) + env(safe-area-inset-right, 0px));
    bottom: calc(var(--pad-a-y, 22vh) + env(safe-area-inset-bottom, 0px));
  }
  .face-b {
    right: calc(var(--pad-b-x, 7vw) + env(safe-area-inset-right, 0px));
    bottom: calc(var(--pad-b-y, 10vh) + env(safe-area-inset-bottom, 0px));
  }
  #vp .face-meta {
    position: absolute;
    top: calc(var(--pad-meta-y, 6vh) + env(safe-area-inset-top, 0px));
    right: calc(var(--pad-meta-x, 7vw) + env(safe-area-inset-right, 0px));
    bottom: auto;
    left: auto;
    display: flex;
    gap: 8px;
    padding: 0;
    z-index: 6;
    pointer-events: auto;
  }
  #vp .face-meta .vbtn.meta {
    width: calc(46px * var(--pad-meta-scale, 1));
    height: calc(30px * var(--pad-meta-scale, 1));
    font-size: calc(10px * var(--pad-meta-scale, 1));
    opacity: calc(var(--pad-opacity, .28) + 0.18);
  }
  #vp.lefty .face-meta {
    right: auto;
    left: calc(var(--pad-meta-x, 7vw) + env(safe-area-inset-left, 0px));
  }
  #vp.lefty .dpad.stick,
  #vp.lefty .dpad.cross {
    left: auto;
    right: calc(var(--pad-stick-x, 7vw) + env(safe-area-inset-right, 0px));
  }
  #vp.lefty .face-a {
    right: auto;
    left: calc(var(--pad-a-x, 7vw) + env(safe-area-inset-left, 0px));
  }
  #vp.lefty .face-b {
    right: auto;
    left: calc(var(--pad-b-x, 7vw) + env(safe-area-inset-left, 0px));
  }

  .vbtn {
    background: rgba(255,255,255,.06);
    border: 1px solid rgba(255,255,255,.18);
    color: rgba(255,255,255,.72);
    opacity: var(--pad-opacity, .28);
    box-shadow: none;
    -webkit-backdrop-filter: blur(1.5px);
    backdrop-filter: blur(1.5px);
  }
  .vbtn:active, .vbtn.pressed {
    background: rgba(255,208,0,.38);
    color: #fff;
    opacity: .82;
    border-color: rgba(255,208,0,.5);
  }
  .face-a.vbtn small,
  .face-b.vbtn small { color: rgba(255,255,255,.5); font-size: calc(9px * var(--pad-btn-scale, 1)); }
  .stick-ring {
    background:
      radial-gradient(circle at center, rgba(255,255,255,.04) 0 28%, transparent 29%),
      rgba(255,255,255,.04);
  }
  .hand-toggle {
    bottom: 1.6vh; padding: 4px 10px; font-size: 12px;
    background: rgba(0,0,0,.28); opacity: .55; pointer-events: auto;
  }
  .vol-box {
    left: 8px; top: 46px;
    opacity: .9;
  }
  .pad-opacity { width: 84px; }
}

/* 拖动调整按键位置 */
.pad-layout-edit-bar {
  position: absolute;
  left: 50%;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 50001;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: rgba(10,10,10,.88);
  border: 1px solid #555;
  border-radius: 12px;
  pointer-events: auto;
  max-width: min(92vw, 360px);
}
.pad-layout-edit-hint {
  margin: 0;
  font-size: 13px;
  color: #ddd;
  text-align: center;
}
.pad-layout-edit-btns {
  display: flex;
  gap: 8px;
  width: 100%;
}
.pad-layout-edit-btns .menu-btn {
  flex: 1;
  padding: 9px 10px;
  font-size: 14px;
}
body.pad-layout-edit #vp {
  display: block !important;
  pointer-events: auto !important;
  z-index: 50000 !important;
}
body.pad-layout-edit .dpad.stick,
body.pad-layout-edit .dpad.cross,
body.pad-layout-edit .face-a,
body.pad-layout-edit .face-b,
body.pad-layout-edit .face-meta {
  opacity: 0.62 !important;
  outline: 2px dashed rgba(255,208,0,.55);
  outline-offset: 5px;
  touch-action: none;
  cursor: grab;
}
body.pad-layout-edit .dpad.stick.pad-dragging,
body.pad-layout-edit .dpad.cross.pad-dragging,
body.pad-layout-edit .face-a.pad-dragging,
body.pad-layout-edit .face-b.pad-dragging,
body.pad-layout-edit .face-meta.pad-dragging {
  opacity: 0.85 !important;
  cursor: grabbing;
  outline-color: #ffd000;
}

@media (pointer: coarse) and (min-width: 768px) {
  :root { --pad-stick-size: 148px; }
  .dpad.stick,
  .dpad.cross { width: calc(var(--pad-stick-size) * var(--pad-stick-scale, 1)); height: calc(var(--pad-stick-size) * var(--pad-stick-scale, 1)); }
  .dpad.cross .cross-btn { width: 50px; height: 50px; }
  .stick-knob { width: 46px; height: 46px; margin: -23px 0 0 -23px; }
  .face-a.vbtn.round { width: calc(78px * var(--pad-btn-scale, 1)); height: calc(78px * var(--pad-btn-scale, 1)); }
  .face-a.vbtn.round.big { width: calc(90px * var(--pad-btn-scale, 1)); height: calc(90px * var(--pad-btn-scale, 1)); }
  .face-b.vbtn.round { width: calc(78px * var(--pad-btn-scale, 1)); height: calc(78px * var(--pad-btn-scale, 1)); }
  .face-meta { gap: 12px; }
  .vol-box { top: 54px; }
  .pad-opacity { width: 100px; }
}

@media (orientation: portrait) and (pointer: coarse) {
  #game:not(.stream-hide-tip)::after {
    content: none;
  }
}

/* 竖屏遮罩：强制提示横屏（触控设备） */
#rotateMask {
  display: none;
  position: fixed; inset: 0; z-index: 20000;
  background: #0a0a0a;
  color: #eee;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
}
#rotateMask .rotate-ico {
  width: 72px; height: 72px;
  border: 3px solid #ffd000;
  border-radius: 12px;
  position: relative;
  animation: nes-rotate-hint 1.6s ease-in-out infinite;
}
#rotateMask .rotate-ico::after {
  content: "";
  position: absolute; left: 50%; top: 50%;
  width: 18px; height: 18px;
  margin: -9px 0 0 -9px;
  border-right: 3px solid #ffd000;
  border-bottom: 3px solid #ffd000;
  transform: rotate(-45deg);
}
#rotateMask .rotate-title { color: #ffd000; font-size: 20px; font-weight: 600; }
#rotateMask .rotate-sub { color: #aaa; font-size: 14px; line-height: 1.5; max-width: 280px; }
@keyframes nes-rotate-hint {
  0%, 100% { transform: rotate(0deg); }
  40% { transform: rotate(90deg); }
  60% { transform: rotate(90deg); }
}
/* 竖屏只盖提示层，绝不隐藏游戏区 */
body.in-game.need-landscape #rotateMask { display: flex; z-index: 25000; }

/* 对局中顶栏必须压在舞台之上（否则绝对定位的 #stage 会盖住字，看起来纯黑无字） */
body.in-game #topbar {
  position: absolute !important;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30 !important;
  opacity: 1 !important;
  color: #eee !important;
  pointer-events: none;
  background: linear-gradient(rgba(0,0,0,.72), transparent);
  text-shadow: 0 1px 2px rgba(0,0,0,.9);
}
body.in-game #topbar .topbtns,
body.in-game #topbar button {
  pointer-events: auto;
}

/* PWA：用 flex 占满，禁止把 stage 强行 inset:0 盖死顶栏；也不用 !important 抢 display:none */
body.pwa-standalone.in-game #game {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  display: flex;
  flex-direction: column;
  background: #000;
  box-sizing: border-box;
}
body.pwa-standalone.in-game.touch-play #stage {
  /* 仍可绝对铺满，但顶栏 z-index:30 保证可见 */
  z-index: 1;
}
body.pwa-standalone.in-game #vp {
  z-index: 20;
}

@media (max-height: 480px) and (pointer: coarse) {
  #lobby.panel { padding: 12px 16px; }
  #lobby h1 { font-size: 18px; margin-bottom: 4px; }
  .row { margin-bottom: 8px; }
  .btns { margin: 10px 0 4px; }
}

/* iPhone/iPad Safari：系统不允许网页真全屏，用沉浸模式尽量占满可视区 */
body.ios-immersive {
  overflow: hidden;
  overscroll-behavior: none;
  background: #000;
}
body.ios-immersive #lobby { display: none !important; }
body.ios-immersive #game {
  display: flex !important;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  z-index: 9999;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
body.ios-immersive #topbar {
  position: absolute;
  left: 0; right: 0; top: 0;
  background: linear-gradient(rgba(0,0,0,.65), transparent);
  opacity: 1;
  z-index: 30;
  transition: opacity .2s;
}
body.ios-immersive #topbar:hover,
body.ios-immersive #topbar:focus-within,
body.ios-immersive #topbar.is-show {
  opacity: 1;
}
body.ios-immersive #stage {
  position: absolute;
  inset: 0;
}
.ios-fs-tip {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%);
  z-index: 10000; max-width: 92vw;
  background: rgba(20,20,20,.92); border: 1px solid #444; border-radius: 12px;
  padding: 10px 14px; color: #eee; font-size: 13px; text-align: center;
  box-shadow: 0 8px 24px rgba(0,0,0,.45);
}
.ios-fs-tip button {
  margin-top: 8px; width: 100%; padding: 8px; font-size: 13px;
}

/* 微信 / 加主屏兼容提示 */
.compat-mask {
  position: fixed; inset: 0; z-index: 50000;
  background: rgba(0,0,0,.78);
  display: flex; align-items: flex-start; justify-content: center;
  padding: max(48px, env(safe-area-inset-top)) 16px 24px;
  box-sizing: border-box;
}
.compat-card {
  width: min(360px, 94vw);
  background: #1b1b1b;
  border: 1px solid #3a3a3a;
  border-radius: 14px;
  padding: 18px 16px 14px;
  color: #eee;
  position: relative;
  box-shadow: 0 12px 40px rgba(0,0,0,.55);
}
.compat-title {
  color: #ffd000; font-size: 17px; font-weight: 700; margin-bottom: 8px; text-align: center;
}
.compat-desc {
  color: #ccc; font-size: 14px; line-height: 1.55; text-align: center; margin-bottom: 14px;
}
.compat-muted {
  display: block;
  margin-top: 8px;
  font-size: 12px;
  color: #888;
  line-height: 1.4;
}
.compat-btn {
  width: 100%; padding: 11px; font-size: 14px;
  background: #333; color: #eee; border: 1px solid #444; border-radius: 10px;
}
.wechat-card { margin-top: 8px; }
.wechat-arrow {
  position: absolute; right: 10px; top: -36px;
  font-size: 28px; color: #ffd000;
  animation: nes-wechat-arrow 1.2s ease-in-out infinite;
}
@keyframes nes-wechat-arrow {
  0%, 100% { transform: translate(0, 0); opacity: 1; }
  50% { transform: translate(4px, -6px); opacity: .7; }
}

.a2hs-bar {
  display: flex; align-items: center; gap: 8px;
  margin: 0 0 12px;
  padding: 10px 12px;
  background: rgba(255, 208, 0, .08);
  border: 1px solid rgba(255, 208, 0, .28);
  border-radius: 10px;
  flex-wrap: wrap;
}
.a2hs-text {
  flex: 1 1 140px;
  font-size: 12px;
  color: #ddd;
  line-height: 1.4;
  min-width: 0;
}
.a2hs-text strong { color: #ffd000; }
.a2hs-btn {
  flex: 0 0 auto;
  padding: 6px 12px;
  font-size: 12px;
  background: #ffd000;
  color: #111;
  border: none;
  border-radius: 8px;
  font-weight: 600;
}
.a2hs-btn-ghost {
  background: transparent;
  color: #aaa;
  border: 1px solid #444;
  font-weight: 500;
}

.rejoin-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 10px 0 12px;
  padding: 12px 14px;
  background: rgba(255, 80, 80, .1);
  border: 1px solid rgba(255, 100, 100, .35);
  border-radius: 10px;
  flex-wrap: wrap;
}
.rejoin-text {
  flex: 1 1 160px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.rejoin-text strong {
  color: #ffb0b0;
  font-size: 14px;
}
.rejoin-text span {
  color: #bbb;
  font-size: 12px;
  line-height: 1.4;
}
.rejoin-btn {
  flex: 0 0 auto;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 700;
  background: #ffd000;
  color: #111;
  border: none;
  border-radius: 8px;
}
.rejoin-bar-float {
  position: fixed;
  left: 50%;
  bottom: max(72px, calc(env(safe-area-inset-bottom, 0px) + 56px));
  transform: translateX(-50%);
  z-index: 45000;
  width: min(92vw, 420px);
  margin: 0;
  box-shadow: 0 10px 32px rgba(0,0,0,.5);
}
body.in-game .rejoin-bar-float {
  bottom: max(16px, env(safe-area-inset-bottom, 0px));
}

/* ---------- 管理端密钥门禁 / 双端入口 ---------- */
.host-gate {
  position: fixed;
  inset: 0;
  z-index: 100000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: #0a0a0f;
}
.host-gate-card {
  width: min(100%, 380px);
  padding: 28px 22px;
  background: #151520;
  border: 1px solid #333;
  border-radius: 16px;
  text-align: center;
}
.host-gate-title { font-size: 22px; color: #ffd000; margin: 0 0 8px; }
.host-gate-sub { font-size: 14px; color: #999; margin: 0 0 20px; line-height: 1.5; }
.host-gate-form { text-align: left; }
.host-gate-form label { display: block; font-size: 13px; color: #aaa; margin-bottom: 6px; }
.host-gate-form input[type="password"] {
  width: 100%;
  box-sizing: border-box;
  min-height: 48px;
  padding: 12px 14px;
  font-size: 16px;
  border-radius: 10px;
  border: 1px solid #444;
  background: #0d0d12;
  color: #fff;
  margin-bottom: 12px;
}
.host-gate-remember {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #888;
  margin-bottom: 12px;
  cursor: pointer;
}
.host-gate-err { min-height: 20px; font-size: 13px; color: #f66; margin: 0 0 8px; }
.host-gate-form button[type="submit"],
#hostGateBtn {
  width: 100%;
  min-height: 48px;
  font-size: 16px;
  font-weight: 700;
  border: none;
  border-radius: 10px;
  background: #ffd000;
  color: #111;
  cursor: pointer;
}
.host-gate-foot { margin-top: 16px; font-size: 13px; }
.host-gate-foot a { color: #8ef; }

.host-info-box {
  margin: 12px 0;
  padding: 14px;
  background: #1a1a24;
  border: 1px solid #335;
  border-radius: 12px;
  text-align: center;
}
.host-info-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 6px 0;
}
.host-info-label { font-size: 13px; color: #888; min-width: 56px; text-align: right; }
.host-info-val { font-size: 28px; color: #ffd000; letter-spacing: 2px; }
.host-code-val { font-size: 32px; }

.host-status-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  margin: 10px 0;
}
.host-spectate-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: #ccc;
  cursor: pointer;
  min-height: 44px;
  padding: 0 8px;
}

.app-host .room-actions button { min-height: 44px; }
.app-host #hostTools button { min-height: 44px; }
.app-host #hostBtns button { min-height: 48px; font-size: 16px; }

.host-qr-box {
  margin: 12px auto;
  width: fit-content;
  padding: 10px;
  background: #fff;
  border-radius: 8px;
}
.host-share-qr { text-align: center; margin-top: 8px; }
.entry-landing-btns { flex-direction: column; gap: 12px; }
.entry-link {
  display: block;
  padding: 14px 20px;
  border-radius: 10px;
  text-decoration: none;
  font-weight: 600;
  font-size: 16px;
}
.entry-link-play { background: #ffd000; color: #111; }
.entry-link-host { background: #222; color: #ffd000; border: 1px solid #665500; }

.app-player #hostKeyRow,
.app-player #btnCreate,
.app-player .host-only { display: none !important; }

@media (max-width: 768px) {
  .app-host #lobby.panel { padding: 12px 14px; }
  .app-host .host-tools { grid-template-columns: 1fr 1fr; }
  .host-info-val { font-size: 24px; }
}
