/* ================================================================
   Aprende Matemáticas con Kuk — Segundo Grado
   Mobile-first for low-end Android phones (360px-414px)
   ================================================================ */

@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800;900&display=swap');

:root {
  --color-primary: #1565C0;
  --color-primary-light: #1E88E5;
  --color-secondary: #FF6F00;
  --color-secondary-light: #FFA000;
  --color-accent: #E91E63;
  --color-accent-light: #F06292;
  --color-gold: #FFD700;
  --color-gold-dark: #FFA000;
  --bg-sky: #87CEEB;
  --bg-sky-deep: #4FC3F7;
  --bg-earth: #8B4513;
  --bg-earth-light: #A0522D;
  --bg-grass: #388E3C;
  --color-white: #FFFFFF;
  --color-dark: #1A1A2E;
  --color-text: #2C2C2C;
  --color-text-light: #666666;
  --shadow-soft: 0 4px 20px rgba(0,0,0,0.15);
  --shadow-strong: 0 8px 32px rgba(0,0,0,0.3);
  --border-radius-lg: 24px;
  --border-radius-xl: 40px;
  --transition-fast: 0.2s ease;
  --transition-normal: 0.35s cubic-bezier(0.34,1.56,0.64,1);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
}

html {
  font-size: 16px;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Nunito', 'Trebuchet MS', sans-serif;
  background: var(--bg-sky);
  color: var(--color-text);
  height: 100%;
  width: 100%;
  overflow: hidden;
  position: fixed;
  top: 0;
  left: 0;
}

#app {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
}

/* ── Screen System ────────────────────────────────────────────── */
.screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  pointer-events: none;
  transform: scale(0.96) translateY(20px);
  transition: opacity 0.35s ease, transform 0.35s cubic-bezier(0.34,1.56,0.64,1);
  will-change: opacity, transform;
  overflow: hidden;
}

.screen.active {
  opacity: 1;
  pointer-events: all;
  transform: scale(1) translateY(0);
  z-index: 10;
}

/* ── Loading Screen ───────────────────────────────────────────── */
#loading-screen {
  background: linear-gradient(180deg, var(--bg-sky) 0%, #B3E5FC 50%, var(--bg-grass) 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  z-index: 100;
}

#loading-screen.active {
  opacity: 1;
  pointer-events: all;
  transform: none;
}

.loading-kuk {
  width: 140px;
  height: 140px;
  animation: kukBounce 1s ease-in-out infinite;
}

.loading-title {
  font-size: 1.6rem;
  font-weight: 900;
  color: var(--color-primary);
  text-shadow: 2px 2px 0 rgba(255,255,255,0.8);
  text-align: center;
}

.loading-dots {
  display: flex;
  gap: 8px;
}

.loading-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--color-gold);
  animation: dotBounce 0.6s ease-in-out infinite alternate;
}
.loading-dot:nth-child(2) { animation-delay: 0.2s; background: var(--color-secondary); }
.loading-dot:nth-child(3) { animation-delay: 0.4s; background: var(--color-accent); }

/* ── Map Screen ───────────────────────────────────────────────── */
#map-screen {
  background: linear-gradient(
    180deg,
    #1565C0 0%,
    #42A5F5 20%,
    #81C784 55%,
    #A5D6A7 70%,
    #8B4513 100%
  );
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.map-header {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: rgba(255,255,255,0.2);
  backdrop-filter: blur(4px);
}

.map-stars-display {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.9);
  border-radius: 20px;
  padding: 6px 14px;
  box-shadow: var(--shadow-soft);
}

.map-stars-icon { font-size: 1.4rem; }

.map-stars-count {
  font-size: 1.3rem;
  font-weight: 900;
  color: var(--color-gold-dark);
}

.map-title {
  font-size: 1.1rem;
  font-weight: 800;
  color: white;
  text-shadow: 1px 2px 4px rgba(0,0,0,0.4);
}

.map-profile-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 3px solid white;
  background: var(--color-secondary);
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  transition: transform var(--transition-fast);
}

.map-profile-btn:active { transform: scale(0.9); }

.map-world {
  position: relative;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 20px 16px 100px;
}

.map-path-svg {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
}

/* ── World Nodes ─────────────────────────────────────────────── */
.world-nodes-container {
  position: relative;
  width: 100%;
  min-height: 700px;
}

.world-node {
  position: absolute;
  width: 88px;
  height: 88px;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: 4px solid white;
  box-shadow: var(--shadow-strong);
  transition: transform var(--transition-fast);
  z-index: 5;
}

.world-node:active { transform: scale(0.9); }

.world-node.unlocked {
  animation: worldPulse 2s ease-in-out infinite;
}

.world-node.locked {
  opacity: 0.55;
  filter: grayscale(60%);
  cursor: default;
}

.world-node.completed {
  border-color: var(--color-gold);
  box-shadow: 0 0 20px rgba(255,215,0,0.6), var(--shadow-strong);
}

.world-node-emoji { font-size: 2rem; line-height: 1; }

.world-node-stars {
  display: flex;
  gap: 1px;
  margin-top: 2px;
}

.world-node-star {
  font-size: 0.75rem;
  color: rgba(255,255,255,0.4);
}

.world-node-star.earned { color: var(--color-gold); }

.world-node-lock {
  position: absolute;
  top: -4px;
  right: -4px;
  background: rgba(0,0,0,0.6);
  border-radius: 50%;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
}

.world-label {
  position: absolute;
  bottom: -28px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255,255,255,0.95);
  border-radius: 12px;
  padding: 2px 10px;
  font-size: 0.7rem;
  font-weight: 800;
  color: var(--color-text);
  white-space: nowrap;
  box-shadow: var(--shadow-soft);
}

/* ── Kuk Guide ─────────────────────────────────────────────────── */
.kuk-guide {
  position: fixed;
  bottom: 20px;
  right: 16px;
  width: 90px;
  height: 90px;
  z-index: 50;
  cursor: pointer;
  filter: drop-shadow(2px 4px 8px rgba(0,0,0,0.3));
  transition: transform 0.6s cubic-bezier(0.34,1.56,0.64,1);
}

.kuk-guide:active { transform: scale(0.9); }
.kuk-guide svg { width: 100%; height: 100%; }

.kuk-speech-bubble {
  position: fixed;
  bottom: 120px;
  right: 16px;
  max-width: 220px;
  background: white;
  border-radius: 18px 18px 4px 18px;
  padding: 12px 16px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--color-text);
  box-shadow: var(--shadow-strong);
  z-index: 51;
  opacity: 0;
  transform: scale(0.8) translateY(10px);
  transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.34,1.56,0.64,1);
  pointer-events: none;
}

.kuk-speech-bubble.visible {
  opacity: 1;
  transform: scale(1) translateY(0);
}

.kuk-speech-bubble::after {
  content: '';
  position: absolute;
  bottom: -12px;
  right: 20px;
  width: 0; height: 0;
  border-left: 12px solid transparent;
  border-right: 6px solid transparent;
  border-top: 12px solid white;
}

/* ── Lesson Screen ────────────────────────────────────────────── */
#lesson-screen {
  background: rgba(0,0,0,0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
}

.lesson-header {
  width: 100%;
  display: flex;
  align-items: center;
  padding: 12px 16px;
  gap: 12px;
  background: rgba(255,255,255,0.1);
}

.lesson-back-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  font-size: 1.4rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast), transform var(--transition-fast);
}

.lesson-back-btn:active {
  background: rgba(255,255,255,0.35);
  transform: scale(0.9);
}

.lesson-progress-dots {
  display: flex;
  gap: 8px;
  flex: 1;
  justify-content: center;
}

.lesson-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: rgba(255,255,255,0.3);
  transition: background 0.3s ease, transform 0.3s ease;
}

.lesson-dot.active {
  background: var(--color-gold);
  transform: scale(1.3);
}

.lesson-dot.done { background: var(--color-primary-light); }

.lesson-canvas-wrap {
  position: relative;
  width: 100%;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.lesson-canvas {
  display: block;
  max-width: 100vw;
  max-height: 80vh;
  border-radius: 0;
  touch-action: none;
}

/* ── Profile Screen ───────────────────────────────────────────── */
#profile-screen {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-y: auto;
  padding: 20px 16px 40px;
  gap: 20px;
}

.profile-back-btn {
  align-self: flex-start;
  width: 48px; height: 48px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  font-size: 1.4rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.profile-avatar-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  width: 100%;
  max-width: 320px;
}

.profile-avatar-option {
  aspect-ratio: 1;
  border-radius: 20px;
  background: rgba(255,255,255,0.2);
  border: 3px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform var(--transition-normal), border-color var(--transition-fast);
  overflow: hidden;
}

.profile-avatar-option.selected {
  border-color: var(--color-gold);
  background: rgba(255,215,0,0.25);
  transform: scale(1.08);
}

.profile-avatar-option svg { width: 80%; height: 80%; }

.profile-name-display {
  font-size: 2.2rem;
  font-weight: 900;
  color: white;
  text-shadow: 2px 3px 6px rgba(0,0,0,0.3);
  text-align: center;
}

.profile-stars-field {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  padding: 16px;
  background: rgba(255,255,255,0.15);
  border-radius: 20px;
  width: 100%;
  min-height: 80px;
}

.profile-star-item {
  font-size: 1.5rem;
  animation: sparkle 0.4s ease-out;
}

.profile-module-progress {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.module-progress-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255,255,255,0.15);
  border-radius: 16px;
  padding: 10px 14px;
}

.module-progress-emoji { font-size: 1.6rem; flex-shrink: 0; }

.module-progress-track {
  flex: 1;
  height: 14px;
  background: rgba(255,255,255,0.2);
  border-radius: 7px;
  overflow: hidden;
}

.module-progress-fill {
  height: 100%;
  border-radius: 7px;
  background: linear-gradient(90deg, var(--color-gold), var(--color-secondary));
  transition: width 1s cubic-bezier(0.34,1.56,0.64,1);
}

.profile-create-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  width: 100%;
  max-width: 340px;
}

/* ── Parent Screen ────────────────────────────────────────────── */
#parent-screen {
  background: linear-gradient(135deg, #1a237e 0%, #283593 100%);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.parent-header {
  display: flex;
  align-items: center;
  padding: 16px;
  gap: 12px;
  background: rgba(0,0,0,0.2);
}

.parent-back-btn {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  border: none;
  color: white;
  font-size: 1.4rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.parent-title {
  font-size: 1.3rem;
  font-weight: 800;
  color: white;
  flex: 1;
}

.parent-content {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.parent-card {
  background: rgba(255,255,255,0.1);
  border-radius: 20px;
  padding: 18px;
  border: 1px solid rgba(255,255,255,0.15);
}

.parent-card-title {
  font-size: 1rem;
  font-weight: 800;
  color: rgba(255,255,255,0.9);
  margin-bottom: 14px;
}

.parent-stat {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.parent-stat:last-child { border-bottom: none; }

.parent-stat-label { color: rgba(255,255,255,0.7); font-size: 0.9rem; font-weight: 600; }
.parent-stat-value { color: var(--color-gold); font-size: 1.2rem; font-weight: 900; }

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 80px;
  padding-top: 8px;
}

.bar-chart-bar {
  flex: 1;
  background: linear-gradient(180deg, var(--color-secondary-light), var(--color-secondary));
  border-radius: 4px 4px 0 0;
  min-height: 4px;
}

.bar-chart-label {
  font-size: 0.6rem;
  color: rgba(255,255,255,0.5);
  text-align: center;
  margin-top: 4px;
}

.bar-chart-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.module-completion-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.module-completion-emoji { font-size: 1.3rem; }

.module-completion-bar-track {
  flex: 1;
  height: 10px;
  background: rgba(255,255,255,0.15);
  border-radius: 5px;
  overflow: hidden;
}

.module-completion-fill {
  height: 100%;
  border-radius: 5px;
}

.module-completion-pct {
  font-size: 0.85rem;
  font-weight: 800;
  color: rgba(255,255,255,0.9);
  min-width: 36px;
  text-align: right;
}

/* ── PIN Entry ────────────────────────────────────────────────── */
.pin-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 40px 20px;
}

.pin-dots { display: flex; gap: 14px; }

.pin-dot {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.5);
  background: transparent;
  transition: background var(--transition-fast);
}

.pin-dot.filled { background: var(--color-gold); border-color: var(--color-gold); }

.pin-keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  width: 100%;
  max-width: 280px;
}

.pin-key {
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  border: 2px solid rgba(255,255,255,0.25);
  color: white;
  font-size: 1.6rem;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast), transform var(--transition-fast);
  font-family: 'Nunito', sans-serif;
}

.pin-key:active {
  background: rgba(255,255,255,0.35);
  transform: scale(0.88);
}

.pin-key.delete { font-size: 1.2rem; }

/* ── Buttons ──────────────────────────────────────────────────── */
.btn-large {
  min-height: 60px;
  padding: 14px 32px;
  border-radius: var(--border-radius-xl);
  border: none;
  font-family: 'Nunito', sans-serif;
  font-size: 1.15rem;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  box-shadow: 0 4px 0 rgba(0,0,0,0.25), var(--shadow-soft);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  width: 100%;
  max-width: 320px;
}

.btn-large:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(0,0,0,0.25);
}

.btn-primary {
  background: linear-gradient(135deg, var(--color-primary-light), var(--color-primary));
  color: white;
}

.btn-secondary {
  background: linear-gradient(135deg, var(--color-secondary-light), var(--color-secondary));
  color: white;
}

.btn-gold {
  background: linear-gradient(135deg, #FFE066, var(--color-gold));
  color: var(--color-text);
}

/* ── Victory Overlay ──────────────────────────────────────────── */
.victory-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 200;
  gap: 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.victory-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.victory-stars { display: flex; gap: 12px; }

.victory-star {
  font-size: 4rem;
  animation: victoryBurst 0.5s cubic-bezier(0.34,1.56,0.64,1) both;
}

.victory-star:nth-child(2) { animation-delay: 0.15s; }
.victory-star:nth-child(3) { animation-delay: 0.3s; }

.victory-text {
  font-size: 2rem;
  font-weight: 900;
  color: white;
  text-shadow: 2px 3px 0 rgba(0,0,0,0.3);
  animation: victoryBurst 0.5s cubic-bezier(0.34,1.56,0.64,1) 0.1s both;
}

.victory-btn {
  animation: victoryBurst 0.5s cubic-bezier(0.34,1.56,0.64,1) 0.5s both;
}

/* ── Input Fields ─────────────────────────────────────────────── */
.input-field {
  width: 100%;
  max-width: 320px;
  padding: 16px 20px;
  border-radius: 20px;
  border: 3px solid rgba(255,255,255,0.3);
  background: rgba(255,255,255,0.15);
  color: white;
  font-family: 'Nunito', sans-serif;
  font-size: 1.3rem;
  font-weight: 700;
  text-align: center;
  outline: none;
  transition: border-color var(--transition-fast), background var(--transition-fast);
}

.input-field::placeholder { color: rgba(255,255,255,0.5); }
.input-field:focus {
  border-color: var(--color-gold);
  background: rgba(255,255,255,0.25);
}

/* ── Scrollbar ────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 0; height: 0; }

/* ================================================================
   ANIMATIONS
   ================================================================ */

@keyframes kukBounce {
  0%, 100% { transform: translateY(0) rotate(-3deg); }
  50% { transform: translateY(-16px) rotate(3deg); }
}

@keyframes worldPulse {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 8px 32px rgba(0,0,0,0.3), 0 0 0 0 rgba(255,215,0,0.5);
  }
  50% {
    transform: scale(1.06);
    box-shadow: 0 8px 32px rgba(0,0,0,0.3), 0 0 0 12px rgba(255,215,0,0);
  }
}

@keyframes sparkle {
  0% { transform: scale(0) rotate(-30deg); opacity: 0; }
  60% { transform: scale(1.3) rotate(10deg); opacity: 1; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

@keyframes victoryBurst {
  0% { transform: scale(0) rotate(-20deg); opacity: 0; }
  70% { transform: scale(1.2) rotate(5deg); opacity: 1; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

@keyframes feedbackCorrect {
  0% { transform: scale(1); }
  30% { transform: scale(1.25); filter: brightness(1.3); }
  100% { transform: scale(1); filter: brightness(1); }
}

@keyframes feedbackWrong {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}

@keyframes dotBounce {
  0% { transform: translateY(0); }
  100% { transform: translateY(-12px); }
}

@keyframes popIn {
  0% { transform: scale(0) rotate(-15deg); opacity: 0; }
  70% { transform: scale(1.15) rotate(3deg); opacity: 1; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

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

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px) rotate(-2deg); }
  75% { transform: translateX(8px) rotate(2deg); }
}

/* ── Responsive ────────────────────────────────────────────────── */
@media (min-width: 414px) {
  .world-node { width: 96px; height: 96px; }
  .lesson-canvas { border-radius: 12px; }
}

@media (max-width: 360px) {
  .world-node { width: 76px; height: 76px; }
  .world-node-emoji { font-size: 1.6rem; }
  .btn-large { font-size: 1rem; min-height: 54px; }
}
