/*
 * Header mega-menu (P018 2026-05).
 *
 * Bento grid hover panel for top-nav items that have multiple children
 * (Tools = pilot; Games/Services/Projects/Blog to follow). 2026 design
 * pattern: icon + title + microcopy per card, glass aesthetic, 200ms
 * hover-intent delay, keyboard-accessible, RTL-aware.
 *
 * Mobile (<992px): panel hard-hidden via media query so the existing
 * aurora-mobile-menu (separate DOM tree) handles small viewports
 * untouched. The trigger element on mobile behaves like a regular link.
 */

/* ── Trigger wrapper ─────────────────────────────────────── */
.has-megamenu {
    position: relative;
}

.has-megamenu .aurora-nav-link {
    /* Chevron caret hint on the trigger; rotates when panel is open. */
    display: inline-flex;
    align-items: center;
    gap: .35rem;
}

.has-megamenu .megamenu-chevron {
    width: .85rem;
    height: .85rem;
    transition: transform 220ms ease-out;
    flex: 0 0 auto;
    opacity: .7;
}

.has-megamenu[data-open="true"] .megamenu-chevron {
    transform: rotate(180deg);
    opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
    .has-megamenu .megamenu-chevron { transition: none; }
}

/* ── Panel — base hidden state ───────────────────────────── */
.megamenu-panel {
    position: absolute;
    top: calc(100% + .5rem);
    left: 50%;
    transform: translateX(-50%) translateY(-4px);
    z-index: 1050;

    /* Width: fits 4 cards across on a card min-width of ~190px + gaps. */
    width: min(820px, calc(100vw - 2rem));

    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition:
        opacity 200ms ease-out,
        transform 240ms cubic-bezier(.16, 1, .3, 1),
        visibility 0s linear 240ms;
}

.megamenu-panel[hidden] {
    /* Hidden attribute fully removes from a11y tree until JS opens it. */
    display: none;
}

.has-megamenu[data-open="true"] .megamenu-panel {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateX(-50%) translateY(0);
    transition:
        opacity 200ms ease-out,
        transform 240ms cubic-bezier(.16, 1, .3, 1),
        visibility 0s linear 0s;
}

@media (prefers-reduced-motion: reduce) {
    .megamenu-panel {
        transition-property: opacity, visibility;
        transform: translateX(-50%) translateY(0);
    }
    .has-megamenu[data-open="true"] .megamenu-panel {
        transform: translateX(-50%) translateY(0);
    }
}

/* Bridge hit-area between trigger and panel so the cursor doesn't lose
   hover state crossing the gap. Invisible 12px strip above the panel. */
.megamenu-panel::before {
    content: "";
    position: absolute;
    inset: -12px 0 auto 0;
    height: 12px;
}

/* ── Panel inner — glass surface ─────────────────────────────
 * Explicit colors (no var() reliance) — the site's --color-glass-surface
 * token defaults to rgba(255,255,255,.06) for dark mode (the global :root),
 * which is far too transparent for a foreground menu sitting over hero
 * gradients, brand banners and large H1 text. We need a near-opaque
 * surface so underlying content cannot bleed through.
 * ─────────────────────────────────────────────────────────── */
.megamenu-panel-inner {
    /* Light mode default — high-opacity white */
    background: rgba(255, 255, 255, .97);
    border: 1px solid rgba(15, 23, 42, .08);
    border-radius: 18px;
    padding: 1.4rem 1.4rem 1.1rem;
    box-shadow:
        0 18px 48px -12px rgba(15, 23, 42, .22),
        0 4px 12px -6px rgba(15, 23, 42, .14);
    -webkit-backdrop-filter: blur(20px) saturate(160%);
    backdrop-filter: blur(20px) saturate(160%);
}

/* Dark mode — slate-900 near-opaque; supports both theme conventions
   used on the site (html[data-theme="dark"] from theme.js + body.dark
   from dark.css legacy). */
[data-theme="dark"] .megamenu-panel-inner,
body.dark .megamenu-panel-inner {
    background: rgba(15, 23, 42, .97);
    border-color: rgba(148, 163, 184, .18);
    box-shadow:
        0 18px 48px -12px rgba(0, 0, 0, .65),
        0 4px 12px -6px rgba(0, 0, 0, .45);
}

/* ── Head — eyebrow + tagline ────────────────────────────── */
.megamenu-head {
    margin-bottom: 1rem;
    padding-bottom: .85rem;
    border-bottom: 1px solid var(--color-border-default, rgba(15, 23, 42, .08));
}

.megamenu-eyebrow {
    display: block;
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--color-text-secondary, #6b7280);
    margin-bottom: .35rem;
}

.megamenu-tagline {
    margin: 0;
    font-size: .85rem;
    line-height: 1.45;
    color: var(--color-text-secondary, #6b7280);
    max-width: 56ch;
}

/* ── Grid — bento layout ─────────────────────────────────── */
.megamenu-grid {
    list-style: none;
    margin: 0 0 1rem;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: .6rem;
}

/* ── Card ────────────────────────────────────────────────── */
.megamenu-card {
    display: flex;
    align-items: flex-start;
    gap: .75rem;
    padding: .75rem .85rem;
    border-radius: 12px;
    text-decoration: none;
    color: inherit;
    border: 1px solid transparent;
    transition:
        background-color 160ms ease-out,
        border-color 160ms ease-out,
        transform 160ms ease-out;
}

.megamenu-card:hover,
.megamenu-card:focus-visible {
    background: var(--color-surface-hover, rgba(99, 102, 241, .07));
    border-color: var(--color-border-accent, rgba(99, 102, 241, .25));
    text-decoration: none;
    outline: none;
}

.megamenu-card:focus-visible {
    outline: 2px solid var(--color-accent, #6366f1);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    .megamenu-card { transition: none; }
}

.megamenu-card-icon {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: var(--color-surface-elevated, rgba(99, 102, 241, .1));
    color: var(--color-accent, #6366f1);
}

.megamenu-card-icon svg {
    width: 20px;
    height: 20px;
}

.megamenu-card-body {
    display: flex;
    flex-direction: column;
    gap: .15rem;
    min-width: 0;
    flex: 1;
}

.megamenu-card-title-row {
    display: flex;
    align-items: center;
    gap: .45rem;
    flex-wrap: wrap;
}

.megamenu-card-title {
    font-size: .92rem;
    font-weight: 600;
    line-height: 1.25;
    color: var(--color-text-primary, #111827);
}

.megamenu-card-badge {
    display: inline-block;
    font-size: .65rem;
    font-weight: 600;
    letter-spacing: .04em;
    padding: .12rem .45rem;
    border-radius: 999px;
    background: var(--color-accent-soft, rgba(99, 102, 241, .12));
    color: var(--color-accent, #6366f1);
    white-space: nowrap;
}

.megamenu-card-desc {
    font-size: .78rem;
    line-height: 1.45;
    color: var(--color-text-secondary, #6b7280);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ── CTA row — "View all →" ──────────────────────────────── */
.megamenu-cta {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    margin: 0;
    padding: .55rem .9rem;
    border-radius: 999px;
    font-size: .85rem;
    font-weight: 600;
    color: var(--color-accent, #6366f1);
    text-decoration: none;
    border: 1px solid var(--color-border-accent, rgba(99, 102, 241, .3));
    transition: background-color 160ms ease-out, transform 160ms ease-out;
}

.megamenu-cta:hover,
.megamenu-cta:focus-visible {
    background: var(--color-accent-soft, rgba(99, 102, 241, .12));
    text-decoration: none;
    outline: none;
}

.megamenu-cta:focus-visible {
    outline: 2px solid var(--color-accent, #6366f1);
    outline-offset: 2px;
}

.megamenu-cta-arrow {
    width: 1rem;
    height: 1rem;
    transition: transform 160ms ease-out;
}

.megamenu-cta:hover .megamenu-cta-arrow {
    transform: translateX(3px);
}

@media (prefers-reduced-motion: reduce) {
    .megamenu-cta,
    .megamenu-cta-arrow { transition: none; }
}

/* ── RTL — mirror chevron & arrow direction ──────────────── */
[dir="rtl"] .megamenu-cta-arrow {
    transform: scaleX(-1);
}

[dir="rtl"] .megamenu-cta:hover .megamenu-cta-arrow {
    transform: scaleX(-1) translateX(3px);
}

/* ── Dark mode — explicit overrides for sub-elements ─────────
 * The site's --color-* tokens are defined globally for both modes,
 * but several values (card-hover bg, icon-slot bg, head divider)
 * are tuned for the rest of the UI, not for a glass surface that
 * sits on top of bright hero gradients. We override with explicit
 * dark-mode colors here so cards have visible resting + hover
 * surfaces, the head divider is readable, and the CTA stands out.
 * ─────────────────────────────────────────────────────────── */
[data-theme="dark"] .megamenu-head,
body.dark .megamenu-head {
    border-bottom-color: rgba(148, 163, 184, .18);
}

[data-theme="dark"] .megamenu-eyebrow,
body.dark .megamenu-eyebrow {
    color: rgba(226, 232, 240, .95);
}

[data-theme="dark"] .megamenu-tagline,
body.dark .megamenu-tagline {
    color: rgba(203, 213, 225, .82);
}

[data-theme="dark"] .megamenu-card,
body.dark .megamenu-card {
    background: rgba(30, 41, 59, .55);
    border-color: rgba(148, 163, 184, .12);
}

[data-theme="dark"] .megamenu-card:hover,
[data-theme="dark"] .megamenu-card:focus-visible,
body.dark .megamenu-card:hover,
body.dark .megamenu-card:focus-visible {
    background: rgba(99, 102, 241, .22);
    border-color: rgba(129, 140, 248, .45);
}

[data-theme="dark"] .megamenu-card-icon,
body.dark .megamenu-card-icon {
    background: rgba(99, 102, 241, .18);
    color: #c7d2fe;
}

[data-theme="dark"] .megamenu-card-title,
body.dark .megamenu-card-title {
    color: rgba(248, 250, 252, .96);
}

[data-theme="dark"] .megamenu-card-desc,
body.dark .megamenu-card-desc {
    color: rgba(226, 232, 240, .9);
}

[data-theme="dark"] .megamenu-card-badge,
body.dark .megamenu-card-badge {
    background: rgba(99, 102, 241, .35);
    color: #e0e7ff;
}

[data-theme="dark"] .megamenu-cta,
body.dark .megamenu-cta {
    color: #e0e7ff;
    border-color: rgba(129, 140, 248, .55);
}

[data-theme="dark"] .megamenu-cta:hover,
[data-theme="dark"] .megamenu-cta:focus-visible,
body.dark .megamenu-cta:hover,
body.dark .megamenu-cta:focus-visible {
    background: rgba(99, 102, 241, .22);
    color: #e0e7ff;
}

/* ── Mobile guard — fully hide panel on small viewports ──── */
@media (max-width: 991.98px) {
    .megamenu-panel { display: none !important; }
    .has-megamenu .megamenu-chevron { display: none; }
}
