/* ============================================================
   拼图活动通用样式
============================================================ */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  color: #333;
  padding: 20px;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
}

/* 语言切换器（右上角固定） */
.lang-switcher {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.95);
  padding: 8px 12px;
  border-radius: 999px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}
.lang-label {
  font-size: 12px;
  color: #6b7280;
  font-weight: 600;
}
.lang-select {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 13px;
  background: white;
  color: #1f2937;
  cursor: pointer;
  max-width: 160px;
}
.consent-text {
  margin-top: 16px;
  font-size: 12px;
  color: #9ca3af;
  text-align: center;
}
.warm-tip {
  margin: 0 0 16px;
  padding: 12px 14px;
  background: #fff7ed;
  border: 1px solid #fdba74;
  border-radius: 10px;
  color: #9a3412;
  font-size: 13px;
  line-height: 1.6;
}
.field-hint {
  margin-top: 6px;
  font-size: 12px;
  color: #6b7280;
}
.attempts-info {
  margin: 0 0 12px;
  padding: 10px 12px;
  background: #eff6ff;
  border-radius: 8px;
  font-size: 13px;
  color: #1e40af;
  line-height: 1.5;
}
.attempts-line {
  margin-top: 4px !important;
  color: #4c1d95 !important;
  font-weight: 600;
}
.attempts-exhausted {
  margin-top: 8px;
  font-size: 12px;
  color: #b91c1c;
  font-weight: 600;
}
.level-item.exhausted {
  opacity: 0.75;
  cursor: not-allowed;
}
.preview-label {
  font-size: 12px;
  color: #6b7280;
  margin-bottom: 8px;
  text-align: center;
}
.play-tips {
  font-size: 12px;
  color: #9ca3af;
  margin-top: 12px;
  text-align: center;
  max-width: 200px;
}

.header {
  text-align: center;
  color: white;
  margin-bottom: 30px;
}
.header h1 {
  font-size: 32px;
  margin-bottom: 8px;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
}
.header p {
  opacity: 0.9;
  font-size: 14px;
}

.layout {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 20px;
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
}

.card {
  background: white;
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.12);
}

.card h2 {
  font-size: 20px;
  margin-bottom: 16px;
  color: #4c1d95;
  border-bottom: 2px solid #ede9fe;
  padding-bottom: 10px;
}

.btn {
  display: inline-block;
  padding: 12px 28px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  text-decoration: none;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(102,126,234,0.4); }
.btn:disabled { background: #ccc; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-secondary { background: #f3f4f6; color: #4c1d95; }
.btn-secondary:hover { background: #ede9fe; }

.input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid #e5e7eb;
  border-radius: 10px;
  font-size: 15px;
  transition: border-color 0.15s;
}
.input:focus { outline: none; border-color: #667eea; }
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 14px;
  margin-bottom: 6px;
  color: #4b5563;
  font-weight: 500;
}

/* ---- 关卡列表 ---- */
.level-list { display: flex; flex-direction: column; gap: 12px; }
.level-item {
  display: flex;
  align-items: center;
  padding: 16px;
  border: 2px solid #e5e7eb;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.15s;
}
.level-item.unlocked:hover { border-color: #667eea; background: #f5f3ff; }
.level-item.locked { opacity: 0.5; cursor: not-allowed; }
.level-item.completed { background: linear-gradient(135deg, #dcfce7 0%, #bbf7d0 100%); border-color: #86efac; }
.level-item .level-icon { font-size: 32px; margin-right: 16px; }
.level-item .level-info { flex: 1; }
.level-item .level-info h3 { font-size: 16px; margin-bottom: 4px; color: #1f2937; }
.level-item .level-info p { font-size: 13px; color: #6b7280; }
.level-item .level-badge {
  padding: 6px 12px; border-radius: 20px; font-size: 12px; font-weight: 600;
}
.badge-locked { background: #f3f4f6; color: #9ca3af; }
.badge-ready { background: #dbeafe; color: #1e40af; }
.badge-done { background: #22c55e; color: white; }

/* ---- 排行榜 ---- */
.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.leaderboard-table th {
  padding: 10px 8px;
  background: #f9fafb;
  color: #6b7280;
  font-weight: 600;
  text-align: left;
  border-bottom: 2px solid #e5e7eb;
  font-size: 12px;
}
.leaderboard-table td {
  padding: 10px 8px;
  border-bottom: 1px solid #f3f4f6;
}
.leaderboard-table tr:hover { background: #fafafa; }
.leaderboard-table tr.lb-me { background: #fef3c7; }
.rank-1 { color: #f59e0b; font-weight: 700; font-size: 16px; }
.rank-2 { color: #6b7280; font-weight: 700; font-size: 15px; }
.rank-3 { color: #b45309; font-weight: 700; font-size: 15px; }
.lb-caption {
  font-size: 12px;
  color: #6b7280;
  margin-bottom: 8px;
}
.my-rank-box {
  margin-top: 14px;
  padding: 12px 14px;
  background: linear-gradient(135deg, #ede9fe 0%, #e0e7ff 100%);
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  color: #3730a3;
  line-height: 1.5;
}
.my-rank-box.muted {
  background: #f3f4f6;
  color: #6b7280;
  font-weight: 500;
}
.my-rank-hint {
  margin-top: 4px;
  font-size: 12px;
  font-weight: 500;
  color: #6366f1;
}

/* ---- 拼图游戏 ---- */
.puzzle-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}
.timer {
  font-size: 24px;
  font-weight: 700;
  color: #dc2626;
  font-family: "Courier New", monospace;
  background: #fef2f2;
  padding: 8px 16px;
  border-radius: 8px;
}
.puzzle-wrap {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  flex-wrap: wrap;
  justify-content: center;
}
.puzzle-board {
  display: grid;
  gap: 2px;
  background: #333;
  padding: 4px;
  border-radius: 8px;
  width: min(520px, 90vw);
  aspect-ratio: 1;
}
.puzzle-preview {
  width: 200px;
  height: 200px;
  border: 3px solid #667eea;
  border-radius: 8px;
  background-size: cover;
}
.puzzle-cell {
  background-size: cover;
  cursor: grab;
  user-select: none;
  transition: transform 0.1s, box-shadow 0.1s;
  border-radius: 2px;
}
.puzzle-cell.correct { box-shadow: inset 0 0 0 2px #22c55e; }
.puzzle-cell.dragging { opacity: 0.4; }
.puzzle-cell.drag-over { box-shadow: inset 0 0 0 3px #f59e0b; }

.result-panel {
  text-align: center;
  padding: 30px;
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
  border-radius: 12px;
  margin: 20px 0;
}
.result-panel h2 { color: #92400e; font-size: 28px; margin-bottom: 8px; }
.result-panel .time { font-size: 36px; font-weight: 700; color: #dc2626; margin: 10px 0; }
.result-panel .best { font-size: 14px; color: #78350f; }

/* ---- 奖励页 ---- */
.reward-gallery { display: flex; flex-direction: column; gap: 16px; align-items: center; }
.reward-gallery img { max-width: 100%; border-radius: 12px; box-shadow: 0 4px 15px rgba(0,0,0,0.1); }

.intro-text {
  white-space: pre-line;
  line-height: 1.8;
  color: #4b5563;
  background: #f9fafb;
  padding: 16px;
  border-radius: 10px;
  margin-bottom: 20px;
  font-size: 14px;
}

/* ---- 管理后台 ---- */
.admin-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 16px;
  font-size: 13px;
}
.admin-table th, .admin-table td {
  padding: 10px 8px;
  border: 1px solid #e5e7eb;
  text-align: left;
}
.admin-table th { background: #f9fafb; font-weight: 600; }
.admin-table tr:nth-child(even) { background: #fafafa; }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.stats { display: flex; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.stat-card { flex: 1; min-width: 120px; background: #f5f3ff; padding: 16px; border-radius: 10px; text-align: center; }
.stat-card .num { font-size: 28px; font-weight: 700; color: #4c1d95; }
.stat-card .label { font-size: 12px; color: #6b7280; margin-top: 4px; }

.loading { text-align: center; padding: 40px; color: #6b7280; }
.empty { text-align: center; padding: 40px; color: #9ca3af; font-size: 14px; }

/* ---- 再次挑战按钮（关卡列表） ---- */
.retry-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 10px 14px;
  min-height: 44px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.retry-btn:active { transform: scale(0.97); opacity: 0.92; }
.retry-ico { font-size: 16px; line-height: 1; }
.retry-txt { line-height: 1.2; }

/* ---- 通关结果操作区 ---- */
.result-actions {
  margin-top: 20px;
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}
.result-actions .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  min-width: 140px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.result-actions .btn-ico { font-size: 18px; line-height: 1; }
.btn-retry {
  background: linear-gradient(135deg, #f59e0b 0%, #ea580c 100%) !important;
  color: #fff !important;
  box-shadow: 0 4px 14px rgba(234, 88, 12, 0.35);
}
.result-hint {
  margin-top: 12px;
  font-size: 12px;
  color: #92400e;
  opacity: 0.85;
}

/* ---- 手机端适配 ---- */
html, body {
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: contain;
}
.btn, .input, .level-item, .lang-select, .retry-btn {
  touch-action: manipulation;
}

@media (max-width: 900px) {
  body { padding: 12px; padding-top: 56px; }
  .header { margin-bottom: 16px; }
  .header h1 { font-size: 22px; padding: 0 48px; }
  .header p { font-size: 13px; }
  .card { padding: 16px; border-radius: 14px; }
  .card h2 { font-size: 17px; }

  .lang-switcher {
    top: 8px;
    right: 8px;
    padding: 6px 10px;
    gap: 6px;
  }
  .lang-label { display: none; }
  .lang-select {
    max-width: 130px;
    font-size: 14px;
    min-height: 36px;
  }

  .btn {
    width: 100%;
    min-height: 48px;
    font-size: 16px;
    padding: 14px 16px;
  }

  .level-item {
    flex-wrap: wrap;
    gap: 8px;
    padding: 14px;
    min-height: 72px;
  }
  .level-item .level-icon { font-size: 28px; margin-right: 10px; }
  .level-item .level-info { flex: 1 1 55%; min-width: 0; }
  .level-item .level-info h3 { font-size: 15px; }
  .level-item .level-info p { font-size: 12px; }
  .level-item .level-badge {
    font-size: 11px;
    padding: 8px 10px;
  }
  .retry-btn {
    width: 100%;
    justify-content: center;
    margin-top: 8px;
    font-size: 15px;
  }

  .puzzle-header { gap: 8px; }
  .puzzle-header .btn { width: auto; min-width: 120px; }
  .timer { font-size: 20px; width: 100%; text-align: center; }

  .puzzle-wrap {
    flex-direction: column;
    align-items: center;
  }
  .puzzle-board {
    width: min(100%, 92vw);
    max-width: 420px;
  }
  .puzzle-preview {
    width: 120px;
    height: 120px;
  }
  .play-tips { max-width: none; }

  .result-panel { padding: 20px 14px; margin: 12px 0; }
  .result-panel h2 { font-size: 22px; }
  .result-panel .time { font-size: 30px; }
  .result-actions {
    flex-direction: column;
    gap: 10px;
  }
  .result-actions .btn {
    width: 100%;
    min-width: 0;
  }

  .leaderboard-table { font-size: 12px; }
  .leaderboard-table th,
  .leaderboard-table td { padding: 8px 4px; }

  .my-rank-box { font-size: 12px; }
}

@media (max-width: 380px) {
  .header h1 { font-size: 18px; }
  .level-item .level-badge { width: 100%; text-align: center; }
}
