/* The blog nav with the text caret: the top bar of a writer's blog, alone on a white page. The name in italic, four
   links in Newsreader (a variable serif, weight 200 to 800) and a text caret in ink blue after the page you are on. */
:root {
  --page: #09090b;                          /* the page */
  --halo: rgba(92, 116, 255, 0.16);         /* the soft light behind the bar */
  --glass-top: rgba(255, 255, 255, 0.075);  /* the bar's glass, at the top */
  --glass-bottom: rgba(255, 255, 255, 0.025); /* the bar's glass, at the bottom */
  --edge: rgba(255, 255, 255, 0.09);        /* the 1px edge of the bar */
  --edge-light: rgba(255, 255, 255, 0.22);  /* the top edge, where it catches the light */
  --ink: #f0f0f4;                           /* the name and the current link */
  --muted: #7c7c88;                         /* the other links */
  --caret: #7590ff;                         /* the caret and its light */
}

* {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
}

html,
body {
  margin: 0;
  overflow-x: clip;
}

body {
  min-height: 100svh;
  background: var(--page);
  color: var(--ink);
  font-family: 'Newsreader Variable', 'Newsreader', Georgia, 'Times New Roman', serif;
  -webkit-font-smoothing: antialiased;
}

.stage {
  position: relative;
  min-height: 100svh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  place-items: center;
  padding: 24px 16px;
  overflow: hidden;
  /* a soft light behind the bar, so the page is never flat */
  background: radial-gradient(ellipse min(520px, 80vw) min(200px, 30vh) at 50% 50%, var(--halo), transparent 70%);
}

/* a fine grain over the whole page, drawn here as SVG noise */
.stage::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.07;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

a {
  color: inherit;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

a:focus {
  outline: none;
}

/* ---------------------------------------------------------------- the bar: a capsule of smoked glass */
.bar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(600px, 100%);
  height: 60px;
  padding: 0 26px 0 24px;
  border-radius: 30px;
  background: linear-gradient(180deg, var(--glass-top), var(--glass-bottom));
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  backdrop-filter: blur(14px) saturate(1.2);
  box-shadow:
    inset 0 0 0 1px var(--edge),
    inset 0 1px 0 0 var(--edge-light),
    inset 0 -1px 0 0 rgba(0, 0, 0, 0.35),
    0 1px 2px rgba(0, 0, 0, 0.5),
    0 10px 24px -8px rgba(0, 0, 0, 0.7),
    0 34px 60px -24px rgba(0, 0, 0, 0.85);
}

/* the light under the caret: it pools on the glass where the caret stands and brightens while it moves */
.bar__glow {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  overflow: hidden;
  pointer-events: none;
}

.bar__glow-spot {
  position: absolute;
  left: 0;
  top: 50%;
  width: 150px;
  height: 90px;
  margin: -45px 0 0 -75px;
  border-radius: 50%;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--caret) 34%, transparent), transparent);
  opacity: 0;
}

/* the same light on the bar's bottom edge, a thin line that only shows under the caret */
.bar__glow-line {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 120px;
  height: 1px;
  margin-left: -60px;
  background: linear-gradient(90deg, transparent, var(--caret), transparent);
  opacity: 0;
}

.brand {
  position: relative;
  font-style: italic;
  font-size: 20px;
  font-weight: 420;
  font-variation-settings: 'opsz' 36;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

/* ---------------------------------------------------------------- the links */
.nav {
  position: relative;
}

.list {
  display: flex;
  gap: clamp(18px, 4.4vw, 30px);
  margin: 0;
  padding: 0;
  list-style: none;
}

.link {
  position: relative;
  display: block;
  padding: 8px 0;
  border-radius: 6px;
}

.word {
  display: inline-block;
  font-size: 17px;
  line-height: 22px;
  font-variation-settings: 'opsz' 16;
  white-space: nowrap;
  /* --t goes to 1 for a moment while the caret glides over the word */
  color: color-mix(in srgb, var(--ink) calc(var(--t, 0) * 55%), var(--muted));
}

/* every letter has its own weight: the new page fills in one letter after the other, in the caret's direction */
.ch {
  display: inline-block;
  font-weight: 400;
}

.link[aria-current='page'] .word {
  color: var(--ink);
}

@media (hover: hover) {
  .link:hover .word {
    color: color-mix(in srgb, var(--ink) 78%, var(--muted));
  }
}

/* the word that is chosen glows a little, as text lit by a screen */
.link[aria-current='page'] .word {
  text-shadow: 0 0 18px color-mix(in srgb, var(--caret) 30%, transparent);
}

.link:focus-visible::after {
  content: '';
  position: absolute;
  inset: 3px -7px;
  border: 1px solid var(--caret);
  border-radius: 6px;
}

/* ---------------------------------------------------------------- the caret */
.caret,
.ghost {
  position: absolute;
  left: 0;
  top: 0;
  width: 2px;
  height: 21px;
  pointer-events: none;
}

.caret__body,
.ghost__bar {
  display: block;
  width: 100%;
  height: 100%;
  transform-origin: 50% 100%;
}

.caret__bar {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 1px;
  background: linear-gradient(180deg, #ffffff 0%, var(--caret) 35%, var(--caret) 100%);
  box-shadow: 0 0 6px 0 color-mix(in srgb, var(--caret) 80%, transparent), 0 0 16px 1px color-mix(in srgb, var(--caret) 40%, transparent);
}

.ghost__bar {
  border-radius: 1px;
  background: var(--ink);
  opacity: 0;
  transform-origin: 50% 50%;
}

/* ---------------------------------------------------------------- narrow: the links alone, in the middle */
@media (max-width: 560px) {
  .bar {
    justify-content: center;
    padding: 0 18px;
  }

  .brand {
    display: none;
  }
}
