/* ===== Reset (cloned from wuziqi) ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  touch-action: manipulation;
  overscroll-behavior: contain;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  width: 100%;
  min-height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  color: #4a3520;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding:
    calc(env(safe-area-inset-top) + 28px)
    env(safe-area-inset-right)
    calc(env(safe-area-inset-bottom) + 28px)
    env(safe-area-inset-left);
  background:
    radial-gradient(ellipse at 50% 0%, #fff6d0 0%, rgba(255, 246, 208, 0) 60%),
    radial-gradient(ellipse at 0% 100%, #ffe9a8 0%, rgba(255, 233, 168, 0) 55%),
    radial-gradient(ellipse at 100% 100%, #ffd97a 0%, rgba(255, 217, 122, 0) 55%),
    linear-gradient(180deg, #fff4cc 0%, #ffeab5 100%);
  background-attachment: fixed;
}

/* ===== Back-to-Home Button ===== */
.back-home-btn {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 12px);
  left: 14px;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: none;
  color: #8a6a4a;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  padding: 8px 14px;
  border-radius: 999px;
  text-decoration: none;
  z-index: 50;
  box-shadow: 0 2px 8px rgba(180, 130, 50, 0.15);
  transition: transform 80ms ease, background 80ms ease;
}
.back-home-btn:active {
  transform: scale(0.94);
  background: rgba(255, 255, 255, 0.9);
}

/* ===== Settings Button (corner, subtle — kids ignore) ===== */
.settings-btn {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 12px);
  right: 14px;
  background: rgba(200, 200, 200, 0.35);
  border: none;
  color: #a89888;
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  z-index: 50;
  -webkit-tap-highlight-color: transparent;
}
.settings-btn:active { background: rgba(200, 200, 200, 0.5); }

/* ===== Main App Container ===== */
#app {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  animation: shizi-fade-in 300ms ease-out;
}

@keyframes shizi-fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== Progress Bar (main screen top) ===== */
.shizi-progress-bar {
  display: flex;
  justify-content: space-around;
  padding: 10px 16px;
  margin-bottom: 16px;
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 16px;
  box-shadow: 0 4px 12px rgba(180, 130, 50, 0.12);
}
.shizi-progress-stat {
  font-size: 15px;
  font-weight: 600;
  color: #5a3a1a;
}

/* ===== Main Screen Title ===== */
.shizi-main-title {
  font-size: 36px;
  font-weight: 800;
  color: #5a3a1a;
  text-align: center;
  letter-spacing: 2px;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.6);
  margin-bottom: 4px;
}
.shizi-main-subtitle {
  font-size: 16px;
  color: #8a6a4a;
  text-align: center;
  margin-bottom: 24px;
  letter-spacing: 0.5px;
}

/* ===== Mode Cards (main screen) ===== */
.shizi-mode-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-bottom: 20px;
}
@media (min-width: 480px) {
  .shizi-mode-grid { grid-template-columns: 1fr 1fr; }
}

.shizi-mode-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px;
  min-height: 140px;
  background: linear-gradient(180deg, #fff6d8 0%, #ffe1a0 100%);
  border: none;
  border-radius: 24px;
  box-shadow: 0 8px 22px rgba(200, 130, 30, 0.22), inset 0 0 0 2px rgba(255, 217, 122, 0.7);
  cursor: pointer;
  font-family: inherit;
  transition: transform 150ms ease, box-shadow 150ms ease;
  -webkit-tap-highlight-color: transparent;
  animation: shizi-card-pop 500ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.shizi-mode-card:nth-child(2) { animation-delay: 80ms; }
.shizi-mode-card:nth-child(3) { animation-delay: 160ms; }
.shizi-mode-card:active {
  transform: scale(0.97);
  box-shadow: 0 4px 12px rgba(200, 130, 30, 0.3);
}
.shizi-mode-emoji {
  font-size: 48px;
  margin-bottom: 8px;
  line-height: 1;
}
.shizi-mode-name {
  font-size: 22px;
  font-weight: 700;
  color: #5a3a1a;
  margin-bottom: 4px;
}
.shizi-mode-desc {
  font-size: 14px;
  color: #8a6a4a;
}

@keyframes shizi-card-pop {
  from { opacity: 0; transform: scale(0.92) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

/* ===== Sticker Preview ===== */
.shizi-sticker-preview {
  background: rgba(255, 255, 255, 0.5);
  border-radius: 16px;
  padding: 12px 16px;
  text-align: center;
}
.shizi-sticker-preview h3 {
  font-size: 16px;
  color: #5a3a1a;
  margin-bottom: 8px;
}
.shizi-sticker-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}
.shizi-sticker-badge {
  background: linear-gradient(135deg, #ffd97a, #ffb04a);
  color: #5a3a1a;
  font-size: 13px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  box-shadow: 0 2px 6px rgba(200, 130, 30, 0.25);
}

/* ===== Mode Header (back button + title) ===== */
.shizi-mode-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  padding-top: 8px;
}
.shizi-back-btn {
  min-height: 44px;
  min-width: 80px;
  padding: 0 16px;
  font-size: 15px;
  font-weight: 600;
  color: #5a3a1a;
  background: rgba(255, 255, 255, 0.7);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 2px 8px rgba(180, 130, 50, 0.12);
}
.shizi-back-btn:active { transform: scale(0.95); }
.shizi-mode-title {
  font-size: 20px;
  font-weight: 700;
  color: #5a3a1a;
  letter-spacing: 0.5px;
}

/* ===== Level Select Grid ===== */
.shizi-level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}
.shizi-level-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 8px;
  min-height: 110px;
  background: linear-gradient(180deg, #fff8e0 0%, #ffe9b0 100%);
  border: 2px solid #e8c878;
  border-radius: 18px;
  cursor: pointer;
  font-family: inherit;
  color: #5a3a1a;
  -webkit-tap-highlight-color: transparent;
  transition: transform 80ms ease;
}
.shizi-level-card:active { transform: scale(0.97); }
.shizi-level-card.locked {
  background: #f0ece5;
  border-color: #d8d0c4;
  opacity: 0.6;
  cursor: default;
}
.shizi-level-lock { font-size: 28px; margin-bottom: 4px; }
.shizi-level-num { font-size: 17px; font-weight: 700; }
.shizi-level-theme { font-size: 13px; color: #8a6a4a; margin: 2px 0; }
.shizi-level-progress { font-size: 12px; color: #a89888; }

/* ===== Choice Mode: Speaker Area ===== */
.shizi-speaker-area {
  text-align: center;
  padding: 24px 16px;
  margin-bottom: 16px;
}
.shizi-speaker-icon {
  font-size: 80px;
  line-height: 1;
  margin-bottom: 12px;
  display: inline-block;
}
.shizi-speaker-icon.speaking {
  animation: shizi-speaker-pulse 0.6s ease-in-out infinite;
}
@keyframes shizi-speaker-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}
.shizi-instruction {
  font-size: 20px;
  font-weight: 600;
  color: #5a3a1a;
  letter-spacing: 1px;
}
.shizi-pinyin-hint {
  font-size: 24px;
  color: #8a6a4a;
  font-weight: 600;
  margin-top: 8px;
  letter-spacing: 2px;
}

/* ===== Choice Mode: Options Grid ===== */
.shizi-options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}
.shizi-option-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 110px;
  padding: 12px;
  background: linear-gradient(180deg, #fffaf0 0%, #ffe8c0 100%);
  border: 3px solid #e8c878;
  border-radius: 20px;
  cursor: pointer;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  transition: transform 80ms ease, box-shadow 80ms ease;
  box-shadow: 0 4px 10px rgba(200, 130, 30, 0.15);
}
.shizi-option-card:active {
  transform: scale(0.96);
}
.shizi-option-card.wrong {
  opacity: 0.3;
  filter: grayscale(1);
  pointer-events: none;
}
.shizi-option-card.correct {
  box-shadow: 0 0 30px #4caf50, 0 0 0 3px #4caf50;
  transform: scale(1.1);
  background: linear-gradient(180deg, #e8f5e9 0%, #c8e6c9 100%);
}
.shizi-option-char {
  font-size: 60px;
  font-weight: 700;
  color: #3a2a10;
  line-height: 1.1;
}
.shizi-option-label {
  font-size: 14px;
  color: #8a6a4a;
  font-weight: 600;
  margin-top: 4px;
}

/* ===== Choice Mode: Listen Again Button ===== */
.shizi-listen-again-btn {
  display: block;
  margin: 0 auto;
  min-height: 56px;
  min-width: 180px;
  padding: 0 24px;
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(180deg, #6ec6ff 0%, #4a9fdc 100%);
  border: none;
  border-radius: 18px;
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 4px 0 #2a7fb0, 0 6px 14px rgba(40, 120, 180, 0.3);
  -webkit-tap-highlight-color: transparent;
  transition: transform 80ms ease;
}
.shizi-listen-again-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #2a7fb0;
}

/* ===== Encouragement message ===== */
.shizi-encouragement {
  position: fixed;
  bottom: 30%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(90, 58, 26, 0.85);
  color: #fff;
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 18px;
  font-weight: 600;
  z-index: 100;
  animation: shizi-encouragement-pop 1.5s ease;
}
@keyframes shizi-encouragement-pop {
  0% { opacity: 0; transform: translateX(-50%) scale(0.8); }
  20% { opacity: 1; transform: translateX(-50%) scale(1.1); }
  30% { transform: translateX(-50%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; }
}

/* ===== Mini celebration (correct answer) ===== */
.shizi-mini-celebration {
  position: fixed;
  top: 40%;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(180deg, #fffaf0, #ffe1a0);
  color: #c44a00;
  padding: 16px 32px;
  border-radius: 24px;
  font-size: 28px;
  font-weight: 800;
  z-index: 100;
  box-shadow: 0 8px 20px rgba(200, 130, 30, 0.3);
  border: 3px solid #ffd97a;
  animation: shizi-mini-celebration-pop 1.8s ease;
}
@keyframes shizi-mini-celebration-pop {
  0% { opacity: 0; transform: translateX(-50%) scale(0.5); }
  15% { opacity: 1; transform: translateX(-50%) scale(1.15); }
  25% { transform: translateX(-50%) scale(1); }
  85% { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) scale(0.95); }
}

/* ===== Confetti pieces ===== */
.shizi-confetti-piece {
  position: fixed;
  top: -10px;
  width: 10px;
  height: 14px;
  border-radius: 2px;
  z-index: 99;
  animation: shizi-confetti-fall linear forwards;
}
@keyframes shizi-confetti-fall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

/* ===== Recognize Mode: Stroke Stage ===== */
.shizi-stroke-stage {
  width: 280px;
  height: 280px;
  margin: 16px auto;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.shizi-stroke-stage svg {
  max-width: 100%;
  max-height: 100%;
}
.shizi-plain-fallback {
  background: rgba(255, 255, 255, 0.5);
  border-radius: 24px;
}
.shizi-plain-char {
  font-size: 200px;
  font-weight: 700;
  color: #3a2a10;
  line-height: 1;
  cursor: pointer;
}

/* ===== Recognize Mode: Pinyin display (TTS unavailable) ===== */
.shizi-pinyin-display {
  text-align: center;
  font-size: 28px;
  color: #8a6a4a;
  font-weight: 600;
  letter-spacing: 3px;
  margin-bottom: 8px;
}

/* ===== Recognize Mode: Click hint ===== */
.shizi-click-hint {
  text-align: center;
  font-size: 15px;
  color: #a89888;
  margin-bottom: 12px;
}

/* ===== Recognize Mode: Control buttons ===== */
.shizi-recognize-controls {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 20px;
}
.shizi-control-btn {
  min-height: 50px;
  min-width: 120px;
  padding: 0 20px;
  font-size: 16px;
  font-weight: 600;
  color: #5a3a1a;
  background: rgba(255, 255, 255, 0.7);
  border: 2px solid #e8c878;
  border-radius: 16px;
  cursor: pointer;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  transition: transform 80ms ease;
}
.shizi-control-btn:active { transform: scale(0.96); }

/* ===== Recognize Mode: Parent judgment buttons ===== */
.shizi-judge-row {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-bottom: 16px;
}
.shizi-judge-btn {
  min-height: 70px;
  min-width: 140px;
  padding: 0 24px;
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  border: none;
  border-radius: 20px;
  cursor: pointer;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  transition: transform 80ms ease, box-shadow 80ms ease;
}
.shizi-judge-btn:active { transform: translateY(3px); }
.shizi-judge-yes {
  background: linear-gradient(180deg, #66bb6a 0%, #43a047 100%);
  box-shadow: 0 5px 0 #2e7d32, 0 8px 16px rgba(46, 125, 50, 0.3);
}
.shizi-judge-yes:active {
  box-shadow: 0 2px 0 #2e7d32, 0 4px 10px rgba(46, 125, 50, 0.3);
}
.shizi-judge-no {
  background: linear-gradient(180deg, #ffb74d 0%, #ff9800 100%);
  box-shadow: 0 5px 0 #e65100, 0 8px 16px rgba(230, 81, 0, 0.3);
}
.shizi-judge-no:active {
  box-shadow: 0 2px 0 #e65100, 0 4px 10px rgba(230, 81, 0, 0.3);
}

/* ===== Tip text ===== */
.shizi-tip-text {
  text-align: center;
  font-size: 18px;
  color: #8a6a4a;
  font-weight: 500;
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.4);
  border-radius: 12px;
  margin-bottom: 12px;
}

/* ===== Progress hint ===== */
.shizi-progress-hint {
  text-align: center;
  font-size: 14px;
  color: #a89888;
}

/* ===== Brief checkmark (parent confirmed) ===== */
.shizi-brief-checkmark {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 80px;
  color: #4caf50;
  z-index: 100;
  animation: shizi-checkmark-pop 0.8s ease;
}
@keyframes shizi-checkmark-pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.3); }
  50% { opacity: 1; transform: translate(-50%, -50%) scale(1.2); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1); }
}

/* ===== All mastered screen ===== */
.shizi-all-mastered {
  text-align: center;
  padding: 40px 20px;
}
.shizi-all-mastered-emoji {
  font-size: 80px;
  margin-bottom: 16px;
}
.shizi-all-mastered h2 {
  font-size: 28px;
  color: #5a3a1a;
  margin-bottom: 8px;
}
.shizi-all-mastered p {
  font-size: 16px;
  color: #8a6a4a;
  margin-bottom: 24px;
}

/* ===== Progress View (我的字库) ===== */
.shizi-progress-section {
  margin-bottom: 20px;
}
.shizi-progress-section-title {
  font-size: 17px;
  font-weight: 700;
  color: #5a3a1a;
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 2px solid rgba(200, 130, 30, 0.2);
}
.shizi-progress-chars {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}
.shizi-progress-char-cell {
  text-align: center;
  padding: 8px 4px;
  background: rgba(255, 255, 255, 0.4);
  border-radius: 10px;
}
.shizi-progress-char-cell.mastered {
  background: linear-gradient(180deg, #e8f5e9, #c8e6c9);
}
.shizi-progress-char-cell.unlearned {
  opacity: 0.5;
}
.shizi-progress-char {
  font-size: 28px;
  font-weight: 700;
  color: #3a2a10;
  line-height: 1.2;
}
.shizi-progress-stars {
  font-size: 10px;
  color: #c9933e;
  letter-spacing: 1px;
  margin-top: 2px;
}

/* ===== Celebration Overlay (level clear / sticker) ===== */
.shizi-celebration-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(40, 25, 10, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  overflow: hidden;
}
.shizi-celebration-overlay[hidden] { display: none; }
.shizi-celebration-card {
  background: linear-gradient(180deg, #fffaf0 0%, #fff0d0 100%);
  padding: 32px 40px 28px;
  border-radius: 28px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(80, 50, 10, 0.4);
  border: 3px solid #ffd97a;
  animation: shizi-celebration-pop 600ms cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 201;
  max-width: 80vw;
}
.shizi-celebration-emoji {
  font-size: 72px;
  margin-bottom: 12px;
  animation: shizi-celebration-bounce 1.2s ease-in-out infinite;
}
.shizi-celebration-card h2 {
  font-size: 28px;
  color: #c44a00;
  margin-bottom: 8px;
}
.shizi-celebration-card p {
  font-size: 16px;
  color: #8a6a4a;
}
@keyframes shizi-celebration-pop {
  0% { transform: scale(0.3) rotate(-6deg); opacity: 0; }
  55% { transform: scale(1.1) rotate(2deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); }
}
@keyframes shizi-celebration-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}
.shizi-celebration-confetti {
  position: absolute;
  top: -10px;
  width: 12px;
  height: 16px;
  border-radius: 2px;
  animation: shizi-confetti-fall linear forwards;
}

/* ===== Responsive ===== */
@media (max-width: 380px) {
  .shizi-main-title { font-size: 30px; }
  .shizi-option-char { font-size: 48px; }
  .shizi-stroke-stage { width: 240px; height: 240px; }
  .shizi-plain-char { font-size: 160px; }
  .shizi-progress-chars { grid-template-columns: repeat(5, 1fr); gap: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
