:root {
  --bg-top: #f6efe1;
  --bg-bot: #ead9bf;
  --ink: #2a2118;
  --ink-soft: #6b5a45;
  --accent: #ff7e5f;
  --accent-2: #feb47b;
  --card: #fffaf0;
  --card-shadow: 0 24px 60px rgba(60, 36, 12, 0.18), 0 2px 6px rgba(60, 36, 12, 0.08);
  --pill: rgba(255, 250, 240, 0.85);
  --pill-border: rgba(60, 36, 12, 0.1);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bot) 100%);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
               "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  overscroll-behavior: none;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* 顶栏 */
.topbar {
  position: absolute;
  top: calc(16px + var(--safe-top));
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 12px;
  pointer-events: none;
  z-index: 5;
}

.score-pill {
  background: var(--pill);
  border: 1px solid var(--pill-border);
  border-radius: 999px;
  padding: 6px 18px;
  text-align: center;
  min-width: 88px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 6px 18px rgba(60, 36, 12, 0.08);
}

.score-pill.best { opacity: 0.85; }
.score-label { font-size: 11px; color: var(--ink-soft); letter-spacing: 1px; }
.score-value {
  font-size: 22px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  color: var(--ink);
}

.hint {
  position: absolute;
  bottom: calc(28px + var(--safe-bot));
  left: 0;
  right: 0;
  text-align: center;
  font-size: 13px;
  color: var(--ink-soft);
  opacity: 0.7;
  pointer-events: none;
  z-index: 5;
}

/* 通用遮罩 */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(40, 28, 12, 0.42);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  padding: 20px;
}

.overlay.hidden { display: none; }

.card {
  width: min(420px, 92vw);
  max-height: calc(100vh - 40px);
  overflow: auto;
  background: var(--card);
  border-radius: 22px;
  padding: 26px 24px 22px;
  box-shadow: var(--card-shadow);
  text-align: center;
}

/* 开始菜单 */
.logo {
  font-size: 52px;
  font-weight: 900;
  margin: 4px 0 2px;
  letter-spacing: 4px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.logo span {
  font-size: 38px;
  margin: 0 2px;
  vertical-align: 6px;
  opacity: 0.85;
}

.sub {
  font-size: 13px;
  color: var(--ink-soft);
  margin: 0 0 22px;
  line-height: 1.6;
}

.diff-title {
  font-size: 12px;
  color: var(--ink-soft);
  letter-spacing: 4px;
  margin-bottom: 10px;
}

.diff-list {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 20px;
}

.diff-btn {
  border: 1.5px solid rgba(60, 36, 12, 0.12);
  background: #fffefa;
  border-radius: 14px;
  padding: 12px 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: transform 0.12s ease, border-color 0.18s, background 0.18s, box-shadow 0.18s;
  color: var(--ink);
}
.diff-btn:hover { transform: translateY(-1px); }
.diff-btn.primary {
  border-color: var(--accent);
  background: #fff3eb;
  box-shadow: 0 8px 18px rgba(255, 126, 95, 0.18);
}
.diff-name { font-weight: 700; font-size: 16px; }
.diff-desc { font-size: 11px; color: var(--ink-soft); }

.start-btn {
  width: 100%;
  border: none;
  border-radius: 14px;
  padding: 14px 0;
  font-size: 17px;
  font-weight: 700;
  color: white;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(255, 126, 95, 0.32);
  transition: transform 0.12s ease, box-shadow 0.18s;
}
.start-btn:active {
  transform: translateY(1px);
  box-shadow: 0 6px 14px rgba(255, 126, 95, 0.28);
}

.foot {
  margin-top: 12px;
  font-size: 11px;
  color: var(--ink-soft);
  opacity: 0.7;
}

/* 游戏结束面板 */
.share-card { padding: 22px 22px 18px; }
.result-head { margin-bottom: 10px; }
.result-title {
  font-size: 14px;
  color: var(--ink-soft);
  letter-spacing: 4px;
}
.result-diff {
  margin-top: 4px;
  font-size: 12px;
  color: var(--ink-soft);
  opacity: 0.8;
}

.big-score {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 10px 0 16px;
}
.score-num {
  font-size: 64px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.score-meta {
  margin-top: 6px;
  font-size: 13px;
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  gap: 6px;
}
.score-meta b { color: var(--ink); }
.dot { opacity: 0.5; }
.new-badge {
  background: var(--accent);
  color: white;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
}
.new-badge.hidden { display: none; }

.qr-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 10px 0 18px;
}
.qr-cell {
  background: #fffefa;
  border: 1px solid rgba(60, 36, 12, 0.08);
  border-radius: 12px;
  padding: 10px 8px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.qr-box {
  width: 110px;
  height: 110px;
  background: white;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.qr-box img, .qr-box canvas { width: 100%; height: 100%; display: block; }
.qr-label {
  margin-top: 8px;
  font-size: 11px;
  color: var(--ink-soft);
  text-align: center;
  line-height: 1.4;
}

.action-row {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}
.btn {
  flex: 1;
  border: none;
  border-radius: 12px;
  padding: 12px 0;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  transition: transform 0.12s ease, box-shadow 0.18s;
}
.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  box-shadow: 0 8px 20px rgba(255, 126, 95, 0.28);
}
.btn.ghost {
  background: #fff;
  color: var(--ink);
  border: 1.5px solid rgba(60, 36, 12, 0.14);
}
.btn:active { transform: translateY(1px); }

.link-btn {
  background: none;
  border: none;
  color: var(--ink-soft);
  font-size: 12px;
  margin-top: 14px;
  cursor: pointer;
  text-decoration: underline;
}

/* 分享图预览 */
.preview-card {
  width: min(420px, 92vw);
  background: var(--card);
  border-radius: 22px;
  padding: 18px;
  box-shadow: var(--card-shadow);
  text-align: center;
}
.preview-tip {
  font-size: 12px;
  color: var(--ink-soft);
  margin-bottom: 10px;
}
#shareImg {
  width: 100%;
  border-radius: 14px;
  display: block;
  margin-bottom: 14px;
  background: #fff;
}

@media (max-width: 360px) {
  .logo { font-size: 44px; }
  .qr-box { width: 92px; height: 92px; }
  .score-num { font-size: 52px; }
}
