/**
 * game.css - 「麻将胡了」界面样式
 *
 * 约定：
 *   - 复用 h5-framework 的 tokens.css 变量，本文件只补充 --tile-* 牌面变量
 *   - 动画只使用 transform / opacity，避免触发布局抖动
 *   - 牌面 / 牌背全部用 CSS 渐变绘制，不引用任何外部图片
 */

:root {
  /* 牌面与牌背配色（立体感来自渐变 + 边框 + 阴影） */
  --tile-radius: 12px;
  --tile-edge: #cdbf9f;
  --tile-face-bg: linear-gradient(160deg, #fffdf6 0%, #f3ead3 55%, #e6d9b8 100%);
  --tile-face-ink: #2a2831;
  --tile-suit-ink: #b0402f;
  --tile-back-bg: linear-gradient(160deg, #2f8a63 0%, #1f6247 55%, #174b36 100%);
  --tile-back-line: rgba(255, 255, 255, 0.3);
  --tile-shadow: 0 10px 20px rgba(0, 0, 0, 0.35);
  --tile-shadow-hover: 0 16px 28px rgba(0, 0, 0, 0.45);
  /* 超宽屏下单张牌的宽度上限，避免牌面被拉得过大、比例失调 */
  --tile-max: 96px;
}

/* 通用容器 */
.wrap {
  width: min(920px, 100% - var(--sp-5) * 2);
  margin: 0 auto;
}

/* 顶部栏 */
.topbar {
  padding: var(--sp-4) 0;
}

.topbar__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
}

.brand__title {
  font-size: var(--fs-lg);
  font-weight: 800;
}

.brand__subtitle {
  display: block;
  font-size: var(--fs-sm);
  color: var(--c-text-dim);
}

.lang {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--fs-sm);
  color: var(--c-text-dim);
  white-space: nowrap;
}

.lang select {
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  background: var(--c-surface-2);
  color: var(--c-text);
  border: 1px solid var(--c-border);
}

/* 统计区 */
.hud {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--sp-3);
  margin-bottom: var(--sp-5);
}

.hud__item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--sp-3) var(--sp-4);
}

.hud__num {
  font-size: var(--fs-xl);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.hud__label {
  font-size: var(--fs-sm);
  color: var(--c-text-dim);
}

/* 主舞台：牌桌 + 胡牌区 */
.stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 190px;
  gap: var(--sp-5);
  align-items: start;
}

/* 牌桌 */
.board {
  position: relative;
}

.board__grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--sp-3);
}

/* 窄屏：4 列 x 5 行 */
@media (max-width: 560px) {
  .board__grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* 牌堆（发牌飞行的起点），发牌结束后淡出隐藏 */
.board__deck {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 60px;
  height: 82px;
  transform: translate(-50%, -50%);
  z-index: 3;
  pointer-events: none;
}

.board__deck.is-gone {
  display: none;
}

.deck__layer,
.deck__top {
  position: absolute;
  inset: 0;
  border-radius: var(--tile-radius);
  background: var(--tile-back-bg);
  border: 1px solid rgba(0, 0, 0, 0.28);
  box-shadow: var(--tile-shadow);
}

.deck__layer:nth-child(1) {
  transform: translate(-7px, 7px);
}

.deck__layer:nth-child(2) {
  transform: translate(-3.5px, 3.5px);
}

.deck__top::after {
  content: "";
  position: absolute;
  inset: 16%;
  border-radius: 8px;
  border: 2px solid var(--tile-back-line);
  background: repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.16) 0 6px, transparent 6px 12px);
}

/* 单张牌：格位 / 位移层 */
.tile {
  position: relative;
  width: 100%;
  max-width: var(--tile-max);
  justify-self: center;
  aspect-ratio: 3 / 4;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  perspective: 800px;
  -webkit-tap-highlight-color: transparent;
}

.tile.is-hidden {
  opacity: 0;
}

.tile.is-matched {
  opacity: 0;
  pointer-events: none;
}

/* 翻转层：真正的 3D 翻转 */
.tile__flip {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 480ms var(--ease-out);
  will-change: transform;
}

.tile.is-flipped .tile__flip {
  transform: rotateY(180deg);
}

/* 牌面：正反两面背面不可见 */
.tile__face {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--tile-radius);
  box-shadow: var(--tile-shadow);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

/* 正面：点数 + 花色 */
.tile__face--front {
  flex-direction: column;
  gap: 2px;
  background: var(--tile-face-bg);
  color: var(--tile-face-ink);
  border: 1px solid var(--tile-edge);
  transform: rotateY(180deg);
}

.tile__rank {
  font-size: clamp(20px, 4.4vw, 30px);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.tile__suit {
  font-size: clamp(18px, 4vw, 26px);
  font-weight: 700;
  line-height: 1;
  color: var(--tile-suit-ink);
}

/* 背面：牌背纹样（纯 CSS） */
.tile__face--back {
  background: var(--tile-back-bg);
  border: 1px solid rgba(0, 0, 0, 0.28);
}

.tile__face--back::after {
  content: "";
  position: absolute;
  inset: 16%;
  border-radius: 8px;
  border: 2px solid var(--tile-back-line);
  background: repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.16) 0 6px, transparent 6px 12px);
}

/* 悬停微交互（仅未翻开的牌） */
@media (hover: hover) {
  .tile:not(.is-flipped):not(.is-matched):hover .tile__face--back {
    transform: translateY(-4px);
    box-shadow: var(--tile-shadow-hover);
  }
}

/* 胡牌区 */
.hule {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4);
}

.hule__label {
  font-size: var(--fs-sm);
  color: var(--c-text-dim);
}

.hule__pile {
  width: 60px;
  height: 82px;
  border-radius: var(--radius-md);
  border: 2px dashed var(--c-border);
  background: rgba(255, 255, 255, 0.03);
}

.hule__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

.hule__chip {
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--c-border);
  background: var(--c-primary-soft);
  font-size: var(--fs-sm);
}

/* 操作区 */
.controls {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  flex-wrap: wrap;
  margin-top: var(--sp-5);
}

.hint {
  display: flex;
  gap: var(--sp-3);
  flex-wrap: wrap;
  font-size: var(--fs-sm);
  color: var(--c-text-dim);
}

/* 连击浮字层 */
.combo-layer {
  position: fixed;
  left: 0;
  right: 0;
  top: 20%;
  height: 0;
  z-index: 40;
  pointer-events: none;
}

.combo {
  position: absolute;
  left: 50%;
  top: 0;
  white-space: nowrap;
  font-size: var(--fs-xl);
  font-weight: 800;
  color: var(--c-accent);
  text-shadow: 0 4px 16px rgba(0, 0, 0, 0.55);
  opacity: 0; /* 起始透明，由 tween 首帧接管 */
  will-change: transform, opacity;
}

/* 结算面板 */
.result {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
  background: rgba(8, 10, 20, 0.72);
  backdrop-filter: blur(4px);
}

.result[hidden] {
  display: none;
}

.result__card {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  width: min(360px, 100%);
  padding: var(--sp-6);
  text-align: center;
  animation: result-pop var(--dur-base) var(--ease-out);
}

.result__title {
  font-size: var(--fs-xl);
  font-weight: 800;
}

.result__subtitle {
  color: var(--c-text-dim);
  font-size: var(--fs-sm);
}

.result__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-sm);
  background: var(--c-surface-2);
}

.result__value {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.result__record {
  color: var(--c-accent);
  font-weight: 700;
}

.result__record[hidden] {
  display: none;
}

@keyframes result-pop {
  from {
    transform: scale(0.86);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

/* 窄屏：主舞台单列，胡牌区置于牌桌下方 */
@media (max-width: 760px) {
  .stage {
    grid-template-columns: 1fr;
  }

  .hule {
    flex-direction: row;
    justify-content: center;
  }
}

@media (max-width: 560px) {
  .hud {
    grid-template-columns: repeat(2, 1fr);
  }
}
