<?php
declare(strict_types=1);

require __DIR__ . '/lib/content.php';

$c = load_content();
$reviews = load_reviews();
$phone = $c['phone'] ?? '';
$phoneTel = $c['phone_tel'] ?? preg_replace('/\D+/', '', $phone);
$phone2 = $c['phone2'] ?? '';
$phone2Tel = $c['phone2_tel'] ?? preg_replace('/\D+/', '', $phone2);
$siteUrl = rtrim($c['site_url'] ?? 'https://vlasevo.ru', '/');
$title = $c['meta']['title'] ?? 'Власьево';
$description = $c['meta']['description'] ?? '';
$brand = $c['brand'] ?? 'Власьево';
$map = $c['map'] ?? [];
$mapShare = $map['share'] ?? 'https://yandex.com/maps/-/CXEdjGZ1';
$mapLl = $map['ll'] ?? '34.813168,55.753492';
$mapPt = $map['pt'] ?? '34.813312,55.753383';
$mapZoom = (int) ($map['zoom'] ?? 16);
[$mapLon, $mapLat] = array_pad(explode(',', $mapLl), 2, '');
[$ptLon, $ptLat] = array_pad(explode(',', $mapPt), 2, '');
$mapWidget = 'https://yandex.ru/map-widget/v1/?ll=' . rawurlencode($mapLon . ',' . $mapLat)
    . '&z=' . $mapZoom
    . '&pt=' . rawurlencode($ptLon . ',' . $ptLat . ',pm2rdm');

$telegram = $c['telegram'] ?? 'https://t.me/lisinwi';
$maxUrl = $c['max'] ?? '';
$vk = $c['vk'] ?? '';

function icon_svg(string $name): string
{
    // Монохромные марки, оптически выровненные в квадрате кнопки.
    if ($name === 'telegram') {
        return '<svg class="soc-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path fill="currentColor" d="M21.55 3.08 3.62 10.2c-1.18.47-1.16 2.14.04 2.56l4.55 1.62 1.78 5.72c.26.84 1.32 1.05 1.86.36l2.58-3.26 4.62 3.4c.76.56 1.82.18 2.02-.74L22.72 4.36a1.25 1.25 0 0 0-1.17-1.28Zm-10.55 11.05 8.16-7.42c.17-.15.38.08.24.25L12.6 15.1l-.45 3.38-1.15-4.35Z"/></svg>';
    }
    if ($name === 'vk') {
        return '<svg class="soc-icon" viewBox="3.2 6.2 17.6 12.2" aria-hidden="true" focusable="false"><path fill="currentColor" d="M12.78 17.35s.28-.03.42-.19c.13-.15.13-.42.13-.42s-.02-1.28.58-1.47c.58-.19 1.34.98 2.14 1.41.6.33 1.06.26 1.06.26l2.14-.03s1.12-.07.59-.95c-.04-.07-.31-.65-1.59-1.83-1.34-1.23-1.16-.05.45-2.74.98-1.64 1.38-2.65 1.26-3.08-.12-.41-.85-.3-.85-.3h-2.18s-.16-.02-.28.07c-.12.09-.19.3-.19.3s-.34.89-.79 1.64c-.94 1.59-1.32 1.68-1.47 1.58-.36-.23-.27-1.08-.27-1.66 0-1.8.27-2.41-.53-2.6-.27-.06-.47-.1-1.15-.11-.88-.01-1.62 0-2.04.16-.28.1-.5.33-.36.35.17.02.54.1.74.37.26.35.25 1.14.25 1.14s.15 2.16-.34 2.43c-.33.18-.8-.19-1.79-1.9-.51-.88-.89-1.85-.89-1.85s-.07-.18-.21-.28c-.16-.12-.38-.15-.38-.15H4.5s-.33.01-.44.15c-.1.13-.01.39-.01.39s1.58 3.7 3.37 5.56c1.64 1.7 3.5 1.59 3.5 1.59h.84z"/></svg>';
    }
    if ($name === 'max') {
        return '<svg class="soc-icon" viewBox="-2 -1 104 102" aria-hidden="true" focusable="false"><path fill="currentColor" fill-rule="evenodd" clip-rule="evenodd" d="M50.76 0c27.53 0 49.12 22.34 49.12 49.89S77.61 99.23 51.02 99.23c-9.43 0-14.01-1.33-21.37-6.54-.5-.36-1.2-.26-1.63.19-5.66 6.04-20.17 10.28-20.83 2.03C7.19 80.53 0 71.18 0 49.61 0 21.3 23.22 0 50.76 0m.77 24.55c-13.07-.68-23.26 8.39-25.51 22.58-1.86 11.75 1.44 26.07 4.26 26.8 1.2.3 4.08-1.9 6.18-3.88.4-.37.99-.44 1.45-.15 3.27 2 6.97 3.5 11.05 3.71 13.42.7 25.3-9.8 26-23.21.71-13.42-10.01-25.14-23.43-25.85"/></svg>';
    }
    // Белый гриб / боровик — силуэт без «мухоморных» точек
    if ($name === 'bolete' || $name === 'mushroom') {
        return '<img class="service-icon-svg" src="assets/img/icon-bolete.svg" alt="" width="18" height="18" decoding="async">';
    }
    return '';
}

function service_icon_html(string $icon): string
{
    $key = strtolower(trim($icon));
    // Старый emoji-мухомор и ключ bolete → иконка белого гриба
    if ($key === 'bolete' || $key === 'mushroom' || $key === '🍄' || $key === "\u{1F344}") {
        return icon_svg('bolete');
    }
    if (in_array($key, ['telegram', 'vk', 'max'], true)) {
        return icon_svg($key);
    }
    if ($icon === '') {
        return '';
    }
    return htmlspecialchars($icon, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
}


$schemaFaq = [];
foreach (($c['faq']['items'] ?? []) as $item) {
    $schemaFaq[] = [
        '@type' => 'Question',
        'name' => $item['q'] ?? '',
        'acceptedAnswer' => [
            '@type' => 'Answer',
            'text' => $item['a'] ?? '',
        ],
    ];
}

$schemaOffers = [];
foreach (($c['prices']['groups'] ?? []) as $group) {
    foreach (($group['items'] ?? []) as $offer) {
        $schemaOffers[] = [
            '@type' => 'Offer',
            'name' => $offer['name'] ?? '',
            'description' => $offer['desc'] ?? '',
            'priceCurrency' => 'RUB',
            'availability' => 'https://schema.org/InStock',
            'url' => $siteUrl . '/#prices',
        ];
    }
}

$schema = [
    '@context' => 'https://schema.org',
    '@graph' => [
        [
            '@type' => ['LocalBusiness', 'TouristAttraction'],
            '@id' => $siteUrl . '/#business',
            'name' => 'Центр активного отдыха «Власьево»',
            'description' => $description !== '' ? $description : 'Рыбалка на реке Яуза у слияния с Вазузским водохранилищем, активный отдых в деревне Власьево.',
            'image' => [
                $siteUrl . '/assets/img/og-cover.png',
                $siteUrl . '/assets/img/logo-social.png',
            ],
            'url' => $siteUrl . '/',
            'telephone' => array_values(array_filter([$phoneTel, $phone2Tel])),
            'email' => $c['email'] ?? '',
            'priceRange' => '₽₽',
            'address' => [
                '@type' => 'PostalAddress',
                'streetAddress' => 'деревня Власьево, 32',
                'addressLocality' => 'Гагаринский район',
                'addressRegion' => 'Смоленская область',
                'addressCountry' => 'RU',
            ],
            'areaServed' => [
                [
                    '@type' => 'Place',
                    'name' => 'Река Яуза у слияния с Вазузским водохранилищем',
                ],
                [
                    '@type' => 'AdministrativeArea',
                    'name' => 'Гагаринский район, Смоленская область',
                ],
            ],
            'geo' => [
                '@type' => 'GeoCoordinates',
                'latitude' => (float) $mapLat,
                'longitude' => (float) $mapLon,
            ],
            'openingHoursSpecification' => [
                '@type' => 'OpeningHoursSpecification',
                'dayOfWeek' => ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'],
                'opens' => '08:00',
                'closes' => '20:00',
            ],
            'sameAs' => array_values(array_filter([$vk, $telegram, $maxUrl, $mapShare])),
            'aggregateRating' => !empty($reviews['rating']) ? [
                '@type' => 'AggregateRating',
                'ratingValue' => (string) $reviews['rating'],
                'reviewCount' => (string) ($reviews['reviews_count'] ?? count($reviews['items'] ?? [])),
                'bestRating' => '5',
                'worstRating' => '1',
            ] : null,
            'makesOffer' => $schemaOffers,
        ],
        [
            '@type' => 'WebSite',
            '@id' => $siteUrl . '/#website',
            'url' => $siteUrl . '/',
            'name' => 'Власьево',
            'publisher' => ['@id' => $siteUrl . '/#business'],
            'inLanguage' => 'ru-RU',
        ],
        [
            '@type' => 'FAQPage',
            '@id' => $siteUrl . '/#faq',
            'mainEntity' => $schemaFaq,
        ],
    ],
];

// remove nulls
array_walk_recursive($schema, static function (&$v) {
    // no-op placeholder
});
$schema['@graph'][0] = array_filter($schema['@graph'][0], static fn($v) => $v !== null);
?>
<!DOCTYPE html>
<html lang="ru">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title><?= e($title) ?></title>
  <meta name="description" content="<?= e($description) ?>">
  <link rel="canonical" href="<?= e($siteUrl) ?>/">
  <meta property="og:locale" content="ru_RU">
  <meta property="og:type" content="website">
  <meta property="og:site_name" content="Власьево">
  <meta property="og:url" content="<?= e($siteUrl) ?>/">
  <meta property="og:title" content="<?= e($title) ?>">
  <meta property="og:description" content="<?= e($description) ?>">
  <meta property="og:image" content="<?= e($siteUrl) ?>/assets/img/og-cover.png">
  <meta property="og:image:secure_url" content="<?= e($siteUrl) ?>/assets/img/og-cover.png">
  <meta property="og:image:type" content="image/png">
  <meta property="og:image:width" content="1200">
  <meta property="og:image:height" content="630">
  <meta property="og:image:alt" content="Центр активного отдыха «Власьево» — рыбалка на реке Яуза">
  <meta name="twitter:card" content="summary_large_image">
  <meta name="twitter:title" content="<?= e($title) ?>">
  <meta name="twitter:description" content="<?= e($description) ?>">
  <meta name="twitter:image" content="<?= e($siteUrl) ?>/assets/img/og-cover.png">
  <meta name="twitter:image:alt" content="Центр активного отдыха «Власьево»">
  <link rel="icon" href="assets/img/favicon.svg?v=3" type="image/svg+xml">
  <link rel="icon" href="assets/img/favicon.ico?v=3" sizes="any">
  <link rel="icon" href="assets/img/favicon-32.png?v=3" type="image/png" sizes="32x32">
  <link rel="icon" href="assets/img/favicon-16.png?v=3" type="image/png" sizes="16x16">
  <link rel="apple-touch-icon" href="assets/img/apple-touch-icon.png?v=3" sizes="180x180">
  <link rel="manifest" href="site.webmanifest?v=3">
  <meta name="theme-color" content="#0f241c">
  <link rel="preload" as="image" href="assets/img/hero.webp" type="image/webp" fetchpriority="high">
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link href="https://fonts.googleapis.com/css2?family=Cormorant+Garamond:wght@600;700&family=Manrope:wght@400;500;600;700&display=swap&subset=cyrillic,latin" rel="stylesheet">
  <link rel="stylesheet" href="assets/css/style.css?v=<?= filemtime(__DIR__ . '/assets/css/style.css') ?>">
  <script type="application/ld+json"><?= json_encode($schema, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?></script>
  <!-- Yandex.Metrika counter -->
  <script type="text/javascript">
    (function(m,e,t,r,i,k,a){
        m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)};
        m[i].l=1*new Date();
        for (var j = 0; j < document.scripts.length; j++) {if (document.scripts[j].src === r) { return; }}
        k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)
    })(window, document,'script','https://mc.yandex.ru/metrika/tag.js', 'ym');
    ym(94572893, 'init', {webvisor:true, clickmap:true, referrer: document.referrer, url: location.href, accurateTrackBounce:true, trackLinks:true});
  </script>
  <!-- /Yandex.Metrika counter -->
</head>
<body>
  <noscript><div><img src="https://mc.yandex.ru/watch/94572893" style="position:absolute; left:-9999px;" alt=""></div></noscript>
  <a class="skip-link" href="#top">К содержанию</a>

  <header class="site-header">
    <div class="container header-inner">
      <a class="brand" href="#top"><?= e($brand) ?></a>
      <button class="nav-toggle" type="button" aria-label="Меню" aria-expanded="false" aria-controls="site-nav">
        <span class="nav-toggle-bars" aria-hidden="true"></span>
      </button>
      <nav class="nav" id="site-nav" aria-label="Основная навигация">
        <div class="nav-panel">
          <a href="#services">Услуги</a>
          <a href="#videos">Видео</a>
          <a href="#gallery">Фото</a>
          <a href="#prices">Цены</a>
          <a href="#reviews">Отзывы</a>
          <a href="#faq">FAQ</a>
          <a href="#contacts">Контакты</a>
          <a class="header-phone nav-phone" href="tel:<?= e($phoneTel) ?>"><?= e($phone) ?></a>
          <div class="header-socials nav-socials">
            <a class="soc-btn" href="<?= e($telegram) ?>" target="_blank" rel="noopener" aria-label="Telegram" title="Telegram"><?= icon_svg('telegram') ?></a>
            <?php if ($maxUrl): ?>
              <a class="soc-btn" href="<?= e($maxUrl) ?>" target="_blank" rel="noopener" aria-label="MAX" title="MAX"><?= icon_svg('max') ?></a>
            <?php endif; ?>
            <?php if ($vk): ?>
              <a class="soc-btn" href="<?= e($vk) ?>" target="_blank" rel="noopener" aria-label="ВКонтакте" title="ВКонтакте"><?= icon_svg('vk') ?></a>
            <?php endif; ?>
          </div>
        </div>
      </nav>
    </div>
  </header>
  <div class="nav-backdrop" hidden></div>

  <main id="top">
    <section class="hero" aria-label="Главный экран">
      <div class="hero-media">
        <picture>
          <source srcset="assets/img/hero.webp" type="image/webp">
          <img src="assets/img/hero.jpg" alt="Туман над рекой Яуза во Власьево, Гагаринский район" width="1680" height="945" fetchpriority="high">
        </picture>
        <div class="hero-overlay" aria-hidden="true"></div>
      </div>
      <div class="hero-content">
        <p class="hero-brand"><?= e($brand) ?></p>
        <h1><?= e($c['hero']['title'] ?? $title) ?></h1>
        <p class="hero-lead"><?= e($c['hero']['lead'] ?? '') ?></p>
        <p class="hero-text"><?= e($c['hero']['text'] ?? '') ?></p>
        <div class="hero-actions">
          <a class="btn btn-primary" href="tel:<?= e($phoneTel) ?>">Позвонить</a>
          <?php if ($maxUrl): ?>
            <a class="btn btn-ghost btn-with-icon" href="<?= e($maxUrl) ?>" target="_blank" rel="noopener"><?= icon_svg('max') ?> MAX</a>
          <?php endif; ?>
          <a class="btn btn-ghost btn-with-icon" href="<?= e($telegram) ?>" target="_blank" rel="noopener"><?= icon_svg('telegram') ?> Telegram</a>
        </div>
      </div>
    </section>

    <?php if (!empty($c['notice'])): ?>
    <aside class="notice-bar" role="note">
      <div class="container notice-inner">
        <div class="notice-icon" aria-hidden="true">!</div>
        <div>
          <h2><?= e($c['notice']['title'] ?? '') ?></h2>
          <p><?= e($c['notice']['text'] ?? '') ?></p>
        </div>
      </div>
    </aside>
    <?php endif; ?>

    <?php if (!empty($reviews['rating'])):
      $ratingVal = (float) $reviews['rating'];
      $ratingFilled = (int) round($ratingVal);
      $ratingFilled = max(1, min(5, $ratingFilled));
    ?>
    <section class="rating-strip" aria-label="Рейтинг <?= e(number_format($ratingVal, 1, '.', '')) ?> из 5 на Яндекс.Картах, <?= (int) ($reviews['ratings_count'] ?? 0) ?> оценок, <?= (int) ($reviews['reviews_count'] ?? 0) ?> отзывов">
      <div class="container rating-strip-inner">
        <div class="rating-cluster">
          <div class="rating-score-block">
            <strong class="rating-num"><?= e(number_format($ratingVal, 1, '.', '')) ?></strong>
            <div class="rating-stars" aria-hidden="true"><?= str_repeat('★', $ratingFilled) . str_repeat('☆', 5 - $ratingFilled) ?></div>
          </div>
          <div class="rating-copy">
            <span class="rating-meta">из 5 на Яндекс.Картах</span>
            <span class="rating-meta rating-counts"><?= (int) ($reviews['ratings_count'] ?? 0) ?> оценок · <?= (int) ($reviews['reviews_count'] ?? 0) ?> отзывов</span>
          </div>
        </div>
        <a class="btn btn-outline-light rating-strip-btn" href="<?= e($reviews['source_url'] ?? $mapShare) ?>" target="_blank" rel="noopener">Все отзывы на карте</a>
      </div>
    </section>
    <?php endif; ?>

    <?php if (!empty($c['benefits'])): ?>
    <section class="benefits" aria-label="Преимущества">
      <div class="container benefits-grid">
        <?php foreach ($c['benefits'] as $i => $b): ?>
          <article class="benefit reveal">
            <span class="benefit-num"><?= str_pad((string) ($i + 1), 2, '0', STR_PAD_LEFT) ?></span>
            <h3><?= e($b['title'] ?? '') ?></h3>
            <p><?= e($b['text'] ?? '') ?></p>
          </article>
        <?php endforeach; ?>
      </div>
    </section>
    <?php endif; ?>

    <section class="section about" id="about">
      <div class="container about-grid">
        <div class="reveal">
          <div class="section-head">
            <span class="section-kicker">О нас</span>
            <h2><?= e($c['about']['title'] ?? '') ?></h2>
            <p><?= e($c['about']['text'] ?? '') ?></p>
          </div>
          <div class="contact-actions">
            <a class="btn btn-dark" href="tel:<?= e($phoneTel) ?>">Обсудить выезд</a>
            <?php if ($maxUrl): ?>
              <a class="btn btn-outline btn-with-icon" href="<?= e($maxUrl) ?>" target="_blank" rel="noopener"><?= icon_svg('max') ?> MAX</a>
            <?php endif; ?>
            <a class="btn btn-outline btn-with-icon" href="<?= e($telegram) ?>" target="_blank" rel="noopener"><?= icon_svg('telegram') ?> Telegram</a>
          </div>
        </div>
        <a class="about-visual reveal vlasevo-zoomable" href="assets/img/g1.jpg">
          <picture>
            <source srcset="assets/img/g1.webp" type="image/webp">
            <img src="assets/img/g1.jpg" alt="Лес и водоёмы Гагаринского района" width="840" height="560" loading="lazy">
          </picture>
          <span class="zoom-chip" aria-hidden="true">Открыть</span>
        </a>
      </div>
    </section>

    <?php if (!empty($c['steps'])): ?>
    <section class="section steps" id="how">
      <div class="container">
        <div class="section-head reveal">
          <span class="section-kicker">Схема</span>
          <h2><?= e($c['steps']['title'] ?? '') ?></h2>
          <p><?= e($c['steps']['text'] ?? '') ?></p>
        </div>
        <div class="steps-grid">
          <?php foreach (($c['steps']['items'] ?? []) as $step): ?>
            <article class="step reveal">
              <span class="step-num"><?= e($step['num'] ?? '') ?></span>
              <h3><?= e($step['title'] ?? '') ?></h3>
              <p><?= e($step['text'] ?? '') ?></p>
            </article>
          <?php endforeach; ?>
        </div>
      </div>
    </section>
    <?php endif; ?>

    <section class="section services" id="services">
      <div class="container">
        <div class="section-head reveal">
          <span class="section-kicker">Услуги</span>
          <h2><?= e($c['services_intro']['title'] ?? '') ?></h2>
          <p><?= e($c['services_intro']['text'] ?? '') ?></p>
        </div>
        <div class="service-panels">
          <?php foreach (($c['services'] ?? []) as $i => $service): ?>
            <?php
              $img = $service['image_fallback'] ?? preg_replace('/\.webp$/i', '.jpg', $service['image'] ?? '');
              $webp = $service['image'] ?? '';
            ?>
            <article class="service-panel reveal<?= $i % 2 === 1 ? ' is-reverse' : '' ?><?= !empty($service['photos']) ? ' has-photos' : '' ?>" id="<?= e($service['id'] ?? '') ?>">
              <div class="service-media">
                <a class="service-visual vlasevo-zoomable" href="<?= e($img) ?>">
                  <picture>
                    <source srcset="<?= e($webp) ?>" type="image/webp">
                    <img src="<?= e($img) ?>" alt="<?= e($service['title'] ?? '') ?>" loading="lazy" width="900" height="700">
                  </picture>
                  <span class="zoom-chip" aria-hidden="true">Смотреть</span>
                </a>
                <?php if (!empty($service['photos'])): ?>
                  <?php
                    $servicePhotos = array_values($service['photos']);
                    $servicePhotoTotal = count($servicePhotos);
                    $servicePhotoPreview = 6;
                    $servicePhotoExtra = max(0, $servicePhotoTotal - $servicePhotoPreview);
                  ?>
                  <div class="service-photos<?= $servicePhotoExtra > 0 ? ' is-collapsed' : '' ?>"<?= $servicePhotoExtra > 0 ? ' data-collapsed="1"' : '' ?>>
                    <?php foreach ($servicePhotos as $pi => $photo): ?>
                      <?php
                        $pFall = $photo['fallback'] ?? preg_replace('/\.webp$/i', '.jpg', $photo['src'] ?? '');
                        $pWebp = $photo['src'] ?? '';
                      ?>
                      <a class="service-photo vlasevo-zoomable<?= $pi >= $servicePhotoPreview ? ' is-more' : '' ?>" href="<?= e($pFall) ?>" title="<?= e($photo['alt'] ?? '') ?>">
                        <picture>
                          <source srcset="<?= e($pWebp) ?>" type="image/webp">
                          <img src="<?= e($pFall) ?>" alt="<?= e($photo['alt'] ?? '') ?>" loading="lazy" width="220" height="160">
                        </picture>
                      </a>
                    <?php endforeach; ?>
                    <?php if ($servicePhotoExtra > 0): ?>
                      <button type="button" class="service-photos-more" data-photos-more>
                        Ещё <?= (int) $servicePhotoExtra ?> фото
                      </button>
                    <?php endif; ?>
                  </div>
                <?php endif; ?>
              </div>
              <div class="service-body">
                <span class="service-eyebrow"><?= e($service['eyebrow'] ?? '') ?> <?= service_icon_html((string) ($service['icon'] ?? '')) ?></span>
                <h3><?= e($service['title'] ?? '') ?></h3>
                <p><?= e($service['text'] ?? '') ?></p>
                <ul class="service-meta">
                  <?php if (!empty($service['for_whom'])): ?><li><strong>Для кого:</strong> <?= e($service['for_whom']) ?></li><?php endif; ?>
                  <?php if (!empty($service['season'])): ?><li><strong>Сезон:</strong> <?= e($service['season']) ?></li><?php endif; ?>
                  <?php if (!empty($service['duration'])): ?><li><strong>Длительность:</strong> <?= e($service['duration']) ?></li><?php endif; ?>
                </ul>
                <?php if (!empty($service['points'])): ?>
                  <ul>
                    <?php foreach ($service['points'] as $point): ?>
                      <li><?= e($point) ?></li>
                    <?php endforeach; ?>
                  </ul>
                <?php endif; ?>
                <div class="service-actions">
                  <a class="btn btn-primary" href="tel:<?= e($phoneTel) ?>"><?= e($service['cta'] ?? 'Позвонить') ?></a>
                  <?php if ($maxUrl): ?>
                    <a class="btn btn-ghost btn-with-icon" href="<?= e($maxUrl) ?>" target="_blank" rel="noopener"><?= icon_svg('max') ?> MAX</a>
                  <?php endif; ?>
                  <a class="btn btn-ghost btn-with-icon" href="<?= e($telegram) ?>" target="_blank" rel="noopener"><?= icon_svg('telegram') ?> Telegram</a>
                  <?php if (($service['id'] ?? '') === 'karakat' && !empty($c['videos']['items'])): ?>
                    <a class="btn btn-ghost" href="#videos">Смотреть видео</a>
                  <?php endif; ?>
                </div>
              </div>
            </article>
          <?php endforeach; ?>
        </div>
        <?php if (!empty($c['videos']['items'])): ?>
          <p class="services-to-videos reveal">
            <a href="#videos">Видео с выездов →</a>
          </p>
        <?php endif; ?>
      </div>
    </section>

    <?php if (!empty($c['videos']['items'])): ?>
    <section class="section videos" id="videos">
      <div class="container">
        <div class="section-head reveal">
          <span class="section-kicker">Видео</span>
          <h2><?= e($c['videos']['title'] ?? 'Видео') ?></h2>
          <p><?= e($c['videos']['text'] ?? '') ?></p>
        </div>
        <div class="videos-grid">
          <?php foreach ($c['videos']['items'] as $video):
            $vSrc = $video['src'] ?? '';
            $vEmbed = $video['embed'] ?? '';
            $vShare = $video['share'] ?? '';
          ?>
            <article
              class="video-card reveal"
              <?php if ($vSrc): ?>data-video-src="<?= e($vSrc) ?>"<?php endif; ?>
              <?php if ($vEmbed): ?>data-video-embed="<?= e($vEmbed) ?>"<?php endif; ?>
              <?php if ($vShare): ?>data-video-share="<?= e($vShare) ?>"<?php endif; ?>
            >
              <div class="video-frame">
                <button type="button" class="video-poster" aria-label="Смотреть: <?= e($video['title'] ?? '') ?>">
                  <picture>
                    <source srcset="<?= e($video['poster'] ?? '') ?>" type="image/webp">
                    <img src="<?= e($video['poster_fallback'] ?? $video['poster'] ?? '') ?>" alt="<?= e($video['title'] ?? '') ?>" loading="lazy" width="800" height="450">
                  </picture>
                  <span class="video-play" aria-hidden="true">▶</span>
                </button>
              </div>
              <div class="video-body">
                <h3><?= e($video['title'] ?? '') ?></h3>
                <p><?= e($video['desc'] ?? '') ?></p>
                <?php if ($vShare): ?>
                  <a href="<?= e($vShare) ?>" target="_blank" rel="noopener">Открыть на Яндекс.Картах</a>
                <?php endif; ?>
              </div>
            </article>
          <?php endforeach; ?>
        </div>
      </div>
    </section>
    <?php endif; ?>

    <?php if (!empty($c['prices'])): ?>
    <section class="section prices" id="prices">
      <div class="container">
        <div class="section-head reveal">
          <span class="section-kicker">Прайс</span>
          <h2><?= e($c['prices']['title'] ?? '') ?></h2>
          <p><?= e($c['prices']['text'] ?? '') ?></p>
        </div>
        <?php if (!empty($c['prices']['note'])): ?>
          <p class="price-note reveal"><?= e($c['prices']['note']) ?></p>
        <?php endif; ?>
        <?php foreach (($c['prices']['groups'] ?? []) as $group): ?>
          <div class="price-group reveal">
            <h3><?= e($group['title'] ?? '') ?></h3>
            <div class="price-list">
              <?php foreach (($group['items'] ?? []) as $item): ?>
                <article class="price-item<?= !empty($item['negotiable']) ? ' is-negotiable' : '' ?>">
                  <div class="price-item-top">
                    <h4><?= e($item['name'] ?? '') ?></h4>
                    <div class="price-value"><?= e($item['price'] ?? '') ?></div>
                  </div>
                  <p><?= e($item['desc'] ?? '') ?></p>
                  <ul class="service-meta">
                    <?php if (!empty($item['for_whom'])): ?><li><strong>Для кого:</strong> <?= e($item['for_whom']) ?></li><?php endif; ?>
                    <?php if (!empty($item['season'])): ?><li><strong>Сезон:</strong> <?= e($item['season']) ?></li><?php endif; ?>
                    <?php if (!empty($item['duration'])): ?><li><strong>Длительность:</strong> <?= e($item['duration']) ?></li><?php endif; ?>
                  </ul>
                </article>
              <?php endforeach; ?>
            </div>
          </div>
        <?php endforeach; ?>
        <div class="contact-actions reveal" style="margin-top:2rem">
          <a class="btn btn-dark" href="tel:<?= e($phoneTel) ?>">Уточнить и забронировать</a>
          <?php if ($maxUrl): ?>
            <a class="btn btn-outline btn-with-icon" href="<?= e($maxUrl) ?>" target="_blank" rel="noopener"><?= icon_svg('max') ?> Написать в MAX</a>
          <?php endif; ?>
          <a class="btn btn-outline btn-with-icon" href="<?= e($telegram) ?>" target="_blank" rel="noopener"><?= icon_svg('telegram') ?> Telegram</a>
        </div>
      </div>
    </section>
    <?php endif; ?>

    <?php if (!empty($c['cta_band'])): ?>
    <section class="cta-band">
      <div class="container cta-band-inner reveal">
        <div class="cta-band-copy">
          <h2><?= e($c['cta_band']['title'] ?? '') ?></h2>
          <p><?= e($c['cta_band']['text'] ?? '') ?></p>
        </div>
        <div class="cta-band-actions contact-actions">
          <?php if ($maxUrl): ?>
            <a class="btn btn-primary btn-with-icon" href="<?= e($maxUrl) ?>" target="_blank" rel="noopener"><?= icon_svg('max') ?> Написать в MAX</a>
          <?php endif; ?>
          <a class="btn btn-ghost btn-with-icon" href="<?= e($telegram) ?>" target="_blank" rel="noopener"><?= icon_svg('telegram') ?> Telegram</a>
          <a class="btn btn-ghost" href="tel:<?= e($phoneTel) ?>">Позвонить</a>
        </div>
      </div>
    </section>
    <?php endif; ?>

    <?php if (!empty($reviews['items'])): ?>
    <section class="section reviews" id="reviews">
      <div class="container">
        <div class="section-head reveal">
          <span class="section-kicker">Отзывы</span>
          <h2>Что пишут гости</h2>
          <p>Положительные отзывы с Яндекс.Карт. Обновляются автоматически со страницы организации.</p>
        </div>
        <div class="reviews-grid">
          <?php foreach (array_slice($reviews['items'], 0, 6) as $rev): ?>
            <blockquote class="review-card reveal">
              <div class="review-stars" aria-label="Оценка <?= (int) ($rev['rating'] ?? 5) ?> из 5">
                <?= str_repeat('★', max(1, min(5, (int) ($rev['rating'] ?? 5)))) ?>
              </div>
              <p><?= e($rev['text'] ?? '') ?></p>
              <cite><?= e($rev['author'] ?? 'Гость') ?></cite>
            </blockquote>
          <?php endforeach; ?>
        </div>
        <p class="reveal" style="margin-top:1.5rem">
          <a class="btn btn-outline" href="<?= e($reviews['source_url'] ?? $mapShare) ?>" target="_blank" rel="noopener">Читать все на Яндекс.Картах</a>
        </p>
      </div>
    </section>
    <?php endif; ?>

    <?php if (!empty($c['gallery'])): ?>
    <section class="section gallery-section" id="gallery">
      <div class="container">
        <div class="section-head reveal">
          <span class="section-kicker">Галерея</span>
          <h2><?= e($c['gallery_intro']['title'] ?? 'Галерея') ?></h2>
          <p><?= e($c['gallery_intro']['text'] ?? '') ?></p>
        </div>
        <?php
          $galleryItems = array_values($c['gallery']);
          $galleryTotal = count($galleryItems);
          $galleryPreview = 16;
          $galleryExtra = max(0, $galleryTotal - $galleryPreview);
        ?>
        <div class="gallery-grid<?= $galleryExtra > 0 ? ' is-collapsed' : '' ?>"<?= $galleryExtra > 0 ? ' data-collapsed="1"' : '' ?>>
          <?php foreach ($galleryItems as $gi => $item): ?>
            <a class="gallery-item reveal vlasevo-zoomable<?= $gi >= $galleryPreview ? ' is-more' : '' ?>" href="<?= e($item['fallback'] ?? $item['src'] ?? '') ?>">
              <picture>
                <source srcset="<?= e($item['src'] ?? '') ?>" type="image/webp">
                <img src="<?= e($item['fallback'] ?? $item['src'] ?? '') ?>" alt="<?= e($item['alt'] ?? '') ?>" loading="lazy" width="800" height="600">
              </picture>
              <span class="vlasevo-zoom-hint" aria-hidden="true">
                <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="18" height="18"><circle cx="11" cy="11" r="7"></circle><path d="M21 21l-4.3-4.3"></path><path d="M11 8v6M8 11h6"></path></svg>
              </span>
            </a>
          <?php endforeach; ?>
        </div>
        <?php if ($galleryExtra > 0): ?>
          <div class="gallery-more-wrap reveal">
            <button type="button" class="btn btn-outline" data-gallery-more>
              Показать все фото · <?= (int) $galleryTotal ?>
            </button>
          </div>
        <?php endif; ?>
      </div>
    </section>
    <?php endif; ?>

    <?php if (!empty($c['faq'])): ?>
    <section class="section faq" id="faq">
      <div class="container">
        <div class="section-head reveal">
          <span class="section-kicker">FAQ</span>
          <h2><?= e($c['faq']['title'] ?? '') ?></h2>
          <p><?= e($c['faq']['text'] ?? '') ?></p>
        </div>
        <div class="faq-layout">
          <div class="faq-list reveal">
            <?php foreach (($c['faq']['items'] ?? []) as $i => $item): ?>
              <details class="faq-item" <?= $i === 0 ? 'open' : '' ?>>
                <summary><?= e($item['q'] ?? '') ?></summary>
                <p><?= e($item['a'] ?? '') ?></p>
              </details>
            <?php endforeach; ?>
          </div>
          <aside class="faq-aside reveal">
            <div class="faq-aside-card">
              <p class="faq-aside-kicker">Не нашли ответ?</p>
              <h3>Напишите или позвоните</h3>
              <p>Подскажем маршрут, состав снаряжения и свободные окна на выходные.</p>
              <ul class="faq-aside-contacts">
                <li><a href="tel:<?= e($phoneTel) ?>"><?= e($phone) ?></a><span>основной</span></li>
                <?php if ($phone2): ?>
                  <li><a href="tel:<?= e($phone2Tel) ?>"><?= e($phone2) ?></a><span>резервный</span></li>
                <?php endif; ?>
              </ul>
              <div class="contact-actions">
                <?php if ($maxUrl): ?>
                  <a class="btn btn-primary btn-with-icon" href="<?= e($maxUrl) ?>" target="_blank" rel="noopener"><?= icon_svg('max') ?> MAX</a>
                <?php endif; ?>
                <a class="btn btn-outline-light btn-with-icon" href="<?= e($telegram) ?>" target="_blank" rel="noopener"><?= icon_svg('telegram') ?> Telegram</a>
              </div>
            </div>
          </aside>
        </div>
      </div>
    </section>
    <?php endif; ?>

    <section class="section terms" id="terms">
      <div class="container">
        <div class="section-head reveal">
          <span class="section-kicker">Условия</span>
          <h2><?= e($c['terms']['title'] ?? '') ?></h2>
          <p><?= e($c['terms']['intro'] ?? '') ?></p>
        </div>
        <div class="terms-grid">
          <?php foreach (($c['terms']['items'] ?? []) as $term): ?>
            <?php
              $isAlert = !empty($term['alert']) || (
                isset($term['title']) && (
                  mb_stripos($term['title'], 'проживан') !== false
                  || mb_stripos($term['title'], 'не сдаются') !== false
                  || mb_stripos($term['title'], 'Отсутствие') !== false
                )
              );
            ?>
            <article class="term-card reveal<?= $isAlert ? ' is-alert' : '' ?>">
              <span class="term-card-icon" aria-hidden="true"><?= e($term['icon'] ?? '•') ?></span>
              <div>
                <h3><?= e($term['title'] ?? '') ?></h3>
                <p><?= e($term['text'] ?? '') ?></p>
              </div>
            </article>
          <?php endforeach; ?>
        </div>
      </div>
    </section>

    <section class="section contacts" id="contacts">
      <div class="container contacts-grid">
        <div class="reveal">
          <div class="section-head">
            <span class="section-kicker">Контакты</span>
            <h2><?= e($c['contacts']['title'] ?? '') ?></h2>
            <p><?= e($c['contacts']['text'] ?? '') ?></p>
          </div>
          <ul class="contact-list">
            <li>
              <span>Телефон основной</span>
              <a href="tel:<?= e($phoneTel) ?>"><?= e($phone) ?></a>
            </li>
            <?php if ($phone2): ?>
            <li>
              <span>Телефон резервный</span>
              <a href="tel:<?= e($phone2Tel) ?>"><?= e($phone2) ?></a>
            </li>
            <?php endif; ?>
            <li>
              <span>Telegram</span>
              <a href="<?= e($telegram) ?>" target="_blank" rel="noopener"><?= e($c['telegram_handle'] ?? '@lisinwi') ?></a>
            </li>
            <?php if ($maxUrl): ?>
            <li>
              <span>MAX</span>
              <a href="<?= e($maxUrl) ?>" target="_blank" rel="noopener"><?= e($c['max_note'] ?? 'Написать в MAX') ?></a>
            </li>
            <?php endif; ?>
            <?php if ($vk): ?>
            <li>
              <span>ВКонтакте</span>
              <a href="<?= e($vk) ?>" target="_blank" rel="noopener">vk.com/vlasevo_ru</a>
            </li>
            <?php endif; ?>
            <li>
              <span>Email</span>
              <a href="mailto:<?= e($c['email'] ?? '') ?>"><?= e($c['email'] ?? '') ?></a>
            </li>
            <li>
              <span>Точка выдачи</span>
              <a href="<?= e($mapShare) ?>" target="_blank" rel="noopener"><?= e($c['address'] ?? '') ?></a>
            </li>
          </ul>
          <div class="contact-actions">
            <a class="btn btn-dark" href="tel:<?= e($phoneTel) ?>">Позвонить</a>
            <?php if ($maxUrl): ?>
              <a class="btn btn-outline btn-with-icon" href="<?= e($maxUrl) ?>" target="_blank" rel="noopener"><?= icon_svg('max') ?> MAX</a>
            <?php endif; ?>
            <a class="btn btn-outline btn-with-icon" href="<?= e($telegram) ?>" target="_blank" rel="noopener"><?= icon_svg('telegram') ?> Telegram</a>
            <a class="btn btn-outline" href="<?= e($mapShare) ?>" target="_blank" rel="noopener">Карта</a>
          </div>
        </div>
        <div class="map-frame reveal">
          <iframe
            title="Карта — Центр активного отдыха Власьево"
            loading="lazy"
            referrerpolicy="no-referrer-when-downgrade"
            src="<?= e($mapWidget) ?>"
            allowfullscreen></iframe>
        </div>
      </div>
    </section>
  </main>

  <footer class="site-footer">
    <div class="container footer-inner">
      <p><?= e($c['footer'] ?? '') ?></p>
      <p>
        <a href="tel:<?= e($phoneTel) ?>"><?= e($phone) ?></a>
        <?php if ($phone2): ?> · <a href="tel:<?= e($phone2Tel) ?>"><?= e($phone2) ?></a><?php endif; ?>
        · <a href="<?= e($telegram) ?>" target="_blank" rel="noopener">Telegram</a>
        <?php if ($maxUrl): ?> · <a href="<?= e($maxUrl) ?>" target="_blank" rel="noopener">MAX</a><?php endif; ?>
      </p>
    </div>
  </footer>

  <div class="mobile-dock" aria-label="Быстрая связь">
    <a href="tel:<?= e($phoneTel) ?>">Звонок</a>
    <a href="<?= e($telegram) ?>" target="_blank" rel="noopener">Telegram</a>
    <?php if ($maxUrl): ?>
      <a href="<?= e($maxUrl) ?>" target="_blank" rel="noopener">MAX</a>
    <?php else: ?>
      <a href="#prices">Цены</a>
    <?php endif; ?>
  </div>

  <script src="assets/js/vlasevo-lightbox.js?v=<?= filemtime(__DIR__ . '/assets/js/vlasevo-lightbox.js') ?>" defer></script>
  <script src="assets/js/main.js?v=<?= filemtime(__DIR__ . '/assets/js/main.js') ?>" defer></script>
</body>
</html>
