<?php
/**
 * Branded 404 page — shown by core/Router.php when no route matches.
 * Self-contained: derives its own base/assets URLs and pulls the shared theme
 * tokens + the official animated crystal brand lockup. Theme-aware, reduced-motion safe.
 */
$__base = rtrim(dirname((string) ($_SERVER['SCRIPT_NAME'] ?? '')), '/');
if ($__base === '.' ) $__base = '';
$baseUrl   = $__base;
$assetsUrl = $__base . '/assets';
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Page not found · <?= htmlspecialchars(\PpPhp\Core\Brand::name()) ?></title>
    <?php include constant('BASE_PATH') . '/core/views/favicon.php'; ?>
    <link href="<?= htmlspecialchars($assetsUrl) ?>/icons/bootstrap-icons.css" rel="stylesheet">
    <?php include constant('BASE_PATH') . '/core/views/theme-head.php'; ?>
    <style>
        body { margin: 0; background: var(--pp-app-bg, #0b1220); color: var(--pp-text, #e5e7eb);
            font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif; }
        .e404 { position: relative; overflow: hidden; min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
        /* Ambient crystal aurora */
        .e404-aurora { position: absolute; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
        .e404-aurora span { position: absolute; border-radius: 50%; filter: blur(70px); opacity: .5; will-change: transform; }
        .e404-aurora span:nth-child(1) { width: 460px; height: 460px; top: -160px; right: -80px;
            background: radial-gradient(circle, color-mix(in srgb, var(--pp-accent, #4f46e5) 55%, transparent), transparent 70%); animation: e404a 20s ease-in-out infinite; }
        .e404-aurora span:nth-child(2) { width: 380px; height: 380px; bottom: -150px; left: -90px;
            background: radial-gradient(circle, color-mix(in srgb, #8b5cf6 48%, transparent), transparent 70%); animation: e404b 24s ease-in-out infinite; }
        .e404-aurora span:nth-child(3) { width: 320px; height: 320px; top: 40%; left: 45%;
            background: radial-gradient(circle, color-mix(in srgb, #22d3ee 34%, transparent), transparent 70%); animation: e404c 28s ease-in-out infinite; }
        @keyframes e404a { 0%,100% { transform: none; } 50% { transform: translate(-40px, 30px) scale(1.12); } }
        @keyframes e404b { 0%,100% { transform: none; } 50% { transform: translate(40px, -26px) scale(1.08); } }
        @keyframes e404c { 0%,100% { transform: none; } 50% { transform: translate(-30px, -30px) scale(1.15); } }
        .e404-inner { position: relative; z-index: 1; width: min(560px, 100%); text-align: center;
            background: color-mix(in srgb, var(--pp-surface, #131c2e) 82%, transparent);
            border: 1px solid color-mix(in srgb, var(--pp-border, #22304a) 80%, transparent);
            border-radius: 22px; padding: 2.4rem 2rem 2rem; backdrop-filter: blur(8px);
            box-shadow: 0 30px 80px rgba(2, 6, 23, .38); animation: e404in .5s cubic-bezier(.4,0,.2,1) both; }
        @keyframes e404in { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
        .e404-brand { display: flex; justify-content: center; margin-bottom: 1.2rem; }
        .e404-code { font-size: clamp(4.5rem, 16vw, 7.5rem); font-weight: 900; line-height: 1; letter-spacing: -.05em;
            background: linear-gradient(180deg, #7dd3fc, #6366f1 45%, #a855f7); -webkit-background-clip: text; background-clip: text;
            -webkit-text-fill-color: transparent; color: transparent; filter: drop-shadow(0 6px 24px color-mix(in srgb, var(--pp-accent, #4f46e5) 30%, transparent)); }
        .e404-inner h1 { margin: .3rem 0 .5rem; font-size: 1.5rem; font-weight: 800; letter-spacing: -.02em; color: var(--pp-text, #f1f5f9); }
        .e404-inner p { margin: 0 auto 1.5rem; max-width: 40ch; font-size: .92rem; line-height: 1.6; color: var(--pp-text-muted, #94a3b8); }
        .e404-actions { display: flex; gap: .6rem; justify-content: center; flex-wrap: wrap; }
        .e404-btn { display: inline-flex; align-items: center; gap: .45rem; padding: .6rem 1.05rem; border-radius: 11px;
            font-size: .86rem; font-weight: 700; text-decoration: none; transition: transform .15s ease, box-shadow .15s ease, background-color .15s ease;
            border: 1px solid color-mix(in srgb, var(--pp-border, #334155) 90%, transparent); color: var(--pp-text, #e5e7eb);
            background: color-mix(in srgb, var(--pp-surface-soft, #1b2740) 70%, transparent); }
        .e404-btn:hover { transform: translateY(-1px); border-color: var(--pp-accent, #6366f1); color: var(--pp-text, #fff); }
        .e404-btn.primary { border-color: transparent; color: #fff;
            background: linear-gradient(135deg, var(--pp-accent, #4f46e5), color-mix(in srgb, var(--pp-accent, #4f46e5) 55%, #8b5cf6));
            box-shadow: 0 10px 24px color-mix(in srgb, var(--pp-accent, #4f46e5) 34%, transparent); }
        .e404-btn.primary:hover { filter: brightness(1.06); color: #fff; }
        .e404-foot { margin-top: 1.6rem; font-size: .68rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
            color: var(--pp-text-muted, #64748b); opacity: .8; }
        @media (prefers-reduced-motion: reduce) { .e404-aurora span { animation: none !important; } .e404-inner { animation: none !important; } }
    </style>
</head>
<body>
    <main class="e404">
        <div class="e404-aurora" aria-hidden="true"><span></span><span></span><span></span></div>
        <div class="e404-inner">
            <div class="e404-brand"><?= \PpPhp\Core\Brand::lockup(46) ?></div>
            <div class="e404-code">404</div>
            <h1>This page wandered off</h1>
            <p>The link may be broken, or the page may have moved. Let's get you back to building.</p>
            <div class="e404-actions">
                <a class="e404-btn primary" href="<?= htmlspecialchars($baseUrl) ?>/"><i class="bi bi-house-door"></i> Back to app</a>
                <a class="e404-btn" href="<?= htmlspecialchars($baseUrl) ?>/help"><i class="bi bi-life-preserver"></i> Help center</a>
                <a class="e404-btn" href="javascript:history.back()"><i class="bi bi-arrow-left"></i> Go back</a>
            </div>
            <div class="e404-foot">PPPHP · Rapid application studio</div>
        </div>
    </main>
</body>
</html>
