/* ===== RESET & BASE ===== */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --primary: #6C63FF;
  --primary-light: #8B85FF;
  --primary-glow: rgba(108,99,255,0.3);
  --secondary: #FF6B9D;
  --accent: #FFD93D;
  --bg: #F0F0FF;
  --card: #FFFFFF;
  --text: #2D2D3F;
  --text-light: #8888AA;
  --success: #4CAF50;
  --success-glow: rgba(76,175,80,0.3);
  --shadow: 0 8px 32px rgba(108,99,255,0.15);
  --shadow-sm: 0 4px 16px rgba(108,99,255,0.1);
  --radius: 24px;
  --radius-sm: 16px;
  --radius-xs: 12px;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

html, body {
  height: 100%; width: 100%;
  font-family: 'Nunito', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  display: flex; flex-direction: column;
  height: 100dvh; width: 100%;
  position: relative;
}

/* ===== ANIMATED GRADIENT BACKGROUND ===== */
body::before {
  content: '';
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(135deg, #F0F0FF 0%, #FFE8F0 25%, #E8F0FF 50%, #F0FFE8 75%, #FFF0E8 100%);
  background-size: 400% 400%;
  animation: gradientShift 15s ease infinite;
  z-index: -1;
}

@keyframes gradientShift {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* ===== HEADER ===== */
#app-header {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px;
  background: linear-gradient(135deg, var(--primary) 0%, #8B5CF6 100%);
  color: white;
  min-height: 60px;
  z-index: 10;
  box-shadow: 0 4px 20px rgba(108,99,255,0.3);
}

#header-title {
  font-size: 22px;
  font-weight: 800;
  flex: 1;
  letter-spacing: -0.5px;
}

.star-counter {
  display: flex; align-items: center; gap: 4px;
  background: rgba(255,255,255,0.2);
  padding: 6px 14px;
  border-radius: 20px;
  font-weight: 800;
  font-size: 16px;
  backdrop-filter: blur(10px);
}

.star-icon {
  font-size: 18px;
  animation: starPulse 2s ease-in-out infinite;
}

@keyframes starPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.2); }
}

.icon-btn {
  background: rgba(255,255,255,0.2);
  border: none; color: white;
  width: 48px; height: 48px;
  border-radius: 50%;
  font-size: 24px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(10px);
  transition: var(--transition);
}
.icon-btn:active {
  background: rgba(255,255,255,0.4);
  transform: scale(0.9);
}
.hidden { display: none !important; }
.spacer { flex: 1; }

/* ===== SCREENS ===== */
.screen {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 16px;
  display: none;
  animation: screenIn 0.4s ease-out;
}
.screen.active { display: block; }

@keyframes screenIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== HOME ===== */
.hero {
  text-align: center;
  padding: 20px 0 12px;
}
.hero-emoji {
  font-size: 72px;
  margin-bottom: 8px;
}
.hero h2 {
  font-size: 32px;
  font-weight: 900;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.hero p {
  font-size: 18px;
  color: var(--text-light);
  margin-top: 4px;
  font-weight: 600;
}

.animate-bounce {
  animation: heroBounce 2s ease-in-out infinite;
}

@keyframes heroBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

/* ===== CATEGORY CARDS ===== */
.categories-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  padding-bottom: 24px;
}

.cat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px 12px 14px;
  text-align: center;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: var(--transition);
  border: 3px solid transparent;
  position: relative;
  overflow: hidden;
  animation: cardPop 0.5s ease-out backwards;
}

.cat-card:nth-child(1) { animation-delay: 0.05s; }
.cat-card:nth-child(2) { animation-delay: 0.1s; }
.cat-card:nth-child(3) { animation-delay: 0.15s; }
.cat-card:nth-child(4) { animation-delay: 0.2s; }
.cat-card:nth-child(5) { animation-delay: 0.25s; }
.cat-card:nth-child(6) { animation-delay: 0.3s; }

.cat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--primary), var(--secondary));
  opacity: 0;
  transition: var(--transition);
}

.cat-card:active {
  transform: scale(0.95);
  border-color: var(--primary);
}
.cat-card:active::before { opacity: 1; }

.cat-card-img {
  width: 80px;
  height: 80px;
  margin: 0 auto 8px;
  object-fit: contain;
  border-radius: 16px;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,0.1));
}

.cat-emoji {
  font-size: 52px;
  display: block;
  margin-bottom: 8px;
  line-height: 1.1;
}
.cat-name {
  font-size: 15px;
  font-weight: 800;
  color: var(--text);
}
.cat-count {
  font-size: 12px;
  color: var(--text-light);
  margin-top: 2px;
  font-weight: 600;
}

/* Difficulty dots */
.difficulty-dots {
  display: flex;
  gap: 4px;
  justify-content: center;
  margin-top: 6px;
}
.diff-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #E0E0E0;
}
.diff-dot.filled { background: var(--accent); }

@keyframes cardPop {
  0% { transform: scale(0.7) translateY(20px); opacity: 0; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

/* ===== WORKSHEET LIST ===== */
.worksheet-list {
  display: flex; flex-direction: column;
  gap: 14px; padding-bottom: 24px;
}

.ws-card {
  background: var(--card);
  border-radius: var(--radius-sm);
  padding: 16px;
  display: flex; align-items: center; gap: 16px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  animation: listSlide 0.4s ease-out backwards;
}

.ws-card:nth-child(1) { animation-delay: 0.05s; }
.ws-card:nth-child(2) { animation-delay: 0.1s; }
.ws-card:nth-child(3) { animation-delay: 0.15s; }
.ws-card:nth-child(4) { animation-delay: 0.2s; }
.ws-card:nth-child(5) { animation-delay: 0.25s; }
.ws-card:nth-child(6) { animation-delay: 0.3s; }

@keyframes listSlide {
  from { transform: translateX(-20px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.ws-card:active { transform: scale(0.97); }

.ws-preview {
  width: 72px; height: 72px;
  border-radius: var(--radius-xs);
  display: flex; align-items: center; justify-content: center;
  font-size: 40px;
  flex-shrink: 0;
}

.ws-info { flex: 1; }
.ws-name { font-size: 17px; font-weight: 800; }
.ws-desc { font-size: 13px; color: var(--text-light); margin-top: 2px; font-weight: 600; }

.ws-arrow { font-size: 24px; color: var(--text-light); }

/* Completed badge */
.ws-completed {
  position: absolute;
  top: 8px; right: 12px;
  font-size: 24px;
  animation: badgePop 0.3s ease-out;
}

@keyframes badgePop {
  0% { transform: scale(0); }
  100% { transform: scale(1); }
}

/* ===== CANVAS SCREEN ===== */
#screen-worksheet {
  display: none; flex-direction: column;
  padding: 0; overflow: hidden;
  animation: none;
}
#screen-worksheet.active { display: flex; }

/* Instruction bar - at TOP */
.instruction-bar {
  padding: 12px 20px;
  background: linear-gradient(135deg, var(--primary), #8B5CF6);
  color: white;
  text-align: center;
  font-size: 17px;
  font-weight: 700;
  min-height: 48px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 12px rgba(108,99,255,0.2);
}

/* Progress bar */
.worksheet-progress {
  height: 6px;
  background: #E8E8F0;
  flex-shrink: 0;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--secondary));
  width: 0%;
  transition: width 0.5s ease;
  border-radius: 0 3px 3px 0;
}

/* Canvas toolbar */
.canvas-toolbar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px;
  background: white;
  border-bottom: 2px solid #F0F0FF;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.toolbar-spacer { flex: 1; }

.tool-btn {
  width: 52px; height: 52px;
  border: none; border-radius: var(--radius-xs);
  background: #F0F0FF;
  font-size: 26px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: var(--transition);
}
.tool-btn:active {
  background: #DDD8FF;
  transform: scale(0.9);
}
.tool-btn.active {
  background: var(--primary);
  box-shadow: 0 4px 12px var(--primary-glow);
}

/* Color palette */
.color-palette {
  display: flex; gap: 8px; flex-wrap: wrap;
  align-items: center;
  animation: paletteIn 0.3s ease-out;
}

@keyframes paletteIn {
  from { opacity: 0; transform: scaleY(0.8); }
  to { opacity: 1; transform: scaleY(1); }
}

.color-dot {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 4px solid transparent;
  cursor: pointer;
  transition: var(--transition);
}
.color-dot:active { transform: scale(0.85); }
.color-dot.active {
  border-color: var(--text);
  transform: scale(1.2);
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

/* Brush sizes */
.brush-sizes {
  display: flex; gap: 6px; align-items: center;
  animation: paletteIn 0.3s ease-out;
}
.brush-opt {
  width: 44px; height: 44px;
  border: none; border-radius: var(--radius-xs);
  background: #F0F0FF;
  font-size: 14px; font-weight: 800;
  cursor: pointer;
  transition: var(--transition);
  font-family: inherit;
}
.brush-opt:active { transform: scale(0.9); }
.brush-opt.active {
  background: var(--primary);
  color: white;
  box-shadow: 0 4px 12px var(--primary-glow);
}

/* Canvas container */
#canvas-container {
  flex: 1; position: relative;
  overflow: hidden;
  background: white;
}

#worksheet-canvas {
  display: block;
  width: 100%; height: 100%;
  touch-action: none;
}

#trace-overlay {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
}

/* ===== DONE BUTTON ===== */
.done-bar {
  padding: 12px 20px;
  background: white;
  border-top: 2px solid #F0F0FF;
  flex-shrink: 0;
  display: flex;
  justify-content: center;
}

.btn-done {
  width: 100%;
  max-width: 320px;
  padding: 16px 32px;
  border: none;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--success), #66BB6A);
  color: white;
  font-size: 22px;
  font-weight: 800;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 6px 20px var(--success-glow);
  font-family: inherit;
}

.btn-done:active {
  transform: scale(0.95);
  box-shadow: 0 2px 10px var(--success-glow);
}

/* ===== CELEBRATION OVERLAY ===== */
.celebration-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  backdrop-filter: blur(8px);
  animation: overlayIn 0.3s ease-out;
}

@keyframes overlayIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.celebration-content {
  text-align: center;
  animation: contentBounce 0.5s ease-out;
}

@keyframes contentBounce {
  0% { transform: scale(0.5); opacity: 0; }
  70% { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}

.celebration-stars {
  font-size: 60px;
  line-height: 1.2;
  margin-bottom: 16px;
}

.celebration-text {
  font-size: 48px;
  font-weight: 900;
  color: white;
  text-shadow: 0 4px 20px rgba(0,0,0,0.3);
  margin-bottom: 32px;
}

.celebration-buttons {
  display: flex; flex-direction: column;
  gap: 16px; align-items: center;
}

.btn-next {
  padding: 18px 48px;
  border: none;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--accent), #FFB800);
  color: var(--text);
  font-size: 24px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(255,217,61,0.4);
  font-family: inherit;
  min-width: 240px;
}

.btn-next:active {
  transform: scale(0.95);
}

.btn-back-home {
  padding: 14px 36px;
  border: none;
  border-radius: var(--radius);
  background: rgba(255,255,255,0.2);
  color: white;
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  backdrop-filter: blur(10px);
  font-family: inherit;
}

.btn-back-home:active { transform: scale(0.95); }

/* Pulse animation for Next button */
.pulse {
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 6px 24px rgba(255,217,61,0.4); }
  50% { box-shadow: 0 6px 36px rgba(255,217,61,0.7); transform: scale(1.05); }
  100% { box-shadow: 0 6px 24px rgba(255,217,61,0.4); }
}

/* ===== CONFETTI ===== */
.confetti-piece {
  position: fixed;
  font-size: 32px;
  z-index: 250;
  pointer-events: none;
  animation: confettiFall linear forwards;
}

@keyframes confettiFall {
  0% {
    transform: translateY(-20px) rotate(0deg) scale(1);
    opacity: 1;
  }
  100% {
    transform: translateY(100vh) rotate(720deg) scale(0.3);
    opacity: 0;
  }
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb {
  background: #CCC;
  border-radius: 4px;
}

/* ===== RESPONSIVE - TABLETS ===== */
@media (min-width: 768px) {
  .categories-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    max-width: 700px;
    margin: 0 auto;
  }

  .cat-card {
    padding: 24px 16px 18px;
  }

  .cat-card-img {
    width: 100px;
    height: 100px;
  }

  .cat-name { font-size: 17px; }

  .hero h2 { font-size: 36px; }
  .hero p { font-size: 20px; }

  .worksheet-list {
    max-width: 600px;
    margin: 0 auto;
  }

  .tool-btn {
    width: 56px; height: 56px;
    font-size: 28px;
  }

  .color-dot {
    width: 44px; height: 44px;
  }
}

@media (min-width: 1024px) {
  .categories-grid {
    grid-template-columns: repeat(3, 1fr);
    max-width: 800px;
  }
}

/* Glassmorphism effect helper */
.glass {
  background: rgba(255,255,255,0.7);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
