@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800;900&display=swap');

:root {
  --bg: #f0e6ff;
  --card-bg: #ffffff;
  --purple: #7c4dff;
  --purple-light: #ede7ff;
  --purple-dark: #5c35cc;
  --gold: #ffb300;
  --red: #ff5252;
  --red-light: #fff0f0;
  --green: #00c853;
  --text: #333;
  --text-light: #888;
  --shadow: 0 4px 20px rgba(124,77,255,0.12);
  --radius: 18px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

body {
  font-family: 'Nunito', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: linear-gradient(160deg, #e8d5ff 0%, #d0e8ff 100%);
  min-height: 100vh;
  color: var(--text);
  padding-bottom: 80px;
}

/* ========== Header ========== */
.header {
  background: linear-gradient(135deg, #7c4dff 0%, #448aff 100%);
  padding: 20px 16px 24px;
  text-align: center;
  border-radius: 0 0 30px 30px;
  box-shadow: 0 6px 30px rgba(124,77,255,0.35);
}
.header h1 {
  font-size: 26px;
  font-weight: 900;
  color: #fff;
  letter-spacing: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.header .subtitle {
  font-size: 14px;
  color: rgba(255,255,255,0.85);
  margin-top: 6px;
  font-weight: 600;
}
.weekly-reset-note {
  font-size: 11px;
  color: rgba(255,255,255,0.65);
  margin-top: 4px;
}

/* ========== Stats ========== */
.stats-row {
  display: flex;
  gap: 10px;
  padding: 16px 14px;
}
.stat-card {
  flex: 1;
  background: var(--card-bg);
  border-radius: 16px;
  padding: 14px 10px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat-label {
  font-size: 12px;
  color: var(--text-light);
  font-weight: 700;
}
.stat-value {
  font-size: 32px;
  font-weight: 900;
  margin-top: 4px;
  line-height: 1;
}
.stat-card.earn .stat-value { color: var(--gold); }
.stat-card.lose .stat-value { color: var(--red); }
.stat-card.total .stat-value { color: var(--purple); }

/* ========== Sections ========== */
.section {
  margin: 0 14px 16px;
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.section-title {
  font-size: 17px;
  font-weight: 900;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.section-title.earn { color: var(--gold); }
.section-title.lose { color: var(--red); }

/* ========== Sticker Grid ========== */
.sticker-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.sticker-btn {
  background: #f8f5ff;
  border: none;
  border-radius: 14px;
  padding: 14px 8px 10px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
  position: relative;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}
.sticker-btn:active { transform: scale(0.93); }
.sticker-btn.earn-btn:hover, .sticker-btn.earn-btn:active {
  background: #fff3cd;
  box-shadow: 0 4px 16px rgba(255,179,0,0.25);
}
.sticker-btn.lose-btn { background: #fff5f5; }
.sticker-btn.lose-btn:hover, .sticker-btn.lose-btn:active {
  background: #ffe0e0;
  box-shadow: 0 4px 16px rgba(255,82,82,0.2);
}

.sticker-emoji { font-size: 36px; display: block; line-height: 1.1; }
.sticker-name {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  margin-top: 6px;
  line-height: 1.3;
}
.sticker-points {
  font-size: 11px;
  font-weight: 800;
  margin-top: 4px;
}
.sticker-btn.earn-btn .sticker-points { color: var(--gold); }
.sticker-btn.lose-btn .sticker-points { color: var(--red); }

/* ========== Animations ========== */
.ripple {
  position: absolute;
  border-radius: 50%;
  transform: scale(0);
  animation: ripple-anim 0.5s linear;
  background: rgba(255,255,255,0.5);
  pointer-events: none;
}
@keyframes ripple-anim {
  to { transform: scale(4); opacity: 0; }
}

@keyframes bounce-in {
  0% { transform: scale(1); }
  40% { transform: scale(1.15); }
  70% { transform: scale(0.93); }
  100% { transform: scale(1); }
}
.bounce { animation: bounce-in 0.35s ease; }

.float-flower {
  position: fixed;
  font-size: 28px;
  pointer-events: none;
  z-index: 400;
  animation: float-up 1.2s ease forwards;
}
@keyframes float-up {
  0% { opacity: 1; transform: translateY(0) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-120px) scale(1.3); }
}

/* ========== Toast ========== */
.toast {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: rgba(60,20,120,0.92);
  color: #fff;
  padding: 12px 22px;
  border-radius: 50px;
  font-size: 15px;
  font-weight: 700;
  z-index: 999;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ========== Bottom Bar ========== */
.bottom-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--card-bg);
  display: flex;
  gap: 10px;
  padding: 10px 14px max(14px, env(safe-area-inset-bottom));
  box-shadow: 0 -4px 20px rgba(0,0,0,0.08);
  z-index: 100;
}
.bottom-btn {
  flex: 1;
  padding: 12px 0;
  border: none;
  border-radius: 14px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform 0.15s, box-shadow 0.15s;
}
.bottom-btn:active { transform: scale(0.96); }
.btn-undo { background: #f0f0f0; color: #555; }
.btn-clear { background: #ff5252; color: #fff; }
.btn-history {
  background: linear-gradient(135deg, #7c4dff, #448aff);
  color: #fff;
}

/* ========== History Modal ========== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  align-items: flex-end;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--card-bg);
  border-radius: 24px 24px 0 0;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  padding: 20px 16px 30px;
  animation: slide-up 0.3s ease;
}
@keyframes slide-up {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.modal-title {
  font-size: 18px;
  font-weight: 900;
  color: var(--purple);
}
.modal-close {
  background: #f0eaff;
  border: none;
  width: 32px; height: 32px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
  color: var(--purple);
  font-weight: 800;
}

.history-empty {
  text-align: center;
  color: var(--text-light);
  padding: 30px 0;
  font-size: 15px;
}
.history-day-group { margin-bottom: 16px; }
.history-day-label {
  font-size: 13px;
  font-weight: 800;
  color: var(--text-light);
  margin-bottom: 8px;
  padding-left: 4px;
}
.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  margin-bottom: 6px;
}
.history-item.earn { background: #fffbf0; }
.history-item.lose { background: #fff5f5; }
.history-item-emoji { font-size: 24px; }
.history-item-info { flex: 1; }
.history-item-name { font-size: 14px; font-weight: 700; }
.history-item-time { font-size: 11px; color: var(--text-light); margin-top: 2px; }
.history-item-pts {
  font-size: 16px;
  font-weight: 900;
}
.history-item.earn .history-item-pts { color: var(--gold); }
.history-item.lose .history-item-pts { color: var(--red); }

/* ========== Confirm Dialog ========== */
.confirm-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 300;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.confirm-overlay.open { display: flex; }
.confirm-box {
  background: #fff;
  border-radius: 20px;
  padding: 24px 20px;
  width: 100%;
  max-width: 300px;
  text-align: center;
  animation: pop-in 0.2s ease;
}
@keyframes pop-in {
  from { transform: scale(0.8); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.confirm-emoji { font-size: 40px; margin-bottom: 8px; }
.confirm-title { font-size: 17px; font-weight: 900; margin-bottom: 8px; }
.confirm-msg { font-size: 14px; color: var(--text-light); margin-bottom: 20px; }
.confirm-btns { display: flex; gap: 10px; }
.confirm-no {
  flex: 1; padding: 12px;
  background: #f0f0f0; border: none;
  border-radius: 12px; font-family: inherit;
  font-size: 14px; font-weight: 700; cursor: pointer;
}
.confirm-yes {
  flex: 1; padding: 12px;
  background: var(--red); color: #fff; border: none;
  border-radius: 12px; font-family: inherit;
  font-size: 14px; font-weight: 700; cursor: pointer;
}

/* ========== Audio Debug Panel ========== */
.audio-debug {
  position: fixed;
  bottom: 80px;
  left: 14px;
  right: 14px;
  background: rgba(30,10,60,0.95);
  border-radius: 16px;
  padding: 14px;
  z-index: 500;
  color: #fff;
  font-size: 12px;
  max-height: 200px;
  overflow-y: auto;
}
.audio-debug-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-weight: 700;
  font-size: 14px;
}
.audio-debug-close {
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 12px;
}
.audio-debug-body { line-height: 1.8; }
.audio-debug-test {
  margin-top: 8px;
  padding: 8px 16px;
  background: var(--purple);
  color: #fff;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 700;
  font-size: 13px;
  width: 100%;
}
.audio-debug-test:active { opacity: 0.8; }

/* ========== 语音文字弹幕 ========== */
.speech-caption {
  position: fixed;
  top: 44%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.5);
  background: rgba(30, 10, 70, 0.88);
  color: #fff;
  padding: 18px 28px;
  border-radius: 20px;
  font-size: 17px;
  font-weight: 800;
  z-index: 500;
  pointer-events: none;
  opacity: 0;
  text-align: center;
  max-width: 85vw;
  line-height: 1.6;
  letter-spacing: 1px;
  transition: opacity 0.25s, transform 0.25s;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}
.speech-caption.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}
.speech-caption.earn { background: rgba(124, 77, 255, 0.9); }
.speech-caption.lose { background: rgba(255, 82, 82, 0.88); }
