/* =====================================================================
   games.css —— 苗泽霖个人站 · 游戏模块样式
   全部规则作用域限定在 .zgame 命名空间内；背景透明，适配站点深色区。
   强调色仅用：#a9bd8e（月桂绿）/ #f2efe9（近白）；圆角 12–14px；
   边框统一 1px rgb(242 239 233 / .09)；文字对比度 ≥ 4.5:1。
   ===================================================================== */

.zgame {
  --zg-accent: #a9bd8e;
  --zg-ink: #f2efe9;
  --zg-dim: rgb(242 239 233 / .72);
  --zg-faint: rgb(242 239 233 / .58);
  --zg-line: rgb(242 239 233 / .09);
  --zg-r-lg: 14px;
  --zg-r-sm: 12px;
  position: relative;
  width: 100%;
  max-width: 1280px;
  min-width: 0;
  margin: 0 auto;
  color: var(--zg-ink);
  font-family: inherit;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

.zgame,
.zgame *,
.zgame *::before,
.zgame *::after {
  box-sizing: border-box;
}

.zgame :focus-visible {
  outline: 2px solid rgb(169 189 142 / .85);
  outline-offset: 2px;
  border-radius: 4px;
}

.zgame button {
  font-family: inherit;
}

/* ------------------------------ 头部 ------------------------------ */

.zgame .zg-head {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 18px;
  align-items: flex-end;
  justify-content: space-between;
  margin: 0 0 14px;
}

.zgame .zg-title {
  margin: 0;
  font-family: Georgia, 'Times New Roman', 'Songti SC', 'STSong', 'SimSun', serif;
  font-size: clamp(22px, 3vw, 30px);
  font-weight: 600;
  letter-spacing: .05em;
  line-height: 1.15;
  color: var(--zg-ink);
}

.zgame .zg-sub {
  margin: 5px 0 0;
  font-size: 13px;
  color: var(--zg-dim);
}

.zgame .zg-hud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.zgame .zg-chip {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 66px;
  padding: 7px 12px;
  border: 1px solid var(--zg-line);
  border-radius: var(--zg-r-sm);
  background: rgb(242 239 233 / .045);
}

.zgame .zg-chip-k {
  font-size: 11px;
  letter-spacing: .16em;
  color: var(--zg-faint);
  white-space: nowrap;
}

.zgame .zg-chip-v {
  font-size: 16px;
  font-weight: 600;
  color: var(--zg-ink);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ------------------------------ 按钮 ------------------------------ */

.zgame .zg-btn {
  appearance: none;
  border: 1px solid var(--zg-line);
  background: rgb(242 239 233 / .07);
  color: var(--zg-ink);
  font-size: 14px;
  letter-spacing: .06em;
  padding: 10px 20px;
  min-height: 44px;
  border-radius: var(--zg-r-sm);
  cursor: pointer;
  transition: background .18s ease, border-color .18s ease, transform .12s ease;
}

.zgame .zg-btn:hover {
  background: rgb(169 189 142 / .14);
  border-color: rgb(169 189 142 / .45);
}

.zgame .zg-btn:active {
  transform: translateY(1px);
}

.zgame .zg-btn-primary {
  background: var(--zg-accent);
  border-color: var(--zg-accent);
  color: #171b13;
  font-weight: 600;
}

.zgame .zg-btn-primary:hover {
  background: #b9c8a2;
  border-color: #b9c8a2;
}

.zgame .zg-btn[disabled] {
  opacity: .5;
  cursor: default;
  transform: none;
}

.zgame .zg-hint {
  margin: 10px 2px 0;
  font-size: 12px;
  color: var(--zg-dim);
  letter-spacing: .02em;
}

/* ------------------------------ 舞台 ------------------------------ */

.zgame .zg-stage {
  position: relative;
  border: 1px solid var(--zg-line);
  border-radius: var(--zg-r-lg);
  background: rgb(242 239 233 / .03);
  overflow: hidden;
}

.zgame .zg-stage--pad {
  padding: 14px;
}

.zgame .zg-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

/* ---------------------------- 覆盖层/面板 ---------------------------- */

.zgame .zg-overlay {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgb(10 12 9 / .68);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  border-radius: inherit;
}

.zgame .zg-overlay[hidden] {
  display: none;
}

.zgame .zg-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: min(100%, 420px);
  max-height: 100%;
  overflow: auto;
  padding: 26px 28px;
  text-align: center;
  border: 1px solid var(--zg-line);
  border-radius: var(--zg-r-lg);
  background: rgb(13 16 12 / .88);
}

.zgame .zg-panel-t {
  margin: 0;
  font-family: Georgia, 'Times New Roman', 'Songti SC', 'SimSun', serif;
  font-size: 21px;
  font-weight: 600;
  letter-spacing: .06em;
  color: var(--zg-ink);
}

.zgame .zg-panel-d {
  margin: 0;
  font-size: 13px;
  line-height: 1.7;
  color: var(--zg-dim);
}

.zgame .zg-panel-dim {
  font-size: 12px;
  color: var(--zg-faint);
}

.zgame .zg-grade {
  margin: 0;
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 46px;
  font-weight: 700;
  line-height: 1;
  color: var(--zg-accent);
  text-shadow: 0 0 26px rgb(169 189 142 / .4);
}

.zgame .zg-count {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 72px;
  font-weight: 700;
  line-height: 1;
  color: var(--zg-accent);
  text-shadow: 0 0 26px rgb(169 189 142 / .4);
}

.zgame .zg-stats {
  display: grid;
  grid-template-columns: auto auto;
  gap: 7px 22px;
  margin: 2px 0 4px;
}

.zgame .zg-stats dt {
  font-size: 12px;
  letter-spacing: .12em;
  color: var(--zg-faint);
  text-align: left;
}

.zgame .zg-stats dd {
  margin: 0;
  font-size: 15px;
  color: var(--zg-ink);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ============================ 节奏鼓 drums ============================ */

.zgame .zg-dcv-wrap {
  position: relative;
  height: clamp(300px, 52vh, 520px);
  touch-action: none;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.zgame .zg-dcv {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.zgame .zg-combo {
  position: absolute;
  top: 16px;
  left: 0;
  right: 0;
  z-index: 3;
  text-align: center;
  pointer-events: none;
}

.zgame .zg-combo-n {
  display: inline-block;
  font-family: Georgia, 'Times New Roman', serif;
  font-size: clamp(30px, 5vw, 46px);
  font-weight: 700;
  line-height: 1;
  color: var(--zg-accent);
  text-shadow: 0 0 22px rgb(169 189 142 / .35);
}

.zgame .zg-combo small {
  display: block;
  margin-top: 3px;
  font-size: 10px;
  letter-spacing: .34em;
  color: var(--zg-dim);
}

.zgame .zg-combo.bump .zg-combo-n {
  animation: zg-bump .26s ease;
}

@keyframes zg-bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

.zgame .zg-judge {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 92px;
  z-index: 3;
  text-align: center;
  pointer-events: none;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: .3em;
}

.zgame .zg-judge.perfect {
  color: var(--zg-ink);
  text-shadow: 0 0 14px rgb(169 189 142 / .5);
}

.zgame .zg-judge.good {
  color: var(--zg-accent);
}

.zgame .zg-judge.miss {
  color: rgb(242 239 233 / .55);
}

.zgame .zg-judge.bump {
  animation: zg-jpop .34s ease forwards;
}

@keyframes zg-jpop {
  0% { opacity: 0; transform: translateY(8px); }
  25% { opacity: 1; transform: translateY(0); }
  70% { opacity: 1; }
  100% { opacity: 0; }
}

.zgame .zg-keys {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding: 12px 2px 2px;
}

.zgame .zg-key {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 48px;
  padding: 6px 4px;
  border: 1px solid var(--zg-line);
  border-radius: var(--zg-r-sm);
  background: rgb(242 239 233 / .05);
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transition: background .1s ease, border-color .1s ease;
}

.zgame .zg-key-k {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 17px;
  font-weight: 600;
  line-height: 1;
  color: var(--zg-ink);
}

.zgame .zg-key-n {
  font-size: 11px;
  letter-spacing: .18em;
  color: var(--zg-faint);
}

.zgame .zg-key.lit {
  background: rgb(169 189 142 / .2);
  border-color: rgb(169 189 142 / .6);
}

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

.zgame .zg-board-wrap {
  display: flex;
  justify-content: center;
  padding: 6px;
}

.zgame .zg-board {
  position: relative;
  width: min(100%, 460px);
  aspect-ratio: 1 / 1;
  border: 1px solid var(--zg-line);
  border-radius: var(--zg-r-lg);
  background: rgb(242 239 233 / .04);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.zgame .zg-bgcells {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: var(--zg-g, 10px);
  padding: var(--zg-g, 10px);
}

.zgame .zg-bgcell {
  border-radius: 12px;
  background: rgb(242 239 233 / .045);
}

.zgame .zg-tile {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  font-family: Georgia, 'Times New Roman', 'Songti SC', 'SimSun', serif;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  transition: transform .13s ease;
  will-change: transform;
  background: rgb(242 239 233 / .10);
  color: var(--zg-ink);
}

.zgame .zg-tile[data-val='2'] { background: rgb(242 239 233 / .10); color: var(--zg-ink); }
.zgame .zg-tile[data-val='4'] { background: rgb(242 239 233 / .17); color: var(--zg-ink); }
.zgame .zg-tile[data-val='8'] { background: rgb(169 189 142 / .30); color: var(--zg-ink); }
.zgame .zg-tile[data-val='16'] { background: rgb(169 189 142 / .55); color: #13170f; }
.zgame .zg-tile[data-val='32'] { background: rgb(169 189 142 / .75); color: #13170f; }
.zgame .zg-tile[data-val='64'] { background: #a9bd8e; color: #13170f; }
.zgame .zg-tile[data-val='128'] { background: #b9c8a2; color: #13170f; box-shadow: 0 0 18px rgb(169 189 142 / .22); }
.zgame .zg-tile[data-val='256'] { background: #c7d3b3; color: #13170f; box-shadow: 0 0 20px rgb(169 189 142 / .25); }
.zgame .zg-tile[data-val='512'] { background: #d5decb; color: #13170f; box-shadow: 0 0 22px rgb(169 189 142 / .28); }
.zgame .zg-tile[data-val='1024'] { background: #e4e9dc; color: #13170f; box-shadow: 0 0 24px rgb(169 189 142 / .3); }
.zgame .zg-tile[data-val='2048'],
.zgame .zg-tile[data-val='4096'],
.zgame .zg-tile[data-val='8192'] { background: #f2efe9; color: #13170f; box-shadow: 0 0 28px rgb(169 189 142 / .38); }

.zgame .zg-tile-new {
  animation: zg-pop-in .17s ease-out backwards;
}

@keyframes zg-pop-in {
  from { scale: .35; opacity: .3; }
  to { scale: 1; opacity: 1; }
}

.zgame .zg-tile-merge {
  animation: zg-merge-pop .2s ease;
  z-index: 4;
}

@keyframes zg-merge-pop {
  0% { scale: 1; }
  45% { scale: 1.18; }
  100% { scale: 1; }
}

/* ======================== 单字徽章·记忆翻牌 badges ======================== */

.zgame .zg-bgrid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
  max-width: 760px;
  margin: 0 auto;
}

.zgame .zg-card {
  position: relative;
  aspect-ratio: 3 / 4;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  perspective: 700px;
  -webkit-tap-highlight-color: transparent;
}

.zgame .zg-card-in {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform .45s cubic-bezier(.2, .7, .3, 1);
  will-change: transform;
}

.zgame .zg-card.flipped .zg-card-in,
.zgame .zg-card.matched .zg-card-in {
  transform: rotateY(180deg);
}

.zgame .zg-face {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border: 1px solid var(--zg-line);
  border-radius: var(--zg-r-sm);
}

.zgame .zg-face-f {
  background: rgb(242 239 233 / .05);
  transition: background .18s ease, border-color .18s ease;
}

.zgame .zg-face-f::before {
  content: '';
  width: 42%;
  aspect-ratio: 1 / 1;
  border: 1px solid rgb(242 239 233 / .22);
  border-radius: 50%;
}

.zgame .zg-face-f::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 7px;
  height: 7px;
  transform: translate(-50%, -50%) rotate(45deg);
  background: rgb(242 239 233 / .28);
  border-radius: 1px;
}

.zgame .zg-card:not(.flipped):not(.matched):hover .zg-face-f {
  background: rgb(169 189 142 / .08);
  border-color: rgb(169 189 142 / .4);
}

.zgame .zg-face-b {
  transform: rotateY(180deg);
  background: rgb(242 239 233 / .07);
  font-family: Georgia, 'Songti SC', 'STSong', 'SimSun', serif;
  font-size: clamp(20px, 4.5vw, 34px);
  font-weight: 600;
  color: var(--zg-dim);
  transition: color .25s ease, background .25s ease, border-color .25s ease;
}

.zgame .zg-card.matched {
  cursor: default;
}

.zgame .zg-card.matched .zg-face-b {
  color: var(--zg-accent);
  background: rgb(169 189 142 / .1);
  border-color: rgb(169 189 142 / .55);
  box-shadow: inset 0 0 16px rgb(169 189 142 / .18);
  text-shadow: 0 0 12px rgb(169 189 142 / .45);
}

.zgame .zg-card.matched .zg-card-in {
  animation: zg-mpulse .4s ease;
}

@keyframes zg-mpulse {
  0% { scale: 1; }
  45% { scale: 1.07; }
  100% { scale: 1; }
}

/* ---------------------------- 窄屏适配 ---------------------------- */

@media (max-width: 640px) {
  .zgame .zg-head {
    flex-direction: column;
    align-items: stretch;
  }

  .zgame .zg-hud {
    width: 100%;
  }

  .zgame .zg-chip {
    flex: 1 1 auto;
    min-width: 0;
    padding: 6px 10px;
  }

  .zgame .zg-keys {
    gap: 8px;
  }

  .zgame .zg-key {
    min-height: 44px;
  }

  .zgame .zg-bgrid {
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
  }

  .zgame .zg-panel {
    padding: 20px 18px;
  }
}

/* ------------------ 降低动效（prefers-reduced-motion） ------------------
   下落 / 翻转 / 合并 / 光斑等动画即时切换到最终状态；
   节奏鼓的下落路径另在 JS 中直接改为临场显示，判定时机不变。 */

@media (prefers-reduced-motion: reduce) {
  .zgame *,
  .zgame *::before,
  .zgame *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}
