/* ===== 基础与牌桌 ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --card-w: 84px;
  --card-h: 116px;
  --card-radius: 8px;
  --gap: 12px;
  --green-1: #1b7a4b;
  --green-2: #0f5c38;
  --card-bg: #fdfdfb;
  --card-border: #d8d8d2;
  --red: #d4302a;
  --black: #1c1c1c;
}

html, body { height: 100%; }

body {
  font-family: system-ui, -apple-system, "Microsoft YaHei", "PingFang SC", sans-serif;
  background: linear-gradient(160deg, var(--green-1), var(--green-2));
  color: #fff;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  user-select: none;
}

/* ===== 顶栏 ===== */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px 24px;
  flex-wrap: wrap;
}

.title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 2px;
  text-shadow: 0 1px 2px rgba(0,0,0,.3);
}

.stats { display: flex; gap: 18px; font-size: 14px; opacity: .95; }
.stats b { font-variant-numeric: tabular-nums; font-size: 16px; }

.controls { margin-left: auto; display: flex; gap: 10px; }

.btn {
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: rgba(255,255,255,.16);
  color: #fff;
  backdrop-filter: blur(4px);
  transition: background .15s, transform .1s;
}
.btn:hover { background: rgba(255,255,255,.28); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: #ffd34d; color: #1c1c1c; }
.btn-primary:hover { background: #ffdf73; }

/* ===== 棋盘 ===== */
.board {
  flex: 1;
  padding: 8px 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.top-area {
  display: flex;
  justify-content: space-between;
  gap: 24px;
}

.zone-label {
  font-size: 12px;
  opacity: .8;
  margin-bottom: 6px;
  letter-spacing: 1px;
}

.cells { display: flex; gap: var(--gap); }

/* 单元格（暂存/回收的空位） */
.slot {
  width: var(--card-w);
  height: var(--card-h);
  border-radius: var(--card-radius);
  border: 2px dashed rgba(255,255,255,.35);
  background: rgba(0,0,0,.12);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.slot.drop-ok { border-color: #ffd34d; background: rgba(255,211,77,.18); }

/* ===== 扑克牌 ===== */
.card {
  width: var(--card-w);
  height: var(--card-h);
  border-radius: var(--card-radius);
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  box-shadow: 0 2px 5px rgba(0,0,0,.25);
  position: relative;
  cursor: grab;
  transition: transform .12s ease, box-shadow .12s ease;
  color: var(--black);
  flex: none;
}
.card.red { color: var(--red); }
.card:hover { transform: translateY(-4px); box-shadow: 0 6px 12px rgba(0,0,0,.3); }
.card.selected { outline: 3px solid #ffd34d; outline-offset: 1px; transform: translateY(-4px); }
.card.dragging { opacity: .5; }

.card .corner {
  position: absolute;
  font-weight: 700;
  line-height: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.card .corner.tl { top: 6px; left: 7px; }
.card .corner.br { bottom: 6px; right: 7px; transform: rotate(180deg); }
.card .corner .rank { font-size: 17px; }
.card .corner .suit { font-size: 14px; }

.card .center-suit {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 38px;
  opacity: .9;
}

/* 牌背 */
.card.back {
  background: repeating-linear-gradient(45deg, #2f6fb0, #2f6fb0 6px, #2a629c 6px, #2a629c 12px);
  border-color: #24527e;
}

/* ===== 牌桌列 ===== */
.tableau {
  display: grid;
  grid-template-columns: repeat(8, var(--card-w));
  gap: var(--gap);
  justify-content: center;
}

.column {
  min-height: var(--card-h);
  display: flex;
  flex-direction: column;
}
.column.drop-ok { background: rgba(255,211,77,.12); border-radius: var(--card-radius); }

/* 列内叠放：用负 margin 让牌纵向重叠 */
.column .card { margin-top: -70px; }
.column .card:first-child { margin-top: 0; }

/* 列底占位（空列） */
.column.empty-slot {
  width: var(--card-w);
  height: var(--card-h);
  border-radius: var(--card-radius);
  border: 2px dashed rgba(255,255,255,.35);
  background: rgba(0,0,0,.12);
}

/* ===== 胜利弹窗 ===== */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal-mask[hidden] { display: none; }
.modal {
  background: #fff;
  color: #1c1c1c;
  border-radius: 16px;
  padding: 32px 40px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,.4);
  animation: pop .25s ease;
}
.modal h2 { font-size: 24px; margin-bottom: 12px; }
.modal p { font-size: 16px; margin-bottom: 20px; color: #444; }
.modal b { color: var(--green-1); }

@keyframes pop {
  from { transform: scale(.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* 玩法说明 */
.modal-help { max-width: 460px; text-align: left; }
.help-list { list-style: none; margin: 4px 0 20px; }
.help-list li {
  font-size: 14px;
  line-height: 1.7;
  color: #444;
  padding: 7px 0;
  border-bottom: 1px solid #eee;
}
.help-list li:last-child { border-bottom: none; }
.help-list b { color: var(--green-1); }

/* ===== 响应式 ===== */
@media (max-width: 760px) {
  :root { --card-w: 60px; --card-h: 84px; --gap: 8px; }
  .column .card { margin-top: -50px; }
  .card .center-suit { font-size: 26px; }
  .card .corner .rank { font-size: 13px; }
  .card .corner .suit { font-size: 11px; }
  .title { font-size: 18px; }
}

/* ===== 提示高亮 ===== */
.card.hint-src {
  animation: hintPulse 1s ease-in-out infinite;
  box-shadow: 0 0 0 3px #ffd34d, 0 6px 6px rgba(0,0,0,.35);
}
@keyframes hintPulse {
  0%, 100% { box-shadow: 0 0 0 3px #ffd34d, 0 6px 6px rgba(0,0,0,.35); }
  50% { box-shadow: 0 0 0 5px #ffe48a, 0 6px 6px rgba(0,0,0,.35); }
}
.column.hint-tgt, .slot.hint-tgt {
  outline: 3px solid #4dd0ff;
  outline-offset: 2px;
  border-radius: var(--card-radius);
}

/* ===== 轻提示 toast ===== */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: rgba(0,0,0,.8);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 60;
  pointer-events: none;
  animation: pop .2s ease;
}
.toast[hidden] { display: none; }

/* =========================================================
 * 屏幕切换与菜单
 * ========================================================= */
.screen {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 100vh;
}
.screen.hidden { display: none; }

/* 主菜单 */
.menu-screen { align-items: center; justify-content: center; }
.menu-card { text-align: center; padding: 40px; }
.menu-title {
  font-size: 40px;
  font-weight: 800;
  letter-spacing: 3px;
  text-shadow: 0 2px 6px rgba(0,0,0,.3);
  margin-bottom: 8px;
}
.menu-sub { opacity: .9; margin-bottom: 36px; font-size: 16px; }
.menu-buttons { display: flex; gap: 28px; flex-wrap: wrap; justify-content: center; }
.menu-btn {
  width: 220px;
  padding: 34px 22px;
  border: none;
  border-radius: 18px;
  cursor: pointer;
  background: rgba(255,255,255,.16);
  color: #fff;
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  transition: transform .12s ease, background .15s ease, box-shadow .15s ease;
  box-shadow: 0 6px 18px rgba(0,0,0,.18);
}
.menu-btn:hover {
  background: rgba(255,255,255,.28);
  transform: translateY(-5px);
  box-shadow: 0 12px 26px rgba(0,0,0,.28);
}
.menu-emoji { font-size: 54px; line-height: 1; }
.menu-name { font-size: 22px; font-weight: 700; }
.menu-desc { font-size: 13px; opacity: .85; }

.menu-extra-btn {
  margin-top: 34px;
  border: 2px solid rgba(255,255,255,.5);
  border-radius: 999px;
  padding: 12px 34px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  background: transparent;
  color: #fff;
  transition: background .15s, transform .1s;
}
.menu-extra-btn:hover { background: rgba(255,255,255,.18); }
.menu-extra-btn:active { transform: translateY(1px); }

/* 胜利弹窗中的排名提示 */
.rank-line {
  font-size: 16px;
  font-weight: 700;
  color: #e0892a !important;
  margin-bottom: 18px;
}

/* 排行榜弹窗 */
.modal-lb { max-width: 560px; width: 92vw; text-align: center; }
.lb-note { font-size: 13px; color: #888; margin-bottom: 18px; }
.lb-body {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px 22px;
  text-align: left;
  max-height: 60vh;
  overflow: auto;
  margin-bottom: 18px;
}
.lb-section { min-width: 150px; }
.lb-section h3 {
  font-size: 15px;
  color: var(--green-1);
  margin-bottom: 8px;
  border-bottom: 2px solid #eee;
  padding-bottom: 4px;
}
.lb-list { list-style: none; }
.lb-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  padding: 5px 8px;
  border-radius: 8px;
}
.lb-list li:nth-child(odd) { background: #f5f7f5; }
.lb-list li:nth-child(1) .lb-rank { background: #ffd34d; color: #1c1c1c; }
.lb-rank {
  width: 22px; height: 22px;
  flex: none;
  border-radius: 50%;
  background: #e6e6e6;
  color: #555;
  font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.lb-time { font-weight: 700; font-variant-numeric: tabular-nums; }
.lb-meta { margin-left: auto; color: #999; font-size: 12px; }
.lb-empty { font-size: 13px; color: #bbb; padding: 6px 8px; }
.lb-actions { display: flex; gap: 10px; justify-content: center; }

/* =========================================================
 * 扫雷
 * ========================================================= */
/* =========================================================
 * 扫雷
 * ========================================================= */
.ms-stats {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 16px;
}

/* LED 数码盒：经典黑底红字 */
.ms-led {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 58px;
  padding: 4px 10px;
  background: #181818;
  border: 2px solid #000;
  border-radius: 6px;
  box-shadow: inset 0 1px 4px rgba(0,0,0,.7), 0 1px 0 rgba(255,255,255,.15);
}
.ms-led b {
  font-family: "Courier New", Consolas, monospace;
  font-weight: 700;
  font-size: 20px;
  color: #ff4136;
  letter-spacing: 2px;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 5px rgba(255,65,54,.55);
}

/* 笑脸重开按钮（经典 Windows 扫雷） */
.ms-face {
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 9px;
  border: 2px solid;
  border-color: #f4f4f4 #6f6f6f #6f6f6f #f4f4f4;
  background: #d7d7d7;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform .08s, background .12s;
  box-shadow: 0 2px 4px rgba(0,0,0,.25);
}
.ms-face:hover { background: #e2e2e2; }
.ms-face:active { transform: scale(.93); border-color: #6f6f6f #f4f4f4 #f4f4f4 #6f6f6f; }

.ms-hint-text {
  font-size: 13px;
  opacity: .88;
  margin-left: auto;
  letter-spacing: .3px;
}

.ms-toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 24px 16px;
  flex-wrap: wrap;
}
.ms-levels { display: flex; gap: 8px; }
.ms-level-btn {
  border: none;
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: rgba(255,255,255,.16);
  color: #fff;
  transition: background .15s, transform .1s;
}
.ms-level-btn:hover { background: rgba(255,255,255,.28); }
.ms-level-btn:active { transform: translateY(1px); }
.ms-level-btn.active { background: #ffd34d; color: #1c1c1c; }

.ms-board-wrap {
  flex: 1;
  overflow: auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 10px 24px 28px;
}
/* 经典灰色棋盘面板（凸起外框） */
.ms-board {
  --ms-cell: 30px;
  display: grid;
  gap: 0;
  grid-auto-rows: var(--ms-cell);
  align-content: start;
  background: #bdbdbd;
  border: 4px solid;
  border-color: #7b7b7b #ffffff #ffffff #7b7b7b;
  padding: 5px;
  width: max-content;
  box-shadow: 0 8px 22px rgba(0,0,0,.3);
  margin: auto 0;
}
.ms-cell {
  width: var(--ms-cell);
  height: var(--ms-cell);
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  user-select: none;
  background: #c6c6c6;
  border: 3px outset #e6e6e6;
  color: #1c1c1c;
  line-height: 1;
}
.ms-cell:hover:not(.revealed) { background: #d2d2d2; }
.ms-cell:active:not(.revealed) { border-style: inset; background: #b8b8b8; }
.ms-cell.revealed {
  background: #d9d9d9;
  border: 1px solid #a6a6a6;
  cursor: default;
}
.ms-cell.flag { color: #d4302a; }
.ms-cell.mine { background: #d4302a; color: #fff; border: 1px solid #a0261f; }
.ms-cell.exploded { background: #ff5a4d; }
.ms-cell.n1 { color: #1976d2; }
.ms-cell.n2 { color: #2e7d32; }
.ms-cell.n3 { color: #d32f2f; }
.ms-cell.n4 { color: #512da8; }
.ms-cell.n5 { color: #b5532a; }
.ms-cell.n6 { color: #0097a7; }
.ms-cell.n7 { color: #37474f; }
.ms-cell.n8 { color: #607d8b; }

/* 扫雷移动端：格子略小 */
@media (max-width: 760px) {
  .menu-title { font-size: 30px; }
  .menu-buttons { gap: 16px; }
  .menu-btn { width: 150px; padding: 22px 14px; }
  .menu-emoji { font-size: 40px; }
  .menu-name { font-size: 18px; }
  .ms-board { --ms-cell: 26px; padding: 4px; }
  .ms-cell { font-size: 14px; border-width: 2px; }
  .ms-hint-text { width: 100%; margin-left: 0; order: 3; }
  .ms-led { min-width: 46px; padding: 3px 7px; }
  .ms-led b { font-size: 17px; }
  .ms-face { width: 36px; height: 36px; font-size: 19px; }
}

/* =========================================================
 * 通用游戏屏（2048 / 贪吃蛇 / 俄罗斯方块）
 * ========================================================= */
.game-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 12px 16px 28px;
  overflow: auto;
}
.game-panel {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  flex-wrap: wrap;
  justify-content: center;
}
.game-side {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 130px;
}
.game-info {
  background: rgba(255, 255, 255, .14);
  border-radius: 12px;
  padding: 10px 14px;
  color: #fff;
  text-align: center;
}
.game-info .lab { font-size: 12px; opacity: .85; margin-bottom: 4px; }
.game-info .val {
  font-size: 22px; font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/* ---- 2048 ---- */
.g2048-board {
  position: relative;
  background: #bbada0;
  border-radius: 10px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, .3);
  cursor: grab;
  user-select: none;
  touch-action: none;
}
.g2048-board:active { cursor: grabbing; }
.g2048-grid { display: grid; position: relative; z-index: 1; }
.g2048-cell { background: rgba(238, 228, 218, .5); border-radius: 6px; }
.g2048-tiles { position: absolute; inset: 0; z-index: 2; pointer-events: none; }
.g2048-tile {
  position: absolute; top: 0; left: 0;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; border-radius: 6px;
  transition: transform .12s ease;
}
.t2   { background: #eee4da; color: #776e65; }
.t4   { background: #ede0c8; color: #776e65; }
.t8   { background: #f2b179; color: #fff; }
.t16  { background: #f59563; color: #fff; }
.t32  { background: #f67c5f; color: #fff; }
.t64  { background: #f65e3b; color: #fff; }
.t128 { background: #edcf72; color: #fff; }
.t256 { background: #edcc61; color: #fff; }
.t512 { background: #edc850; color: #fff; }
.t1024{ background: #edc53f; color: #fff; }
.t2048{ background: #edc22e; color: #fff; }
.t-super { background: #3c3a32; color: #fff; }

/* ---- 画布类游戏 ---- */
.snake-canvas, .tetris-canvas, .tetris-next {
  border-radius: 10px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, .3);
  display: block;
}
.tetris-canvas { cursor: pointer; }
.tetris-next { background: #0f3d28; }

/* ---- 屏幕方向键 dpad ---- */
.dpad { display: grid; gap: 8px; }
.snake-dpad {
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(3, 52px);
}
.snake-dpad .up    { grid-area: 1 / 2; }
.snake-dpad .left  { grid-area: 2 / 1; }
.snake-dpad .rot   { grid-area: 2 / 2; }
.snake-dpad .right { grid-area: 2 / 3; }
.snake-dpad .down  { grid-area: 3 / 2; }

.tetris-dpad {
  grid-template-columns: repeat(3, 48px);
  grid-template-rows: repeat(2, 48px);
}
.tetris-dpad .left  { grid-column: 1; grid-row: 1; }
.tetris-dpad .rot   { grid-column: 2; grid-row: 1; }
.tetris-dpad .right { grid-column: 3; grid-row: 1; }
.tetris-dpad .down  { grid-column: 2; grid-row: 2; }
.tetris-dpad .drop  { grid-column: 3; grid-row: 2; }

.dpad-btn {
  border: none;
  border-radius: 10px;
  background: rgba(255, 255, 255, .18);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  transition: background .15s, transform .1s;
}
.dpad-btn:hover { background: rgba(255, 255, 255, .3); }
.dpad-btn:active { transform: translateY(1px); }

/* ---- 新游戏移动端适配 ---- */
@media (max-width: 760px) {
  .menu-btn { width: 150px; padding: 22px 14px; }
  .menu-emoji { font-size: 40px; }
  .menu-name { font-size: 18px; }
  .game-panel { gap: 14px; }
  .snake-dpad { grid-template-columns: repeat(3, 48px); grid-template-rows: repeat(3, 48px); }
  .tetris-dpad { grid-template-columns: repeat(3, 44px); grid-template-rows: repeat(2, 44px); }
  .dpad-btn { font-size: 18px; }
  .game-side { min-width: 110px; }
  .game-info .val { font-size: 18px; }
}
