<?php
declare(strict_types=1);

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

if (function_exists('header_remove')) {
    header_remove('X-Powered-By');
}
@ini_set('expose_php', '0');

$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'] ?? '';

// Ключевые фото для Schema.org (OG + услуги + галерея)
$schemaImages = [
    $siteUrl . '/assets/img/og-cover.jpg',
    $siteUrl . '/assets/img/hero.jpg',
    $siteUrl . '/assets/img/logo-social.png',
];
foreach ($c['services'] ?? [] as $svc) {
    $imgPath = $svc['image_fallback'] ?? preg_replace('/\.webp$/i', '.jpg', (string) ($svc['image'] ?? ''));
    if (is_string($imgPath) && $imgPath !== '') {
        $schemaImages[] = $siteUrl . '/' . ltrim($imgPath, '/');
    }
}
foreach (array_slice($c['gallery'] ?? [], 0, 12) as $gItem) {
    $imgPath = $gItem['fallback'] ?? preg_replace('/\.webp$/i', '.jpg', (string) ($gItem['src'] ?? ''));
    if (is_string($imgPath) && $imgPath !== '') {
        $schemaImages[] = $siteUrl . '/' . ltrim($imgPath, '/');
    }
}
$schemaImages = array_values(array_unique($schemaImages));

require_once __DIR__ . '/lib/schema.php';

$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',
        ];
    }
}

// Офферы услуг → посадочные
foreach ($c['services'] ?? [] as $svc) {
    $path = service_public_path($svc);
    if ($path === '/#services') {
        continue;
    }
    $schemaOffers[] = [
        '@type' => 'Offer',
        'name' => $svc['title'] ?? '',
        'description' => $svc['text'] ?? '',
        'priceCurrency' => 'RUB',
        'availability' => 'https://schema.org/InStock',
        'url' => $siteUrl . $path,
    ];
}

$businessNode = [
    '@type' => ['LocalBusiness', 'TouristAttraction'],
    '@id' => $siteUrl . '/#business',
    'name' => 'Центр активного отдыха «Власьево»',
    'description' => $description !== '' ? $description : 'Рыбалка на реке Яуза у слияния с Вазузским водохранилищем, активный отдых в деревне Власьево.',
    'image' => $schemaImages,
    '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])),
    'makesOffer' => $schemaOffers,
];
if (!empty($reviews['rating'])) {
    $businessNode['aggregateRating'] = [
        '@type' => 'AggregateRating',
        'ratingValue' => (string) $reviews['rating'],
        'reviewCount' => (string) ($reviews['reviews_count'] ?? count($reviews['items'] ?? [])),
        'bestRating' => '5',
        'worstRating' => '1',
    ];
    $reviewNodes = schema_review_nodes($reviews, $siteUrl);
    if ($reviewNodes) {
        $businessNode['review'] = array_map(
            static fn(array $n): array => ['@id' => $n['@id']],
            $reviewNodes
        );
    }
}

$schemaGraph = [
    $businessNode,
    [
        '@type' => 'WebSite',
        '@id' => $siteUrl . '/#website',
        'url' => $siteUrl . '/',
        'name' => 'Власьево',
        'publisher' => ['@id' => $siteUrl . '/#business'],
        'inLanguage' => 'ru-RU',
    ],
];
if ($schemaFaq) {
    $schemaGraph[] = [
        '@type' => 'FAQPage',
        '@id' => $siteUrl . '/#faq',
        'mainEntity' => $schemaFaq,
    ];
}
foreach (schema_review_nodes($reviews, $siteUrl) as $revNode) {
    $schemaGraph[] = $revNode;
}
foreach (schema_video_nodes($c, $siteUrl) as $vidNode) {
    $schemaGraph[] = $vidNode;
}

$schema = [
    '@context' => 'https://schema.org',
    '@graph' => $schemaGraph,
];

// remove nulls
$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.jpg">
  <meta property="og:image:secure_url" content="<?= e($siteUrl) ?>/assets/img/og-cover.jpg">
  <meta property="og:image:type" content="image/jpeg">
  <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.jpg">
  <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="preload" href="assets/fonts/manrope-400-cyrillic.woff2" as="font" type="font/woff2" crossorigin>
  <link rel="preload" href="assets/fonts/cormorant-garamond-700-cyrillic.woff2" as="font" type="font/woff2" crossorigin>
  <link rel="stylesheet" href="assets/css/fonts.css?v=<?= filemtime(__DIR__ . '/assets/css/fonts.css') ?>">
  <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="<?= e($siteUrl) ?>/"><?= e($brand) ?></a>
      <?php
        require_once __DIR__ . '/lib/nav.php';
        render_site_nav([
          'site_url' => $siteUrl,
          'phone' => $phone,
          'phone_tel' => $phoneTel,
          'telegram' => $telegram,
          'max' => $maxUrl,
          'vk' => $vk,
          'current' => '',
        ]);
      ?>
    </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/tuman-les-reka-yauza-vlasevo.jpg">
          <picture>
            <source srcset="assets/img/tuman-les-reka-yauza-vlasevo.webp" type="image/webp">
            <img src="assets/img/tuman-les-reka-yauza-vlasevo.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) ?>">
                  <?= responsive_picture($webp, $img, (string) ($service['title'] ?? ''), [
                    'loading' => 'lazy',
                    'width' => '900',
                    'height' => '700',
                  ], '(max-width: 960px) 100vw, 560px') ?>
                  <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'] ?? '') ?>">
                        <?= responsive_picture($pWebp, $pFall, (string) ($photo['alt'] ?? ''), [
                          'loading' => 'lazy',
                          'width' => '220',
                          'height' => '160',
                        ], '(max-width: 960px) 30vw, 180px') ?>
                      </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="<?= e($siteUrl . service_public_path($service)) ?>">Подробнее</a>
                  <a class="btn btn-ghost" 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'] ?? '') ?>">
                  <?= responsive_picture(
                    (string) ($video['poster'] ?? ''),
                    (string) ($video['poster_fallback'] ?? $video['poster'] ?? ''),
                    (string) ($video['title'] ?? ''),
                    ['loading' => 'lazy', 'width' => '800', 'height' => '450'],
                    '(max-width: 960px) 100vw, 560px'
                  ) ?>
                  <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'] ?? '') ?>" title="<?= e($item['alt'] ?? '') ?>">
              <?= responsive_picture(
                (string) ($item['src'] ?? ''),
                (string) ($item['fallback'] ?? $item['src'] ?? ''),
                (string) ($item['alt'] ?? ''),
                ['loading' => 'lazy', 'width' => '800', 'height' => '600', 'decoding' => 'async'],
                '(max-width: 700px) 50vw, (max-width: 960px) 33vw, 280px'
              ) ?>
              <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>
