<!DOCTYPE html>
<html lang="zh-TW">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>404 - Not Found</title>
  <style>
    body {
      font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
      display: flex;
      align-items: center;
      justify-content: center;
      min-height: 100vh;
      margin: 0;
      background: #1a1a1a;
      color: #fff;
    }
    .container {
      text-align: center;
      padding: 20px;
    }
    h1 { font-size: 4rem; margin: 0; color: #ff6b6b; }
    p { color: #aaa; margin: 20px 0; }
    a {
      display: inline-block;
      padding: 12px 24px;
      background: #ff6b6b;
      color: #fff;
      text-decoration: none;
      border-radius: 8px;
      margin-top: 20px;
    }
    .reload-hint {
      margin-top: 30px;
      padding: 15px;
      background: rgba(255,255,255,0.1);
      border-radius: 8px;
      font-size: 0.9rem;
    }
  </style>
</head>
<body>
  <div class="container">
    <h1>404</h1>
    <p>找不到此頁面</p>
    <a href="/" onclick="clearCacheAndReload(); return false;">返回首頁</a>
    <div class="reload-hint">
      <p>如果頁面持續無法載入，請嘗試：</p>
      <button onclick="clearCacheAndReload()" style="padding:10px 20px; cursor:pointer; background:#4a90d9; color:#fff; border:none; border-radius:5px;">
        清除快取並重新載入
      </button>
    </div>
  </div>
  <script>
    async function clearCacheAndReload() {
      // 清除 Service Worker
      if ('serviceWorker' in navigator) {
        const registrations = await navigator.serviceWorker.getRegistrations();
        for (const reg of registrations) {
          await reg.unregister();
        }
      }
      // 清除快取
      if ('caches' in window) {
        const names = await caches.keys();
        for (const name of names) {
          await caches.delete(name);
        }
      }
      // 強制重新載入
      window.location.href = '/?nocache=' + Date.now();
    }
  </script>
</body>
</html>
