* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'PingFang SC', -apple-system, BlinkMacSystemFont, 'Microsoft YaHei', sans-serif;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 24px 16px 48px;
  position: relative;
}
/* 虚化企鹅背景层：inset 负值外扩，避免 blur 后边缘露出透明/白边 */
body::before {
  content: '';
  position: fixed;
  inset: -48px;
  z-index: -2;
  background: url('../assets/penguin.jpg') center / cover no-repeat;
  filter: blur(28px) saturate(1.25) brightness(1.08);
}
/* 淡蓝遮罩：压一下背景对比度，保证卡片和文字可读 */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background: linear-gradient(180deg, rgba(160, 215, 255, 0.55) 0%, rgba(90, 160, 230, 0.45) 100%);
}

.page {
  width: 100%;
  max-width: 560px;
}

.header {
  text-align: center;
  margin-bottom: 18px;
}
.header h1 {
  color: #fff;
  font-size: 2rem;
  text-shadow: 2px 2px 6px rgba(0, 60, 120, 0.35);
}
/* 标题里的企鹅 logo：与"华容道"等高、带同款阴影，融入背景 */
.header h1 .h1-logo {
  height: 1.06em;
  vertical-align: -0.12em;
  filter: drop-shadow(2px 2px 6px rgba(0, 60, 120, 0.35));
}
.header .subtitle {
  margin-top: 6px;
  color: rgba(255, 255, 255, 0.92);
  font-size: 0.95rem;
}

.panel {
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 20px;
  padding: 18px 16px 22px;
  box-shadow: 0 14px 44px rgba(0, 50, 110, 0.28);
}

/* ---------- 模式切换 ---------- */
.mode-switch {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 10px;
}
.mode-btn {
  flex: 1;
  max-width: 220px;
  padding: 11px 6px;
  font-size: 1rem;
  font-weight: 800;
  color: #456;
  background: #eef3f8;
  border: 2px solid transparent;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.mode-btn:hover { background: #e2ecf5; }
.mode-btn.active {
  color: #fff;
  background: linear-gradient(135deg, #ff8a3d 0%, #ff5a7a 100%);
  box-shadow: 0 4px 14px rgba(255, 120, 80, 0.4);
}

/* ---------- 难度按钮 ---------- */
.difficulty {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 10px;
}
.diff-btn {
  flex: 1;
  max-width: 150px;
  padding: 10px 4px;
  font-size: 0.95rem;
  font-weight: 700;
  color: #456;
  background: #eef3f8;
  border: 2px solid transparent;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.diff-btn:hover { background: #e2ecf5; }
.diff-btn.active {
  color: #fff;
  background: linear-gradient(135deg, #38a3f5 0%, #2ac9a5 100%);
  box-shadow: 0 4px 14px rgba(56, 163, 245, 0.4);
}

.topbar {
  text-align: center;
  font-size: 0.85rem;
  color: #7a8ba0;
  margin-bottom: 12px;
  min-height: 1.2em;
}
/* PK 统一计时：两个盘共用一块表（两侧不再各计时） */
.pk-timer {
  display: inline-block;
  padding: 2px 14px;
  font-size: 1.5rem;
  font-weight: 900;
  color: #33506b;
  background: rgba(56, 163, 245, 0.14);
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}
.pk-timer.running {
  color: #0f9d58;
  background: rgba(52, 199, 89, 0.18);
}
/* 最后 10 秒：变红闪烁提醒 */
.pk-timer.danger {
  color: #fff;
  background: #e8613c;
  animation: timerBlink 1s ease-in-out infinite;
}
@keyframes timerBlink { 50% { opacity: 0.45; } }

/* 对战中的结束按钮（左上角，裁判用） */
.exit-btn {
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: 55;
  padding: 12px 20px;
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 800;
  color: #33506b;
  background: rgba(255, 255, 255, 0.94);
  border: none;
  border-radius: 12px;
  box-shadow: 0 8px 22px rgba(0, 50, 110, 0.25);
  cursor: pointer;
}
.exit-btn:hover { color: #e8613c; background: #fff; }

/* ---------- 棋盘区（单人 1 个，PK 2 个并排）---------- */
.boards {
  position: relative;
  display: flex;
  gap: 14px;
  justify-content: center;
  margin-bottom: 14px;
}
/* PK 模式：两人并排玩，间距/宽度随屏幕尺寸自适应（屏越宽分得越开） */
body.pk-mode .boards { gap: clamp(24px, 7vw, 260px); }
body.pk-mode .page { max-width: min(96vw, 2560px); }
/* 盘面边长同时受可用高度约束，避免撑出滚动；约束放在 side 上，
   这样两个盘之间的空隙就正好等于上面的 gap，不会被居中留白放大 */
body.pk-mode .board-side { max-width: calc(100vh - 420px); }
/* 按钮区离棋盘远一些：玩的时候手伸到盘上，不会误碰按钮 */
body.pk-mode .boards { margin-bottom: clamp(28px, 4vw, 90px); }
body.pk-mode .actions { gap: 22px; }

/* ---------- PK 专注模式：开始后只留双盘与计时器，其余全部虚化锁定 ---------- */
body.pk-focus .header,
body.pk-focus .mode-switch,
body.pk-focus .difficulty,
body.pk-focus #soloBest,
body.pk-focus .actions,
body.pk-focus .back {
  filter: blur(5px);
  opacity: 0.2;
  pointer-events: none;          /* 不可触摸 */
  user-select: none;
}
/* 面板本身淡出，让两个盘像浮在背景上 */
body.pk-focus .panel {
  background: rgba(255, 255, 255, 0.22);
  border-color: transparent;
  box-shadow: none;
}
/* 双盘浮起来 */
body.pk-focus .boards {
  position: relative;
  z-index: 30;
  transform: scale(1.02);
  filter: drop-shadow(0 26px 50px rgba(6, 40, 80, 0.32));
}
body.pk-focus .board {
  box-shadow: inset 0 0 0 3px #bfe0f7, 0 16px 40px rgba(20, 80, 140, 0.28);
}
/* 计时器浮起来 */
body.pk-focus .pk-timer {
  transform: scale(1.18);
  background: #fff;
  box-shadow: 0 10px 26px rgba(0, 50, 110, 0.26);
}
/* 整页锁定：不能滑动 */
html.pk-focus, html.pk-focus body {
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
}
.board-side {
  flex: 1;
  min-width: 0;
}
/* 单人模式：只显示第一个棋盘 */
body:not(.pk-mode) #side2 { display: none; }

.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  padding: 0 2px;
}
.player-name {
  font-size: 1rem;
  font-weight: 800;
  color: #23303f;
}
body.pk-mode #side1 .player-name { color: #e8613c; }
body.pk-mode #side2 .player-name { color: #2f88c5; }
.side-status {
  font-size: 0.85rem;
  font-weight: 700;
  color: #33506b;
  white-space: nowrap;
}

.board-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
}
.board {
  position: absolute;
  inset: 0;
  background: #d7ecfb;
  border-radius: 14px;
  box-shadow: inset 0 0 0 3px #bfe0f7, 0 4px 14px rgba(20, 80, 140, 0.12);
  overflow: hidden;
  /* 关键：禁用浏览器自身的触摸手势（滚动/缩放/长按），保证多指滑动能被游戏接收 */
  touch-action: none;
}
/* 胜利时：用完整原图盖住整个棋盘，空格也被补齐 */
.board.solved::after {
  content: '';
  position: absolute;
  inset: 0;
  background: url('../assets/penguin.jpg') center / cover no-repeat;
  animation: fadeIn 0.6s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.tile {
  position: absolute;
  top: 0;
  left: 0;
  background-repeat: no-repeat;
  border-radius: 8px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.65), 0 2px 6px rgba(10, 60, 110, 0.25);
  transition: transform 0.16s ease;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  touch-action: none;
}
.tile.movable { cursor: grab; }
.tile.movable:hover { filter: brightness(1.08); }
.tile .num {
  position: absolute;
  top: 4px;
  left: 4px;
  min-width: 20px;
  height: 20px;
  line-height: 20px;
  padding: 0 5px;
  font-size: 0.72rem;
  font-weight: 800;
  color: #1c5d8f;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 8px;
  text-align: center;
  pointer-events: none;
}
.board.hide-num .tile .num { display: none; }

/* ---------- 原图预览（覆盖整个棋盘区）---------- */
.preview {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: rgba(8, 40, 80, 0.92);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.preview img {
  width: 60%;
  max-height: 80%;
  object-fit: contain;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
.preview p { color: #cfe8ff; font-size: 0.85rem; }

/* ---------- 胜利覆盖层 ---------- */
.win-overlay {
  position: absolute;
  inset: 0;
  z-index: 6;
  background: rgba(8, 40, 80, 0.55);
  border-radius: 14px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.4s ease;
}
.win-card {
  width: 92%;
  margin-bottom: 12px;
  background: #fff;
  border-radius: 16px;
  padding: 16px 14px 18px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}
.win-emoji { font-size: 2.4rem; }
.win-card h2 { font-size: 1.1rem; color: #23303f; margin: 4px 0 8px; }
.win-stats { font-size: 0.9rem; color: #33506b; font-weight: 700; line-height: 1.6; }
.win-best { font-size: 0.82rem; color: #e5940b; margin-top: 4px; }
.pk-lose { color: #98a2b3; font-weight: 600; }

/* ---------- PK 倒计时 / 对战结果（全屏居中）---------- */
.countdown,
.pk-result {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 40, 80, 0.5);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
.countdown span {
  font-size: clamp(9rem, 22vw, 26rem);
  font-weight: 900;
  line-height: 1;
  color: #fff;
  text-shadow: 0 12px 32px rgba(0, 60, 120, 0.65);
  animation: cdPop 0.9s ease-out;
}
@keyframes cdPop {
  0% { transform: scale(0.35); opacity: 0; }
  35% { transform: scale(1.18); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
.pk-result .win-card {
  width: 88%;
  max-width: 420px;
  margin: 0;
  padding: 26px 22px 24px;
}
.pk-result .win-emoji { font-size: 4.5rem; }
.pk-result h2 { font-size: 1.5rem; margin: 6px 0 10px; }
.pk-result .btn { margin-top: 16px; }

/* ---------- 玩家名字输入 / 排行榜 ---------- */
.name-input {
  width: 100%;
  margin: 14px 0 4px;
  padding: 14px 16px;
  font-size: 1.25rem;
  font-family: inherit;
  text-align: center;
  color: #23303f;
  background: #f4f8fc;
  border: 2px solid #cfe0f0;
  border-radius: 12px;
  outline: none;
}
.name-input:focus { border-color: #38a3f5; background: #fff; }
.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 16px;
  flex-wrap: wrap;
}
.rank-list {
  margin: 12px 0 4px;
  max-height: 46vh;
  overflow-y: auto;
  text-align: left;
}
/* 表头与数据行共用一套列宽，保证对齐；整行居中，名字和成绩不拉开 */
.rank-head,
.rank-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
}
.rank-head {
  padding: 2px 10px 8px;
  font-size: 0.82rem;
  font-weight: 800;
  color: #a4b1c0;
  border-bottom: 2px solid #edf2f7;
  margin-bottom: 4px;
}
.rank-row {
  padding: 9px 10px;
  border-radius: 10px;
  font-size: 0.95rem;
}
.rank-row:nth-child(odd) { background: #f4f8fc; }
.rank-no { width: 32px; font-weight: 900; color: #e5940b; text-align: center; }
.rank-name {
  min-width: 6em;
  text-align: center;
  font-weight: 800;
  color: #23303f;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rank-stat { color: #7a8ba0; font-weight: 700; white-space: nowrap; }
.rank-time { min-width: 4em; text-align: right; }
.rank-moves { min-width: 3.5em; text-align: right; }
.rank-empty { margin: 14px 0; color: #98a2b3; font-size: 0.95rem; }
.pk-rank-title { margin: 18px 0 2px; font-size: 1.05rem; color: #e5940b; }
/* 清空按钮：放卡片右上角，远离底部的「关闭」 */
.pk-result .win-card { position: relative; }
.rank-clear {
  position: absolute;
  top: 10px;
  right: 12px;
  padding: 6px 10px;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  color: #b6c2d0;
  background: none;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}
.rank-clear:hover { color: #e8613c; background: #fdf1ed; }

/* 排行榜分页 */
.rank-pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 2px solid #edf2f7;
}
.rank-page-btn {
  padding: 10px 18px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, #38a3f5 0%, #2ac9a5 100%);
  border: none;
  border-radius: 12px;
  cursor: pointer;
}
.rank-page-btn:active { transform: translateY(2px); }
.rank-page-btn[disabled] { opacity: 0.35; cursor: default; }
.rank-page-info {
  font-size: 0.9rem;
  font-weight: 800;
  color: #7a8ba0;
  white-space: nowrap;
}
.rank-more { margin-top: 6px; font-size: 0.82rem; color: #98a2b3; }

/* 未开始 / 已结束：棋盘锁定（变暗且不可操作） */
.boards.locked .board { filter: grayscale(0.5) brightness(0.9); }
.boards.locked .tile { pointer-events: none; }

/* ---------- 按钮 ---------- */
.actions {
  display: flex;
  gap: 14px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.btn {
  padding: 11px 16px;
  font-size: 0.92rem;
  font-weight: 700;
  color: #33506b;
  background: #eef3f8;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.btn:hover { background: #e2ecf5; }
.btn:active { transform: translateY(2px); }
.btn.primary {
  color: #fff;
  background: linear-gradient(135deg, #38a3f5 0%, #2ac9a5 100%);
  box-shadow: 0 4px 14px rgba(56, 163, 245, 0.4);
}
.btn.big { padding: 13px 26px; font-size: 1rem; }
.btn.start {
  color: #fff;
  background: linear-gradient(135deg, #34c759 0%, #0f9d58 100%);
  box-shadow: 0 6px 16px rgba(15, 157, 88, 0.4);
}
.btn.toggle { opacity: 0.55; }
.btn.toggle.active { opacity: 1; }

.back {
  display: block;
  margin-top: 14px;
  text-align: center;
  font-size: 0.9rem;
  color: #98a2b3;
  text-decoration: none;
}
.back:hover { color: #38a3f5; }

.hidden { display: none !important; }

/* ---------- 手机端 ---------- */
@media (max-width: 420px) {
  .header h1 { font-size: 1.5rem; }
  body.pk-mode .boards { gap: 16px; } /* 小屏没空间，间距收窄 */
  .panel { padding: 14px 10px 18px; }
  .mode-btn, .diff-btn { font-size: 0.85rem; padding: 9px 2px; }
  .btn { padding: 10px 12px; font-size: 0.85rem; }
  .player-name { font-size: 0.9rem; }
  .side-status { font-size: 0.75rem; }
}

/* ---------- 会议室大屏（Rooms / Surface Hub 等大尺寸触屏）---------- */
@media (min-width: 1400px) {
  .page { max-width: 1180px; }
  /* PK 大屏：中间标出 VS 明确分界（间距与宽度已随视口自适应） */
  body.pk-mode .boards::before {
    content: 'VS';
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    font-size: clamp(2.4rem, 3.4vw, 5rem);
    font-weight: 900;
    letter-spacing: 3px;
    color: #fff;
    text-shadow: 0 3px 12px rgba(0, 60, 120, 0.6);
    pointer-events: none;
  }
  .header h1 { font-size: 2.8rem; }
  .header .subtitle { font-size: 1.2rem; }
  .panel { padding: 26px 24px 30px; border-radius: 24px; }
  .mode-btn, .diff-btn { font-size: 1.15rem; padding: 14px 8px; }
  .topbar { font-size: 1.05rem; }
  .player-name { font-size: 1.5rem; }
  .side-status { font-size: 1.2rem; }
  .tile .num {
    font-size: 1.1rem;
    min-width: 34px;
    height: 34px;
    line-height: 34px;
  }
  .btn { font-size: 1.15rem; padding: 15px 26px; }
  .back { font-size: 1.1rem; }
  .win-emoji { font-size: 3.4rem; }
  .win-card h2 { font-size: 1.6rem; }
  .win-stats { font-size: 1.3rem; }
  .pk-timer { font-size: clamp(1.8rem, 1.7vw, 3rem); padding: 4px 22px; }
  .pk-result .win-card { max-width: 620px; padding: 34px 30px 30px; }
  .pk-result .win-emoji { font-size: 6rem; }
  .pk-result h2 { font-size: 2.4rem; }
  .pk-result .win-stats { font-size: 1.8rem; }
  .name-input { font-size: 1.8rem; padding: 18px 20px; margin: 18px 0 6px; }
  .rank-row { font-size: 1.35rem; padding: 12px 14px; }
  .rank-head { font-size: 1.15rem; gap: 32px; }
  .rank-row { gap: 32px; }
  .rank-list { max-height: 40vh; }
  .rank-clear { font-size: 1.1rem; top: 16px; right: 20px; }
  .rank-page-btn { font-size: 1.25rem; padding: 14px 26px; }
  .rank-page-info { font-size: 1.15rem; }
  .rank-pager { gap: 22px; }
  .exit-btn { font-size: 1.35rem; padding: 16px 26px; top: 26px; left: 26px; }
  .rank-time { min-width: 5em; }
  .rank-moves { min-width: 4.5em; }
}
