/* ============================================================
   Navigation polish — sticky header, anchor offsets, back to top.
   Loaded after the page stylesheets so it only adjusts behaviour.
   ============================================================ */

:root{--hdr-h:84px}

/* The header stays available on long pages instead of leaving with the
   first scroll. It is the same header, not a second one. */
.hdr{
  position:sticky;top:0;z-index:60;
  background:rgba(255,255,255,.86);
  backdrop-filter:blur(14px) saturate(140%);
  -webkit-backdrop-filter:blur(14px) saturate(140%);
  transition:box-shadow .3s var(--ease-soft),background .3s,height .3s var(--ease-soft);
}
.hdr.scrolled{
  background:rgba(255,255,255,.96);
  box-shadow:0 1px 0 var(--line);
}

/* Anchored sections clear the header instead of hiding beneath it. */
[id]{scroll-margin-top:calc(var(--hdr-h) + 24px)}
.hero,#top{scroll-margin-top:0}

/* The current page, stated quietly. */
.nav a[aria-current="page"],
.nav a.is-on{color:var(--ink)}
.nav a[aria-current="page"]::after,
.nav a.is-on::after{
  content:"";position:absolute;left:0;right:0;bottom:-6px;height:1.5px;
  background:var(--cobalt);border-radius:2px;
  transform-origin:left;animation:navline .4s var(--ease-soft) both;
}
.nav a{position:relative}
@keyframes navline{from{transform:scaleX(0);opacity:0}to{transform:scaleX(1);opacity:1}}

/* Focus, visible and consistent with the cobalt accent. */
a:focus-visible,button:focus-visible,summary:focus-visible,
input:focus-visible,select:focus-visible,textarea:focus-visible,
[tabindex]:focus-visible{
  outline:2px solid var(--cobalt);outline-offset:3px;border-radius:2px;
}

/* Back to top: appears only once it is useful. */
.to-top{
  position:fixed;right:28px;bottom:28px;z-index:70;
  width:44px;height:44px;border-radius:50%;
  display:flex;align-items:center;justify-content:center;
  background:#fff;color:var(--ink);border:1px solid var(--line);
  box-shadow:0 6px 22px rgba(23,36,61,.10);
  opacity:0;visibility:hidden;transform:translateY(10px);
  transition:opacity .28s var(--ease-soft),transform .28s var(--ease-soft),
             box-shadow .28s var(--ease-soft),border-color .28s var(--ease-soft),
             visibility .28s;
}
.to-top svg{width:16px;height:16px}
.to-top.is-on{opacity:1;visibility:visible;transform:none}
.to-top:hover{border-color:var(--cobalt);color:var(--cobalt);box-shadow:0 10px 28px rgba(70,92,245,.18)}
.to-top:active{transform:translateY(1px)}

@media(max-width:980px){
  :root{--hdr-h:64px}
  .to-top{right:16px;bottom:16px;width:40px;height:40px}
}

@media(prefers-reduced-motion:reduce){
  .to-top{transition:opacity .01s,visibility .01s}
  .nav a[aria-current="page"]::after,.nav a.is-on::after{animation:none}
}
