/* ==========================================================
   听写打卡小程序 — 样式表
   移动端优先 · 白色背景 · 孩子友好
   ========================================================== */

/* ---- Reset & Base ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #4A90D9;
  --success: #52C41A;
  --warning: #FA8C16;
  --danger: #F5222D;
  --bg: #FFFFFF;
  --bg-gray: #F5F5F5;
  --text: #333333;
  --text-light: #888888;
  --border: #E8E8E8;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  max-width: 480px;
  margin: 0 auto;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

/* ---- Page System ---- */
.page { display: none; padding: 20px 16px; min-height: 100vh; }
.page.active { display: block; animation: fadeIn 0.25s ease; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---- Top Bar ---- */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

.top-title { font-size: 1rem; font-weight: 600; }
.top-progress { font-size: 0.9rem; color: var(--primary); font-weight: 600; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  background: var(--bg);
  color: var(--text);
  transition: all 0.15s;
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
}

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

.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-warning { background: var(--warning); color: #fff; border-color: var(--warning); }
.btn-outline { background: var(--bg); }
.btn-lg { padding: 14px 28px; font-size: 1.05rem; width: 100%; }
.btn-back { background: none; border: none; padding: 6px 10px; font-size: 1rem; color: var(--primary); cursor: pointer; }

/* ---- Header ---- */
.header {
  text-align: center;
  padding: 30px 0 24px;
}

.header h1 {
  font-size: 1.8rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.subtitle {
  color: var(--text-light);
  font-size: 0.9rem;
}

/* ---- Subject Cards ---- */
.subject-cards {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 20px;
}

.subject-card {
  padding: 24px 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}

.subject-card:active { transform: scale(0.97); }

.card-chinese {
  background: linear-gradient(135deg, #FFF7E6, #FFE7BA);
  border: 2px solid #FFD591;
}

.card-english {
  background: linear-gradient(135deg, #E6F7FF, #BAE7FF);
  border: 2px solid #91D5FF;
}

.card-icon { font-size: 2.5rem; margin-bottom: 8px; }
.card-title { font-size: 1.3rem; font-weight: 700; margin-bottom: 4px; }
.card-sub { font-size: 0.85rem; color: var(--text-light); margin-bottom: 8px; }
.card-progress { font-size: 0.85rem; font-weight: 500; }

.home-actions {
  display: flex;
  gap: 12px;
}

.home-actions .btn { flex: 1; }

/* ---- Dictation Page ---- */
.dictation-main {
  text-align: center;
  padding: 30px 0;
}

.word-display {
  background: var(--bg-gray);
  border-radius: var(--radius);
  padding: 30px 20px;
  margin-bottom: 16px;
}

.word-big {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 10px;
  letter-spacing: 4px;
}

.word-extra {
  font-size: 0.95rem;
  color: var(--text-light);
}

.dictation-hint {
  color: var(--text-light);
  font-size: 0.85rem;
  margin-bottom: 20px;
}

.dictation-hint p { margin-bottom: 4px; }

.dictation-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.dictation-actions .btn { flex: 1; min-width: calc(50% - 6px); }
.dictation-actions .btn-lg { flex-basis: 100%; }

/* ---- Photo Page ---- */
.photo-area {
  margin-bottom: 16px;
}

#camera-video {
  width: 100%;
  border-radius: var(--radius);
  background: #000;
}

#photo-preview-img {
  width: 100%;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.upload-hint-inner {
  text-align: center;
  padding: 60px 20px;
  background: var(--bg-gray);
  border-radius: var(--radius);
}

.upload-hint-inner p { margin-bottom: 8px; }

.photo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.photo-actions .btn { flex: 1; min-width: calc(50% - 6px); }
.photo-actions .btn-lg { flex-basis: 100%; }

/* ---- OCR Preview ---- */
#ocr-preview-area {
  margin-top: 16px;
}

#ocr-preview-area h3 {
  font-size: 1rem;
  margin-bottom: 12px;
  color: var(--text-light);
}

#ocr-results-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ocr-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border-radius: 8px;
  border: 2px solid var(--border);
  flex-wrap: wrap;
}

.ocr-correct { border-color: var(--success); background: #F6FFED; }
.ocr-wrong { border-color: var(--danger); background: #FFF2F0; }

.ocr-word-num {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--bg-gray);
  text-align: center;
  line-height: 24px;
  font-size: 0.8rem;
  font-weight: 600;
  flex-shrink: 0;
}

.ocr-answer { font-size: 0.9rem; flex-shrink: 0; }

.ocr-written {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 120px;
}

.ocr-edit-input {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  min-width: 80px;
  background: #fff;
}

.ocr-status { font-size: 1.1rem; flex-shrink: 0; }

/* ---- Result Page ---- */
.result-summary {
  text-align: center;
  font-size: 1.2rem;
  font-weight: 700;
  padding: 20px;
  background: var(--bg-gray);
  border-radius: var(--radius);
  margin-bottom: 16px;
}

.result-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}

.result-item {
  padding: 12px 16px;
  border-radius: 8px;
  border: 2px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.result-correct { border-color: var(--success); background: #F6FFED; }
.result-wrong { border-color: var(--danger); background: #FFF2F0; }

.result-word { font-size: 1.1rem; font-weight: 600; }
.result-written { font-size: 0.85rem; color: var(--danger); }

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.result-actions .btn { flex: 1; min-width: calc(50% - 6px); }

/* ---- History Page ---- */
.tabs {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.tab {
  flex: 1;
  padding: 10px;
  text-align: center;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
}

.tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-card {
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
}

.history-card:active { background: var(--bg-gray); }

.history-date { font-weight: 600; font-size: 1rem; margin-bottom: 4px; }
.history-score { color: var(--primary); font-size: 0.9rem; margin-bottom: 4px; }
.history-words { font-size: 0.85rem; letter-spacing: 4px; }

.history-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-light);
}

/* ---- Detail Page ---- */
.detail-info {
  text-align: center;
  padding: 16px;
  color: var(--text-light);
  font-size: 0.95rem;
  margin-bottom: 16px;
}

.detail-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.detail-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.detail-correct { background: #F6FFED; }
.detail-wrong { background: #FFF2F0; }

.detail-word { font-weight: 600; flex: 1; }
.detail-written { font-size: 0.8rem; color: var(--danger); }

/* ---- Loading ---- */
#loading-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(255,255,255,0.9);
  z-index: 999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.loading-spinner {
  width: 40px; height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-text {
  font-size: 1rem;
  color: var(--text-light);
}

/* ---- Responsive — 平板及以上 ---- */
@media (min-width: 768px) {
  body {
    max-width: 600px;
    box-shadow: 0 0 40px rgba(0,0,0,0.06);
    min-height: 100vh;
  }

  .word-big { font-size: 3rem; }

  .subject-cards {
    flex-direction: row;
  }

  .subject-card { flex: 1; }
}

/* ---- Print (for records) ---- */
@media print {
  .btn, .top-bar, .dictation-actions, .photo-actions, .result-actions { display: none !important; }
  body { max-width: none; }
  .page { display: block !important; }
}
