<!DOCTYPE html>
<html lang="ko">
<head>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-7737599884075463"
     crossorigin="anonymous"></script>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>오늘의 금 시세</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 20px;
            text-align: center;
            background: #f9f9f9;
        }
        .container {
            background: white;
            padding: 20px;
            max-width: 700px;
            margin: auto;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            border-radius: 10px;
        }
        h1 {
            color: #d4af37;
        }
        .gold-price {
            font-size: 24px;
            font-weight: bold;
            color: #d4af37;
        }
        .table-container {
            margin-top: 20px;
            overflow-x: auto;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            background: #fff;
        }
        th, td {
            padding: 10px;
            border: 1px solid #ddd;
            text-align: center;
        }
        th {
            background: #d4af37;
            color: white;
        }
        .chart-container {
            margin-top: 20px;
            width: 100%;
            max-width: 650px;
            height: 300px;
            margin-left: auto;
            margin-right: auto;
        }
        .gold-link {
            display: inline-block;
            background: #d4af37;
            color: white;
            padding: 10px 20px;
            margin-top: 20px;
            text-decoration: none;
            font-weight: bold;
            border-radius: 5px;
            transition: 0.3s;
        }
        .gold-link:hover {
            background: #b5942c;
        }
    </style>
</head>
<body>

    <div class="container">
        <h1>오늘의 금 시세</h1>
        <p class="gold-price">현재 금 가격: <span id="gold-price">로딩 중...</span> 원/g</p>
<!-- 📢 애드센스 광고 위치 -->
        <div class="adsense-ad">
          <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-7737599884075463"
     crossorigin="anonymous"></script>
<!-- 광고 -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-7737599884075463"
     data-ad-slot="5163602545"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
        </div>
        <!-- 📢 광고 끝 -->

        <div class="table-container">
            <h2>최근 금 시세</h2>
            <table>
                <thead>
                    <tr>
                        <th>날짜</th>
                        <th>내가 살 때 (순금)</th>
                        <th>내가 팔 때 (순금)</th>
                        <th>18K 판매가</th>
                        <th>14K 판매가</th>
                    </tr>
                </thead>
                <tbody id="gold-table">
                    <tr><td colspan="5">데이터 로딩 중...</td></tr>
                </tbody>
            </table>
        </div>

        <div class="chart-container">
            <h2>금 시세 변동 그래프</h2>
            <canvas id="goldChart"></canvas>
        </div>

        <a href="https://www.koreagoldx.co.kr" target="_blank" class="gold-link">
            🔗 한국금거래소 시세 확인하기
        </a>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <script>
        document.addEventListener("DOMContentLoaded", function () {
            const goldPriceElem = document.getElementById("gold-price");
            const goldTableElem = document.getElementById("gold-table");

            // 예제 데이터 (API 연동 가능)
            const goldData = [
                { date: "2025.02.27", buy: 594000, sell: 510000, k18: 374900, k14: 290700 },
                { date: "2025.02.26", buy: 591000, sell: 510000, k18: 374900, k14: 290700 },
                { date: "2025.02.25", buy: 599000, sell: 525000, k18: 385900, k14: 299300 },
                { date: "2025.02.24", buy: 597000, sell: 520000, k18: 382200, k14: 296400 },
                { date: "2025.02.22", buy: 598000, sell: 520000, k18: 382200, k14: 296400 },
                { date: "2025.02.21", buy: 600000, sell: 530000, k18: 389600, k14: 302100 },
                { date: "2025.02.20", buy: 603000, sell: 530000, k18: 389600, k14: 302100 },
                { date: "2025.02.19", buy: 602000, sell: 535000, k18: 393300, k14: 305000 }
            ];

            // 최신 금 가격 업데이트
            goldPriceElem.innerText = goldData[0].buy.toLocaleString() + " 원/g";

            // 테이블 업데이트
            goldTableElem.innerHTML = goldData.map(row => `
                <tr>
                    <td>${row.date}</td>
                    <td>${row.buy.toLocaleString()} 원</td>
                    <td>${row.sell.toLocaleString()} 원</td>
                    <td>${row.k18.toLocaleString()} 원</td>
                    <td>${row.k14.toLocaleString()} 원</td>
                </tr>
            `).join('');

            // 금 시세 그래프
            const ctx = document.getElementById("goldChart").getContext("2d");
            new Chart(ctx, {
                type: "line",
                data: {
                    labels: goldData.map(row => row.date),
                    datasets: [
                        {
                            label: "내가 살 때 (순금)",
                            data: goldData.map(row => row.buy),
                            borderColor: "#FFD700",
                            backgroundColor: "rgba(218,165,32,0.2)",
                            fill: true,
                            tension: 0.3,
                            pointRadius: 5,
                            pointBackgroundColor: "#FFD700"
                        },
                        {
                            label: "내가 팔 때 (순금)",
                            data: goldData.map(row => row.sell),
                            borderColor: "#FF4500",
                            backgroundColor: "rgba(255,69,0,0.2)",
                            fill: true,
                            tension: 0.3,
                            pointRadius: 5,
                            pointBackgroundColor: "#FF4500"
                        }
                    ]
                },
                options: {
                    responsive: true,
                    maintainAspectRatio: false,
                    plugins: {
                        tooltip: {
                            enabled: true,
                            callbacks: {
                                label: function (tooltipItem) {
                                    return tooltipItem.dataset.label + ": " + tooltipItem.raw.toLocaleString() + " 원";
                                }
                            }
                        }
                    },
                    scales: {
                        x: {
                            grid: {
                                display: false
                            }
                        },
                        y: {
                            beginAtZero: false,
                            grid: {
                                color: "rgba(200,200,200,0.3)"
                            }
                        }
                    }
                }
            });
        });
    </script>

</body>
</html>