
  * { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
  html {
    margin: 0; width: 100%; height: 100%; height: 100dvh;
    overflow: hidden; overscroll-behavior: none;
    /* manipulation = 允许菜单滚动，但禁掉双击放大；页面本身 overflow:hidden 也滚不动 */
    touch-action: manipulation;
    -webkit-text-size-adjust: 100%; text-size-adjust: 100%;
    background: #0a0e1a;
  }
  body {
    margin: 0; position: fixed; inset: 0; width: 100%; height: 100%;
    overflow: hidden; overscroll-behavior: none; touch-action: manipulation;
    -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
    background: radial-gradient(circle at 50% 0%, #1b2544 0%, #0a0e1a 65%);
    font-family: "Microsoft YaHei", "PingFang SC", system-ui, -apple-system, sans-serif;
    color: #e8f0ff;
  }
  #app { position: fixed; top: 0; left: 0; width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
  #stage { position: relative; width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; overflow: hidden; }
  /* 画布铺满整个屏幕：场景按比例居中，四周用同一套场景背景补满 */
  canvas { display: block; width: 100%; height: 100%; touch-action: none; }

  .overlay {
    position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
    background: rgba(6, 10, 22, .82); backdrop-filter: blur(6px); z-index: 20;
  }
  .overlay.hide { display: none; }
  .panel {
    width: min(560px, 92vw); background: linear-gradient(180deg, rgba(30, 41, 72, .96), rgba(16, 22, 40, .98));
    border: 1px solid rgba(120, 170, 255, .25); border-radius: 18px; padding: 26px 28px 22px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .55), inset 0 1px 0 rgba(255, 255, 255, .07);
    max-height: 94dvh; overflow-y: auto; overscroll-behavior: contain;
    touch-action: pan-y; -webkit-overflow-scrolling: touch;
  }
  h1 { margin: 0 0 4px; font-size: 30px; letter-spacing: 2px; text-align: center;
       background: linear-gradient(90deg, #7fe3ff, #b9a0ff 55%, #ffb37f);
       -webkit-background-clip: text; background-clip: text; color: transparent; }
  .sub { text-align: center; color: #8ea6cc; font-size: 13px; margin-bottom: 18px; }
  .diffrow { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 12px; }
  .moderow { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
  .modepick {
    padding: 12px 4px; border-radius: 12px; text-align: center; cursor: pointer; font-size: 14px; font-weight: 700;
    border: 1px solid rgba(130, 170, 235, .3); background: rgba(255, 255, 255, .04); color: #cbdcf7; transition: .15s;
  }
  .modepick:hover { background: rgba(255, 255, 255, .09); }
  .modepick.sel { border-color: #7fe3ff; background: linear-gradient(180deg, rgba(70, 190, 255, .32), rgba(70, 150, 255, .12)); color: #fff;
                  box-shadow: 0 0 0 1px rgba(127, 227, 255, .5), 0 6px 20px rgba(60, 160, 255, .25); }
  #diffWrap.off { opacity: .35; pointer-events: none; }
  .diffpick {
    padding: 11px 4px; border-radius: 11px; text-align: center; cursor: pointer; font-size: 15px; font-weight: 700;
    border: 1px solid rgba(130, 170, 235, .3); background: rgba(255, 255, 255, .04); color: #cbdcf7;
    transition: .15s;
  }
  .diffpick:hover { background: rgba(255, 255, 255, .09); }
  .diffpick.sel { border-color: #6cc6ff; background: linear-gradient(180deg, rgba(70, 150, 255, .35), rgba(70, 150, 255, .12)); color: #fff; box-shadow: 0 0 0 1px rgba(108, 198, 255, .5), 0 6px 20px rgba(60, 130, 255, .25); }
  .diffpick[data-d="hell"].sel { border-color: #ff6b6b; background: linear-gradient(180deg, rgba(255, 90, 90, .35), rgba(255, 90, 90, .12)); box-shadow: 0 0 0 1px rgba(255, 107, 107, .5), 0 6px 20px rgba(255, 70, 70, .25); }
  #diffNote { min-height: 38px; font-size: 13px; line-height: 1.6; color: #9fb6d9; background: rgba(0, 0, 0, .22);
              border-left: 3px solid rgba(110, 190, 255, .6); border-radius: 6px; padding: 8px 12px; margin-bottom: 16px; }
  .keys { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13px; color: #a9bede; margin-bottom: 18px; }
  .keys b { color: #e9f2ff; background: rgba(255, 255, 255, .09); border: 1px solid rgba(255, 255, 255, .16);
            border-radius: 6px; padding: 2px 8px; font-weight: 600; text-align: center; }
  button.primary {
    width: 100%; padding: 14px; font-size: 18px; font-weight: 800; letter-spacing: 3px; cursor: pointer;
    color: #051022; border: 0; border-radius: 12px;
    background: linear-gradient(180deg, #8fe0ff, #4aa8ff); box-shadow: 0 10px 26px rgba(74, 168, 255, .35);
  }
  button.primary:hover { filter: brightness(1.08); }
  button.ghost {
    width: 100%; padding: 11px; margin-top: 10px; font-size: 15px; cursor: pointer; color: #cfdcf2;
    background: rgba(255, 255, 255, .07); border: 1px solid rgba(255, 255, 255, .16); border-radius: 10px;
  }
  button.ghost:hover { background: rgba(255, 255, 255, .13); }
  #overTitle { font-size: 34px; font-weight: 900; text-align: center; letter-spacing: 6px; margin-bottom: 6px; }
  #overScore { text-align: center; font-size: 40px; font-weight: 900; color: #fff; letter-spacing: 4px; }
  #overInfo { text-align: center; font-size: 13px; color: #9fb6d9; margin: 10px 0 18px; }
  #overInfo b { color: #d8e6ff; }

  /* 触屏按键层：铺满屏幕，但避开刘海/圆角/底部手势条 */
  #touch {
    position: absolute; inset: 0; pointer-events: none; z-index: 10;
    /* 支持 env() 的浏览器再按刘海/手势条收进来（不支持时保留上面的 inset:0） */
    top: env(safe-area-inset-top, 0px); right: env(safe-area-inset-right, 0px);
    bottom: env(safe-area-inset-bottom, 0px); left: env(safe-area-inset-left, 0px);
  }
  #touch.hide { display: none; }
  .tbtn {
    position: absolute; bottom: 2vmin; width: 12vmin; height: 12vmin; min-width: 46px; min-height: 46px;
    max-width: 92px; max-height: 92px; border-radius: 50%;
    background: rgba(255, 255, 255, .10); border: 1px solid rgba(255, 255, 255, .25);
    color: #dce9ff; font-size: 4vmin; font-weight: 700; display: flex; align-items: center; justify-content: center;
    pointer-events: auto; backdrop-filter: blur(3px); touch-action: none; user-select: none;
  }
  .tbtn.on { background: rgba(110, 190, 255, .45); }
  /* 手机端：左下角是左右移动的两个箭头按钮（原来是一个摇杆） */
  .tbtn[data-k="left"]  { display: flex; left: 2vmin; }
  .tbtn[data-k="right"] { display: flex; left: 16vmin; }
  /* 跳跃键放到右手区：杀球键正上方 */
  .tbtn[data-k="jump"] {
    display: flex; right: 1.5vmin; bottom: 17vmin;
    width: 11vmin; height: 11vmin; max-width: 84px; max-height: 84px; font-size: 3.6vmin;
  }
  /* 动作键：屏幕上从左到右 吊球 高远 挥拍（挥拍最贴右手拇指） */
  .tbtn[data-k="drop"]  { right: 33vmin; }
  /* 虚拟摇杆已停用（DOM 保留，脚本里还有引用，不影响布局） */
  .stick { display: none; }
  .stick .knob {
    position: absolute; left: 50%; top: 50%; width: 40%; height: 40%; margin: -20% 0 0 -20%;
    border-radius: 50%; background: rgba(150,205,255,.35); border: 1px solid rgba(200,230,255,.55);
  }
  #stick1 { left: 2vmin; }
  #stick2 { right: 2vmin; }
  /* 手机端系统键：暂停 / 音效 / 返回菜单（小尺寸，右上角） */
  #sysbtns { position: absolute; right: 1.5vmin; top: 1.5vmin; display: flex; gap: 1.4vmin; }
  .sbtn {
    width: 7.5vmin; height: 7.5vmin; min-width: 28px; min-height: 28px; max-width: 42px; max-height: 42px;
    border-radius: 9px; background: rgba(255,255,255,.10); border: 1px solid rgba(255,255,255,.22);
    color: #dce9ff; font-size: 3.4vmin; line-height: 1; display: flex; align-items: center; justify-content: center;
    pointer-events: auto; touch-action: none; user-select: none; backdrop-filter: blur(3px);
  }
  .sbtn:active { background: rgba(110,190,255,.45); }
  .tbtn[data-k="high"]  { right: 17.5vmin; }
  .tbtn[data-k="smash"] { right: 1.5vmin; width: 14vmin; height: 14vmin; max-width: 106px; max-height: 106px; font-size: 3.4vmin; }
  /* 挑球单独放在吊球上方一格，不挤占右手拇指的主操作区 */
  .tbtn[data-k="lift"]  { right: 33vmin; bottom: 15vmin; }
  /* 反手救球放在高远球上方一格，和挑球同一行 */
  .tbtn[data-k="backhand"] { right: 17.5vmin; bottom: 15vmin; }
  /* ---------- 双人模式的触屏布局：左右各一套、镜像排布 ---------- */
  .p2btn { display: none; }
  /* 单人/人机模式下，玩家2 的触屏键一律不显示（否则会被上面的 .tbtn[data-k] 规则复活） */
  #touch:not(.twoP) .p2btn { display: none; }
  /* 双人模式：两侧各显示移动箭头 + 跳跃 + 动作键 */
  #touch.twoP .p2btn[data-k="high"],
  #touch.twoP .p2btn[data-k="smash"],
  #touch.twoP .p2btn[data-k="lift"],
  #touch.twoP .p2btn[data-k="drop"],
  #touch.twoP .p2btn[data-k="left"],
  #touch.twoP .p2btn[data-k="right"],
  #touch.twoP .p2btn[data-k="jump"] { display: flex; }
  /* 观战模式：所有操作键（含摇杆）都不显示，只保留右上角系统键 */
  #touch.spectate .tbtn, #touch.spectate .stick { display: none; }
  /* 背身反手只在单人/人机模式给玩家1一个触屏键；双人模式用键盘 J */
  #touch.twoP .tbtn[data-k="backhand"] { display: none; }
  #touch.twoP .tbtn { width: 10.5vmin; height: 10.5vmin; min-width: 38px; min-height: 38px; font-size: 3.2vmin; transform: none; }
  #touch.twoP .tbtn[data-k="smash"] { width: 12vmin; height: 12vmin; min-width: 44px; min-height: 44px; font-size: 2.9vmin; }
  /* 玩家1（左侧） */
  #touch.twoP .tbtn[data-side="1"] { left: auto; right: auto; }
  #touch.twoP .tbtn[data-side="1"][data-k="left"]  { left: 1vmin; }
  #touch.twoP .tbtn[data-side="1"][data-k="right"] { left: 13vmin; }
  #touch.twoP .tbtn[data-side="1"][data-k="jump"]  { left: 30vmin; bottom: 13.5vmin; }
  #touch.twoP .tbtn[data-side="1"][data-k="smash"] { left: 30vmin; }
  #touch.twoP .tbtn[data-side="1"][data-k="high"]  { left: 44vmin; }
  #touch.twoP .tbtn[data-side="1"][data-k="drop"]  { left: 58vmin; }
  #touch.twoP .tbtn[data-side="1"][data-k="lift"]  { left: 58vmin; bottom: 13.5vmin; }
  /* 玩家2（右侧）：与玩家1 完全镜像 —— 同名键到各自屏幕边缘的距离相同 */
  #touch.twoP .tbtn[data-side="2"] { right: auto; left: auto; }
  /* 方向键特殊处理：不论哪一侧，屏幕上从左到右都要是 "◀ ▶"（符合直觉） */
  #touch.twoP .tbtn[data-side="2"][data-k="left"]  { right: 13vmin; }
  #touch.twoP .tbtn[data-side="2"][data-k="right"] { right: 1vmin; }
  #touch.twoP .tbtn[data-side="2"][data-k="jump"]  { right: 30vmin; bottom: 13.5vmin; }
  #touch.twoP .tbtn[data-side="2"][data-k="smash"] { right: 30vmin; }
  #touch.twoP .tbtn[data-side="2"][data-k="high"]  { right: 44vmin; }
  #touch.twoP .tbtn[data-side="2"][data-k="drop"]  { right: 58vmin; }
  #touch.twoP .tbtn[data-side="2"][data-k="lift"]  { right: 58vmin; bottom: 13.5vmin; }
  /* 小屏 / 矮屏：整体压缩，保证菜单一屏装得下（不改变桌面观感） */
  @media (max-height: 780px), (max-width: 560px), (orientation: portrait) {
    .panel { padding: 14px 16px 12px; border-radius: 14px; }
    h1 { font-size: 22px; margin-bottom: 2px; }
    .sub { font-size: 11px; margin-bottom: 10px; }
    .modepick { padding: 9px 3px; font-size: 12px; }
    .diffpick { padding: 8px 3px; font-size: 13px; }
    .moderow, .diffrow { gap: 6px; margin-bottom: 8px; }
    #diffNote { font-size: 11px; line-height: 1.45; padding: 6px 9px; min-height: 0; margin-bottom: 10px; }
    .keys { font-size: 11px; gap: 3px 8px; margin-bottom: 10px; }
    .keys b { padding: 1px 6px; }
    button.primary { padding: 11px; font-size: 16px; letter-spacing: 2px; }
    #overTitle { font-size: 26px; letter-spacing: 4px; }
    #overScore { font-size: 32px; }
  }
  /* 竖屏提示：横屏才是 1000x560 的主场 */
  #rotate { display: none; position: absolute; inset: 0; z-index: 30; align-items: center; justify-content: center;
            flex-direction: column; gap: 3vmin;
            background: rgba(6,10,22,.9); color: #cfe4ff; font-size: 5vmin; font-weight: 700; text-align: center; padding: 8vw; }
  #rotate .sub2 { font-size: 3.2vmin; font-weight: 400; color: #8ea6cc; }
  @media (orientation: portrait) and (pointer: coarse) { #rotate { display: flex; } }

  /* ---------- 观战倍速（只在「观战 · 互打」里出现） ---------- */
  #speed {
    position: absolute; left: 50%; bottom: max(8px, env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%); z-index: 12;
    display: flex; align-items: center; gap: 8px; padding: 5px 10px;
    border-radius: 999px; pointer-events: auto;
    background: rgba(8, 14, 30, .72); border: 1px solid rgba(140, 180, 255, .28);
    box-shadow: 0 6px 20px rgba(0, 0, 0, .4); backdrop-filter: blur(4px);
    font-size: 12px; color: #cfe0ff; user-select: none; -webkit-user-select: none;
    touch-action: manipulation;
  }
  #speed.hide { display: none; }
  #speed .spTitle { opacity: .72; letter-spacing: 1px; }
  #speed .spBtn {
    width: 22px; height: 22px; padding: 0; border-radius: 50%; line-height: 1;
    display: flex; align-items: center; justify-content: center;
    background: rgba(255, 255, 255, .10); border: 1px solid rgba(160, 200, 255, .30);
    color: #dce9ff; font-size: 15px; cursor: pointer; touch-action: manipulation;
  }
  #speed .spBtn:active { background: rgba(110, 190, 255, .45); }
  #spRange { width: 132px; height: 18px; margin: 0; accent-color: #5bc8ff; touch-action: none; }
  #spVal { min-width: 40px; text-align: right; font-weight: 700; color: #9fe0ff; font-variant-numeric: tabular-nums; }
  @media (max-width: 560px), (max-height: 420px) {
    #speed { gap: 6px; padding: 4px 8px; font-size: 11px; }
    #spRange { width: 92px; }
    #spVal { min-width: 36px; }
  }
