/* ============ 页面外壳 ============ */
:root {
  --bg: #f7f7f8;
  --card: #ffffff;
  --text: #535353;
  --muted: #9a9a9a;
  --border: #e3e3e5;
}
* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  overscroll-behavior-y: contain; /* 防止下拉刷新/回弹误触 */
}

.page { width: 100%; max-width: 640px; text-align: center; }

.page__title { font-size: 28px; font-weight: 700; letter-spacing: 1px; }
.page__subtitle { margin-top: 6px; color: var(--muted); font-size: 14px; }

/* ============ 游戏画布卡片 ============ */
.game-card {
  position: relative;
  margin: 20px auto 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 6px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, .06);
  /* 夜晚模式时由游戏脚本切换此类，颜色平滑过渡 */
  transition: background-color 1.5s ease, border-color 1.5s ease;
}

/* 全屏按钮（桌面/手机都可用） */
.fs-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, .72);
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.fs-btn:active { background: #ececf0; }

/* 全屏模式：卡片铺满、画布放大居中 */
.game-card:fullscreen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border: none;
  border-radius: 0;
}
.game-card:fullscreen #game-canvas { max-width: 960px; }
.game-card:-webkit-full-screen { display: flex; align-items: center; justify-content: center; border: none; border-radius: 0; }
.game-card:-webkit-full-screen #game-canvas { max-width: 960px; }

/* 沉浸模式（iOS 不支持全屏 API 时的替代：隐藏无关元素） */
body.immersive { padding: 0; }
body.immersive .page__title,
body.immersive .page__subtitle,
body.immersive .help,
body.immersive .footer { display: none; }
body.immersive .game-card {
  margin: 0;
  border: none;
  border-radius: 0;
  box-shadow: none;
  width: 100%;
}

/* ============ 移动端虚拟按键（粗指针 / 小屏时显示） ============ */
.touch-controls,
.help--touch { display: none; }

@media (pointer: coarse), (max-width: 640px) {
  .help--keys { display: none; }
  .help--touch { display: flex; }
  .page__title { font-size: 22px; }
  .page__subtitle { font-size: 12px; }
  body { padding: 14px 12px calc(14px + env(safe-area-inset-bottom)); }

  .touch-controls {
    display: flex;
    gap: 12px;
    margin-top: 14px;
    user-select: none;
    -webkit-user-select: none;
  }
  .ctl-btn {
    flex: 1;
    min-height: 64px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--card);
    color: var(--text);
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    box-shadow: 0 3px 10px rgba(0, 0, 0, .05);
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
  }
  .ctl-btn:active {
    background: #ececf0;
    transform: scale(.97);
  }
}

/* 沉浸模式时隐藏虚拟按键外的所有元素后，让画布尽量大 */
body.immersive #game-canvas { max-width: 960px; }
.game-card.night {
  background: #17181c;
  border-color: #2b2d33;
}

#game-canvas {
  display: block;
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  touch-action: manipulation; /* 防止双击缩放 */
  image-rendering: -webkit-optimize-contrast;
}

/* ============ 操作说明 ============ */
.help {
  margin-top: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  justify-content: center;
  font-size: 13px;
  color: var(--muted);
}
kbd {
  display: inline-block;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--card);
  font-family: inherit;
  font-size: 12px;
  color: var(--text);
}

.footer { margin-top: 26px; font-size: 12px; color: var(--muted); }
.footer a { color: var(--muted); }
