/* ── Gradient menu ── */
.menu {
  /* Bauhaus palette */
  --crimson:   #F40220;
  --tangerine: #FF7B30;
  --blueprint: #4A78FF; /* lightened from #0019FF so black text reads on it */
  --flamingo:  #FF5AA9;
  --herbs:     #09A953;
  --saffron:   #ECB617;

  --gap: var(--space-4);
  --strip: var(--space-1);
  --duration: 400ms;

  width: 100%;
  max-width: 480px;
}

/* Keep the menu anchored while panels open */
.dx-stage {
  place-items: start center;
}

.menu ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

.menu > ol > li {
  --gradient: var(--dx-fg);  /* strip colour, also the panel's base */
  --tone: var(--blanco);     /* the panel fades towards this */
  --panel-dir: to right;     /* away from the strip */
  --ink: var(--negro);       /* text on the open panel */
  position: relative;
  isolation: isolate;
  border-left: var(--strip) solid var(--gradient);
  border-bottom: var(--border-hairline) solid color-mix(in srgb, var(--dx-fg) 25%, transparent);
}

/* Saffron is left out: it is too close to the mustard page */
.menu > ol > li:nth-child(1) { --gradient: var(--blueprint); }
.menu > ol > li:nth-child(2) { --gradient: var(--tangerine); }
.menu > ol > li:nth-child(3) { --gradient: var(--herbs); }
.menu > ol > li:nth-child(4) { --gradient: var(--crimson); }
.menu > ol > li:nth-child(5) { --gradient: var(--flamingo); }

/* Colour panel: starts in the strip colour and lightens towards --tone */
.menu > ol > li::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  max-width: 0;
  background: linear-gradient(var(--panel-dir), var(--gradient), color-mix(in oklab, var(--gradient), var(--tone) 30%));
  transition: max-width var(--duration) var(--ease-out), inset var(--duration) var(--ease-out);
}

.menu a {
  position: relative;
  display: block;
  padding: var(--gap);
  color: inherit;
  font-weight: 700;
  text-decoration: none;
}

.menu a:focus-visible {
  outline: none;
}

/* Chevron on items with a sub-menu */
.menu a:not(:last-child)::before {
  content: "";
  position: absolute;
  top: 50%;
  right: calc(var(--gap) + var(--space-1));
  width: 8px;
  height: 8px;
  border-right: var(--border-rule) solid currentColor;
  border-bottom: var(--border-rule) solid currentColor;
  transform: translateY(-75%) rotate(45deg);
  transition: transform var(--duration) var(--ease-out);
}

/* Underline indicator */
.menu a::after {
  content: "";
  position: absolute;
  left: var(--gap);
  bottom: var(--space-2);
  width: 0;
  height: var(--border-rule);
  background: currentColor;
  transition: width var(--duration) var(--ease-out) var(--duration-fast);
}

.menu a:focus-visible::after { width: var(--space-6); }

/* Sub-menu */
.sub-menu {
  position: relative;
  max-height: 0;
  overflow: hidden;
  margin-left: calc(var(--gap) * 1.5);
  padding-left: calc(var(--gap) / 2);
  border-left: var(--border-hairline) solid currentColor;
  transition: max-height var(--duration) var(--ease-out);
}

.sub-menu a {
  padding-block: var(--space-3);
  font: 500 var(--text-meta) / 1.2 var(--font-mono);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.sub-menu a::after { bottom: var(--space-1); height: var(--border-hairline); }
.sub-menu a:focus-visible { background: color-mix(in srgb, currentColor 15%, transparent); }
.sub-menu a:focus-visible::after { width: var(--space-4); }

/* Open state: keyboard and touch */
.menu > ol > li:focus-within {
  z-index: 5;
  color: var(--ink);
}
.menu > ol > li:focus-within::after { max-width: 100%; }
.menu > ol > li:focus-within .sub-menu { max-height: 500px; }
.menu > ol > li:focus-within > a::before { transform: translateY(-25%) rotate(225deg); }

/* Open state: mouse */
@media (hover: hover) and (pointer: fine) {
  .menu > ol > li:hover {
    z-index: 5;
    color: var(--ink);
  }
  .menu > ol > li:hover::after { max-width: 100%; }
  .menu > ol > li:hover > a::before { transform: translateY(-25%) rotate(225deg); }
  .menu a:hover::after { width: var(--space-6); }
  .sub-menu a:hover { background: color-mix(in srgb, currentColor 15%, transparent); }
  .sub-menu a:hover::after { width: var(--space-4); }
}

/* Horizontal bar */
@media (min-width: 600px) {
  .menu {
    max-width: none;
    margin-top: 30vh;
  }

  .menu > ol {
    display: flex;
    justify-content: center;
    align-items: flex-start;
  }

  .menu > ol > li {
    width: 120px;
    border-left: 0;
    border-bottom: 0;
    border-top: var(--strip) solid var(--gradient);
    text-align: center;
  }

  .menu > ol > li::after {
    --panel-dir: to bottom;
  }

  .menu > ol > li:focus-within::after {
    inset: calc(var(--gap) * -1);
    max-width: none;
  }

  .menu a::after {
    left: 0;
    right: 0;
    margin: auto;
  }

  .menu a:not(:last-child)::before { right: var(--space-3); }

  .sub-menu {
    margin: var(--gap) calc(var(--gap) * -1) calc(var(--gap) * -1);
    padding-left: 0;
    border-left: 0;
  }
}

@media (min-width: 600px) and (hover: hover) and (pointer: fine) {
  .menu > ol > li:hover::after {
    inset: calc(var(--gap) * -1);
    max-width: none;
  }
  .menu > ol > li:hover .sub-menu { max-height: 500px; }
}

@media (min-width: 775px) {
  .menu > ol > li { width: 150px; }
  .menu a:not(:last-child)::before { right: var(--gap); }
}

/* Reduced motion: panels fade in place */
@media (prefers-reduced-motion: reduce) {
  .menu > ol > li::after {
    max-width: none;
    opacity: 0;
    transition: opacity var(--duration-fast) linear;
  }
  .menu > ol > li:focus-within::after { opacity: 1; }

  .sub-menu {
    opacity: 0;
    transition: opacity var(--duration-fast) linear;
  }
  .menu > ol > li:focus-within .sub-menu { opacity: 1; }

  .menu a::before,
  .menu a::after { transition: none; }
}

@media (prefers-reduced-motion: reduce) and (hover: hover) and (pointer: fine) {
  .menu > ol > li:hover::after { opacity: 1; }
  .menu > ol > li:hover .sub-menu { opacity: 1; }
}
