/* ============================================================
   崔彦斌的游戏空间 · 游戏页通用样式
   ============================================================ */

body.game-page {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  background: radial-gradient(
      820px 520px at 50% -12%,
      rgba(124, 92, 255, 0.18),
      transparent 62%
    ),
    var(--bg);
}

/* ---------- 顶栏 ---------- */

.page-head {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px clamp(12px, 3vw, 24px);
  border-bottom: 1px solid var(--line);
  background: rgba(8, 10, 18, 0.74);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 550;
  color: var(--muted);
  white-space: nowrap;
  transition: color 0.18s ease, background 0.18s ease;
}

.back-link:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.page-title {
  flex: 1;
  margin: 0;
  text-align: center;
  font-size: 15px;
  font-weight: 680;
  letter-spacing: 0.02em;
}

.page-head .icon-btn {
  flex: none;
  width: 38px;
  height: 38px;
  font-size: 17px;
}

/* ---------- 主体 ---------- */

.game-shell {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: min(740px, 100%);
  margin-inline: auto;
  padding: 20px clamp(12px, 3vw, 24px) 34px;
}

.game-shell.is-wide {
  width: min(820px, 100%);
}

.hud {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  width: 100%;
}

.hud-item {
  flex: 1 1 0;
  min-width: 82px;
  max-width: 170px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.035);
  text-align: center;
}

.hud-item span {
  display: block;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.09em;
  color: var(--muted-soft);
}

.hud-item strong {
  display: block;
  font-family: var(--mono);
  font-size: 19px;
  line-height: 1.35;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.hud-item strong.is-hot {
  color: var(--yellow);
}

.hud-item strong.is-good {
  color: var(--green);
}

/* ---------- 舞台与浮层 ---------- */

.stage {
  position: relative;
  width: 100%;
  max-width: 560px;
  margin-inline: auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.028);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.42);
}

.stage > canvas {
  width: 100%;
  height: auto;
  border-radius: 12px;
  background: #090d18;
  touch-action: none;
}

.stage.is-square {
  max-width: 520px;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  padding: 18px;
  border-radius: inherit;
  background: rgba(6, 8, 15, 0.74);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  text-align: center;
}

.overlay[hidden] {
  display: none;
}

.overlay-card {
  width: min(340px, 100%);
  padding: 24px 22px;
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  background: linear-gradient(
    180deg,
    rgba(25, 29, 48, 0.97),
    rgba(12, 16, 30, 0.97)
  );
  box-shadow: 0 26px 60px rgba(0, 0, 0, 0.55);
}

.overlay-kicker {
  margin: 0 0 5px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--brand-2);
}

.overlay h2 {
  margin: 0 0 7px;
  font-size: 23px;
  line-height: 1.25;
  letter-spacing: -0.02em;
}

.overlay p {
  margin: 0 0 18px;
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--muted);
}

.overlay p b {
  color: var(--text);
  font-family: var(--mono);
  font-size: 15px;
}

.overlay-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.overlay-actions .btn {
  width: 100%;
}

/* ---------- 控制区 ---------- */

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.hint {
  margin: 2px 0 0;
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--muted-soft);
  text-align: center;
}

.hint kbd {
  display: inline-block;
  min-width: 20px;
  padding: 1px 6px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.06);
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
}

.page-foot {
  margin-top: auto;
  padding: 18px 16px 24px;
  border-top: 1px solid var(--line);
  text-align: center;
  font-size: 12px;
  color: var(--muted-soft);
}

.page-foot a {
  color: var(--muted);
}

.page-foot a:hover {
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ---------- 方向键 / 触屏按钮 ---------- */

.touch-pad {
  display: none;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  width: min(260px, 100%);
  margin-inline: auto;
}

.touch-pad .up {
  grid-area: 1 / 2;
}

.touch-pad .left {
  grid-area: 2 / 1;
}

.touch-pad .down {
  grid-area: 2 / 2;
}

.touch-pad .right {
  grid-area: 2 / 3;
}

.touch-btn {
  display: grid;
  place-items: center;
  height: 56px;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.055);
  font-size: 19px;
  line-height: 1;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: background 0.12s ease, transform 0.12s ease;
}

.touch-btn:active {
  background: rgba(124, 92, 255, 0.34);
  transform: scale(0.96);
}

@media (hover: none), (pointer: coarse) {
  .touch-pad {
    display: grid;
  }
}

/* ============================================================
   贪吃蛇
   ============================================================ */

.snake-stage {
  touch-action: none;
}

/* ============================================================
   2048
   ============================================================ */

.board-2048 {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.035);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.bg-2048 {
  position: absolute;
  inset: var(--pad, 10px);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: var(--gap, 10px);
  pointer-events: none;
}

.bg-2048 i {
  border: 1px solid rgba(255, 255, 255, 0.028);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.035);
}

.num-tile {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  border-radius: 8px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  will-change: transform;
  transition: transform 0.12s ease;
}

.num-tile.is-new {
  animation: tile-pop 0.18s ease;
}

@keyframes tile-pop {
  from {
    opacity: 0.2;
    scale: 0.6;
  }
}

.tile-2 {
  color: #4a3f33;
  background: #ede0c8;
}
.tile-4 {
  color: #4a3f33;
  background: #f2d9a8;
}
.tile-8 {
  color: #fff;
  background: #f2b179;
}
.tile-16 {
  color: #fff;
  background: #f59563;
}
.tile-32 {
  color: #fff;
  background: #f67c5f;
}
.tile-64 {
  color: #fff;
  background: #f65e3b;
}
.tile-128 {
  color: #3b2f14;
  background: #edcf72;
  box-shadow: 0 0 18px rgba(237, 207, 114, 0.24);
}
.tile-256 {
  color: #3b2f14;
  background: #edcc61;
  box-shadow: 0 0 20px rgba(237, 204, 97, 0.28);
}
.tile-512 {
  color: #3b2f14;
  background: #edc850;
  box-shadow: 0 0 22px rgba(237, 200, 80, 0.32);
}
.tile-1024 {
  color: #3b2f14;
  background: #edc53f;
  box-shadow: 0 0 24px rgba(237, 197, 63, 0.36);
}
.tile-2048 {
  color: #2a2109;
  background: linear-gradient(135deg, #ffe082, #f0b429);
  box-shadow: 0 0 30px rgba(240, 180, 41, 0.55);
}
.tile-super {
  color: #fff;
  background: linear-gradient(135deg, #8b5cf6, #22d3ee);
  box-shadow: 0 0 30px rgba(139, 92, 246, 0.55);
}

/* ============================================================
   扫雷
   ============================================================ */

.ms-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
}

.segmented {
  display: inline-flex;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.035);
}

.seg-btn {
  padding: 6px 15px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 550;
  color: var(--muted);
  transition: background 0.16s ease, color 0.16s ease;
}

.seg-btn:hover {
  color: var(--text);
}

.seg-btn.is-active {
  color: #fff;
  background: rgba(124, 92, 255, 0.4);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}

.flag-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.05);
  font-size: 13px;
  font-weight: 550;
  color: var(--muted);
  transition: background 0.16s ease, color 0.16s ease,
    border-color 0.16s ease;
}

.flag-toggle[aria-pressed="true"] {
  color: #0a0c14;
  background: linear-gradient(135deg, #ffd166, #ffb347);
  border-color: transparent;
  font-weight: 700;
}

.ms-stage {
  position: relative;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.03);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.4);
}

.ms-board-wrap {
  max-width: 100%;
  padding: 2px;
  overflow: auto;
  border-radius: 12px;
  overscroll-behavior: contain;
}

.ms-board {
  display: grid;
  gap: 2px;
  width: max-content;
  margin-inline: auto;
  touch-action: manipulation;
}

.ms-cell {
  position: relative;
  display: grid;
  place-items: center;
  width: var(--cell, 28px);
  height: var(--cell, 28px);
  padding: 0;
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 4px;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.14),
    rgba(255, 255, 255, 0.065)
  );
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.22);
  font-family: var(--mono);
  font-size: calc(var(--cell, 28px) * 0.5);
  font-weight: 700;
  line-height: 1;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
  transition: background 0.12s ease;
}

.ms-cell:hover {
  background: rgba(255, 255, 255, 0.19);
}

.ms-cell.is-revealed {
  border-color: rgba(255, 255, 255, 0.035);
  background: rgba(255, 255, 255, 0.035);
  box-shadow: none;
  cursor: default;
}

.ms-cell.is-revealed:hover {
  background: rgba(255, 255, 255, 0.045);
}

.ms-cell.is-mine {
  background: rgba(255, 107, 107, 0.18);
}

.ms-cell.is-exploded {
  background: rgba(255, 107, 107, 0.42);
}

.ms-cell.is-wrong {
  background: rgba(255, 107, 107, 0.24);
}

.ms-cell.is-flagged {
  color: var(--yellow);
  font-size: calc(var(--cell, 28px) * 0.48);
}

.ms-cell.n1 {
  color: #7dd3fc;
}
.ms-cell.n2 {
  color: #5ee6a8;
}
.ms-cell.n3 {
  color: #ff9ec7;
}
.ms-cell.n4 {
  color: #c4b5fd;
}
.ms-cell.n5 {
  color: #ffd166;
}
.ms-cell.n6 {
  color: #67e8f9;
}
.ms-cell.n7 {
  color: #f1f5f9;
}
.ms-cell.n8 {
  color: #a3aec9;
}

/* ============================================================
   打砖块
   ============================================================ */

.breakout-stage {
  max-width: clamp(270px, calc((100dvh - 260px) * 0.75), 540px);
}

/* ============================================================
   记忆翻牌
   ============================================================ */

.mem-board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  width: 100%;
}

.mem-card {
  position: relative;
  aspect-ratio: 1 / 1;
  padding: 0;
  border-radius: 14px;
  perspective: 700px;
  background: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.mem-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 0.38s cubic-bezier(0.2, 0.8, 0.3, 1);
}

.mem-card.is-open .mem-inner {
  transform: rotateY(180deg);
}

.mem-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 14px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.mem-face.front {
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: linear-gradient(
      145deg,
      rgba(124, 92, 255, 0.32),
      rgba(34, 211, 238, 0.14)
    ),
    rgba(255, 255, 255, 0.03);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16);
  font-size: 22px;
  font-weight: 800;
  color: rgba(255, 255, 255, 0.4);
}

.mem-face.front::after {
  content: "";
  position: absolute;
  inset: 18%;
  border: 1px dashed rgba(255, 255, 255, 0.16);
  border-radius: 8px;
}

.mem-face.back {
  transform: rotateY(180deg);
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: linear-gradient(
    145deg,
    rgba(255, 255, 255, 0.14),
    rgba(255, 255, 255, 0.05)
  );
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2);
  font-size: clamp(26px, 6.5vw, 40px);
}

.mem-card.is-matched .mem-face.back {
  border-color: rgba(94, 230, 168, 0.5);
  background: linear-gradient(
    145deg,
    rgba(94, 230, 168, 0.26),
    rgba(34, 211, 238, 0.1)
  );
  animation: matched-pulse 0.45s ease;
}

@keyframes matched-pulse {
  50% {
    transform: rotateY(180deg) scale(1.06);
  }
}

/* ============================================================
   俄罗斯方块
   ============================================================ */

.tetris-layout {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 14px;
  width: 100%;
}

.tetris-board-wrap {
  position: relative;
  width: min(330px, 74vw);
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.03);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.42);
}

.tetris-board-wrap > canvas {
  width: 100%;
  height: auto;
  border-radius: 10px;
  background: #080b16;
  touch-action: none;
}

.tetris-side {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 112px;
}

.tetris-box {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.035);
  text-align: center;
}

.tetris-box span {
  display: block;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: var(--muted-soft);
}

.tetris-box b {
  display: block;
  margin-top: 2px;
  font-family: var(--mono);
  font-size: 19px;
  font-variant-numeric: tabular-nums;
}

.tetris-box canvas {
  width: 100%;
  height: auto;
  margin-top: 4px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.24);
}

.tetris-controls {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
  max-width: 440px;
}

.tetris-controls .touch-btn {
  height: 52px;
  font-size: 17px;
}

@media (max-width: 600px) {
  .tetris-layout {
    flex-direction: column;
    align-items: center;
  }

  .tetris-side {
    flex-direction: row;
    width: 100%;
    max-width: 330px;
  }

  .tetris-side .tetris-box {
    flex: 1;
  }

  .tetris-box canvas {
    max-height: 62px;
    width: auto;
    margin-inline: auto;
  }

  .tetris-controls {
    position: sticky;
    bottom: 8px;
    z-index: 8;
    padding: 7px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: rgba(8, 10, 18, 0.88);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
  }
}

/* ============================================================
   打地鼠
   ============================================================ */

.whack-board {
  position: relative;
  width: 100%;
  max-width: 470px;
  margin-inline: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: radial-gradient(
      120% 100% at 50% 0%,
      rgba(132, 204, 22, 0.12),
      transparent 60%
    ),
    rgba(255, 255, 255, 0.025);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.4);
}

.whack-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: 100%;
}

.hole {
  position: relative;
  aspect-ratio: 1 / 1;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: radial-gradient(
    circle at 50% 28%,
    #1c2238,
    #0a0d19 72%
  );
  box-shadow: inset 0 14px 26px rgba(0, 0, 0, 0.6),
    inset 0 -2px 0 rgba(255, 255, 255, 0.05);
  overflow: hidden;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.hole::after {
  content: "";
  position: absolute;
  inset: 30% 6% 4%;
  border-radius: 50%;
  background: radial-gradient(
    ellipse at 50% 20%,
    rgba(255, 255, 255, 0.07),
    transparent 70%
  );
  pointer-events: none;
}

.mole {
  position: absolute;
  bottom: -4%;
  left: 50%;
  font-size: clamp(32px, 9vw, 52px);
  line-height: 1;
  pointer-events: none;
  transform: translate(-50%, 108%);
  transition: transform 0.16s cubic-bezier(0.2, 0.9, 0.3, 1.25);
  filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.55));
}

.hole.is-up {
  border-color: rgba(132, 204, 22, 0.45);
}

.hole.is-up .mole {
  transform: translate(-50%, 4%);
}

.hole.is-golden .mole {
  filter: drop-shadow(0 0 14px rgba(255, 209, 102, 0.95));
}

.hole.is-golden::after {
  background: radial-gradient(
    ellipse at 50% 45%,
    rgba(255, 209, 102, 0.2),
    transparent 68%
  );
}

.hole.is-hit {
  animation: hole-hit 0.2s ease;
}

.hit-pop {
  position: absolute;
  top: 34%;
  left: 50%;
  z-index: 3;
  font-size: 15px;
  font-weight: 800;
  color: var(--yellow);
  pointer-events: none;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
  animation: hit-float 0.55s ease forwards;
}

@keyframes hit-float {
  to {
    opacity: 0;
    transform: translate(-50%, -26px);
  }
}

@keyframes hole-hit {
  50% {
    transform: scale(0.96);
    background: radial-gradient(circle at 50% 50%, #2b3a22, #0a0d19 74%);
  }
}

/* ============================================================
   五子棋
   ============================================================ */

.gomoku-stage {
  max-width: clamp(300px, calc(100dvh - 320px), 580px);
}

.gomoku-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 30px;
  font-size: 14px;
  font-weight: 550;
  color: var(--muted);
}

.gomoku-status .stone-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #f4f5fa;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.3),
    0 0 10px rgba(255, 255, 255, 0.25);
}

.gomoku-status .stone-dot.is-black {
  background: #12151f;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.35);
}

/* ---------- 通用小屏适配 ---------- */

@media (max-width: 480px) {
  .game-shell {
    padding-top: 14px;
    gap: 11px;
  }

  .hud-item {
    padding: 7px 10px;
    border-radius: 12px;
  }

  .hud-item strong {
    font-size: 17px;
  }

  .stage {
    padding: 7px;
    border-radius: 16px;
  }

  .overlay-card {
    padding: 20px 17px;
  }

  .overlay h2 {
    font-size: 21px;
  }

  .mem-board {
    gap: 7px;
  }

  .whack-grid {
    gap: 7px;
  }
}
