/* =========================================================
   Pill navigation
   A floating, centred pill (logo · links · theme toggle).
   On desktop it folds down to just the logo once the page is
   scrolled, and opens again on hover or keyboard focus.
   Loaded last on every page, so it wins over the older nav
   rules in style.css / case.css. Behaviour: assets/js/nav-pill.js
   ========================================================= */

nav.pill-nav {
  --pill-bg: rgba(30, 30, 30, 0.72);
  --pill-line: rgba(255, 255, 255, 0.08);
  --pill-fg: #f5f5f5;
  --pill-ease: cubic-bezier(0.2, 0.715, 0.205, 0.99);

  position: sticky;
  top: 0;
  z-index: 1000;
  height: 72px;
  padding: 12px 16px 0;
  background: transparent;
  border: 0;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  /* Only the pill itself takes clicks; the strip around it lets them through. */
  pointer-events: none;
}

html[data-theme="light"] nav.pill-nav {
  --pill-bg: rgba(255, 255, 255, 0.82);
  --pill-line: rgba(0, 0, 0, 0.06);
  --pill-fg: #1e1e1e;
  background: transparent;
  border: 0;
}

nav.pill-nav .nav-content {
  position: relative;
  width: max-content;
  max-width: 100%;
  min-height: 0;
  height: 56px;
  margin: 0 auto;
  padding: 0 14px 0 22px;
  display: flex;
  align-items: center;
  border-radius: 16px;
  pointer-events: auto;
  transition: padding 0.5s var(--pill-ease);
}

/* The glass surface lives on a pseudo-element: a backdrop-filter on the
   pill itself would trap the mobile menu (position: fixed) inside it. */
nav.pill-nav .nav-content::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background: var(--pill-bg);
  box-shadow: inset 0 0 0 1px var(--pill-line), 0 10px 30px -18px rgba(0, 0, 0, 0.5);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  backdrop-filter: blur(16px) saturate(1.4);
}

nav.pill-nav a:has(.logo) {
  flex-shrink: 0;
  display: flex;
  align-items: center;
}
nav.pill-nav .logo { width: 44px; }

nav.pill-nav .nav-divider { display: none; }

/* ---------- Links + actions (the part that folds away) ---------- */
nav.pill-nav .nav-links,
nav.pill-nav .nav-actions {
  overflow: hidden;
  white-space: nowrap;
  max-width: 420px;
  opacity: 1;
  transition:
    max-width 0.5s var(--pill-ease),
    opacity 0.35s var(--pill-ease),
    margin 0.5s var(--pill-ease),
    padding 0.5s var(--pill-ease);
}

nav.pill-nav .nav-links {
  flex: 0 0 auto;
  margin: 0;
  padding: 0 0 0 18px;
}

nav.pill-nav .nav-links a {
  color: var(--pill-fg);
  margin: 0 12px;
  padding: 0;
  font-size: 16px;
  font-weight: 400;
  line-height: 56px;
}
nav.pill-nav .nav-links a:hover { opacity: 0.6; }
nav.pill-nav .nav-links a.active::after {
  bottom: 10px;
  width: 4px;
  height: 4px;
  background-color: var(--pill-fg);
}

nav.pill-nav .nav-actions {
  margin-left: 6px;
  gap: 4px;
}
nav.pill-nav .theme-toggle {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 10px;
  color: var(--pill-fg);
}
nav.pill-nav .theme-toggle:hover {
  opacity: 1;
  background: rgba(127, 127, 127, 0.16);
}
nav.pill-nav .hamburger span { background-color: var(--pill-fg); }

/* ---------- Compact: logo only (desktop) ---------- */
@media (min-width: 769px) {
  nav.pill-nav.is-compact .nav-content { padding: 0 14px; }

  nav.pill-nav.is-compact .nav-links,
  nav.pill-nav.is-compact .nav-actions {
    max-width: 0;
    opacity: 0;
    margin: 0;
    padding: 0;
    pointer-events: none;
  }

  /* Opening again: links come back slightly after the pill widens. */
  nav.pill-nav:not(.is-compact) .nav-links,
  nav.pill-nav:not(.is-compact) .nav-actions {
    transition-delay: 0s, 0.08s, 0s, 0s;
  }
}

/* ---------- Mobile: full-width pill, menu via hamburger ---------- */
@media (max-width: 768px) {
  nav.pill-nav { padding: 12px 16px 0; }

  nav.pill-nav .nav-content {
    width: 100%;
    max-width: none;
    padding: 0 16px 0 18px;
  }

  /* The slide-in menu keeps its own layout from style.css */
  nav.pill-nav .nav-links {
    overflow: visible;
    max-width: none;
    padding: 6rem 2rem 2rem;
  }
  nav.pill-nav .nav-links a {
    font-size: 2rem;
    line-height: 1.6;
  }
  nav.pill-nav .nav-links a.active::after { bottom: -6px; }

  nav.pill-nav .nav-actions {
    overflow: visible;
    max-width: none;
    margin-left: auto;
    gap: 0.75rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  nav.pill-nav .nav-content,
  nav.pill-nav .nav-links,
  nav.pill-nav .nav-actions { transition: none; }
}

/* =========================================================
   Liquid glass surface for the pill
   Clear tint, strong blur + saturation, a bright rim along the
   top edge and a soft sheen. On Chromium a displacement filter
   (injected by nav-pill.js) adds a slight refraction at the edges.
   ========================================================= */
nav.pill-nav {
  --glass-tint: rgba(28, 28, 30, 0.28);
  --glass-rim: rgba(255, 255, 255, 0.28);
  --glass-rim-soft: rgba(255, 255, 255, 0.08);
  --glass-sheen: rgba(255, 255, 255, 0.10);
  --glass-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.45);
}
html[data-theme="light"] nav.pill-nav {
  --glass-tint: rgba(255, 255, 255, 0.22);
  --glass-rim: rgba(255, 255, 255, 0.9);
  --glass-rim-soft: rgba(255, 255, 255, 0.35);
  --glass-sheen: rgba(255, 255, 255, 0.35);
  --glass-shadow: 0 10px 30px -12px rgba(0, 0, 0, 0.25);
}

nav.pill-nav .nav-content::before {
  background:
    linear-gradient(180deg, var(--glass-sheen) 0%, rgba(255, 255, 255, 0) 55%),
    var(--glass-tint);
  box-shadow:
    inset 0 1px 0 0 var(--glass-rim),            /* bright top edge */
    inset 0 -1px 0 0 var(--glass-rim-soft),      /* faint bottom edge */
    inset 0 0 0 1px var(--glass-rim-soft),       /* hairline all round */
    inset 0 0 12px 0 rgba(255, 255, 255, 0.06),  /* inner glow */
    var(--glass-shadow);
  -webkit-backdrop-filter: blur(14px) saturate(1.8) brightness(1.05);
  backdrop-filter: blur(14px) saturate(1.8) brightness(1.05);
}

/* Specular highlight that drifts with the pointer (set by nav-pill.js) */
nav.pill-nav .nav-content::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  pointer-events: none;
  background: radial-gradient(120px 60px at var(--glass-x, 30%) 0%, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0) 70%);
  opacity: 0.8;
  transition: opacity 0.3s ease;
}

/* Chromium: refraction via an SVG displacement map in the backdrop */
html.glass-refract nav.pill-nav .nav-content::before {
  -webkit-backdrop-filter: url(#pill-glass) blur(10px) saturate(1.8) brightness(1.05);
  backdrop-filter: url(#pill-glass) blur(10px) saturate(1.8) brightness(1.05);
}

@media (prefers-reduced-transparency: reduce) {
  nav.pill-nav .nav-content::before { background: rgba(30, 30, 30, 0.92); }
  html[data-theme="light"] nav.pill-nav .nav-content::before { background: rgba(250, 250, 250, 0.95); }
}

/* Over a dark surface (e.g. the black hero card in the light theme) the
   clear glass would leave dark text on dark: nav-pill.js adds .on-dark
   and the pill switches to light text with a darker tint. */
html[data-theme="light"] nav.pill-nav.on-dark {
  --pill-fg: #f5f5f5;
  --glass-tint: rgba(28, 28, 30, 0.32);
  --glass-rim: rgba(255, 255, 255, 0.3);
  --glass-rim-soft: rgba(255, 255, 255, 0.1);
  --glass-sheen: rgba(255, 255, 255, 0.1);
}
html[data-theme="light"] nav.pill-nav.on-dark .logo { filter: none; }
html[data-theme="light"] nav.pill-nav.on-dark .theme-toggle { color: #f5f5f5; }
nav.pill-nav .nav-links a,
nav.pill-nav .theme-toggle,
nav.pill-nav .logo { transition: color 0.3s ease, filter 0.3s ease, opacity 0.3s; }

/* The mirror case on the dark theme: over a light surface (e.g. the white
   footer card) the pill switches to dark text. */
html:not([data-theme="light"]) nav.pill-nav.on-light {
  --pill-fg: #1e1e1e;
  --glass-tint: rgba(255, 255, 255, 0.3);
  --glass-rim: rgba(255, 255, 255, 0.9);
  --glass-rim-soft: rgba(255, 255, 255, 0.35);
  --glass-sheen: rgba(255, 255, 255, 0.35);
}
html:not([data-theme="light"]) nav.pill-nav.on-light .logo { filter: invert(1); }

/* =========================================================
   Mobile full-screen menu
   Fades in (no side slide), links rise in one after another,
   the logo and controls stay visible on top, the scroll-to-top
   button hides and the page stops scrolling. html.menu-open is
   set by toggleMenu() in main.js.
   ========================================================= */
@media (max-width: 768px) {
  nav.pill-nav .nav-links {
    transform: none;
    opacity: 0;
    visibility: hidden;
    justify-content: center;
    gap: 0.25rem;
    transition: opacity 0.35s ease, visibility 0s linear 0.35s;
  }
  nav.pill-nav .nav-links.show {
    transform: none;
    opacity: 1;
    visibility: visible;
    transition: opacity 0.35s ease, visibility 0s;
  }
  nav.pill-nav .nav-links.hide { transform: none; }

  nav.pill-nav .nav-links li {
    opacity: 0;
    transform: translateY(18px);
    transition: opacity 0.3s ease, transform 0.3s ease;
  }
  nav.pill-nav .nav-links.show li {
    opacity: 1;
    transform: none;
    transition: opacity 0.6s cubic-bezier(0.16, 1, 0.3, 1), transform 0.7s cubic-bezier(0.16, 1, 0.3, 1);
  }
  nav.pill-nav .nav-links.show li:nth-child(1) { transition-delay: 0.08s; }
  nav.pill-nav .nav-links.show li:nth-child(2) { transition-delay: 0.14s; }
  nav.pill-nav .nav-links.show li:nth-child(3) { transition-delay: 0.20s; }

  nav.pill-nav .nav-links a {
    display: inline-block;
    font-size: 2.5rem;
    font-weight: 600;
    letter-spacing: -0.03em;
    line-height: 1.35;
  }
  nav.pill-nav .nav-links a.active::after { bottom: 2px; width: 6px; height: 6px; }

  /* Logo stays above the open menu, like the controls */
  nav.pill-nav a:has(.logo) { position: relative; z-index: 1100; }

  /* Hamburger -> close: three centred 2px lines that cross into an X */
  nav.pill-nav .hamburger {
    position: relative;
    width: 40px;
    height: 40px;
    display: block;
    gap: 0;
    border-radius: 12px;
    cursor: pointer;
  }
  nav.pill-nav .hamburger span {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 22px;
    height: 2px;
    margin: -1px 0 0 -11px;
    border-radius: 2px;
    transition: transform 0.45s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease;
  }
  nav.pill-nav .hamburger span:nth-child(1) { transform: translateY(-7px); }
  nav.pill-nav .hamburger span:nth-child(3) { transform: translateY(7px); }
  nav.pill-nav .hamburger.active span:nth-child(1) { transform: rotate(45deg); }
  nav.pill-nav .hamburger.active span:nth-child(2) { opacity: 0; transform: scaleX(0.2); }
  nav.pill-nav .hamburger.active span:nth-child(3) { transform: rotate(-45deg); }
}

html.menu-open,
html.menu-open body { overflow: hidden; }
html.menu-open #fab-button { opacity: 0 !important; visibility: hidden !important; pointer-events: none; }

/* The open menu has the page colour, so undo the over-dark / over-light
   contrast swap while it is showing. */
html[data-theme="light"].menu-open nav.pill-nav.on-dark { --pill-fg: #1e1e1e; }
html[data-theme="light"].menu-open nav.pill-nav.on-dark .logo { filter: invert(1); }
html[data-theme="light"].menu-open nav.pill-nav.on-dark .theme-toggle { color: #111; }
html:not([data-theme="light"]).menu-open nav.pill-nav.on-light { --pill-fg: #f5f5f5; }
html:not([data-theme="light"]).menu-open nav.pill-nav.on-light .logo { filter: none; }

@media (prefers-reduced-motion: reduce) {
  nav.pill-nav .nav-links li,
  nav.pill-nav .hamburger span { transition: none; }
}

/* logo.svg draws the "a." low in its square (glyph centre at 171 of 300),
   so lift it by that 7% to sit on the pill's centre line. */
nav.pill-nav .logo { transform: translateY(-7%); }

/* Active-page dot: the link has to be a block as tall as the pill (56px)
   for "bottom: 10px" to land under the word, not across it. */
@media (min-width: 769px) {
  nav.pill-nav .nav-links a { display: inline-block; line-height: 56px; }
  nav.pill-nav .nav-links a.active::after { bottom: 9px; }
}

/* Pages on case.css have no global border-box, which made the nav's
   padding add to its height (100px + 40px). Measure it the same everywhere. */
nav.pill-nav, nav.pill-nav .nav-content { box-sizing: border-box; }
