:root {
  --bg: #f4f9f9;
  --accent: #58b99a;
  --accent-dark: #45967a;
  --white: #ffffff;
  --text-main: #2c3e50;
  --text-sub: #7f8c8d;
  --success: #2ecc71;
  --danger: #e74c3c;
  --shadow: 0 4px 12px rgba(0,0,0,0.08);
  --radius: 14px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  -webkit-tap-highlight-color: transparent;
}

#app {
  width: 100%;
  max-width: 480px;
  height: 100dvh;
  background: var(--white);
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow);
}

/* 顶部状态栏 */
.hud {
  padding: 12px 16px;
  background: var(--white);
  border-bottom: 1px solid #eef2f5;
  z-index: 10;
}

.hud-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
}

.hud-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 16px;
  font-weight: 700;
}

.hud-icon { font-size: 20px; }
.hud-val { color: var(--text-main); }

.progress-track {
  width: 100%;
  height: 8px;
  background: #e8ecef;
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--success));
  border-radius: 4px;
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* 游戏主区域 */
.game-area {
  flex: 1;
  padding: 16px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow-y: auto;
  background: var(--bg);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  width: 100%;
  max-width: 420px;
}

/* 动态生成的卡片样式 */
.card {
  aspect-ratio: 3/4;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  padding: 6px;
  transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
  user-select: none;
  border: 2px solid transparent;
  overflow-wrap: break-word;
}

.card:active { transform: scale(0.96); }

.card.flipped {
  background: #e8f5f0;
  border-color: var(--accent);
  transform: scale(0.98);
}

.card.matched {
  background: #d1f2eb;
  border-color: var(--success);
  opacity: 0.7;
  pointer-events: none;
  transform: scale(0.95);
}

.card-back {
  background: var(--accent);
  color: var(--white);
  font-size: 28px;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: calc(var(--radius) - 2px);
}

/* 实时反馈提示 */
.feedback-toast {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.9);
  background: rgba(44, 62, 80, 0.92);
  color: var(--white);
  padding: 12px 24px;
  border-radius: 24px;
  font-size: 18px;
  font-weight: 700;
  pointer-events: none;
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 20;
  text-align: center;
  white-space: nowrap;
}

.feedback-toast.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* 覆盖层（开始/结算） */
.screen-overlay {
  position: absolute;
  inset: 0;
  background: rgba(244, 249, 249, 0.96);
  backdrop-filter: blur(6px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 30;
  transition: opacity 0.3s ease;
}

.screen-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.screen-content {
  background: var(--white);
  padding: 32px 24px;
  border-radius: 20px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.12);
  text-align: center;
  width: 88%;
  max-width: 360px;
}

.title-main { font-size: 28px; color: var(--text-main); margin-bottom: 8px; font-weight: 800; }
.title-sub { font-size: 16px; color: var(--text-sub); margin-bottom: 24px; line-height: 1.5; }
.title-result { font-size: 26px; color: var(--text-main); margin-bottom: 12px; }
.result-desc { font-size: 16px; color: var(--text-sub); margin-bottom: 20px; }

.result-stats {
  background: var(--bg);
  padding: 14px;
  border-radius: 12px;
  margin-bottom: 24px;
  font-size: 16px;
  color: var(--text-main);
}

.result-stats p { margin: 6px 0; }

.btn-group { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* 按钮组件 */
.btn {
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 700;
  border-radius: 14px;
  transition: transform 0.1s, box-shadow 0.2s, background 0.2s;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(0.96); }

.btn-lg { padding: 14px 28px; font-size: 18px; }

.btn-primary {
  background: var(--accent);
  color: var(--white);
  box-shadow: 0 4px 14px rgba(88, 185, 154, 0.4);
}
.btn-primary:hover { background: #4ea88a; }

.btn-accent {
  background: var(--accent-dark);
  color: var(--white);
  box-shadow: 0 4px 14px rgba(69, 150, 122, 0.4);
}
.btn-accent:hover { background: #3a8068; }

.btn-outline {
  background: transparent;
  color: var(--text-sub);
  border: 2px solid #dce4e8;
}
.btn-outline:hover { background: #f0f4f7; }

/* 小屏幕适配 */
@media (max-width: 380px) {
  .card-grid { gap: 8px; }
  .card { font-size: 12px; padding: 4px; }
  .title-main { font-size: 24px; }
  .btn-lg { padding: 12px 20px; font-size: 16px; }
}