/* 像素风麻将 - 全局样式 */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}

body {
  background: #0a0a0a;
  color: #e0e0e0;
  font-family: "PingFang SC", "Noto Sans SC", "Microsoft YaHei", 'Courier New', monospace;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
}

#game-canvas {
  display: none;
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* ===== 覆盖层 ===== */
.overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.menu-box {
  background: linear-gradient(135deg, #1a3a2a, #0d2d1d);
  border: 3px solid #2a6a3a;
  padding: 30px 24px;
  max-width: 360px;
  width: 90%;
  text-align: center;
  image-rendering: pixelated;
}

.pixel-title {
  font-size: 28px;
  color: #ffd54f;
  text-shadow: 2px 2px 0 #b8860b, 4px 4px 0 rgba(0,0,0,0.5);
  margin-bottom: 4px;
  letter-spacing: 4px;
}

.subtitle {
  color: #81c784;
  font-size: 14px;
  margin-bottom: 24px;
}

/* ===== 按钮 ===== */
.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

.pixel-btn {
  font-family: "PingFang SC", "Noto Sans SC", "Microsoft YaHei", 'Courier New', monospace;
  font-size: 16px;
  font-weight: bold;
  padding: 12px 24px;
  border: none;
  cursor: pointer;
  image-rendering: pixelated;
  letter-spacing: 2px;
  transition: transform 0.1s;
  position: relative;
}

.pixel-btn:active {
  transform: translateY(2px);
}

.btn-primary {
  background: #d32f2f;
  color: #fff;
  border-bottom: 4px solid #9a0007;
  border-right: 2px solid #9a0007;
  border-top: 2px solid #ff6659;
  border-left: 2px solid #ff6659;
}

.btn-secondary {
  background: #1565c0;
  color: #fff;
  border-bottom: 4px solid #003c8f;
  border-right: 2px solid #003c8f;
  border-top: 2px solid #5e92f3;
  border-left: 2px solid #5e92f3;
}

.btn-small {
  font-size: 12px;
  padding: 6px 16px;
}

/* ===== 用户信息 ===== */
.user-info {
  margin-top: 12px;
  color: #aaa;
  font-size: 13px;
}

/* ===== 排行榜 ===== */
.leaderboard-box {
  max-height: 80vh;
  overflow-y: auto;
}

.rank-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  justify-content: center;
}

.tab-btn {
  background: #333;
  color: #aaa;
  border: 2px solid #555;
  padding: 6px 12px;
  font-family: "PingFang SC", "Noto Sans SC", "Microsoft YaHei", 'Courier New', monospace;
  font-size: 12px;
  cursor: pointer;
}

.tab-btn.active {
  background: #2e7d32;
  color: #fff;
  border-color: #4caf50;
}

.rank-list {
  text-align: left;
  margin-bottom: 16px;
  max-height: 300px;
  overflow-y: auto;
}

.rank-row {
  display: flex;
  padding: 6px 8px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  align-items: center;
}

.rank-pos {
  width: 30px;
  font-size: 16px;
}

.rank-name {
  flex: 1;
  font-size: 13px;
  color: #ccc;
}

.rank-val {
  font-size: 14px;
  color: #ffd54f;
  font-weight: bold;
}

.empty {
  text-align: center;
  color: #666;
  padding: 20px;
}

/* ===== 统计 ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 16px 0;
}

.stat-item {
  text-align: center;
}

.stat-val {
  display: block;
  font-size: 22px;
  color: #ffd54f;
  font-weight: bold;
}

.stat-label {
  display: block;
  font-size: 11px;
  color: #888;
  margin-top: 4px;
}

/* ===== 操作按钮 ===== */
.action-buttons {
  position: fixed;
  bottom: 90px;
  left: 0; right: 0;
  display: none;
  justify-content: center;
  gap: 12px;
  z-index: 50;
  padding: 0 20px;
}

.action-btn {
  font-size: 18px;
  padding: 12px 24px;
  min-width: 70px;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.btn-hu { background: #d32f2f; color: #fff; border-bottom: 3px solid #9a0007; }
.btn-peng { background: #f57c00; color: #fff; border-bottom: 3px solid #bb4d00; }
.btn-gang { background: #7b1fa2; color: #fff; border-bottom: 3px solid #4a0072; }
.btn-pass { background: #455a64; color: #fff; border-bottom: 3px solid #1c313a; }

/* ===== 结算 ===== */
.result-box h2 {
  font-size: 24px;
  margin-bottom: 16px;
}

.result-box.win h2 {
  color: #ffd54f;
  text-shadow: 2px 2px 0 #b8860b;
}

.fan-list {
  margin: 12px 0;
}

.fan-item {
  padding: 4px 0;
  color: #81c784;
  font-size: 14px;
}

.fan-total {
  font-size: 18px;
  color: #ffd54f;
  font-weight: bold;
  margin: 8px 0 16px;
}

.result-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
}

/* ===== 滚动条 ===== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #444; }

/* ===== 玩法选择 ===== */
.rule-select { display: flex; gap: 8px; justify-content: center; margin: 12px 0; }
.rule-btn { padding: 8px 16px; border: 2px solid #555; background: #333; color: #aaa; font-size: 14px; cursor: pointer; font-family: "PingFang SC", "Noto Sans SC", monospace; }
.rule-btn.active { border-color: #ffd54f; background: #4a3f00; color: #ffd54f; }

/* ===== 换三张 ===== */
.swap-box { max-width: 360px; }
.swap-tiles { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px; margin: 12px 0; max-height: 200px; overflow-y: auto; }
.swap-tiles canvas { border: 1px solid transparent; }

/* ===== 定缺 ===== */
.lack-box { max-width: 300px; }
.lack-buttons { display: flex; gap: 12px; justify-content: center; margin: 16px 0; }
.lack-btn { width: 72px; height: 72px; font-size: 28px; border: 3px solid #fff; cursor: pointer; font-family: "PingFang SC", "Noto Sans SC", monospace; }
.lack-btn:hover { transform: scale(1.1); }
