/* ==========================================================================
   Mate Aventuras · estilos
   Paleta y tipografía infantil. Móvil-first y accesible.
   Para cambiar colores: tocá las variables :root.
   ========================================================================== */

:root {
  --color-bg:        #FFFAEC;
  --color-bg-2:      #FFF3D0;
  --color-surface:   #FFFFFF;
  --color-text:      #2D2D44;
  --color-muted:     #6B6B85;

  --color-primary:   #4D96FF;  /* azul cielo */
  --color-primary-d: #2F7BE0;
  --color-success:   #6BCB77;  /* verde menta */
  --color-success-d: #4FB05D;
  --color-warning:   #FFD93D;  /* amarillo dorado */
  --color-danger:    #FF6B6B;  /* coral */
  --color-accent:    #B983FF;  /* lila */

  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;

  --shadow-card: 0 12px 30px rgba(45, 45, 68, 0.10), 0 4px 10px rgba(45, 45, 68, 0.06);
  --shadow-btn:  0 6px 0 rgba(0, 0, 0, 0.12);
  --shadow-pop:  0 8px 24px rgba(77, 150, 255, 0.30);

  --font-display: 'Baloo 2', 'Fredoka', system-ui, sans-serif;
  --font-body:    'Fredoka', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  color: var(--color-text);
  background:
    radial-gradient(circle at 10% 10%, #FFE8A8 0, transparent 35%),
    radial-gradient(circle at 90% 15%, #BEE3FF 0, transparent 40%),
    radial-gradient(circle at 50% 100%, #D5FFD9 0, transparent 45%),
    linear-gradient(180deg, var(--color-bg) 0%, var(--color-bg-2) 100%);
  background-attachment: fixed;
  min-height: 100vh;
  min-height: 100svh;
  line-height: 1.4;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  border: 0; overflow: hidden;
  clip: rect(0 0 0 0);
}

.hidden { display: none !important; }

/* ============ LAYOUT ============ */

.app {
  max-width: 760px;
  margin: 0 auto;
  padding: 16px 16px 32px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100svh;
}

.app-header {
  padding: 12px 4px 18px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo img {
  border-radius: 14px;
  box-shadow: 0 6px 16px rgba(77, 150, 255, 0.30);
  background: #fff;
}

.logo-text h1 {
  font-family: var(--font-display);
  margin: 0;
  font-size: clamp(1.6rem, 5vw, 2.1rem);
  line-height: 1;
  color: var(--color-primary-d);
  letter-spacing: 0.5px;
}

.logo-text .subtitle {
  margin: 4px 0 0;
  color: var(--color-muted);
  font-weight: 500;
  font-size: 0.95rem;
}

.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.app-footer {
  text-align: center;
  color: var(--color-muted);
  padding-top: 18px;
}

/* ============ CARDS ============ */

.card {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  padding: 24px 20px 28px;
  box-shadow: var(--shadow-card);
  border: 3px solid #fff;
  position: relative;
}

.card-title {
  font-family: var(--font-display);
  margin: 0 0 16px;
  text-align: center;
  font-size: clamp(1.4rem, 4.5vw, 1.8rem);
  color: var(--color-primary-d);
}

/* ============ SCREENS / TRANSICIONES ============ */

.screen {
  display: none;
  animation: fadeUp 320ms cubic-bezier(.16,1,.3,1);
}

.screen.active { display: block; }

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

/* ============ PICKERS (opciones grandes) ============ */

.picker {
  border: 0;
  padding: 0;
  margin: 0 0 18px;
}

.picker legend {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--color-text);
  margin-bottom: 10px;
  display: block;
}

.options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.options-small {
  grid-template-columns: repeat(4, 1fr);
}

.option {
  appearance: none;
  border: 3px solid #EEE7CF;
  background: #FFFDF5;
  border-radius: var(--radius-lg);
  padding: 14px 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease, box-shadow 120ms ease;
  font-family: var(--font-body);
  color: var(--color-text);
  min-height: 76px;
}

.option:hover { transform: translateY(-2px); }
.option:active { transform: translateY(1px); }

.option .option-icon {
  font-size: 1.6rem;
  line-height: 1;
}

.option .option-label {
  font-weight: 600;
  font-size: 0.95rem;
}

.option.chip {
  min-height: 56px;
  padding: 12px 6px;
}

.option[aria-pressed="true"] {
  border-color: var(--color-primary);
  background: linear-gradient(180deg, #E6F1FF 0%, #C7DEFF 100%);
  box-shadow: 0 6px 0 rgba(47, 123, 224, 0.25);
}

.op-sum[aria-pressed="true"] { border-color: var(--color-success); background: linear-gradient(180deg, #E5FBE8 0%, #C6F4CC 100%); box-shadow: 0 6px 0 rgba(79, 176, 93, 0.25); }
.op-res[aria-pressed="true"] { border-color: var(--color-warning); background: linear-gradient(180deg, #FFF5C2 0%, #FFE98A 100%); box-shadow: 0 6px 0 rgba(200, 160, 0, 0.25); }
.op-mul[aria-pressed="true"] { border-color: var(--color-accent);  background: linear-gradient(180deg, #F1E4FF 0%, #DDC1FF 100%); box-shadow: 0 6px 0 rgba(140, 90, 220, 0.25); }

/* ============ COUNTER ============ */

.counter {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #FFFDF5;
  border: 3px solid #EEE7CF;
  border-radius: var(--radius-lg);
  padding: 10px 14px;
}

.counter-btn {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 0;
  background: var(--color-primary);
  color: #fff;
  font-size: 1.8rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--color-primary-d);
  transition: transform 120ms ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.counter-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--color-primary-d); }

.counter-value {
  text-align: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 2.2rem;
  color: var(--color-primary-d);
  line-height: 1;
}

.counter-value small {
  display: block;
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 0.85rem;
  color: var(--color-muted);
  margin-top: 4px;
}

/* ============ SWITCH (estilo iOS, con etiquetas SÍ/NO) ============ */

.switch {
  display: flex;
  align-items: center;
  gap: 16px;
  background: #FFFDF5;
  border: 3px solid #EEE7CF;
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  cursor: pointer;
  user-select: none;
  transition: border-color 200ms ease, background 200ms ease;
}

.switch:hover { border-color: #E6D7A5; }

/* Checkbox real escondido — manejado vía label */
.switch input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 0;
  height: 0;
}

/* El "carril" del switch */
.switch-control {
  position: relative;
  flex-shrink: 0;
  width: 88px;
  height: 44px;
  border-radius: 999px;
  background: #BFC7D6;
  transition: background 240ms ease;
  display: flex;
  align-items: center;
  padding: 0 12px;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.12);
  overflow: hidden;
}

.switch-label {
  flex: 1;
  text-align: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 0.88rem;
  color: #fff;
  letter-spacing: 0.6px;
  pointer-events: none;
  transition: opacity 200ms ease;
  z-index: 1;
}

.switch-on  { opacity: 0; }
.switch-off { opacity: 1; }

/* La perilla circular */
.switch-knob {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 36px;
  height: 36px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  transition: transform 260ms cubic-bezier(.16,1,.3,1);
  z-index: 2;
}

/* Estado encendido */
.switch input:checked ~ .switch-control {
  background: var(--color-success);
}
.switch input:checked ~ .switch-control .switch-knob {
  transform: translateX(44px);
}
.switch input:checked ~ .switch-control .switch-on  { opacity: 1; }
.switch input:checked ~ .switch-control .switch-off { opacity: 0; }

/* Foco accesible */
.switch input:focus-visible ~ .switch-control {
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.12),
              0 0 0 4px rgba(77, 150, 255, 0.30);
}

/* Borde del contenedor cambia al activarse (donde :has() esté disponible) */
.switch:has(input:checked) {
  border-color: var(--color-success);
  background: #F1FBF3;
}

/* Texto al lado del switch */
.switch-info strong {
  display: block;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--color-text);
  line-height: 1.1;
}

.switch-info small {
  display: block;
  color: var(--color-muted);
  font-size: 0.85rem;
  margin-top: 4px;
  line-height: 1.3;
}

/* ============ BUTTONS ============ */

.btn {
  appearance: none;
  border: 0;
  border-radius: var(--radius-lg);
  padding: 14px 20px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  transition: transform 100ms ease, box-shadow 100ms ease, filter 100ms ease;
  color: #fff;
  min-height: 52px;
}

.btn-primary   { background: var(--color-primary);  box-shadow: 0 5px 0 var(--color-primary-d); }
.btn-success   { background: var(--color-success);  box-shadow: 0 5px 0 var(--color-success-d); }
.btn-secondary { background: #6C7B95;               box-shadow: 0 5px 0 #4B5670; }

.btn-lg { font-size: 1.15rem; padding: 16px 22px; min-height: 58px; }
.btn-xl { font-size: 1.25rem; padding: 18px 24px; min-height: 64px; width: 100%; margin-top: 6px; }

.btn:hover { filter: brightness(1.04); }
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0,0,0,0.2); }

.btn:disabled {
  filter: grayscale(0.4) brightness(0.95);
  cursor: not-allowed;
  box-shadow: 0 3px 0 rgba(0,0,0,0.12);
}

.btn-text {
  background: none;
  border: 0;
  color: var(--color-muted);
  cursor: pointer;
  margin-top: 12px;
  font-size: 0.95rem;
  font-family: var(--font-body);
  padding: 8px;
  width: 100%;
  text-align: center;
}
.btn-text:hover { color: var(--color-primary-d); }

/* ============ EXERCISE ============ */

.card-exercise {
  padding-top: 16px;
}

.progress {
  margin-bottom: 18px;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 8px;
}

.progress-label {
  font-weight: 600;
  color: var(--color-text);
  font-size: 1rem;
}

.progress-label strong {
  font-family: var(--font-display);
  color: var(--color-primary-d);
}

.progress-motivation {
  font-family: var(--font-display);
  color: var(--color-accent);
  font-weight: 700;
  font-size: 0.95rem;
}

.progress-bar {
  height: 14px;
  background: #EEE7CF;
  border-radius: 999px;
  overflow: hidden;
  border: 2px solid #fff;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.08);
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #FFD93D 0%, #6BCB77 50%, #4D96FF 100%);
  border-radius: 999px;
  transition: width 360ms cubic-bezier(.16,1,.3,1);
}

/* === Operación vertical estilo cuaderno ===
   Construida en JS como una grilla: 1 columna para el signo + N columnas (una por dígito)
   para que unidades, decenas y centenas queden alineadas perfectamente. */
.operation {
  --cell-w: clamp(40px, 10vw, 60px);
  --cell-h: clamp(50px, 12vw, 74px);
  --cell-gap: clamp(4px, 1vw, 8px);
  --sign-col-w: clamp(28px, 6vw, 40px);

  background: #FFFDF5;
  border: 3px dashed #EEDFB4;
  border-radius: var(--radius-lg);
  padding: 22px 18px 18px;
  margin: 8px 0 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.op-row,
.op-line-row {
  display: grid;
  grid-template-columns: var(--sign-col-w) repeat(var(--cells, 3), var(--cell-w));
  gap: var(--cell-gap);
  align-items: center;
}

.op-line-row { margin: 4px 0 6px; }

.op-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Baloo 2', system-ui;
  font-weight: 800;
  font-size: clamp(1.7rem, 7vw, 2.4rem);
  color: var(--color-text);
  line-height: 1;
  height: var(--cell-h);
  position: relative;
}

/* Superíndice de acarreo (cuando "Ayudar" está activo).
   Inicia oculto y se revela al capturar el input de la columna que LO GENERA.
   Se posiciona arriba-izquierda del dígito que LO RECIBE, en rojo. */
.op-row.with-carries { margin-top: 22px; }
.op-row.with-carries .op-cell { overflow: visible; }
.op-cell > .carry {
  position: absolute;
  top: -20px;
  left: 4px;
  font-size: 0.55em;
  font-weight: 900;
  font-family: 'Baloo 2', system-ui;
  color: var(--color-danger);
  line-height: 1;
  pointer-events: none;
  text-shadow: 0 1px 0 rgba(255,255,255,0.9);

  /* Estado inicial: oculto, listo para animar de entrada */
  opacity: 0;
  transform: translateY(10px) scale(0.4);
  transition: opacity 220ms ease,
              transform 380ms cubic-bezier(.34, 1.56, .64, 1);
}

.op-cell > .carry.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.op-sign-cell {
  color: var(--color-primary-d);
  font-size: clamp(1.5rem, 6vw, 2.1rem);
}

.op-line {
  height: 5px;
  background: var(--color-text);
  border-radius: 5px;
  opacity: 0.9;
  width: 100%;
}

.digit-input {
  width: 100%;
  height: var(--cell-h);
  border-radius: 14px;
  border: 3px solid #C9D6EA;
  background: #fff;
  font-family: 'Baloo 2', system-ui;
  font-weight: 800;
  font-size: clamp(1.6rem, 6.5vw, 2.2rem);
  color: var(--color-primary-d);
  text-align: center;
  outline: none;
  caret-color: var(--color-primary);
  transition: border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
  -moz-appearance: textfield;
  appearance: textfield;
  padding: 0;
}

.digit-input::-webkit-outer-spin-button,
.digit-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.digit-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 4px rgba(77, 150, 255, 0.20);
  transform: translateY(-2px);
}

.digit-input.filled { background: #F1F7FF; }
.digit-input.correct { border-color: var(--color-success); background: #E8FBEC; color: var(--color-success-d); }
.digit-input.wrong   { border-color: var(--color-danger);  background: #FFECEC; color: var(--color-danger); animation: shake 360ms; }

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

/* ============ FEEDBACK ============ */

.feedback {
  min-height: 44px;
  text-align: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  margin: 6px 0 8px;
  transition: color 120ms ease;
}

.feedback.ok    { color: var(--color-success-d); }
.feedback.bad   { color: var(--color-danger); }
.feedback.bounce { animation: bounce 480ms; }

@keyframes bounce {
  0%   { transform: scale(0.9); opacity: 0; }
  60%  { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); }
}

/* ============ ACTIONS ============ */

.actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.actions .btn { flex: 1; min-width: 160px; }

/* ============ PANTALLA FINAL ============ */

.card-final {
  text-align: center;
  padding: 36px 22px 30px;
}

.trophy {
  font-size: 5rem;
  line-height: 1;
  animation: pop 600ms cubic-bezier(.16,1,.3,1);
}

@keyframes pop {
  0% { transform: scale(0.4) rotate(-12deg); opacity: 0; }
  60% { transform: scale(1.15) rotate(6deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); }
}

.card-final h2 {
  font-family: var(--font-display);
  color: var(--color-primary-d);
  margin: 8px 0 6px;
  font-size: 2rem;
}

.card-final p { color: var(--color-text); margin: 6px 0; }

.final-stats {
  font-size: 1.1rem;
  background: #FFF6D0;
  border-radius: var(--radius-md);
  padding: 10px 14px;
  display: inline-block;
  margin: 14px 0;
  font-weight: 600;
}

.final-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 8px;
}

.final-actions .btn { flex: 1; min-width: 200px; }

/* ============ CONFETTI ============ */

.confetti {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 9999;
}

.confetti-piece {
  position: absolute;
  top: -20px;
  width: 10px;
  height: 14px;
  border-radius: 3px;
  opacity: 0.95;
  animation: confetti-fall linear forwards;
}

@keyframes confetti-fall {
  0%   { transform: translateY(-30px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(110vh) rotate(720deg); opacity: 0.7; }
}

/* ============ RESPONSIVE ============ */

@media (max-width: 420px) {
  .options { gap: 8px; }
  .option .option-icon { font-size: 1.4rem; }
  .option .option-label { font-size: 0.85rem; }
  .options-small { grid-template-columns: repeat(2, 1fr); }
  .actions .btn { min-width: 100%; }
  .logo-text h1 { font-size: 1.5rem; }
  .card { padding: 20px 14px 24px; }
}

@media (min-width: 720px) {
  .app { padding-top: 28px; }
  .options-small { grid-template-columns: repeat(4, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
