* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: #FFF8E7;
  font-family: "Verdana", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #333; overflow: hidden;
  user-select: none; -webkit-user-select: none;
}
body { display: flex; flex-direction: column; }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; background: #FFE0B2;
  box-shadow: 0 2px 6px rgba(0,0,0,.08);
}
.icon-btn {
  width: 52px; height: 52px; border-radius: 50%;
  border: none; background: #fff; font-size: 26px;
  box-shadow: 0 2px 4px rgba(0,0,0,.12); cursor: pointer;
}
.icon-btn:active { transform: scale(.94); }
.task-title { display: flex; align-items: baseline; gap: 10px; }
.task-label { font-size: 16px; color: #8D6E63; }
.task-char {
  font-size: 44px; font-weight: 900; color: #E64A19; line-height: 1;
}
.topbar-right { display: flex; gap: 8px; }

/* ---------- 舞台 ---------- */
.stage {
  flex: 1; position: relative;
  display: flex; align-items: center; justify-content: center;
  padding: 8px;
}
.canvas {
  width: min(94vw, 78vh, 640px);
  height: min(94vw, 78vh, 640px);
  background: #fff; border-radius: 24px;
  box-shadow: 0 6px 20px rgba(0,0,0,.10);
  touch-action: none;
}

/* ---------- 进度光环 ---------- */
.progress-ring {
  position: absolute; top: 12px; right: 12px;
  width: 60px; height: 60px;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.ring-text {
  position: absolute; font-size: 14px; font-weight: bold; color: #E64A19;
}
#ringFill { transition: stroke-dashoffset .25s ease; }

/* ---------- 星星 ---------- */
.stars {
  position: absolute; bottom: 8px; left: 50%;
  transform: translateX(-50%);
  display: flex; gap: 8px; font-size: 26px;
  pointer-events: none;
}
.stars .star { opacity: .18; transition: opacity .3s, transform .3s; }
.stars .star.on { opacity: 1; transform: scale(1.15); }

/* ---------- 起点提示 ---------- */
.start-hint {
  position: absolute;
  background: #FFCC80; color: #5D4037;
  padding: 6px 12px; border-radius: 20px;
  font-size: 14px; font-weight: bold;
  animation: bounce 1.2s infinite ease-in-out;
  pointer-events: none;
  transform: translate(-50%, -50%);
  white-space: nowrap; opacity: 0;
  transition: opacity .3s;
}
.start-hint.show { opacity: 1; }
@keyframes bounce {
  0%, 100% { transform: translate(-50%, -50%) translateY(0); }
  50%      { transform: translate(-50%, -50%) translateY(-8px); }
}

/* ---------- Combo 浮动 ---------- */
.combo-float {
  position: absolute; top: 18%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: 48px; font-weight: 900;
  color: #FF9800;
  text-shadow: 0 4px 12px rgba(255,152,0,.5);
  pointer-events: none; opacity: 0;
  z-index: 50;
}
.combo-float.show { animation: comboPop .9s ease forwards; }
@keyframes comboPop {
  0%   { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
  30%  { transform: translate(-50%, -50%) scale(1.3); opacity: 1; }
  70%  { transform: translate(-50%, -50%) scale(1);   opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1.1); opacity: 0; }
}
.combo-float.combo-2 { color: #E91E63; font-size: 56px; text-shadow: 0 4px 14px rgba(233,30,99,.5); }
.combo-float.combo-3 { color: #9C27B0; font-size: 64px; text-shadow: 0 4px 16px rgba(156,39,176,.5); }
.combo-float.combo-4 {
  font-size: 72px;
  background: linear-gradient(45deg, #FF7043, #E91E63, #9C27B0, #2196F3);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 4px 16px rgba(233,30,99,.6));
}

/* ---------- 完美徽章 ---------- */
.perfect-badge {
  position: absolute; top: 22%; left: 50%;
  transform: translate(-50%, -50%) scale(0);
  font-size: 120px; pointer-events: none;
  opacity: 0; z-index: 60;
  filter: drop-shadow(0 6px 20px rgba(255,193,7,.6));
}
.perfect-badge.show { animation: perfectPop 2.4s ease forwards; }
@keyframes perfectPop {
  0%   { transform: translate(-50%, -50%) scale(0) rotate(-30deg); opacity: 0; }
  20%  { transform: translate(-50%, -50%) scale(1.3) rotate(10deg); opacity: 1; }
  40%  { transform: translate(-50%, -50%) scale(1) rotate(-5deg); opacity: 1; }
  80%  { transform: translate(-50%, -50%) scale(1) rotate(0); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1.2) rotate(0); opacity: 0; }
}

/* ---------- 底栏 ---------- */
.toolbar {
  display: flex; justify-content: center; gap: 10px;
  padding: 10px 12px 16px; background: #FFE0B2;
  box-shadow: 0 -2px 6px rgba(0,0,0,.08);
  flex-wrap: wrap;
}
.tool-btn {
  min-width: 56px; height: 52px; border-radius: 26px;
  border: none; background: #fff;
  font-size: 18px; font-weight: bold; color: #5D4037;
  box-shadow: 0 2px 6px rgba(0,0,0,.12); cursor: pointer;
  padding: 0 16px;
  display: flex; align-items: center; justify-content: center;
  gap: 4px;
}
.tool-btn.primary { background: #FF7043; color: #fff; }
.tool-btn.clear-btn { background: #FFCDD2; color: #C62828; }
.tool-btn.finish-btn {
  background: #4CAF50; color: #fff;
  animation: pulse 1.5s infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}
.tool-btn:active { transform: scale(.96); }

/* ---------- 家长面板 ---------- */
.parent-panel {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.45); z-index: 100;
  align-items: center; justify-content: center;
  padding: 16px;
}
.parent-panel.show { display: flex; }
.parent-card {
  background: #fff; border-radius: 18px; padding: 20px;
  width: 100%; max-width: 420px; max-height: 90vh; overflow-y: auto;
}
.parent-card h2 {
  margin: 0 0 16px; font-size: 20px; color: #E64A19;
}
.parent-card .row {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 14px; font-size: 14px;
}
.parent-card .row > span:first-child {
  min-width: 90px; color: #5D4037;
}
.parent-card .row input[type=range] { flex: 1; }
.parent-card .row input[type=text],
.parent-card textarea {
  flex: 1; font-size: 14px; padding: 8px;
  border-radius: 8px; border: 1px solid #ccc; resize: vertical;
  width: 100%;
}
.parent-card .buttons { justify-content: flex-end; }
.parent-card .buttons button {
  padding: 10px 20px; border-radius: 10px;
  border: none; font-size: 15px; font-weight: bold; cursor: pointer;
}
#btnApply { background: #FF7043; color: #fff; }
#btnCloseParent, #btnCloseSticker, #btnCloseGallery { background: #eee; color: #333; }
#btnClearGallery { background: #FFCDD2; color: #C62828; }
.download-btn { background: #4CAF50; color: #fff; }

/* ---------- 难度选择 ---------- */
#difficultyLevel {
  flex: 1; padding: 8px 12px; border-radius: 8px;
  border: 1px solid #ccc; font-size: 15px; background: #fff;
}

/* ---------- 已保存字表列表 ---------- */
.saved-sets-list {
  width: 100%;
  max-height: 120px;
  overflow-y: auto;
  border: 1px solid #eee;
  border-radius: 8px;
  padding: 6px;
  background: #fafafa;
}
.saved-set-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 8px; margin-bottom: 4px;
  background: #fff; border-radius: 6px;
  border: 1px solid #eee;
  font-size: 13px;
}
.saved-set-item:last-child { margin-bottom: 0; }
.saved-set-item .set-name {
  font-weight: bold; color: #5D4037;
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.saved-set-item .set-chars {
  color: #999; font-size: 11px; margin-left: 8px;
  max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.saved-set-item button {
  padding: 4px 10px; border-radius: 6px; border: none;
  background: #FFE0B2; color: #5D4037; font-size: 12px;
  font-weight: bold; cursor: pointer; margin-left: 6px;
}
.saved-set-item button.del {
  background: #FFCDD2; color: #C62828;
}

/* ---------- 贴纸册 ---------- */
.sticker-card h2 { text-align: center; }
.sticker-grid {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 10px; margin: 16px 0;
  max-height: 50vh; overflow-y: auto; padding: 8px;
}
.sticker-cell {
  aspect-ratio: 1;
  display: flex; align-items: center; justify-content: center;
  background: #f5f5f5; border-radius: 12px;
  font-size: 28px; font-weight: 900; color: #ccc;
  border: 2px dashed #ddd;
  transition: all .3s;
}
.sticker-cell.earned {
  background: linear-gradient(135deg, #FFE0B2, #FFCC80);
  color: #E64A19;
  border: 2px solid #FF7043;
  box-shadow: 0 2px 8px rgba(255,112,67,.3);
}
.sticker-stats {
  text-align: center; font-size: 18px;
  color: #5D4037; margin: 12px 0; font-weight: bold;
}
.sticker-stats span:first-child {
  color: #E64A19; font-size: 28px;
}

/* ---------- 作品集 ---------- */
.gallery-card h2 { text-align: center; }
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
  margin: 16px 0;
  max-height: 60vh;
  overflow-y: auto;
  padding: 8px;
}
.gallery-item {
  background: #fff;
  border-radius: 12px;
  padding: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
  text-align: center;
  border: 2px solid #FFE0B2;
  transition: transform .2s;
}
.gallery-item:active { transform: scale(.96); }
.gallery-item img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  border-radius: 8px;
  background: #f9f9f9;
  display: block;
}
.gallery-item .char-name {
  font-size: 22px;
  font-weight: 900;
  color: #E64A19;
  margin: 4px 0 2px;
  line-height: 1;
}
.gallery-item .stats {
  font-size: 11px;
  color: #666;
  line-height: 1.4;
}
.gallery-item .stats .pct {
  color: #FF7043; font-weight: bold;
}
.gallery-item .stats .stars-mini {
  color: #FFB300;
}
.gallery-empty {
  text-align: center;
  padding: 40px 20px;
  color: #999;
  font-size: 15px;
}

/* ---------- 庆祝层 ---------- */
.celebrate {
  display: none; position: fixed; inset: 0;
  background: rgba(255, 248, 231, .96); z-index: 200;
  align-items: center; justify-content: center;
}
.celebrate.show { display: flex; }
.celebrate-inner { text-align: center; }
.celebrate-emoji { font-size: 100px; animation: pop .6s ease; }
.celebrate-text {
  font-size: 40px; font-weight: 900; color: #E64A19;
  margin: 10px 0 30px;
}
.celebrate-next {
  font-size: 22px; padding: 16px 40px; border-radius: 40px;
  border: none; background: #FF7043; color: #fff; font-weight: bold;
  box-shadow: 0 4px 12px rgba(255,112,67,.5); cursor: pointer;
}
@keyframes pop {
  0%   { transform: scale(0); }
  70%  { transform: scale(1.2); }
  100% { transform: scale(1); }
}

/* ---------- 移动端适配 ---------- */
@media (max-width: 480px) {
  .btn-text { display: none; }
  .tool-btn {
    min-width: 44px; height: 44px; padding: 0 12px; font-size: 20px;
  }
  .toolbar { gap: 6px; padding: 8px 8px 12px; }
  .task-char { font-size: 36px; }
  .icon-btn { width: 44px; height: 44px; font-size: 22px; }
  .topbar { padding: 8px 10px; }
  .combo-float { font-size: 36px; }
  .combo-float.combo-3 { font-size: 44px; }
  .combo-float.combo-4 { font-size: 52px; }
  .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); }
}

@media (max-height: 620px) {
  .task-char { font-size: 32px; }
  .canvas { width: min(90vw, 70vh); height: min(90vw, 70vh); }
}
/* ---------- 级别完成模态框 ---------- */
.level-complete-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 300;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s;
}
.level-complete-modal.show {
  display: flex;
  opacity: 1;
}
.level-complete-content {
  background: linear-gradient(135deg, #FFE0B2, #FFCC80);
  border-radius: 24px;
  padding: 40px;
  text-align: center;
  max-width: 400px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
  animation: modalPop 0.5s ease;
}
.level-complete-emoji {
  font-size: 100px;
  margin-bottom: 20px;
  animation: bounce 1s infinite;
}
.level-complete-content h2 {
  font-size: 32px;
  color: #E64A19;
  margin: 0 0 10px;
}
.level-complete-content p {
  font-size: 20px;
  color: #5D4037;
  margin: 10px 0;
}
.level-complete-btn {
  margin-top: 20px;
  padding: 16px 40px;
  font-size: 20px;
  font-weight: bold;
  background: #FF7043;
  color: #fff;
  border: none;
  border-radius: 40px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(255,112,67,0.5);
  transition: transform 0.2s;
}
.level-complete-btn:active {
  transform: scale(0.95);
}
@keyframes modalPop {
  0% { transform: scale(0.5); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
