<?php
$items = array_values(array_filter($s['items'], fn($item) => $item['title'] || $item['image']));
$cols = ['1' => '', '2' => 'md:grid-cols-2', '3' => 'md:grid-cols-3'][$s['columns']] ?? 'md:grid-cols-2';
$height = ['sm' => 'min-h-[220px]', 'md' => 'min-h-[320px] sm:min-h-[380px]', 'lg' => 'min-h-[420px] sm:min-h-[520px]'][$s['height']] ?? 'min-h-[320px]';
?>
<div class="grid gap-4 sm:gap-6 <?= $cols ?>">
    <?php foreach ($items as $item): ?>
        <?php $dark = $item['dark_text'] === '1' ?>
        <a href="<?= e(section_link($item['link']) ?: '#') ?>" class="group relative flex overflow-hidden rounded-[var(--radius-panel)] <?= $height ?>" style="background-color: <?= e(hex_color($item['color'], '#18181b')) ?>">
            <?php if ($item['image']): ?>
                <img src="<?= e(upload_url($item['image'])) ?>" alt="" class="absolute inset-0 h-full w-full object-cover transition duration-700 ease-out-soft group-hover:scale-[1.03]" loading="lazy">
                <?php if (!$dark): ?><div class="absolute inset-0 bg-gradient-to-t from-black/60 via-black/10 to-transparent"></div><?php endif ?>
            <?php else: ?>
                <div class="absolute -right-20 -bottom-24 size-80 rounded-full bg-white/10 blur-2xl"></div>
            <?php endif ?>
            <div class="relative mt-auto p-7 sm:p-10 <?= $dark ? 'text-ink' : 'text-white' ?>">
                <?php if ($item['eyebrow']): ?><p class="text-xs font-semibold tracking-[.18em] uppercase opacity-70"><?= e($item['eyebrow']) ?></p><?php endif ?>
                <h3 class="font-display mt-3 text-3xl <?= heading_weight_class() ?> tracking-tight sm:text-4xl"><?= e($item['title']) ?></h3>
                <?php if ($item['text']): ?><p class="mt-3 max-w-md text-sm leading-6 opacity-80"><?= e($item['text']) ?></p><?php endif ?>
                <?php if ($item['button_text']): ?>
                    <span class="mt-6 inline-flex items-center gap-2 border-b-2 pb-1 text-sm font-semibold <?= $dark ? 'border-ink' : 'border-white' ?>"><?= e($item['button_text']) ?><?= icon('arrow', 'size-4 transition group-hover:translate-x-1', '2') ?></span>
                <?php endif ?>
            </div>
        </a>
    <?php endforeach ?>
</div>
