/* ============================================================
   汉字消消乐 — style.css
   ============================================================ */

/* ---------- 基础重置 ---------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ---------- 全局 ---------- */
html, body {
  height: 100%;
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
  background: #f0f4ff;
  color: #333;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

/* ---------- 游戏主容器 ---------- */
#game-container {
  max-width: 750px;
  margin: 0 auto;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom, 0px)) 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  min-height: 100vh;
}

/* ---------- 目标拼音区 ---------- */
#target-area {
  width: 100%;
  text-align: center;
  background: linear-gradient(135deg, #4f6ef7 0%, #7b5ef8 100%);
  border-radius: 16px;
  padding: 14px 20px 18px;
  box-shadow: 0 4px 16px rgba(79, 110, 247, 0.35);
}

#target-area .label {
  font-size: 0.82rem;
  color: rgba(255, 255, 255, 0.85);
  margin-bottom: 6px;
  letter-spacing: 0.03em;
}

#target-pinyin {
  font-size: 2.4rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.12em;
  line-height: 1.2;
  text-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

/* ---------- 得分区 ---------- */
#score-area {
  width: 100%;
  display: flex;
  justify-content: space-around;
  gap: 12px;
}

#score-area > span {
  flex: 1;
  text-align: center;
  background: #fff;
  border-radius: 12px;
  padding: 10px 8px;
  font-size: 0.95rem;
  color: #555;
  box-shadow: 0 2px 8px rgba(0,0,0,0.07);
}

#current-score,
#high-score,
#remaining-count {
  font-weight: 700;
  font-size: 1.3rem;
  color: #4f6ef7;
  display: inline-block;
  transition: transform 0.15s ease;
}

#current-score.jump,
#high-score.jump {
  transform: scale(1.35);
}

/* ---------- 网格容器 ---------- */
#grid-container {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

/* 暂停时网格模糊 */
#grid-container.paused {
  filter: blur(4px);
  pointer-events: none;
  user-select: none;
}

/* ---------- 格子 ---------- */
.cell {
  aspect-ratio: 1 / 1;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 3px 10px rgba(0,0,0,0.10);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.1rem;
  font-weight: 700;
  color: #2d2d2d;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  -webkit-user-select: none;
  user-select: none;
  min-height: 44px;
  min-width: 44px;
}

.cell:active {
  transform: scale(0.92);
  box-shadow: 0 1px 4px rgba(0,0,0,0.10);
}

.cell.empty {
  background: #e8ecf8;
  box-shadow: none;
  cursor: default;
}

/* 多字词语格子字体适配 */
.cell-2char {
  font-size: 1.5rem;
  letter-spacing: 0.05em;
}

.cell-3char {
  font-size: 1.15rem;
  letter-spacing: 0.03em;
}

.cell-4char {
  font-size: 0.95rem;
  letter-spacing: 0.02em;
}

/* ---------- 正确消除动画 ---------- */
@keyframes cellCorrect {
  0%   { transform: scale(1);    opacity: 1; }
  40%  { transform: scale(1.18); opacity: 0.9; }
  100% { transform: scale(0);    opacity: 0; }
}

.cell-correct {
  animation: cellCorrect 0.32s ease forwards;
  pointer-events: none;
}

/* ---------- 错误抖动动画 ---------- */
@keyframes cellWrong {
  0%   { transform: translateX(0); }
  15%  { transform: translateX(-8px); }
  30%  { transform: translateX(8px); }
  45%  { transform: translateX(-6px); }
  60%  { transform: translateX(6px); }
  75%  { transform: translateX(-3px); }
  90%  { transform: translateX(3px); }
  100% { transform: translateX(0); }
}

.cell-wrong {
  animation: cellWrong 0.42s ease;
  background: #ffe5e5 !important;
}

/* ---------- 格子出现动画 ---------- */
@keyframes cellAppear {
  0%   { transform: translateY(-28px) scale(0.8); opacity: 0; }
  60%  { transform: translateY(4px)   scale(1.05); opacity: 1; }
  100% { transform: translateY(0)     scale(1);    opacity: 1; }
}

.cell-appear {
  animation: cellAppear 0.34s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* ---------- 得分浮动弹出 ---------- */
@keyframes scoreFloat {
  0%   { opacity: 1; transform: translateY(0)    scale(1); }
  60%  { opacity: 1; transform: translateY(-44px) scale(1.2); }
  100% { opacity: 0; transform: translateY(-72px) scale(0.9); }
}

#score-popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 2rem;
  font-weight: 900;
  color: #4f6ef7;
  text-shadow: 0 2px 8px rgba(79, 110, 247, 0.4);
  pointer-events: none;
  z-index: 9999;
  animation: none;
}

#score-popup.animate {
  animation: scoreFloat 0.7s ease forwards;
}

/* ---------- 连击显示 ---------- */
#combo-display {
  position: fixed;
  top: 35%;
  left: 50%;
  transform: translateX(-50%);
  font-size: 1.5rem;
  font-weight: 900;
  color: #ff6b35;
  text-shadow: 0 2px 8px rgba(255, 107, 53, 0.4);
  pointer-events: none;
  z-index: 9998;
}

@keyframes comboAppear {
  0%   { transform: translateX(-50%) scale(0.5); opacity: 0; }
  50%  { transform: translateX(-50%) scale(1.25); opacity: 1; }
  100% { transform: translateX(-50%) scale(1); opacity: 1; }
}

#combo-display.combo-anim {
  animation: comboAppear 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* ---------- 控制按钮区 ---------- */
#controls {
  width: 100%;
  display: flex;
  gap: 10px;
  justify-content: center;
}

#controls button {
  flex: 1;
  min-height: 46px;
  border: none;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s ease, opacity 0.1s ease;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}

#controls button:active {
  transform: scale(0.95);
  opacity: 0.85;
}

#btn-restart {
  background: #4f6ef7;
  color: #fff;
  box-shadow: 0 3px 10px rgba(79, 110, 247, 0.35);
}

#btn-pause {
  background: #ff9a3c;
  color: #fff;
  box-shadow: 0 3px 10px rgba(255, 154, 60, 0.35);
}

#btn-wordbank {
  background: #fff;
  color: #4f6ef7;
  border: 2px solid #4f6ef7;
  box-shadow: 0 2px 8px rgba(79, 110, 247, 0.12);
}

/* ---------- 游戏说明 ---------- */
#game-info {
  font-size: 0.8rem;
  color: #999;
  text-align: center;
}

/* ---------- 全局 hidden ---------- */
.hidden {
  display: none !important;
}

/* ---------- 模态遮罩 ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
  backdrop-filter: blur(2px);
}

.modal-content {
  background: #fff;
  border-radius: 20px;
  padding: 24px 20px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-content h3 {
  font-size: 1.25rem;
  font-weight: 700;
  color: #222;
  text-align: center;
}

.modal-content p {
  text-align: center;
  font-size: 1rem;
  color: #444;
  line-height: 1.6;
}

/* ---------- 字词库弹窗细节 ---------- */
.modal-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal-section label {
  font-size: 0.88rem;
  color: #555;
  font-weight: 600;
}

.modal-section textarea {
  width: 100%;
  min-height: 72px;
  border: 1.5px solid #dce1f0;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 1rem;
  font-family: inherit;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s;
  color: #333;
  background: #f8f9ff;
}

.modal-section textarea:focus {
  border-color: #4f6ef7;
}

.modal-section input[type="file"] {
  font-size: 0.88rem;
  color: #444;
}

#ocr-progress {
  font-size: 0.88rem;
  color: #ff9a3c;
  font-style: italic;
}

/* ---------- 字词库弹窗加宽 ---------- */
.wordbank-modal-content {
  max-height: 88vh;
  overflow-y: auto;
}

/* ---------- 预设主题词库按钮 ---------- */
#preset-bank-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.preset-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border: 1.5px solid #dce1f0;
  border-radius: 8px;
  background: #f8f9ff;
  font-size: 0.82rem;
  font-weight: 600;
  color: #444;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.preset-btn:hover {
  border-color: #4f6ef7;
  color: #4f6ef7;
}

.preset-btn.active {
  background: #4f6ef7;
  color: #fff;
  border-color: #4f6ef7;
}

.preset-btn .preset-icon {
  font-size: 1rem;
}

/* ---------- 校验反馈 ---------- */
#wordbank-validation {
  margin-top: 6px;
  font-size: 0.82rem;
  line-height: 1.5;
}

#validation-stats {
  display: block;
  font-weight: 600;
  color: #4caf50;
}

#validation-stats.has-invalid {
  color: #ff9800;
}

#validation-stats.all-invalid {
  color: #e53935;
}

#validation-detail {
  margin-top: 4px;
  padding: 6px 10px;
  background: #fff8e1;
  border-radius: 6px;
  color: #795548;
  font-size: 0.78rem;
  line-height: 1.6;
  word-break: break-all;
}

/* ---------- 字词库列表 ---------- */
#wordbank-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 160px;
  overflow-y: auto;
  padding: 8px;
  background: #f8f9ff;
  border-radius: 10px;
  border: 1.5px solid #e8ecf8;
}

.wordbank-item {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: 0 10px;
  background: #fff;
  border: 1.5px solid #dce1f0;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  color: #333;
  cursor: pointer;
  transition: all 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.wordbank-item:hover {
  border-color: #4f6ef7;
  color: #4f6ef7;
  background: #f0f3ff;
}

.wordbank-item:active {
  transform: scale(0.93);
}

.wordbank-item.item-no-pinyin {
  opacity: 0.4;
  cursor: not-allowed;
  border-color: #e0e0e0;
}

.wordbank-list-empty {
  width: 100%;
  text-align: center;
  font-size: 0.82rem;
  color: #999;
  padding: 12px 0;
}

/* ---------- 字词详情弹窗 ---------- */
.word-detail-content {
  max-width: 380px;
  gap: 14px;
}

#word-detail-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1.5px solid #eef0f8;
}

#word-detail-word {
  font-size: 2rem;
  font-weight: 800;
  color: #2d2d2d;
}

#word-detail-pinyin {
  font-size: 1.1rem;
  color: #4f6ef7;
  font-weight: 600;
  letter-spacing: 0.05em;
}

.word-detail-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.detail-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.detail-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

#word-detail-meaning {
  font-size: 0.95rem;
  color: #333;
  line-height: 1.6;
}

#word-detail-phrases,
#word-detail-synonyms {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.phrase-tag {
  display: inline-block;
  padding: 3px 10px;
  background: #eef1ff;
  border-radius: 6px;
  font-size: 0.82rem;
  color: #4f6ef7;
  font-weight: 500;
}

.synonym-tag {
  display: inline-block;
  padding: 3px 10px;
  background: #f0f7ee;
  border-radius: 6px;
  font-size: 0.82rem;
  color: #4caf50;
  font-weight: 500;
}

.detail-empty {
  font-size: 0.82rem;
  color: #bbb;
  font-style: italic;
}

#btn-close-detail {
  width: 100%;
  min-height: 42px;
  border: none;
  border-radius: 10px;
  background: #eee;
  color: #555;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

#btn-close-detail:active {
  transform: scale(0.96);
}

/* ---------- 弹窗按钮 ---------- */
.modal-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.modal-buttons button {
  flex: 1;
  min-height: 44px;
  border: none;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.1s ease, opacity 0.1s ease;
  -webkit-tap-highlight-color: transparent;
}

.modal-buttons button:active {
  transform: scale(0.95);
  opacity: 0.85;
}

#btn-save-wordbank {
  background: #4f6ef7;
  color: #fff;
}

#btn-reset-wordbank {
  background: #ff9a3c;
  color: #fff;
}

#btn-close-modal {
  background: #eee;
  color: #555;
}

/* ---------- 游戏结束弹窗 ---------- */
#gameover-modal .modal-content {
  gap: 14px;
}

#gameover-modal h3 {
  color: #e53935;
}

#final-score,
#final-high,
#final-combo {
  font-weight: 700;
  font-size: 1.2rem;
  color: #4f6ef7;
}

#btn-restart2 {
  width: 100%;
  min-height: 48px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, #4f6ef7, #7b5ef8);
  color: #fff;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 4px 14px rgba(79, 110, 247, 0.4);
  transition: transform 0.1s ease;
  -webkit-tap-highlight-color: transparent;
}

#btn-restart2:active {
  transform: scale(0.96);
}

/* ---------- 媒体查询：小屏幕 (<375px) ---------- */
@media (max-width: 374px) {
  #target-pinyin {
    font-size: 1.9rem;
  }

  .cell {
    font-size: 1.6rem;
    border-radius: 10px;
  }

  #controls {
    flex-wrap: wrap;
  }

  #controls button {
    flex: 1 1 calc(50% - 5px);
    font-size: 0.82rem;
    min-height: 42px;
  }

  #score-area > span {
    font-size: 0.82rem;
  }

  #current-score,
  #high-score,
  #remaining-count {
    font-size: 1.1rem;
  }
}

/* ---------- 媒体查询：大屏幕 (>600px) ---------- */
@media (min-width: 600px) {
  #grid-container {
    gap: 14px;
  }

  .cell {
    font-size: 2.5rem;
  }

  #target-pinyin {
    font-size: 2.8rem;
  }
}

/* ---------- 错题集按钮 ---------- */
#btn-mistakes {
  background: #e53935;
  color: #fff;
  box-shadow: 0 3px 10px rgba(229, 57, 53, 0.35);
}

/* ---------- 错题集弹窗 ---------- */
.mistake-modal-content {
  max-height: 88vh;
  overflow-y: auto;
}

.mistake-count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  background: #e53935;
  color: #fff;
  border-radius: 11px;
  font-size: 0.75rem;
  font-weight: 700;
  vertical-align: middle;
  margin-left: 6px;
}

/* ---------- 错题列表 ---------- */
#mistake-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 55vh;
  overflow-y: auto;
  padding: 4px 0;
}

.mistake-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px;
  background: #f8f9ff;
  border: 1.5px solid #e8ecf8;
  border-radius: 12px;
  transition: border-color 0.15s;
}

.mistake-item:hover {
  border-color: #d0d5ee;
}

.mistake-word {
  flex-shrink: 0;
  min-width: 48px;
  min-height: 48px;
  padding: 4px 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border: 1.5px solid #dce1f0;
  border-radius: 10px;
  font-weight: 800;
  color: #2d2d2d;
}

.mistake-word.mw-1char {
  width: 48px;
  font-size: 1.5rem;
}

.mistake-word.mw-2char {
  font-size: 1.2rem;
  letter-spacing: 0.03em;
}

.mistake-word.mw-3char {
  font-size: 1rem;
  letter-spacing: 0.02em;
}

.mistake-word.mw-4char {
  font-size: 0.85rem;
  letter-spacing: 0.01em;
}

.mistake-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.mistake-pinyin {
  font-size: 0.85rem;
  color: #4f6ef7;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.mistake-meaning {
  font-size: 0.82rem;
  color: #555;
  line-height: 1.5;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mistake-error-count {
  font-size: 0.75rem;
  color: #e53935;
  font-weight: 600;
}

.mistake-actions {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
  align-self: center;
}

.btn-add-wordbank {
  padding: 5px 10px;
  border: none;
  border-radius: 6px;
  background: #4caf50;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.1s, opacity 0.1s;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}

.btn-add-wordbank:active {
  transform: scale(0.93);
  opacity: 0.85;
}

.btn-add-wordbank.btn-in-wordbank {
  background: #ccc;
  color: #888;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-remove-mistake {
  padding: 5px 10px;
  border: none;
  border-radius: 6px;
  background: #fff5f5;
  color: #d32f2f;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.1s, opacity 0.1s;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}

.btn-remove-mistake:active {
  transform: scale(0.93);
}

.mistake-empty {
  text-align: center;
  padding: 32px 0;
  color: #bbb;
  font-size: 0.9rem;
}

.btn-warn-mistake {
  background: #e53935;
  color: #fff;
}

/* 错题集按钮在小屏适配 */
@media (max-width: 374px) {
  .mistake-item {
    padding: 8px;
    gap: 8px;
  }

  .mistake-word {
    min-width: 40px;
    min-height: 40px;
    padding: 3px 8px;
  }

  .mistake-word.mw-1char {
    width: 40px;
    font-size: 1.3rem;
  }

  .mistake-word.mw-2char {
    font-size: 1.05rem;
  }

  .mistake-word.mw-3char {
    font-size: 0.9rem;
  }

  .mistake-word.mw-4char {
    font-size: 0.78rem;
  }

  .mistake-actions {
    gap: 3px;
  }

  .btn-add-wordbank,
  .btn-remove-mistake {
    font-size: 0.7rem;
    padding: 4px 8px;
  }
}
