<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="theme-color" content="#6366f1">
    <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="청춘약국">
    <link rel="manifest" href="/static/manifest.json">
    <link rel="apple-touch-icon" href="/static/icons/icon-192.png">
    <link rel="icon" type="image/png" sizes="192x192" href="/static/icons/icon-192.png">
    <title>적립 완료 - 청춘약국</title>
    <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=Noto+Sans+KR:wght@400;500;700&display=swap" rel="stylesheet">
    <style>
        * { margin: 0; padding: 0; box-sizing: border-box; }

        body {
            font-family: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
            background: #f5f7fa;
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 16px;
            -webkit-font-smoothing: antialiased;
        }

        .app-container {
            background: #ffffff;
            border-radius: 24px;
            max-width: 420px;
            width: 100%;
            box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
            overflow: hidden;
            text-align: center;
            padding: 60px 24px;
        }

        .success-icon-wrap {
            width: 80px;
            height: 80px;
            background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
            border-radius: 50%;
            margin: 0 auto 24px auto;
            display: flex;
            align-items: center;
            justify-content: center;
            animation: scaleIn 0.4s ease;
        }

        @keyframes scaleIn {
            0% { transform: scale(0); opacity: 0; }
            60% { transform: scale(1.1); }
            100% { transform: scale(1); opacity: 1; }
        }

        .success-icon-wrap svg {
            width: 40px;
            height: 40px;
            fill: none;
            stroke: #ffffff;
            stroke-width: 3;
            stroke-linecap: round;
            stroke-linejoin: round;
            stroke-dasharray: 100;
            stroke-dashoffset: 100;
            animation: drawCheck 0.6s 0.3s ease forwards;
        }

        @keyframes drawCheck {
            to { stroke-dashoffset: 0; }
        }

        .success-title {
            font-size: 24px;
            font-weight: 700;
            color: #212529;
            margin-bottom: 16px;
            letter-spacing: -0.5px;
        }

        .success-name {
            font-size: 15px;
            color: #868e96;
            font-weight: 500;
            margin-bottom: 20px;
        }

        .success-name strong {
            color: #495057;
        }

        .success-points {
            font-size: 48px;
            font-weight: 700;
            color: #6366f1;
            margin-bottom: 8px;
            letter-spacing: -1.5px;
        }

        .success-balance {
            color: #868e96;
            font-size: 15px;
            font-weight: 500;
            margin-bottom: 32px;
            letter-spacing: -0.2px;
        }

        .success-balance strong {
            color: #495057;
        }

        .kakao-badge {
            display: inline-flex;
            align-items: center;
            gap: 6px;
            font-size: 13px;
            color: #191919;
            background: #FEE500;
            padding: 6px 14px;
            border-radius: 20px;
            font-weight: 600;
            margin-bottom: 32px;
        }

        .button-group {
            display: flex;
            gap: 12px;
        }

        .btn-secondary, .btn-primary {
            flex: 1;
            padding: 16px;
            border-radius: 14px;
            font-size: 15px;
            font-weight: 600;
            text-decoration: none;
            text-align: center;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.2s ease;
            letter-spacing: -0.2px;
        }

        .btn-secondary {
            background: #f1f3f5;
            color: #495057;
        }

        .btn-primary {
            background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
            color: #ffffff;
        }

        .btn-secondary:active, .btn-primary:active {
            transform: scale(0.98);
        }

        @media (max-width: 480px) {
            body { padding: 0; }
            .app-container { border-radius: 0; min-height: 100vh; display: flex; flex-direction: column; justify-content: center; }
        }
    </style>
</head>
<body>
    <div class="app-container">
        <div class="success-icon-wrap">
            <svg viewBox="0 0 52 52">
                <path d="M14.1 27.2l7.1 7.2 16.7-16.8"/>
            </svg>
        </div>
        <div class="success-title">적립 완료!</div>
        <div class="success-name"><strong>{{ name }}</strong>님</div>
        <div class="success-points">+{{ "{:,}".format(points) }}P</div>
        <div class="success-balance">
            총 포인트 <strong>{{ "{:,}".format(balance) }}P</strong>
        </div>
        <div class="kakao-badge">
            <svg width="14" height="14" viewBox="0 0 20 20" fill="none">
                <path d="M10 1C4.477 1 0 4.477 0 8.5c0 2.58 1.693 4.847 4.243 6.134l-1.084 3.97a.3.3 0 00.457.338L7.7 16.392c.75.112 1.52.17 2.3.17 5.523 0 10-3.477 10-7.562C20 4.477 15.523 1 10 1z" fill="#191919"/>
            </svg>
            카카오로 적립됨
        </div>
        <div class="button-group">
            <a href="/" class="btn-secondary">홈으로</a>
            <a href="/my-page?phone={{ phone }}" class="btn-primary">내역 보기</a>
        </div>

        <!-- PWA 설치 유도 배너 -->
        <div id="installBanner" style="display:none; margin-top:24px; padding:16px 20px; background:#f8f9fa; border-radius:14px; text-align:left;">
            <div style="font-size:14px; font-weight:700; color:#212529; margin-bottom:6px; letter-spacing:-0.3px;">
                홈 화면에 추가하면 더 편해요!
            </div>
            <div id="installDesc" style="font-size:13px; color:#868e96; line-height:1.6; letter-spacing:-0.2px;"></div>
            <button id="installBtn" style="display:none; margin-top:10px; width:100%; padding:12px; background:linear-gradient(135deg,#6366f1,#8b5cf6); color:#fff; border:none; border-radius:10px; font-size:14px; font-weight:600; cursor:pointer; letter-spacing:-0.2px;">
                앱 설치하기
            </button>
        </div>
    </div>

    <script>
    if('serviceWorker' in navigator){navigator.serviceWorker.register('/sw.js').catch(()=>{});}

    // PWA 설치 유도
    (function() {
        const banner = document.getElementById('installBanner');
        const desc = document.getElementById('installDesc');
        const btn = document.getElementById('installBtn');

        // 이미 PWA로 실행 중이면 표시 안 함
        if (window.matchMedia('(display-mode: standalone)').matches || navigator.standalone) return;

        let deferredPrompt = null;

        // Android Chrome: beforeinstallprompt 이벤트
        window.addEventListener('beforeinstallprompt', function(e) {
            e.preventDefault();
            deferredPrompt = e;
            desc.textContent = '다음부터 QR 스캔하면 입력 없이 바로 적립됩니다.';
            btn.style.display = 'block';
            banner.style.display = 'block';
        });

        btn.addEventListener('click', function() {
            if (deferredPrompt) {
                deferredPrompt.prompt();
                deferredPrompt.userChoice.then(function() { banner.style.display = 'none'; });
            }
        });

        // iOS Safari 감지
        const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent);
        const isSafari = /Safari/.test(navigator.userAgent) && !/CriOS|FxiOS/.test(navigator.userAgent);
        if (isIOS && isSafari && !deferredPrompt) {
            desc.innerHTML = '하단 <strong style="color:#495057;">공유 버튼</strong> ➜ <strong style="color:#495057;">홈 화면에 추가</strong>를 누르면<br>다음부터 QR만 찍으면 바로 적립!';
            banner.style.display = 'block';
        }
    })();
    </script>
</body>
</html>
