/* Design System & Base Variables */
:root {
  --primary-color: #ff6b6b;
  --primary-hover: #ff5252;
  --secondary-color: #4ecdc4;
  --secondary-hover: #45b7aa;
  --accent-color: #feca57;
  --accent-hover: #ffb833;
  --bg-color: #f0f8ff;
  --text-primary: #2d3436;
  --text-secondary: #636e72;
  --white: #ffffff;
  --shadow-sm: 0 4px 6px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 8px 15px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 15px 25px rgba(0, 0, 0, 0.15);
  --radius: 20px;
  --radius-sm: 12px;
  --transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Nunito', sans-serif;
  background-color: var(--bg-color);
  background-image: radial-gradient(circle at 10% 20%, rgba(216, 241, 230, 0.46) 0%, rgba(233, 226, 226, 0.28) 90%);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow-x: hidden;
}

/* Main App Container simulating a mobile/tablet view for gamification focus */
#app-container {
  width: 100%;
  max-width: 500px;
  height: 100vh;
  max-height: 900px;
  background-color: var(--white);
  position: relative;
  overflow-y: auto;
  overflow-x: hidden;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
}

@media (min-width: 500px) {
  #app-container {
    height: 90vh;
    border-radius: 30px;
    border: 8px solid #dfe6e9;
  }
}

/* HUD / Header */
#hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  background: var(--white);
  border-bottom: 2px solid #f1f2f6;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.score-container {
  font-weight: 900;
  font-size: 1.2rem;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(254, 202, 87, 0.2);
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-sm);
}

#progress-bar-container {
  flex-grow: 1;
  height: 10px;
  background-color: #f1f2f6;
  border-radius: 5px;
  margin: 0 1rem;
  overflow: hidden;
}

#progress-bar {
  height: 100%;
  width: 0%;
  background-color: var(--secondary-color);
  transition: width 0.4s ease-out;
}

/* Screens */
.screen {
  flex: 1;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  animation: fadeIn 0.4s ease-out forwards;
}

.screen.hidden {
  display: none !important;
}

.section-title {
  text-align: center;
  color: var(--text-secondary);
  font-size: 1.2rem;
  margin-bottom: 1rem;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* Hero elements */
.hero {
  text-align: center;
  padding: 2rem 0;
}

.hero h1 {
  font-size: 2.2rem;
  color: var(--primary-color);
  margin-bottom: 0.5rem;
}

.hero p {
  color: var(--text-secondary);
  font-size: 1.1rem;
}

/* Buttons */
.btn {
  font-family: inherit;
  font-weight: 700;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.8rem 1.5rem;
  cursor: pointer;
  transition: var(--transition);
  font-size: 1.1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.1);
  /* 3D effect */
  transform: translateY(0);
}

.btn:active {
  transform: translateY(4px);
  box-shadow: 0 0 0 rgba(0, 0, 0, 0);
}

.btn-primary {
  background-color: var(--primary-color);
  color: var(--white);
}

.btn-primary:hover {
  background-color: var(--primary-hover);
}

.btn-secondary {
  background-color: var(--secondary-color);
  color: var(--white);
}

.btn-secondary:hover {
  background-color: var(--secondary-hover);
}

.btn-accent {
  background-color: var(--accent-color);
  color: var(--text-primary);
}

.btn-accent:hover {
  background-color: var(--accent-hover);
}

.btn-large {
  padding: 1.2rem 2rem;
  font-size: 1.3rem;
  width: 100%;
}

.btn-bottom {
  margin-top: auto;
  width: 100%;
  padding: 1.2rem;
}

.btn-icon {
  background: none;
  border: none;
  font-size: 1.2rem;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 50%;
  transition: var(--transition);
}

.btn-icon:hover {
  background: #f1f2f6;
  color: var(--primary-color);
}

/* Books and Lessons Grid */
.grid-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.grid-item {
  background: var(--white);
  border: 2px solid #f1f2f6;
  border-radius: var(--radius);
  padding: 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
}

.grid-item:hover {
  transform: translateY(-5px);
  box-shadow: var(--shadow-md);
  border-color: var(--secondary-color);
}

.grid-item h3 {
  font-size: 1.5rem;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.grid-item p {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

/* Flashcard */
.card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow-md);
  text-align: center;
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  border: 4px solid var(--accent-color);
  background-image: linear-gradient(to bottom, #fffdf8, #ffffff);
}

.word-display {
  font-size: 6rem;
  font-weight: 400;
  color: var(--text-primary);
  line-height: 1;
  font-family: 'KaiTi', 'SimKai', sans-serif;
  /* Traditional looking Chinese font */
}

.pinyin-display {
  font-size: 1.5rem;
  color: var(--primary-color);
  font-weight: 700;
  letter-spacing: 2px;
}

.meaning-display {
  font-size: 1.2rem;
  color: var(--text-secondary);
}

.mb-2 {
  margin-bottom: 1rem;
}

/* Stroke Practice */
.canvas-wrapper {
  background: #fffdfa;
  border: 2px dashed #b2bec3;
  border-radius: var(--radius);
  width: 250px;
  height: 250px;
  margin: 0 auto 1.5rem;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.02);
}

#character-target {
  width: 230px;
  height: 230px;
}

.stroke-controls {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 2rem;
}

.stroke-controls .btn-icon {
  background: #f1f2f6;
  font-size: 1rem;
  padding: 0.8rem 1rem;
  border-radius: var(--radius-sm);
  font-weight: 700;
}

/* Sentence Builder */
.sentence-box {
  background: #f1fbf9;
  border: 2px solid var(--secondary-color);
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  text-align: center;
  margin-bottom: 2rem;
}

.chinese-sentence {
  font-size: 1.8rem;
  color: var(--text-primary);
  margin-bottom: 1rem;
  line-height: 1.5;
}

.chinese-sentence .blank {
  display: inline-block;
  min-width: 60px;
  border-bottom: 3px solid var(--primary-color);
  text-align: center;
  color: var(--primary-color);
  font-weight: bold;
}

.english-meaning {
  font-size: 1.1rem;
  color: var(--text-secondary);
  font-style: italic;
}

.options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 2rem;
}

.option-btn {
  font-size: 1.8rem;
  padding: 1rem;
  background: var(--white);
  border: 2px solid #dfe6e9;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
  font-family: 'KaiTi', 'SimKai', sans-serif;
}

.option-btn:hover {
  border-color: var(--secondary-color);
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}

.option-btn.correct {
  background: var(--secondary-color);
  color: var(--white);
  border-color: var(--secondary-color);
  animation: pulse 0.5s;
}

.option-btn.wrong {
  background: var(--primary-color);
  color: var(--white);
  border-color: var(--primary-color);
  animation: shake 0.5s;
}

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.05);
  }

  100% {
    transform: scale(1);
  }
}

@keyframes shake {

  0%,
  100% {
    transform: translateX(0);
  }

  25% {
    transform: translateX(-5px);
  }

  50% {
    transform: translateX(5px);
  }

  75% {
    transform: translateX(-5px);
  }
}

.btn-pulse {
  animation: pulse 2s infinite;
}

.bounce-in {
  animation: fadeIn 0.8s cubic-bezier(0.68, -0.55, 0.26, 1.55);
}

.big-star {
  margin: 2rem 0;
  animation: pulse 2s infinite;
}

/* Avatars & Profile */
.avatar-selection {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin: 2rem 0;
  flex-wrap: wrap;
}

.avatar-btn {
  background: var(--white);
  border: 3px solid #dfe6e9;
  border-radius: var(--radius);
  padding: 1rem;
  font-size: 1.2rem;
  cursor: pointer;
  transition: var(--transition);
  color: var(--text-secondary);
  font-weight: bold;
  font-family: inherit;
  width: 90px;
}

.avatar-btn i {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}

.avatar-btn:hover {
  transform: translateY(-5px);
  box-shadow: var(--shadow-sm);
}

.avatar-btn.selected {
  border-color: var(--secondary-color);
  color: var(--secondary-color);
  background: #f1fbf9;
  animation: pulse 1s;
}

/* Save Slots */
.save-slots {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-top: 1rem;
}

.save-slot {
  background: var(--white);
  border: 2px solid #dfe6e9;
  border-radius: var(--radius-sm);
  padding: 1rem;
  width: 120px;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
}

.save-slot:hover {
  border-color: var(--secondary-color);
  transform: translateY(-3px);
  box-shadow: var(--shadow-sm);
}

.save-slot.active {
  border-color: var(--secondary-color);
  background: #f1fbf9;
  border-width: 3px;
}

.save-slot h4 {
  font-size: 1rem;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.save-slot .slot-info {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.2;
}

.btn-delete-slot {
  position: absolute;
  top: -10px;
  right: -10px;
  background: #ff7675;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  padding: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 0.8rem;
  box-shadow: var(--shadow-sm);
}

.btn-delete-slot:hover {
  background: #d63031;
}

.bottom-actions {
  display: flex;
  justify-content: space-between;
  margin-top: auto;
  gap: 0.5rem;
}

/* Modals */
.modal {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  border-radius: inherit;
}

.modal.hidden {
  display: none !important;
}

.modal-content {
  background: var(--white);
  width: 90%;
  max-width: 400px;
  max-height: 80%;
  overflow-y: auto;
  border-radius: var(--radius);
  padding: 2rem;
  position: relative;
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: fadeIn 0.3s ease-out;
}

.trophy-item {
  background: #fdfbf7;
  border: 2px solid #f1f2f6;
  border-radius: var(--radius-sm);
  padding: 1rem;
  opacity: 0.5;
  filter: grayscale(1);
  transition: var(--transition);
}

.trophy-item.unlocked {
  opacity: 1;
  filter: grayscale(0);
  border-color: #feca57;
  background: #fffdf3;
  box-shadow: inset 0 0 10px rgba(254, 202, 87, 0.2);
}

.trophy-item i {
  font-size: 2rem;
  color: #feca57;
  margin-bottom: 0.5rem;
}

.trophy-item h4 {
  font-size: 0.9rem;
  color: var(--text-primary);
}