{{- /* 1. Host & Production Environment Guard */ -}}
{{- $host := "pilot.nemo.zone" -}}
{{- if and .Req .Req.Host -}}
  {{- $host = lower .Req.Host -}}
{{- else if .Host -}}
  {{- $host = lower .Host -}}
{{- end -}}
{{- $isProdHost := or (eq $host "pilot.nemo.zone") (and (hasSuffix ".nemo.zone" $host) (not (hasPrefix "dev." $host)) (not (contains ".dev." $host))) -}}

{{- /* 2. Path & Query Parsing */ -}}
{{- $reqPath := "/" -}}
{{- $rawQuery := "" -}}
{{- if and .Req .Req.URL -}}
  {{- $reqPath = .Req.URL.Path -}}
  {{- $rawQuery = lower .Req.URL.RawQuery -}}
{{- end -}}

{{- /* 3. Language Resolution: explicit ?hl= first, then Accept-Language, default ko for bots */ -}}
{{- $hlParam := "" -}}
{{- if or (contains "hl=ko" $rawQuery) (contains "lang=ko" $rawQuery) -}}
  {{- $hlParam = "ko" -}}
{{- else if or (contains "hl=ja" $rawQuery) (contains "lang=ja" $rawQuery) -}}
  {{- $hlParam = "ja" -}}
{{- else if or (contains "hl=en" $rawQuery) (contains "lang=en" $rawQuery) -}}
  {{- $hlParam = "en" -}}
{{- end -}}
{{- $acceptLang := "" -}}
{{- if and .Req .Req.Header -}}
  {{- $acceptLang = lower (.Req.Header.Get "Accept-Language") -}}
{{- end -}}
{{- $isJa := or (eq $hlParam "ja") (and (eq $hlParam "") (hasPrefix "ja" $acceptLang)) -}}
{{- $isEn := or (eq $hlParam "en") (and (eq $hlParam "") (not $isJa) (not (contains "ko" $acceptLang)) (ne $acceptLang "")) -}}
{{- $isKo := and (not $isJa) (not $isEn) -}}

{{- /* 4. Canonical & Alternate URLs */ -}}
{{- $canonicalPath := "/" -}}
{{- $baseCanonicalUrl := printf "https://pilot.nemo.zone%s" $canonicalPath -}}
{{- $enAlternateUrl := printf "%s?hl=en" $baseCanonicalUrl -}}
{{- $jaAlternateUrl := printf "%s?hl=ja" $baseCanonicalUrl -}}
{{- $canonicalUrl := $baseCanonicalUrl -}}
{{- if eq $hlParam "en" -}}
  {{- $canonicalUrl = $enAlternateUrl -}}
{{- else if eq $hlParam "ja" -}}
  {{- $canonicalUrl = $jaAlternateUrl -}}
{{- end -}}
{{- $isPublicPage := and $isProdHost (or (eq $reqPath "/") (eq $reqPath "/index.html")) (not (contains "code=" $rawQuery)) (not (contains "id=" $rawQuery)) -}}
<!DOCTYPE html>
<html lang="{{ if $isJa }}ja{{ else if $isKo }}ko{{ else }}en{{ end }}">
<head>
  <base href="/">
  <meta charset="UTF-8">
  <meta content="IE=Edge" http-equiv="X-UA-Compatible">

  {{- $pageTitle := "파일럿 | 실제 사용자 앱·웹 출시 전 검증 & 리워드 테스트" -}}
  {{- $pageDesc := "앱·웹 출시 전 실제 사용자 테스트와 투명한 리워드 정산 — 파일럿(Pilot)에서 TestFlight, Google Play 비공개 테스트, 웹 서비스를 검증하고 버그·UX 피드백 보상을 받으세요." -}}
  {{- $pageKeywords := "파일럿, Pilot, 앱 테스트, 베타 테스터, 출시 전 검증, Google Play 12명 14일 비공개 테스트, TestFlight, UX 피드백, 버그 바운티, Nemo" -}}
  {{- if $isKo -}}
    {{- $pageTitle = "파일럿 | 실제 사용자 앱·웹 출시 전 검증 & 리워드 테스트" -}}
    {{- $pageDesc = "앱·웹 출시 전 실제 사용자 테스트와 투명한 리워드 정산 — 파일럿(Pilot)에서 TestFlight, Google Play 비공개 테스트, 웹 서비스를 검증하고 버그·UX 피드백 보상을 받으세요." -}}
    {{- $pageKeywords = "파일럿, Pilot, 앱 테스트, 베타 테스터, 출시 전 검증, Google Play 12명 14일 비공개 테스트, TestFlight, UX 피드백, 버그 바운티, Nemo" -}}
  {{- else if $isJa -}}
    {{- $pageTitle = "パイロット | 実ユーザーによるアプリ・Webリリース前検証＆リワードテスト" -}}
    {{- $pageDesc = "アプリ・Webリリース前の実ユーザーテストと透明なリワード還元 — パイロット(Pilot)でTestFlight、Google Playクローズドテスト、Webサービスを検証し、バグ・UXフィードバック報酬を獲得しましょう。" -}}
    {{- $pageKeywords = "パイロット, Pilot, アプリテスト, ベータテスター, リリース前検証, Google Play クローズドテスト, TestFlight, UXフィードバック, バグバウンティ, Nemo" -}}
  {{- else -}}
    {{- $pageTitle = "Pilot | Real-User App & Web Pre-Release QA Testing" -}}
    {{- $pageDesc = "Real-user testing and transparent reward bounties before launch — verify TestFlight, Google Play closed testing, and web apps on Pilot while earning bug and UX feedback rewards." -}}
    {{- $pageKeywords = "Pilot, App Testing, Beta Testing, Pre-Release QA, Google Play Closed Testing, TestFlight, UX Feedback, Bug Bounty, Nemo" -}}
  {{- end -}}

  <title>{{$pageTitle}}</title>
  <meta name="description" content="{{$pageDesc}}">
  <meta name="keywords" content="{{$pageKeywords}}">
  <meta property="og:title" content="{{$pageTitle}}">
  <meta property="og:description" content="{{$pageDesc}}">
  <meta property="og:locale" content="{{ if $isJa }}ja_JP{{ else if $isKo }}ko_KR{{ else }}en_US{{ end }}">
  <meta property="og:type" content="website">
  <meta property="og:site_name" content="Nemo">
  <meta property="og:url" content="{{$canonicalUrl}}">
  <meta name="twitter:card" content="summary">
  <meta name="twitter:title" content="{{$pageTitle}}">
  <meta name="twitter:description" content="{{$pageDesc}}">

  {{- if $isPublicPage -}}
    <meta name="robots" content="index, follow, max-image-preview:large, max-snippet:-1, max-video-preview:-1">
  {{- else -}}
    <meta name="robots" content="noindex, nofollow, noarchive">
  {{- end -}}
  <link rel="canonical" href="{{$canonicalUrl}}">
  <link rel="alternate" hreflang="ko" href="{{$baseCanonicalUrl}}">
  <link rel="alternate" hreflang="en" href="{{$enAlternateUrl}}">
  <link rel="alternate" hreflang="ja" href="{{$jaAlternateUrl}}">
  <link rel="alternate" hreflang="x-default" href="{{$baseCanonicalUrl}}">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
  <meta name="mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
  <meta name="apple-mobile-web-app-title" content="Pilot">
  <meta name="theme-color" media="(prefers-color-scheme: dark)" content="#0C0C0E">
  <meta name="theme-color" media="(prefers-color-scheme: light)" content="#F8FAFC">
  <link rel="manifest" href="manifest.json">
  <link rel="icon" type="image/svg+xml" href="favicon.svg">
  <link rel="icon" type="image/png" sizes="32x32" href="favicon-32x32.png">
  <link rel="icon" type="image/png" sizes="16x16" href="favicon-16x16.png">
  <link rel="shortcut icon" href="favicon.ico">
  <link rel="apple-touch-icon" href="apple-touch-icon.png">
  <link rel="stylesheet" as="style" crossorigin href="https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/static/pretendard-dynamic-subset.css" />
  <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&family=Noto+Sans+KR:wght@400;500;600;700;800;900&display=swap">
  <script>
    window.setDocumentTitle = function(title) {
      try {
        document.title = title;
      } catch (e) {}
    };

    window.isBrowserOnline = function() {
      return navigator.onLine !== false;
    };
  </script>
  <style>
    body {
      inset: 0;
      overflow: hidden;
      margin: 0;
      padding: 0;
      position: fixed;
      user-select: none;
      -webkit-user-select: none;
      touch-action: manipulation;
      background-color: #0C0C0E;
      font-family: Pretendard, -apple-system, BlinkMacSystemFont, system-ui, Roboto, 'Helvetica Neue', 'Segoe UI', 'Apple SD Gothic Neo', 'Noto Sans KR', 'Malgun Gothic', sans-serif;
    }
  </style>
</head>
<body>
  <div id="nemo-app-loading" style="position:fixed;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;background:#0C0C0E;z-index:9999;transition:opacity 0.25s ease-out;font-family:'Pretendard',sans-serif;pointer-events:none;">
    <style>
      @media (prefers-color-scheme: light) {
        #nemo-app-loading { background: #FFFFFF !important; }
      }
      .vector-logo-svg {
        width: 68px;
        height: 68px;
        overflow: visible;
      }
      .anim-pilot .pilot-plane-group {
        transform-box: view-box;
        transform-origin: 256px 260px;
        animation: pilotFlight 2.4s ease-in-out infinite;
      }
      .anim-pilot .pilot-spark {
        transform-box: view-box;
        transform-origin: 412px 96px;
        animation: pilotSpark 2.4s ease-in-out infinite;
      }
      @keyframes pilotFlight {
        0%, 100% { transform: translateY(0) rotate(0deg); }
        25% { transform: translateY(-8px) rotate(5deg); }
        50% { transform: translateY(-16px) rotate(0deg); }
        75% { transform: translateY(-8px) rotate(-5deg); }
      }
      @keyframes pilotSpark {
        0%, 100% { transform: translateY(0) scale(1); }
        50% { transform: translateY(-24px) scale(1.3); }
      }
    </style>
    <div style="display:flex;flex-direction:column;align-items:center;justify-content:center;">
      <svg class="vector-logo-svg anim-pilot" viewBox="0 0 512 512" fill="none">
        <g class="pilot-plane-group">
          <path d="M 256 76 L 72 380 L 232 344 Z" fill="#38BDF8" />
          <path d="M 256 76 L 440 380 L 280 344 Z" fill="#0EA5E9" />
          <path d="M 256 76 L 280 344 L 256 436 L 232 344 Z" fill="#0284C7" />
        </g>
        <path class="pilot-spark" d="M 412 64 Q 412 96 444 96 Q 412 96 412 128 Q 412 96 380 96 Q 412 96 412 64 Z" fill="#BAE6FD" />
      </svg>
    </div>
  </div>
  <script>
    (function() {
      function dismissLoader() {
        var el = document.getElementById('nemo-app-loading');
        if (el) {
          el.style.opacity = '0';
          el.style.pointerEvents = 'none';
          el.style.display = 'none';
          if (el.parentNode) {
            el.parentNode.removeChild(el);
          }
        }
      }
      window.addEventListener('flutter-first-frame', dismissLoader);
      setTimeout(dismissLoader, 20000);
    })();
  </script>
  <script src="flutter_bootstrap.js" async></script>
</body>
</html>
