/* =========================================================
   2.5D 麻将牌系统 - 基于 CSS 3D Transform
   支持 3 种尺寸: large (手牌), medium (弃牌河/副露), small (花槽/大屏 AI)
   ========================================================= */

body {
  margin: 0;
  color: #fff;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
* { box-sizing: border-box; }

/* =========================================================
   2.5D 牌体基类
   ========================================================= */

.mj {
  position: relative;
  cursor: pointer;
  transition: transform 0.15s;
  flex-shrink: 0;
  vertical-align: middle;
}
.mj:hover { transform: translateY(-6px); }
.mj:active { transform: translateY(-2px); }
.mj.locked { opacity: 0.55; filter: saturate(0.4) brightness(0.85); cursor: not-allowed; }
.mj.locked:hover { transform: none; }

/* 正面 (装 SVG) */
.mj .mj-face {
  position: absolute;
  inset: 0;
  border-radius: 5px;
  overflow: hidden;
  background: linear-gradient(178deg, #fffef0 0%, #f8e8c8 50%, #e8d4a0 100%);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,1),
    inset 0 -2px 5px rgba(160,130,80,0.4),
    inset 1.5px 0 0 rgba(0,0,0,0.05),
    inset -1.5px 0 0 rgba(0,0,0,0.08);
}
.mj .mj-face svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* 牌底厚边 */
.mj .mj-edge-bottom {
  position: absolute;
  left: 0; right: 0; bottom: -3px;
  height: 3px;
  background: linear-gradient(180deg, #c9a566 0%, #8a6028 60%, #5a3a14 100%);
  border-radius: 0 0 4px 4px;
  z-index: -1;
}
.mj .mj-edge-right {
  position: absolute;
  top: 0; bottom: -2px; right: -2px;
  width: 2px;
  background: linear-gradient(90deg, #c9a566 0%, #8a6028 100%);
  border-radius: 0 4px 4px 0;
  z-index: -1;
}

/* 牌背 */
.mj.back .mj-face {
  background: #1d6336;
  box-shadow: inset 0 0 0 2px #0a3418, inset 0 0 0 4px #1d6336;
}

/* drawn 状态 */
.mj.drawn { transform: translateY(-4px); filter: drop-shadow(0 0 12px rgba(245,158,11,0.7)); }
.mj.drawn .mj-face {
  outline: 2px solid #f59e0b;
  outline-offset: -1px;
  background: linear-gradient(178deg, #fff8d8 0%, #f8e8a8 50%, #e8c870 100%);
}
.mj.newest .mj-face {
  outline: 1.5px solid #ef4444;
  outline-offset: -1px;
}

/* 投影 */
.mj { filter: drop-shadow(0 3px 4px rgba(0,0,0,0.5)); }

/* === 旧的 2.5D 多面 (保留作 fallback, 新 makeTile 不再生成这些元素) === */
.mj .mj-old-face {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, #fffef8 0%, #f4eedd 88%, #e8dcb8 100%);
  border-radius: 5px 5px 3px 3px;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,1),
    inset 1px 0 0 rgba(0,0,0,0.04),
    inset -1px 0 0 rgba(0,0,0,0.08),
    inset 0 -1px 0 rgba(130,100,50,0.15);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: 'Ma Shan Zheng', 'STKaiti', 'KaiTi', serif;
  overflow: hidden;
}

/* 顶面 - 浅黄色薄边 */
.mj .mj-top {
  position: absolute;
  left: 0; right: 0; top: 0;
  background: linear-gradient(180deg, #fefce8 0%, #e8dcb8 100%);
  transform-origin: top;
  border-radius: 5px 5px 0 0;
}

/* 右侧 */
.mj .mj-right {
  position: absolute;
  top: 0; bottom: 0; right: 0;
  background: linear-gradient(90deg, #d9c496 0%, #a88d58 100%);
  transform-origin: right;
}

/* 左侧 */
.mj .mj-left {
  position: absolute;
  top: 0; bottom: 0; left: 0;
  background: linear-gradient(90deg, #a88d58 0%, #d9c496 100%);
  transform-origin: left;
}

/* 底面 - 深色厚底 */
.mj .mj-bottom {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: linear-gradient(180deg, #b89a60 0%, #7a5f30 100%);
  transform-origin: bottom;
}

/* 投影 */
.mj::after {
  content: '';
  position: absolute;
  background: radial-gradient(ellipse, rgba(0,0,0,0.55) 0%, transparent 70%);
  filter: blur(3px);
  pointer-events: none;
  z-index: -1;
}

/* 刚摸的牌 - 金光 */
.mj.drawn .mj-face {
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,1),
    0 0 0 2px #fbbf24,
    0 0 20px rgba(251,191,36,0.8);
}

/* 锁定 (非自己回合) */
.mj.locked {
  opacity: 0.55;
  filter: saturate(0.5);
  cursor: not-allowed;
}
.mj.locked:active { transform: rotateX(8deg); }
.mj.locked:hover { transform: rotateX(8deg); }

/* 不可点的静态展示 */
.mj.static { cursor: default; }
.mj.static:hover { transform: rotateX(8deg); }

/* =========================================================
   尺寸 1: large (手牌主尺寸 - 手机)
   ========================================================= */
.mj.large {
  width: 47px;
  height: 64px;
  margin-right: 2px;
  margin-bottom: 10px;
}
.mj.large .mj-face { transform: translateZ(3.5px); }
.mj.large .mj-top { height: 7px; transform: rotateX(-90deg) translateZ(3.5px); }
.mj.large .mj-right { width: 7px; transform: rotateY(90deg) translateZ(3.5px); }
.mj.large .mj-left { width: 7px; transform: rotateY(-90deg) translateZ(3.5px); }
.mj.large .mj-bottom { height: 7px; transform: rotateX(90deg) translateZ(3.5px); }
.mj.large::after { left: 2px; right: 0; bottom: -5px; height: 6px; }
.mj.large .face-num {
  font-size: 26px;
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 1px 0 #fff, 0 -1px 0 rgba(0,0,0,0.25);
}
.mj.large .face-suit {
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  margin-top: 2px;
}
.mj.large .face-word {
  font-size: 36px;
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 1px 0 #fff, 0 -1px 0 rgba(0,0,0,0.3);
}

/* =========================================================
   尺寸 2: medium (弃牌河/副露组 - 大屏)
   ========================================================= */
.mj.medium {
  width: 32px;
  height: 44px;
  margin-right: 2px;
  margin-bottom: 6px;
}
.mj.medium .mj-face { transform: translateZ(3px); }
.mj.medium .mj-top { height: 5px; transform: rotateX(-90deg) translateZ(3px); }
.mj.medium .mj-right { width: 5px; transform: rotateY(90deg) translateZ(3px); }
.mj.medium .mj-left { width: 5px; transform: rotateY(-90deg) translateZ(3px); }
.mj.medium .mj-bottom { height: 5px; transform: rotateX(90deg) translateZ(3px); }
.mj.medium::after { left: 2px; right: 0; bottom: -3px; height: 4px; }
.mj.medium .face-num {
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
}
.mj.medium .face-suit {
  font-size: 8px;
  font-weight: 800;
  line-height: 1;
  margin-top: 1px;
}
.mj.medium .face-word {
  font-size: 24px;
  font-weight: 900;
  line-height: 1;
}

/* =========================================================
   尺寸 3: small (花槽 / 大屏 AI 牌背)
   ========================================================= */
.mj.small {
  width: 22px;
  height: 30px;
  margin-right: 1px;
  margin-bottom: 3px;
}
.mj.small .mj-face { transform: translateZ(2px); }
.mj.small .mj-top { height: 3px; transform: rotateX(-90deg) translateZ(2px); }
.mj.small .mj-right { width: 3px; transform: rotateY(90deg) translateZ(2px); }
.mj.small .mj-left { width: 3px; transform: rotateY(-90deg) translateZ(2px); }
.mj.small .mj-bottom { height: 3px; transform: rotateX(90deg) translateZ(2px); }
.mj.small::after { left: 1px; right: 0; bottom: -2px; height: 3px; }
.mj.small .face-num {
  font-size: 13px;
  font-weight: 900;
  line-height: 1;
}
.mj.small .face-suit {
  font-size: 6px;
  font-weight: 800;
  line-height: 1;
  margin-top: 0.5px;
}
.mj.small .face-word {
  font-size: 16px;
  font-weight: 900;
  line-height: 1;
}

/* =========================================================
   牌背 (AI 玩家的牌显示为背面)
   ========================================================= */
.mj.back .mj-face {
  background:
    radial-gradient(ellipse at 30% 20%, #2d7a4a 0%, transparent 50%),
    linear-gradient(180deg, #1b5c2a 0%, #0e3816 100%);
  box-shadow:
    inset 0 1px 0 rgba(120,200,140,0.3),
    inset 0 -1px 0 rgba(0,0,0,0.4),
    inset 1px 0 0 rgba(0,0,0,0.15),
    inset -1px 0 0 rgba(0,0,0,0.15);
}
/* 牌背中央的金色标志 */
.mj.back .mj-face::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 50%;
  height: 50%;
  border: 1.5px solid rgba(253,224,71,0.4);
  border-radius: 2px;
  transform: translate(-50%, -50%) rotate(45deg);
  box-shadow: 0 0 6px rgba(253,224,71,0.3);
}
.mj.back.small .mj-face::before { border-width: 1px; }

/* 白板 - 特殊处理 */
.mj .baiban {
  width: 55%;
  height: 70%;
  border: 2px solid #1b4e8e;
  border-radius: 2px;
}
.mj.medium .baiban { border-width: 1.5px; }
.mj.small .baiban { border-width: 1px; }

/* =========================================================
   特效叠加
   ========================================================= */
.mj.highlight .mj-face {
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,1),
    0 0 0 2px #fbbf24,
    0 0 14px rgba(251,191,36,0.6);
}

/* 弃牌河里的刚打出的牌高亮 */
.mj.newest .mj-face {
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,1),
    0 0 0 1.5px #ef4444,
    0 0 10px rgba(239,68,68,0.5);
}
