/* ============= Design System ============= */
:root {
  --bg: #0b1020;
  --bg-2: #131a2e;
  --card: rgba(255, 255, 255, 0.06);
  --card-hover: rgba(255, 255, 255, 0.12);
  --border: rgba(255, 255, 255, 0.08);
  --text: #f5f7ff;
  --text-2: #aab2d0;
  --accent: #ff5e7e;
  --accent-2: #5eb4ff;
  --accent-3: #ffd86e;
  --radius-l: 22px;
  --radius-m: 14px;
  --radius-s: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  /* v19 修复（2026-05-18）：苏总反馈所有页面安卓还是滑不动
     根因：
       1) `html` + `body` 同时 overflow-x:hidden + max-width:100vw，
          会让安卓 Chromium / 鸿蒙 / 华为 / MIUI 内核找不到「真正可滚动的根」，
          于是两个都不滚，整页死锁。
       2) html 上的 overflow-x:hidden 在 Android WebView 经常等价于把 vertical
          scroll 一起干掉。
     修法：
       - 不再在 html 上设 overflow / max-width，把横向溢出兜底只放在 body 上；
       - 保留 -webkit-overflow-scrolling: touch（iOS only，不影响安卓）；
       - 保留 min-height: 100% 兜底（鸿蒙 100vh 异常）。 */
  -webkit-overflow-scrolling: touch;
  min-height: 100%;
}

body {
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(255, 94, 126, 0.25), transparent 60%),
    radial-gradient(900px 500px at 100% 10%, rgba(94, 180, 255, 0.22), transparent 65%),
    radial-gradient(800px 400px at 50% 110%, rgba(255, 216, 110, 0.18), transparent 60%),
    var(--bg);
  min-height: 100%;       /* 鸿蒙兜底 */
  min-height: 100vh;      /* 现代浏览器优先（写在后覆盖） */
  overflow-x: hidden;     /* 横向溢出只锁 body，html 保持默认滚动根 */
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* ============= Top Hero ============= */
.hero {
  padding: 44px 22px 30px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;   /* 三个子元素垂直排 + 水平居中 */
}
.hero .live-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px 5px 10px;
  border-radius: 999px;
  background: rgba(94, 180, 255, 0.08);
  border: 1px solid rgba(94, 180, 255, 0.22);
  color: #b3dcff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
  margin-bottom: 18px;   /* 在 flex column 下自然独占一行 */
}
.hero .live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #5eb4ff;
  box-shadow: 0 0 10px #5eb4ff;
  animation: livePulse 1.8s ease-in-out infinite;
}
@keyframes livePulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.35; transform: scale(0.8); }
}
.hero h1 {
  font-size: 34px;
  font-weight: 800;
  letter-spacing: -0.8px;
  background: linear-gradient(135deg, #ff8ea7 0%, #b18cff 50%, #5eb4ff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  display: inline-block;
}
.hero p {
  margin-top: 8px;
  font-size: 14px;
  color: var(--text-2);
  letter-spacing: 0.2px;
}

/* ============= Grid ============= */
.grid-wrap { padding: 8px 16px 90px; max-width: 880px; margin: 0 auto; }
.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 820px) { .grid { grid-template-columns: repeat(4, 1fr); } }

.card {
  position: relative;
  display: block;
  padding: 18px 16px 16px;
  border-radius: var(--radius-l);
  background: var(--card);
  border: 1px solid var(--border);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  overflow: hidden;
  transition: transform .25s cubic-bezier(0.23, 1, 0.32, 1), background .25s ease, box-shadow .25s ease;
}
/* 大公司质感：inner glow + 1px 微光高光 */
.card::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius-l);
  pointer-events: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
.card:active {
  transform: scale(0.96);
  background: var(--card-hover);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
.card .icon-box {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.12) 0%, rgba(255, 255, 255, 0.02) 100%);
  border: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.07);
  margin: 0 auto 14px;     /* 卡片内水平居中 */
  overflow: hidden;
}
.card .emoji {
  /* 框死 56×56 视觉区，统一 emoji 大小 */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  font-size: 40px;
  line-height: 1;
  text-align: center;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.4));
}
/* 自定义 SVG 图标（如中国象棋），与 .emoji 同等视觉区域 */
.card .icon-box .cn-chess-svg,
.card .icon-box > svg {
  width: 56px;
  height: 56px;
  display: block;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.4));
}
.card .name,
.card .desc { text-align: center; }   /* 文字也整体居中 */
.card .name {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.2px;
}
.card .desc {
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-2);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card .tag {
  position: absolute;
  top: 14px;
  right: 14px;
  font-size: 9px;
  padding: 3px 7px;
  border-radius: 6px;
  font-weight: 800;
  letter-spacing: 0.8px;
  color: #fff;
  text-transform: uppercase;
}
.tag.hot {
  background: linear-gradient(135deg, #ff5e7e, #ff8e5e);
  box-shadow: 0 4px 10px rgba(255, 94, 126, 0.35);
}
.tag.new {
  background: linear-gradient(135deg, #5eb4ff, #7c8eff);
  box-shadow: 0 4px 10px rgba(94, 180, 255, 0.35);
}

/* ============= Share bar ============= */
.share-bar {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  padding: 8px;
  border-radius: 999px;
  background: rgba(15, 18, 35, 0.78);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  z-index: 50;
}
.share-bar button {
  border: 0;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  padding: 9px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
}
.share-bar button:active { background: rgba(255, 255, 255, 0.18); }
.share-bar .primary {
  background: linear-gradient(135deg, #ff5e7e, #ff8e5e);
}

/* ============= In-game top bar ============= */
.game-topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: rgba(11, 16, 32, 0.78);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}
.game-topbar .back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 13px;
  color: var(--text);
  flex-shrink: 0;
}
.game-topbar .title {
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex-shrink: 1;
}
.game-topbar .score {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 45%;
  flex-shrink: 0;
}
.game-topbar .share-mini {
  margin-left: 4px;
  border: 0;
  padding: 5px 10px;
  border-radius: 999px;
  background: linear-gradient(135deg, #ff5e7e, #ff8e5e);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
}
.game-topbar .share-mini:active { opacity: 0.85; }

/* ============= Toast / Modal ============= */
.toast {
  position: fixed;
  left: 50%;
  top: 20%;
  transform: translateX(-50%);
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  font-size: 13px;
  z-index: 999;
  opacity: 0;
  transition: opacity .2s ease;
  pointer-events: none;
}
.toast.show { opacity: 1; }

.modal-mask {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6);
  display: none; align-items: center; justify-content: center; z-index: 200;
}
.modal-mask.show { display: flex; }
.modal {
  width: min(360px, 85vw);
  background: var(--bg-2);
  border-radius: 20px;
  border: 1px solid var(--border);
  padding: 22px;
  text-align: center;
}
.modal h3 { font-size: 18px; margin-bottom: 8px; }
.modal p { font-size: 13px; color: var(--text-2); margin-bottom: 18px; }
.modal .actions { display: flex; gap: 10px; }
.modal .actions button {
  flex: 1; padding: 10px; border: 0; border-radius: 12px; font-size: 14px; font-weight: 600;
  background: rgba(255, 255, 255, 0.08); color: var(--text);
}
.modal .actions .primary { background: linear-gradient(135deg, #ff5e7e, #ff8e5e); }

/* ============= 分数榜面板（结束弹窗里）============= */
.gh-score-panel {
  margin: 8px 0 16px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(0,0,0,0.25);
  border: 1px solid rgba(255,255,255,0.06);
  text-align: left;
}
.gh-score-panel .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-2);
  padding: 4px 0;
}
.gh-score-panel .row .lbl { font-weight: 600; }
.gh-score-panel .row b {
  font-size: 16px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.3px;
}
.gh-score-panel .row.rank b {
  font-size: 13px;
  color: var(--accent-3);
}
.gh-score-panel .row .cur { color: var(--accent); font-size: 20px; }
.gh-score-panel .row .max { color: var(--accent-3); }
.gh-score-panel .row .who { font-size: 11px; color: var(--text-2); margin-left: 6px; font-weight: 500; }

/* ============= Game canvas frame ============= */
.canvas-frame {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
}
.canvas-frame canvas {
  display: block;
  /* 显式用 viewport 单位避免 percentage 在 min() 中 resolve 时机异常。
     width = min(可用宽, 480, viewport 高减底部预留后能让 canvas 容纳的最大宽)
     底部预留通过 --canvas-bottom-pad 控制，sokoban 等含 D-pad 的游戏可 override */
  width: min(calc(100vw - 32px), 480px, calc((100vh - var(--canvas-bottom-pad, 240px)) * 0.6));
  height: auto;
  aspect-ratio: 360 / 600;
  background: rgba(0, 0, 0, 0.25);
  border-radius: var(--radius-m);
  border: 1px solid var(--border);
  touch-action: none;
}

.control-row {
  display: flex !important;
  gap: 10px;
  margin: 14px auto 0 !important;
  /* 三层保护：viewport-based、绝对上限、box-sizing 不留余地 */
  width: calc(100vw - 32px) !important;
  max-width: 480px !important;
  box-sizing: border-box;
  position: relative;
  z-index: 60;
}
.control-row .btn {
  flex: 1 1 0 !important;
  min-width: 0 !important;
  max-width: calc(50% - 5px) !important;
  padding: 11px;
  border: 0;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.control-row .btn:active { background: rgba(255, 255, 255, 0.18); }
.control-row .btn.primary { background: linear-gradient(135deg, #ff5e7e, #ff8e5e); }
.control-row .btn.primary:active { filter: brightness(0.92); }

/* small helper */
.muted { color: var(--text-2); }
.center { text-align: center; }
.mt-12 { margin-top: 12px; }
.mt-20 { margin-top: 20px; }
