/* =====================================================================
   网页台球 · 8 球 —— 样式表
   浅色主题，移动端也可用
   ===================================================================== */
:root {
  --bg1: #e8f0f7;
  --bg2: #f7fafc;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e2e8f0;
  --primary: #2f7cf6;
  --primary-dark: #1d5fd8;
  --accent: #f59e0b;
  --shadow-lg: 0 18px 42px rgba(31, 41, 55, 0.18);
  --shadow-sm: 0 6px 18px rgba(31, 41, 55, 0.12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: "Helvetica Neue", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: linear-gradient(160deg, var(--bg1), var(--bg2));
  color: var(--panel);
  min-height: 100vh;
}

#app { max-width: 1240px; margin: 0 auto; padding: 14px 16px 30px; }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  background: var(--card);
  border-radius: 14px;
  padding: 10px 14px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 14px;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { font-size: 30px; line-height: 1; }
.brand-text h1 { margin: 0; font-size: 18px; color: var(--panel); }
.brand-sub { font-size: 12px; color: var(--muted); }

.mode-switch { margin-left: auto; display: flex; gap: 6px; background: #eef2f7; border-radius: 999px; padding: 4px; }
.mode-switch .chip {
  border: none; background: transparent; color: var(--muted);
  padding: 6px 14px; border-radius: 999px; cursor: pointer; font-size: 13px; transition: all 0.2s;
}
.mode-switch .chip.active { background: var(--card); color: var(--text); box-shadow: var(--shadow-sm); font-weight: 600; }

.top-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* AI 难度切换（vs AI 时生效） */
.diff-switch {
  display: flex; gap: 4px; background: #eef2f7;
  border-radius: 999px; padding: 3px;
}
.diff-switch .chip {
  border: none; background: transparent; color: var(--muted);
  padding: 5px 12px; border-radius: 999px; cursor: pointer;
  font-size: 12.5px; transition: all 0.2s;
}
.diff-switch .chip.active {
  background: var(--accent); color: #fff;
  box-shadow: 0 3px 8px rgba(245, 158, 11, 0.35); font-weight: 700;
}

/* ---------- ⑥ 顶栏分组：主钮 + 折叠下拉（原按钮 ID/事件不变，仅收纳进菜单） ---------- */
.top-group { position: relative; display: inline-flex; }
.top-group .grp-btn { white-space: nowrap; }
.top-group .grp-btn.open { background: var(--accent); color: #fff; border-color: transparent; }
.top-dropdown {
  position: absolute; top: calc(100% + 8px); left: 0; z-index: 60;
  display: none; flex-direction: column; gap: 6px; min-width: 168px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
}
.top-dropdown.open { display: flex; }
.top-dropdown .btn { width: 100%; text-align: left; white-space: nowrap; }
/* ---------- ⑤ 沉浸态最小化浮动按钮组（JS 生成到 body，不依赖被隐藏的 .topbar） ---------- */
.imm-mini { display: none; }
body.immersed .imm-mini {
  display: flex; flex-direction: column; gap: 10px;
  position: fixed; top: 14px; right: 16px; z-index: 60;
}
.imm-mini .imm-keep {
  background: rgba(255, 255, 255, 0.12); color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  backdrop-filter: blur(4px);
  padding: 8px 14px; border-radius: 999px;
  font-size: 13px; font-weight: 600; cursor: pointer;
}
.imm-mini .imm-keep:active { transform: scale(0.97); }

/* ---------- 辅助线分档子面板（总开关开启时显示，5 类线独立勾选） ---------- */
.guide-panel {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  background: var(--card);
  border-radius: 12px;
  padding: 8px 12px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 14px;
}
.guide-panel.hidden { display: none; }
.guide-panel-title { font-size: 12px; font-weight: 700; color: var(--muted); margin-right: 4px; }
.guide-chip {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s;
}
.guide-chip:hover { background: #f1f5f9; }
.guide-chip.on {
  background: #e8f6ee;
  color: var(--primary);
  border-color: #98d8b5;
  font-weight: 800;
  box-shadow: 0 2px 6px rgba(47, 200, 120, 0.25);
}

/* ---------- 按钮 ---------- */
.btn {
  border: none; cursor: pointer; border-radius: 10px;
  padding: 8px 16px; font-size: 13px; font-weight: 600;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.2s;
}
.btn:active { transform: translateY(1px) scale(0.98); }
.btn.primary { background: var(--primary); color: #fff; box-shadow: 0 4px 12px rgba(47, 124, 246, 0.35); }
.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost { background: var(--card); color: var(--text); border: 1px solid var(--line); }
.btn.ghost:hover { background: #f1f5f9; }
.btn.big { font-size: 16px; padding: 14px 28px; width: 100%; text-align: center; border-radius: 12px; background: var(--card); color: var(--text); border: 1px solid var(--line); box-shadow: var(--shadow-sm); }
.btn.big:hover { background: #f1f5f9; }
.btn.big.accent { background: var(--accent); color: #fff; border-color: transparent; box-shadow: 0 8px 18px rgba(245, 158, 11, 0.4); }
.btn.big.accent:hover { filter: brightness(1.06); }
.btn.big.challenge { background: linear-gradient(135deg, #11998e, #38ef7d); color: #fff; border-color: transparent; box-shadow: 0 8px 18px rgba(17, 153, 142, 0.35); }
.btn.big.challenge:hover { filter: brightness(1.05); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
/* U1：结算 / 菜单主按钮交互态（仅加 hover/active，不改默认配色） */
.end-actions button,
.menu-card button {
  transition: all 0.15s ease;
}
.end-actions button:not(.accent):not(.challenge):hover,
.menu-card button:not(.accent):not(.challenge):hover {
  background: var(--primary-dark);
  box-shadow: var(--shadow-lg);
  transform: translateY(-1px);
}
.end-actions button:not(.accent):not(.challenge):active,
.menu-card button:not(.accent):not(.challenge):active {
  transform: translateY(1px);
  box-shadow: 0 2px 6px rgba(31, 41, 55, 0.28);
}
/* accent / challenge（渐变）按钮 hover 走 brightness，不覆盖底色 */
.end-actions button.accent:hover,
.menu-card button.accent:hover,
.end-actions button.challenge:hover,
.menu-card button.challenge:hover {
  filter: brightness(1.06);
  box-shadow: 0 10px 22px rgba(245, 158, 11, 0.42);
}
.end-actions button.accent:active,
.menu-card button.accent:active,
.end-actions button.challenge:active,
.menu-card button.challenge:active {
  transform: translateY(1px);
  box-shadow: 0 4px 10px rgba(245, 158, 11, 0.32);
}

/* ---------- 主布局 ---------- */
/* 使用 grid，右侧面板占据固定 300px，不重叠舞台 */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  grid-template-areas: "stage panel";
  gap: 14px;
  align-items: start; /* 关键：不让 stage 被拉伸到与 panel 等高 */
}
@media (max-width: 980px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "stage" "panel";
  }
  .panel { flex-direction: row; flex-wrap: wrap; }
  .score-card { flex: 1 1 220px; }
}

.stage {
  position: relative;
  grid-area: stage;
  min-width: 0;
  /* 关键：宽高比 2:1 与球台比例一致，由 padding-bottom 撑开高度 */
  aspect-ratio: 2 / 1;   /* 现代浏览器支持；fallback 见下 */
  width: 100%;
  height: auto;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  background: #dbe6f2; /* canvas 加载前的占位底色 */
}
/* 兼容老浏览器：用 padding-bottom 实现 2:1 比例盒 */
@supports not (aspect-ratio: 2 / 1) {
  .stage { position: relative; }
  .stage::before {
    content: "";
    display: block;
    padding-bottom: 50%;
  }
  .stage > canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
}
.stage canvas {
  display: block;
  width: 100%;
  height: 100%;     /* 填满整个 stage，不再依赖 2:1 ratio */
  touch-action: none;
  cursor: crosshair;
}

/* ---------- 遮罩 ---------- */
.overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(23, 32, 47, 0.55);
  backdrop-filter: blur(3px);
  z-index: 10;
}
.overlay.hidden { display: none; }
/* 关键：隐藏的遮罩也不能拦截 pointer 事件，防御性兜底 */
.overlay.hidden { pointer-events: none; }

.menu-card, .end-card {
  background: var(--card);
  border-radius: 18px;
  padding: 30px 34px;
  max-width: 440px;
  width: calc(100% - 40px);
  text-align: center;
  line-height: 1.6;
  box-shadow: var(--shadow-lg);
}
/* 自适应窗口：主菜单卡片高度受限，内容超高时内部滚动，按钮换行成两列，避免小窗口被截断 */
#menuOverlay .menu-card {
  max-height: calc(100% - 40px);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.menu-modes {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
/* 视口够宽时，模式按钮排成两列，压缩纵向高度 */
@media (min-width: 720px) {
  #menuOverlay .menu-card { max-width: 560px; }
  .menu-modes { grid-template-columns: 1fr 1fr; }
}

.menu-title { font-size: 26px; font-weight: 800; color: var(--text); }
.menu-desc { color: var(--muted); font-size: 14px; margin: 12px 0 20px; }
.menu-modes { display: grid; grid-template-columns: 1fr; gap: 10px; }
.menu-records { display: none; margin-top: 6px; padding: 8px 12px; background: rgba(17, 153, 142, 0.08); border: 1px dashed rgba(17, 153, 142, 0.4); border-radius: 10px; font-size: 13px; color: #0d5e54; }
.menu-records-inner b { color: #11998e; font-weight: 800; }
/* ⑦ 残局挑战码输入区 */
.code-entry { display: flex; gap: 8px; margin-top: 10px; }
/* ③ 经典残局预设：2 列网格小按钮（名称 + 难度点），置于 .menu-modes 之后 */
.menu-presets {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
  padding: 10px 12px;
  background: rgba(17, 153, 142, 0.06);
  border: 1px dashed rgba(17, 153, 142, 0.35);
  border-radius: 10px;
}
.menu-presets-title {
  grid-column: 1 / -1;
  font-size: 13px; font-weight: 800; color: #0d5e54;
  margin-bottom: 2px;
}
.menu-presets .btn.big {
  padding: 7px 10px; font-size: 12.5px; text-align: left; min-height: 0;
  white-space: normal; line-height: 1.35;
}
.menu-presets .btn.big .preset-dots { color: #e8b71f; font-size: 11px; margin-left: 4px; }
.code-entry input {
  flex: 1; min-width: 0; padding: 8px 10px; font-size: 13px;
  border: 1px solid rgba(17, 153, 142, 0.4); border-radius: 8px;
  background: rgba(255, 255, 255, 0.7); color: #234;
}
.code-entry input:focus { outline: none; border-color: #11998e; }
.code-entry .btn.ghost { padding: 8px 14px; font-size: 13px; min-height: 0; }
.menu-tip { color: var(--muted); font-size: 12.5px; margin-top: 18px; }

.end-title { font-size: 28px; font-weight: 800; color: var(--text); margin-bottom: 6px; }
.end-sub { color: var(--muted); font-size: 14px; margin-bottom: 20px; }
.end-summary {
  display: flex; flex-direction: column; gap: 7px;
  background: #f5f8fc; border: 1px solid var(--line);
  border-radius: 12px; padding: 14px 16px; margin-bottom: 18px;
  font-size: 13px; color: var(--text); text-align: left;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.end-summary span { line-height: 1.5; letter-spacing: 0.01em; }
.end-summary span b { font-weight: 700; color: #d97706; }
.end-summary .sum-icon { display: inline-block; width: 18px; }
.end-summary .sum-time { color: var(--muted); font-size: 12px; margin-top: 2px; }
.end-summary:empty { display: none; }
.end-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ---------- 高级主题解锁弹窗 ---------- */
#premiumModal { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(23, 32, 47, 0.55); backdrop-filter: blur(3px); z-index: 30; }
#premiumModal .modal { background: var(--card); border-radius: 18px; padding: 26px 30px; max-width: 380px; width: calc(100% - 48px); text-align: center; line-height: 1.6; box-shadow: var(--shadow-lg); color: var(--text); }
#premiumModal .modal h3 { margin: 0 0 4px; font-size: 20px; }
#premiumModal .modal p { color: var(--muted); font-size: 14px; }
#premiumModal .modal .end-actions button { min-height: 42px; padding: 0 20px; }

/* ---------- 提示气泡 ---------- */
.toast {
  position: absolute; left: 50%; top: 18px; transform: translateX(-50%);
  background: rgba(17, 24, 39, 0.82); color: #fff;
  padding: 10px 18px; border-radius: 999px; font-size: 14px; line-height: 1.4;
  z-index: 15; pointer-events: none; max-width: 88%;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
  transition: opacity 0.25s ease;
}
.toast.hidden { opacity: 0; }

/* ---------- 物理参数面板 ---------- */
.phys-board .stats-head { justify-content: space-between; }
.phys-board .btn.ghost { padding: 4px 10px; font-size: 12px; min-height: 0; }
.phys-row { margin-top: 8px; }
.phys-row label {
  display: flex; justify-content: space-between;
  font-size: 12px; color: #345; margin-bottom: 3px; font-weight: 600;
}
.phys-row label span { color: #1a56a0; font-variant-numeric: tabular-nums; }
.phys-row input[type="range"] {
  width: 100%; accent-color: #1d5fd8; height: 6px; cursor: pointer;
}
.phys-tip { font-size: 11px; color: #789; margin: 8px 0 2px; }

/* ---------- ④ 本地排行榜面板 ---------- */
.board-panel .stats-head { justify-content: space-between; }
.board-panel .btn.ghost { padding: 4px 10px; font-size: 12px; min-height: 0; }
#boardRows { margin-top: 8px; display: flex; flex-direction: column; gap: 5px; }
.board-row {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 8px; border-radius: 8px;
  background: rgba(255,255,255,0.5);
}
.board-row:nth-child(1) { background: rgba(255,214,102,0.28); }
.board-row:nth-child(2) { background: rgba(200,200,210,0.28); }
.board-row:nth-child(3) { background: rgba(215,150,95,0.26); }
.board-rank {
  width: 18px; height: 18px; flex: 0 0 18px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; background: #345; color: #fff;
  font-size: 11px; font-weight: 700;
}
.board-icon { flex: 0 0 20px; font-size: 15px; }
.board-name { flex: 1; font-size: 13px; font-weight: 600; color: #234; }
.board-val { font-size: 16px; font-weight: 800; color: #1a56a0; font-variant-numeric: tabular-nums; }
.board-sub { font-size: 10px; color: #789; min-width: 44px; text-align: right; }
.board-empty { font-size: 12px; color: #789; text-align: center; padding: 14px 0; }

/* ---------- 竖屏旋转提示 ---------- */
.rotate-hint {
  display: none;
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  background: rgba(29, 95, 216, 0.92); color: #fff;
  padding: 8px 16px; border-radius: 999px; font-size: 13px; font-weight: 600;
  z-index: 20; pointer-events: none; white-space: nowrap;
  box-shadow: 0 4px 14px rgba(29, 95, 216, 0.4);
  animation: rhFloat 1.6s ease-in-out infinite;
}
@keyframes rhFloat {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(-4px); }
}

/* ---------- 右侧面板 ---------- */
.panel {
  grid-area: panel;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.score-card {
  background: var(--card);
  border-radius: 14px;
  padding: 14px;
  box-shadow: var(--shadow-sm);
  border: 2px solid transparent;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.score-card.on-turn { border-color: var(--primary); box-shadow: 0 8px 22px rgba(47, 124, 246, 0.22); }

.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.player-name { font-weight: 800; font-size: 16px; color: var(--text); }
.group-tag { font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; background: #eef2f7; color: var(--muted); }
.group-tag.solids { background: #fde8e8; color: #b91c1c; }
.group-tag.stripes { background: #e8effd; color: #1d4ed8; }

.progress { font-size: 12.5px; color: var(--muted); margin-bottom: 8px; }
.ball-row { display: flex; flex-wrap: wrap; gap: 5px; min-height: 22px; margin-bottom: 8px; }
.mini-ball {
  width: 20px; height: 20px; border-radius: 50%;
  position: relative; border: 1px solid rgba(0, 0, 0, 0.18);
  box-shadow: inset -2px -2px 4px rgba(0, 0, 0, 0.25);
}
.mini-ball .stripe {
  position: absolute; left: 0; right: 0; top: 6px; height: 8px; background: #fff; border-radius: 2px;
}
.mini-ball .num {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 8.5px; font-weight: 800; color: #fff;
}
.mini-ball.set .inner {
  position: absolute; inset: 3px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.85), transparent 45%);
  display: flex; align-items: center; justify-content: center;
  font-size: 9px; font-weight: 800; color: #222; border: 1px solid rgba(0, 0, 0, 0.15);
}
.mini-ball.done { opacity: 0.38; filter: grayscale(0.7); }

.turn-hint { font-size: 12px; color: var(--muted); min-height: 16px; }
.turn-hint.active { color: var(--primary); font-weight: 700; }

.vs {
  text-align: center; font-weight: 900; font-size: 20px; color: var(--muted);
  letter-spacing: 2px; line-height: 1;
}

.info-box {
  background: var(--card);
  border-radius: 14px;
  padding: 14px;
  box-shadow: var(--shadow-sm);
}
.status { font-size: 14px; color: var(--text); font-weight: 600; margin-bottom: 10px; min-height: 20px; }
.rules { font-size: 12px; color: var(--muted); line-height: 1.8; }

/* ---------- 击打控制（杆法 + 力量槽） ---------- */
.control-board {
  background: var(--card);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: var(--shadow-sm);
}
.power-slot { margin-bottom: 10px; }
.power-slot input[type="range"] {
  width: 100%; accent-color: var(--primary); height: 22px; cursor: pointer;
}
.power-slot-labels {
  display: flex; justify-content: space-between;
  font-size: 11px; color: var(--muted); margin-top: 2px;
}
/* U3：力量滑条 0/50/100 三档刻度（纯展示小字灰） */
.power-slot-scale {
  display: flex; justify-content: space-between;
  font-size: 11px; color: #9ca3af; margin-top: 1px;
  font-variant-numeric: tabular-nums; letter-spacing: 0.5px;
}
.spin-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 8px;
}
.spin-btn {
  border: 1px solid var(--line); background: #f7f9fc; color: var(--text);
  border-radius: 9px; padding: 8px 4px; font-size: 12px; font-weight: 600;
  cursor: pointer; transition: all 0.15s; min-height: 38px;
}
.spin-btn:hover { background: #eef2f7; }
.spin-btn.active {
  background: var(--primary); color: #fff; border-color: transparent;
  box-shadow: 0 3px 8px rgba(47, 124, 246, 0.35); font-weight: 700;
}
.control-tip { font-size: 11px; color: var(--muted); line-height: 1.5; }

/* ---------- 限时挑战倒计时 ---------- */
.shot-timer {
  font-size: 14px; font-weight: 800; color: var(--primary);
  font-variant-numeric: tabular-nums; margin-bottom: 10px;
  padding: 6px 12px; border-radius: 8px; background: #eef4ff;
  border: 1px solid #cfe0ff;
  transition: color 0.2s, background 0.2s;
}
.shot-timer.urgent { color: #d64545; background: #fdecec; border-color: #f7c2c2; animation: timerPulse 0.6s ease-in-out infinite; }
@keyframes timerPulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.04); } }
.btn.ghost.on { background: #eef4ff; color: var(--primary); border-color: #9db9f0; font-weight: 800; }

/* ---------- 计时记分板 ---------- */
.stats-board {
  background: var(--card);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: var(--shadow-sm);
}
.stats-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.stats-title { font-size: 13px; font-weight: 800; color: var(--text); letter-spacing: 0.5px; }
.stats-clock {
  font-size: 13px; font-weight: 700; color: var(--primary);
  font-variant-numeric: tabular-nums;
}
.stats-table {
  width: 100%; border-collapse: collapse; font-size: 12.5px;
  color: var(--text);
}
.stats-table th, .stats-table td {
  text-align: center; padding: 5px 2px; border-bottom: 1px solid var(--line);
  font-weight: 500;
}
.stats-table th { color: var(--muted); font-size: 11px; font-weight: 700; }
.stats-table .s-name { text-align: left; font-weight: 700; }
.stats-table tbody tr:last-child td { border-bottom: none; }
.replay-btn {
  width: 100%; margin-top: 10px;
  background: #f1f5f9; color: var(--text); border: 1px solid var(--line);
}
.replay-btn:hover { background: #e7edf5; }

/* ---------- 回放控制栏（stage 底部通栏） ---------- */
.replay-bar {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; align-items: center; gap: 8px;
  background: rgba(15, 22, 33, 0.92);
  padding: 10px 14px;
  z-index: 30;
  backdrop-filter: blur(4px);
  color: #fff;
  flex-wrap: wrap;
}
.replay-bar.hidden { display: none; }
.replay-title { font-size: 13px; font-weight: 800; color: #fff; margin-right: 4px; }
.replay-ctrl {
  width: 38px; height: 34px; border-radius: 8px;
  background: rgba(255,255,255,0.12); border: 1px solid rgba(255,255,255,0.18);
  color: #fff; font-size: 14px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.replay-ctrl.big { width: 78px; font-size: 13px; font-weight: 700; background: var(--primary); border-color: transparent; }
.replay-ctrl.big:hover { background: var(--primary-dark); }
.replay-ctrl:not(.big):hover { background: rgba(255,255,255,0.24); }
/* ⑧ 运动回放开关按钮（文字钮 + 激活高亮） */
.replay-ctrl.motion {
  width: auto; min-width: 84px; padding: 0 10px;
  font-size: 12px; font-weight: 700;
  background: rgba(255, 176, 64, 0.16); border-color: rgba(255, 176, 64, 0.4);
}
.replay-ctrl.motion.active { background: var(--accent); color: #fff; border-color: transparent; box-shadow: 0 2px 8px rgba(245, 158, 11, 0.4); }
#replayScrub { flex: 1 1 120px; accent-color: var(--primary); height: 6px; }
.replay-speed { display: flex; gap: 4px; }
.replay-speed .spd {
  width: 30px; height: 26px; border-radius: 6px;
  background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.15);
  color: #cfd6e0; font-size: 12px; font-weight: 700; cursor: pointer;
}
.replay-speed .spd.active { background: var(--accent); color: #fff; border-color: transparent; }
.replay-caption { font-size: 12px; color: #d8e0ec; min-width: 220px; text-align: right; }
.replay-caption .foul { color: #ff7a7a; font-weight: 700; }
.replay-close {
  width: 30px; height: 30px; border-radius: 50%;
  background: rgba(255,255,255,0.12); border: 1px solid rgba(255,255,255,0.18);
  color: #fff; font-size: 14px; cursor: pointer;
}
.replay-close:hover { background: rgba(255, 120, 120, 0.5); }

@media (max-width: 820px) {
  .panel { flex-basis: 100%; flex-direction: row; flex-wrap: wrap; }
  .score-card { flex: 1 1 200px; }
  .info-box { flex: 1 1 100%; }
  .vs { display: none; }
}

/* ---------- 竖屏（手机竖着拿）：单列堆叠 + 旋转提示 + 加大触控热区 ---------- */
@media (orientation: portrait) and (max-width: 760px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "stage" "panel";
  }
  .panel { flex-direction: column; }
  .score-card { flex-basis: auto; }
  .rotate-hint { display: block; }

  /* 触控热区加大：按钮/切换 chips 更易点中（≥ 44px 高） */
  .btn { padding: 12px 18px; font-size: 14px; min-height: 44px; }
  .btn.big { padding: 16px 28px; font-size: 16px; min-height: 52px; }
  .mode-switch .chip, .diff-switch .chip { padding: 10px 16px; font-size: 14px; min-height: 40px; }
  .topbar { padding: 12px; }
  .top-actions { gap: 10px; }
  .replay-ctrl { width: 44px; height: 44px; }
  .replay-ctrl.big { min-width: 92px; }
  .replay-speed .spd { width: 40px; height: 40px; font-size: 14px; }
  .replay-close { width: 40px; height: 40px; }
}

/* ---------- 沉浸模式：全屏隐藏顶栏与面板，球台居中放大 + 深色球房 ---------- */
body.immersed { overflow: hidden; }
body.immersed .topbar,
body.immersed .panel { display: none !important; }
body.immersed #app {
  max-width: none; padding: 0;
  min-height: 100vh; min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  background: #0d1015;
}
body.immersed .layout {
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "stage";
  gap: 0;
  width: 100%; max-width: 1280px;
}
body.immersed .stage {
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.6);
}
/* 沉浸时顶栏按钮隐藏，浮一个小的退出按钮在舞台右上角 */
.btn-imm-escape {
  display: none;
  position: fixed; top: 14px; right: 16px; z-index: 40;
  background: rgba(255, 255, 255, 0.12); color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  backdrop-filter: blur(4px);
  padding: 8px 14px; border-radius: 999px;
  font-size: 13px; font-weight: 600; cursor: pointer;
}
body.immersed .btn-imm-escape { display: block; }
/* 沉浸时旋转提示常驻顶部（球房暗色下更醒目） */
body.immersed .rotate-hint { display: none; }

/* ---------- 斯诺克规则遮罩 ---------- */
#snookerRulesOverlay { background: rgba(10, 16, 24, 0.72); backdrop-filter: blur(4px); }
.snooker-rules-card { max-width: 560px; }
.snooker-rules-list { margin: 6px 0 16px; padding-left: 18px; line-height: 1.75; font-size: 14px; color: var(--text); }
.snooker-rules-list li { margin-bottom: 8px; }
.snooker-rules-list b { color: var(--primary-dark); }

/* ---------- ⑭ 成就徽章网格（复用 overlay + menu-card，少量新增） ---------- */
#achievementsOverlay { background: rgba(10, 16, 24, 0.72); backdrop-filter: blur(4px); }
.achv-card { max-width: 520px; }
.achv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0 16px; }
.achv-item {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 10px 12px; border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  opacity: 0.55; /* 未解锁灰显 */
}
.achv-item.got { opacity: 1; background: rgba(255, 200, 80, 0.12); border-color: rgba(255, 200, 80, 0.45); } /* 已解锁亮色 */
.achv-icon { position: relative; font-size: 22px; line-height: 1; }
.achv-check {
  position: absolute; right: -12px; top: -8px; font-size: 11px; font-weight: 700;
  color: #ffd873; text-shadow: 0 0 4px rgba(0, 0, 0, 0.5);
}
.achv-name { font-size: 13px; font-weight: 600; color: var(--text); }
.achv-item.got .achv-name { color: #ffd873; }
.achv-desc { font-size: 11px; color: var(--muted, #9aa4b5); }

/* ---------- ⑲ 台型预设按钮（物理参数面板内，休闲/写实一键套用） ---------- */
.preset-row {
  display: flex; gap: 8px; margin-bottom: 10px;
}
.preset-btn {
  flex: 1; padding: 7px 10px; border-radius: 8px; cursor: pointer;
  background: #f1f5f9; color: var(--text); border: 1px solid var(--line);
  font-size: 12px; font-weight: 700;
}
.preset-btn:hover { background: #e7edf5; border-color: var(--primary); }
.preset-btn:active { background: var(--primary); color: #fff; }

/* ---------- ⑰ 移动端浮动工具条（右下竖排 4 圆钮；桌面隐藏，≤760px 显示） ---------- */
#mobileBar {
  display: none; /* 桌面默认隐藏（顶栏/侧栏已有完整控件） */
}
@media (max-width: 760px) {
  #mobileBar {
    display: flex; flex-direction: column; gap: 10px;
    position: fixed; right: 12px; bottom: 84px;
    z-index: 35; /* 高于 canvas、低于 overlay（z=30+ 的浮层之上可点，菜单遮罩 40+ 盖住） */
    align-items: center;
  }
  #mobileBar button {
    width: 48px; height: 48px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; line-height: 1; cursor: pointer;
    background: rgba(15, 22, 33, 0.78); color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.22);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(4px);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }
  #mobileBar button:active { background: rgba(255, 200, 60, 0.85); transform: scale(0.94); }
}

/* ---------- U5 移动端（≤720px）记分板布局：单列 + 双卡并排 + 2 列统计 ---------- */
@media (max-width: 720px) {
  /* 单列：记分面板移到画布下方，横向占满 */
  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "stage" "panel";
  }
  .panel {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
  }
  /* 双玩家卡横向并排（各 50% 宽，padding 减到 10px） */
  .score-card {
    flex: 1 1 48%;
    min-width: 48%;
    padding: 10px;
  }
  /* 6 列统计表 → 2 列网格，每个玩家占一整行（6 项两两并排） */
  .stats-table {
    display: block;
    width: 100%;
    border-collapse: separate;
    border-spacing: 0 8px;
  }
  .stats-table thead { display: none; } /* 表头在 2 列网格下隐藏，改由每格 data-label 承载 */
  .stats-table tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-bottom: 6px;
  }
  .stats-table td {
    display: flex; align-items: center; justify-content: space-between;
    padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px;
    background: #f7f9fc; font-weight: 600;
  }
  .stats-table td::before {
    content: attr(data-label);
    font-size: 10px; color: var(--muted); font-weight: 700; margin-right: 6px;
  }
  .stats-table .s-name {
    grid-column: 1 / -1;
    justify-content: flex-start; font-weight: 800;
  }
  .stats-table .s-name::before { content: none; }
  /* 控台 6 宫格杆法按钮保持 3×2，字号减 1px */
  .spin-grid { grid-template-columns: repeat(3, 1fr); }
  .spin-btn { font-size: 11px; padding: 7px 3px; }
}

/* ---------- 九宫格白球击球点模型（点白球某位置=对应杆法走位） ---------- */
.spin-ball-panel {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 14px 16px; margin-top: 4px;
  background: rgba(17, 24, 39, 0.5); border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
}
.spin-ball {
  position: relative;
  width: 116px; height: 116px; border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #ffffff 0%, #f2ede3 38%, #cfc7b6 78%, #a99f8a 100%);
  box-shadow: inset -6px -8px 14px rgba(0, 0, 0, 0.28), inset 6px 8px 12px rgba(255, 255, 255, 0.5), 0 4px 10px rgba(0, 0, 0, 0.35);
  cursor: pointer; user-select: none; -webkit-user-select: none;
  touch-action: manipulation;
}
/* 十字准线（对应图片中的横竖两条线，区分上下左右象限） */
.spin-cross { position: absolute; inset: 0; pointer-events: none; }
.spin-cross-h { position: absolute; left: 18%; right: 18%; top: 50%; height: 1.5px; background: rgba(40, 40, 48, 0.55); }
.spin-cross-v { position: absolute; top: 18%; bottom: 18%; left: 50%; width: 1.5px; background: rgba(40, 40, 48, 0.55); }
/* 击球点（紫色圆点，可点选） */
.spin-dot {
  position: absolute; width: 18px; height: 18px; margin: -9px 0 0 -9px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #b98ae0 0%, #7a3ea6 60%, #5a2c86 100%);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.6), 0 2px 4px rgba(0, 0, 0, 0.35);
  cursor: pointer; transition: transform 0.12s ease, box-shadow 0.12s ease;
  z-index: 2;
}
.spin-dot:hover { transform: scale(1.25); }
.spin-dot.active {
  transform: scale(1.45);
  box-shadow: 0 0 0 3px rgba(240, 170, 60, 0.95), 0 0 14px rgba(240, 170, 60, 0.7);
}
.spin-ball-label {
  min-height: 18px; font-size: 13px; font-weight: 600; letter-spacing: 0.5px;
  color: #f0d27a; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}
@media (max-width: 560px) {
  .spin-ball { width: 92px; height: 92px; }
  .spin-ball-panel { padding: 10px 12px; }
}
