/* 苹方-简 常规体（中文；此子集不含数字/字母，由下面的 SF Pro 补上） */
@font-face {
  font-family: 'PingFang SC';
  src: url('fonts/PingFangSC-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

/* 西文/数字用 SF Pro Display（苹果西文字体，补上苹方子集缺失的数字字母） */
@font-face {
  font-family: 'SF Pro Display';
  src: url('fonts/sf-pro-display_regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

/* =========================================================
   视觉风格：Microsoft Fluent + 腾讯 TDesign 混合
   - 浅灰底 / 白卡片 / 科技蓝主色 / 柔和分层阴影
   - 微交互：淡入、抬升、按压回弹、3D 翻转、弹跳
   ========================================================= */
:root {
  --bg: #faf9f8;
  --surface: #ffffff;
  --stroke: #e1dfdd;
  --text: #242424;
  --text-secondary: #616161;
  --accent: #0078d4;          /* 微软蓝 */
  --accent-hover: #0067c0;
  --accent-pressed: #005a9e;
  --success: #2ba471;         /* 腾讯绿 */
  --radius: 8px;
  /* Fluent 阴影层级 */
  --shadow-8: 0 1.6px 3.6px rgba(0,0,0,.13), 0 .3px .9px rgba(0,0,0,.11);
  --shadow-16: 0 6.4px 14.4px rgba(0,0,0,.13), 0 1.2px 3.6px rgba(0,0,0,.11);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
body {
  font-family: "SF Pro Display", "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background-color: #f3f4f7;
  background-image:
    radial-gradient(90% 60% at 50% 110%, rgba(0, 120, 212, 0.13), transparent 65%),
    radial-gradient(rgba(15, 23, 42, 0.05) 1px, transparent 1px);
  background-size: 100% 100%, 24px 24px;
  background-repeat: no-repeat, repeat;
  min-height: 100vh;
  overscroll-behavior-y: none;   /* 禁用手机下拉刷新 */
}

/* 顶部命令栏（Fluent command bar） */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--stroke);
}
.home-btn {
  background: #ffffff;
  border: 1px solid #e5e5ea;
  color: #007aff;
  padding: 8px 18px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 400;
  transition: background .12s, transform .08s;
}
.home-btn:hover { background: #f2f2f7; }
.home-btn:active { transform: scale(0.97); }
.logo { font-size: 20px; font-weight: 700; letter-spacing: .3px; color: var(--text); }

main { padding: 18px 20px 48px; max-width: 760px; margin: 0 auto; }

/* 首页卡片 */
.hub { display: none; text-align: center; padding-top: 28px; }
.hub.active { display: block; }
.subtitle { font-size: 17px; color: var(--text-secondary); margin-bottom: 24px; }
.cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; }
.card {
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.04);
  border-radius: 24px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.05);
  padding: 34px 20px 30px;
  cursor: pointer;
  transition: transform .22s ease, box-shadow .22s ease;
  animation: fadeUp .4s ease both;
}
.card:nth-child(2) { animation-delay: .05s; }
.card:nth-child(3) { animation-delay: .1s; }
.card:nth-child(4) { animation-delay: .15s; }
.card:hover { transform: translateY(-6px) scale(1.02); box-shadow: 0 20px 40px rgba(0, 0, 0, 0.10); }
.card:active { transform: translateY(-2px) scale(0.99); }
.card-emoji { font-size: 52px; display: flex; align-items: center; justify-content: center; transition: transform .2s ease; }
.card-emoji svg { width: 56px; height: 56px; }
.card:hover .card-emoji { transform: scale(1.1); }
.card h2 { margin: 14px 0 6px; font-size: 22px; font-weight: 700; color: var(--text); }
.card p { color: var(--text-secondary); font-size: 15px; }

/* 每张卡片的主题色微渐变（苹果发布会式彩色卡片） */
.card[data-game="snake"] { background: linear-gradient(180deg, #ffffff 0%, #e9f6ef 100%); }
.card[data-game="g2048"] { background: linear-gradient(180deg, #ffffff 0%, #e9f1fb 100%); }
.card[data-game="memory"] { background: linear-gradient(180deg, #ffffff 0%, #e7f4f4 100%); }
.card[data-game="whack"] { background: linear-gradient(180deg, #ffffff 0%, #fdf1e6 100%); }

/* 游戏面板 */
.game-panel {
  display: none;
  position: relative;
  background: var(--surface);
  border: 1px solid var(--stroke);
  border-radius: 14px;
  box-shadow: var(--shadow-8);
  padding: 22px;
}
.game-panel.active { display: block; animation: fadeUp .28s ease; }
.game-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.game-head h2 { font-size: 21px; color: var(--text); }
.score {
  background: #f3f2f1;
  border: 1px solid var(--stroke);
  color: var(--text);
  padding: 6px 12px; border-radius: 14px; font-size: 14px;
}
.ctrl { margin-top: 16px; display: flex; gap: 10px; }
.ctrl button {
  background: #007aff;
  border: none;
  color: #fff; font-weight: 400;
  padding: 10px 24px; border-radius: 999px;
  cursor: pointer; font-size: 15px;
  transition: background .12s, transform .08s;
}
.ctrl button:hover { background: #0070e0; }
.ctrl button:active { background: #0063cc; transform: scale(0.97); }
.hint { margin-top: 12px; color: var(--text-secondary); font-size: 13px; }

canvas {
  background: #1e1e2e;
  border: 1px solid var(--stroke);
  border-radius: 12px;
  display: block; margin: 0 auto; max-width: 100%; touch-action: none;
}

/* 2048（tile 绝对定位 + 过渡动画） */
.g-board {
  position: relative;
  width: 300px;
  max-width: 100%;
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  background-color: #f0f0f0;
  /* 仅用横竖 1px 灰线画出 4x4 网格，无圆角 */
  background-image:
    linear-gradient(to right, #d9d9d9 1px, transparent 1px),
    linear-gradient(to bottom, #d9d9d9 1px, transparent 1px);
  background-size: 25% 25%;
}
.g-tile {
  position: absolute;
  transition: transform .12s ease;
  will-change: transform;
}
.g-tile > span {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%;
  border-radius: 0;
  font-weight: 800; color: #776e65;
}
.g-tile.v2 > span { background: #eee4da; }
.g-tile.v4 > span { background: #ede0c8; }
.g-tile.v8 > span { background: #f2b179; color: #fff; }
.g-tile.v16 > span { background: #f59563; color: #fff; }
.g-tile.v32 > span { background: #f67c5f; color: #fff; }
.g-tile.v64 > span { background: #f65e3b; color: #fff; }
.g-tile.v128 > span { background: #edcf72; color: #fff; }
.g-tile.v256 > span { background: #edcc61; color: #fff; }
.g-tile.v512 > span { background: #edc850; color: #fff; }
.g-tile.v1024 > span { background: #edc53f; color: #fff; }
.g-tile.v2048 > span { background: #edc22e; color: #fff; }
.g-tile.new > span { animation: tileSpawn .14s ease; }
.g-tile.merge > span { animation: tileMerge .14s ease; }
@keyframes tileSpawn { 0% { transform: scale(0); } 100% { transform: scale(1); } }
@keyframes tileMerge { 0% { transform: scale(1); } 50% { transform: scale(1.18); } 100% { transform: scale(1); } }

/* 记忆翻牌（3D 翻转） */
.m-board { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; max-width: 380px; margin: 0 auto; }
.m-card { aspect-ratio: 1; perspective: 600px; cursor: pointer; }
.m-inner {
  position: relative; width: 100%; height: 100%;
  transition: transform .4s ease; transform-style: preserve-3d;
}
.m-card.open .m-inner, .m-card.done .m-inner { transform: rotateY(180deg); }
.m-front, .m-back {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  border-radius: 12px; backface-visibility: hidden; font-size: 34px;
}
.m-front { background: #e6e6e6; color: #9a9a9a; }
.m-back { background: #fff; border: 1px solid var(--stroke); transform: rotateY(180deg); color: var(--accent); }
.m-back svg { width: 58%; height: 58%; }
.m-card.done .m-back { background: #e7f6ef; border-color: var(--success); }

/* 打地鼠（弹跳出现） */
.timer { text-align: center; margin-bottom: 12px; font-size: 16px; color: var(--text); }
.w-board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; max-width: 360px; margin: 0 auto; }
.w-hole {
  aspect-ratio: 1;
  background: #ececec;
  border: 1px solid var(--stroke);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 40px; cursor: pointer; position: relative;
  transition: background .12s, box-shadow .12s;
}
.w-hole .mole {
  display: none;
  width: 58%; height: 58%;
  background: #8d6e63;
  border-radius: 50% 50% 45% 45%;
  position: relative;
}
.w-hole.up { background: #fff; box-shadow: inset 0 0 0 3px var(--accent); }
.w-hole.up .mole { display: block; animation: pop .18s ease; }
.w-hole .mole::before, .w-hole .mole::after {
  content: ""; position: absolute; top: 34%;
  width: 14%; height: 14%; background: #3e2723; border-radius: 50%;
}
.w-hole .mole::before { left: 28%; }
.w-hole .mole::after { right: 28%; }
.w-hole:active { transform: scale(.96); }

/* 页面内结果提示（替代 alert 弹窗） */
.result {
  display: none;
  position: absolute; inset: 0;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(2px);
  border-radius: 14px;
  align-items: center; justify-content: center;
  z-index: 5;
}
.result.show { display: flex; animation: fadeUp .25s ease; }
.result-box {
  background: var(--surface);
  border: 1px solid var(--stroke);
  box-shadow: var(--shadow-16);
  border-radius: 12px;
  padding: 24px 30px;
  text-align: center; max-width: 82%;
}
.result-msg { font-size: 18px; font-weight: 600; color: var(--text); margin-bottom: 16px; }
.result-btn {
  background: #007aff; color: #fff;
  border: none;
  padding: 10px 28px; border-radius: 999px;
  font-weight: 400; cursor: pointer; font-size: 15px;
  transition: background .12s, transform .08s;
}
.result-btn:hover { background: #0070e0; }
.result-btn:active { background: #0063cc; transform: scale(0.97); }

/* 动效 */
@keyframes fadeUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes pop { 0% { transform: scale(.3); opacity: 0; } 60% { transform: scale(1.12); } 100% { transform: scale(1); opacity: 1; } }

/* 键盘焦点高亮（无障碍） */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (max-width: 480px) {
  .cards { grid-template-columns: 1fr; }
}
