* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --red: #c0392b;
  --gold: #f39c12;
  --green: #27ae60;
  --dark: #1a1a2e;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
  --radius: 20px;
}

body {
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  color: white;
  padding: 20px;
}

/* Header */
header {
  text-align: center;
  margin-bottom: 24px;
  width: 100%;
  max-width: 700px;
}

header h1 {
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: 2px;
  background: linear-gradient(135deg, #f39c12, #e74c3c);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 4px;
}

header p {
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.5);
  letter-spacing: 1px;
}

/* Category Filter */
.category-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-bottom: 24px;
  max-width: 700px;
  width: 100%;
}

.cat-btn {
  padding: 6px 16px;
  border: 1.5px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.07);
  color: rgba(255, 255, 255, 0.75);
  border-radius: 50px;
  cursor: pointer;
  font-size: 0.82rem;
  font-family: inherit;
  transition: all 0.2s;
  letter-spacing: 0.5px;
}

.cat-btn:hover {
  background: rgba(243, 156, 18, 0.2);
  border-color: var(--gold);
  color: var(--gold);
}

.cat-btn.active {
  background: linear-gradient(135deg, #f39c12, #e74c3c);
  border-color: transparent;
  color: white;
  font-weight: 600;
}

/* Progress */
.progress-area {
  width: 100%;
  max-width: 700px;
  margin-bottom: 20px;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.5);
  margin-bottom: 8px;
}

.progress-bar-track {
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #27ae60, #2ecc71);
  border-radius: 4px;
  transition: width 0.5s ease;
}

/* Flashcard Scene */
.scene {
  width: 100%;
  max-width: 500px;
  height: 320px;
  perspective: 1200px;
  cursor: pointer;
  margin-bottom: 20px;
}

.card {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.card.flipped {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 28px;
}

/* Front face */
.card-front {
  background: white;
  box-shadow: var(--shadow);
  border-top: 6px solid var(--red);
}

.card-category-badge {
  position: absolute;
  top: 16px;
  right: 18px;
  font-size: 0.72rem;
  background: rgba(192, 57, 43, 0.1);
  color: var(--red);
  border: 1px solid rgba(192, 57, 43, 0.3);
  border-radius: 20px;
  padding: 3px 10px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.character {
  font-size: 6rem;
  color: #1a1a2e;
  line-height: 1;
  font-weight: 700;
  margin-bottom: 12px;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.05);
}

.pinyin {
  font-size: 1.3rem;
  color: var(--red);
  letter-spacing: 3px;
  font-weight: 500;
  margin-bottom: 8px;
}

.flip-hint {
  position: absolute;
  bottom: 14px;
  font-size: 0.72rem;
  color: rgba(0, 0, 0, 0.3);
  letter-spacing: 0.5px;
}

/* Back face */
.card-back {
  background: linear-gradient(145deg, #1a1a2e, #16213e);
  border: 1px solid rgba(243, 156, 18, 0.3);
  box-shadow: var(--shadow), inset 0 0 60px rgba(243, 156, 18, 0.05);
  transform: rotateY(180deg);
  text-align: center;
}

.meaning-label {
  font-size: 0.72rem;
  letter-spacing: 2px;
  color: var(--gold);
  text-transform: uppercase;
  margin-bottom: 8px;
  opacity: 0.8;
}

.meaning {
  font-size: 1.5rem;
  font-weight: 600;
  color: white;
  margin-bottom: 16px;
}

.divider {
  width: 40px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  margin: 0 auto 16px;
}

.example-block {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 12px 16px;
  width: 100%;
  text-align: left;
}

.example-label {
  font-size: 0.65rem;
  color: var(--gold);
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 6px;
  opacity: 0.8;
}

.example-zh {
  font-size: 0.95rem;
  color: white;
  line-height: 1.6;
  margin-bottom: 3px;
}

.example-py {
  font-size: 0.75rem;
  color: rgba(243, 156, 18, 0.8);
  margin-bottom: 4px;
  font-style: italic;
}

.example-en {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.5);
}

/* ── Rating buttons (shown after flip) ── */
.rating-row {
  display: none;
  gap: 14px;
  margin-bottom: 14px;
  width: 100%;
  max-width: 500px;
}

.rating-row.visible {
  display: flex;
}

.btn-wrong {
  flex: 1;
  justify-content: center;
  background: rgba(231, 76, 60, 0.15);
  color: #e74c3c;
  border: 2px solid rgba(231, 76, 60, 0.5);
  border-radius: 14px;
  padding: 14px 10px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
  letter-spacing: 0.5px;
}

.btn-wrong:hover {
  background: rgba(231, 76, 60, 0.3);
  border-color: #e74c3c;
  transform: translateY(-2px);
}

.btn-correct {
  flex: 1;
  justify-content: center;
  background: rgba(39, 174, 96, 0.15);
  color: #2ecc71;
  border: 2px solid rgba(39, 174, 96, 0.5);
  border-radius: 14px;
  padding: 14px 10px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
  letter-spacing: 0.5px;
}

.btn-correct:hover {
  background: rgba(39, 174, 96, 0.3);
  border-color: #2ecc71;
  transform: translateY(-2px);
}

/* ── Pre-flip button ── */
.preflip-row {
  display: none;
  margin-bottom: 14px;
  width: 100%;
  max-width: 500px;
}

.preflip-row.visible {
  display: flex;
}

.btn-flip {
  flex: 1;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.7);
  border: 1.5px dashed rgba(255, 255, 255, 0.25);
  border-radius: 14px;
  padding: 14px 10px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
  letter-spacing: 0.5px;
  text-align: center;
}

.btn-flip:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.4);
  color: white;
}

/* ── Bottom toolbar ── */
.toolbar {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

.btn-restart {
  background: transparent;
  color: rgba(255, 255, 255, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 50px;
  padding: 7px 18px;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
  letter-spacing: 0.5px;
}

.btn-restart:hover {
  color: white;
  border-color: rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.07);
}

/* ── Stats row ── */
.stats-row {
  display: flex;
  gap: 12px;
  margin-bottom: 0;
}

.stat-card {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  padding: 12px 20px;
  text-align: center;
  min-width: 90px;
}

.stat-num {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--gold);
}

.stat-mastered { color: #2ecc71; }
.stat-queue    { color: #e74c3c; }

.stat-label {
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.4);
  margin-top: 2px;
  letter-spacing: 0.5px;
}

/* Keyboard hint */
.keyboard-hint {
  margin-top: 16px;
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.3);
  letter-spacing: 0.5px;
  text-align: center;
}

kbd {
  display: inline-block;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 0.7rem;
  font-family: inherit;
}

/* ── Completion overlay ── */
.completion-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 30, 0.88);
  backdrop-filter: blur(8px);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.completion-overlay.visible {
  display: flex;
}

.completion-box {
  background: linear-gradient(145deg, #1a1a2e, #16213e);
  border: 1px solid rgba(243, 156, 18, 0.4);
  border-radius: 24px;
  padding: 48px 40px;
  text-align: center;
  max-width: 380px;
  width: 100%;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
  animation: popIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.8); }
  to   { opacity: 1; transform: scale(1); }
}

.completion-emoji {
  font-size: 3.5rem;
  margin-bottom: 16px;
}

.completion-title {
  font-size: 1.8rem;
  font-weight: 700;
  background: linear-gradient(135deg, #f39c12, #e74c3c);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}

.completion-sub {
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.5);
  margin-bottom: 28px;
  line-height: 1.5;
}

.completion-stats {
  display: flex;
  justify-content: center;
  gap: 32px;
  margin-bottom: 32px;
}

.cs-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.cs-num {
  font-size: 2rem;
  font-weight: 700;
  color: var(--gold);
}

.cs-label {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.4);
  letter-spacing: 1px;
}

.btn-again {
  display: inline-block;
  background: linear-gradient(135deg, #f39c12, #e74c3c);
  color: white;
  border: none;
  border-radius: 50px;
  padding: 14px 36px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
  letter-spacing: 0.5px;
}

.btn-again:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 24px rgba(243, 156, 18, 0.4);
}

/* Animations */
@keyframes cardIn {
  from { opacity: 0; transform: translateY(10px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.scene.animate-in {
  animation: cardIn 0.3s ease forwards;
}

/* Responsive */
@media (max-width: 480px) {
  header h1   { font-size: 1.4rem; }
  .character  { font-size: 4.5rem; }
  .scene      { height: 280px; }
  .stats-row  { gap: 8px; }
  .stat-card  { padding: 10px 14px; min-width: 75px; }
  .completion-box { padding: 36px 24px; }
  .btn-wrong, .btn-correct { font-size: 0.9rem; padding: 12px 8px; }
}
