<?php
// api_playlist.php
require 'config.php';
header('Content-Type: application/json');
header("Access-Control-Allow-Origin: *");

$formato = $_GET['formato'] ?? '16:9';

// MUDANÇA: ORDER BY ordem ASC
$stmt = $pdo->prepare("SELECT * FROM conteudos WHERE formato = ? AND ativo = 1 ORDER BY ordem ASC");
$stmt->execute([$formato]);
$slides = $stmt->fetchAll(PDO::FETCH_ASSOC);

echo json_encode($slides);
?>